MCPcopy Create free account
hub / github.com/TruthHun/BookStack / makeSqrtImage

Function makeSqrtImage

static/katex/katex.mjs:8296–8360  ·  view source on GitHub ↗
(height, options)

Source from the content-addressed store, hash-verified

8294
8295
8296const makeSqrtImage = function makeSqrtImage(height, options) {
8297 // Define a newOptions that removes the effect of size changes such as \Huge.
8298 // We don't pick different a height surd for \Huge. For it, we scale up.
8299 const newOptions = options.havingBaseSizing(); // Pick the desired surd glyph from a sequence of surds.
8300
8301 const delim = traverseSequence("\\surd", height * newOptions.sizeMultiplier, stackLargeDelimiterSequence, newOptions);
8302 let sizeMultiplier = newOptions.sizeMultiplier; // default
8303 // Create a span containing an SVG image of a sqrt symbol.
8304
8305 let span;
8306 let spanHeight = 0;
8307 let texHeight = 0;
8308 let viewBoxHeight = 0;
8309 let advanceWidth; // We create viewBoxes with 80 units of "padding" above each surd.
8310 // Then browser rounding error on the parent span height will not
8311 // encroach on the ink of the viniculum. But that padding is not
8312 // included in the TeX-like `height` used for calculation of
8313 // vertical alignment. So texHeight = span.height < span.style.height.
8314
8315 if (delim.type === "small") {
8316 // Get an SVG that is derived from glyph U+221A in font KaTeX-Main.
8317 viewBoxHeight = 1000 + vbPad; // 1000 unit glyph height.
8318
8319 if (height < 1.0) {
8320 sizeMultiplier = 1.0; // mimic a \textfont radical
8321 } else if (height < 1.4) {
8322 sizeMultiplier = 0.7; // mimic a \scriptfont radical
8323 }
8324
8325 spanHeight = (1.0 + emPad) / sizeMultiplier;
8326 texHeight = 1.00 / sizeMultiplier;
8327 span = sqrtSvg("sqrtMain", spanHeight, viewBoxHeight, options);
8328 span.style.minWidth = "0.853em";
8329 advanceWidth = 0.833 / sizeMultiplier; // from the font.
8330 } else if (delim.type === "large") {
8331 // These SVGs come from fonts: KaTeX_Size1, _Size2, etc.
8332 viewBoxHeight = (1000 + vbPad) * sizeToMaxHeight[delim.size];
8333 texHeight = sizeToMaxHeight[delim.size] / sizeMultiplier;
8334 spanHeight = (sizeToMaxHeight[delim.size] + emPad) / sizeMultiplier;
8335 span = sqrtSvg("sqrtSize" + delim.size, spanHeight, viewBoxHeight, options);
8336 span.style.minWidth = "1.02em";
8337 advanceWidth = 1.0 / sizeMultiplier; // 1.0 from the font.
8338 } else {
8339 // Tall sqrt. In TeX, this would be stacked using multiple glyphs.
8340 // We'll use a single SVG to accomplish the same thing.
8341 spanHeight = height + emPad;
8342 texHeight = height;
8343 viewBoxHeight = Math.floor(1000 * height) + vbPad;
8344 span = sqrtSvg("sqrtTall", spanHeight, viewBoxHeight, options);
8345 span.style.minWidth = "0.742em";
8346 advanceWidth = 1.056;
8347 }
8348
8349 span.height = texHeight;
8350 span.style.height = spanHeight + "em";
8351 return {
8352 span,
8353 advanceWidth,

Callers

nothing calls this directly

Calls 4

sqrtSvgFunction · 0.85
havingBaseSizingMethod · 0.80
fontMetricsMethod · 0.80
traverseSequenceFunction · 0.70

Tested by

no test coverage detected