katex 0.10.0-rc → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +214 -126
- package/README.md +18 -17
- package/cli.js +5 -1
- package/contrib/auto-render/README.md +1 -1
- package/contrib/auto-render/auto-render.js +4 -1
- package/contrib/auto-render/test/auto-render-spec.js +17 -0
- package/contrib/copy-tex/README.md +8 -2
- package/contrib/copy-tex/copy-tex.js +0 -1
- package/contrib/copy-tex/copy-tex.webpack.js +6 -0
- package/contrib/mathtex-script-type/README.md +10 -6
- package/contrib/mhchem/README.md +19 -0
- package/contrib/mhchem/mhchem.js +1695 -0
- package/contrib/mhchem/mhchem.patch +235 -0
- package/dist/README.md +18 -17
- package/dist/contrib/auto-render.js +179 -161
- package/dist/contrib/auto-render.min.js +1 -1
- package/dist/contrib/auto-render.mjs +215 -0
- package/dist/contrib/copy-tex.js +84 -62
- package/dist/contrib/copy-tex.min.css +1 -1
- package/dist/contrib/copy-tex.min.js +1 -1
- package/dist/contrib/copy-tex.mjs +85 -0
- package/dist/contrib/mathtex-script-type.js +17 -14
- package/dist/contrib/mathtex-script-type.mjs +24 -0
- package/dist/contrib/mhchem.js +3241 -0
- package/dist/contrib/mhchem.min.js +1 -0
- package/dist/contrib/mhchem.mjs +3109 -0
- package/dist/fonts/KaTeX_AMS-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_AMS-Regular.woff +0 -0
- package/dist/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_Fraktur-Bold.woff +0 -0
- package/dist/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Fraktur-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_Main-Bold.woff +0 -0
- package/dist/fonts/KaTeX_Main-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
- package/dist/fonts/KaTeX_Main-BoldItalic.woff +0 -0
- package/dist/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Italic.ttf +0 -0
- package/dist/fonts/KaTeX_Main-Italic.woff +0 -0
- package/dist/fonts/KaTeX_Main-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Main-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Main-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
- package/dist/fonts/KaTeX_Math-BoldItalic.woff +0 -0
- package/dist/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/dist/fonts/KaTeX_Math-Italic.ttf +0 -0
- package/dist/fonts/KaTeX_Math-Italic.woff +0 -0
- package/dist/fonts/KaTeX_Math-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_SansSerif-Bold.woff +0 -0
- package/dist/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
- package/dist/fonts/KaTeX_SansSerif-Italic.woff +0 -0
- package/dist/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_SansSerif-Regular.woff +0 -0
- package/dist/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Script-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Script-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Script-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size1-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size1-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size2-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size2-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size3-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size3-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size4-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size4-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Typewriter-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/dist/katex.css +24 -9
- package/dist/katex.js +13295 -12413
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +13388 -11826
- package/katex.js +1 -2
- package/package.json +60 -48
- package/src/Lexer.js +25 -25
- package/src/MacroExpander.js +0 -1
- package/src/Options.js +11 -75
- package/src/Parser.js +231 -313
- package/src/Settings.js +6 -0
- package/src/buildCommon.js +140 -103
- package/src/buildHTML.js +125 -121
- package/src/buildMathML.js +14 -4
- package/src/buildTree.js +16 -10
- package/src/delimiter.js +4 -3
- package/src/domTree.js +91 -44
- package/src/environments/array.js +120 -7
- package/src/fontMetrics.js +3 -2
- package/src/functions/arrow.js +21 -7
- package/src/functions/color.js +2 -37
- package/src/functions/delimsizing.js +18 -11
- package/src/functions/enclose.js +19 -4
- package/src/functions/environment.js +35 -4
- package/src/functions/font.js +1 -2
- package/src/functions/genfrac.js +35 -20
- package/src/functions/href.js +5 -3
- package/src/functions/includegraphics.js +146 -0
- package/src/functions/mclass.js +1 -0
- package/src/functions/op.js +21 -32
- package/src/functions/operatorname.js +1 -2
- package/src/functions/ordgroup.js +4 -0
- package/src/functions/phantom.js +7 -3
- package/src/functions/rule.js +20 -9
- package/src/functions/sizing.js +2 -4
- package/src/functions/smash.js +5 -2
- package/src/functions/sqrt.js +1 -4
- package/src/functions/styling.js +0 -1
- package/src/functions/supsub.js +6 -2
- package/src/functions/symbolsOp.js +4 -0
- package/src/functions/symbolsSpacing.js +29 -6
- package/src/functions/tag.js +20 -4
- package/src/functions/text.js +6 -4
- package/src/functions/verb.js +16 -4
- package/src/functions.js +2 -0
- package/src/katex.less +35 -12
- package/src/macros.js +161 -36
- package/src/mathMLTree.js +17 -19
- package/src/parseNode.js +27 -1
- package/src/stretchy.js +3 -1
- package/src/svgGeometry.js +1 -1
- package/src/symbols.js +39 -17
- package/src/tree.js +0 -4
- package/src/types.js +4 -3
- package/src/unicodeMake.js +1 -1
- package/src/utils.js +1 -62
- package/src/wide-character.js +2 -2
package/src/Settings.js
CHANGED
|
@@ -18,6 +18,8 @@ export type StrictFunction =
|
|
|
18
18
|
|
|
19
19
|
export type SettingsOptions = {
|
|
20
20
|
displayMode?: boolean;
|
|
21
|
+
leqno?: boolean;
|
|
22
|
+
fleqn?: boolean;
|
|
21
23
|
throwOnError?: boolean;
|
|
22
24
|
errorColor?: string;
|
|
23
25
|
macros?: MacroMap;
|
|
@@ -40,6 +42,8 @@ export type SettingsOptions = {
|
|
|
40
42
|
*/
|
|
41
43
|
class Settings {
|
|
42
44
|
displayMode: boolean;
|
|
45
|
+
leqno: boolean;
|
|
46
|
+
fleqn: boolean;
|
|
43
47
|
throwOnError: boolean;
|
|
44
48
|
errorColor: string;
|
|
45
49
|
macros: MacroMap;
|
|
@@ -53,6 +57,8 @@ class Settings {
|
|
|
53
57
|
// allow null options
|
|
54
58
|
options = options || {};
|
|
55
59
|
this.displayMode = utils.deflt(options.displayMode, false);
|
|
60
|
+
this.leqno = utils.deflt(options.leqno, false);
|
|
61
|
+
this.fleqn = utils.deflt(options.fleqn, false);
|
|
56
62
|
this.throwOnError = utils.deflt(options.throwOnError, true);
|
|
57
63
|
this.errorColor = utils.deflt(options.errorColor, "#cc0000");
|
|
58
64
|
this.macros = options.macros || {};
|
package/src/buildCommon.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* different kinds of domTree nodes in a consistent manner.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {SymbolNode, Anchor, Span, PathNode, SvgNode} from "./domTree";
|
|
8
|
+
import {SymbolNode, Anchor, Span, PathNode, SvgNode, createClass} from "./domTree";
|
|
9
9
|
import {getCharacterMetrics} from "./fontMetrics";
|
|
10
10
|
import symbols, {ligatures} from "./symbols";
|
|
11
11
|
import utils from "./utils";
|
|
@@ -15,15 +15,14 @@ import {DocumentFragment} from "./tree";
|
|
|
15
15
|
|
|
16
16
|
import type Options from "./Options";
|
|
17
17
|
import type {ParseNode} from "./parseNode";
|
|
18
|
-
import type {NodeType} from "./parseNode";
|
|
19
18
|
import type {CharacterMetrics} from "./fontMetrics";
|
|
20
19
|
import type {FontVariant, Mode} from "./types";
|
|
21
20
|
import type {documentFragment as HtmlDocumentFragment} from "./domTree";
|
|
22
21
|
import type {HtmlDomNode, DomSpan, SvgSpan, CssStyle} from "./domTree";
|
|
23
22
|
import type {Measurement} from "./units";
|
|
24
23
|
|
|
25
|
-
// The following have to be loaded from Main-Italic font, using class
|
|
26
|
-
const
|
|
24
|
+
// The following have to be loaded from Main-Italic font, using class mathit
|
|
25
|
+
const mathitLetters = [
|
|
27
26
|
"\\imath", "ı", // dotless i
|
|
28
27
|
"\\jmath", "ȷ", // dotless j
|
|
29
28
|
"\\pounds", "\\mathsterling", "\\textsterling", "£", // pounds symbol
|
|
@@ -73,7 +72,7 @@ const makeSymbol = function(
|
|
|
73
72
|
let symbolNode;
|
|
74
73
|
if (metrics) {
|
|
75
74
|
let italic = metrics.italic;
|
|
76
|
-
if (mode === "text") {
|
|
75
|
+
if (mode === "text" || (options && options.font === "mathit")) {
|
|
77
76
|
italic = 0;
|
|
78
77
|
}
|
|
79
78
|
symbolNode = new SymbolNode(
|
|
@@ -133,70 +132,58 @@ const mathsym = function(
|
|
|
133
132
|
};
|
|
134
133
|
|
|
135
134
|
/**
|
|
136
|
-
*
|
|
135
|
+
* Determines which of the two font names (Main-Italic and Math-Italic) and
|
|
136
|
+
* corresponding style tags (maindefault or mathit) to use for default math font,
|
|
137
|
+
* depending on the symbol.
|
|
137
138
|
*/
|
|
138
|
-
const
|
|
139
|
+
const mathdefault = function(
|
|
139
140
|
value: string,
|
|
140
141
|
mode: Mode,
|
|
141
142
|
options: Options,
|
|
142
143
|
classes: string[],
|
|
143
|
-
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const fontName = retrieveTextFontName("amsrm", options.fontWeight,
|
|
153
|
-
options.fontShape);
|
|
154
|
-
return makeSymbol(
|
|
155
|
-
value, fontName, mode, options,
|
|
156
|
-
classes.concat("amsrm", options.fontWeight, options.fontShape));
|
|
157
|
-
} else if (font === "main" || !font) {
|
|
158
|
-
const fontName = retrieveTextFontName("textrm", options.fontWeight,
|
|
159
|
-
options.fontShape);
|
|
160
|
-
return makeSymbol(
|
|
161
|
-
value, fontName, mode, options,
|
|
162
|
-
classes.concat(options.fontWeight, options.fontShape));
|
|
163
|
-
} else { // fonts added by plugins
|
|
164
|
-
const fontName = retrieveTextFontName(font, options.fontWeight,
|
|
165
|
-
options.fontShape);
|
|
166
|
-
// We add font name as a css class
|
|
167
|
-
return makeSymbol(
|
|
168
|
-
value, fontName, mode, options,
|
|
169
|
-
classes.concat(fontName, options.fontWeight, options.fontShape));
|
|
170
|
-
}
|
|
144
|
+
): {| fontName: string, fontClass: string |} {
|
|
145
|
+
if (/[0-9]/.test(value.charAt(0)) ||
|
|
146
|
+
// glyphs for \imath and \jmath do not exist in Math-Italic so we
|
|
147
|
+
// need to use Main-Italic instead
|
|
148
|
+
utils.contains(mathitLetters, value)) {
|
|
149
|
+
return {
|
|
150
|
+
fontName: "Main-Italic",
|
|
151
|
+
fontClass: "mathit",
|
|
152
|
+
};
|
|
171
153
|
} else {
|
|
172
|
-
|
|
154
|
+
return {
|
|
155
|
+
fontName: "Math-Italic",
|
|
156
|
+
fontClass: "mathdefault",
|
|
157
|
+
};
|
|
173
158
|
}
|
|
174
159
|
};
|
|
175
160
|
|
|
176
161
|
/**
|
|
177
|
-
* Determines which of the
|
|
178
|
-
* corresponding style tags (
|
|
179
|
-
* depending on the symbol. Use this function instead of fontMap for
|
|
180
|
-
* "
|
|
162
|
+
* Determines which of the font names (Main-Italic, Math-Italic, and Caligraphic)
|
|
163
|
+
* and corresponding style tags (mathit, mathdefault, or mathcal) to use for font
|
|
164
|
+
* "mathnormal", depending on the symbol. Use this function instead of fontMap for
|
|
165
|
+
* font "mathnormal".
|
|
181
166
|
*/
|
|
182
|
-
const
|
|
167
|
+
const mathnormal = function(
|
|
183
168
|
value: string,
|
|
184
169
|
mode: Mode,
|
|
185
170
|
options: Options,
|
|
186
171
|
classes: string[],
|
|
187
172
|
): {| fontName: string, fontClass: string |} {
|
|
188
|
-
if (
|
|
189
|
-
// glyphs for \imath and \jmath do not exist in Math-Italic so we
|
|
190
|
-
// need to use Main-Italic instead
|
|
191
|
-
utils.contains(mainitLetters, value)) {
|
|
173
|
+
if (utils.contains(mathitLetters, value)) {
|
|
192
174
|
return {
|
|
193
175
|
fontName: "Main-Italic",
|
|
194
|
-
fontClass: "
|
|
176
|
+
fontClass: "mathit",
|
|
177
|
+
};
|
|
178
|
+
} else if (/[0-9]/.test(value.charAt(0))) {
|
|
179
|
+
return {
|
|
180
|
+
fontName: "Caligraphic-Regular",
|
|
181
|
+
fontClass: "mathcal",
|
|
195
182
|
};
|
|
196
183
|
} else {
|
|
197
184
|
return {
|
|
198
185
|
fontName: "Math-Italic",
|
|
199
|
-
fontClass: "
|
|
186
|
+
fontClass: "mathdefault",
|
|
200
187
|
};
|
|
201
188
|
}
|
|
202
189
|
};
|
|
@@ -252,15 +239,15 @@ const makeOrd = function<NODETYPE: "spacing" | "mathord" | "textord">(
|
|
|
252
239
|
} else if (fontOrFamily) {
|
|
253
240
|
let fontName;
|
|
254
241
|
let fontClasses;
|
|
255
|
-
if (fontOrFamily === "boldsymbol") {
|
|
256
|
-
const fontData =
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
} else if (fontOrFamily === "mathit" ||
|
|
260
|
-
utils.contains(mainitLetters, text)) {
|
|
261
|
-
const fontData = mathit(text, mode, options, classes);
|
|
242
|
+
if (fontOrFamily === "boldsymbol" || fontOrFamily === "mathnormal") {
|
|
243
|
+
const fontData = fontOrFamily === "boldsymbol"
|
|
244
|
+
? boldsymbol(text, mode, options, classes)
|
|
245
|
+
: mathnormal(text, mode, options, classes);
|
|
262
246
|
fontName = fontData.fontName;
|
|
263
247
|
fontClasses = [fontData.fontClass];
|
|
248
|
+
} else if (utils.contains(mathitLetters, text)) {
|
|
249
|
+
fontName = "Main-Italic";
|
|
250
|
+
fontClasses = ["mathit"];
|
|
264
251
|
} else if (isFont) {
|
|
265
252
|
fontName = fontMap[fontOrFamily].fontName;
|
|
266
253
|
fontClasses = [fontOrFamily];
|
|
@@ -282,21 +269,88 @@ const makeOrd = function<NODETYPE: "spacing" | "mathord" | "textord">(
|
|
|
282
269
|
classes.concat(fontClasses)));
|
|
283
270
|
}
|
|
284
271
|
return makeFragment(parts);
|
|
285
|
-
}
|
|
286
|
-
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Makes a symbol in the default font for mathords and textords.
|
|
276
|
+
if (type === "mathord") {
|
|
277
|
+
const fontLookup = mathdefault(text, mode, options, classes);
|
|
278
|
+
return makeSymbol(text, fontLookup.fontName, mode, options,
|
|
279
|
+
classes.concat([fontLookup.fontClass]));
|
|
280
|
+
} else if (type === "textord") {
|
|
281
|
+
const font = symbols[mode][text] && symbols[mode][text].font;
|
|
282
|
+
if (font === "ams") {
|
|
283
|
+
const fontName = retrieveTextFontName("amsrm", options.fontWeight,
|
|
284
|
+
options.fontShape);
|
|
285
|
+
return makeSymbol(
|
|
286
|
+
text, fontName, mode, options,
|
|
287
|
+
classes.concat("amsrm", options.fontWeight, options.fontShape));
|
|
288
|
+
} else if (font === "main" || !font) {
|
|
289
|
+
const fontName = retrieveTextFontName("textrm", options.fontWeight,
|
|
290
|
+
options.fontShape);
|
|
291
|
+
return makeSymbol(
|
|
292
|
+
text, fontName, mode, options,
|
|
293
|
+
classes.concat(options.fontWeight, options.fontShape));
|
|
294
|
+
} else { // fonts added by plugins
|
|
295
|
+
const fontName = retrieveTextFontName(font, options.fontWeight,
|
|
296
|
+
options.fontShape);
|
|
297
|
+
// We add font name as a css class
|
|
298
|
+
return makeSymbol(
|
|
299
|
+
text, fontName, mode, options,
|
|
300
|
+
classes.concat(fontName, options.fontWeight, options.fontShape));
|
|
287
301
|
}
|
|
288
302
|
} else {
|
|
289
|
-
|
|
303
|
+
throw new Error("unexpected type: " + type + " in makeOrd");
|
|
290
304
|
}
|
|
291
305
|
};
|
|
292
306
|
|
|
293
307
|
/**
|
|
294
|
-
*
|
|
295
|
-
*
|
|
308
|
+
* Returns true if subsequent symbolNodes have the same classes, skew, maxFont,
|
|
309
|
+
* and styles.
|
|
296
310
|
*/
|
|
297
|
-
const
|
|
311
|
+
const canCombine = (prev: SymbolNode, next: SymbolNode) => {
|
|
312
|
+
if (createClass(prev.classes) !== createClass(next.classes)
|
|
313
|
+
|| prev.skew !== next.skew
|
|
314
|
+
|| prev.maxFontSize !== next.maxFontSize) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
for (const style in prev.style) {
|
|
319
|
+
if (prev.style.hasOwnProperty(style)
|
|
320
|
+
&& prev.style[style] !== next.style[style]) {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
for (const style in next.style) {
|
|
326
|
+
if (next.style.hasOwnProperty(style)
|
|
327
|
+
&& prev.style[style] !== next.style[style]) {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return true;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Combine consequetive domTree.symbolNodes into a single symbolNode.
|
|
337
|
+
* Note: this function mutates the argument.
|
|
338
|
+
*/
|
|
339
|
+
const tryCombineChars = (chars: HtmlDomNode[]): HtmlDomNode[] => {
|
|
298
340
|
for (let i = 0; i < chars.length - 1; i++) {
|
|
299
|
-
|
|
341
|
+
const prev = chars[i];
|
|
342
|
+
const next = chars[i + 1];
|
|
343
|
+
if (prev instanceof SymbolNode
|
|
344
|
+
&& next instanceof SymbolNode
|
|
345
|
+
&& canCombine(prev, next)) {
|
|
346
|
+
|
|
347
|
+
prev.text += next.text;
|
|
348
|
+
prev.height = Math.max(prev.height, next.height);
|
|
349
|
+
prev.depth = Math.max(prev.depth, next.depth);
|
|
350
|
+
// Use the last character's italic correction since we use
|
|
351
|
+
// it to add padding to the right of the span created from
|
|
352
|
+
// the combined characters.
|
|
353
|
+
prev.italic = next.italic;
|
|
300
354
|
chars.splice(i + 1, 1);
|
|
301
355
|
i--;
|
|
302
356
|
}
|
|
@@ -405,6 +459,20 @@ const makeFragment = function(
|
|
|
405
459
|
return fragment;
|
|
406
460
|
};
|
|
407
461
|
|
|
462
|
+
/**
|
|
463
|
+
* Wraps group in a span if it's a document fragment, allowing to apply classes
|
|
464
|
+
* and styles
|
|
465
|
+
*/
|
|
466
|
+
const wrapFragment = function(
|
|
467
|
+
group: HtmlDomNode,
|
|
468
|
+
options: Options,
|
|
469
|
+
): HtmlDomNode {
|
|
470
|
+
if (group instanceof DocumentFragment) {
|
|
471
|
+
return makeSpan([], [group], options);
|
|
472
|
+
}
|
|
473
|
+
return group;
|
|
474
|
+
};
|
|
475
|
+
|
|
408
476
|
|
|
409
477
|
// These are exact object types to catch typos in the names of the optional fields.
|
|
410
478
|
export type VListElem = {|
|
|
@@ -611,18 +679,6 @@ const makeVList = function(params: VListParam, options: Options): DomSpan {
|
|
|
611
679
|
return vtable;
|
|
612
680
|
};
|
|
613
681
|
|
|
614
|
-
// Converts verb group into body string, dealing with \verb* form
|
|
615
|
-
const makeVerb = function(group: ParseNode<"verb">, options: Options): string {
|
|
616
|
-
let text = group.body;
|
|
617
|
-
if (group.star) {
|
|
618
|
-
text = text.replace(/ /g, '\u2423'); // Open Box
|
|
619
|
-
} else {
|
|
620
|
-
text = text.replace(/ /g, '\xA0'); // No-Break Space
|
|
621
|
-
// (so that, in particular, spaces don't coalesce)
|
|
622
|
-
}
|
|
623
|
-
return text;
|
|
624
|
-
};
|
|
625
|
-
|
|
626
682
|
// Glue is a concept from TeX which is a flexible space between elements in
|
|
627
683
|
// either a vertical or horizontal list. In KaTeX, at least for now, it's
|
|
628
684
|
// static space between elements in a horizontal layout.
|
|
@@ -672,29 +728,6 @@ const retrieveTextFontName = function(
|
|
|
672
728
|
return `${baseFontName}-${fontStylesName}`;
|
|
673
729
|
};
|
|
674
730
|
|
|
675
|
-
// A map of CSS-based spacing functions to their CSS class.
|
|
676
|
-
const cssSpace: {[string]: string} = {
|
|
677
|
-
"\\nobreak": "nobreak",
|
|
678
|
-
"\\allowbreak": "allowbreak",
|
|
679
|
-
};
|
|
680
|
-
|
|
681
|
-
// A lookup table to determine whether a spacing function/symbol should be
|
|
682
|
-
// treated like a regular space character. If a symbol or command is a key
|
|
683
|
-
// in this table, then it should be a regular space character. Furthermore,
|
|
684
|
-
// the associated value may have a `className` specifying an extra CSS class
|
|
685
|
-
// to add to the created `span`.
|
|
686
|
-
const regularSpace: {[string]: { className?: string }} = {
|
|
687
|
-
" ": {},
|
|
688
|
-
"\\ ": {},
|
|
689
|
-
"~": {
|
|
690
|
-
className: "nobreak",
|
|
691
|
-
},
|
|
692
|
-
"\\space": {},
|
|
693
|
-
"\\nobreakspace": {
|
|
694
|
-
className: "nobreak",
|
|
695
|
-
},
|
|
696
|
-
};
|
|
697
|
-
|
|
698
731
|
/**
|
|
699
732
|
* Maps TeX font commands to objects containing:
|
|
700
733
|
* - variant: string used for "mathvariant" attribute in buildMathML.js
|
|
@@ -715,11 +748,17 @@ const fontMap: {[string]: {| variant: FontVariant, fontName: string |}} = {
|
|
|
715
748
|
variant: "italic",
|
|
716
749
|
fontName: "Main-Italic",
|
|
717
750
|
},
|
|
751
|
+
"mathit": {
|
|
752
|
+
variant: "italic",
|
|
753
|
+
fontName: "Main-Italic",
|
|
754
|
+
},
|
|
718
755
|
|
|
719
|
-
// "
|
|
720
|
-
// fonts: Main-Italic and Math-Italic for
|
|
721
|
-
// Main-
|
|
722
|
-
//
|
|
756
|
+
// Default math font, "mathnormal" and "boldsymbol" are missing because they
|
|
757
|
+
// require the use of several fonts: Main-Italic and Math-Italic for default
|
|
758
|
+
// math font, Main-Italic, Math-Italic, Caligraphic for "mathnormal", and
|
|
759
|
+
// Math-BoldItalic and Main-Bold for "boldsymbol". This is handled by a
|
|
760
|
+
// special case in makeOrd which ends up calling mathdefault, mathnormal,
|
|
761
|
+
// and boldsymbol.
|
|
723
762
|
|
|
724
763
|
// families
|
|
725
764
|
"mathbb": {
|
|
@@ -787,13 +826,11 @@ export default {
|
|
|
787
826
|
makeLineSpan,
|
|
788
827
|
makeAnchor,
|
|
789
828
|
makeFragment,
|
|
829
|
+
wrapFragment,
|
|
790
830
|
makeVList,
|
|
791
831
|
makeOrd,
|
|
792
|
-
makeVerb,
|
|
793
832
|
makeGlue,
|
|
794
833
|
staticSvg,
|
|
795
834
|
svgData,
|
|
796
835
|
tryCombineChars,
|
|
797
|
-
cssSpace,
|
|
798
|
-
regularSpace,
|
|
799
836
|
};
|