(
group: SymbolParseNode,
options: Options,
)
| 72 | * Returns the math variant as a string or null if none is required. |
| 73 | */ |
| 74 | export const getVariant = ( |
| 75 | group: SymbolParseNode, |
| 76 | options: Options, |
| 77 | ): FontVariant | null | undefined => { |
| 78 | // Handle \text... font specifiers as best we can. |
| 79 | // MathML has a limited list of allowable mathvariant specifiers; see |
| 80 | // https://www.w3.org/TR/MathML3/chapter3.html#presm.commatt |
| 81 | if (group.mode === "text") { |
| 82 | if (options.fontFamily === "texttt") { |
| 83 | return "monospace"; |
| 84 | } else if (options.fontFamily === "textsf") { |
| 85 | if (options.fontShape === "textit" && |
| 86 | options.fontWeight === "textbf") { |
| 87 | return "sans-serif-bold-italic"; |
| 88 | } else if (options.fontShape === "textit") { |
| 89 | return "sans-serif-italic"; |
| 90 | } else if (options.fontWeight === "textbf") { |
| 91 | return "bold-sans-serif"; |
| 92 | } else { |
| 93 | return "sans-serif"; |
| 94 | } |
| 95 | } else if (options.fontShape === "textit" && |
| 96 | options.fontWeight === "textbf") { |
| 97 | return "bold-italic"; |
| 98 | } else if (options.fontShape === "textit") { |
| 99 | return "italic"; |
| 100 | } else if (options.fontWeight === "textbf") { |
| 101 | return "bold"; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | const font = options.font; |
| 106 | if (!font || font === "mathnormal") { |
| 107 | return null; |
| 108 | } |
| 109 | |
| 110 | const mode = group.mode; |
| 111 | const mathVariant = mathFontVariants[font]; |
| 112 | |
| 113 | if (mathVariant) { |
| 114 | return typeof mathVariant === "function" |
| 115 | ? mathVariant(group) |
| 116 | : mathVariant; |
| 117 | } |
| 118 | |
| 119 | let text = group.text; |
| 120 | if (noVariantSymbols.has(text)) { |
| 121 | return null; |
| 122 | } |
| 123 | |
| 124 | if (symbols[mode][text]) { |
| 125 | const replacement = symbols[mode][text].replace; |
| 126 | if (replacement) { |
| 127 | text = replacement; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | const fontName = fontMap[font].fontName; |
nothing calls this directly
no test coverage detected
searching dependent graphs…