katex 0.11.1 → 0.12.0

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.
Files changed (116) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/LICENSE +1 -1
  3. package/README.md +5 -5
  4. package/contrib/auto-render/auto-render.js +12 -3
  5. package/contrib/copy-tex/README.md +3 -5
  6. package/contrib/mathtex-script-type/README.md +12 -14
  7. package/contrib/mhchem/README.md +1 -1
  8. package/contrib/render-a11y-string/render-a11y-string.js +10 -0
  9. package/dist/README.md +5 -5
  10. package/dist/contrib/auto-render.js +14 -3
  11. package/dist/contrib/auto-render.min.js +1 -1
  12. package/dist/contrib/auto-render.mjs +14 -3
  13. package/dist/contrib/mhchem.min.js +1 -1
  14. package/dist/contrib/render-a11y-string.js +12 -0
  15. package/dist/contrib/render-a11y-string.min.js +1 -1
  16. package/dist/contrib/render-a11y-string.mjs +12 -0
  17. package/dist/fonts/KaTeX_AMS-Regular.ttf +0 -0
  18. package/dist/fonts/KaTeX_AMS-Regular.woff +0 -0
  19. package/dist/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  20. package/dist/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  21. package/dist/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  22. package/dist/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  23. package/dist/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  24. package/dist/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  25. package/dist/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  26. package/dist/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  27. package/dist/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  28. package/dist/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  29. package/dist/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  30. package/dist/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  31. package/dist/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  32. package/dist/fonts/KaTeX_Main-Bold.ttf +0 -0
  33. package/dist/fonts/KaTeX_Main-Bold.woff +0 -0
  34. package/dist/fonts/KaTeX_Main-Bold.woff2 +0 -0
  35. package/dist/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  36. package/dist/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  37. package/dist/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  38. package/dist/fonts/KaTeX_Main-Italic.ttf +0 -0
  39. package/dist/fonts/KaTeX_Main-Italic.woff +0 -0
  40. package/dist/fonts/KaTeX_Main-Italic.woff2 +0 -0
  41. package/dist/fonts/KaTeX_Main-Regular.ttf +0 -0
  42. package/dist/fonts/KaTeX_Main-Regular.woff +0 -0
  43. package/dist/fonts/KaTeX_Main-Regular.woff2 +0 -0
  44. package/dist/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  45. package/dist/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  46. package/dist/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  47. package/dist/fonts/KaTeX_Math-Italic.ttf +0 -0
  48. package/dist/fonts/KaTeX_Math-Italic.woff +0 -0
  49. package/dist/fonts/KaTeX_Math-Italic.woff2 +0 -0
  50. package/dist/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  51. package/dist/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  52. package/dist/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  53. package/dist/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  54. package/dist/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  55. package/dist/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  56. package/dist/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  57. package/dist/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  58. package/dist/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  59. package/dist/fonts/KaTeX_Script-Regular.ttf +0 -0
  60. package/dist/fonts/KaTeX_Script-Regular.woff +0 -0
  61. package/dist/fonts/KaTeX_Script-Regular.woff2 +0 -0
  62. package/dist/fonts/KaTeX_Size1-Regular.ttf +0 -0
  63. package/dist/fonts/KaTeX_Size1-Regular.woff +0 -0
  64. package/dist/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  65. package/dist/fonts/KaTeX_Size2-Regular.ttf +0 -0
  66. package/dist/fonts/KaTeX_Size2-Regular.woff +0 -0
  67. package/dist/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  68. package/dist/fonts/KaTeX_Size3-Regular.ttf +0 -0
  69. package/dist/fonts/KaTeX_Size3-Regular.woff +0 -0
  70. package/dist/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  71. package/dist/fonts/KaTeX_Size4-Regular.ttf +0 -0
  72. package/dist/fonts/KaTeX_Size4-Regular.woff +0 -0
  73. package/dist/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  74. package/dist/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  75. package/dist/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  76. package/dist/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  77. package/dist/katex.css +25 -2
  78. package/dist/katex.js +1140 -1257
  79. package/dist/katex.min.css +1 -1
  80. package/dist/katex.min.js +1 -1
  81. package/dist/katex.mjs +1119 -1229
  82. package/package.json +9 -9
  83. package/src/MacroExpander.js +39 -10
  84. package/src/Parser.js +28 -24
  85. package/src/Settings.js +19 -0
  86. package/src/Token.js +2 -0
  87. package/src/buildCommon.js +16 -82
  88. package/src/buildHTML.js +29 -30
  89. package/src/buildMathML.js +5 -1
  90. package/src/buildTree.js +3 -2
  91. package/src/defineFunction.js +1 -4
  92. package/src/delimiter.js +14 -3
  93. package/src/environments/array.js +11 -9
  94. package/src/functions/accent.js +6 -7
  95. package/src/functions/accentunder.js +2 -2
  96. package/src/functions/def.js +184 -0
  97. package/src/functions/delimsizing.js +5 -4
  98. package/src/functions/font.js +1 -1
  99. package/src/functions/genfrac.js +8 -15
  100. package/src/functions/horizBrace.js +6 -7
  101. package/src/functions/html.js +102 -0
  102. package/src/functions/lap.js +4 -7
  103. package/src/functions/op.js +5 -6
  104. package/src/functions/operatorname.js +5 -6
  105. package/src/functions/supsub.js +3 -5
  106. package/src/functions/utils/assembleSupSub.js +0 -2
  107. package/src/functions.js +2 -0
  108. package/src/katex.less +29 -1
  109. package/src/macros.js +97 -56
  110. package/src/parseNode.js +14 -56
  111. package/src/svgGeometry.js +4 -0
  112. package/src/symbols.js +36 -53
  113. package/src/unicodeAccents.js +3 -1
  114. package/src/unicodeSymbols.js +30 -321
  115. package/src/wide-character.js +2 -2
  116. package/src/unicodeMake.js +0 -70
package/src/functions.js CHANGED
@@ -13,6 +13,7 @@ import "./functions/arrow";
13
13
  import "./functions/char";
14
14
  import "./functions/color";
15
15
  import "./functions/cr";
16
+ import "./functions/def";
16
17
  import "./functions/delimsizing";
17
18
  import "./functions/enclose";
18
19
  import "./functions/environment";
@@ -20,6 +21,7 @@ import "./functions/font";
20
21
  import "./functions/genfrac";
21
22
  import "./functions/horizBrace";
22
23
  import "./functions/href";
24
+ import "./functions/html";
23
25
  import "./functions/htmlmathml";
24
26
  import "./functions/includegraphics";
25
27
  import "./functions/kern";
package/src/katex.less CHANGED
@@ -17,6 +17,9 @@
17
17
  // Prevent a rendering bug that misplaces \vec in Chrome.
18
18
  text-rendering: auto;
19
19
 
20
+ // Insulate fraction bars and rules from CSS that sets border-color.
21
+ border-color: currentColor;
22
+
20
23
  // Prevent background resetting on elements in Windows's high-contrast
21
24
  // mode, while still allowing background/foreground setting on root .katex
22
25
  * { -ms-high-contrast-adjust: none !important; }
@@ -81,7 +84,7 @@
81
84
  }
82
85
 
83
86
  // Math fonts.
84
- .mathdefault {
87
+ .mathnormal {
85
88
  font-family: KaTeX_Math;
86
89
  font-style: italic;
87
90
  }
@@ -168,6 +171,7 @@
168
171
  .vlist-t {
169
172
  display: inline-table;
170
173
  table-layout: fixed;
174
+ border-collapse: collapse;
171
175
  }
172
176
 
173
177
  .vlist-r {
@@ -214,6 +218,29 @@
214
218
  min-width: 2px;
215
219
  }
216
220
 
221
+ .vbox {
222
+ display: -ms-inline-flexbox;
223
+ display: inline-flex;
224
+ -ms-flex-direction: column;
225
+ flex-direction: column;
226
+ align-items: baseline;
227
+ }
228
+
229
+ .hbox {
230
+ display: -ms-inline-flexbox;
231
+ display: inline-flex;
232
+ -ms-flex-direction: row;
233
+ flex-direction: row;
234
+ width: 100%;
235
+ }
236
+
237
+ .thinbox {
238
+ display: inline-flex;
239
+ flex-direction: row;
240
+ width: 0;
241
+ max-width: 0; // necessary for Safari
242
+ }
243
+
217
244
  .msupsub {
218
245
  text-align: left;
219
246
  }
@@ -594,4 +621,5 @@
594
621
  // Flush-left display math
595
622
  .katex-display.fleqn > .katex {
596
623
  text-align: left;
624
+ padding-left: 2em;
597
625
  }
package/src/macros.js CHANGED
@@ -5,6 +5,7 @@
5
5
  */
6
6
 
7
7
  import fontMetricsData from "../submodules/katex-fonts/fontMetricsData";
8
+ import functions from "./functions";
8
9
  import symbols from "./symbols";
9
10
  import utils from "./utils";
10
11
  import {Token} from "./Token";
@@ -36,6 +37,16 @@ export interface MacroContextInterface {
36
37
  */
37
38
  popToken(): Token;
38
39
 
40
+ /**
41
+ * Consume all following space tokens, without expansion.
42
+ */
43
+ consumeSpaces(): void;
44
+
45
+ /**
46
+ * Expand the next token only once if possible.
47
+ */
48
+ expandOnce(expandableOnly?: boolean): Token | Token[];
49
+
39
50
  /**
40
51
  * Expand the next token only once (if possible), and return the resulting
41
52
  * top token on the stack (without removing anything from the stack).
@@ -73,10 +84,19 @@ export interface MacroContextInterface {
73
84
  * `implicitCommands`.
74
85
  */
75
86
  isDefined(name: string): boolean;
87
+
88
+ /**
89
+ * Determine whether a command is expandable.
90
+ */
91
+ isExpandable(name: string): boolean;
76
92
  }
77
93
 
78
94
  /** Macro tokens (in reverse order). */
79
- export type MacroExpansion = {tokens: Token[], numArgs: number};
95
+ export type MacroExpansion = {
96
+ tokens: Token[],
97
+ numArgs: number,
98
+ unexpandable?: boolean, // used in \let
99
+ };
80
100
 
81
101
  export type MacroDefinition = string | MacroExpansion |
82
102
  (MacroContextInterface => (string | MacroExpansion));
@@ -93,6 +113,29 @@ export function defineMacro(name: string, body: MacroDefinition) {
93
113
  //////////////////////////////////////////////////////////////////////
94
114
  // macro tools
95
115
 
116
+ defineMacro("\\noexpand", function(context) {
117
+ // The expansion is the token itself; but that token is interpreted
118
+ // as if its meaning were ‘\relax’ if it is a control sequence that
119
+ // would ordinarily be expanded by TeX’s expansion rules.
120
+ const t = context.popToken();
121
+ if (context.isExpandable(t.text)) {
122
+ t.noexpand = true;
123
+ t.treatAsRelax = true;
124
+ }
125
+ return {tokens: [t], numArgs: 0};
126
+ });
127
+
128
+ defineMacro("\\expandafter", function(context) {
129
+ // TeX first reads the token that comes immediately after \expandafter,
130
+ // without expanding it; let’s call this token t. Then TeX reads the
131
+ // token that comes after t (and possibly more tokens, if that token
132
+ // has an argument), replacing it by its expansion. Finally TeX puts
133
+ // t back in front of that expansion.
134
+ const t = context.popToken();
135
+ context.expandOnce(true); // expand only an expandable token
136
+ return {tokens: [t], numArgs: 0};
137
+ });
138
+
96
139
  // LaTeX's \@firstoftwo{#1}{#2} expands to #1, skipping #2
97
140
  // TeX source: \long\def\@firstoftwo#1#2{#1}
98
141
  defineMacro("\\@firstoftwo", function(context) {
@@ -108,10 +151,12 @@ defineMacro("\\@secondoftwo", function(context) {
108
151
  });
109
152
 
110
153
  // LaTeX's \@ifnextchar{#1}{#2}{#3} looks ahead to the next (unexpanded)
111
- // symbol. If it matches #1, then the macro expands to #2; otherwise, #3.
112
- // Note, however, that it does not consume the next symbol in either case.
154
+ // symbol that isn't a space, consuming any spaces but not consuming the
155
+ // first nonspace character. If that nonspace character matches #1, then
156
+ // the macro expands to #2; otherwise, it expands to #3.
113
157
  defineMacro("\\@ifnextchar", function(context) {
114
158
  const args = context.consumeArgs(3); // symbol, if, else
159
+ context.consumeSpaces();
115
160
  const nextToken = context.future();
116
161
  if (args[0].length === 1 && args[0][0].text === nextToken.text) {
117
162
  return {tokens: args[1], numArgs: 0};
@@ -191,59 +236,6 @@ defineMacro("\\char", function(context) {
191
236
  return `\\@char{${number}}`;
192
237
  });
193
238
 
194
- // Basic support for macro definitions:
195
- // \def\macro{expansion}
196
- // \def\macro#1{expansion}
197
- // \def\macro#1#2{expansion}
198
- // \def\macro#1#2#3#4#5#6#7#8#9{expansion}
199
- // Also the \gdef and \global\def equivalents
200
- const def = (context, global: boolean) => {
201
- let arg = context.consumeArgs(1)[0];
202
- if (arg.length !== 1) {
203
- throw new ParseError("\\gdef's first argument must be a macro name");
204
- }
205
- const name = arg[0].text;
206
- // Count argument specifiers, and check they are in the order #1 #2 ...
207
- let numArgs = 0;
208
- arg = context.consumeArgs(1)[0];
209
- while (arg.length === 1 && arg[0].text === "#") {
210
- arg = context.consumeArgs(1)[0];
211
- if (arg.length !== 1) {
212
- throw new ParseError(`Invalid argument number length "${arg.length}"`);
213
- }
214
- if (!(/^[1-9]$/.test(arg[0].text))) {
215
- throw new ParseError(`Invalid argument number "${arg[0].text}"`);
216
- }
217
- numArgs++;
218
- if (parseInt(arg[0].text) !== numArgs) {
219
- throw new ParseError(`Argument number "${arg[0].text}" out of order`);
220
- }
221
- arg = context.consumeArgs(1)[0];
222
- }
223
- // Final arg is the expansion of the macro
224
- context.macros.set(name, {
225
- tokens: arg,
226
- numArgs,
227
- }, global);
228
- return '';
229
- };
230
- defineMacro("\\gdef", (context) => def(context, true));
231
- defineMacro("\\def", (context) => def(context, false));
232
- defineMacro("\\global", (context) => {
233
- const next = context.consumeArgs(1)[0];
234
- if (next.length !== 1) {
235
- throw new ParseError("Invalid command after \\global");
236
- }
237
- const command = next[0].text;
238
- // TODO: Should expand command
239
- if (command === "\\def") {
240
- // \global\def is equivalent to \gdef
241
- return def(context, true);
242
- } else {
243
- throw new ParseError(`Invalid command '${command}' after \\global`);
244
- }
245
- });
246
-
247
239
  // \newcommand{\macro}[args]{definition}
248
240
  // \renewcommand{\macro}[args]{definition}
249
241
  // TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
@@ -293,6 +285,28 @@ defineMacro("\\newcommand", (context) => newcommand(context, false, true));
293
285
  defineMacro("\\renewcommand", (context) => newcommand(context, true, false));
294
286
  defineMacro("\\providecommand", (context) => newcommand(context, true, true));
295
287
 
288
+ // terminal (console) tools
289
+ defineMacro("\\message", (context) => {
290
+ const arg = context.consumeArgs(1)[0];
291
+ // eslint-disable-next-line no-console
292
+ console.log(arg.reverse().map(token => token.text).join(""));
293
+ return '';
294
+ });
295
+ defineMacro("\\errmessage", (context) => {
296
+ const arg = context.consumeArgs(1)[0];
297
+ // eslint-disable-next-line no-console
298
+ console.error(arg.reverse().map(token => token.text).join(""));
299
+ return '';
300
+ });
301
+ defineMacro("\\show", (context) => {
302
+ const tok = context.popToken();
303
+ const name = tok.text;
304
+ // eslint-disable-next-line no-console
305
+ console.log(tok, context.macros.get(name), functions[name],
306
+ symbols.math[name], symbols.text[name]);
307
+ return '';
308
+ });
309
+
296
310
  //////////////////////////////////////////////////////////////////////
297
311
  // Grouping
298
312
  // \let\bgroup={ \let\egroup=}
@@ -398,6 +412,13 @@ defineMacro("\u00A9", "\\copyright");
398
412
  defineMacro("\u00AE", "\\textregistered");
399
413
  defineMacro("\uFE0F", "\\textregistered");
400
414
 
415
+ // The KaTeX fonts have corners at codepoints that don't match Unicode.
416
+ // For MathML purposes, use the Unicode code point.
417
+ defineMacro("\\ulcorner", "\\html@mathml{\\@ulcorner}{\\mathop{\\char\"231c}}");
418
+ defineMacro("\\urcorner", "\\html@mathml{\\@urcorner}{\\mathop{\\char\"231d}}");
419
+ defineMacro("\\llcorner", "\\html@mathml{\\@llcorner}{\\mathop{\\char\"231e}}");
420
+ defineMacro("\\lrcorner", "\\html@mathml{\\@lrcorner}{\\mathop{\\char\"231f}}");
421
+
401
422
  //////////////////////////////////////////////////////////////////////
402
423
  // LaTeX_2ε
403
424
 
@@ -834,6 +855,8 @@ defineMacro("\\varsubsetneq", "\\html@mathml{\\@varsubsetneq}{⊊}");
834
855
  defineMacro("\\varsubsetneqq", "\\html@mathml{\\@varsubsetneqq}{⫋}");
835
856
  defineMacro("\\varsupsetneq", "\\html@mathml{\\@varsupsetneq}{⊋}");
836
857
  defineMacro("\\varsupsetneqq", "\\html@mathml{\\@varsupsetneqq}{⫌}");
858
+ defineMacro("\\imath", "\\html@mathml{\\@imath}{\u0131}");
859
+ defineMacro("\\jmath", "\\html@mathml{\\@jmath}{\u0237}");
837
860
 
838
861
  //////////////////////////////////////////////////////////////////////
839
862
  // stmaryrd and semantic
@@ -864,6 +887,14 @@ defineMacro("\u2984", "\\rBrace"); // blackboard bold }
864
887
  // TODO: Create variable sized versions of the last two items. I believe that
865
888
  // will require new font glyphs.
866
889
 
890
+ // The stmaryrd function `\minuso` provides a "Plimsoll" symbol that
891
+ // superimposes the characters \circ and \mathminus. Used in chemistry.
892
+ defineMacro("\\minuso", "\\mathbin{\\html@mathml{" +
893
+ "{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}" +
894
+ "{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}" +
895
+ "{\\char`⦵}}");
896
+ defineMacro("⦵", "\\minuso");
897
+
867
898
  //////////////////////////////////////////////////////////////////////
868
899
  // texvc.sty
869
900
 
@@ -946,6 +977,16 @@ defineMacro("\\argmin", "\\DOTSB\\operatorname*{arg\\,min}");
946
977
  defineMacro("\\argmax", "\\DOTSB\\operatorname*{arg\\,max}");
947
978
  defineMacro("\\plim", "\\DOTSB\\mathop{\\operatorname{plim}}\\limits");
948
979
 
980
+ //////////////////////////////////////////////////////////////////////
981
+ // braket.sty
982
+ // http://ctan.math.washington.edu/tex-archive/macros/latex/contrib/braket/braket.pdf
983
+
984
+ defineMacro("\\bra", "\\mathinner{\\langle{#1}|}");
985
+ defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
986
+ defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
987
+ defineMacro("\\Bra", "\\left\\langle#1\\right|");
988
+ defineMacro("\\Ket", "\\left|#1\\right\\rangle");
989
+
949
990
  // Custom Khan Academy colors, should be moved to an optional package
950
991
  defineMacro("\\blue", "\\textcolor{##6495ed}{#1}");
951
992
  defineMacro("\\orange", "\\textcolor{##ffa500}{#1}");
package/src/parseNode.js CHANGED
@@ -270,6 +270,13 @@ type ParseNodeTypes = {
270
270
  href: string,
271
271
  body: AnyParseNode[],
272
272
  |},
273
+ "html": {|
274
+ type: "html",
275
+ mode: Mode,
276
+ loc?: ?SourceLocation,
277
+ attributes: {[string]: string},
278
+ body: AnyParseNode[],
279
+ |},
273
280
  "htmlmathml": {|
274
281
  type: "htmlmathml",
275
282
  mode: Mode,
@@ -295,6 +302,11 @@ type ParseNodeTypes = {
295
302
  size?: Measurement,
296
303
  token: ?Token,
297
304
  |},
305
+ "internal": {|
306
+ type: "internal",
307
+ mode: Mode,
308
+ loc?: ?SourceLocation,
309
+ |},
298
310
  "kern": {|
299
311
  type: "kern",
300
312
  mode: Mode,
@@ -441,66 +453,12 @@ export function assertNodeType<NODETYPE: NodeType>(
441
453
  node: ?AnyParseNode,
442
454
  type: NODETYPE,
443
455
  ): ParseNode<NODETYPE> {
444
- const typedNode = checkNodeType(node, type);
445
- if (!typedNode) {
456
+ if (!node || node.type !== type) {
446
457
  throw new Error(
447
458
  `Expected node of type ${type}, but got ` +
448
459
  (node ? `node of type ${node.type}` : String(node)));
449
460
  }
450
- // $FlowFixMe: Unsure why.
451
- return typedNode;
452
- }
453
-
454
- /**
455
- * Returns the node more strictly typed iff it is of the given type. Otherwise,
456
- * returns null.
457
- */
458
- export function checkNodeType<NODETYPE: NodeType>(
459
- node: ?AnyParseNode,
460
- type: NODETYPE,
461
- ): ?ParseNode<NODETYPE> {
462
- if (node && node.type === type) {
463
- // The definition of ParseNode<TYPE> doesn't communicate to flow that
464
- // `type: TYPE` (as that's not explicitly mentioned anywhere), though that
465
- // happens to be true for all our value types.
466
- // $FlowFixMe
467
- return node;
468
- }
469
- return null;
470
- }
471
-
472
- /**
473
- * Asserts that the node is of the given type and returns it with stricter
474
- * typing. Throws if the node's type does not match.
475
- */
476
- export function assertAtomFamily(
477
- node: ?AnyParseNode,
478
- family: Atom,
479
- ): ParseNode<"atom"> {
480
- const typedNode = checkAtomFamily(node, family);
481
- if (!typedNode) {
482
- throw new Error(
483
- `Expected node of type "atom" and family "${family}", but got ` +
484
- (node ?
485
- (node.type === "atom" ?
486
- `atom of family ${node.family}` :
487
- `node of type ${node.type}`) :
488
- String(node)));
489
- }
490
- return typedNode;
491
- }
492
-
493
- /**
494
- * Returns the node more strictly typed iff it is of the given type. Otherwise,
495
- * returns null.
496
- */
497
- export function checkAtomFamily(
498
- node: ?AnyParseNode,
499
- family: Atom,
500
- ): ?ParseNode<"atom"> {
501
- return node && node.type === "atom" && node.family === family ?
502
- node :
503
- null;
461
+ return node;
504
462
  }
505
463
 
506
464
  /**
@@ -147,6 +147,10 @@ export const sqrtPath = function(
147
147
  };
148
148
 
149
149
  export const path: {[string]: string} = {
150
+ // Two paths that cover gaps in built-up parentheses.
151
+ leftParenInner: `M291 0 H417 V300 H291 z`,
152
+ rightParenInner: `M457 0 H583 V300 H457 z`,
153
+
150
154
  // The doubleleftarrow geometry is from glyph U+21D0 in the font KaTeX Main
151
155
  doubleleftarrow: `M262 157
152
156
  l10-10c34-36 62.7-77 86-123 3.3-8 5-13.3 5-16 0-5.3-6.7-8-20-8-7.3
package/src/symbols.js CHANGED
@@ -287,8 +287,9 @@ defineSymbol(math, ams, textord, "\u29eb", "\\blacklozenge");
287
287
  defineSymbol(math, ams, textord, "\u2605", "\\bigstar");
288
288
  defineSymbol(math, ams, textord, "\u2222", "\\sphericalangle", true);
289
289
  defineSymbol(math, ams, textord, "\u2201", "\\complement", true);
290
- // unicode-math maps U+F0 (ð) to \matheth. We map to AMS function \eth
290
+ // unicode-math maps U+F0 to \matheth. We map to AMS function \eth
291
291
  defineSymbol(math, ams, textord, "\u00f0", "\\eth", true);
292
+ defineSymbol(text, main, textord, "\u00f0", "\u00f0");
292
293
  defineSymbol(math, ams, textord, "\u2571", "\\diagup");
293
294
  defineSymbol(math, ams, textord, "\u2572", "\\diagdown");
294
295
  defineSymbol(math, ams, textord, "\u25a1", "\\square");
@@ -310,10 +311,10 @@ defineSymbol(math, ams, textord, "\u03dd", "\\digamma", true);
310
311
  defineSymbol(math, ams, textord, "\u03f0", "\\varkappa");
311
312
 
312
313
  // AMS Delimiters
313
- defineSymbol(math, ams, open, "\u250c", "\\ulcorner", true);
314
- defineSymbol(math, ams, close, "\u2510", "\\urcorner", true);
315
- defineSymbol(math, ams, open, "\u2514", "\\llcorner", true);
316
- defineSymbol(math, ams, close, "\u2518", "\\lrcorner", true);
314
+ defineSymbol(math, ams, open, "\u250c", "\\@ulcorner", true);
315
+ defineSymbol(math, ams, close, "\u2510", "\\@urcorner", true);
316
+ defineSymbol(math, ams, open, "\u2514", "\\@llcorner", true);
317
+ defineSymbol(math, ams, close, "\u2518", "\\@lrcorner", true);
317
318
 
318
319
  // AMS Binary Relations
319
320
  defineSymbol(math, ams, rel, "\u2266", "\\leqq", true);
@@ -545,28 +546,22 @@ defineSymbol(math, main, bin, "\u2228", "\\lor");
545
546
  defineSymbol(math, main, bin, "\u2227", "\\wedge", true);
546
547
  defineSymbol(math, main, bin, "\u2228", "\\vee", true);
547
548
  defineSymbol(math, main, textord, "\u221a", "\\surd");
548
- defineSymbol(math, main, open, "(", "(");
549
- defineSymbol(math, main, open, "[", "[");
550
549
  defineSymbol(math, main, open, "\u27e8", "\\langle", true);
551
550
  defineSymbol(math, main, open, "\u2223", "\\lvert");
552
551
  defineSymbol(math, main, open, "\u2225", "\\lVert");
553
- defineSymbol(math, main, close, ")", ")");
554
- defineSymbol(math, main, close, "]", "]");
555
552
  defineSymbol(math, main, close, "?", "?");
556
553
  defineSymbol(math, main, close, "!", "!");
557
554
  defineSymbol(math, main, close, "\u27e9", "\\rangle", true);
558
555
  defineSymbol(math, main, close, "\u2223", "\\rvert");
559
556
  defineSymbol(math, main, close, "\u2225", "\\rVert");
560
557
  defineSymbol(math, main, rel, "=", "=");
561
- defineSymbol(math, main, rel, "<", "<");
562
- defineSymbol(math, main, rel, ">", ">");
563
558
  defineSymbol(math, main, rel, ":", ":");
564
559
  defineSymbol(math, main, rel, "\u2248", "\\approx", true);
565
560
  defineSymbol(math, main, rel, "\u2245", "\\cong", true);
566
561
  defineSymbol(math, main, rel, "\u2265", "\\ge");
567
562
  defineSymbol(math, main, rel, "\u2265", "\\geq", true);
568
563
  defineSymbol(math, main, rel, "\u2190", "\\gets");
569
- defineSymbol(math, main, rel, ">", "\\gt");
564
+ defineSymbol(math, main, rel, ">", "\\gt", true);
570
565
  defineSymbol(math, main, rel, "\u2208", "\\in", true);
571
566
  defineSymbol(math, main, rel, "\ue020", "\\@not");
572
567
  defineSymbol(math, main, rel, "\u2282", "\\subset", true);
@@ -579,7 +574,7 @@ defineSymbol(math, main, rel, "\u22a8", "\\models");
579
574
  defineSymbol(math, main, rel, "\u2190", "\\leftarrow", true);
580
575
  defineSymbol(math, main, rel, "\u2264", "\\le");
581
576
  defineSymbol(math, main, rel, "\u2264", "\\leq", true);
582
- defineSymbol(math, main, rel, "<", "\\lt");
577
+ defineSymbol(math, main, rel, "<", "\\lt", true);
583
578
  defineSymbol(math, main, rel, "\u2192", "\\rightarrow", true);
584
579
  defineSymbol(math, main, rel, "\u2192", "\\to");
585
580
  defineSymbol(math, ams, rel, "\u2271", "\\ngeq", true);
@@ -590,6 +585,7 @@ defineSymbol(math, main, spacing, "\u00a0", "\\space");
590
585
  // Ref: LaTeX Source 2e: \DeclareRobustCommand{\nobreakspace}{%
591
586
  defineSymbol(math, main, spacing, "\u00a0", "\\nobreakspace");
592
587
  defineSymbol(text, main, spacing, "\u00a0", "\\ ");
588
+ defineSymbol(text, main, spacing, "\u00a0", " ");
593
589
  defineSymbol(text, main, spacing, "\u00a0", "~");
594
590
  defineSymbol(text, main, spacing, "\u00a0", "\\space");
595
591
  defineSymbol(text, main, spacing, "\u00a0", "\\nobreakspace");
@@ -621,14 +617,14 @@ defineSymbol(text, main, textord, "}", "\\}");
621
617
  defineSymbol(text, main, textord, "}", "\\textbraceright");
622
618
  defineSymbol(math, main, open, "{", "\\lbrace");
623
619
  defineSymbol(math, main, close, "}", "\\rbrace");
624
- defineSymbol(math, main, open, "[", "\\lbrack");
625
- defineSymbol(text, main, textord, "[", "\\lbrack");
626
- defineSymbol(math, main, close, "]", "\\rbrack");
627
- defineSymbol(text, main, textord, "]", "\\rbrack");
628
- defineSymbol(math, main, open, "(", "\\lparen");
629
- defineSymbol(math, main, close, ")", "\\rparen");
630
- defineSymbol(text, main, textord, "<", "\\textless"); // in T1 fontenc
631
- defineSymbol(text, main, textord, ">", "\\textgreater"); // in T1 fontenc
620
+ defineSymbol(math, main, open, "[", "\\lbrack", true);
621
+ defineSymbol(text, main, textord, "[", "\\lbrack", true);
622
+ defineSymbol(math, main, close, "]", "\\rbrack", true);
623
+ defineSymbol(text, main, textord, "]", "\\rbrack", true);
624
+ defineSymbol(math, main, open, "(", "\\lparen", true);
625
+ defineSymbol(math, main, close, ")", "\\rparen", true);
626
+ defineSymbol(text, main, textord, "<", "\\textless", true); // in T1 fontenc
627
+ defineSymbol(text, main, textord, ">", "\\textgreater", true); // in T1 fontenc
632
628
  defineSymbol(math, main, open, "\u230a", "\\lfloor", true);
633
629
  defineSymbol(math, main, close, "\u230b", "\\rfloor", true);
634
630
  defineSymbol(math, main, open, "\u2308", "\\lceil", true);
@@ -636,7 +632,7 @@ defineSymbol(math, main, close, "\u2309", "\\rceil", true);
636
632
  defineSymbol(math, main, textord, "\\", "\\backslash");
637
633
  defineSymbol(math, main, textord, "\u2223", "|");
638
634
  defineSymbol(math, main, textord, "\u2223", "\\vert");
639
- defineSymbol(text, main, textord, "|", "\\textbar"); // in T1 fontenc
635
+ defineSymbol(text, main, textord, "|", "\\textbar", true); // in T1 fontenc
640
636
  defineSymbol(math, main, textord, "\u2225", "\\|");
641
637
  defineSymbol(math, main, textord, "\u2225", "\\Vert");
642
638
  defineSymbol(text, main, textord, "\u2225", "\\textbardbl");
@@ -665,8 +661,6 @@ defineSymbol(math, main, op, "\u2a02", "\\bigotimes");
665
661
  defineSymbol(math, main, op, "\u2a01", "\\bigoplus");
666
662
  defineSymbol(math, main, op, "\u2a00", "\\bigodot");
667
663
  defineSymbol(math, main, op, "\u222e", "\\oint");
668
- defineSymbol(math, main, op, "\u222f", "\\oiint");
669
- defineSymbol(math, main, op, "\u2230", "\\oiiint");
670
664
  defineSymbol(math, main, op, "\u2a06", "\\bigsqcup");
671
665
  defineSymbol(math, main, op, "\u222b", "\\smallint");
672
666
  defineSymbol(text, main, inner, "\u2026", "\\textellipsis");
@@ -687,13 +681,15 @@ defineSymbol(math, main, accent, "\u005e", "\\hat");
687
681
  defineSymbol(math, main, accent, "\u20d7", "\\vec");
688
682
  defineSymbol(math, main, accent, "\u02d9", "\\dot");
689
683
  defineSymbol(math, main, accent, "\u02da", "\\mathring");
690
- defineSymbol(math, main, mathord, "\u0131", "\\imath", true);
691
- defineSymbol(math, main, mathord, "\u0237", "\\jmath", true);
684
+ // \imath and \jmath should be invariant to \mathrm, \mathbf, etc., so use PUA
685
+ defineSymbol(math, main, mathord, "\ue131", "\\@imath");
686
+ defineSymbol(math, main, mathord, "\ue237", "\\@jmath");
687
+ defineSymbol(math, main, textord, "\u0131", "\u0131");
688
+ defineSymbol(math, main, textord, "\u0237", "\u0237");
692
689
  defineSymbol(text, main, textord, "\u0131", "\\i", true);
693
690
  defineSymbol(text, main, textord, "\u0237", "\\j", true);
694
691
  defineSymbol(text, main, textord, "\u00df", "\\ss", true);
695
692
  defineSymbol(text, main, textord, "\u00e6", "\\ae", true);
696
- defineSymbol(text, main, textord, "\u00e6", "\\ae", true);
697
693
  defineSymbol(text, main, textord, "\u0153", "\\oe", true);
698
694
  defineSymbol(text, main, textord, "\u00f8", "\\o", true);
699
695
  defineSymbol(text, main, textord, "\u00c6", "\\AE", true);
@@ -720,17 +716,17 @@ export const ligatures = {
720
716
  "''": true,
721
717
  };
722
718
 
723
- defineSymbol(text, main, textord, "\u2013", "--");
719
+ defineSymbol(text, main, textord, "\u2013", "--", true);
724
720
  defineSymbol(text, main, textord, "\u2013", "\\textendash");
725
- defineSymbol(text, main, textord, "\u2014", "---");
721
+ defineSymbol(text, main, textord, "\u2014", "---", true);
726
722
  defineSymbol(text, main, textord, "\u2014", "\\textemdash");
727
- defineSymbol(text, main, textord, "\u2018", "`");
723
+ defineSymbol(text, main, textord, "\u2018", "`", true);
728
724
  defineSymbol(text, main, textord, "\u2018", "\\textquoteleft");
729
- defineSymbol(text, main, textord, "\u2019", "'");
725
+ defineSymbol(text, main, textord, "\u2019", "'", true);
730
726
  defineSymbol(text, main, textord, "\u2019", "\\textquoteright");
731
- defineSymbol(text, main, textord, "\u201c", "``");
727
+ defineSymbol(text, main, textord, "\u201c", "``", true);
732
728
  defineSymbol(text, main, textord, "\u201c", "\\textquotedblleft");
733
- defineSymbol(text, main, textord, "\u201d", "''");
729
+ defineSymbol(text, main, textord, "\u201d", "''", true);
734
730
  defineSymbol(text, main, textord, "\u201d", "\\textquotedblright");
735
731
  // \degree from gensymb package
736
732
  defineSymbol(math, main, textord, "\u00b0", "\\degree", true);
@@ -738,18 +734,14 @@ defineSymbol(text, main, textord, "\u00b0", "\\degree");
738
734
  // \textdegree from inputenc package
739
735
  defineSymbol(text, main, textord, "\u00b0", "\\textdegree", true);
740
736
  // TODO: In LaTeX, \pounds can generate a different character in text and math
741
- // mode, but among our fonts, only Main-Italic defines this character "163".
742
- defineSymbol(math, main, mathord, "\u00a3", "\\pounds");
743
- defineSymbol(math, main, mathord, "\u00a3", "\\mathsterling", true);
744
- defineSymbol(text, main, mathord, "\u00a3", "\\pounds");
745
- defineSymbol(text, main, mathord, "\u00a3", "\\textsterling", true);
737
+ // mode, but among our fonts, only Main-Regular defines this character "163".
738
+ defineSymbol(math, main, textord, "\u00a3", "\\pounds");
739
+ defineSymbol(math, main, textord, "\u00a3", "\\mathsterling", true);
740
+ defineSymbol(text, main, textord, "\u00a3", "\\pounds");
741
+ defineSymbol(text, main, textord, "\u00a3", "\\textsterling", true);
746
742
  defineSymbol(math, ams, textord, "\u2720", "\\maltese");
747
743
  defineSymbol(text, ams, textord, "\u2720", "\\maltese");
748
744
 
749
- defineSymbol(text, main, spacing, "\u00a0", "\\ ");
750
- defineSymbol(text, main, spacing, "\u00a0", " ");
751
- defineSymbol(text, main, spacing, "\u00a0", "~");
752
-
753
745
  // There are lots of symbols which are the same, so we add them in afterwards.
754
746
  // All of these are textords in math mode
755
747
  const mathTextSymbols = "0123456789/@.\"";
@@ -759,7 +751,7 @@ for (let i = 0; i < mathTextSymbols.length; i++) {
759
751
  }
760
752
 
761
753
  // All of these are textords in text mode
762
- const textSymbols = "0123456789!@*()-=+[]<>|\";:?/.,";
754
+ const textSymbols = "0123456789!@*()-=+\";:?/.,";
763
755
  for (let i = 0; i < textSymbols.length; i++) {
764
756
  const ch = textSymbols.charAt(i);
765
757
  defineSymbol(text, main, textord, ch, ch);
@@ -879,18 +871,9 @@ for (let i = 0; i < 10; i++) {
879
871
  // but they are not actually in the font, nor are they supported by the
880
872
  // Unicode accent mechanism, so they fall back to Times font and look ugly.
881
873
  // TODO(edemaine): Fix this.
882
- export const extraLatin = "ÇÐÞçþ";
874
+ export const extraLatin = "\u00c7\u00d0\u00de\u00e7\u00fe";
883
875
  for (let i = 0; i < extraLatin.length; i++) {
884
876
  const ch = extraLatin.charAt(i);
885
877
  defineSymbol(math, main, mathord, ch, ch);
886
878
  defineSymbol(text, main, textord, ch, ch);
887
879
  }
888
- defineSymbol(text, main, textord, "ð", "ð");
889
-
890
- // Unicode versions of existing characters
891
- defineSymbol(text, main, textord, "\u2013", "–");
892
- defineSymbol(text, main, textord, "\u2014", "—");
893
- defineSymbol(text, main, textord, "\u2018", "‘");
894
- defineSymbol(text, main, textord, "\u2019", "’");
895
- defineSymbol(text, main, textord, "\u201c", "“");
896
- defineSymbol(text, main, textord, "\u201d", "”");
@@ -1,6 +1,8 @@
1
1
  // Mapping of Unicode accent characters to their LaTeX equivalent in text and
2
2
  // math mode (when they exist).
3
- export default {
3
+ // This exports a CommonJS module, allowing to be required in unicodeSymbols
4
+ // without transpiling.
5
+ module.exports = {
4
6
  '\u0301': {text: "\\'", math: '\\acute'},
5
7
  '\u0300': {text: '\\`', math: '\\grave'},
6
8
  '\u0308': {text: '\\"', math: '\\ddot'},