You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18049 lines
580 KiB

  1. /**
  2. * Lexing or parsing positional information for error reporting.
  3. * This object is immutable.
  4. */
  5. class SourceLocation {
  6. // The + prefix indicates that these fields aren't writeable
  7. // Lexer holding the input string.
  8. // Start offset, zero-based inclusive.
  9. // End offset, zero-based exclusive.
  10. constructor(lexer, start, end) {
  11. this.lexer = void 0;
  12. this.start = void 0;
  13. this.end = void 0;
  14. this.lexer = lexer;
  15. this.start = start;
  16. this.end = end;
  17. }
  18. /**
  19. * Merges two `SourceLocation`s from location providers, given they are
  20. * provided in order of appearance.
  21. * - Returns the first one's location if only the first is provided.
  22. * - Returns a merged range of the first and the last if both are provided
  23. * and their lexers match.
  24. * - Otherwise, returns null.
  25. */
  26. static range(first, second) {
  27. if (!second) {
  28. return first && first.loc;
  29. } else if (!first || !first.loc || !second.loc || first.loc.lexer !== second.loc.lexer) {
  30. return null;
  31. } else {
  32. return new SourceLocation(first.loc.lexer, first.loc.start, second.loc.end);
  33. }
  34. }
  35. }
  36. /**
  37. * Interface required to break circular dependency between Token, Lexer, and
  38. * ParseError.
  39. */
  40. /**
  41. * The resulting token returned from `lex`.
  42. *
  43. * It consists of the token text plus some position information.
  44. * The position information is essentially a range in an input string,
  45. * but instead of referencing the bare input string, we refer to the lexer.
  46. * That way it is possible to attach extra metadata to the input string,
  47. * like for example a file name or similar.
  48. *
  49. * The position information is optional, so it is OK to construct synthetic
  50. * tokens if appropriate. Not providing available position information may
  51. * lead to degraded error reporting, though.
  52. */
  53. class Token {
  54. // don't expand the token
  55. // used in \noexpand
  56. constructor(text, // the text of this token
  57. loc) {
  58. this.text = void 0;
  59. this.loc = void 0;
  60. this.noexpand = void 0;
  61. this.treatAsRelax = void 0;
  62. this.text = text;
  63. this.loc = loc;
  64. }
  65. /**
  66. * Given a pair of tokens (this and endToken), compute a `Token` encompassing
  67. * the whole input range enclosed by these two.
  68. */
  69. range(endToken, // last token of the range, inclusive
  70. text // the text of the newly constructed token
  71. ) {
  72. return new Token(text, SourceLocation.range(this, endToken));
  73. }
  74. }
  75. /**
  76. * This is the ParseError class, which is the main error thrown by KaTeX
  77. * functions when something has gone wrong. This is used to distinguish internal
  78. * errors from errors in the expression that the user provided.
  79. *
  80. * If possible, a caller should provide a Token or ParseNode with information
  81. * about where in the source string the problem occurred.
  82. */
  83. class ParseError {
  84. // Error position based on passed-in Token or ParseNode.
  85. constructor(message, // The error message
  86. token // An object providing position information
  87. ) {
  88. this.position = void 0;
  89. var error = "KaTeX parse error: " + message;
  90. var start;
  91. var loc = token && token.loc;
  92. if (loc && loc.start <= loc.end) {
  93. // If we have the input and a position, make the error a bit fancier
  94. // Get the input
  95. var input = loc.lexer.input; // Prepend some information
  96. start = loc.start;
  97. var end = loc.end;
  98. if (start === input.length) {
  99. error += " at end of input: ";
  100. } else {
  101. error += " at position " + (start + 1) + ": ";
  102. } // Underline token in question using combining underscores
  103. var underlined = input.slice(start, end).replace(/[^]/g, "$&\u0332"); // Extract some context from the input and add it to the error
  104. var left;
  105. if (start > 15) {
  106. left = "…" + input.slice(start - 15, start);
  107. } else {
  108. left = input.slice(0, start);
  109. }
  110. var right;
  111. if (end + 15 < input.length) {
  112. right = input.slice(end, end + 15) + "…";
  113. } else {
  114. right = input.slice(end);
  115. }
  116. error += left + underlined + right;
  117. } // Some hackery to make ParseError a prototype of Error
  118. // See http://stackoverflow.com/a/8460753
  119. var self = new Error(error);
  120. self.name = "ParseError"; // $FlowFixMe
  121. self.__proto__ = ParseError.prototype; // $FlowFixMe
  122. self.position = start;
  123. return self;
  124. }
  125. } // $FlowFixMe More hackery
  126. ParseError.prototype.__proto__ = Error.prototype;
  127. /**
  128. * This file contains a list of utility functions which are useful in other
  129. * files.
  130. */
  131. /**
  132. * Return whether an element is contained in a list
  133. */
  134. var contains = function contains(list, elem) {
  135. return list.indexOf(elem) !== -1;
  136. };
  137. /**
  138. * Provide a default value if a setting is undefined
  139. * NOTE: Couldn't use `T` as the output type due to facebook/flow#5022.
  140. */
  141. var deflt = function deflt(setting, defaultIfUndefined) {
  142. return setting === undefined ? defaultIfUndefined : setting;
  143. }; // hyphenate and escape adapted from Facebook's React under Apache 2 license
  144. var uppercase = /([A-Z])/g;
  145. var hyphenate = function hyphenate(str) {
  146. return str.replace(uppercase, "-$1").toLowerCase();
  147. };
  148. var ESCAPE_LOOKUP = {
  149. "&": "&amp;",
  150. ">": "&gt;",
  151. "<": "&lt;",
  152. "\"": "&quot;",
  153. "'": "&#x27;"
  154. };
  155. var ESCAPE_REGEX = /[&><"']/g;
  156. /**
  157. * Escapes text to prevent scripting attacks.
  158. */
  159. function escape(text) {
  160. return String(text).replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
  161. }
  162. /**
  163. * Sometimes we want to pull out the innermost element of a group. In most
  164. * cases, this will just be the group itself, but when ordgroups and colors have
  165. * a single element, we want to pull that out.
  166. */
  167. var getBaseElem = function getBaseElem(group) {
  168. if (group.type === "ordgroup") {
  169. if (group.body.length === 1) {
  170. return getBaseElem(group.body[0]);
  171. } else {
  172. return group;
  173. }
  174. } else if (group.type === "color") {
  175. if (group.body.length === 1) {
  176. return getBaseElem(group.body[0]);
  177. } else {
  178. return group;
  179. }
  180. } else if (group.type === "font") {
  181. return getBaseElem(group.body);
  182. } else {
  183. return group;
  184. }
  185. };
  186. /**
  187. * TeXbook algorithms often reference "character boxes", which are simply groups
  188. * with a single character in them. To decide if something is a character box,
  189. * we find its innermost group, and see if it is a single character.
  190. */
  191. var isCharacterBox = function isCharacterBox(group) {
  192. var baseElem = getBaseElem(group); // These are all they types of groups which hold single characters
  193. return baseElem.type === "mathord" || baseElem.type === "textord" || baseElem.type === "atom";
  194. };
  195. var assert = function assert(value) {
  196. if (!value) {
  197. throw new Error('Expected non-null, but got ' + String(value));
  198. }
  199. return value;
  200. };
  201. /**
  202. * Return the protocol of a URL, or "_relative" if the URL does not specify a
  203. * protocol (and thus is relative).
  204. */
  205. var protocolFromUrl = function protocolFromUrl(url) {
  206. var protocol = /^\s*([^\\/#]*?)(?::|&#0*58|&#x0*3a)/i.exec(url);
  207. return protocol != null ? protocol[1] : "_relative";
  208. };
  209. var utils = {
  210. contains,
  211. deflt,
  212. escape,
  213. hyphenate,
  214. getBaseElem,
  215. isCharacterBox,
  216. protocolFromUrl
  217. };
  218. /* eslint no-console:0 */
  219. // TODO: automatically generate documentation
  220. // TODO: check all properties on Settings exist
  221. // TODO: check the type of a property on Settings matches
  222. var SETTINGS_SCHEMA = {
  223. displayMode: {
  224. type: "boolean",
  225. description: "Render math in display mode, which puts the math in " + "display style (so \\int and \\sum are large, for example), and " + "centers the math on the page on its own line.",
  226. cli: "-d, --display-mode"
  227. },
  228. output: {
  229. type: {
  230. enum: ["htmlAndMathml", "html", "mathml"]
  231. },
  232. description: "Determines the markup language of the output.",
  233. cli: "-F, --format <type>"
  234. },
  235. leqno: {
  236. type: "boolean",
  237. description: "Render display math in leqno style (left-justified tags)."
  238. },
  239. fleqn: {
  240. type: "boolean",
  241. description: "Render display math flush left."
  242. },
  243. throwOnError: {
  244. type: "boolean",
  245. default: true,
  246. cli: "-t, --no-throw-on-error",
  247. cliDescription: "Render errors (in the color given by --error-color) ins" + "tead of throwing a ParseError exception when encountering an error."
  248. },
  249. errorColor: {
  250. type: "string",
  251. default: "#cc0000",
  252. cli: "-c, --error-color <color>",
  253. cliDescription: "A color string given in the format 'rgb' or 'rrggbb' " + "(no #). This option determines the color of errors rendered by the " + "-t option.",
  254. cliProcessor: color => "#" + color
  255. },
  256. macros: {
  257. type: "object",
  258. cli: "-m, --macro <def>",
  259. cliDescription: "Define custom macro of the form '\\foo:expansion' (use " + "multiple -m arguments for multiple macros).",
  260. cliDefault: [],
  261. cliProcessor: (def, defs) => {
  262. defs.push(def);
  263. return defs;
  264. }
  265. },
  266. minRuleThickness: {
  267. type: "number",
  268. description: "Specifies a minimum thickness, in ems, for fraction lines," + " `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, " + "`\\hdashline`, `\\underline`, `\\overline`, and the borders of " + "`\\fbox`, `\\boxed`, and `\\fcolorbox`.",
  269. processor: t => Math.max(0, t),
  270. cli: "--min-rule-thickness <size>",
  271. cliProcessor: parseFloat
  272. },
  273. colorIsTextColor: {
  274. type: "boolean",
  275. description: "Makes \\color behave like LaTeX's 2-argument \\textcolor, " + "instead of LaTeX's one-argument \\color mode change.",
  276. cli: "-b, --color-is-text-color"
  277. },
  278. strict: {
  279. type: [{
  280. enum: ["warn", "ignore", "error"]
  281. }, "boolean", "function"],
  282. description: "Turn on strict / LaTeX faithfulness mode, which throws an " + "error if the input uses features that are not supported by LaTeX.",
  283. cli: "-S, --strict",
  284. cliDefault: false
  285. },
  286. trust: {
  287. type: ["boolean", "function"],
  288. description: "Trust the input, enabling all HTML features such as \\url.",
  289. cli: "-T, --trust"
  290. },
  291. maxSize: {
  292. type: "number",
  293. default: Infinity,
  294. description: "If non-zero, all user-specified sizes, e.g. in " + "\\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, " + "elements and spaces can be arbitrarily large",
  295. processor: s => Math.max(0, s),
  296. cli: "-s, --max-size <n>",
  297. cliProcessor: parseInt
  298. },
  299. maxExpand: {
  300. type: "number",
  301. default: 1000,
  302. description: "Limit the number of macro expansions to the specified " + "number, to prevent e.g. infinite macro loops. If set to Infinity, " + "the macro expander will try to fully expand as in LaTeX.",
  303. processor: n => Math.max(0, n),
  304. cli: "-e, --max-expand <n>",
  305. cliProcessor: n => n === "Infinity" ? Infinity : parseInt(n)
  306. },
  307. globalGroup: {
  308. type: "boolean",
  309. cli: false
  310. }
  311. };
  312. function getDefaultValue(schema) {
  313. if (schema.default) {
  314. return schema.default;
  315. }
  316. var type = schema.type;
  317. var defaultType = Array.isArray(type) ? type[0] : type;
  318. if (typeof defaultType !== 'string') {
  319. return defaultType.enum[0];
  320. }
  321. switch (defaultType) {
  322. case 'boolean':
  323. return false;
  324. case 'string':
  325. return '';
  326. case 'number':
  327. return 0;
  328. case 'object':
  329. return {};
  330. }
  331. }
  332. /**
  333. * The main Settings object
  334. *
  335. * The current options stored are:
  336. * - displayMode: Whether the expression should be typeset as inline math
  337. * (false, the default), meaning that the math starts in
  338. * \textstyle and is placed in an inline-block); or as display
  339. * math (true), meaning that the math starts in \displaystyle
  340. * and is placed in a block with vertical margin.
  341. */
  342. class Settings {
  343. constructor(options) {
  344. this.displayMode = void 0;
  345. this.output = void 0;
  346. this.leqno = void 0;
  347. this.fleqn = void 0;
  348. this.throwOnError = void 0;
  349. this.errorColor = void 0;
  350. this.macros = void 0;
  351. this.minRuleThickness = void 0;
  352. this.colorIsTextColor = void 0;
  353. this.strict = void 0;
  354. this.trust = void 0;
  355. this.maxSize = void 0;
  356. this.maxExpand = void 0;
  357. this.globalGroup = void 0;
  358. // allow null options
  359. options = options || {};
  360. for (var prop in SETTINGS_SCHEMA) {
  361. if (SETTINGS_SCHEMA.hasOwnProperty(prop)) {
  362. // $FlowFixMe
  363. var schema = SETTINGS_SCHEMA[prop]; // TODO: validate options
  364. // $FlowFixMe
  365. this[prop] = options[prop] !== undefined ? schema.processor ? schema.processor(options[prop]) : options[prop] : getDefaultValue(schema);
  366. }
  367. }
  368. }
  369. /**
  370. * Report nonstrict (non-LaTeX-compatible) input.
  371. * Can safely not be called if `this.strict` is false in JavaScript.
  372. */
  373. reportNonstrict(errorCode, errorMsg, token) {
  374. var strict = this.strict;
  375. if (typeof strict === "function") {
  376. // Allow return value of strict function to be boolean or string
  377. // (or null/undefined, meaning no further processing).
  378. strict = strict(errorCode, errorMsg, token);
  379. }
  380. if (!strict || strict === "ignore") {
  381. return;
  382. } else if (strict === true || strict === "error") {
  383. throw new ParseError("LaTeX-incompatible input and strict mode is set to 'error': " + (errorMsg + " [" + errorCode + "]"), token);
  384. } else if (strict === "warn") {
  385. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to 'warn': " + (errorMsg + " [" + errorCode + "]"));
  386. } else {
  387. // won't happen in type-safe code
  388. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to " + ("unrecognized '" + strict + "': " + errorMsg + " [" + errorCode + "]"));
  389. }
  390. }
  391. /**
  392. * Check whether to apply strict (LaTeX-adhering) behavior for unusual
  393. * input (like `\\`). Unlike `nonstrict`, will not throw an error;
  394. * instead, "error" translates to a return value of `true`, while "ignore"
  395. * translates to a return value of `false`. May still print a warning:
  396. * "warn" prints a warning and returns `false`.
  397. * This is for the second category of `errorCode`s listed in the README.
  398. */
  399. useStrictBehavior(errorCode, errorMsg, token) {
  400. var strict = this.strict;
  401. if (typeof strict === "function") {
  402. // Allow return value of strict function to be boolean or string
  403. // (or null/undefined, meaning no further processing).
  404. // But catch any exceptions thrown by function, treating them
  405. // like "error".
  406. try {
  407. strict = strict(errorCode, errorMsg, token);
  408. } catch (error) {
  409. strict = "error";
  410. }
  411. }
  412. if (!strict || strict === "ignore") {
  413. return false;
  414. } else if (strict === true || strict === "error") {
  415. return true;
  416. } else if (strict === "warn") {
  417. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to 'warn': " + (errorMsg + " [" + errorCode + "]"));
  418. return false;
  419. } else {
  420. // won't happen in type-safe code
  421. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to " + ("unrecognized '" + strict + "': " + errorMsg + " [" + errorCode + "]"));
  422. return false;
  423. }
  424. }
  425. /**
  426. * Check whether to test potentially dangerous input, and return
  427. * `true` (trusted) or `false` (untrusted). The sole argument `context`
  428. * should be an object with `command` field specifying the relevant LaTeX
  429. * command (as a string starting with `\`), and any other arguments, etc.
  430. * If `context` has a `url` field, a `protocol` field will automatically
  431. * get added by this function (changing the specified object).
  432. */
  433. isTrusted(context) {
  434. if (context.url && !context.protocol) {
  435. context.protocol = utils.protocolFromUrl(context.url);
  436. }
  437. var trust = typeof this.trust === "function" ? this.trust(context) : this.trust;
  438. return Boolean(trust);
  439. }
  440. }
  441. /**
  442. * This file contains information and classes for the various kinds of styles
  443. * used in TeX. It provides a generic `Style` class, which holds information
  444. * about a specific style. It then provides instances of all the different kinds
  445. * of styles possible, and provides functions to move between them and get
  446. * information about them.
  447. */
  448. /**
  449. * The main style class. Contains a unique id for the style, a size (which is
  450. * the same for cramped and uncramped version of a style), and a cramped flag.
  451. */
  452. class Style {
  453. constructor(id, size, cramped) {
  454. this.id = void 0;
  455. this.size = void 0;
  456. this.cramped = void 0;
  457. this.id = id;
  458. this.size = size;
  459. this.cramped = cramped;
  460. }
  461. /**
  462. * Get the style of a superscript given a base in the current style.
  463. */
  464. sup() {
  465. return styles[sup[this.id]];
  466. }
  467. /**
  468. * Get the style of a subscript given a base in the current style.
  469. */
  470. sub() {
  471. return styles[sub[this.id]];
  472. }
  473. /**
  474. * Get the style of a fraction numerator given the fraction in the current
  475. * style.
  476. */
  477. fracNum() {
  478. return styles[fracNum[this.id]];
  479. }
  480. /**
  481. * Get the style of a fraction denominator given the fraction in the current
  482. * style.
  483. */
  484. fracDen() {
  485. return styles[fracDen[this.id]];
  486. }
  487. /**
  488. * Get the cramped version of a style (in particular, cramping a cramped style
  489. * doesn't change the style).
  490. */
  491. cramp() {
  492. return styles[cramp[this.id]];
  493. }
  494. /**
  495. * Get a text or display version of this style.
  496. */
  497. text() {
  498. return styles[text$1[this.id]];
  499. }
  500. /**
  501. * Return true if this style is tightly spaced (scriptstyle/scriptscriptstyle)
  502. */
  503. isTight() {
  504. return this.size >= 2;
  505. }
  506. } // Export an interface for type checking, but don't expose the implementation.
  507. // This way, no more styles can be generated.
  508. // IDs of the different styles
  509. var D = 0;
  510. var Dc = 1;
  511. var T = 2;
  512. var Tc = 3;
  513. var S = 4;
  514. var Sc = 5;
  515. var SS = 6;
  516. var SSc = 7; // Instances of the different styles
  517. var styles = [new Style(D, 0, false), new Style(Dc, 0, true), new Style(T, 1, false), new Style(Tc, 1, true), new Style(S, 2, false), new Style(Sc, 2, true), new Style(SS, 3, false), new Style(SSc, 3, true)]; // Lookup tables for switching from one style to another
  518. var sup = [S, Sc, S, Sc, SS, SSc, SS, SSc];
  519. var sub = [Sc, Sc, Sc, Sc, SSc, SSc, SSc, SSc];
  520. var fracNum = [T, Tc, S, Sc, SS, SSc, SS, SSc];
  521. var fracDen = [Tc, Tc, Sc, Sc, SSc, SSc, SSc, SSc];
  522. var cramp = [Dc, Dc, Tc, Tc, Sc, Sc, SSc, SSc];
  523. var text$1 = [D, Dc, T, Tc, T, Tc, T, Tc]; // We only export some of the styles.
  524. var Style$1 = {
  525. DISPLAY: styles[D],
  526. TEXT: styles[T],
  527. SCRIPT: styles[S],
  528. SCRIPTSCRIPT: styles[SS]
  529. };
  530. /*
  531. * This file defines the Unicode scripts and script families that we
  532. * support. To add new scripts or families, just add a new entry to the
  533. * scriptData array below. Adding scripts to the scriptData array allows
  534. * characters from that script to appear in \text{} environments.
  535. */
  536. /**
  537. * Each script or script family has a name and an array of blocks.
  538. * Each block is an array of two numbers which specify the start and
  539. * end points (inclusive) of a block of Unicode codepoints.
  540. */
  541. /**
  542. * Unicode block data for the families of scripts we support in \text{}.
  543. * Scripts only need to appear here if they do not have font metrics.
  544. */
  545. var scriptData = [{
  546. // Latin characters beyond the Latin-1 characters we have metrics for.
  547. // Needed for Czech, Hungarian and Turkish text, for example.
  548. name: 'latin',
  549. blocks: [[0x0100, 0x024f], // Latin Extended-A and Latin Extended-B
  550. [0x0300, 0x036f] // Combining Diacritical marks
  551. ]
  552. }, {
  553. // The Cyrillic script used by Russian and related languages.
  554. // A Cyrillic subset used to be supported as explicitly defined
  555. // symbols in symbols.js
  556. name: 'cyrillic',
  557. blocks: [[0x0400, 0x04ff]]
  558. }, {
  559. // Armenian
  560. name: 'armenian',
  561. blocks: [[0x0530, 0x058F]]
  562. }, {
  563. // The Brahmic scripts of South and Southeast Asia
  564. // Devanagari (0900–097F)
  565. // Bengali (0980–09FF)
  566. // Gurmukhi (0A00–0A7F)
  567. // Gujarati (0A80–0AFF)
  568. // Oriya (0B00–0B7F)
  569. // Tamil (0B80–0BFF)
  570. // Telugu (0C00–0C7F)
  571. // Kannada (0C80–0CFF)
  572. // Malayalam (0D00–0D7F)
  573. // Sinhala (0D80–0DFF)
  574. // Thai (0E00–0E7F)
  575. // Lao (0E80–0EFF)
  576. // Tibetan (0F00–0FFF)
  577. // Myanmar (1000–109F)
  578. name: 'brahmic',
  579. blocks: [[0x0900, 0x109F]]
  580. }, {
  581. name: 'georgian',
  582. blocks: [[0x10A0, 0x10ff]]
  583. }, {
  584. // Chinese and Japanese.
  585. // The "k" in cjk is for Korean, but we've separated Korean out
  586. name: "cjk",
  587. blocks: [[0x3000, 0x30FF], // CJK symbols and punctuation, Hiragana, Katakana
  588. [0x4E00, 0x9FAF], // CJK ideograms
  589. [0xFF00, 0xFF60] // Fullwidth punctuation
  590. // TODO: add halfwidth Katakana and Romanji glyphs
  591. ]
  592. }, {
  593. // Korean
  594. name: 'hangul',
  595. blocks: [[0xAC00, 0xD7AF]]
  596. }];
  597. /**
  598. * Given a codepoint, return the name of the script or script family
  599. * it is from, or null if it is not part of a known block
  600. */
  601. function scriptFromCodepoint(codepoint) {
  602. for (var i = 0; i < scriptData.length; i++) {
  603. var script = scriptData[i];
  604. for (var _i = 0; _i < script.blocks.length; _i++) {
  605. var block = script.blocks[_i];
  606. if (codepoint >= block[0] && codepoint <= block[1]) {
  607. return script.name;
  608. }
  609. }
  610. }
  611. return null;
  612. }
  613. /**
  614. * A flattened version of all the supported blocks in a single array.
  615. * This is an optimization to make supportedCodepoint() fast.
  616. */
  617. var allBlocks = [];
  618. scriptData.forEach(s => s.blocks.forEach(b => allBlocks.push(...b)));
  619. /**
  620. * Given a codepoint, return true if it falls within one of the
  621. * scripts or script families defined above and false otherwise.
  622. *
  623. * Micro benchmarks shows that this is faster than
  624. * /[\u3000-\u30FF\u4E00-\u9FAF\uFF00-\uFF60\uAC00-\uD7AF\u0900-\u109F]/.test()
  625. * in Firefox, Chrome and Node.
  626. */
  627. function supportedCodepoint(codepoint) {
  628. for (var i = 0; i < allBlocks.length; i += 2) {
  629. if (codepoint >= allBlocks[i] && codepoint <= allBlocks[i + 1]) {
  630. return true;
  631. }
  632. }
  633. return false;
  634. }
  635. /**
  636. * This file provides support to domTree.js and delimiter.js.
  637. * It's a storehouse of path geometry for SVG images.
  638. */
  639. // In all paths below, the viewBox-to-em scale is 1000:1.
  640. var hLinePad = 80; // padding above a sqrt viniculum. Prevents image cropping.
  641. // The viniculum of a \sqrt can be made thicker by a KaTeX rendering option.
  642. // Think of variable extraViniculum as two detours in the SVG path.
  643. // The detour begins at the lower left of the area labeled extraViniculum below.
  644. // The detour proceeds one extraViniculum distance up and slightly to the right,
  645. // displacing the radiused corner between surd and viniculum. The radius is
  646. // traversed as usual, then the detour resumes. It goes right, to the end of
  647. // the very long viniculumn, then down one extraViniculum distance,
  648. // after which it resumes regular path geometry for the radical.
  649. /* viniculum
  650. /
  651. /▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒←extraViniculum
  652. / █████████████████████←0.04em (40 unit) std viniculum thickness
  653. / /
  654. / /
  655. / /\
  656. / / surd
  657. */
  658. var sqrtMain = function sqrtMain(extraViniculum, hLinePad) {
  659. // sqrtMain path geometry is from glyph U221A in the font KaTeX Main
  660. return "M95," + (622 + extraViniculum + hLinePad) + "\nc-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14\nc0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54\nc44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10\ns173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429\nc69,-144,104.5,-217.7,106.5,-221\nl" + extraViniculum / 2.075 + " -" + extraViniculum + "\nc5.3,-9.3,12,-14,20,-14\nH400000v" + (40 + extraViniculum) + "H845.2724\ns-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7\nc-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z\nM" + (834 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "h-400000z";
  661. };
  662. var sqrtSize1 = function sqrtSize1(extraViniculum, hLinePad) {
  663. // size1 is from glyph U221A in the font KaTeX_Size1-Regular
  664. return "M263," + (601 + extraViniculum + hLinePad) + "c0.7,0,18,39.7,52,119\nc34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120\nc340,-704.7,510.7,-1060.3,512,-1067\nl" + extraViniculum / 2.084 + " -" + extraViniculum + "\nc4.7,-7.3,11,-11,19,-11\nH40000v" + (40 + extraViniculum) + "H1012.3\ns-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232\nc-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1\ns-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26\nc-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60z\nM" + (1001 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "h-400000z";
  665. };
  666. var sqrtSize2 = function sqrtSize2(extraViniculum, hLinePad) {
  667. // size2 is from glyph U221A in the font KaTeX_Size2-Regular
  668. return "M983 " + (10 + extraViniculum + hLinePad) + "\nl" + extraViniculum / 3.13 + " -" + extraViniculum + "\nc4,-6.7,10,-10,18,-10 H400000v" + (40 + extraViniculum) + "\nH1013.1s-83.4,268,-264.1,840c-180.7,572,-277,876.3,-289,913c-4.7,4.7,-12.7,7,-24,7\ns-12,0,-12,0c-1.3,-3.3,-3.7,-11.7,-7,-25c-35.3,-125.3,-106.7,-373.3,-214,-744\nc-10,12,-21,25,-33,39s-32,39,-32,39c-6,-5.3,-15,-14,-27,-26s25,-30,25,-30\nc26.7,-32.7,52,-63,76,-91s52,-60,52,-60s208,722,208,722\nc56,-175.3,126.3,-397.3,211,-666c84.7,-268.7,153.8,-488.2,207.5,-658.5\nc53.7,-170.3,84.5,-266.8,92.5,-289.5z\nM" + (1001 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "h-400000z";
  669. };
  670. var sqrtSize3 = function sqrtSize3(extraViniculum, hLinePad) {
  671. // size3 is from glyph U221A in the font KaTeX_Size3-Regular
  672. return "M424," + (2398 + extraViniculum + hLinePad) + "\nc-1.3,-0.7,-38.5,-172,-111.5,-514c-73,-342,-109.8,-513.3,-110.5,-514\nc0,-2,-10.7,14.3,-32,49c-4.7,7.3,-9.8,15.7,-15.5,25c-5.7,9.3,-9.8,16,-12.5,20\ns-5,7,-5,7c-4,-3.3,-8.3,-7.7,-13,-13s-13,-13,-13,-13s76,-122,76,-122s77,-121,77,-121\ns209,968,209,968c0,-2,84.7,-361.7,254,-1079c169.3,-717.3,254.7,-1077.7,256,-1081\nl" + extraViniculum / 4.223 + " -" + extraViniculum + "c4,-6.7,10,-10,18,-10 H400000\nv" + (40 + extraViniculum) + "H1014.6\ns-87.3,378.7,-272.6,1166c-185.3,787.3,-279.3,1182.3,-282,1185\nc-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2z M" + (1001 + extraViniculum) + " " + hLinePad + "\nh400000v" + (40 + extraViniculum) + "h-400000z";
  673. };
  674. var sqrtSize4 = function sqrtSize4(extraViniculum, hLinePad) {
  675. // size4 is from glyph U221A in the font KaTeX_Size4-Regular
  676. return "M473," + (2713 + extraViniculum + hLinePad) + "\nc339.3,-1799.3,509.3,-2700,510,-2702 l" + extraViniculum / 5.298 + " -" + extraViniculum + "\nc3.3,-7.3,9.3,-11,18,-11 H400000v" + (40 + extraViniculum) + "H1017.7\ns-90.5,478,-276.2,1466c-185.7,988,-279.5,1483,-281.5,1485c-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2c0,-1.3,-5.3,-32,-16,-92c-50.7,-293.3,-119.7,-693.3,-207,-1200\nc0,-1.3,-5.3,8.7,-16,30c-10.7,21.3,-21.3,42.7,-32,64s-16,33,-16,33s-26,-26,-26,-26\ns76,-153,76,-153s77,-151,77,-151c0.7,0.7,35.7,202,105,604c67.3,400.7,102,602.7,104,\n606zM" + (1001 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "H1017.7z";
  677. };
  678. var phasePath = function phasePath(y) {
  679. var x = y / 2; // x coordinate at top of angle
  680. return "M400000 " + y + " H0 L" + x + " 0 l65 45 L145 " + (y - 80) + " H400000z";
  681. };
  682. var sqrtTall = function sqrtTall(extraViniculum, hLinePad, viewBoxHeight) {
  683. // sqrtTall is from glyph U23B7 in the font KaTeX_Size4-Regular
  684. // One path edge has a variable length. It runs vertically from the viniculumn
  685. // to a point near (14 units) the bottom of the surd. The viniculum
  686. // is normally 40 units thick. So the length of the line in question is:
  687. var vertSegment = viewBoxHeight - 54 - hLinePad - extraViniculum;
  688. return "M702 " + (extraViniculum + hLinePad) + "H400000" + (40 + extraViniculum) + "\nH742v" + vertSegment + "l-4 4-4 4c-.667.7 -2 1.5-4 2.5s-4.167 1.833-6.5 2.5-5.5 1-9.5 1\nh-12l-28-84c-16.667-52-96.667 -294.333-240-727l-212 -643 -85 170\nc-4-3.333-8.333-7.667-13 -13l-13-13l77-155 77-156c66 199.333 139 419.667\n219 661 l218 661zM702 " + hLinePad + "H400000v" + (40 + extraViniculum) + "H742z";
  689. };
  690. var sqrtPath = function sqrtPath(size, extraViniculum, viewBoxHeight) {
  691. extraViniculum = 1000 * extraViniculum; // Convert from document ems to viewBox.
  692. var path = "";
  693. switch (size) {
  694. case "sqrtMain":
  695. path = sqrtMain(extraViniculum, hLinePad);
  696. break;
  697. case "sqrtSize1":
  698. path = sqrtSize1(extraViniculum, hLinePad);
  699. break;
  700. case "sqrtSize2":
  701. path = sqrtSize2(extraViniculum, hLinePad);
  702. break;
  703. case "sqrtSize3":
  704. path = sqrtSize3(extraViniculum, hLinePad);
  705. break;
  706. case "sqrtSize4":
  707. path = sqrtSize4(extraViniculum, hLinePad);
  708. break;
  709. case "sqrtTall":
  710. path = sqrtTall(extraViniculum, hLinePad, viewBoxHeight);
  711. }
  712. return path;
  713. };
  714. var innerPath = function innerPath(name, height) {
  715. // The inner part of stretchy tall delimiters
  716. switch (name) {
  717. case "\u239c":
  718. return "M291 0 H417 V" + height + " H291z M291 0 H417 V" + height + " H291z";
  719. case "\u2223":
  720. return "M145 0 H188 V" + height + " H145z M145 0 H188 V" + height + " H145z";
  721. case "\u2225":
  722. return "M145 0 H188 V" + height + " H145z M145 0 H188 V" + height + " H145z" + ("M367 0 H410 V" + height + " H367z M367 0 H410 V" + height + " H367z");
  723. case "\u239f":
  724. return "M457 0 H583 V" + height + " H457z M457 0 H583 V" + height + " H457z";
  725. case "\u23a2":
  726. return "M319 0 H403 V" + height + " H319z M319 0 H403 V" + height + " H319z";
  727. case "\u23a5":
  728. return "M263 0 H347 V" + height + " H263z M263 0 H347 V" + height + " H263z";
  729. case "\u23aa":
  730. return "M384 0 H504 V" + height + " H384z M384 0 H504 V" + height + " H384z";
  731. case "\u23d0":
  732. return "M312 0 H355 V" + height + " H312z M312 0 H355 V" + height + " H312z";
  733. case "\u2016":
  734. return "M257 0 H300 V" + height + " H257z M257 0 H300 V" + height + " H257z" + ("M478 0 H521 V" + height + " H478z M478 0 H521 V" + height + " H478z");
  735. default:
  736. return "";
  737. }
  738. };
  739. var path = {
  740. // The doubleleftarrow geometry is from glyph U+21D0 in the font KaTeX Main
  741. doubleleftarrow: "M262 157\nl10-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\n 0-12.2.5-14.5 1.5-2.3 1-4.8 4.5-7.5 10.5-49.3 97.3-121.7 169.3-217 216-28\n 14-57.3 25-88 33-6.7 2-11 3.8-13 5.5-2 1.7-3 4.2-3 7.5s1 5.8 3 7.5\nc2 1.7 6.3 3.5 13 5.5 68 17.3 128.2 47.8 180.5 91.5 52.3 43.7 93.8 96.2 124.5\n 157.5 9.3 8 15.3 12.3 18 13h6c12-.7 18-4 18-10 0-2-1.7-7-5-15-23.3-46-52-87\n-86-123l-10-10h399738v-40H218c328 0 0 0 0 0l-10-8c-26.7-20-65.7-43-117-69 2.7\n-2 6-3.7 10-5 36.7-16 72.3-37.3 107-64l10-8h399782v-40z\nm8 0v40h399730v-40zm0 194v40h399730v-40z",
  742. // doublerightarrow is from glyph U+21D2 in font KaTeX Main
  743. doublerightarrow: "M399738 392l\n-10 10c-34 36-62.7 77-86 123-3.3 8-5 13.3-5 16 0 5.3 6.7 8 20 8 7.3 0 12.2-.5\n 14.5-1.5 2.3-1 4.8-4.5 7.5-10.5 49.3-97.3 121.7-169.3 217-216 28-14 57.3-25 88\n-33 6.7-2 11-3.8 13-5.5 2-1.7 3-4.2 3-7.5s-1-5.8-3-7.5c-2-1.7-6.3-3.5-13-5.5-68\n-17.3-128.2-47.8-180.5-91.5-52.3-43.7-93.8-96.2-124.5-157.5-9.3-8-15.3-12.3-18\n-13h-6c-12 .7-18 4-18 10 0 2 1.7 7 5 15 23.3 46 52 87 86 123l10 10H0v40h399782\nc-328 0 0 0 0 0l10 8c26.7 20 65.7 43 117 69-2.7 2-6 3.7-10 5-36.7 16-72.3 37.3\n-107 64l-10 8H0v40zM0 157v40h399730v-40zm0 194v40h399730v-40z",
  744. // leftarrow is from glyph U+2190 in font KaTeX Main
  745. leftarrow: "M400000 241H110l3-3c68.7-52.7 113.7-120\n 135-202 4-14.7 6-23 6-25 0-7.3-7-11-21-11-8 0-13.2.8-15.5 2.5-2.3 1.7-4.2 5.8\n-5.5 12.5-1.3 4.7-2.7 10.3-4 17-12 48.7-34.8 92-68.5 130S65.3 228.3 18 247\nc-10 4-16 7.7-18 11 0 8.7 6 14.3 18 17 47.3 18.7 87.8 47 121.5 85S196 441.3 208\n 490c.7 2 1.3 5 2 9s1.2 6.7 1.5 8c.3 1.3 1 3.3 2 6s2.2 4.5 3.5 5.5c1.3 1 3.3\n 1.8 6 2.5s6 1 10 1c14 0 21-3.7 21-11 0-2-2-10.3-6-25-20-79.3-65-146.7-135-202\n l-3-3h399890zM100 241v40h399900v-40z",
  746. // overbrace is from glyphs U+23A9/23A8/23A7 in font KaTeX_Size4-Regular
  747. leftbrace: "M6 548l-6-6v-35l6-11c56-104 135.3-181.3 238-232 57.3-28.7 117\n-45 179-50h399577v120H403c-43.3 7-81 15-113 26-100.7 33-179.7 91-237 174-2.7\n 5-6 9-10 13-.7 1-7.3 1-20 1H6z",
  748. leftbraceunder: "M0 6l6-6h17c12.688 0 19.313.3 20 1 4 4 7.313 8.3 10 13\n 35.313 51.3 80.813 93.8 136.5 127.5 55.688 33.7 117.188 55.8 184.5 66.5.688\n 0 2 .3 4 1 18.688 2.7 76 4.3 172 5h399450v120H429l-6-1c-124.688-8-235-61.7\n-331-161C60.687 138.7 32.312 99.3 7 54L0 41V6z",
  749. // overgroup is from the MnSymbol package (public domain)
  750. leftgroup: "M400000 80\nH435C64 80 168.3 229.4 21 260c-5.9 1.2-18 0-18 0-2 0-3-1-3-3v-38C76 61 257 0\n 435 0h399565z",
  751. leftgroupunder: "M400000 262\nH435C64 262 168.3 112.6 21 82c-5.9-1.2-18 0-18 0-2 0-3 1-3 3v38c76 158 257 219\n 435 219h399565z",
  752. // Harpoons are from glyph U+21BD in font KaTeX Main
  753. leftharpoon: "M0 267c.7 5.3 3 10 7 14h399993v-40H93c3.3\n-3.3 10.2-9.5 20.5-18.5s17.8-15.8 22.5-20.5c50.7-52 88-110.3 112-175 4-11.3 5\n-18.3 3-21-1.3-4-7.3-6-18-6-8 0-13 .7-15 2s-4.7 6.7-8 16c-42 98.7-107.3 174.7\n-196 228-6.7 4.7-10.7 8-12 10-1.3 2-2 5.7-2 11zm100-26v40h399900v-40z",
  754. leftharpoonplus: "M0 267c.7 5.3 3 10 7 14h399993v-40H93c3.3-3.3 10.2-9.5\n 20.5-18.5s17.8-15.8 22.5-20.5c50.7-52 88-110.3 112-175 4-11.3 5-18.3 3-21-1.3\n-4-7.3-6-18-6-8 0-13 .7-15 2s-4.7 6.7-8 16c-42 98.7-107.3 174.7-196 228-6.7 4.7\n-10.7 8-12 10-1.3 2-2 5.7-2 11zm100-26v40h399900v-40zM0 435v40h400000v-40z\nm0 0v40h400000v-40z",
  755. leftharpoondown: "M7 241c-4 4-6.333 8.667-7 14 0 5.333.667 9 2 11s5.333\n 5.333 12 10c90.667 54 156 130 196 228 3.333 10.667 6.333 16.333 9 17 2 .667 5\n 1 9 1h5c10.667 0 16.667-2 18-6 2-2.667 1-9.667-3-21-32-87.333-82.667-157.667\n-152-211l-3-3h399907v-40zM93 281 H400000 v-40L7 241z",
  756. leftharpoondownplus: "M7 435c-4 4-6.3 8.7-7 14 0 5.3.7 9 2 11s5.3 5.3 12\n 10c90.7 54 156 130 196 228 3.3 10.7 6.3 16.3 9 17 2 .7 5 1 9 1h5c10.7 0 16.7\n-2 18-6 2-2.7 1-9.7-3-21-32-87.3-82.7-157.7-152-211l-3-3h399907v-40H7zm93 0\nv40h399900v-40zM0 241v40h399900v-40zm0 0v40h399900v-40z",
  757. // hook is from glyph U+21A9 in font KaTeX Main
  758. lefthook: "M400000 281 H103s-33-11.2-61-33.5S0 197.3 0 164s14.2-61.2 42.5\n-83.5C70.8 58.2 104 47 142 47 c16.7 0 25 6.7 25 20 0 12-8.7 18.7-26 20-40 3.3\n-68.7 15.7-86 37-10 12-15 25.3-15 40 0 22.7 9.8 40.7 29.5 54 19.7 13.3 43.5 21\n 71.5 23h399859zM103 281v-40h399897v40z",
  759. leftlinesegment: "M40 281 V428 H0 V94 H40 V241 H400000 v40z\nM40 281 V428 H0 V94 H40 V241 H400000 v40z",
  760. leftmapsto: "M40 281 V448H0V74H40V241H400000v40z\nM40 281 V448H0V74H40V241H400000v40z",
  761. // tofrom is from glyph U+21C4 in font KaTeX AMS Regular
  762. leftToFrom: "M0 147h400000v40H0zm0 214c68 40 115.7 95.7 143 167h22c15.3 0 23\n-.3 23-1 0-1.3-5.3-13.7-16-37-18-35.3-41.3-69-70-101l-7-8h399905v-40H95l7-8\nc28.7-32 52-65.7 70-101 10.7-23.3 16-35.7 16-37 0-.7-7.7-1-23-1h-22C115.7 265.3\n 68 321 0 361zm0-174v-40h399900v40zm100 154v40h399900v-40z",
  763. longequal: "M0 50 h400000 v40H0z m0 194h40000v40H0z\nM0 50 h400000 v40H0z m0 194h40000v40H0z",
  764. midbrace: "M200428 334\nc-100.7-8.3-195.3-44-280-108-55.3-42-101.7-93-139-153l-9-14c-2.7 4-5.7 8.7-9 14\n-53.3 86.7-123.7 153-211 199-66.7 36-137.3 56.3-212 62H0V214h199568c178.3-11.7\n 311.7-78.3 403-201 6-8 9.7-12 11-12 .7-.7 6.7-1 18-1s17.3.3 18 1c1.3 0 5 4 11\n 12 44.7 59.3 101.3 106.3 170 141s145.3 54.3 229 60h199572v120z",
  765. midbraceunder: "M199572 214\nc100.7 8.3 195.3 44 280 108 55.3 42 101.7 93 139 153l9 14c2.7-4 5.7-8.7 9-14\n 53.3-86.7 123.7-153 211-199 66.7-36 137.3-56.3 212-62h199568v120H200432c-178.3\n 11.7-311.7 78.3-403 201-6 8-9.7 12-11 12-.7.7-6.7 1-18 1s-17.3-.3-18-1c-1.3 0\n-5-4-11-12-44.7-59.3-101.3-106.3-170-141s-145.3-54.3-229-60H0V214z",
  766. oiintSize1: "M512.6 71.6c272.6 0 320.3 106.8 320.3 178.2 0 70.8-47.7 177.6\n-320.3 177.6S193.1 320.6 193.1 249.8c0-71.4 46.9-178.2 319.5-178.2z\nm368.1 178.2c0-86.4-60.9-215.4-368.1-215.4-306.4 0-367.3 129-367.3 215.4 0 85.8\n60.9 214.8 367.3 214.8 307.2 0 368.1-129 368.1-214.8z",
  767. oiintSize2: "M757.8 100.1c384.7 0 451.1 137.6 451.1 230 0 91.3-66.4 228.8\n-451.1 228.8-386.3 0-452.7-137.5-452.7-228.8 0-92.4 66.4-230 452.7-230z\nm502.4 230c0-111.2-82.4-277.2-502.4-277.2s-504 166-504 277.2\nc0 110 84 276 504 276s502.4-166 502.4-276z",
  768. oiiintSize1: "M681.4 71.6c408.9 0 480.5 106.8 480.5 178.2 0 70.8-71.6 177.6\n-480.5 177.6S202.1 320.6 202.1 249.8c0-71.4 70.5-178.2 479.3-178.2z\nm525.8 178.2c0-86.4-86.8-215.4-525.7-215.4-437.9 0-524.7 129-524.7 215.4 0\n85.8 86.8 214.8 524.7 214.8 438.9 0 525.7-129 525.7-214.8z",
  769. oiiintSize2: "M1021.2 53c603.6 0 707.8 165.8 707.8 277.2 0 110-104.2 275.8\n-707.8 275.8-606 0-710.2-165.8-710.2-275.8C311 218.8 415.2 53 1021.2 53z\nm770.4 277.1c0-131.2-126.4-327.6-770.5-327.6S248.4 198.9 248.4 330.1\nc0 130 128.8 326.4 772.7 326.4s770.5-196.4 770.5-326.4z",
  770. rightarrow: "M0 241v40h399891c-47.3 35.3-84 78-110 128\n-16.7 32-27.7 63.7-33 95 0 1.3-.2 2.7-.5 4-.3 1.3-.5 2.3-.5 3 0 7.3 6.7 11 20\n 11 8 0 13.2-.8 15.5-2.5 2.3-1.7 4.2-5.5 5.5-11.5 2-13.3 5.7-27 11-41 14.7-44.7\n 39-84.5 73-119.5s73.7-60.2 119-75.5c6-2 9-5.7 9-11s-3-9-9-11c-45.3-15.3-85\n-40.5-119-75.5s-58.3-74.8-73-119.5c-4.7-14-8.3-27.3-11-40-1.3-6.7-3.2-10.8-5.5\n-12.5-2.3-1.7-7.5-2.5-15.5-2.5-14 0-21 3.7-21 11 0 2 2 10.3 6 25 20.7 83.3 67\n 151.7 139 205zm0 0v40h399900v-40z",
  771. rightbrace: "M400000 542l\n-6 6h-17c-12.7 0-19.3-.3-20-1-4-4-7.3-8.3-10-13-35.3-51.3-80.8-93.8-136.5-127.5\ns-117.2-55.8-184.5-66.5c-.7 0-2-.3-4-1-18.7-2.7-76-4.3-172-5H0V214h399571l6 1\nc124.7 8 235 61.7 331 161 31.3 33.3 59.7 72.7 85 118l7 13v35z",
  772. rightbraceunder: "M399994 0l6 6v35l-6 11c-56 104-135.3 181.3-238 232-57.3\n 28.7-117 45-179 50H-300V214h399897c43.3-7 81-15 113-26 100.7-33 179.7-91 237\n-174 2.7-5 6-9 10-13 .7-1 7.3-1 20-1h17z",
  773. rightgroup: "M0 80h399565c371 0 266.7 149.4 414 180 5.9 1.2 18 0 18 0 2 0\n 3-1 3-3v-38c-76-158-257-219-435-219H0z",
  774. rightgroupunder: "M0 262h399565c371 0 266.7-149.4 414-180 5.9-1.2 18 0 18\n 0 2 0 3 1 3 3v38c-76 158-257 219-435 219H0z",
  775. rightharpoon: "M0 241v40h399993c4.7-4.7 7-9.3 7-14 0-9.3\n-3.7-15.3-11-18-92.7-56.7-159-133.7-199-231-3.3-9.3-6-14.7-8-16-2-1.3-7-2-15-2\n-10.7 0-16.7 2-18 6-2 2.7-1 9.7 3 21 15.3 42 36.7 81.8 64 119.5 27.3 37.7 58\n 69.2 92 94.5zm0 0v40h399900v-40z",
  776. rightharpoonplus: "M0 241v40h399993c4.7-4.7 7-9.3 7-14 0-9.3-3.7-15.3-11\n-18-92.7-56.7-159-133.7-199-231-3.3-9.3-6-14.7-8-16-2-1.3-7-2-15-2-10.7 0-16.7\n 2-18 6-2 2.7-1 9.7 3 21 15.3 42 36.7 81.8 64 119.5 27.3 37.7 58 69.2 92 94.5z\nm0 0v40h399900v-40z m100 194v40h399900v-40zm0 0v40h399900v-40z",
  777. rightharpoondown: "M399747 511c0 7.3 6.7 11 20 11 8 0 13-.8 15-2.5s4.7-6.8\n 8-15.5c40-94 99.3-166.3 178-217 13.3-8 20.3-12.3 21-13 5.3-3.3 8.5-5.8 9.5\n-7.5 1-1.7 1.5-5.2 1.5-10.5s-2.3-10.3-7-15H0v40h399908c-34 25.3-64.7 57-92 95\n-27.3 38-48.7 77.7-64 119-3.3 8.7-5 14-5 16zM0 241v40h399900v-40z",
  778. rightharpoondownplus: "M399747 705c0 7.3 6.7 11 20 11 8 0 13-.8\n 15-2.5s4.7-6.8 8-15.5c40-94 99.3-166.3 178-217 13.3-8 20.3-12.3 21-13 5.3-3.3\n 8.5-5.8 9.5-7.5 1-1.7 1.5-5.2 1.5-10.5s-2.3-10.3-7-15H0v40h399908c-34 25.3\n-64.7 57-92 95-27.3 38-48.7 77.7-64 119-3.3 8.7-5 14-5 16zM0 435v40h399900v-40z\nm0-194v40h400000v-40zm0 0v40h400000v-40z",
  779. righthook: "M399859 241c-764 0 0 0 0 0 40-3.3 68.7-15.7 86-37 10-12 15-25.3\n 15-40 0-22.7-9.8-40.7-29.5-54-19.7-13.3-43.5-21-71.5-23-17.3-1.3-26-8-26-20 0\n-13.3 8.7-20 26-20 38 0 71 11.2 99 33.5 0 0 7 5.6 21 16.7 14 11.2 21 33.5 21\n 66.8s-14 61.2-42 83.5c-28 22.3-61 33.5-99 33.5L0 241z M0 281v-40h399859v40z",
  780. rightlinesegment: "M399960 241 V94 h40 V428 h-40 V281 H0 v-40z\nM399960 241 V94 h40 V428 h-40 V281 H0 v-40z",
  781. rightToFrom: "M400000 167c-70.7-42-118-97.7-142-167h-23c-15.3 0-23 .3-23\n 1 0 1.3 5.3 13.7 16 37 18 35.3 41.3 69 70 101l7 8H0v40h399905l-7 8c-28.7 32\n-52 65.7-70 101-10.7 23.3-16 35.7-16 37 0 .7 7.7 1 23 1h23c24-69.3 71.3-125 142\n-167z M100 147v40h399900v-40zM0 341v40h399900v-40z",
  782. // twoheadleftarrow is from glyph U+219E in font KaTeX AMS Regular
  783. twoheadleftarrow: "M0 167c68 40\n 115.7 95.7 143 167h22c15.3 0 23-.3 23-1 0-1.3-5.3-13.7-16-37-18-35.3-41.3-69\n-70-101l-7-8h125l9 7c50.7 39.3 85 86 103 140h46c0-4.7-6.3-18.7-19-42-18-35.3\n-40-67.3-66-96l-9-9h399716v-40H284l9-9c26-28.7 48-60.7 66-96 12.7-23.333 19\n-37.333 19-42h-46c-18 54-52.3 100.7-103 140l-9 7H95l7-8c28.7-32 52-65.7 70-101\n 10.7-23.333 16-35.7 16-37 0-.7-7.7-1-23-1h-22C115.7 71.3 68 127 0 167z",
  784. twoheadrightarrow: "M400000 167\nc-68-40-115.7-95.7-143-167h-22c-15.3 0-23 .3-23 1 0 1.3 5.3 13.7 16 37 18 35.3\n 41.3 69 70 101l7 8h-125l-9-7c-50.7-39.3-85-86-103-140h-46c0 4.7 6.3 18.7 19 42\n 18 35.3 40 67.3 66 96l9 9H0v40h399716l-9 9c-26 28.7-48 60.7-66 96-12.7 23.333\n-19 37.333-19 42h46c18-54 52.3-100.7 103-140l9-7h125l-7 8c-28.7 32-52 65.7-70\n 101-10.7 23.333-16 35.7-16 37 0 .7 7.7 1 23 1h22c27.3-71.3 75-127 143-167z",
  785. // tilde1 is a modified version of a glyph from the MnSymbol package
  786. tilde1: "M200 55.538c-77 0-168 73.953-177 73.953-3 0-7\n-2.175-9-5.437L2 97c-1-2-2-4-2-6 0-4 2-7 5-9l20-12C116 12 171 0 207 0c86 0\n 114 68 191 68 78 0 168-68 177-68 4 0 7 2 9 5l12 19c1 2.175 2 4.35 2 6.525 0\n 4.35-2 7.613-5 9.788l-19 13.05c-92 63.077-116.937 75.308-183 76.128\n-68.267.847-113-73.952-191-73.952z",
  787. // ditto tilde2, tilde3, & tilde4
  788. tilde2: "M344 55.266c-142 0-300.638 81.316-311.5 86.418\n-8.01 3.762-22.5 10.91-23.5 5.562L1 120c-1-2-1-3-1-4 0-5 3-9 8-10l18.4-9C160.9\n 31.9 283 0 358 0c148 0 188 122 331 122s314-97 326-97c4 0 8 2 10 7l7 21.114\nc1 2.14 1 3.21 1 4.28 0 5.347-3 9.626-7 10.696l-22.3 12.622C852.6 158.372 751\n 181.476 676 181.476c-149 0-189-126.21-332-126.21z",
  789. tilde3: "M786 59C457 59 32 175.242 13 175.242c-6 0-10-3.457\n-11-10.37L.15 138c-1-7 3-12 10-13l19.2-6.4C378.4 40.7 634.3 0 804.3 0c337 0\n 411.8 157 746.8 157 328 0 754-112 773-112 5 0 10 3 11 9l1 14.075c1 8.066-.697\n 16.595-6.697 17.492l-21.052 7.31c-367.9 98.146-609.15 122.696-778.15 122.696\n -338 0-409-156.573-744-156.573z",
  790. tilde4: "M786 58C457 58 32 177.487 13 177.487c-6 0-10-3.345\n-11-10.035L.15 143c-1-7 3-12 10-13l22-6.7C381.2 35 637.15 0 807.15 0c337 0 409\n 177 744 177 328 0 754-127 773-127 5 0 10 3 11 9l1 14.794c1 7.805-3 13.38-9\n 14.495l-20.7 5.574c-366.85 99.79-607.3 139.372-776.3 139.372-338 0-409\n -175.236-744-175.236z",
  791. // vec is from glyph U+20D7 in font KaTeX Main
  792. vec: "M377 20c0-5.333 1.833-10 5.5-14S391 0 397 0c4.667 0 8.667 1.667 12 5\n3.333 2.667 6.667 9 10 19 6.667 24.667 20.333 43.667 41 57 7.333 4.667 11\n10.667 11 18 0 6-1 10-3 12s-6.667 5-14 9c-28.667 14.667-53.667 35.667-75 63\n-1.333 1.333-3.167 3.5-5.5 6.5s-4 4.833-5 5.5c-1 .667-2.5 1.333-4.5 2s-4.333 1\n-7 1c-4.667 0-9.167-1.833-13.5-5.5S337 184 337 178c0-12.667 15.667-32.333 47-59\nH213l-171-1c-8.667-6-13-12.333-13-19 0-4.667 4.333-11.333 13-20h359\nc-16-25.333-24-45-24-59z",
  793. // widehat1 is a modified version of a glyph from the MnSymbol package
  794. widehat1: "M529 0h5l519 115c5 1 9 5 9 10 0 1-1 2-1 3l-4 22\nc-1 5-5 9-11 9h-2L532 67 19 159h-2c-5 0-9-4-11-9l-5-22c-1-6 2-12 8-13z",
  795. // ditto widehat2, widehat3, & widehat4
  796. widehat2: "M1181 0h2l1171 176c6 0 10 5 10 11l-2 23c-1 6-5 10\n-11 10h-1L1182 67 15 220h-1c-6 0-10-4-11-10l-2-23c-1-6 4-11 10-11z",
  797. widehat3: "M1181 0h2l1171 236c6 0 10 5 10 11l-2 23c-1 6-5 10\n-11 10h-1L1182 67 15 280h-1c-6 0-10-4-11-10l-2-23c-1-6 4-11 10-11z",
  798. widehat4: "M1181 0h2l1171 296c6 0 10 5 10 11l-2 23c-1 6-5 10\n-11 10h-1L1182 67 15 340h-1c-6 0-10-4-11-10l-2-23c-1-6 4-11 10-11z",
  799. // widecheck paths are all inverted versions of widehat
  800. widecheck1: "M529,159h5l519,-115c5,-1,9,-5,9,-10c0,-1,-1,-2,-1,-3l-4,-22c-1,\n-5,-5,-9,-11,-9h-2l-512,92l-513,-92h-2c-5,0,-9,4,-11,9l-5,22c-1,6,2,12,8,13z",
  801. widecheck2: "M1181,220h2l1171,-176c6,0,10,-5,10,-11l-2,-23c-1,-6,-5,-10,\n-11,-10h-1l-1168,153l-1167,-153h-1c-6,0,-10,4,-11,10l-2,23c-1,6,4,11,10,11z",
  802. widecheck3: "M1181,280h2l1171,-236c6,0,10,-5,10,-11l-2,-23c-1,-6,-5,-10,\n-11,-10h-1l-1168,213l-1167,-213h-1c-6,0,-10,4,-11,10l-2,23c-1,6,4,11,10,11z",
  803. widecheck4: "M1181,340h2l1171,-296c6,0,10,-5,10,-11l-2,-23c-1,-6,-5,-10,\n-11,-10h-1l-1168,273l-1167,-273h-1c-6,0,-10,4,-11,10l-2,23c-1,6,4,11,10,11z",
  804. // The next ten paths support reaction arrows from the mhchem package.
  805. // Arrows for \ce{<-->} are offset from xAxis by 0.22ex, per mhchem in LaTeX
  806. // baraboveleftarrow is mostly from from glyph U+2190 in font KaTeX Main
  807. baraboveleftarrow: "M400000 620h-399890l3 -3c68.7 -52.7 113.7 -120 135 -202\nc4 -14.7 6 -23 6 -25c0 -7.3 -7 -11 -21 -11c-8 0 -13.2 0.8 -15.5 2.5\nc-2.3 1.7 -4.2 5.8 -5.5 12.5c-1.3 4.7 -2.7 10.3 -4 17c-12 48.7 -34.8 92 -68.5 130\ns-74.2 66.3 -121.5 85c-10 4 -16 7.7 -18 11c0 8.7 6 14.3 18 17c47.3 18.7 87.8 47\n121.5 85s56.5 81.3 68.5 130c0.7 2 1.3 5 2 9s1.2 6.7 1.5 8c0.3 1.3 1 3.3 2 6\ns2.2 4.5 3.5 5.5c1.3 1 3.3 1.8 6 2.5s6 1 10 1c14 0 21 -3.7 21 -11\nc0 -2 -2 -10.3 -6 -25c-20 -79.3 -65 -146.7 -135 -202l-3 -3h399890z\nM100 620v40h399900v-40z M0 241v40h399900v-40zM0 241v40h399900v-40z",
  808. // rightarrowabovebar is mostly from glyph U+2192, KaTeX Main
  809. rightarrowabovebar: "M0 241v40h399891c-47.3 35.3-84 78-110 128-16.7 32\n-27.7 63.7-33 95 0 1.3-.2 2.7-.5 4-.3 1.3-.5 2.3-.5 3 0 7.3 6.7 11 20 11 8 0\n13.2-.8 15.5-2.5 2.3-1.7 4.2-5.5 5.5-11.5 2-13.3 5.7-27 11-41 14.7-44.7 39\n-84.5 73-119.5s73.7-60.2 119-75.5c6-2 9-5.7 9-11s-3-9-9-11c-45.3-15.3-85-40.5\n-119-75.5s-58.3-74.8-73-119.5c-4.7-14-8.3-27.3-11-40-1.3-6.7-3.2-10.8-5.5\n-12.5-2.3-1.7-7.5-2.5-15.5-2.5-14 0-21 3.7-21 11 0 2 2 10.3 6 25 20.7 83.3 67\n151.7 139 205zm96 379h399894v40H0zm0 0h399904v40H0z",
  810. // The short left harpoon has 0.5em (i.e. 500 units) kern on the left end.
  811. // Ref from mhchem.sty: \rlap{\raisebox{-.22ex}{$\kern0.5em
  812. baraboveshortleftharpoon: "M507,435c-4,4,-6.3,8.7,-7,14c0,5.3,0.7,9,2,11\nc1.3,2,5.3,5.3,12,10c90.7,54,156,130,196,228c3.3,10.7,6.3,16.3,9,17\nc2,0.7,5,1,9,1c0,0,5,0,5,0c10.7,0,16.7,-2,18,-6c2,-2.7,1,-9.7,-3,-21\nc-32,-87.3,-82.7,-157.7,-152,-211c0,0,-3,-3,-3,-3l399351,0l0,-40\nc-398570,0,-399437,0,-399437,0z M593 435 v40 H399500 v-40z\nM0 281 v-40 H399908 v40z M0 281 v-40 H399908 v40z",
  813. rightharpoonaboveshortbar: "M0,241 l0,40c399126,0,399993,0,399993,0\nc4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,\n-231c-3.3,-9.3,-6,-14.7,-8,-16c-2,-1.3,-7,-2,-15,-2c-10.7,0,-16.7,2,-18,6\nc-2,2.7,-1,9.7,3,21c15.3,42,36.7,81.8,64,119.5c27.3,37.7,58,69.2,92,94.5z\nM0 241 v40 H399908 v-40z M0 475 v-40 H399500 v40z M0 475 v-40 H399500 v40z",
  814. shortbaraboveleftharpoon: "M7,435c-4,4,-6.3,8.7,-7,14c0,5.3,0.7,9,2,11\nc1.3,2,5.3,5.3,12,10c90.7,54,156,130,196,228c3.3,10.7,6.3,16.3,9,17c2,0.7,5,1,9,\n1c0,0,5,0,5,0c10.7,0,16.7,-2,18,-6c2,-2.7,1,-9.7,-3,-21c-32,-87.3,-82.7,-157.7,\n-152,-211c0,0,-3,-3,-3,-3l399907,0l0,-40c-399126,0,-399993,0,-399993,0z\nM93 435 v40 H400000 v-40z M500 241 v40 H400000 v-40z M500 241 v40 H400000 v-40z",
  815. shortrightharpoonabovebar: "M53,241l0,40c398570,0,399437,0,399437,0\nc4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,\n-231c-3.3,-9.3,-6,-14.7,-8,-16c-2,-1.3,-7,-2,-15,-2c-10.7,0,-16.7,2,-18,6\nc-2,2.7,-1,9.7,3,21c15.3,42,36.7,81.8,64,119.5c27.3,37.7,58,69.2,92,94.5z\nM500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z"
  816. };
  817. /**
  818. * This node represents a document fragment, which contains elements, but when
  819. * placed into the DOM doesn't have any representation itself. It only contains
  820. * children and doesn't have any DOM node properties.
  821. */
  822. class DocumentFragment {
  823. // HtmlDomNode
  824. // Never used; needed for satisfying interface.
  825. constructor(children) {
  826. this.children = void 0;
  827. this.classes = void 0;
  828. this.height = void 0;
  829. this.depth = void 0;
  830. this.maxFontSize = void 0;
  831. this.style = void 0;
  832. this.children = children;
  833. this.classes = [];
  834. this.height = 0;
  835. this.depth = 0;
  836. this.maxFontSize = 0;
  837. this.style = {};
  838. }
  839. hasClass(className) {
  840. return utils.contains(this.classes, className);
  841. }
  842. /** Convert the fragment into a node. */
  843. toNode() {
  844. var frag = document.createDocumentFragment();
  845. for (var i = 0; i < this.children.length; i++) {
  846. frag.appendChild(this.children[i].toNode());
  847. }
  848. return frag;
  849. }
  850. /** Convert the fragment into HTML markup. */
  851. toMarkup() {
  852. var markup = ""; // Simply concatenate the markup for the children together.
  853. for (var i = 0; i < this.children.length; i++) {
  854. markup += this.children[i].toMarkup();
  855. }
  856. return markup;
  857. }
  858. /**
  859. * Converts the math node into a string, similar to innerText. Applies to
  860. * MathDomNode's only.
  861. */
  862. toText() {
  863. // To avoid this, we would subclass documentFragment separately for
  864. // MathML, but polyfills for subclassing is expensive per PR 1469.
  865. // $FlowFixMe: Only works for ChildType = MathDomNode.
  866. var toText = child => child.toText();
  867. return this.children.map(toText).join("");
  868. }
  869. }
  870. // This file is GENERATED by buildMetrics.sh. DO NOT MODIFY.
  871. var fontMetricsData = {
  872. "AMS-Regular": {
  873. "32": [0, 0, 0, 0, 0.25],
  874. "65": [0, 0.68889, 0, 0, 0.72222],
  875. "66": [0, 0.68889, 0, 0, 0.66667],
  876. "67": [0, 0.68889, 0, 0, 0.72222],
  877. "68": [0, 0.68889, 0, 0, 0.72222],
  878. "69": [0, 0.68889, 0, 0, 0.66667],
  879. "70": [0, 0.68889, 0, 0, 0.61111],
  880. "71": [0, 0.68889, 0, 0, 0.77778],
  881. "72": [0, 0.68889, 0, 0, 0.77778],
  882. "73": [0, 0.68889, 0, 0, 0.38889],
  883. "74": [0.16667, 0.68889, 0, 0, 0.5],
  884. "75": [0, 0.68889, 0, 0, 0.77778],
  885. "76": [0, 0.68889, 0, 0, 0.66667],
  886. "77": [0, 0.68889, 0, 0, 0.94445],
  887. "78": [0, 0.68889, 0, 0, 0.72222],
  888. "79": [0.16667, 0.68889, 0, 0, 0.77778],
  889. "80": [0, 0.68889, 0, 0, 0.61111],
  890. "81": [0.16667, 0.68889, 0, 0, 0.77778],
  891. "82": [0, 0.68889, 0, 0, 0.72222],
  892. "83": [0, 0.68889, 0, 0, 0.55556],
  893. "84": [0, 0.68889, 0, 0, 0.66667],
  894. "85": [0, 0.68889, 0, 0, 0.72222],
  895. "86": [0, 0.68889, 0, 0, 0.72222],
  896. "87": [0, 0.68889, 0, 0, 1.0],
  897. "88": [0, 0.68889, 0, 0, 0.72222],
  898. "89": [0, 0.68889, 0, 0, 0.72222],
  899. "90": [0, 0.68889, 0, 0, 0.66667],
  900. "107": [0, 0.68889, 0, 0, 0.55556],
  901. "160": [0, 0, 0, 0, 0.25],
  902. "165": [0, 0.675, 0.025, 0, 0.75],
  903. "174": [0.15559, 0.69224, 0, 0, 0.94666],
  904. "240": [0, 0.68889, 0, 0, 0.55556],
  905. "295": [0, 0.68889, 0, 0, 0.54028],
  906. "710": [0, 0.825, 0, 0, 2.33334],
  907. "732": [0, 0.9, 0, 0, 2.33334],
  908. "770": [0, 0.825, 0, 0, 2.33334],
  909. "771": [0, 0.9, 0, 0, 2.33334],
  910. "989": [0.08167, 0.58167, 0, 0, 0.77778],
  911. "1008": [0, 0.43056, 0.04028, 0, 0.66667],
  912. "8245": [0, 0.54986, 0, 0, 0.275],
  913. "8463": [0, 0.68889, 0, 0, 0.54028],
  914. "8487": [0, 0.68889, 0, 0, 0.72222],
  915. "8498": [0, 0.68889, 0, 0, 0.55556],
  916. "8502": [0, 0.68889, 0, 0, 0.66667],
  917. "8503": [0, 0.68889, 0, 0, 0.44445],
  918. "8504": [0, 0.68889, 0, 0, 0.66667],
  919. "8513": [0, 0.68889, 0, 0, 0.63889],
  920. "8592": [-0.03598, 0.46402, 0, 0, 0.5],
  921. "8594": [-0.03598, 0.46402, 0, 0, 0.5],
  922. "8602": [-0.13313, 0.36687, 0, 0, 1.0],
  923. "8603": [-0.13313, 0.36687, 0, 0, 1.0],
  924. "8606": [0.01354, 0.52239, 0, 0, 1.0],
  925. "8608": [0.01354, 0.52239, 0, 0, 1.0],
  926. "8610": [0.01354, 0.52239, 0, 0, 1.11111],
  927. "8611": [0.01354, 0.52239, 0, 0, 1.11111],
  928. "8619": [0, 0.54986, 0, 0, 1.0],
  929. "8620": [0, 0.54986, 0, 0, 1.0],
  930. "8621": [-0.13313, 0.37788, 0, 0, 1.38889],
  931. "8622": [-0.13313, 0.36687, 0, 0, 1.0],
  932. "8624": [0, 0.69224, 0, 0, 0.5],
  933. "8625": [0, 0.69224, 0, 0, 0.5],
  934. "8630": [0, 0.43056, 0, 0, 1.0],
  935. "8631": [0, 0.43056, 0, 0, 1.0],
  936. "8634": [0.08198, 0.58198, 0, 0, 0.77778],
  937. "8635": [0.08198, 0.58198, 0, 0, 0.77778],
  938. "8638": [0.19444, 0.69224, 0, 0, 0.41667],
  939. "8639": [0.19444, 0.69224, 0, 0, 0.41667],
  940. "8642": [0.19444, 0.69224, 0, 0, 0.41667],
  941. "8643": [0.19444, 0.69224, 0, 0, 0.41667],
  942. "8644": [0.1808, 0.675, 0, 0, 1.0],
  943. "8646": [0.1808, 0.675, 0, 0, 1.0],
  944. "8647": [0.1808, 0.675, 0, 0, 1.0],
  945. "8648": [0.19444, 0.69224, 0, 0, 0.83334],
  946. "8649": [0.1808, 0.675, 0, 0, 1.0],
  947. "8650": [0.19444, 0.69224, 0, 0, 0.83334],
  948. "8651": [0.01354, 0.52239, 0, 0, 1.0],
  949. "8652": [0.01354, 0.52239, 0, 0, 1.0],
  950. "8653": [-0.13313, 0.36687, 0, 0, 1.0],
  951. "8654": [-0.13313, 0.36687, 0, 0, 1.0],
  952. "8655": [-0.13313, 0.36687, 0, 0, 1.0],
  953. "8666": [0.13667, 0.63667, 0, 0, 1.0],
  954. "8667": [0.13667, 0.63667, 0, 0, 1.0],
  955. "8669": [-0.13313, 0.37788, 0, 0, 1.0],
  956. "8672": [-0.064, 0.437, 0, 0, 1.334],
  957. "8674": [-0.064, 0.437, 0, 0, 1.334],
  958. "8705": [0, 0.825, 0, 0, 0.5],
  959. "8708": [0, 0.68889, 0, 0, 0.55556],
  960. "8709": [0.08167, 0.58167, 0, 0, 0.77778],
  961. "8717": [0, 0.43056, 0, 0, 0.42917],
  962. "8722": [-0.03598, 0.46402, 0, 0, 0.5],
  963. "8724": [0.08198, 0.69224, 0, 0, 0.77778],
  964. "8726": [0.08167, 0.58167, 0, 0, 0.77778],
  965. "8733": [0, 0.69224, 0, 0, 0.77778],
  966. "8736": [0, 0.69224, 0, 0, 0.72222],
  967. "8737": [0, 0.69224, 0, 0, 0.72222],
  968. "8738": [0.03517, 0.52239, 0, 0, 0.72222],
  969. "8739": [0.08167, 0.58167, 0, 0, 0.22222],
  970. "8740": [0.25142, 0.74111, 0, 0, 0.27778],
  971. "8741": [0.08167, 0.58167, 0, 0, 0.38889],
  972. "8742": [0.25142, 0.74111, 0, 0, 0.5],
  973. "8756": [0, 0.69224, 0, 0, 0.66667],
  974. "8757": [0, 0.69224, 0, 0, 0.66667],
  975. "8764": [-0.13313, 0.36687, 0, 0, 0.77778],
  976. "8765": [-0.13313, 0.37788, 0, 0, 0.77778],
  977. "8769": [-0.13313, 0.36687, 0, 0, 0.77778],
  978. "8770": [-0.03625, 0.46375, 0, 0, 0.77778],
  979. "8774": [0.30274, 0.79383, 0, 0, 0.77778],
  980. "8776": [-0.01688, 0.48312, 0, 0, 0.77778],
  981. "8778": [0.08167, 0.58167, 0, 0, 0.77778],
  982. "8782": [0.06062, 0.54986, 0, 0, 0.77778],
  983. "8783": [0.06062, 0.54986, 0, 0, 0.77778],
  984. "8785": [0.08198, 0.58198, 0, 0, 0.77778],
  985. "8786": [0.08198, 0.58198, 0, 0, 0.77778],
  986. "8787": [0.08198, 0.58198, 0, 0, 0.77778],
  987. "8790": [0, 0.69224, 0, 0, 0.77778],
  988. "8791": [0.22958, 0.72958, 0, 0, 0.77778],
  989. "8796": [0.08198, 0.91667, 0, 0, 0.77778],
  990. "8806": [0.25583, 0.75583, 0, 0, 0.77778],
  991. "8807": [0.25583, 0.75583, 0, 0, 0.77778],
  992. "8808": [0.25142, 0.75726, 0, 0, 0.77778],
  993. "8809": [0.25142, 0.75726, 0, 0, 0.77778],
  994. "8812": [0.25583, 0.75583, 0, 0, 0.5],
  995. "8814": [0.20576, 0.70576, 0, 0, 0.77778],
  996. "8815": [0.20576, 0.70576, 0, 0, 0.77778],
  997. "8816": [0.30274, 0.79383, 0, 0, 0.77778],
  998. "8817": [0.30274, 0.79383, 0, 0, 0.77778],
  999. "8818": [0.22958, 0.72958, 0, 0, 0.77778],
  1000. "8819": [0.22958, 0.72958, 0, 0, 0.77778],
  1001. "8822": [0.1808, 0.675, 0, 0, 0.77778],
  1002. "8823": [0.1808, 0.675, 0, 0, 0.77778],
  1003. "8828": [0.13667, 0.63667, 0, 0, 0.77778],
  1004. "8829": [0.13667, 0.63667, 0, 0, 0.77778],
  1005. "8830": [0.22958, 0.72958, 0, 0, 0.77778],
  1006. "8831": [0.22958, 0.72958, 0, 0, 0.77778],
  1007. "8832": [0.20576, 0.70576, 0, 0, 0.77778],
  1008. "8833": [0.20576, 0.70576, 0, 0, 0.77778],
  1009. "8840": [0.30274, 0.79383, 0, 0, 0.77778],
  1010. "8841": [0.30274, 0.79383, 0, 0, 0.77778],
  1011. "8842": [0.13597, 0.63597, 0, 0, 0.77778],
  1012. "8843": [0.13597, 0.63597, 0, 0, 0.77778],
  1013. "8847": [0.03517, 0.54986, 0, 0, 0.77778],
  1014. "8848": [0.03517, 0.54986, 0, 0, 0.77778],
  1015. "8858": [0.08198, 0.58198, 0, 0, 0.77778],
  1016. "8859": [0.08198, 0.58198, 0, 0, 0.77778],
  1017. "8861": [0.08198, 0.58198, 0, 0, 0.77778],
  1018. "8862": [0, 0.675, 0, 0, 0.77778],
  1019. "8863": [0, 0.675, 0, 0, 0.77778],
  1020. "8864": [0, 0.675, 0, 0, 0.77778],
  1021. "8865": [0, 0.675, 0, 0, 0.77778],
  1022. "8872": [0, 0.69224, 0, 0, 0.61111],
  1023. "8873": [0, 0.69224, 0, 0, 0.72222],
  1024. "8874": [0, 0.69224, 0, 0, 0.88889],
  1025. "8876": [0, 0.68889, 0, 0, 0.61111],
  1026. "8877": [0, 0.68889, 0, 0, 0.61111],
  1027. "8878": [0, 0.68889, 0, 0, 0.72222],
  1028. "8879": [0, 0.68889, 0, 0, 0.72222],
  1029. "8882": [0.03517, 0.54986, 0, 0, 0.77778],
  1030. "8883": [0.03517, 0.54986, 0, 0, 0.77778],
  1031. "8884": [0.13667, 0.63667, 0, 0, 0.77778],
  1032. "8885": [0.13667, 0.63667, 0, 0, 0.77778],
  1033. "8888": [0, 0.54986, 0, 0, 1.11111],
  1034. "8890": [0.19444, 0.43056, 0, 0, 0.55556],
  1035. "8891": [0.19444, 0.69224, 0, 0, 0.61111],
  1036. "8892": [0.19444, 0.69224, 0, 0, 0.61111],
  1037. "8901": [0, 0.54986, 0, 0, 0.27778],
  1038. "8903": [0.08167, 0.58167, 0, 0, 0.77778],
  1039. "8905": [0.08167, 0.58167, 0, 0, 0.77778],
  1040. "8906": [0.08167, 0.58167, 0, 0, 0.77778],
  1041. "8907": [0, 0.69224, 0, 0, 0.77778],
  1042. "8908": [0, 0.69224, 0, 0, 0.77778],
  1043. "8909": [-0.03598, 0.46402, 0, 0, 0.77778],
  1044. "8910": [0, 0.54986, 0, 0, 0.76042],
  1045. "8911": [0, 0.54986, 0, 0, 0.76042],
  1046. "8912": [0.03517, 0.54986, 0, 0, 0.77778],
  1047. "8913": [0.03517, 0.54986, 0, 0, 0.77778],
  1048. "8914": [0, 0.54986, 0, 0, 0.66667],
  1049. "8915": [0, 0.54986, 0, 0, 0.66667],
  1050. "8916": [0, 0.69224, 0, 0, 0.66667],
  1051. "8918": [0.0391, 0.5391, 0, 0, 0.77778],
  1052. "8919": [0.0391, 0.5391, 0, 0, 0.77778],
  1053. "8920": [0.03517, 0.54986, 0, 0, 1.33334],
  1054. "8921": [0.03517, 0.54986, 0, 0, 1.33334],
  1055. "8922": [0.38569, 0.88569, 0, 0, 0.77778],
  1056. "8923": [0.38569, 0.88569, 0, 0, 0.77778],
  1057. "8926": [0.13667, 0.63667, 0, 0, 0.77778],
  1058. "8927": [0.13667, 0.63667, 0, 0, 0.77778],
  1059. "8928": [0.30274, 0.79383, 0, 0, 0.77778],
  1060. "8929": [0.30274, 0.79383, 0, 0, 0.77778],
  1061. "8934": [0.23222, 0.74111, 0, 0, 0.77778],
  1062. "8935": [0.23222, 0.74111, 0, 0, 0.77778],
  1063. "8936": [0.23222, 0.74111, 0, 0, 0.77778],
  1064. "8937": [0.23222, 0.74111, 0, 0, 0.77778],
  1065. "8938": [0.20576, 0.70576, 0, 0, 0.77778],
  1066. "8939": [0.20576, 0.70576, 0, 0, 0.77778],
  1067. "8940": [0.30274, 0.79383, 0, 0, 0.77778],
  1068. "8941": [0.30274, 0.79383, 0, 0, 0.77778],
  1069. "8994": [0.19444, 0.69224, 0, 0, 0.77778],
  1070. "8995": [0.19444, 0.69224, 0, 0, 0.77778],
  1071. "9416": [0.15559, 0.69224, 0, 0, 0.90222],
  1072. "9484": [0, 0.69224, 0, 0, 0.5],
  1073. "9488": [0, 0.69224, 0, 0, 0.5],
  1074. "9492": [0, 0.37788, 0, 0, 0.5],
  1075. "9496": [0, 0.37788, 0, 0, 0.5],
  1076. "9585": [0.19444, 0.68889, 0, 0, 0.88889],
  1077. "9586": [0.19444, 0.74111, 0, 0, 0.88889],
  1078. "9632": [0, 0.675, 0, 0, 0.77778],
  1079. "9633": [0, 0.675, 0, 0, 0.77778],
  1080. "9650": [0, 0.54986, 0, 0, 0.72222],
  1081. "9651": [0, 0.54986, 0, 0, 0.72222],
  1082. "9654": [0.03517, 0.54986, 0, 0, 0.77778],
  1083. "9660": [0, 0.54986, 0, 0, 0.72222],
  1084. "9661": [0, 0.54986, 0, 0, 0.72222],
  1085. "9664": [0.03517, 0.54986, 0, 0, 0.77778],
  1086. "9674": [0.11111, 0.69224, 0, 0, 0.66667],
  1087. "9733": [0.19444, 0.69224, 0, 0, 0.94445],
  1088. "10003": [0, 0.69224, 0, 0, 0.83334],
  1089. "10016": [0, 0.69224, 0, 0, 0.83334],
  1090. "10731": [0.11111, 0.69224, 0, 0, 0.66667],
  1091. "10846": [0.19444, 0.75583, 0, 0, 0.61111],
  1092. "10877": [0.13667, 0.63667, 0, 0, 0.77778],
  1093. "10878": [0.13667, 0.63667, 0, 0, 0.77778],
  1094. "10885": [0.25583, 0.75583, 0, 0, 0.77778],
  1095. "10886": [0.25583, 0.75583, 0, 0, 0.77778],
  1096. "10887": [0.13597, 0.63597, 0, 0, 0.77778],
  1097. "10888": [0.13597, 0.63597, 0, 0, 0.77778],
  1098. "10889": [0.26167, 0.75726, 0, 0, 0.77778],
  1099. "10890": [0.26167, 0.75726, 0, 0, 0.77778],
  1100. "10891": [0.48256, 0.98256, 0, 0, 0.77778],
  1101. "10892": [0.48256, 0.98256, 0, 0, 0.77778],
  1102. "10901": [0.13667, 0.63667, 0, 0, 0.77778],
  1103. "10902": [0.13667, 0.63667, 0, 0, 0.77778],
  1104. "10933": [0.25142, 0.75726, 0, 0, 0.77778],
  1105. "10934": [0.25142, 0.75726, 0, 0, 0.77778],
  1106. "10935": [0.26167, 0.75726, 0, 0, 0.77778],
  1107. "10936": [0.26167, 0.75726, 0, 0, 0.77778],
  1108. "10937": [0.26167, 0.75726, 0, 0, 0.77778],
  1109. "10938": [0.26167, 0.75726, 0, 0, 0.77778],
  1110. "10949": [0.25583, 0.75583, 0, 0, 0.77778],
  1111. "10950": [0.25583, 0.75583, 0, 0, 0.77778],
  1112. "10955": [0.28481, 0.79383, 0, 0, 0.77778],
  1113. "10956": [0.28481, 0.79383, 0, 0, 0.77778],
  1114. "57350": [0.08167, 0.58167, 0, 0, 0.22222],
  1115. "57351": [0.08167, 0.58167, 0, 0, 0.38889],
  1116. "57352": [0.08167, 0.58167, 0, 0, 0.77778],
  1117. "57353": [0, 0.43056, 0.04028, 0, 0.66667],
  1118. "57356": [0.25142, 0.75726, 0, 0, 0.77778],
  1119. "57357": [0.25142, 0.75726, 0, 0, 0.77778],
  1120. "57358": [0.41951, 0.91951, 0, 0, 0.77778],
  1121. "57359": [0.30274, 0.79383, 0, 0, 0.77778],
  1122. "57360": [0.30274, 0.79383, 0, 0, 0.77778],
  1123. "57361": [0.41951, 0.91951, 0, 0, 0.77778],
  1124. "57366": [0.25142, 0.75726, 0, 0, 0.77778],
  1125. "57367": [0.25142, 0.75726, 0, 0, 0.77778],
  1126. "57368": [0.25142, 0.75726, 0, 0, 0.77778],
  1127. "57369": [0.25142, 0.75726, 0, 0, 0.77778],
  1128. "57370": [0.13597, 0.63597, 0, 0, 0.77778],
  1129. "57371": [0.13597, 0.63597, 0, 0, 0.77778]
  1130. },
  1131. "Caligraphic-Regular": {
  1132. "32": [0, 0, 0, 0, 0.25],
  1133. "65": [0, 0.68333, 0, 0.19445, 0.79847],
  1134. "66": [0, 0.68333, 0.03041, 0.13889, 0.65681],
  1135. "67": [0, 0.68333, 0.05834, 0.13889, 0.52653],
  1136. "68": [0, 0.68333, 0.02778, 0.08334, 0.77139],
  1137. "69": [0, 0.68333, 0.08944, 0.11111, 0.52778],
  1138. "70": [0, 0.68333, 0.09931, 0.11111, 0.71875],
  1139. "71": [0.09722, 0.68333, 0.0593, 0.11111, 0.59487],
  1140. "72": [0, 0.68333, 0.00965, 0.11111, 0.84452],
  1141. "73": [0, 0.68333, 0.07382, 0, 0.54452],
  1142. "74": [0.09722, 0.68333, 0.18472, 0.16667, 0.67778],
  1143. "75": [0, 0.68333, 0.01445, 0.05556, 0.76195],
  1144. "76": [0, 0.68333, 0, 0.13889, 0.68972],
  1145. "77": [0, 0.68333, 0, 0.13889, 1.2009],
  1146. "78": [0, 0.68333, 0.14736, 0.08334, 0.82049],
  1147. "79": [0, 0.68333, 0.02778, 0.11111, 0.79611],
  1148. "80": [0, 0.68333, 0.08222, 0.08334, 0.69556],
  1149. "81": [0.09722, 0.68333, 0, 0.11111, 0.81667],
  1150. "82": [0, 0.68333, 0, 0.08334, 0.8475],
  1151. "83": [0, 0.68333, 0.075, 0.13889, 0.60556],
  1152. "84": [0, 0.68333, 0.25417, 0, 0.54464],
  1153. "85": [0, 0.68333, 0.09931, 0.08334, 0.62583],
  1154. "86": [0, 0.68333, 0.08222, 0, 0.61278],
  1155. "87": [0, 0.68333, 0.08222, 0.08334, 0.98778],
  1156. "88": [0, 0.68333, 0.14643, 0.13889, 0.7133],
  1157. "89": [0.09722, 0.68333, 0.08222, 0.08334, 0.66834],
  1158. "90": [0, 0.68333, 0.07944, 0.13889, 0.72473],
  1159. "160": [0, 0, 0, 0, 0.25]
  1160. },
  1161. "Fraktur-Regular": {
  1162. "32": [0, 0, 0, 0, 0.25],
  1163. "33": [0, 0.69141, 0, 0, 0.29574],
  1164. "34": [0, 0.69141, 0, 0, 0.21471],
  1165. "38": [0, 0.69141, 0, 0, 0.73786],
  1166. "39": [0, 0.69141, 0, 0, 0.21201],
  1167. "40": [0.24982, 0.74947, 0, 0, 0.38865],
  1168. "41": [0.24982, 0.74947, 0, 0, 0.38865],
  1169. "42": [0, 0.62119, 0, 0, 0.27764],
  1170. "43": [0.08319, 0.58283, 0, 0, 0.75623],
  1171. "44": [0, 0.10803, 0, 0, 0.27764],
  1172. "45": [0.08319, 0.58283, 0, 0, 0.75623],
  1173. "46": [0, 0.10803, 0, 0, 0.27764],
  1174. "47": [0.24982, 0.74947, 0, 0, 0.50181],
  1175. "48": [0, 0.47534, 0, 0, 0.50181],
  1176. "49": [0, 0.47534, 0, 0, 0.50181],
  1177. "50": [0, 0.47534, 0, 0, 0.50181],
  1178. "51": [0.18906, 0.47534, 0, 0, 0.50181],
  1179. "52": [0.18906, 0.47534, 0, 0, 0.50181],
  1180. "53": [0.18906, 0.47534, 0, 0, 0.50181],
  1181. "54": [0, 0.69141, 0, 0, 0.50181],
  1182. "55": [0.18906, 0.47534, 0, 0, 0.50181],
  1183. "56": [0, 0.69141, 0, 0, 0.50181],
  1184. "57": [0.18906, 0.47534, 0, 0, 0.50181],
  1185. "58": [0, 0.47534, 0, 0, 0.21606],
  1186. "59": [0.12604, 0.47534, 0, 0, 0.21606],
  1187. "61": [-0.13099, 0.36866, 0, 0, 0.75623],
  1188. "63": [0, 0.69141, 0, 0, 0.36245],
  1189. "65": [0, 0.69141, 0, 0, 0.7176],
  1190. "66": [0, 0.69141, 0, 0, 0.88397],
  1191. "67": [0, 0.69141, 0, 0, 0.61254],
  1192. "68": [0, 0.69141, 0, 0, 0.83158],
  1193. "69": [0, 0.69141, 0, 0, 0.66278],
  1194. "70": [0.12604, 0.69141, 0, 0, 0.61119],
  1195. "71": [0, 0.69141, 0, 0, 0.78539],
  1196. "72": [0.06302, 0.69141, 0, 0, 0.7203],
  1197. "73": [0, 0.69141, 0, 0, 0.55448],
  1198. "74": [0.12604, 0.69141, 0, 0, 0.55231],
  1199. "75": [0, 0.69141, 0, 0, 0.66845],
  1200. "76": [0, 0.69141, 0, 0, 0.66602],
  1201. "77": [0, 0.69141, 0, 0, 1.04953],
  1202. "78": [0, 0.69141, 0, 0, 0.83212],
  1203. "79": [0, 0.69141, 0, 0, 0.82699],
  1204. "80": [0.18906, 0.69141, 0, 0, 0.82753],
  1205. "81": [0.03781, 0.69141, 0, 0, 0.82699],
  1206. "82": [0, 0.69141, 0, 0, 0.82807],
  1207. "83": [0, 0.69141, 0, 0, 0.82861],
  1208. "84": [0, 0.69141, 0, 0, 0.66899],
  1209. "85": [0, 0.69141, 0, 0, 0.64576],
  1210. "86": [0, 0.69141, 0, 0, 0.83131],
  1211. "87": [0, 0.69141, 0, 0, 1.04602],
  1212. "88": [0, 0.69141, 0, 0, 0.71922],
  1213. "89": [0.18906, 0.69141, 0, 0, 0.83293],
  1214. "90": [0.12604, 0.69141, 0, 0, 0.60201],
  1215. "91": [0.24982, 0.74947, 0, 0, 0.27764],
  1216. "93": [0.24982, 0.74947, 0, 0, 0.27764],
  1217. "94": [0, 0.69141, 0, 0, 0.49965],
  1218. "97": [0, 0.47534, 0, 0, 0.50046],
  1219. "98": [0, 0.69141, 0, 0, 0.51315],
  1220. "99": [0, 0.47534, 0, 0, 0.38946],
  1221. "100": [0, 0.62119, 0, 0, 0.49857],
  1222. "101": [0, 0.47534, 0, 0, 0.40053],
  1223. "102": [0.18906, 0.69141, 0, 0, 0.32626],
  1224. "103": [0.18906, 0.47534, 0, 0, 0.5037],
  1225. "104": [0.18906, 0.69141, 0, 0, 0.52126],
  1226. "105": [0, 0.69141, 0, 0, 0.27899],
  1227. "106": [0, 0.69141, 0, 0, 0.28088],
  1228. "107": [0, 0.69141, 0, 0, 0.38946],
  1229. "108": [0, 0.69141, 0, 0, 0.27953],
  1230. "109": [0, 0.47534, 0, 0, 0.76676],
  1231. "110": [0, 0.47534, 0, 0, 0.52666],
  1232. "111": [0, 0.47534, 0, 0, 0.48885],
  1233. "112": [0.18906, 0.52396, 0, 0, 0.50046],
  1234. "113": [0.18906, 0.47534, 0, 0, 0.48912],
  1235. "114": [0, 0.47534, 0, 0, 0.38919],
  1236. "115": [0, 0.47534, 0, 0, 0.44266],
  1237. "116": [0, 0.62119, 0, 0, 0.33301],
  1238. "117": [0, 0.47534, 0, 0, 0.5172],
  1239. "118": [0, 0.52396, 0, 0, 0.5118],
  1240. "119": [0, 0.52396, 0, 0, 0.77351],
  1241. "120": [0.18906, 0.47534, 0, 0, 0.38865],
  1242. "121": [0.18906, 0.47534, 0, 0, 0.49884],
  1243. "122": [0.18906, 0.47534, 0, 0, 0.39054],
  1244. "160": [0, 0, 0, 0, 0.25],
  1245. "8216": [0, 0.69141, 0, 0, 0.21471],
  1246. "8217": [0, 0.69141, 0, 0, 0.21471],
  1247. "58112": [0, 0.62119, 0, 0, 0.49749],
  1248. "58113": [0, 0.62119, 0, 0, 0.4983],
  1249. "58114": [0.18906, 0.69141, 0, 0, 0.33328],
  1250. "58115": [0.18906, 0.69141, 0, 0, 0.32923],
  1251. "58116": [0.18906, 0.47534, 0, 0, 0.50343],
  1252. "58117": [0, 0.69141, 0, 0, 0.33301],
  1253. "58118": [0, 0.62119, 0, 0, 0.33409],
  1254. "58119": [0, 0.47534, 0, 0, 0.50073]
  1255. },
  1256. "Main-Bold": {
  1257. "32": [0, 0, 0, 0, 0.25],
  1258. "33": [0, 0.69444, 0, 0, 0.35],
  1259. "34": [0, 0.69444, 0, 0, 0.60278],
  1260. "35": [0.19444, 0.69444, 0, 0, 0.95833],
  1261. "36": [0.05556, 0.75, 0, 0, 0.575],
  1262. "37": [0.05556, 0.75, 0, 0, 0.95833],
  1263. "38": [0, 0.69444, 0, 0, 0.89444],
  1264. "39": [0, 0.69444, 0, 0, 0.31944],
  1265. "40": [0.25, 0.75, 0, 0, 0.44722],
  1266. "41": [0.25, 0.75, 0, 0, 0.44722],
  1267. "42": [0, 0.75, 0, 0, 0.575],
  1268. "43": [0.13333, 0.63333, 0, 0, 0.89444],
  1269. "44": [0.19444, 0.15556, 0, 0, 0.31944],
  1270. "45": [0, 0.44444, 0, 0, 0.38333],
  1271. "46": [0, 0.15556, 0, 0, 0.31944],
  1272. "47": [0.25, 0.75, 0, 0, 0.575],
  1273. "48": [0, 0.64444, 0, 0, 0.575],
  1274. "49": [0, 0.64444, 0, 0, 0.575],
  1275. "50": [0, 0.64444, 0, 0, 0.575],
  1276. "51": [0, 0.64444, 0, 0, 0.575],
  1277. "52": [0, 0.64444, 0, 0, 0.575],
  1278. "53": [0, 0.64444, 0, 0, 0.575],
  1279. "54": [0, 0.64444, 0, 0, 0.575],
  1280. "55": [0, 0.64444, 0, 0, 0.575],
  1281. "56": [0, 0.64444, 0, 0, 0.575],
  1282. "57": [0, 0.64444, 0, 0, 0.575],
  1283. "58": [0, 0.44444, 0, 0, 0.31944],
  1284. "59": [0.19444, 0.44444, 0, 0, 0.31944],
  1285. "60": [0.08556, 0.58556, 0, 0, 0.89444],
  1286. "61": [-0.10889, 0.39111, 0, 0, 0.89444],
  1287. "62": [0.08556, 0.58556, 0, 0, 0.89444],
  1288. "63": [0, 0.69444, 0, 0, 0.54305],
  1289. "64": [0, 0.69444, 0, 0, 0.89444],
  1290. "65": [0, 0.68611, 0, 0, 0.86944],
  1291. "66": [0, 0.68611, 0, 0, 0.81805],
  1292. "67": [0, 0.68611, 0, 0, 0.83055],
  1293. "68": [0, 0.68611, 0, 0, 0.88194],
  1294. "69": [0, 0.68611, 0, 0, 0.75555],
  1295. "70": [0, 0.68611, 0, 0, 0.72361],
  1296. "71": [0, 0.68611, 0, 0, 0.90416],
  1297. "72": [0, 0.68611, 0, 0, 0.9],
  1298. "73": [0, 0.68611, 0, 0, 0.43611],
  1299. "74": [0, 0.68611, 0, 0, 0.59444],
  1300. "75": [0, 0.68611, 0, 0, 0.90138],
  1301. "76": [0, 0.68611, 0, 0, 0.69166],
  1302. "77": [0, 0.68611, 0, 0, 1.09166],
  1303. "78": [0, 0.68611, 0, 0, 0.9],
  1304. "79": [0, 0.68611, 0, 0, 0.86388],
  1305. "80": [0, 0.68611, 0, 0, 0.78611],
  1306. "81": [0.19444, 0.68611, 0, 0, 0.86388],
  1307. "82": [0, 0.68611, 0, 0, 0.8625],
  1308. "83": [0, 0.68611, 0, 0, 0.63889],
  1309. "84": [0, 0.68611, 0, 0, 0.8],
  1310. "85": [0, 0.68611, 0, 0, 0.88472],
  1311. "86": [0, 0.68611, 0.01597, 0, 0.86944],
  1312. "87": [0, 0.68611, 0.01597, 0, 1.18888],
  1313. "88": [0, 0.68611, 0, 0, 0.86944],
  1314. "89": [0, 0.68611, 0.02875, 0, 0.86944],
  1315. "90": [0, 0.68611, 0, 0, 0.70277],
  1316. "91": [0.25, 0.75, 0, 0, 0.31944],
  1317. "92": [0.25, 0.75, 0, 0, 0.575],
  1318. "93": [0.25, 0.75, 0, 0, 0.31944],
  1319. "94": [0, 0.69444, 0, 0, 0.575],
  1320. "95": [0.31, 0.13444, 0.03194, 0, 0.575],
  1321. "97": [0, 0.44444, 0, 0, 0.55902],
  1322. "98": [0, 0.69444, 0, 0, 0.63889],
  1323. "99": [0, 0.44444, 0, 0, 0.51111],
  1324. "100": [0, 0.69444, 0, 0, 0.63889],
  1325. "101": [0, 0.44444, 0, 0, 0.52708],
  1326. "102": [0, 0.69444, 0.10903, 0, 0.35139],
  1327. "103": [0.19444, 0.44444, 0.01597, 0, 0.575],
  1328. "104": [0, 0.69444, 0, 0, 0.63889],
  1329. "105": [0, 0.69444, 0, 0, 0.31944],
  1330. "106": [0.19444, 0.69444, 0, 0, 0.35139],
  1331. "107": [0, 0.69444, 0, 0, 0.60694],
  1332. "108": [0, 0.69444, 0, 0, 0.31944],
  1333. "109": [0, 0.44444, 0, 0, 0.95833],
  1334. "110": [0, 0.44444, 0, 0, 0.63889],
  1335. "111": [0, 0.44444, 0, 0, 0.575],
  1336. "112": [0.19444, 0.44444, 0, 0, 0.63889],
  1337. "113": [0.19444, 0.44444, 0, 0, 0.60694],
  1338. "114": [0, 0.44444, 0, 0, 0.47361],
  1339. "115": [0, 0.44444, 0, 0, 0.45361],
  1340. "116": [0, 0.63492, 0, 0, 0.44722],
  1341. "117": [0, 0.44444, 0, 0, 0.63889],
  1342. "118": [0, 0.44444, 0.01597, 0, 0.60694],
  1343. "119": [0, 0.44444, 0.01597, 0, 0.83055],
  1344. "120": [0, 0.44444, 0, 0, 0.60694],
  1345. "121": [0.19444, 0.44444, 0.01597, 0, 0.60694],
  1346. "122": [0, 0.44444, 0, 0, 0.51111],
  1347. "123": [0.25, 0.75, 0, 0, 0.575],
  1348. "124": [0.25, 0.75, 0, 0, 0.31944],
  1349. "125": [0.25, 0.75, 0, 0, 0.575],
  1350. "126": [0.35, 0.34444, 0, 0, 0.575],
  1351. "160": [0, 0, 0, 0, 0.25],
  1352. "163": [0, 0.69444, 0, 0, 0.86853],
  1353. "168": [0, 0.69444, 0, 0, 0.575],
  1354. "172": [0, 0.44444, 0, 0, 0.76666],
  1355. "176": [0, 0.69444, 0, 0, 0.86944],
  1356. "177": [0.13333, 0.63333, 0, 0, 0.89444],
  1357. "184": [0.17014, 0, 0, 0, 0.51111],
  1358. "198": [0, 0.68611, 0, 0, 1.04166],
  1359. "215": [0.13333, 0.63333, 0, 0, 0.89444],
  1360. "216": [0.04861, 0.73472, 0, 0, 0.89444],
  1361. "223": [0, 0.69444, 0, 0, 0.59722],
  1362. "230": [0, 0.44444, 0, 0, 0.83055],
  1363. "247": [0.13333, 0.63333, 0, 0, 0.89444],
  1364. "248": [0.09722, 0.54167, 0, 0, 0.575],
  1365. "305": [0, 0.44444, 0, 0, 0.31944],
  1366. "338": [0, 0.68611, 0, 0, 1.16944],
  1367. "339": [0, 0.44444, 0, 0, 0.89444],
  1368. "567": [0.19444, 0.44444, 0, 0, 0.35139],
  1369. "710": [0, 0.69444, 0, 0, 0.575],
  1370. "711": [0, 0.63194, 0, 0, 0.575],
  1371. "713": [0, 0.59611, 0, 0, 0.575],
  1372. "714": [0, 0.69444, 0, 0, 0.575],
  1373. "715": [0, 0.69444, 0, 0, 0.575],
  1374. "728": [0, 0.69444, 0, 0, 0.575],
  1375. "729": [0, 0.69444, 0, 0, 0.31944],
  1376. "730": [0, 0.69444, 0, 0, 0.86944],
  1377. "732": [0, 0.69444, 0, 0, 0.575],
  1378. "733": [0, 0.69444, 0, 0, 0.575],
  1379. "915": [0, 0.68611, 0, 0, 0.69166],
  1380. "916": [0, 0.68611, 0, 0, 0.95833],
  1381. "920": [0, 0.68611, 0, 0, 0.89444],
  1382. "923": [0, 0.68611, 0, 0, 0.80555],
  1383. "926": [0, 0.68611, 0, 0, 0.76666],
  1384. "928": [0, 0.68611, 0, 0, 0.9],
  1385. "931": [0, 0.68611, 0, 0, 0.83055],
  1386. "933": [0, 0.68611, 0, 0, 0.89444],
  1387. "934": [0, 0.68611, 0, 0, 0.83055],
  1388. "936": [0, 0.68611, 0, 0, 0.89444],
  1389. "937": [0, 0.68611, 0, 0, 0.83055],
  1390. "8211": [0, 0.44444, 0.03194, 0, 0.575],
  1391. "8212": [0, 0.44444, 0.03194, 0, 1.14999],
  1392. "8216": [0, 0.69444, 0, 0, 0.31944],
  1393. "8217": [0, 0.69444, 0, 0, 0.31944],
  1394. "8220": [0, 0.69444, 0, 0, 0.60278],
  1395. "8221": [0, 0.69444, 0, 0, 0.60278],
  1396. "8224": [0.19444, 0.69444, 0, 0, 0.51111],
  1397. "8225": [0.19444, 0.69444, 0, 0, 0.51111],
  1398. "8242": [0, 0.55556, 0, 0, 0.34444],
  1399. "8407": [0, 0.72444, 0.15486, 0, 0.575],
  1400. "8463": [0, 0.69444, 0, 0, 0.66759],
  1401. "8465": [0, 0.69444, 0, 0, 0.83055],
  1402. "8467": [0, 0.69444, 0, 0, 0.47361],
  1403. "8472": [0.19444, 0.44444, 0, 0, 0.74027],
  1404. "8476": [0, 0.69444, 0, 0, 0.83055],
  1405. "8501": [0, 0.69444, 0, 0, 0.70277],
  1406. "8592": [-0.10889, 0.39111, 0, 0, 1.14999],
  1407. "8593": [0.19444, 0.69444, 0, 0, 0.575],
  1408. "8594": [-0.10889, 0.39111, 0, 0, 1.14999],
  1409. "8595": [0.19444, 0.69444, 0, 0, 0.575],
  1410. "8596": [-0.10889, 0.39111, 0, 0, 1.14999],
  1411. "8597": [0.25, 0.75, 0, 0, 0.575],
  1412. "8598": [0.19444, 0.69444, 0, 0, 1.14999],
  1413. "8599": [0.19444, 0.69444, 0, 0, 1.14999],
  1414. "8600": [0.19444, 0.69444, 0, 0, 1.14999],
  1415. "8601": [0.19444, 0.69444, 0, 0, 1.14999],
  1416. "8636": [-0.10889, 0.39111, 0, 0, 1.14999],
  1417. "8637": [-0.10889, 0.39111, 0, 0, 1.14999],
  1418. "8640": [-0.10889, 0.39111, 0, 0, 1.14999],
  1419. "8641": [-0.10889, 0.39111, 0, 0, 1.14999],
  1420. "8656": [-0.10889, 0.39111, 0, 0, 1.14999],
  1421. "8657": [0.19444, 0.69444, 0, 0, 0.70277],
  1422. "8658": [-0.10889, 0.39111, 0, 0, 1.14999],
  1423. "8659": [0.19444, 0.69444, 0, 0, 0.70277],
  1424. "8660": [-0.10889, 0.39111, 0, 0, 1.14999],
  1425. "8661": [0.25, 0.75, 0, 0, 0.70277],
  1426. "8704": [0, 0.69444, 0, 0, 0.63889],
  1427. "8706": [0, 0.69444, 0.06389, 0, 0.62847],
  1428. "8707": [0, 0.69444, 0, 0, 0.63889],
  1429. "8709": [0.05556, 0.75, 0, 0, 0.575],
  1430. "8711": [0, 0.68611, 0, 0, 0.95833],
  1431. "8712": [0.08556, 0.58556, 0, 0, 0.76666],
  1432. "8715": [0.08556, 0.58556, 0, 0, 0.76666],
  1433. "8722": [0.13333, 0.63333, 0, 0, 0.89444],
  1434. "8723": [0.13333, 0.63333, 0, 0, 0.89444],
  1435. "8725": [0.25, 0.75, 0, 0, 0.575],
  1436. "8726": [0.25, 0.75, 0, 0, 0.575],
  1437. "8727": [-0.02778, 0.47222, 0, 0, 0.575],
  1438. "8728": [-0.02639, 0.47361, 0, 0, 0.575],
  1439. "8729": [-0.02639, 0.47361, 0, 0, 0.575],
  1440. "8730": [0.18, 0.82, 0, 0, 0.95833],
  1441. "8733": [0, 0.44444, 0, 0, 0.89444],
  1442. "8734": [0, 0.44444, 0, 0, 1.14999],
  1443. "8736": [0, 0.69224, 0, 0, 0.72222],
  1444. "8739": [0.25, 0.75, 0, 0, 0.31944],
  1445. "8741": [0.25, 0.75, 0, 0, 0.575],
  1446. "8743": [0, 0.55556, 0, 0, 0.76666],
  1447. "8744": [0, 0.55556, 0, 0, 0.76666],
  1448. "8745": [0, 0.55556, 0, 0, 0.76666],
  1449. "8746": [0, 0.55556, 0, 0, 0.76666],
  1450. "8747": [0.19444, 0.69444, 0.12778, 0, 0.56875],
  1451. "8764": [-0.10889, 0.39111, 0, 0, 0.89444],
  1452. "8768": [0.19444, 0.69444, 0, 0, 0.31944],
  1453. "8771": [0.00222, 0.50222, 0, 0, 0.89444],
  1454. "8773": [0.027, 0.638, 0, 0, 0.894],
  1455. "8776": [0.02444, 0.52444, 0, 0, 0.89444],
  1456. "8781": [0.00222, 0.50222, 0, 0, 0.89444],
  1457. "8801": [0.00222, 0.50222, 0, 0, 0.89444],
  1458. "8804": [0.19667, 0.69667, 0, 0, 0.89444],
  1459. "8805": [0.19667, 0.69667, 0, 0, 0.89444],
  1460. "8810": [0.08556, 0.58556, 0, 0, 1.14999],
  1461. "8811": [0.08556, 0.58556, 0, 0, 1.14999],
  1462. "8826": [0.08556, 0.58556, 0, 0, 0.89444],
  1463. "8827": [0.08556, 0.58556, 0, 0, 0.89444],
  1464. "8834": [0.08556, 0.58556, 0, 0, 0.89444],
  1465. "8835": [0.08556, 0.58556, 0, 0, 0.89444],
  1466. "8838": [0.19667, 0.69667, 0, 0, 0.89444],
  1467. "8839": [0.19667, 0.69667, 0, 0, 0.89444],
  1468. "8846": [0, 0.55556, 0, 0, 0.76666],
  1469. "8849": [0.19667, 0.69667, 0, 0, 0.89444],
  1470. "8850": [0.19667, 0.69667, 0, 0, 0.89444],
  1471. "8851": [0, 0.55556, 0, 0, 0.76666],
  1472. "8852": [0, 0.55556, 0, 0, 0.76666],
  1473. "8853": [0.13333, 0.63333, 0, 0, 0.89444],
  1474. "8854": [0.13333, 0.63333, 0, 0, 0.89444],
  1475. "8855": [0.13333, 0.63333, 0, 0, 0.89444],
  1476. "8856": [0.13333, 0.63333, 0, 0, 0.89444],
  1477. "8857": [0.13333, 0.63333, 0, 0, 0.89444],
  1478. "8866": [0, 0.69444, 0, 0, 0.70277],
  1479. "8867": [0, 0.69444, 0, 0, 0.70277],
  1480. "8868": [0, 0.69444, 0, 0, 0.89444],
  1481. "8869": [0, 0.69444, 0, 0, 0.89444],
  1482. "8900": [-0.02639, 0.47361, 0, 0, 0.575],
  1483. "8901": [-0.02639, 0.47361, 0, 0, 0.31944],
  1484. "8902": [-0.02778, 0.47222, 0, 0, 0.575],
  1485. "8968": [0.25, 0.75, 0, 0, 0.51111],
  1486. "8969": [0.25, 0.75, 0, 0, 0.51111],
  1487. "8970": [0.25, 0.75, 0, 0, 0.51111],
  1488. "8971": [0.25, 0.75, 0, 0, 0.51111],
  1489. "8994": [-0.13889, 0.36111, 0, 0, 1.14999],
  1490. "8995": [-0.13889, 0.36111, 0, 0, 1.14999],
  1491. "9651": [0.19444, 0.69444, 0, 0, 1.02222],
  1492. "9657": [-0.02778, 0.47222, 0, 0, 0.575],
  1493. "9661": [0.19444, 0.69444, 0, 0, 1.02222],
  1494. "9667": [-0.02778, 0.47222, 0, 0, 0.575],
  1495. "9711": [0.19444, 0.69444, 0, 0, 1.14999],
  1496. "9824": [0.12963, 0.69444, 0, 0, 0.89444],
  1497. "9825": [0.12963, 0.69444, 0, 0, 0.89444],
  1498. "9826": [0.12963, 0.69444, 0, 0, 0.89444],
  1499. "9827": [0.12963, 0.69444, 0, 0, 0.89444],
  1500. "9837": [0, 0.75, 0, 0, 0.44722],
  1501. "9838": [0.19444, 0.69444, 0, 0, 0.44722],
  1502. "9839": [0.19444, 0.69444, 0, 0, 0.44722],
  1503. "10216": [0.25, 0.75, 0, 0, 0.44722],
  1504. "10217": [0.25, 0.75, 0, 0, 0.44722],
  1505. "10815": [0, 0.68611, 0, 0, 0.9],
  1506. "10927": [0.19667, 0.69667, 0, 0, 0.89444],
  1507. "10928": [0.19667, 0.69667, 0, 0, 0.89444],
  1508. "57376": [0.19444, 0.69444, 0, 0, 0]
  1509. },
  1510. "Main-BoldItalic": {
  1511. "32": [0, 0, 0, 0, 0.25],
  1512. "33": [0, 0.69444, 0.11417, 0, 0.38611],
  1513. "34": [0, 0.69444, 0.07939, 0, 0.62055],
  1514. "35": [0.19444, 0.69444, 0.06833, 0, 0.94444],
  1515. "37": [0.05556, 0.75, 0.12861, 0, 0.94444],
  1516. "38": [0, 0.69444, 0.08528, 0, 0.88555],
  1517. "39": [0, 0.69444, 0.12945, 0, 0.35555],
  1518. "40": [0.25, 0.75, 0.15806, 0, 0.47333],
  1519. "41": [0.25, 0.75, 0.03306, 0, 0.47333],
  1520. "42": [0, 0.75, 0.14333, 0, 0.59111],
  1521. "43": [0.10333, 0.60333, 0.03306, 0, 0.88555],
  1522. "44": [0.19444, 0.14722, 0, 0, 0.35555],
  1523. "45": [0, 0.44444, 0.02611, 0, 0.41444],
  1524. "46": [0, 0.14722, 0, 0, 0.35555],
  1525. "47": [0.25, 0.75, 0.15806, 0, 0.59111],
  1526. "48": [0, 0.64444, 0.13167, 0, 0.59111],
  1527. "49": [0, 0.64444, 0.13167, 0, 0.59111],
  1528. "50": [0, 0.64444, 0.13167, 0, 0.59111],
  1529. "51": [0, 0.64444, 0.13167, 0, 0.59111],
  1530. "52": [0.19444, 0.64444, 0.13167, 0, 0.59111],
  1531. "53": [0, 0.64444, 0.13167, 0, 0.59111],
  1532. "54": [0, 0.64444, 0.13167, 0, 0.59111],
  1533. "55": [0.19444, 0.64444, 0.13167, 0, 0.59111],
  1534. "56": [0, 0.64444, 0.13167, 0, 0.59111],
  1535. "57": [0, 0.64444, 0.13167, 0, 0.59111],
  1536. "58": [0, 0.44444, 0.06695, 0, 0.35555],
  1537. "59": [0.19444, 0.44444, 0.06695, 0, 0.35555],
  1538. "61": [-0.10889, 0.39111, 0.06833, 0, 0.88555],
  1539. "63": [0, 0.69444, 0.11472, 0, 0.59111],
  1540. "64": [0, 0.69444, 0.09208, 0, 0.88555],
  1541. "65": [0, 0.68611, 0, 0, 0.86555],
  1542. "66": [0, 0.68611, 0.0992, 0, 0.81666],
  1543. "67": [0, 0.68611, 0.14208, 0, 0.82666],
  1544. "68": [0, 0.68611, 0.09062, 0, 0.87555],
  1545. "69": [0, 0.68611, 0.11431, 0, 0.75666],
  1546. "70": [0, 0.68611, 0.12903, 0, 0.72722],
  1547. "71": [0, 0.68611, 0.07347, 0, 0.89527],
  1548. "72": [0, 0.68611, 0.17208, 0, 0.8961],
  1549. "73": [0, 0.68611, 0.15681, 0, 0.47166],
  1550. "74": [0, 0.68611, 0.145, 0, 0.61055],
  1551. "75": [0, 0.68611, 0.14208, 0, 0.89499],
  1552. "76": [0, 0.68611, 0, 0, 0.69777],
  1553. "77": [0, 0.68611, 0.17208, 0, 1.07277],
  1554. "78": [0, 0.68611, 0.17208, 0, 0.8961],
  1555. "79": [0, 0.68611, 0.09062, 0, 0.85499],
  1556. "80": [0, 0.68611, 0.0992, 0, 0.78721],
  1557. "81": [0.19444, 0.68611, 0.09062, 0, 0.85499],
  1558. "82": [0, 0.68611, 0.02559, 0, 0.85944],
  1559. "83": [0, 0.68611, 0.11264, 0, 0.64999],
  1560. "84": [0, 0.68611, 0.12903, 0, 0.7961],
  1561. "85": [0, 0.68611, 0.17208, 0, 0.88083],
  1562. "86": [0, 0.68611, 0.18625, 0, 0.86555],
  1563. "87": [0, 0.68611, 0.18625, 0, 1.15999],
  1564. "88": [0, 0.68611, 0.15681, 0, 0.86555],
  1565. "89": [0, 0.68611, 0.19803, 0, 0.86555],
  1566. "90": [0, 0.68611, 0.14208, 0, 0.70888],
  1567. "91": [0.25, 0.75, 0.1875, 0, 0.35611],
  1568. "93": [0.25, 0.75, 0.09972, 0, 0.35611],
  1569. "94": [0, 0.69444, 0.06709, 0, 0.59111],
  1570. "95": [0.31, 0.13444, 0.09811, 0, 0.59111],
  1571. "97": [0, 0.44444, 0.09426, 0, 0.59111],
  1572. "98": [0, 0.69444, 0.07861, 0, 0.53222],
  1573. "99": [0, 0.44444, 0.05222, 0, 0.53222],
  1574. "100": [0, 0.69444, 0.10861, 0, 0.59111],
  1575. "101": [0, 0.44444, 0.085, 0, 0.53222],
  1576. "102": [0.19444, 0.69444, 0.21778, 0, 0.4],
  1577. "103": [0.19444, 0.44444, 0.105, 0, 0.53222],
  1578. "104": [0, 0.69444, 0.09426, 0, 0.59111],
  1579. "105": [0, 0.69326, 0.11387, 0, 0.35555],
  1580. "106": [0.19444, 0.69326, 0.1672, 0, 0.35555],
  1581. "107": [0, 0.69444, 0.11111, 0, 0.53222],
  1582. "108": [0, 0.69444, 0.10861, 0, 0.29666],
  1583. "109": [0, 0.44444, 0.09426, 0, 0.94444],
  1584. "110": [0, 0.44444, 0.09426, 0, 0.64999],
  1585. "111": [0, 0.44444, 0.07861, 0, 0.59111],
  1586. "112": [0.19444, 0.44444, 0.07861, 0, 0.59111],
  1587. "113": [0.19444, 0.44444, 0.105, 0, 0.53222],
  1588. "114": [0, 0.44444, 0.11111, 0, 0.50167],
  1589. "115": [0, 0.44444, 0.08167, 0, 0.48694],
  1590. "116": [0, 0.63492, 0.09639, 0, 0.385],
  1591. "117": [0, 0.44444, 0.09426, 0, 0.62055],
  1592. "118": [0, 0.44444, 0.11111, 0, 0.53222],
  1593. "119": [0, 0.44444, 0.11111, 0, 0.76777],
  1594. "120": [0, 0.44444, 0.12583, 0, 0.56055],
  1595. "121": [0.19444, 0.44444, 0.105, 0, 0.56166],
  1596. "122": [0, 0.44444, 0.13889, 0, 0.49055],
  1597. "126": [0.35, 0.34444, 0.11472, 0, 0.59111],
  1598. "160": [0, 0, 0, 0, 0.25],
  1599. "168": [0, 0.69444, 0.11473, 0, 0.59111],
  1600. "176": [0, 0.69444, 0, 0, 0.94888],
  1601. "184": [0.17014, 0, 0, 0, 0.53222],
  1602. "198": [0, 0.68611, 0.11431, 0, 1.02277],
  1603. "216": [0.04861, 0.73472, 0.09062, 0, 0.88555],
  1604. "223": [0.19444, 0.69444, 0.09736, 0, 0.665],
  1605. "230": [0, 0.44444, 0.085, 0, 0.82666],
  1606. "248": [0.09722, 0.54167, 0.09458, 0, 0.59111],
  1607. "305": [0, 0.44444, 0.09426, 0, 0.35555],
  1608. "338": [0, 0.68611, 0.11431, 0, 1.14054],
  1609. "339": [0, 0.44444, 0.085, 0, 0.82666],
  1610. "567": [0.19444, 0.44444, 0.04611, 0, 0.385],
  1611. "710": [0, 0.69444, 0.06709, 0, 0.59111],
  1612. "711": [0, 0.63194, 0.08271, 0, 0.59111],
  1613. "713": [0, 0.59444, 0.10444, 0, 0.59111],
  1614. "714": [0, 0.69444, 0.08528, 0, 0.59111],
  1615. "715": [0, 0.69444, 0, 0, 0.59111],
  1616. "728": [0, 0.69444, 0.10333, 0, 0.59111],
  1617. "729": [0, 0.69444, 0.12945, 0, 0.35555],
  1618. "730": [0, 0.69444, 0, 0, 0.94888],
  1619. "732": [0, 0.69444, 0.11472, 0, 0.59111],
  1620. "733": [0, 0.69444, 0.11472, 0, 0.59111],
  1621. "915": [0, 0.68611, 0.12903, 0, 0.69777],
  1622. "916": [0, 0.68611, 0, 0, 0.94444],
  1623. "920": [0, 0.68611, 0.09062, 0, 0.88555],
  1624. "923": [0, 0.68611, 0, 0, 0.80666],
  1625. "926": [0, 0.68611, 0.15092, 0, 0.76777],
  1626. "928": [0, 0.68611, 0.17208, 0, 0.8961],
  1627. "931": [0, 0.68611, 0.11431, 0, 0.82666],
  1628. "933": [0, 0.68611, 0.10778, 0, 0.88555],
  1629. "934": [0, 0.68611, 0.05632, 0, 0.82666],
  1630. "936": [0, 0.68611, 0.10778, 0, 0.88555],
  1631. "937": [0, 0.68611, 0.0992, 0, 0.82666],
  1632. "8211": [0, 0.44444, 0.09811, 0, 0.59111],
  1633. "8212": [0, 0.44444, 0.09811, 0, 1.18221],
  1634. "8216": [0, 0.69444, 0.12945, 0, 0.35555],
  1635. "8217": [0, 0.69444, 0.12945, 0, 0.35555],
  1636. "8220": [0, 0.69444, 0.16772, 0, 0.62055],
  1637. "8221": [0, 0.69444, 0.07939, 0, 0.62055]
  1638. },
  1639. "Main-Italic": {
  1640. "32": [0, 0, 0, 0, 0.25],
  1641. "33": [0, 0.69444, 0.12417, 0, 0.30667],
  1642. "34": [0, 0.69444, 0.06961, 0, 0.51444],
  1643. "35": [0.19444, 0.69444, 0.06616, 0, 0.81777],
  1644. "37": [0.05556, 0.75, 0.13639, 0, 0.81777],
  1645. "38": [0, 0.69444, 0.09694, 0, 0.76666],
  1646. "39": [0, 0.69444, 0.12417, 0, 0.30667],
  1647. "40": [0.25, 0.75, 0.16194, 0, 0.40889],
  1648. "41": [0.25, 0.75, 0.03694, 0, 0.40889],
  1649. "42": [0, 0.75, 0.14917, 0, 0.51111],
  1650. "43": [0.05667, 0.56167, 0.03694, 0, 0.76666],
  1651. "44": [0.19444, 0.10556, 0, 0, 0.30667],
  1652. "45": [0, 0.43056, 0.02826, 0, 0.35778],
  1653. "46": [0, 0.10556, 0, 0, 0.30667],
  1654. "47": [0.25, 0.75, 0.16194, 0, 0.51111],
  1655. "48": [0, 0.64444, 0.13556, 0, 0.51111],
  1656. "49": [0, 0.64444, 0.13556, 0, 0.51111],
  1657. "50": [0, 0.64444, 0.13556, 0, 0.51111],
  1658. "51": [0, 0.64444, 0.13556, 0, 0.51111],
  1659. "52": [0.19444, 0.64444, 0.13556, 0, 0.51111],
  1660. "53": [0, 0.64444, 0.13556, 0, 0.51111],
  1661. "54": [0, 0.64444, 0.13556, 0, 0.51111],
  1662. "55": [0.19444, 0.64444, 0.13556, 0, 0.51111],
  1663. "56": [0, 0.64444, 0.13556, 0, 0.51111],
  1664. "57": [0, 0.64444, 0.13556, 0, 0.51111],
  1665. "58": [0, 0.43056, 0.0582, 0, 0.30667],
  1666. "59": [0.19444, 0.43056, 0.0582, 0, 0.30667],
  1667. "61": [-0.13313, 0.36687, 0.06616, 0, 0.76666],
  1668. "63": [0, 0.69444, 0.1225, 0, 0.51111],
  1669. "64": [0, 0.69444, 0.09597, 0, 0.76666],
  1670. "65": [0, 0.68333, 0, 0, 0.74333],
  1671. "66": [0, 0.68333, 0.10257, 0, 0.70389],
  1672. "67": [0, 0.68333, 0.14528, 0, 0.71555],
  1673. "68": [0, 0.68333, 0.09403, 0, 0.755],
  1674. "69": [0, 0.68333, 0.12028, 0, 0.67833],
  1675. "70": [0, 0.68333, 0.13305, 0, 0.65277],
  1676. "71": [0, 0.68333, 0.08722, 0, 0.77361],
  1677. "72": [0, 0.68333, 0.16389, 0, 0.74333],
  1678. "73": [0, 0.68333, 0.15806, 0, 0.38555],
  1679. "74": [0, 0.68333, 0.14028, 0, 0.525],
  1680. "75": [0, 0.68333, 0.14528, 0, 0.76888],
  1681. "76": [0, 0.68333, 0, 0, 0.62722],
  1682. "77": [0, 0.68333, 0.16389, 0, 0.89666],
  1683. "78": [0, 0.68333, 0.16389, 0, 0.74333],
  1684. "79": [0, 0.68333, 0.09403, 0, 0.76666],
  1685. "80": [0, 0.68333, 0.10257, 0, 0.67833],
  1686. "81": [0.19444, 0.68333, 0.09403, 0, 0.76666],
  1687. "82": [0, 0.68333, 0.03868, 0, 0.72944],
  1688. "83": [0, 0.68333, 0.11972, 0, 0.56222],
  1689. "84": [0, 0.68333, 0.13305, 0, 0.71555],
  1690. "85": [0, 0.68333, 0.16389, 0, 0.74333],
  1691. "86": [0, 0.68333, 0.18361, 0, 0.74333],
  1692. "87": [0, 0.68333, 0.18361, 0, 0.99888],
  1693. "88": [0, 0.68333, 0.15806, 0, 0.74333],
  1694. "89": [0, 0.68333, 0.19383, 0, 0.74333],
  1695. "90": [0, 0.68333, 0.14528, 0, 0.61333],
  1696. "91": [0.25, 0.75, 0.1875, 0, 0.30667],
  1697. "93": [0.25, 0.75, 0.10528, 0, 0.30667],
  1698. "94": [0, 0.69444, 0.06646, 0, 0.51111],
  1699. "95": [0.31, 0.12056, 0.09208, 0, 0.51111],
  1700. "97": [0, 0.43056, 0.07671, 0, 0.51111],
  1701. "98": [0, 0.69444, 0.06312, 0, 0.46],
  1702. "99": [0, 0.43056, 0.05653, 0, 0.46],
  1703. "100": [0, 0.69444, 0.10333, 0, 0.51111],
  1704. "101": [0, 0.43056, 0.07514, 0, 0.46],
  1705. "102": [0.19444, 0.69444, 0.21194, 0, 0.30667],
  1706. "103": [0.19444, 0.43056, 0.08847, 0, 0.46],
  1707. "104": [0, 0.69444, 0.07671, 0, 0.51111],
  1708. "105": [0, 0.65536, 0.1019, 0, 0.30667],
  1709. "106": [0.19444, 0.65536, 0.14467, 0, 0.30667],
  1710. "107": [0, 0.69444, 0.10764, 0, 0.46],
  1711. "108": [0, 0.69444, 0.10333, 0, 0.25555],
  1712. "109": [0, 0.43056, 0.07671, 0, 0.81777],
  1713. "110": [0, 0.43056, 0.07671, 0, 0.56222],
  1714. "111": [0, 0.43056, 0.06312, 0, 0.51111],
  1715. "112": [0.19444, 0.43056, 0.06312, 0, 0.51111],
  1716. "113": [0.19444, 0.43056, 0.08847, 0, 0.46],
  1717. "114": [0, 0.43056, 0.10764, 0, 0.42166],
  1718. "115": [0, 0.43056, 0.08208, 0, 0.40889],
  1719. "116": [0, 0.61508, 0.09486, 0, 0.33222],
  1720. "117": [0, 0.43056, 0.07671, 0, 0.53666],
  1721. "118": [0, 0.43056, 0.10764, 0, 0.46],
  1722. "119": [0, 0.43056, 0.10764, 0, 0.66444],
  1723. "120": [0, 0.43056, 0.12042, 0, 0.46389],
  1724. "121": [0.19444, 0.43056, 0.08847, 0, 0.48555],
  1725. "122": [0, 0.43056, 0.12292, 0, 0.40889],
  1726. "126": [0.35, 0.31786, 0.11585, 0, 0.51111],
  1727. "160": [0, 0, 0, 0, 0.25],
  1728. "168": [0, 0.66786, 0.10474, 0, 0.51111],
  1729. "176": [0, 0.69444, 0, 0, 0.83129],
  1730. "184": [0.17014, 0, 0, 0, 0.46],
  1731. "198": [0, 0.68333, 0.12028, 0, 0.88277],
  1732. "216": [0.04861, 0.73194, 0.09403, 0, 0.76666],
  1733. "223": [0.19444, 0.69444, 0.10514, 0, 0.53666],
  1734. "230": [0, 0.43056, 0.07514, 0, 0.71555],
  1735. "248": [0.09722, 0.52778, 0.09194, 0, 0.51111],
  1736. "338": [0, 0.68333, 0.12028, 0, 0.98499],
  1737. "339": [0, 0.43056, 0.07514, 0, 0.71555],
  1738. "710": [0, 0.69444, 0.06646, 0, 0.51111],
  1739. "711": [0, 0.62847, 0.08295, 0, 0.51111],
  1740. "713": [0, 0.56167, 0.10333, 0, 0.51111],
  1741. "714": [0, 0.69444, 0.09694, 0, 0.51111],
  1742. "715": [0, 0.69444, 0, 0, 0.51111],
  1743. "728": [0, 0.69444, 0.10806, 0, 0.51111],
  1744. "729": [0, 0.66786, 0.11752, 0, 0.30667],
  1745. "730": [0, 0.69444, 0, 0, 0.83129],
  1746. "732": [0, 0.66786, 0.11585, 0, 0.51111],
  1747. "733": [0, 0.69444, 0.1225, 0, 0.51111],
  1748. "915": [0, 0.68333, 0.13305, 0, 0.62722],
  1749. "916": [0, 0.68333, 0, 0, 0.81777],
  1750. "920": [0, 0.68333, 0.09403, 0, 0.76666],
  1751. "923": [0, 0.68333, 0, 0, 0.69222],
  1752. "926": [0, 0.68333, 0.15294, 0, 0.66444],
  1753. "928": [0, 0.68333, 0.16389, 0, 0.74333],
  1754. "931": [0, 0.68333, 0.12028, 0, 0.71555],
  1755. "933": [0, 0.68333, 0.11111, 0, 0.76666],
  1756. "934": [0, 0.68333, 0.05986, 0, 0.71555],
  1757. "936": [0, 0.68333, 0.11111, 0, 0.76666],
  1758. "937": [0, 0.68333, 0.10257, 0, 0.71555],
  1759. "8211": [0, 0.43056, 0.09208, 0, 0.51111],
  1760. "8212": [0, 0.43056, 0.09208, 0, 1.02222],
  1761. "8216": [0, 0.69444, 0.12417, 0, 0.30667],
  1762. "8217": [0, 0.69444, 0.12417, 0, 0.30667],
  1763. "8220": [0, 0.69444, 0.1685, 0, 0.51444],
  1764. "8221": [0, 0.69444, 0.06961, 0, 0.51444],
  1765. "8463": [0, 0.68889, 0, 0, 0.54028]
  1766. },
  1767. "Main-Regular": {
  1768. "32": [0, 0, 0, 0, 0.25],
  1769. "33": [0, 0.69444, 0, 0, 0.27778],
  1770. "34": [0, 0.69444, 0, 0, 0.5],
  1771. "35": [0.19444, 0.69444, 0, 0, 0.83334],
  1772. "36": [0.05556, 0.75, 0, 0, 0.5],
  1773. "37": [0.05556, 0.75, 0, 0, 0.83334],
  1774. "38": [0, 0.69444, 0, 0, 0.77778],
  1775. "39": [0, 0.69444, 0, 0, 0.27778],
  1776. "40": [0.25, 0.75, 0, 0, 0.38889],
  1777. "41": [0.25, 0.75, 0, 0, 0.38889],
  1778. "42": [0, 0.75, 0, 0, 0.5],
  1779. "43": [0.08333, 0.58333, 0, 0, 0.77778],
  1780. "44": [0.19444, 0.10556, 0, 0, 0.27778],
  1781. "45": [0, 0.43056, 0, 0, 0.33333],
  1782. "46": [0, 0.10556, 0, 0, 0.27778],
  1783. "47": [0.25, 0.75, 0, 0, 0.5],
  1784. "48": [0, 0.64444, 0, 0, 0.5],
  1785. "49": [0, 0.64444, 0, 0, 0.5],
  1786. "50": [0, 0.64444, 0, 0, 0.5],
  1787. "51": [0, 0.64444, 0, 0, 0.5],
  1788. "52": [0, 0.64444, 0, 0, 0.5],
  1789. "53": [0, 0.64444, 0, 0, 0.5],
  1790. "54": [0, 0.64444, 0, 0, 0.5],
  1791. "55": [0, 0.64444, 0, 0, 0.5],
  1792. "56": [0, 0.64444, 0, 0, 0.5],
  1793. "57": [0, 0.64444, 0, 0, 0.5],
  1794. "58": [0, 0.43056, 0, 0, 0.27778],
  1795. "59": [0.19444, 0.43056, 0, 0, 0.27778],
  1796. "60": [0.0391, 0.5391, 0, 0, 0.77778],
  1797. "61": [-0.13313, 0.36687, 0, 0, 0.77778],
  1798. "62": [0.0391, 0.5391, 0, 0, 0.77778],
  1799. "63": [0, 0.69444, 0, 0, 0.47222],
  1800. "64": [0, 0.69444, 0, 0, 0.77778],
  1801. "65": [0, 0.68333, 0, 0, 0.75],
  1802. "66": [0, 0.68333, 0, 0, 0.70834],
  1803. "67": [0, 0.68333, 0, 0, 0.72222],
  1804. "68": [0, 0.68333, 0, 0, 0.76389],
  1805. "69": [0, 0.68333, 0, 0, 0.68056],
  1806. "70": [0, 0.68333, 0, 0, 0.65278],
  1807. "71": [0, 0.68333, 0, 0, 0.78472],
  1808. "72": [0, 0.68333, 0, 0, 0.75],
  1809. "73": [0, 0.68333, 0, 0, 0.36111],
  1810. "74": [0, 0.68333, 0, 0, 0.51389],
  1811. "75": [0, 0.68333, 0, 0, 0.77778],
  1812. "76": [0, 0.68333, 0, 0, 0.625],
  1813. "77": [0, 0.68333, 0, 0, 0.91667],
  1814. "78": [0, 0.68333, 0, 0, 0.75],
  1815. "79": [0, 0.68333, 0, 0, 0.77778],
  1816. "80": [0, 0.68333, 0, 0, 0.68056],
  1817. "81": [0.19444, 0.68333, 0, 0, 0.77778],
  1818. "82": [0, 0.68333, 0, 0, 0.73611],
  1819. "83": [0, 0.68333, 0, 0, 0.55556],
  1820. "84": [0, 0.68333, 0, 0, 0.72222],
  1821. "85": [0, 0.68333, 0, 0, 0.75],
  1822. "86": [0, 0.68333, 0.01389, 0, 0.75],
  1823. "87": [0, 0.68333, 0.01389, 0, 1.02778],
  1824. "88": [0, 0.68333, 0, 0, 0.75],
  1825. "89": [0, 0.68333, 0.025, 0, 0.75],
  1826. "90": [0, 0.68333, 0, 0, 0.61111],
  1827. "91": [0.25, 0.75, 0, 0, 0.27778],
  1828. "92": [0.25, 0.75, 0, 0, 0.5],
  1829. "93": [0.25, 0.75, 0, 0, 0.27778],
  1830. "94": [0, 0.69444, 0, 0, 0.5],
  1831. "95": [0.31, 0.12056, 0.02778, 0, 0.5],
  1832. "97": [0, 0.43056, 0, 0, 0.5],
  1833. "98": [0, 0.69444, 0, 0, 0.55556],
  1834. "99": [0, 0.43056, 0, 0, 0.44445],
  1835. "100": [0, 0.69444, 0, 0, 0.55556],
  1836. "101": [0, 0.43056, 0, 0, 0.44445],
  1837. "102": [0, 0.69444, 0.07778, 0, 0.30556],
  1838. "103": [0.19444, 0.43056, 0.01389, 0, 0.5],
  1839. "104": [0, 0.69444, 0, 0, 0.55556],
  1840. "105": [0, 0.66786, 0, 0, 0.27778],
  1841. "106": [0.19444, 0.66786, 0, 0, 0.30556],
  1842. "107": [0, 0.69444, 0, 0, 0.52778],
  1843. "108": [0, 0.69444, 0, 0, 0.27778],
  1844. "109": [0, 0.43056, 0, 0, 0.83334],
  1845. "110": [0, 0.43056, 0, 0, 0.55556],
  1846. "111": [0, 0.43056, 0, 0, 0.5],
  1847. "112": [0.19444, 0.43056, 0, 0, 0.55556],
  1848. "113": [0.19444, 0.43056, 0, 0, 0.52778],
  1849. "114": [0, 0.43056, 0, 0, 0.39167],
  1850. "115": [0, 0.43056, 0, 0, 0.39445],
  1851. "116": [0, 0.61508, 0, 0, 0.38889],
  1852. "117": [0, 0.43056, 0, 0, 0.55556],
  1853. "118": [0, 0.43056, 0.01389, 0, 0.52778],
  1854. "119": [0, 0.43056, 0.01389, 0, 0.72222],
  1855. "120": [0, 0.43056, 0, 0, 0.52778],
  1856. "121": [0.19444, 0.43056, 0.01389, 0, 0.52778],
  1857. "122": [0, 0.43056, 0, 0, 0.44445],
  1858. "123": [0.25, 0.75, 0, 0, 0.5],
  1859. "124": [0.25, 0.75, 0, 0, 0.27778],
  1860. "125": [0.25, 0.75, 0, 0, 0.5],
  1861. "126": [0.35, 0.31786, 0, 0, 0.5],
  1862. "160": [0, 0, 0, 0, 0.25],
  1863. "163": [0, 0.69444, 0, 0, 0.76909],
  1864. "167": [0.19444, 0.69444, 0, 0, 0.44445],
  1865. "168": [0, 0.66786, 0, 0, 0.5],
  1866. "172": [0, 0.43056, 0, 0, 0.66667],
  1867. "176": [0, 0.69444, 0, 0, 0.75],
  1868. "177": [0.08333, 0.58333, 0, 0, 0.77778],
  1869. "182": [0.19444, 0.69444, 0, 0, 0.61111],
  1870. "184": [0.17014, 0, 0, 0, 0.44445],
  1871. "198": [0, 0.68333, 0, 0, 0.90278],
  1872. "215": [0.08333, 0.58333, 0, 0, 0.77778],
  1873. "216": [0.04861, 0.73194, 0, 0, 0.77778],
  1874. "223": [0, 0.69444, 0, 0, 0.5],
  1875. "230": [0, 0.43056, 0, 0, 0.72222],
  1876. "247": [0.08333, 0.58333, 0, 0, 0.77778],
  1877. "248": [0.09722, 0.52778, 0, 0, 0.5],
  1878. "305": [0, 0.43056, 0, 0, 0.27778],
  1879. "338": [0, 0.68333, 0, 0, 1.01389],
  1880. "339": [0, 0.43056, 0, 0, 0.77778],
  1881. "567": [0.19444, 0.43056, 0, 0, 0.30556],
  1882. "710": [0, 0.69444, 0, 0, 0.5],
  1883. "711": [0, 0.62847, 0, 0, 0.5],
  1884. "713": [0, 0.56778, 0, 0, 0.5],
  1885. "714": [0, 0.69444, 0, 0, 0.5],
  1886. "715": [0, 0.69444, 0, 0, 0.5],
  1887. "728": [0, 0.69444, 0, 0, 0.5],
  1888. "729": [0, 0.66786, 0, 0, 0.27778],
  1889. "730": [0, 0.69444, 0, 0, 0.75],
  1890. "732": [0, 0.66786, 0, 0, 0.5],
  1891. "733": [0, 0.69444, 0, 0, 0.5],
  1892. "915": [0, 0.68333, 0, 0, 0.625],
  1893. "916": [0, 0.68333, 0, 0, 0.83334],
  1894. "920": [0, 0.68333, 0, 0, 0.77778],
  1895. "923": [0, 0.68333, 0, 0, 0.69445],
  1896. "926": [0, 0.68333, 0, 0, 0.66667],
  1897. "928": [0, 0.68333, 0, 0, 0.75],
  1898. "931": [0, 0.68333, 0, 0, 0.72222],
  1899. "933": [0, 0.68333, 0, 0, 0.77778],
  1900. "934": [0, 0.68333, 0, 0, 0.72222],
  1901. "936": [0, 0.68333, 0, 0, 0.77778],
  1902. "937": [0, 0.68333, 0, 0, 0.72222],
  1903. "8211": [0, 0.43056, 0.02778, 0, 0.5],
  1904. "8212": [0, 0.43056, 0.02778, 0, 1.0],
  1905. "8216": [0, 0.69444, 0, 0, 0.27778],
  1906. "8217": [0, 0.69444, 0, 0, 0.27778],
  1907. "8220": [0, 0.69444, 0, 0, 0.5],
  1908. "8221": [0, 0.69444, 0, 0, 0.5],
  1909. "8224": [0.19444, 0.69444, 0, 0, 0.44445],
  1910. "8225": [0.19444, 0.69444, 0, 0, 0.44445],
  1911. "8230": [0, 0.123, 0, 0, 1.172],
  1912. "8242": [0, 0.55556, 0, 0, 0.275],
  1913. "8407": [0, 0.71444, 0.15382, 0, 0.5],
  1914. "8463": [0, 0.68889, 0, 0, 0.54028],
  1915. "8465": [0, 0.69444, 0, 0, 0.72222],
  1916. "8467": [0, 0.69444, 0, 0.11111, 0.41667],
  1917. "8472": [0.19444, 0.43056, 0, 0.11111, 0.63646],
  1918. "8476": [0, 0.69444, 0, 0, 0.72222],
  1919. "8501": [0, 0.69444, 0, 0, 0.61111],
  1920. "8592": [-0.13313, 0.36687, 0, 0, 1.0],
  1921. "8593": [0.19444, 0.69444, 0, 0, 0.5],
  1922. "8594": [-0.13313, 0.36687, 0, 0, 1.0],
  1923. "8595": [0.19444, 0.69444, 0, 0, 0.5],
  1924. "8596": [-0.13313, 0.36687, 0, 0, 1.0],
  1925. "8597": [0.25, 0.75, 0, 0, 0.5],
  1926. "8598": [0.19444, 0.69444, 0, 0, 1.0],
  1927. "8599": [0.19444, 0.69444, 0, 0, 1.0],
  1928. "8600": [0.19444, 0.69444, 0, 0, 1.0],
  1929. "8601": [0.19444, 0.69444, 0, 0, 1.0],
  1930. "8614": [0.011, 0.511, 0, 0, 1.0],
  1931. "8617": [0.011, 0.511, 0, 0, 1.126],
  1932. "8618": [0.011, 0.511, 0, 0, 1.126],
  1933. "8636": [-0.13313, 0.36687, 0, 0, 1.0],
  1934. "8637": [-0.13313, 0.36687, 0, 0, 1.0],
  1935. "8640": [-0.13313, 0.36687, 0, 0, 1.0],
  1936. "8641": [-0.13313, 0.36687, 0, 0, 1.0],
  1937. "8652": [0.011, 0.671, 0, 0, 1.0],
  1938. "8656": [-0.13313, 0.36687, 0, 0, 1.0],
  1939. "8657": [0.19444, 0.69444, 0, 0, 0.61111],
  1940. "8658": [-0.13313, 0.36687, 0, 0, 1.0],
  1941. "8659": [0.19444, 0.69444, 0, 0, 0.61111],
  1942. "8660": [-0.13313, 0.36687, 0, 0, 1.0],
  1943. "8661": [0.25, 0.75, 0, 0, 0.61111],
  1944. "8704": [0, 0.69444, 0, 0, 0.55556],
  1945. "8706": [0, 0.69444, 0.05556, 0.08334, 0.5309],
  1946. "8707": [0, 0.69444, 0, 0, 0.55556],
  1947. "8709": [0.05556, 0.75, 0, 0, 0.5],
  1948. "8711": [0, 0.68333, 0, 0, 0.83334],
  1949. "8712": [0.0391, 0.5391, 0, 0, 0.66667],
  1950. "8715": [0.0391, 0.5391, 0, 0, 0.66667],
  1951. "8722": [0.08333, 0.58333, 0, 0, 0.77778],
  1952. "8723": [0.08333, 0.58333, 0, 0, 0.77778],
  1953. "8725": [0.25, 0.75, 0, 0, 0.5],
  1954. "8726": [0.25, 0.75, 0, 0, 0.5],
  1955. "8727": [-0.03472, 0.46528, 0, 0, 0.5],
  1956. "8728": [-0.05555, 0.44445, 0, 0, 0.5],
  1957. "8729": [-0.05555, 0.44445, 0, 0, 0.5],
  1958. "8730": [0.2, 0.8, 0, 0, 0.83334],
  1959. "8733": [0, 0.43056, 0, 0, 0.77778],
  1960. "8734": [0, 0.43056, 0, 0, 1.0],
  1961. "8736": [0, 0.69224, 0, 0, 0.72222],
  1962. "8739": [0.25, 0.75, 0, 0, 0.27778],
  1963. "8741": [0.25, 0.75, 0, 0, 0.5],
  1964. "8743": [0, 0.55556, 0, 0, 0.66667],
  1965. "8744": [0, 0.55556, 0, 0, 0.66667],
  1966. "8745": [0, 0.55556, 0, 0, 0.66667],
  1967. "8746": [0, 0.55556, 0, 0, 0.66667],
  1968. "8747": [0.19444, 0.69444, 0.11111, 0, 0.41667],
  1969. "8764": [-0.13313, 0.36687, 0, 0, 0.77778],
  1970. "8768": [0.19444, 0.69444, 0, 0, 0.27778],
  1971. "8771": [-0.03625, 0.46375, 0, 0, 0.77778],
  1972. "8773": [-0.022, 0.589, 0, 0, 0.778],
  1973. "8776": [-0.01688, 0.48312, 0, 0, 0.77778],
  1974. "8781": [-0.03625, 0.46375, 0, 0, 0.77778],
  1975. "8784": [-0.133, 0.673, 0, 0, 0.778],
  1976. "8801": [-0.03625, 0.46375, 0, 0, 0.77778],
  1977. "8804": [0.13597, 0.63597, 0, 0, 0.77778],
  1978. "8805": [0.13597, 0.63597, 0, 0, 0.77778],
  1979. "8810": [0.0391, 0.5391, 0, 0, 1.0],
  1980. "8811": [0.0391, 0.5391, 0, 0, 1.0],
  1981. "8826": [0.0391, 0.5391, 0, 0, 0.77778],
  1982. "8827": [0.0391, 0.5391, 0, 0, 0.77778],
  1983. "8834": [0.0391, 0.5391, 0, 0, 0.77778],
  1984. "8835": [0.0391, 0.5391, 0, 0, 0.77778],
  1985. "8838": [0.13597, 0.63597, 0, 0, 0.77778],
  1986. "8839": [0.13597, 0.63597, 0, 0, 0.77778],
  1987. "8846": [0, 0.55556, 0, 0, 0.66667],
  1988. "8849": [0.13597, 0.63597, 0, 0, 0.77778],
  1989. "8850": [0.13597, 0.63597, 0, 0, 0.77778],
  1990. "8851": [0, 0.55556, 0, 0, 0.66667],
  1991. "8852": [0, 0.55556, 0, 0, 0.66667],
  1992. "8853": [0.08333, 0.58333, 0, 0, 0.77778],
  1993. "8854": [0.08333, 0.58333, 0, 0, 0.77778],
  1994. "8855": [0.08333, 0.58333, 0, 0, 0.77778],
  1995. "8856": [0.08333, 0.58333, 0, 0, 0.77778],
  1996. "8857": [0.08333, 0.58333, 0, 0, 0.77778],
  1997. "8866": [0, 0.69444, 0, 0, 0.61111],
  1998. "8867": [0, 0.69444, 0, 0, 0.61111],
  1999. "8868": [0, 0.69444, 0, 0, 0.77778],
  2000. "8869": [0, 0.69444, 0, 0, 0.77778],
  2001. "8872": [0.249, 0.75, 0, 0, 0.867],
  2002. "8900": [-0.05555, 0.44445, 0, 0, 0.5],
  2003. "8901": [-0.05555, 0.44445, 0, 0, 0.27778],
  2004. "8902": [-0.03472, 0.46528, 0, 0, 0.5],
  2005. "8904": [0.005, 0.505, 0, 0, 0.9],
  2006. "8942": [0.03, 0.903, 0, 0, 0.278],
  2007. "8943": [-0.19, 0.313, 0, 0, 1.172],
  2008. "8945": [-0.1, 0.823, 0, 0, 1.282],
  2009. "8968": [0.25, 0.75, 0, 0, 0.44445],
  2010. "8969": [0.25, 0.75, 0, 0, 0.44445],
  2011. "8970": [0.25, 0.75, 0, 0, 0.44445],
  2012. "8971": [0.25, 0.75, 0, 0, 0.44445],
  2013. "8994": [-0.14236, 0.35764, 0, 0, 1.0],
  2014. "8995": [-0.14236, 0.35764, 0, 0, 1.0],
  2015. "9136": [0.244, 0.744, 0, 0, 0.412],
  2016. "9137": [0.244, 0.745, 0, 0, 0.412],
  2017. "9651": [0.19444, 0.69444, 0, 0, 0.88889],
  2018. "9657": [-0.03472, 0.46528, 0, 0, 0.5],
  2019. "9661": [0.19444, 0.69444, 0, 0, 0.88889],
  2020. "9667": [-0.03472, 0.46528, 0, 0, 0.5],
  2021. "9711": [0.19444, 0.69444, 0, 0, 1.0],
  2022. "9824": [0.12963, 0.69444, 0, 0, 0.77778],
  2023. "9825": [0.12963, 0.69444, 0, 0, 0.77778],
  2024. "9826": [0.12963, 0.69444, 0, 0, 0.77778],
  2025. "9827": [0.12963, 0.69444, 0, 0, 0.77778],
  2026. "9837": [0, 0.75, 0, 0, 0.38889],
  2027. "9838": [0.19444, 0.69444, 0, 0, 0.38889],
  2028. "9839": [0.19444, 0.69444, 0, 0, 0.38889],
  2029. "10216": [0.25, 0.75, 0, 0, 0.38889],
  2030. "10217": [0.25, 0.75, 0, 0, 0.38889],
  2031. "10222": [0.244, 0.744, 0, 0, 0.412],
  2032. "10223": [0.244, 0.745, 0, 0, 0.412],
  2033. "10229": [0.011, 0.511, 0, 0, 1.609],
  2034. "10230": [0.011, 0.511, 0, 0, 1.638],
  2035. "10231": [0.011, 0.511, 0, 0, 1.859],
  2036. "10232": [0.024, 0.525, 0, 0, 1.609],
  2037. "10233": [0.024, 0.525, 0, 0, 1.638],
  2038. "10234": [0.024, 0.525, 0, 0, 1.858],
  2039. "10236": [0.011, 0.511, 0, 0, 1.638],
  2040. "10815": [0, 0.68333, 0, 0, 0.75],
  2041. "10927": [0.13597, 0.63597, 0, 0, 0.77778],
  2042. "10928": [0.13597, 0.63597, 0, 0, 0.77778],
  2043. "57376": [0.19444, 0.69444, 0, 0, 0]
  2044. },
  2045. "Math-BoldItalic": {
  2046. "32": [0, 0, 0, 0, 0.25],
  2047. "48": [0, 0.44444, 0, 0, 0.575],
  2048. "49": [0, 0.44444, 0, 0, 0.575],
  2049. "50": [0, 0.44444, 0, 0, 0.575],
  2050. "51": [0.19444, 0.44444, 0, 0, 0.575],
  2051. "52": [0.19444, 0.44444, 0, 0, 0.575],
  2052. "53": [0.19444, 0.44444, 0, 0, 0.575],
  2053. "54": [0, 0.64444, 0, 0, 0.575],
  2054. "55": [0.19444, 0.44444, 0, 0, 0.575],
  2055. "56": [0, 0.64444, 0, 0, 0.575],
  2056. "57": [0.19444, 0.44444, 0, 0, 0.575],
  2057. "65": [0, 0.68611, 0, 0, 0.86944],
  2058. "66": [0, 0.68611, 0.04835, 0, 0.8664],
  2059. "67": [0, 0.68611, 0.06979, 0, 0.81694],
  2060. "68": [0, 0.68611, 0.03194, 0, 0.93812],
  2061. "69": [0, 0.68611, 0.05451, 0, 0.81007],
  2062. "70": [0, 0.68611, 0.15972, 0, 0.68889],
  2063. "71": [0, 0.68611, 0, 0, 0.88673],
  2064. "72": [0, 0.68611, 0.08229, 0, 0.98229],
  2065. "73": [0, 0.68611, 0.07778, 0, 0.51111],
  2066. "74": [0, 0.68611, 0.10069, 0, 0.63125],
  2067. "75": [0, 0.68611, 0.06979, 0, 0.97118],
  2068. "76": [0, 0.68611, 0, 0, 0.75555],
  2069. "77": [0, 0.68611, 0.11424, 0, 1.14201],
  2070. "78": [0, 0.68611, 0.11424, 0, 0.95034],
  2071. "79": [0, 0.68611, 0.03194, 0, 0.83666],
  2072. "80": [0, 0.68611, 0.15972, 0, 0.72309],
  2073. "81": [0.19444, 0.68611, 0, 0, 0.86861],
  2074. "82": [0, 0.68611, 0.00421, 0, 0.87235],
  2075. "83": [0, 0.68611, 0.05382, 0, 0.69271],
  2076. "84": [0, 0.68611, 0.15972, 0, 0.63663],
  2077. "85": [0, 0.68611, 0.11424, 0, 0.80027],
  2078. "86": [0, 0.68611, 0.25555, 0, 0.67778],
  2079. "87": [0, 0.68611, 0.15972, 0, 1.09305],
  2080. "88": [0, 0.68611, 0.07778, 0, 0.94722],
  2081. "89": [0, 0.68611, 0.25555, 0, 0.67458],
  2082. "90": [0, 0.68611, 0.06979, 0, 0.77257],
  2083. "97": [0, 0.44444, 0, 0, 0.63287],
  2084. "98": [0, 0.69444, 0, 0, 0.52083],
  2085. "99": [0, 0.44444, 0, 0, 0.51342],
  2086. "100": [0, 0.69444, 0, 0, 0.60972],
  2087. "101": [0, 0.44444, 0, 0, 0.55361],
  2088. "102": [0.19444, 0.69444, 0.11042, 0, 0.56806],
  2089. "103": [0.19444, 0.44444, 0.03704, 0, 0.5449],
  2090. "104": [0, 0.69444, 0, 0, 0.66759],
  2091. "105": [0, 0.69326, 0, 0, 0.4048],
  2092. "106": [0.19444, 0.69326, 0.0622, 0, 0.47083],
  2093. "107": [0, 0.69444, 0.01852, 0, 0.6037],
  2094. "108": [0, 0.69444, 0.0088, 0, 0.34815],
  2095. "109": [0, 0.44444, 0, 0, 1.0324],
  2096. "110": [0, 0.44444, 0, 0, 0.71296],
  2097. "111": [0, 0.44444, 0, 0, 0.58472],
  2098. "112": [0.19444, 0.44444, 0, 0, 0.60092],
  2099. "113": [0.19444, 0.44444, 0.03704, 0, 0.54213],
  2100. "114": [0, 0.44444, 0.03194, 0, 0.5287],
  2101. "115": [0, 0.44444, 0, 0, 0.53125],
  2102. "116": [0, 0.63492, 0, 0, 0.41528],
  2103. "117": [0, 0.44444, 0, 0, 0.68102],
  2104. "118": [0, 0.44444, 0.03704, 0, 0.56666],
  2105. "119": [0, 0.44444, 0.02778, 0, 0.83148],
  2106. "120": [0, 0.44444, 0, 0, 0.65903],
  2107. "121": [0.19444, 0.44444, 0.03704, 0, 0.59028],
  2108. "122": [0, 0.44444, 0.04213, 0, 0.55509],
  2109. "160": [0, 0, 0, 0, 0.25],
  2110. "915": [0, 0.68611, 0.15972, 0, 0.65694],
  2111. "916": [0, 0.68611, 0, 0, 0.95833],
  2112. "920": [0, 0.68611, 0.03194, 0, 0.86722],
  2113. "923": [0, 0.68611, 0, 0, 0.80555],
  2114. "926": [0, 0.68611, 0.07458, 0, 0.84125],
  2115. "928": [0, 0.68611, 0.08229, 0, 0.98229],
  2116. "931": [0, 0.68611, 0.05451, 0, 0.88507],
  2117. "933": [0, 0.68611, 0.15972, 0, 0.67083],
  2118. "934": [0, 0.68611, 0, 0, 0.76666],
  2119. "936": [0, 0.68611, 0.11653, 0, 0.71402],
  2120. "937": [0, 0.68611, 0.04835, 0, 0.8789],
  2121. "945": [0, 0.44444, 0, 0, 0.76064],
  2122. "946": [0.19444, 0.69444, 0.03403, 0, 0.65972],
  2123. "947": [0.19444, 0.44444, 0.06389, 0, 0.59003],
  2124. "948": [0, 0.69444, 0.03819, 0, 0.52222],
  2125. "949": [0, 0.44444, 0, 0, 0.52882],
  2126. "950": [0.19444, 0.69444, 0.06215, 0, 0.50833],
  2127. "951": [0.19444, 0.44444, 0.03704, 0, 0.6],
  2128. "952": [0, 0.69444, 0.03194, 0, 0.5618],
  2129. "953": [0, 0.44444, 0, 0, 0.41204],
  2130. "954": [0, 0.44444, 0, 0, 0.66759],
  2131. "955": [0, 0.69444, 0, 0, 0.67083],
  2132. "956": [0.19444, 0.44444, 0, 0, 0.70787],
  2133. "957": [0, 0.44444, 0.06898, 0, 0.57685],
  2134. "958": [0.19444, 0.69444, 0.03021, 0, 0.50833],
  2135. "959": [0, 0.44444, 0, 0, 0.58472],
  2136. "960": [0, 0.44444, 0.03704, 0, 0.68241],
  2137. "961": [0.19444, 0.44444, 0, 0, 0.6118],
  2138. "962": [0.09722, 0.44444, 0.07917, 0, 0.42361],
  2139. "963": [0, 0.44444, 0.03704, 0, 0.68588],
  2140. "964": [0, 0.44444, 0.13472, 0, 0.52083],
  2141. "965": [0, 0.44444, 0.03704, 0, 0.63055],
  2142. "966": [0.19444, 0.44444, 0, 0, 0.74722],
  2143. "967": [0.19444, 0.44444, 0, 0, 0.71805],
  2144. "968": [0.19444, 0.69444, 0.03704, 0, 0.75833],
  2145. "969": [0, 0.44444, 0.03704, 0, 0.71782],
  2146. "977": [0, 0.69444, 0, 0, 0.69155],
  2147. "981": [0.19444, 0.69444, 0, 0, 0.7125],
  2148. "982": [0, 0.44444, 0.03194, 0, 0.975],
  2149. "1009": [0.19444, 0.44444, 0, 0, 0.6118],
  2150. "1013": [0, 0.44444, 0, 0, 0.48333],
  2151. "57649": [0, 0.44444, 0, 0, 0.39352],
  2152. "57911": [0.19444, 0.44444, 0, 0, 0.43889]
  2153. },
  2154. "Math-Italic": {
  2155. "32": [0, 0, 0, 0, 0.25],
  2156. "48": [0, 0.43056, 0, 0, 0.5],
  2157. "49": [0, 0.43056, 0, 0, 0.5],
  2158. "50": [0, 0.43056, 0, 0, 0.5],
  2159. "51": [0.19444, 0.43056, 0, 0, 0.5],
  2160. "52": [0.19444, 0.43056, 0, 0, 0.5],
  2161. "53": [0.19444, 0.43056, 0, 0, 0.5],
  2162. "54": [0, 0.64444, 0, 0, 0.5],
  2163. "55": [0.19444, 0.43056, 0, 0, 0.5],
  2164. "56": [0, 0.64444, 0, 0, 0.5],
  2165. "57": [0.19444, 0.43056, 0, 0, 0.5],
  2166. "65": [0, 0.68333, 0, 0.13889, 0.75],
  2167. "66": [0, 0.68333, 0.05017, 0.08334, 0.75851],
  2168. "67": [0, 0.68333, 0.07153, 0.08334, 0.71472],
  2169. "68": [0, 0.68333, 0.02778, 0.05556, 0.82792],
  2170. "69": [0, 0.68333, 0.05764, 0.08334, 0.7382],
  2171. "70": [0, 0.68333, 0.13889, 0.08334, 0.64306],
  2172. "71": [0, 0.68333, 0, 0.08334, 0.78625],
  2173. "72": [0, 0.68333, 0.08125, 0.05556, 0.83125],
  2174. "73": [0, 0.68333, 0.07847, 0.11111, 0.43958],
  2175. "74": [0, 0.68333, 0.09618, 0.16667, 0.55451],
  2176. "75": [0, 0.68333, 0.07153, 0.05556, 0.84931],
  2177. "76": [0, 0.68333, 0, 0.02778, 0.68056],
  2178. "77": [0, 0.68333, 0.10903, 0.08334, 0.97014],
  2179. "78": [0, 0.68333, 0.10903, 0.08334, 0.80347],
  2180. "79": [0, 0.68333, 0.02778, 0.08334, 0.76278],
  2181. "80": [0, 0.68333, 0.13889, 0.08334, 0.64201],
  2182. "81": [0.19444, 0.68333, 0, 0.08334, 0.79056],
  2183. "82": [0, 0.68333, 0.00773, 0.08334, 0.75929],
  2184. "83": [0, 0.68333, 0.05764, 0.08334, 0.6132],
  2185. "84": [0, 0.68333, 0.13889, 0.08334, 0.58438],
  2186. "85": [0, 0.68333, 0.10903, 0.02778, 0.68278],
  2187. "86": [0, 0.68333, 0.22222, 0, 0.58333],
  2188. "87": [0, 0.68333, 0.13889, 0, 0.94445],
  2189. "88": [0, 0.68333, 0.07847, 0.08334, 0.82847],
  2190. "89": [0, 0.68333, 0.22222, 0, 0.58056],
  2191. "90": [0, 0.68333, 0.07153, 0.08334, 0.68264],
  2192. "97": [0, 0.43056, 0, 0, 0.52859],
  2193. "98": [0, 0.69444, 0, 0, 0.42917],
  2194. "99": [0, 0.43056, 0, 0.05556, 0.43276],
  2195. "100": [0, 0.69444, 0, 0.16667, 0.52049],
  2196. "101": [0, 0.43056, 0, 0.05556, 0.46563],
  2197. "102": [0.19444, 0.69444, 0.10764, 0.16667, 0.48959],
  2198. "103": [0.19444, 0.43056, 0.03588, 0.02778, 0.47697],
  2199. "104": [0, 0.69444, 0, 0, 0.57616],
  2200. "105": [0, 0.65952, 0, 0, 0.34451],
  2201. "106": [0.19444, 0.65952, 0.05724, 0, 0.41181],
  2202. "107": [0, 0.69444, 0.03148, 0, 0.5206],
  2203. "108": [0, 0.69444, 0.01968, 0.08334, 0.29838],
  2204. "109": [0, 0.43056, 0, 0, 0.87801],
  2205. "110": [0, 0.43056, 0, 0, 0.60023],
  2206. "111": [0, 0.43056, 0, 0.05556, 0.48472],
  2207. "112": [0.19444, 0.43056, 0, 0.08334, 0.50313],
  2208. "113": [0.19444, 0.43056, 0.03588, 0.08334, 0.44641],
  2209. "114": [0, 0.43056, 0.02778, 0.05556, 0.45116],
  2210. "115": [0, 0.43056, 0, 0.05556, 0.46875],
  2211. "116": [0, 0.61508, 0, 0.08334, 0.36111],
  2212. "117": [0, 0.43056, 0, 0.02778, 0.57246],
  2213. "118": [0, 0.43056, 0.03588, 0.02778, 0.48472],
  2214. "119": [0, 0.43056, 0.02691, 0.08334, 0.71592],
  2215. "120": [0, 0.43056, 0, 0.02778, 0.57153],
  2216. "121": [0.19444, 0.43056, 0.03588, 0.05556, 0.49028],
  2217. "122": [0, 0.43056, 0.04398, 0.05556, 0.46505],
  2218. "160": [0, 0, 0, 0, 0.25],
  2219. "915": [0, 0.68333, 0.13889, 0.08334, 0.61528],
  2220. "916": [0, 0.68333, 0, 0.16667, 0.83334],
  2221. "920": [0, 0.68333, 0.02778, 0.08334, 0.76278],
  2222. "923": [0, 0.68333, 0, 0.16667, 0.69445],
  2223. "926": [0, 0.68333, 0.07569, 0.08334, 0.74236],
  2224. "928": [0, 0.68333, 0.08125, 0.05556, 0.83125],
  2225. "931": [0, 0.68333, 0.05764, 0.08334, 0.77986],
  2226. "933": [0, 0.68333, 0.13889, 0.05556, 0.58333],
  2227. "934": [0, 0.68333, 0, 0.08334, 0.66667],
  2228. "936": [0, 0.68333, 0.11, 0.05556, 0.61222],
  2229. "937": [0, 0.68333, 0.05017, 0.08334, 0.7724],
  2230. "945": [0, 0.43056, 0.0037, 0.02778, 0.6397],
  2231. "946": [0.19444, 0.69444, 0.05278, 0.08334, 0.56563],
  2232. "947": [0.19444, 0.43056, 0.05556, 0, 0.51773],
  2233. "948": [0, 0.69444, 0.03785, 0.05556, 0.44444],
  2234. "949": [0, 0.43056, 0, 0.08334, 0.46632],
  2235. "950": [0.19444, 0.69444, 0.07378, 0.08334, 0.4375],
  2236. "951": [0.19444, 0.43056, 0.03588, 0.05556, 0.49653],
  2237. "952": [0, 0.69444, 0.02778, 0.08334, 0.46944],
  2238. "953": [0, 0.43056, 0, 0.05556, 0.35394],
  2239. "954": [0, 0.43056, 0, 0, 0.57616],
  2240. "955": [0, 0.69444, 0, 0, 0.58334],
  2241. "956": [0.19444, 0.43056, 0, 0.02778, 0.60255],
  2242. "957": [0, 0.43056, 0.06366, 0.02778, 0.49398],
  2243. "958": [0.19444, 0.69444, 0.04601, 0.11111, 0.4375],
  2244. "959": [0, 0.43056, 0, 0.05556, 0.48472],
  2245. "960": [0, 0.43056, 0.03588, 0, 0.57003],
  2246. "961": [0.19444, 0.43056, 0, 0.08334, 0.51702],
  2247. "962": [0.09722, 0.43056, 0.07986, 0.08334, 0.36285],
  2248. "963": [0, 0.43056, 0.03588, 0, 0.57141],
  2249. "964": [0, 0.43056, 0.1132, 0.02778, 0.43715],
  2250. "965": [0, 0.43056, 0.03588, 0.02778, 0.54028],
  2251. "966": [0.19444, 0.43056, 0, 0.08334, 0.65417],
  2252. "967": [0.19444, 0.43056, 0, 0.05556, 0.62569],
  2253. "968": [0.19444, 0.69444, 0.03588, 0.11111, 0.65139],
  2254. "969": [0, 0.43056, 0.03588, 0, 0.62245],
  2255. "977": [0, 0.69444, 0, 0.08334, 0.59144],
  2256. "981": [0.19444, 0.69444, 0, 0.08334, 0.59583],
  2257. "982": [0, 0.43056, 0.02778, 0, 0.82813],
  2258. "1009": [0.19444, 0.43056, 0, 0.08334, 0.51702],
  2259. "1013": [0, 0.43056, 0, 0.05556, 0.4059],
  2260. "57649": [0, 0.43056, 0, 0.02778, 0.32246],
  2261. "57911": [0.19444, 0.43056, 0, 0.08334, 0.38403]
  2262. },
  2263. "SansSerif-Bold": {
  2264. "32": [0, 0, 0, 0, 0.25],
  2265. "33": [0, 0.69444, 0, 0, 0.36667],
  2266. "34": [0, 0.69444, 0, 0, 0.55834],
  2267. "35": [0.19444, 0.69444, 0, 0, 0.91667],
  2268. "36": [0.05556, 0.75, 0, 0, 0.55],
  2269. "37": [0.05556, 0.75, 0, 0, 1.02912],
  2270. "38": [0, 0.69444, 0, 0, 0.83056],
  2271. "39": [0, 0.69444, 0, 0, 0.30556],
  2272. "40": [0.25, 0.75, 0, 0, 0.42778],
  2273. "41": [0.25, 0.75, 0, 0, 0.42778],
  2274. "42": [0, 0.75, 0, 0, 0.55],
  2275. "43": [0.11667, 0.61667, 0, 0, 0.85556],
  2276. "44": [0.10556, 0.13056, 0, 0, 0.30556],
  2277. "45": [0, 0.45833, 0, 0, 0.36667],
  2278. "46": [0, 0.13056, 0, 0, 0.30556],
  2279. "47": [0.25, 0.75, 0, 0, 0.55],
  2280. "48": [0, 0.69444, 0, 0, 0.55],
  2281. "49": [0, 0.69444, 0, 0, 0.55],
  2282. "50": [0, 0.69444, 0, 0, 0.55],
  2283. "51": [0, 0.69444, 0, 0, 0.55],
  2284. "52": [0, 0.69444, 0, 0, 0.55],
  2285. "53": [0, 0.69444, 0, 0, 0.55],
  2286. "54": [0, 0.69444, 0, 0, 0.55],
  2287. "55": [0, 0.69444, 0, 0, 0.55],
  2288. "56": [0, 0.69444, 0, 0, 0.55],
  2289. "57": [0, 0.69444, 0, 0, 0.55],
  2290. "58": [0, 0.45833, 0, 0, 0.30556],
  2291. "59": [0.10556, 0.45833, 0, 0, 0.30556],
  2292. "61": [-0.09375, 0.40625, 0, 0, 0.85556],
  2293. "63": [0, 0.69444, 0, 0, 0.51945],
  2294. "64": [0, 0.69444, 0, 0, 0.73334],
  2295. "65": [0, 0.69444, 0, 0, 0.73334],
  2296. "66": [0, 0.69444, 0, 0, 0.73334],
  2297. "67": [0, 0.69444, 0, 0, 0.70278],
  2298. "68": [0, 0.69444, 0, 0, 0.79445],
  2299. "69": [0, 0.69444, 0, 0, 0.64167],
  2300. "70": [0, 0.69444, 0, 0, 0.61111],
  2301. "71": [0, 0.69444, 0, 0, 0.73334],
  2302. "72": [0, 0.69444, 0, 0, 0.79445],
  2303. "73": [0, 0.69444, 0, 0, 0.33056],
  2304. "74": [0, 0.69444, 0, 0, 0.51945],
  2305. "75": [0, 0.69444, 0, 0, 0.76389],
  2306. "76": [0, 0.69444, 0, 0, 0.58056],
  2307. "77": [0, 0.69444, 0, 0, 0.97778],
  2308. "78": [0, 0.69444, 0, 0, 0.79445],
  2309. "79": [0, 0.69444, 0, 0, 0.79445],
  2310. "80": [0, 0.69444, 0, 0, 0.70278],
  2311. "81": [0.10556, 0.69444, 0, 0, 0.79445],
  2312. "82": [0, 0.69444, 0, 0, 0.70278],
  2313. "83": [0, 0.69444, 0, 0, 0.61111],
  2314. "84": [0, 0.69444, 0, 0, 0.73334],
  2315. "85": [0, 0.69444, 0, 0, 0.76389],
  2316. "86": [0, 0.69444, 0.01528, 0, 0.73334],
  2317. "87": [0, 0.69444, 0.01528, 0, 1.03889],
  2318. "88": [0, 0.69444, 0, 0, 0.73334],
  2319. "89": [0, 0.69444, 0.0275, 0, 0.73334],
  2320. "90": [0, 0.69444, 0, 0, 0.67223],
  2321. "91": [0.25, 0.75, 0, 0, 0.34306],
  2322. "93": [0.25, 0.75, 0, 0, 0.34306],
  2323. "94": [0, 0.69444, 0, 0, 0.55],
  2324. "95": [0.35, 0.10833, 0.03056, 0, 0.55],
  2325. "97": [0, 0.45833, 0, 0, 0.525],
  2326. "98": [0, 0.69444, 0, 0, 0.56111],
  2327. "99": [0, 0.45833, 0, 0, 0.48889],
  2328. "100": [0, 0.69444, 0, 0, 0.56111],
  2329. "101": [0, 0.45833, 0, 0, 0.51111],
  2330. "102": [0, 0.69444, 0.07639, 0, 0.33611],
  2331. "103": [0.19444, 0.45833, 0.01528, 0, 0.55],
  2332. "104": [0, 0.69444, 0, 0, 0.56111],
  2333. "105": [0, 0.69444, 0, 0, 0.25556],
  2334. "106": [0.19444, 0.69444, 0, 0, 0.28611],
  2335. "107": [0, 0.69444, 0, 0, 0.53056],
  2336. "108": [0, 0.69444, 0, 0, 0.25556],
  2337. "109": [0, 0.45833, 0, 0, 0.86667],
  2338. "110": [0, 0.45833, 0, 0, 0.56111],
  2339. "111": [0, 0.45833, 0, 0, 0.55],
  2340. "112": [0.19444, 0.45833, 0, 0, 0.56111],
  2341. "113": [0.19444, 0.45833, 0, 0, 0.56111],
  2342. "114": [0, 0.45833, 0.01528, 0, 0.37222],
  2343. "115": [0, 0.45833, 0, 0, 0.42167],
  2344. "116": [0, 0.58929, 0, 0, 0.40417],
  2345. "117": [0, 0.45833, 0, 0, 0.56111],
  2346. "118": [0, 0.45833, 0.01528, 0, 0.5],
  2347. "119": [0, 0.45833, 0.01528, 0, 0.74445],
  2348. "120": [0, 0.45833, 0, 0, 0.5],
  2349. "121": [0.19444, 0.45833, 0.01528, 0, 0.5],
  2350. "122": [0, 0.45833, 0, 0, 0.47639],
  2351. "126": [0.35, 0.34444, 0, 0, 0.55],
  2352. "160": [0, 0, 0, 0, 0.25],
  2353. "168": [0, 0.69444, 0, 0, 0.55],
  2354. "176": [0, 0.69444, 0, 0, 0.73334],
  2355. "180": [0, 0.69444, 0, 0, 0.55],
  2356. "184": [0.17014, 0, 0, 0, 0.48889],
  2357. "305": [0, 0.45833, 0, 0, 0.25556],
  2358. "567": [0.19444, 0.45833, 0, 0, 0.28611],
  2359. "710": [0, 0.69444, 0, 0, 0.55],
  2360. "711": [0, 0.63542, 0, 0, 0.55],
  2361. "713": [0, 0.63778, 0, 0, 0.55],
  2362. "728": [0, 0.69444, 0, 0, 0.55],
  2363. "729": [0, 0.69444, 0, 0, 0.30556],
  2364. "730": [0, 0.69444, 0, 0, 0.73334],
  2365. "732": [0, 0.69444, 0, 0, 0.55],
  2366. "733": [0, 0.69444, 0, 0, 0.55],
  2367. "915": [0, 0.69444, 0, 0, 0.58056],
  2368. "916": [0, 0.69444, 0, 0, 0.91667],
  2369. "920": [0, 0.69444, 0, 0, 0.85556],
  2370. "923": [0, 0.69444, 0, 0, 0.67223],
  2371. "926": [0, 0.69444, 0, 0, 0.73334],
  2372. "928": [0, 0.69444, 0, 0, 0.79445],
  2373. "931": [0, 0.69444, 0, 0, 0.79445],
  2374. "933": [0, 0.69444, 0, 0, 0.85556],
  2375. "934": [0, 0.69444, 0, 0, 0.79445],
  2376. "936": [0, 0.69444, 0, 0, 0.85556],
  2377. "937": [0, 0.69444, 0, 0, 0.79445],
  2378. "8211": [0, 0.45833, 0.03056, 0, 0.55],
  2379. "8212": [0, 0.45833, 0.03056, 0, 1.10001],
  2380. "8216": [0, 0.69444, 0, 0, 0.30556],
  2381. "8217": [0, 0.69444, 0, 0, 0.30556],
  2382. "8220": [0, 0.69444, 0, 0, 0.55834],
  2383. "8221": [0, 0.69444, 0, 0, 0.55834]
  2384. },
  2385. "SansSerif-Italic": {
  2386. "32": [0, 0, 0, 0, 0.25],
  2387. "33": [0, 0.69444, 0.05733, 0, 0.31945],
  2388. "34": [0, 0.69444, 0.00316, 0, 0.5],
  2389. "35": [0.19444, 0.69444, 0.05087, 0, 0.83334],
  2390. "36": [0.05556, 0.75, 0.11156, 0, 0.5],
  2391. "37": [0.05556, 0.75, 0.03126, 0, 0.83334],
  2392. "38": [0, 0.69444, 0.03058, 0, 0.75834],
  2393. "39": [0, 0.69444, 0.07816, 0, 0.27778],
  2394. "40": [0.25, 0.75, 0.13164, 0, 0.38889],
  2395. "41": [0.25, 0.75, 0.02536, 0, 0.38889],
  2396. "42": [0, 0.75, 0.11775, 0, 0.5],
  2397. "43": [0.08333, 0.58333, 0.02536, 0, 0.77778],
  2398. "44": [0.125, 0.08333, 0, 0, 0.27778],
  2399. "45": [0, 0.44444, 0.01946, 0, 0.33333],
  2400. "46": [0, 0.08333, 0, 0, 0.27778],
  2401. "47": [0.25, 0.75, 0.13164, 0, 0.5],
  2402. "48": [0, 0.65556, 0.11156, 0, 0.5],
  2403. "49": [0, 0.65556, 0.11156, 0, 0.5],
  2404. "50": [0, 0.65556, 0.11156, 0, 0.5],
  2405. "51": [0, 0.65556, 0.11156, 0, 0.5],
  2406. "52": [0, 0.65556, 0.11156, 0, 0.5],
  2407. "53": [0, 0.65556, 0.11156, 0, 0.5],
  2408. "54": [0, 0.65556, 0.11156, 0, 0.5],
  2409. "55": [0, 0.65556, 0.11156, 0, 0.5],
  2410. "56": [0, 0.65556, 0.11156, 0, 0.5],
  2411. "57": [0, 0.65556, 0.11156, 0, 0.5],
  2412. "58": [0, 0.44444, 0.02502, 0, 0.27778],
  2413. "59": [0.125, 0.44444, 0.02502, 0, 0.27778],
  2414. "61": [-0.13, 0.37, 0.05087, 0, 0.77778],
  2415. "63": [0, 0.69444, 0.11809, 0, 0.47222],
  2416. "64": [0, 0.69444, 0.07555, 0, 0.66667],
  2417. "65": [0, 0.69444, 0, 0, 0.66667],
  2418. "66": [0, 0.69444, 0.08293, 0, 0.66667],
  2419. "67": [0, 0.69444, 0.11983, 0, 0.63889],
  2420. "68": [0, 0.69444, 0.07555, 0, 0.72223],
  2421. "69": [0, 0.69444, 0.11983, 0, 0.59722],
  2422. "70": [0, 0.69444, 0.13372, 0, 0.56945],
  2423. "71": [0, 0.69444, 0.11983, 0, 0.66667],
  2424. "72": [0, 0.69444, 0.08094, 0, 0.70834],
  2425. "73": [0, 0.69444, 0.13372, 0, 0.27778],
  2426. "74": [0, 0.69444, 0.08094, 0, 0.47222],
  2427. "75": [0, 0.69444, 0.11983, 0, 0.69445],
  2428. "76": [0, 0.69444, 0, 0, 0.54167],
  2429. "77": [0, 0.69444, 0.08094, 0, 0.875],
  2430. "78": [0, 0.69444, 0.08094, 0, 0.70834],
  2431. "79": [0, 0.69444, 0.07555, 0, 0.73611],
  2432. "80": [0, 0.69444, 0.08293, 0, 0.63889],
  2433. "81": [0.125, 0.69444, 0.07555, 0, 0.73611],
  2434. "82": [0, 0.69444, 0.08293, 0, 0.64584],
  2435. "83": [0, 0.69444, 0.09205, 0, 0.55556],
  2436. "84": [0, 0.69444, 0.13372, 0, 0.68056],
  2437. "85": [0, 0.69444, 0.08094, 0, 0.6875],
  2438. "86": [0, 0.69444, 0.1615, 0, 0.66667],
  2439. "87": [0, 0.69444, 0.1615, 0, 0.94445],
  2440. "88": [0, 0.69444, 0.13372, 0, 0.66667],
  2441. "89": [0, 0.69444, 0.17261, 0, 0.66667],
  2442. "90": [0, 0.69444, 0.11983, 0, 0.61111],
  2443. "91": [0.25, 0.75, 0.15942, 0, 0.28889],
  2444. "93": [0.25, 0.75, 0.08719, 0, 0.28889],
  2445. "94": [0, 0.69444, 0.0799, 0, 0.5],
  2446. "95": [0.35, 0.09444, 0.08616, 0, 0.5],
  2447. "97": [0, 0.44444, 0.00981, 0, 0.48056],
  2448. "98": [0, 0.69444, 0.03057, 0, 0.51667],
  2449. "99": [0, 0.44444, 0.08336, 0, 0.44445],
  2450. "100": [0, 0.69444, 0.09483, 0, 0.51667],
  2451. "101": [0, 0.44444, 0.06778, 0, 0.44445],
  2452. "102": [0, 0.69444, 0.21705, 0, 0.30556],
  2453. "103": [0.19444, 0.44444, 0.10836, 0, 0.5],
  2454. "104": [0, 0.69444, 0.01778, 0, 0.51667],
  2455. "105": [0, 0.67937, 0.09718, 0, 0.23889],
  2456. "106": [0.19444, 0.67937, 0.09162, 0, 0.26667],
  2457. "107": [0, 0.69444, 0.08336, 0, 0.48889],
  2458. "108": [0, 0.69444, 0.09483, 0, 0.23889],
  2459. "109": [0, 0.44444, 0.01778, 0, 0.79445],
  2460. "110": [0, 0.44444, 0.01778, 0, 0.51667],
  2461. "111": [0, 0.44444, 0.06613, 0, 0.5],
  2462. "112": [0.19444, 0.44444, 0.0389, 0, 0.51667],
  2463. "113": [0.19444, 0.44444, 0.04169, 0, 0.51667],
  2464. "114": [0, 0.44444, 0.10836, 0, 0.34167],
  2465. "115": [0, 0.44444, 0.0778, 0, 0.38333],
  2466. "116": [0, 0.57143, 0.07225, 0, 0.36111],
  2467. "117": [0, 0.44444, 0.04169, 0, 0.51667],
  2468. "118": [0, 0.44444, 0.10836, 0, 0.46111],
  2469. "119": [0, 0.44444, 0.10836, 0, 0.68334],
  2470. "120": [0, 0.44444, 0.09169, 0, 0.46111],
  2471. "121": [0.19444, 0.44444, 0.10836, 0, 0.46111],
  2472. "122": [0, 0.44444, 0.08752, 0, 0.43472],
  2473. "126": [0.35, 0.32659, 0.08826, 0, 0.5],
  2474. "160": [0, 0, 0, 0, 0.25],
  2475. "168": [0, 0.67937, 0.06385, 0, 0.5],
  2476. "176": [0, 0.69444, 0, 0, 0.73752],
  2477. "184": [0.17014, 0, 0, 0, 0.44445],
  2478. "305": [0, 0.44444, 0.04169, 0, 0.23889],
  2479. "567": [0.19444, 0.44444, 0.04169, 0, 0.26667],
  2480. "710": [0, 0.69444, 0.0799, 0, 0.5],
  2481. "711": [0, 0.63194, 0.08432, 0, 0.5],
  2482. "713": [0, 0.60889, 0.08776, 0, 0.5],
  2483. "714": [0, 0.69444, 0.09205, 0, 0.5],
  2484. "715": [0, 0.69444, 0, 0, 0.5],
  2485. "728": [0, 0.69444, 0.09483, 0, 0.5],
  2486. "729": [0, 0.67937, 0.07774, 0, 0.27778],
  2487. "730": [0, 0.69444, 0, 0, 0.73752],
  2488. "732": [0, 0.67659, 0.08826, 0, 0.5],
  2489. "733": [0, 0.69444, 0.09205, 0, 0.5],
  2490. "915": [0, 0.69444, 0.13372, 0, 0.54167],
  2491. "916": [0, 0.69444, 0, 0, 0.83334],
  2492. "920": [0, 0.69444, 0.07555, 0, 0.77778],
  2493. "923": [0, 0.69444, 0, 0, 0.61111],
  2494. "926": [0, 0.69444, 0.12816, 0, 0.66667],
  2495. "928": [0, 0.69444, 0.08094, 0, 0.70834],
  2496. "931": [0, 0.69444, 0.11983, 0, 0.72222],
  2497. "933": [0, 0.69444, 0.09031, 0, 0.77778],
  2498. "934": [0, 0.69444, 0.04603, 0, 0.72222],
  2499. "936": [0, 0.69444, 0.09031, 0, 0.77778],
  2500. "937": [0, 0.69444, 0.08293, 0, 0.72222],
  2501. "8211": [0, 0.44444, 0.08616, 0, 0.5],
  2502. "8212": [0, 0.44444, 0.08616, 0, 1.0],
  2503. "8216": [0, 0.69444, 0.07816, 0, 0.27778],
  2504. "8217": [0, 0.69444, 0.07816, 0, 0.27778],
  2505. "8220": [0, 0.69444, 0.14205, 0, 0.5],
  2506. "8221": [0, 0.69444, 0.00316, 0, 0.5]
  2507. },
  2508. "SansSerif-Regular": {
  2509. "32": [0, 0, 0, 0, 0.25],
  2510. "33": [0, 0.69444, 0, 0, 0.31945],
  2511. "34": [0, 0.69444, 0, 0, 0.5],
  2512. "35": [0.19444, 0.69444, 0, 0, 0.83334],
  2513. "36": [0.05556, 0.75, 0, 0, 0.5],
  2514. "37": [0.05556, 0.75, 0, 0, 0.83334],
  2515. "38": [0, 0.69444, 0, 0, 0.75834],
  2516. "39": [0, 0.69444, 0, 0, 0.27778],
  2517. "40": [0.25, 0.75, 0, 0, 0.38889],
  2518. "41": [0.25, 0.75, 0, 0, 0.38889],
  2519. "42": [0, 0.75, 0, 0, 0.5],
  2520. "43": [0.08333, 0.58333, 0, 0, 0.77778],
  2521. "44": [0.125, 0.08333, 0, 0, 0.27778],
  2522. "45": [0, 0.44444, 0, 0, 0.33333],
  2523. "46": [0, 0.08333, 0, 0, 0.27778],
  2524. "47": [0.25, 0.75, 0, 0, 0.5],
  2525. "48": [0, 0.65556, 0, 0, 0.5],
  2526. "49": [0, 0.65556, 0, 0, 0.5],
  2527. "50": [0, 0.65556, 0, 0, 0.5],
  2528. "51": [0, 0.65556, 0, 0, 0.5],
  2529. "52": [0, 0.65556, 0, 0, 0.5],
  2530. "53": [0, 0.65556, 0, 0, 0.5],
  2531. "54": [0, 0.65556, 0, 0, 0.5],
  2532. "55": [0, 0.65556, 0, 0, 0.5],
  2533. "56": [0, 0.65556, 0, 0, 0.5],
  2534. "57": [0, 0.65556, 0, 0, 0.5],
  2535. "58": [0, 0.44444, 0, 0, 0.27778],
  2536. "59": [0.125, 0.44444, 0, 0, 0.27778],
  2537. "61": [-0.13, 0.37, 0, 0, 0.77778],
  2538. "63": [0, 0.69444, 0, 0, 0.47222],
  2539. "64": [0, 0.69444, 0, 0, 0.66667],
  2540. "65": [0, 0.69444, 0, 0, 0.66667],
  2541. "66": [0, 0.69444, 0, 0, 0.66667],
  2542. "67": [0, 0.69444, 0, 0, 0.63889],
  2543. "68": [0, 0.69444, 0, 0, 0.72223],
  2544. "69": [0, 0.69444, 0, 0, 0.59722],
  2545. "70": [0, 0.69444, 0, 0, 0.56945],
  2546. "71": [0, 0.69444, 0, 0, 0.66667],
  2547. "72": [0, 0.69444, 0, 0, 0.70834],
  2548. "73": [0, 0.69444, 0, 0, 0.27778],
  2549. "74": [0, 0.69444, 0, 0, 0.47222],
  2550. "75": [0, 0.69444, 0, 0, 0.69445],
  2551. "76": [0, 0.69444, 0, 0, 0.54167],
  2552. "77": [0, 0.69444, 0, 0, 0.875],
  2553. "78": [0, 0.69444, 0, 0, 0.70834],
  2554. "79": [0, 0.69444, 0, 0, 0.73611],
  2555. "80": [0, 0.69444, 0, 0, 0.63889],
  2556. "81": [0.125, 0.69444, 0, 0, 0.73611],
  2557. "82": [0, 0.69444, 0, 0, 0.64584],
  2558. "83": [0, 0.69444, 0, 0, 0.55556],
  2559. "84": [0, 0.69444, 0, 0, 0.68056],
  2560. "85": [0, 0.69444, 0, 0, 0.6875],
  2561. "86": [0, 0.69444, 0.01389, 0, 0.66667],
  2562. "87": [0, 0.69444, 0.01389, 0, 0.94445],
  2563. "88": [0, 0.69444, 0, 0, 0.66667],
  2564. "89": [0, 0.69444, 0.025, 0, 0.66667],
  2565. "90": [0, 0.69444, 0, 0, 0.61111],
  2566. "91": [0.25, 0.75, 0, 0, 0.28889],
  2567. "93": [0.25, 0.75, 0, 0, 0.28889],
  2568. "94": [0, 0.69444, 0, 0, 0.5],
  2569. "95": [0.35, 0.09444, 0.02778, 0, 0.5],
  2570. "97": [0, 0.44444, 0, 0, 0.48056],
  2571. "98": [0, 0.69444, 0, 0, 0.51667],
  2572. "99": [0, 0.44444, 0, 0, 0.44445],
  2573. "100": [0, 0.69444, 0, 0, 0.51667],
  2574. "101": [0, 0.44444, 0, 0, 0.44445],
  2575. "102": [0, 0.69444, 0.06944, 0, 0.30556],
  2576. "103": [0.19444, 0.44444, 0.01389, 0, 0.5],
  2577. "104": [0, 0.69444, 0, 0, 0.51667],
  2578. "105": [0, 0.67937, 0, 0, 0.23889],
  2579. "106": [0.19444, 0.67937, 0, 0, 0.26667],
  2580. "107": [0, 0.69444, 0, 0, 0.48889],
  2581. "108": [0, 0.69444, 0, 0, 0.23889],
  2582. "109": [0, 0.44444, 0, 0, 0.79445],
  2583. "110": [0, 0.44444, 0, 0, 0.51667],
  2584. "111": [0, 0.44444, 0, 0, 0.5],
  2585. "112": [0.19444, 0.44444, 0, 0, 0.51667],
  2586. "113": [0.19444, 0.44444, 0, 0, 0.51667],
  2587. "114": [0, 0.44444, 0.01389, 0, 0.34167],
  2588. "115": [0, 0.44444, 0, 0, 0.38333],
  2589. "116": [0, 0.57143, 0, 0, 0.36111],
  2590. "117": [0, 0.44444, 0, 0, 0.51667],
  2591. "118": [0, 0.44444, 0.01389, 0, 0.46111],
  2592. "119": [0, 0.44444, 0.01389, 0, 0.68334],
  2593. "120": [0, 0.44444, 0, 0, 0.46111],
  2594. "121": [0.19444, 0.44444, 0.01389, 0, 0.46111],
  2595. "122": [0, 0.44444, 0, 0, 0.43472],
  2596. "126": [0.35, 0.32659, 0, 0, 0.5],
  2597. "160": [0, 0, 0, 0, 0.25],
  2598. "168": [0, 0.67937, 0, 0, 0.5],
  2599. "176": [0, 0.69444, 0, 0, 0.66667],
  2600. "184": [0.17014, 0, 0, 0, 0.44445],
  2601. "305": [0, 0.44444, 0, 0, 0.23889],
  2602. "567": [0.19444, 0.44444, 0, 0, 0.26667],
  2603. "710": [0, 0.69444, 0, 0, 0.5],
  2604. "711": [0, 0.63194, 0, 0, 0.5],
  2605. "713": [0, 0.60889, 0, 0, 0.5],
  2606. "714": [0, 0.69444, 0, 0, 0.5],
  2607. "715": [0, 0.69444, 0, 0, 0.5],
  2608. "728": [0, 0.69444, 0, 0, 0.5],
  2609. "729": [0, 0.67937, 0, 0, 0.27778],
  2610. "730": [0, 0.69444, 0, 0, 0.66667],
  2611. "732": [0, 0.67659, 0, 0, 0.5],
  2612. "733": [0, 0.69444, 0, 0, 0.5],
  2613. "915": [0, 0.69444, 0, 0, 0.54167],
  2614. "916": [0, 0.69444, 0, 0, 0.83334],
  2615. "920": [0, 0.69444, 0, 0, 0.77778],
  2616. "923": [0, 0.69444, 0, 0, 0.61111],
  2617. "926": [0, 0.69444, 0, 0, 0.66667],
  2618. "928": [0, 0.69444, 0, 0, 0.70834],
  2619. "931": [0, 0.69444, 0, 0, 0.72222],
  2620. "933": [0, 0.69444, 0, 0, 0.77778],
  2621. "934": [0, 0.69444, 0, 0, 0.72222],
  2622. "936": [0, 0.69444, 0, 0, 0.77778],
  2623. "937": [0, 0.69444, 0, 0, 0.72222],
  2624. "8211": [0, 0.44444, 0.02778, 0, 0.5],
  2625. "8212": [0, 0.44444, 0.02778, 0, 1.0],
  2626. "8216": [0, 0.69444, 0, 0, 0.27778],
  2627. "8217": [0, 0.69444, 0, 0, 0.27778],
  2628. "8220": [0, 0.69444, 0, 0, 0.5],
  2629. "8221": [0, 0.69444, 0, 0, 0.5]
  2630. },
  2631. "Script-Regular": {
  2632. "32": [0, 0, 0, 0, 0.25],
  2633. "65": [0, 0.7, 0.22925, 0, 0.80253],
  2634. "66": [0, 0.7, 0.04087, 0, 0.90757],
  2635. "67": [0, 0.7, 0.1689, 0, 0.66619],
  2636. "68": [0, 0.7, 0.09371, 0, 0.77443],
  2637. "69": [0, 0.7, 0.18583, 0, 0.56162],
  2638. "70": [0, 0.7, 0.13634, 0, 0.89544],
  2639. "71": [0, 0.7, 0.17322, 0, 0.60961],
  2640. "72": [0, 0.7, 0.29694, 0, 0.96919],
  2641. "73": [0, 0.7, 0.19189, 0, 0.80907],
  2642. "74": [0.27778, 0.7, 0.19189, 0, 1.05159],
  2643. "75": [0, 0.7, 0.31259, 0, 0.91364],
  2644. "76": [0, 0.7, 0.19189, 0, 0.87373],
  2645. "77": [0, 0.7, 0.15981, 0, 1.08031],
  2646. "78": [0, 0.7, 0.3525, 0, 0.9015],
  2647. "79": [0, 0.7, 0.08078, 0, 0.73787],
  2648. "80": [0, 0.7, 0.08078, 0, 1.01262],
  2649. "81": [0, 0.7, 0.03305, 0, 0.88282],
  2650. "82": [0, 0.7, 0.06259, 0, 0.85],
  2651. "83": [0, 0.7, 0.19189, 0, 0.86767],
  2652. "84": [0, 0.7, 0.29087, 0, 0.74697],
  2653. "85": [0, 0.7, 0.25815, 0, 0.79996],
  2654. "86": [0, 0.7, 0.27523, 0, 0.62204],
  2655. "87": [0, 0.7, 0.27523, 0, 0.80532],
  2656. "88": [0, 0.7, 0.26006, 0, 0.94445],
  2657. "89": [0, 0.7, 0.2939, 0, 0.70961],
  2658. "90": [0, 0.7, 0.24037, 0, 0.8212],
  2659. "160": [0, 0, 0, 0, 0.25]
  2660. },
  2661. "Size1-Regular": {
  2662. "32": [0, 0, 0, 0, 0.25],
  2663. "40": [0.35001, 0.85, 0, 0, 0.45834],
  2664. "41": [0.35001, 0.85, 0, 0, 0.45834],
  2665. "47": [0.35001, 0.85, 0, 0, 0.57778],
  2666. "91": [0.35001, 0.85, 0, 0, 0.41667],
  2667. "92": [0.35001, 0.85, 0, 0, 0.57778],
  2668. "93": [0.35001, 0.85, 0, 0, 0.41667],
  2669. "123": [0.35001, 0.85, 0, 0, 0.58334],
  2670. "125": [0.35001, 0.85, 0, 0, 0.58334],
  2671. "160": [0, 0, 0, 0, 0.25],
  2672. "710": [0, 0.72222, 0, 0, 0.55556],
  2673. "732": [0, 0.72222, 0, 0, 0.55556],
  2674. "770": [0, 0.72222, 0, 0, 0.55556],
  2675. "771": [0, 0.72222, 0, 0, 0.55556],
  2676. "8214": [-0.00099, 0.601, 0, 0, 0.77778],
  2677. "8593": [1e-05, 0.6, 0, 0, 0.66667],
  2678. "8595": [1e-05, 0.6, 0, 0, 0.66667],
  2679. "8657": [1e-05, 0.6, 0, 0, 0.77778],
  2680. "8659": [1e-05, 0.6, 0, 0, 0.77778],
  2681. "8719": [0.25001, 0.75, 0, 0, 0.94445],
  2682. "8720": [0.25001, 0.75, 0, 0, 0.94445],
  2683. "8721": [0.25001, 0.75, 0, 0, 1.05556],
  2684. "8730": [0.35001, 0.85, 0, 0, 1.0],
  2685. "8739": [-0.00599, 0.606, 0, 0, 0.33333],
  2686. "8741": [-0.00599, 0.606, 0, 0, 0.55556],
  2687. "8747": [0.30612, 0.805, 0.19445, 0, 0.47222],
  2688. "8748": [0.306, 0.805, 0.19445, 0, 0.47222],
  2689. "8749": [0.306, 0.805, 0.19445, 0, 0.47222],
  2690. "8750": [0.30612, 0.805, 0.19445, 0, 0.47222],
  2691. "8896": [0.25001, 0.75, 0, 0, 0.83334],
  2692. "8897": [0.25001, 0.75, 0, 0, 0.83334],
  2693. "8898": [0.25001, 0.75, 0, 0, 0.83334],
  2694. "8899": [0.25001, 0.75, 0, 0, 0.83334],
  2695. "8968": [0.35001, 0.85, 0, 0, 0.47222],
  2696. "8969": [0.35001, 0.85, 0, 0, 0.47222],
  2697. "8970": [0.35001, 0.85, 0, 0, 0.47222],
  2698. "8971": [0.35001, 0.85, 0, 0, 0.47222],
  2699. "9168": [-0.00099, 0.601, 0, 0, 0.66667],
  2700. "10216": [0.35001, 0.85, 0, 0, 0.47222],
  2701. "10217": [0.35001, 0.85, 0, 0, 0.47222],
  2702. "10752": [0.25001, 0.75, 0, 0, 1.11111],
  2703. "10753": [0.25001, 0.75, 0, 0, 1.11111],
  2704. "10754": [0.25001, 0.75, 0, 0, 1.11111],
  2705. "10756": [0.25001, 0.75, 0, 0, 0.83334],
  2706. "10758": [0.25001, 0.75, 0, 0, 0.83334]
  2707. },
  2708. "Size2-Regular": {
  2709. "32": [0, 0, 0, 0, 0.25],
  2710. "40": [0.65002, 1.15, 0, 0, 0.59722],
  2711. "41": [0.65002, 1.15, 0, 0, 0.59722],
  2712. "47": [0.65002, 1.15, 0, 0, 0.81111],
  2713. "91": [0.65002, 1.15, 0, 0, 0.47222],
  2714. "92": [0.65002, 1.15, 0, 0, 0.81111],
  2715. "93": [0.65002, 1.15, 0, 0, 0.47222],
  2716. "123": [0.65002, 1.15, 0, 0, 0.66667],
  2717. "125": [0.65002, 1.15, 0, 0, 0.66667],
  2718. "160": [0, 0, 0, 0, 0.25],
  2719. "710": [0, 0.75, 0, 0, 1.0],
  2720. "732": [0, 0.75, 0, 0, 1.0],
  2721. "770": [0, 0.75, 0, 0, 1.0],
  2722. "771": [0, 0.75, 0, 0, 1.0],
  2723. "8719": [0.55001, 1.05, 0, 0, 1.27778],
  2724. "8720": [0.55001, 1.05, 0, 0, 1.27778],
  2725. "8721": [0.55001, 1.05, 0, 0, 1.44445],
  2726. "8730": [0.65002, 1.15, 0, 0, 1.0],
  2727. "8747": [0.86225, 1.36, 0.44445, 0, 0.55556],
  2728. "8748": [0.862, 1.36, 0.44445, 0, 0.55556],
  2729. "8749": [0.862, 1.36, 0.44445, 0, 0.55556],
  2730. "8750": [0.86225, 1.36, 0.44445, 0, 0.55556],
  2731. "8896": [0.55001, 1.05, 0, 0, 1.11111],
  2732. "8897": [0.55001, 1.05, 0, 0, 1.11111],
  2733. "8898": [0.55001, 1.05, 0, 0, 1.11111],
  2734. "8899": [0.55001, 1.05, 0, 0, 1.11111],
  2735. "8968": [0.65002, 1.15, 0, 0, 0.52778],
  2736. "8969": [0.65002, 1.15, 0, 0, 0.52778],
  2737. "8970": [0.65002, 1.15, 0, 0, 0.52778],
  2738. "8971": [0.65002, 1.15, 0, 0, 0.52778],
  2739. "10216": [0.65002, 1.15, 0, 0, 0.61111],
  2740. "10217": [0.65002, 1.15, 0, 0, 0.61111],
  2741. "10752": [0.55001, 1.05, 0, 0, 1.51112],
  2742. "10753": [0.55001, 1.05, 0, 0, 1.51112],
  2743. "10754": [0.55001, 1.05, 0, 0, 1.51112],
  2744. "10756": [0.55001, 1.05, 0, 0, 1.11111],
  2745. "10758": [0.55001, 1.05, 0, 0, 1.11111]
  2746. },
  2747. "Size3-Regular": {
  2748. "32": [0, 0, 0, 0, 0.25],
  2749. "40": [0.95003, 1.45, 0, 0, 0.73611],
  2750. "41": [0.95003, 1.45, 0, 0, 0.73611],
  2751. "47": [0.95003, 1.45, 0, 0, 1.04445],
  2752. "91": [0.95003, 1.45, 0, 0, 0.52778],
  2753. "92": [0.95003, 1.45, 0, 0, 1.04445],
  2754. "93": [0.95003, 1.45, 0, 0, 0.52778],
  2755. "123": [0.95003, 1.45, 0, 0, 0.75],
  2756. "125": [0.95003, 1.45, 0, 0, 0.75],
  2757. "160": [0, 0, 0, 0, 0.25],
  2758. "710": [0, 0.75, 0, 0, 1.44445],
  2759. "732": [0, 0.75, 0, 0, 1.44445],
  2760. "770": [0, 0.75, 0, 0, 1.44445],
  2761. "771": [0, 0.75, 0, 0, 1.44445],
  2762. "8730": [0.95003, 1.45, 0, 0, 1.0],
  2763. "8968": [0.95003, 1.45, 0, 0, 0.58334],
  2764. "8969": [0.95003, 1.45, 0, 0, 0.58334],
  2765. "8970": [0.95003, 1.45, 0, 0, 0.58334],
  2766. "8971": [0.95003, 1.45, 0, 0, 0.58334],
  2767. "10216": [0.95003, 1.45, 0, 0, 0.75],
  2768. "10217": [0.95003, 1.45, 0, 0, 0.75]
  2769. },
  2770. "Size4-Regular": {
  2771. "32": [0, 0, 0, 0, 0.25],
  2772. "40": [1.25003, 1.75, 0, 0, 0.79167],
  2773. "41": [1.25003, 1.75, 0, 0, 0.79167],
  2774. "47": [1.25003, 1.75, 0, 0, 1.27778],
  2775. "91": [1.25003, 1.75, 0, 0, 0.58334],
  2776. "92": [1.25003, 1.75, 0, 0, 1.27778],
  2777. "93": [1.25003, 1.75, 0, 0, 0.58334],
  2778. "123": [1.25003, 1.75, 0, 0, 0.80556],
  2779. "125": [1.25003, 1.75, 0, 0, 0.80556],
  2780. "160": [0, 0, 0, 0, 0.25],
  2781. "710": [0, 0.825, 0, 0, 1.8889],
  2782. "732": [0, 0.825, 0, 0, 1.8889],
  2783. "770": [0, 0.825, 0, 0, 1.8889],
  2784. "771": [0, 0.825, 0, 0, 1.8889],
  2785. "8730": [1.25003, 1.75, 0, 0, 1.0],
  2786. "8968": [1.25003, 1.75, 0, 0, 0.63889],
  2787. "8969": [1.25003, 1.75, 0, 0, 0.63889],
  2788. "8970": [1.25003, 1.75, 0, 0, 0.63889],
  2789. "8971": [1.25003, 1.75, 0, 0, 0.63889],
  2790. "9115": [0.64502, 1.155, 0, 0, 0.875],
  2791. "9116": [1e-05, 0.6, 0, 0, 0.875],
  2792. "9117": [0.64502, 1.155, 0, 0, 0.875],
  2793. "9118": [0.64502, 1.155, 0, 0, 0.875],
  2794. "9119": [1e-05, 0.6, 0, 0, 0.875],
  2795. "9120": [0.64502, 1.155, 0, 0, 0.875],
  2796. "9121": [0.64502, 1.155, 0, 0, 0.66667],
  2797. "9122": [-0.00099, 0.601, 0, 0, 0.66667],
  2798. "9123": [0.64502, 1.155, 0, 0, 0.66667],
  2799. "9124": [0.64502, 1.155, 0, 0, 0.66667],
  2800. "9125": [-0.00099, 0.601, 0, 0, 0.66667],
  2801. "9126": [0.64502, 1.155, 0, 0, 0.66667],
  2802. "9127": [1e-05, 0.9, 0, 0, 0.88889],
  2803. "9128": [0.65002, 1.15, 0, 0, 0.88889],
  2804. "9129": [0.90001, 0, 0, 0, 0.88889],
  2805. "9130": [0, 0.3, 0, 0, 0.88889],
  2806. "9131": [1e-05, 0.9, 0, 0, 0.88889],
  2807. "9132": [0.65002, 1.15, 0, 0, 0.88889],
  2808. "9133": [0.90001, 0, 0, 0, 0.88889],
  2809. "9143": [0.88502, 0.915, 0, 0, 1.05556],
  2810. "10216": [1.25003, 1.75, 0, 0, 0.80556],
  2811. "10217": [1.25003, 1.75, 0, 0, 0.80556],
  2812. "57344": [-0.00499, 0.605, 0, 0, 1.05556],
  2813. "57345": [-0.00499, 0.605, 0, 0, 1.05556],
  2814. "57680": [0, 0.12, 0, 0, 0.45],
  2815. "57681": [0, 0.12, 0, 0, 0.45],
  2816. "57682": [0, 0.12, 0, 0, 0.45],
  2817. "57683": [0, 0.12, 0, 0, 0.45]
  2818. },
  2819. "Typewriter-Regular": {
  2820. "32": [0, 0, 0, 0, 0.525],
  2821. "33": [0, 0.61111, 0, 0, 0.525],
  2822. "34": [0, 0.61111, 0, 0, 0.525],
  2823. "35": [0, 0.61111, 0, 0, 0.525],
  2824. "36": [0.08333, 0.69444, 0, 0, 0.525],
  2825. "37": [0.08333, 0.69444, 0, 0, 0.525],
  2826. "38": [0, 0.61111, 0, 0, 0.525],
  2827. "39": [0, 0.61111, 0, 0, 0.525],
  2828. "40": [0.08333, 0.69444, 0, 0, 0.525],
  2829. "41": [0.08333, 0.69444, 0, 0, 0.525],
  2830. "42": [0, 0.52083, 0, 0, 0.525],
  2831. "43": [-0.08056, 0.53055, 0, 0, 0.525],
  2832. "44": [0.13889, 0.125, 0, 0, 0.525],
  2833. "45": [-0.08056, 0.53055, 0, 0, 0.525],
  2834. "46": [0, 0.125, 0, 0, 0.525],
  2835. "47": [0.08333, 0.69444, 0, 0, 0.525],
  2836. "48": [0, 0.61111, 0, 0, 0.525],
  2837. "49": [0, 0.61111, 0, 0, 0.525],
  2838. "50": [0, 0.61111, 0, 0, 0.525],
  2839. "51": [0, 0.61111, 0, 0, 0.525],
  2840. "52": [0, 0.61111, 0, 0, 0.525],
  2841. "53": [0, 0.61111, 0, 0, 0.525],
  2842. "54": [0, 0.61111, 0, 0, 0.525],
  2843. "55": [0, 0.61111, 0, 0, 0.525],
  2844. "56": [0, 0.61111, 0, 0, 0.525],
  2845. "57": [0, 0.61111, 0, 0, 0.525],
  2846. "58": [0, 0.43056, 0, 0, 0.525],
  2847. "59": [0.13889, 0.43056, 0, 0, 0.525],
  2848. "60": [-0.05556, 0.55556, 0, 0, 0.525],
  2849. "61": [-0.19549, 0.41562, 0, 0, 0.525],
  2850. "62": [-0.05556, 0.55556, 0, 0, 0.525],
  2851. "63": [0, 0.61111, 0, 0, 0.525],
  2852. "64": [0, 0.61111, 0, 0, 0.525],
  2853. "65": [0, 0.61111, 0, 0, 0.525],
  2854. "66": [0, 0.61111, 0, 0, 0.525],
  2855. "67": [0, 0.61111, 0, 0, 0.525],
  2856. "68": [0, 0.61111, 0, 0, 0.525],
  2857. "69": [0, 0.61111, 0, 0, 0.525],
  2858. "70": [0, 0.61111, 0, 0, 0.525],
  2859. "71": [0, 0.61111, 0, 0, 0.525],
  2860. "72": [0, 0.61111, 0, 0, 0.525],
  2861. "73": [0, 0.61111, 0, 0, 0.525],
  2862. "74": [0, 0.61111, 0, 0, 0.525],
  2863. "75": [0, 0.61111, 0, 0, 0.525],
  2864. "76": [0, 0.61111, 0, 0, 0.525],
  2865. "77": [0, 0.61111, 0, 0, 0.525],
  2866. "78": [0, 0.61111, 0, 0, 0.525],
  2867. "79": [0, 0.61111, 0, 0, 0.525],
  2868. "80": [0, 0.61111, 0, 0, 0.525],
  2869. "81": [0.13889, 0.61111, 0, 0, 0.525],
  2870. "82": [0, 0.61111, 0, 0, 0.525],
  2871. "83": [0, 0.61111, 0, 0, 0.525],
  2872. "84": [0, 0.61111, 0, 0, 0.525],
  2873. "85": [0, 0.61111, 0, 0, 0.525],
  2874. "86": [0, 0.61111, 0, 0, 0.525],
  2875. "87": [0, 0.61111, 0, 0, 0.525],
  2876. "88": [0, 0.61111, 0, 0, 0.525],
  2877. "89": [0, 0.61111, 0, 0, 0.525],
  2878. "90": [0, 0.61111, 0, 0, 0.525],
  2879. "91": [0.08333, 0.69444, 0, 0, 0.525],
  2880. "92": [0.08333, 0.69444, 0, 0, 0.525],
  2881. "93": [0.08333, 0.69444, 0, 0, 0.525],
  2882. "94": [0, 0.61111, 0, 0, 0.525],
  2883. "95": [0.09514, 0, 0, 0, 0.525],
  2884. "96": [0, 0.61111, 0, 0, 0.525],
  2885. "97": [0, 0.43056, 0, 0, 0.525],
  2886. "98": [0, 0.61111, 0, 0, 0.525],
  2887. "99": [0, 0.43056, 0, 0, 0.525],
  2888. "100": [0, 0.61111, 0, 0, 0.525],
  2889. "101": [0, 0.43056, 0, 0, 0.525],
  2890. "102": [0, 0.61111, 0, 0, 0.525],
  2891. "103": [0.22222, 0.43056, 0, 0, 0.525],
  2892. "104": [0, 0.61111, 0, 0, 0.525],
  2893. "105": [0, 0.61111, 0, 0, 0.525],
  2894. "106": [0.22222, 0.61111, 0, 0, 0.525],
  2895. "107": [0, 0.61111, 0, 0, 0.525],
  2896. "108": [0, 0.61111, 0, 0, 0.525],
  2897. "109": [0, 0.43056, 0, 0, 0.525],
  2898. "110": [0, 0.43056, 0, 0, 0.525],
  2899. "111": [0, 0.43056, 0, 0, 0.525],
  2900. "112": [0.22222, 0.43056, 0, 0, 0.525],
  2901. "113": [0.22222, 0.43056, 0, 0, 0.525],
  2902. "114": [0, 0.43056, 0, 0, 0.525],
  2903. "115": [0, 0.43056, 0, 0, 0.525],
  2904. "116": [0, 0.55358, 0, 0, 0.525],
  2905. "117": [0, 0.43056, 0, 0, 0.525],
  2906. "118": [0, 0.43056, 0, 0, 0.525],
  2907. "119": [0, 0.43056, 0, 0, 0.525],
  2908. "120": [0, 0.43056, 0, 0, 0.525],
  2909. "121": [0.22222, 0.43056, 0, 0, 0.525],
  2910. "122": [0, 0.43056, 0, 0, 0.525],
  2911. "123": [0.08333, 0.69444, 0, 0, 0.525],
  2912. "124": [0.08333, 0.69444, 0, 0, 0.525],
  2913. "125": [0.08333, 0.69444, 0, 0, 0.525],
  2914. "126": [0, 0.61111, 0, 0, 0.525],
  2915. "127": [0, 0.61111, 0, 0, 0.525],
  2916. "160": [0, 0, 0, 0, 0.525],
  2917. "176": [0, 0.61111, 0, 0, 0.525],
  2918. "184": [0.19445, 0, 0, 0, 0.525],
  2919. "305": [0, 0.43056, 0, 0, 0.525],
  2920. "567": [0.22222, 0.43056, 0, 0, 0.525],
  2921. "711": [0, 0.56597, 0, 0, 0.525],
  2922. "713": [0, 0.56555, 0, 0, 0.525],
  2923. "714": [0, 0.61111, 0, 0, 0.525],
  2924. "715": [0, 0.61111, 0, 0, 0.525],
  2925. "728": [0, 0.61111, 0, 0, 0.525],
  2926. "730": [0, 0.61111, 0, 0, 0.525],
  2927. "770": [0, 0.61111, 0, 0, 0.525],
  2928. "771": [0, 0.61111, 0, 0, 0.525],
  2929. "776": [0, 0.61111, 0, 0, 0.525],
  2930. "915": [0, 0.61111, 0, 0, 0.525],
  2931. "916": [0, 0.61111, 0, 0, 0.525],
  2932. "920": [0, 0.61111, 0, 0, 0.525],
  2933. "923": [0, 0.61111, 0, 0, 0.525],
  2934. "926": [0, 0.61111, 0, 0, 0.525],
  2935. "928": [0, 0.61111, 0, 0, 0.525],
  2936. "931": [0, 0.61111, 0, 0, 0.525],
  2937. "933": [0, 0.61111, 0, 0, 0.525],
  2938. "934": [0, 0.61111, 0, 0, 0.525],
  2939. "936": [0, 0.61111, 0, 0, 0.525],
  2940. "937": [0, 0.61111, 0, 0, 0.525],
  2941. "8216": [0, 0.61111, 0, 0, 0.525],
  2942. "8217": [0, 0.61111, 0, 0, 0.525],
  2943. "8242": [0, 0.61111, 0, 0, 0.525],
  2944. "9251": [0.11111, 0.21944, 0, 0, 0.525]
  2945. }
  2946. };
  2947. /**
  2948. * This file contains metrics regarding fonts and individual symbols. The sigma
  2949. * and xi variables, as well as the metricMap map contain data extracted from
  2950. * TeX, TeX font metrics, and the TTF files. These data are then exposed via the
  2951. * `metrics` variable and the getCharacterMetrics function.
  2952. */
  2953. // In TeX, there are actually three sets of dimensions, one for each of
  2954. // textstyle (size index 5 and higher: >=9pt), scriptstyle (size index 3 and 4:
  2955. // 7-8pt), and scriptscriptstyle (size index 1 and 2: 5-6pt). These are
  2956. // provided in the the arrays below, in that order.
  2957. //
  2958. // The font metrics are stored in fonts cmsy10, cmsy7, and cmsy5 respsectively.
  2959. // This was determined by running the following script:
  2960. //
  2961. // latex -interaction=nonstopmode \
  2962. // '\documentclass{article}\usepackage{amsmath}\begin{document}' \
  2963. // '$a$ \expandafter\show\the\textfont2' \
  2964. // '\expandafter\show\the\scriptfont2' \
  2965. // '\expandafter\show\the\scriptscriptfont2' \
  2966. // '\stop'
  2967. //
  2968. // The metrics themselves were retreived using the following commands:
  2969. //
  2970. // tftopl cmsy10
  2971. // tftopl cmsy7
  2972. // tftopl cmsy5
  2973. //
  2974. // The output of each of these commands is quite lengthy. The only part we
  2975. // care about is the FONTDIMEN section. Each value is measured in EMs.
  2976. var sigmasAndXis = {
  2977. slant: [0.250, 0.250, 0.250],
  2978. // sigma1
  2979. space: [0.000, 0.000, 0.000],
  2980. // sigma2
  2981. stretch: [0.000, 0.000, 0.000],
  2982. // sigma3
  2983. shrink: [0.000, 0.000, 0.000],
  2984. // sigma4
  2985. xHeight: [0.431, 0.431, 0.431],
  2986. // sigma5
  2987. quad: [1.000, 1.171, 1.472],
  2988. // sigma6
  2989. extraSpace: [0.000, 0.000, 0.000],
  2990. // sigma7
  2991. num1: [0.677, 0.732, 0.925],
  2992. // sigma8
  2993. num2: [0.394, 0.384, 0.387],
  2994. // sigma9
  2995. num3: [0.444, 0.471, 0.504],
  2996. // sigma10
  2997. denom1: [0.686, 0.752, 1.025],
  2998. // sigma11
  2999. denom2: [0.345, 0.344, 0.532],
  3000. // sigma12
  3001. sup1: [0.413, 0.503, 0.504],
  3002. // sigma13
  3003. sup2: [0.363, 0.431, 0.404],
  3004. // sigma14
  3005. sup3: [0.289, 0.286, 0.294],
  3006. // sigma15
  3007. sub1: [0.150, 0.143, 0.200],
  3008. // sigma16
  3009. sub2: [0.247, 0.286, 0.400],
  3010. // sigma17
  3011. supDrop: [0.386, 0.353, 0.494],
  3012. // sigma18
  3013. subDrop: [0.050, 0.071, 0.100],
  3014. // sigma19
  3015. delim1: [2.390, 1.700, 1.980],
  3016. // sigma20
  3017. delim2: [1.010, 1.157, 1.420],
  3018. // sigma21
  3019. axisHeight: [0.250, 0.250, 0.250],
  3020. // sigma22
  3021. // These font metrics are extracted from TeX by using tftopl on cmex10.tfm;
  3022. // they correspond to the font parameters of the extension fonts (family 3).
  3023. // See the TeXbook, page 441. In AMSTeX, the extension fonts scale; to
  3024. // match cmex7, we'd use cmex7.tfm values for script and scriptscript
  3025. // values.
  3026. defaultRuleThickness: [0.04, 0.049, 0.049],
  3027. // xi8; cmex7: 0.049
  3028. bigOpSpacing1: [0.111, 0.111, 0.111],
  3029. // xi9
  3030. bigOpSpacing2: [0.166, 0.166, 0.166],
  3031. // xi10
  3032. bigOpSpacing3: [0.2, 0.2, 0.2],
  3033. // xi11
  3034. bigOpSpacing4: [0.6, 0.611, 0.611],
  3035. // xi12; cmex7: 0.611
  3036. bigOpSpacing5: [0.1, 0.143, 0.143],
  3037. // xi13; cmex7: 0.143
  3038. // The \sqrt rule width is taken from the height of the surd character.
  3039. // Since we use the same font at all sizes, this thickness doesn't scale.
  3040. sqrtRuleThickness: [0.04, 0.04, 0.04],
  3041. // This value determines how large a pt is, for metrics which are defined
  3042. // in terms of pts.
  3043. // This value is also used in katex.less; if you change it make sure the
  3044. // values match.
  3045. ptPerEm: [10.0, 10.0, 10.0],
  3046. // The space between adjacent `|` columns in an array definition. From
  3047. // `\showthe\doublerulesep` in LaTeX. Equals 2.0 / ptPerEm.
  3048. doubleRuleSep: [0.2, 0.2, 0.2],
  3049. // The width of separator lines in {array} environments. From
  3050. // `\showthe\arrayrulewidth` in LaTeX. Equals 0.4 / ptPerEm.
  3051. arrayRuleWidth: [0.04, 0.04, 0.04],
  3052. // Two values from LaTeX source2e:
  3053. fboxsep: [0.3, 0.3, 0.3],
  3054. // 3 pt / ptPerEm
  3055. fboxrule: [0.04, 0.04, 0.04] // 0.4 pt / ptPerEm
  3056. }; // This map contains a mapping from font name and character code to character
  3057. // should have Latin-1 and Cyrillic characters, but may not depending on the
  3058. // operating system. The metrics do not account for extra height from the
  3059. // accents. In the case of Cyrillic characters which have both ascenders and
  3060. // descenders we prefer approximations with ascenders, primarily to prevent
  3061. // the fraction bar or root line from intersecting the glyph.
  3062. // TODO(kevinb) allow union of multiple glyph metrics for better accuracy.
  3063. var extraCharacterMap = {
  3064. // Latin-1
  3065. 'Å': 'A',
  3066. 'Ð': 'D',
  3067. 'Þ': 'o',
  3068. 'å': 'a',
  3069. 'ð': 'd',
  3070. 'þ': 'o',
  3071. // Cyrillic
  3072. 'А': 'A',
  3073. 'Б': 'B',
  3074. 'В': 'B',
  3075. 'Г': 'F',
  3076. 'Д': 'A',
  3077. 'Е': 'E',
  3078. 'Ж': 'K',
  3079. 'З': '3',
  3080. 'И': 'N',
  3081. 'Й': 'N',
  3082. 'К': 'K',
  3083. 'Л': 'N',
  3084. 'М': 'M',
  3085. 'Н': 'H',
  3086. 'О': 'O',
  3087. 'П': 'N',
  3088. 'Р': 'P',
  3089. 'С': 'C',
  3090. 'Т': 'T',
  3091. 'У': 'y',
  3092. 'Ф': 'O',
  3093. 'Х': 'X',
  3094. 'Ц': 'U',
  3095. 'Ч': 'h',
  3096. 'Ш': 'W',
  3097. 'Щ': 'W',
  3098. 'Ъ': 'B',
  3099. 'Ы': 'X',
  3100. 'Ь': 'B',
  3101. 'Э': '3',
  3102. 'Ю': 'X',
  3103. 'Я': 'R',
  3104. 'а': 'a',
  3105. 'б': 'b',
  3106. 'в': 'a',
  3107. 'г': 'r',
  3108. 'д': 'y',
  3109. 'е': 'e',
  3110. 'ж': 'm',
  3111. 'з': 'e',
  3112. 'и': 'n',
  3113. 'й': 'n',
  3114. 'к': 'n',
  3115. 'л': 'n',
  3116. 'м': 'm',
  3117. 'н': 'n',
  3118. 'о': 'o',
  3119. 'п': 'n',
  3120. 'р': 'p',
  3121. 'с': 'c',
  3122. 'т': 'o',
  3123. 'у': 'y',
  3124. 'ф': 'b',
  3125. 'х': 'x',
  3126. 'ц': 'n',
  3127. 'ч': 'n',
  3128. 'ш': 'w',
  3129. 'щ': 'w',
  3130. 'ъ': 'a',
  3131. 'ы': 'm',
  3132. 'ь': 'a',
  3133. 'э': 'e',
  3134. 'ю': 'm',
  3135. 'я': 'r'
  3136. };
  3137. /**
  3138. * This function adds new font metrics to default metricMap
  3139. * It can also override existing metrics
  3140. */
  3141. function setFontMetrics(fontName, metrics) {
  3142. fontMetricsData[fontName] = metrics;
  3143. }
  3144. /**
  3145. * This function is a convenience function for looking up information in the
  3146. * metricMap table. It takes a character as a string, and a font.
  3147. *
  3148. * Note: the `width` property may be undefined if fontMetricsData.js wasn't
  3149. * built using `Make extended_metrics`.
  3150. */
  3151. function getCharacterMetrics(character, font, mode) {
  3152. if (!fontMetricsData[font]) {
  3153. throw new Error("Font metrics not found for font: " + font + ".");
  3154. }
  3155. var ch = character.charCodeAt(0);
  3156. var metrics = fontMetricsData[font][ch];
  3157. if (!metrics && character[0] in extraCharacterMap) {
  3158. ch = extraCharacterMap[character[0]].charCodeAt(0);
  3159. metrics = fontMetricsData[font][ch];
  3160. }
  3161. if (!metrics && mode === 'text') {
  3162. // We don't typically have font metrics for Asian scripts.
  3163. // But since we support them in text mode, we need to return
  3164. // some sort of metrics.
  3165. // So if the character is in a script we support but we
  3166. // don't have metrics for it, just use the metrics for
  3167. // the Latin capital letter M. This is close enough because
  3168. // we (currently) only care about the height of the glpyh
  3169. // not its width.
  3170. if (supportedCodepoint(ch)) {
  3171. metrics = fontMetricsData[font][77]; // 77 is the charcode for 'M'
  3172. }
  3173. }
  3174. if (metrics) {
  3175. return {
  3176. depth: metrics[0],
  3177. height: metrics[1],
  3178. italic: metrics[2],
  3179. skew: metrics[3],
  3180. width: metrics[4]
  3181. };
  3182. }
  3183. }
  3184. var fontMetricsBySizeIndex = {};
  3185. /**
  3186. * Get the font metrics for a given size.
  3187. */
  3188. function getGlobalMetrics(size) {
  3189. var sizeIndex;
  3190. if (size >= 5) {
  3191. sizeIndex = 0;
  3192. } else if (size >= 3) {
  3193. sizeIndex = 1;
  3194. } else {
  3195. sizeIndex = 2;
  3196. }
  3197. if (!fontMetricsBySizeIndex[sizeIndex]) {
  3198. var metrics = fontMetricsBySizeIndex[sizeIndex] = {
  3199. cssEmPerMu: sigmasAndXis.quad[sizeIndex] / 18
  3200. };
  3201. for (var key in sigmasAndXis) {
  3202. if (sigmasAndXis.hasOwnProperty(key)) {
  3203. metrics[key] = sigmasAndXis[key][sizeIndex];
  3204. }
  3205. }
  3206. }
  3207. return fontMetricsBySizeIndex[sizeIndex];
  3208. }
  3209. /**
  3210. * This file contains information about the options that the Parser carries
  3211. * around with it while parsing. Data is held in an `Options` object, and when
  3212. * recursing, a new `Options` object can be created with the `.with*` and
  3213. * `.reset` functions.
  3214. */
  3215. var sizeStyleMap = [// Each element contains [textsize, scriptsize, scriptscriptsize].
  3216. // The size mappings are taken from TeX with \normalsize=10pt.
  3217. [1, 1, 1], // size1: [5, 5, 5] \tiny
  3218. [2, 1, 1], // size2: [6, 5, 5]
  3219. [3, 1, 1], // size3: [7, 5, 5] \scriptsize
  3220. [4, 2, 1], // size4: [8, 6, 5] \footnotesize
  3221. [5, 2, 1], // size5: [9, 6, 5] \small
  3222. [6, 3, 1], // size6: [10, 7, 5] \normalsize
  3223. [7, 4, 2], // size7: [12, 8, 6] \large
  3224. [8, 6, 3], // size8: [14.4, 10, 7] \Large
  3225. [9, 7, 6], // size9: [17.28, 12, 10] \LARGE
  3226. [10, 8, 7], // size10: [20.74, 14.4, 12] \huge
  3227. [11, 10, 9] // size11: [24.88, 20.74, 17.28] \HUGE
  3228. ];
  3229. var sizeMultipliers = [// fontMetrics.js:getGlobalMetrics also uses size indexes, so if
  3230. // you change size indexes, change that function.
  3231. 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.44, 1.728, 2.074, 2.488];
  3232. var sizeAtStyle = function sizeAtStyle(size, style) {
  3233. return style.size < 2 ? size : sizeStyleMap[size - 1][style.size - 1];
  3234. }; // In these types, "" (empty string) means "no change".
  3235. /**
  3236. * This is the main options class. It contains the current style, size, color,
  3237. * and font.
  3238. *
  3239. * Options objects should not be modified. To create a new Options with
  3240. * different properties, call a `.having*` method.
  3241. */
  3242. class Options {
  3243. // A font family applies to a group of fonts (i.e. SansSerif), while a font
  3244. // represents a specific font (i.e. SansSerif Bold).
  3245. // See: https://tex.stackexchange.com/questions/22350/difference-between-textrm-and-mathrm
  3246. /**
  3247. * The base size index.
  3248. */
  3249. constructor(data) {
  3250. this.style = void 0;
  3251. this.color = void 0;
  3252. this.size = void 0;
  3253. this.textSize = void 0;
  3254. this.phantom = void 0;
  3255. this.font = void 0;
  3256. this.fontFamily = void 0;
  3257. this.fontWeight = void 0;
  3258. this.fontShape = void 0;
  3259. this.sizeMultiplier = void 0;
  3260. this.maxSize = void 0;
  3261. this.minRuleThickness = void 0;
  3262. this._fontMetrics = void 0;
  3263. this.style = data.style;
  3264. this.color = data.color;
  3265. this.size = data.size || Options.BASESIZE;
  3266. this.textSize = data.textSize || this.size;
  3267. this.phantom = !!data.phantom;
  3268. this.font = data.font || "";
  3269. this.fontFamily = data.fontFamily || "";
  3270. this.fontWeight = data.fontWeight || '';
  3271. this.fontShape = data.fontShape || '';
  3272. this.sizeMultiplier = sizeMultipliers[this.size - 1];
  3273. this.maxSize = data.maxSize;
  3274. this.minRuleThickness = data.minRuleThickness;
  3275. this._fontMetrics = undefined;
  3276. }
  3277. /**
  3278. * Returns a new options object with the same properties as "this". Properties
  3279. * from "extension" will be copied to the new options object.
  3280. */
  3281. extend(extension) {
  3282. var data = {
  3283. style: this.style,
  3284. size: this.size,
  3285. textSize: this.textSize,
  3286. color: this.color,
  3287. phantom: this.phantom,
  3288. font: this.font,
  3289. fontFamily: this.fontFamily,
  3290. fontWeight: this.fontWeight,
  3291. fontShape: this.fontShape,
  3292. maxSize: this.maxSize,
  3293. minRuleThickness: this.minRuleThickness
  3294. };
  3295. for (var key in extension) {
  3296. if (extension.hasOwnProperty(key)) {
  3297. data[key] = extension[key];
  3298. }
  3299. }
  3300. return new Options(data);
  3301. }
  3302. /**
  3303. * Return an options object with the given style. If `this.style === style`,
  3304. * returns `this`.
  3305. */
  3306. havingStyle(style) {
  3307. if (this.style === style) {
  3308. return this;
  3309. } else {
  3310. return this.extend({
  3311. style: style,
  3312. size: sizeAtStyle(this.textSize, style)
  3313. });
  3314. }
  3315. }
  3316. /**
  3317. * Return an options object with a cramped version of the current style. If
  3318. * the current style is cramped, returns `this`.
  3319. */
  3320. havingCrampedStyle() {
  3321. return this.havingStyle(this.style.cramp());
  3322. }
  3323. /**
  3324. * Return an options object with the given size and in at least `\textstyle`.
  3325. * Returns `this` if appropriate.
  3326. */
  3327. havingSize(size) {
  3328. if (this.size === size && this.textSize === size) {
  3329. return this;
  3330. } else {
  3331. return this.extend({
  3332. style: this.style.text(),
  3333. size: size,
  3334. textSize: size,
  3335. sizeMultiplier: sizeMultipliers[size - 1]
  3336. });
  3337. }
  3338. }
  3339. /**
  3340. * Like `this.havingSize(BASESIZE).havingStyle(style)`. If `style` is omitted,
  3341. * changes to at least `\textstyle`.
  3342. */
  3343. havingBaseStyle(style) {
  3344. style = style || this.style.text();
  3345. var wantSize = sizeAtStyle(Options.BASESIZE, style);
  3346. if (this.size === wantSize && this.textSize === Options.BASESIZE && this.style === style) {
  3347. return this;
  3348. } else {
  3349. return this.extend({
  3350. style: style,
  3351. size: wantSize
  3352. });
  3353. }
  3354. }
  3355. /**
  3356. * Remove the effect of sizing changes such as \Huge.
  3357. * Keep the effect of the current style, such as \scriptstyle.
  3358. */
  3359. havingBaseSizing() {
  3360. var size;
  3361. switch (this.style.id) {
  3362. case 4:
  3363. case 5:
  3364. size = 3; // normalsize in scriptstyle
  3365. break;
  3366. case 6:
  3367. case 7:
  3368. size = 1; // normalsize in scriptscriptstyle
  3369. break;
  3370. default:
  3371. size = 6;
  3372. // normalsize in textstyle or displaystyle
  3373. }
  3374. return this.extend({
  3375. style: this.style.text(),
  3376. size: size
  3377. });
  3378. }
  3379. /**
  3380. * Create a new options object with the given color.
  3381. */
  3382. withColor(color) {
  3383. return this.extend({
  3384. color: color
  3385. });
  3386. }
  3387. /**
  3388. * Create a new options object with "phantom" set to true.
  3389. */
  3390. withPhantom() {
  3391. return this.extend({
  3392. phantom: true
  3393. });
  3394. }
  3395. /**
  3396. * Creates a new options object with the given math font or old text font.
  3397. * @type {[type]}
  3398. */
  3399. withFont(font) {
  3400. return this.extend({
  3401. font
  3402. });
  3403. }
  3404. /**
  3405. * Create a new options objects with the given fontFamily.
  3406. */
  3407. withTextFontFamily(fontFamily) {
  3408. return this.extend({
  3409. fontFamily,
  3410. font: ""
  3411. });
  3412. }
  3413. /**
  3414. * Creates a new options object with the given font weight
  3415. */
  3416. withTextFontWeight(fontWeight) {
  3417. return this.extend({
  3418. fontWeight,
  3419. font: ""
  3420. });
  3421. }
  3422. /**
  3423. * Creates a new options object with the given font weight
  3424. */
  3425. withTextFontShape(fontShape) {
  3426. return this.extend({
  3427. fontShape,
  3428. font: ""
  3429. });
  3430. }
  3431. /**
  3432. * Return the CSS sizing classes required to switch from enclosing options
  3433. * `oldOptions` to `this`. Returns an array of classes.
  3434. */
  3435. sizingClasses(oldOptions) {
  3436. if (oldOptions.size !== this.size) {
  3437. return ["sizing", "reset-size" + oldOptions.size, "size" + this.size];
  3438. } else {
  3439. return [];
  3440. }
  3441. }
  3442. /**
  3443. * Return the CSS sizing classes required to switch to the base size. Like
  3444. * `this.havingSize(BASESIZE).sizingClasses(this)`.
  3445. */
  3446. baseSizingClasses() {
  3447. if (this.size !== Options.BASESIZE) {
  3448. return ["sizing", "reset-size" + this.size, "size" + Options.BASESIZE];
  3449. } else {
  3450. return [];
  3451. }
  3452. }
  3453. /**
  3454. * Return the font metrics for this size.
  3455. */
  3456. fontMetrics() {
  3457. if (!this._fontMetrics) {
  3458. this._fontMetrics = getGlobalMetrics(this.size);
  3459. }
  3460. return this._fontMetrics;
  3461. }
  3462. /**
  3463. * Gets the CSS color of the current options object
  3464. */
  3465. getColor() {
  3466. if (this.phantom) {
  3467. return "transparent";
  3468. } else {
  3469. return this.color;
  3470. }
  3471. }
  3472. }
  3473. Options.BASESIZE = 6;
  3474. /**
  3475. * This file does conversion between units. In particular, it provides
  3476. * calculateSize to convert other units into ems.
  3477. */
  3478. // Thus, multiplying a length by this number converts the length from units
  3479. // into pts. Dividing the result by ptPerEm gives the number of ems
  3480. // *assuming* a font size of ptPerEm (normal size, normal style).
  3481. var ptPerUnit = {
  3482. // https://en.wikibooks.org/wiki/LaTeX/Lengths and
  3483. // https://tex.stackexchange.com/a/8263
  3484. "pt": 1,
  3485. // TeX point
  3486. "mm": 7227 / 2540,
  3487. // millimeter
  3488. "cm": 7227 / 254,
  3489. // centimeter
  3490. "in": 72.27,
  3491. // inch
  3492. "bp": 803 / 800,
  3493. // big (PostScript) points
  3494. "pc": 12,
  3495. // pica
  3496. "dd": 1238 / 1157,
  3497. // didot
  3498. "cc": 14856 / 1157,
  3499. // cicero (12 didot)
  3500. "nd": 685 / 642,
  3501. // new didot
  3502. "nc": 1370 / 107,
  3503. // new cicero (12 new didot)
  3504. "sp": 1 / 65536,
  3505. // scaled point (TeX's internal smallest unit)
  3506. // https://tex.stackexchange.com/a/41371
  3507. "px": 803 / 800 // \pdfpxdimen defaults to 1 bp in pdfTeX and LuaTeX
  3508. }; // Dictionary of relative units, for fast validity testing.
  3509. var relativeUnit = {
  3510. "ex": true,
  3511. "em": true,
  3512. "mu": true
  3513. };
  3514. /**
  3515. * Determine whether the specified unit (either a string defining the unit
  3516. * or a "size" parse node containing a unit field) is valid.
  3517. */
  3518. var validUnit = function validUnit(unit) {
  3519. if (typeof unit !== "string") {
  3520. unit = unit.unit;
  3521. }
  3522. return unit in ptPerUnit || unit in relativeUnit || unit === "ex";
  3523. };
  3524. /*
  3525. * Convert a "size" parse node (with numeric "number" and string "unit" fields,
  3526. * as parsed by functions.js argType "size") into a CSS em value for the
  3527. * current style/scale. `options` gives the current options.
  3528. */
  3529. var calculateSize = function calculateSize(sizeValue, options) {
  3530. var scale;
  3531. if (sizeValue.unit in ptPerUnit) {
  3532. // Absolute units
  3533. scale = ptPerUnit[sizeValue.unit] // Convert unit to pt
  3534. / options.fontMetrics().ptPerEm // Convert pt to CSS em
  3535. / options.sizeMultiplier; // Unscale to make absolute units
  3536. } else if (sizeValue.unit === "mu") {
  3537. // `mu` units scale with scriptstyle/scriptscriptstyle.
  3538. scale = options.fontMetrics().cssEmPerMu;
  3539. } else {
  3540. // Other relative units always refer to the *textstyle* font
  3541. // in the current size.
  3542. var unitOptions;
  3543. if (options.style.isTight()) {
  3544. // isTight() means current style is script/scriptscript.
  3545. unitOptions = options.havingStyle(options.style.text());
  3546. } else {
  3547. unitOptions = options;
  3548. } // TODO: In TeX these units are relative to the quad of the current
  3549. // *text* font, e.g. cmr10. KaTeX instead uses values from the
  3550. // comparably-sized *Computer Modern symbol* font. At 10pt, these
  3551. // match. At 7pt and 5pt, they differ: cmr7=1.138894, cmsy7=1.170641;
  3552. // cmr5=1.361133, cmsy5=1.472241. Consider $\scriptsize a\kern1emb$.
  3553. // TeX \showlists shows a kern of 1.13889 * fontsize;
  3554. // KaTeX shows a kern of 1.171 * fontsize.
  3555. if (sizeValue.unit === "ex") {
  3556. scale = unitOptions.fontMetrics().xHeight;
  3557. } else if (sizeValue.unit === "em") {
  3558. scale = unitOptions.fontMetrics().quad;
  3559. } else {
  3560. throw new ParseError("Invalid unit: '" + sizeValue.unit + "'");
  3561. }
  3562. if (unitOptions !== options) {
  3563. scale *= unitOptions.sizeMultiplier / options.sizeMultiplier;
  3564. }
  3565. }
  3566. return Math.min(sizeValue.number * scale, options.maxSize);
  3567. };
  3568. /**
  3569. * Round `n` to 4 decimal places, or to the nearest 1/10,000th em. See
  3570. * https://github.com/KaTeX/KaTeX/pull/2460.
  3571. */
  3572. var makeEm = function makeEm(n) {
  3573. return +n.toFixed(4) + "em";
  3574. };
  3575. /**
  3576. * These objects store the data about the DOM nodes we create, as well as some
  3577. * extra data. They can then be transformed into real DOM nodes with the
  3578. * `toNode` function or HTML markup using `toMarkup`. They are useful for both
  3579. * storing extra properties on the nodes, as well as providing a way to easily
  3580. * work with the DOM.
  3581. *
  3582. * Similar functions for working with MathML nodes exist in mathMLTree.js.
  3583. *
  3584. * TODO: refactor `span` and `anchor` into common superclass when
  3585. * target environments support class inheritance
  3586. */
  3587. /**
  3588. * Create an HTML className based on a list of classes. In addition to joining
  3589. * with spaces, we also remove empty classes.
  3590. */
  3591. var createClass = function createClass(classes) {
  3592. return classes.filter(cls => cls).join(" ");
  3593. };
  3594. var initNode = function initNode(classes, options, style) {
  3595. this.classes = classes || [];
  3596. this.attributes = {};
  3597. this.height = 0;
  3598. this.depth = 0;
  3599. this.maxFontSize = 0;
  3600. this.style = style || {};
  3601. if (options) {
  3602. if (options.style.isTight()) {
  3603. this.classes.push("mtight");
  3604. }
  3605. var color = options.getColor();
  3606. if (color) {
  3607. this.style.color = color;
  3608. }
  3609. }
  3610. };
  3611. /**
  3612. * Convert into an HTML node
  3613. */
  3614. var toNode = function toNode(tagName) {
  3615. var node = document.createElement(tagName); // Apply the class
  3616. node.className = createClass(this.classes); // Apply inline styles
  3617. for (var style in this.style) {
  3618. if (this.style.hasOwnProperty(style)) {
  3619. // $FlowFixMe Flow doesn't seem to understand span.style's type.
  3620. node.style[style] = this.style[style];
  3621. }
  3622. } // Apply attributes
  3623. for (var attr in this.attributes) {
  3624. if (this.attributes.hasOwnProperty(attr)) {
  3625. node.setAttribute(attr, this.attributes[attr]);
  3626. }
  3627. } // Append the children, also as HTML nodes
  3628. for (var i = 0; i < this.children.length; i++) {
  3629. node.appendChild(this.children[i].toNode());
  3630. }
  3631. return node;
  3632. };
  3633. /**
  3634. * Convert into an HTML markup string
  3635. */
  3636. var toMarkup = function toMarkup(tagName) {
  3637. var markup = "<" + tagName; // Add the class
  3638. if (this.classes.length) {
  3639. markup += " class=\"" + utils.escape(createClass(this.classes)) + "\"";
  3640. }
  3641. var styles = ""; // Add the styles, after hyphenation
  3642. for (var style in this.style) {
  3643. if (this.style.hasOwnProperty(style)) {
  3644. styles += utils.hyphenate(style) + ":" + this.style[style] + ";";
  3645. }
  3646. }
  3647. if (styles) {
  3648. markup += " style=\"" + utils.escape(styles) + "\"";
  3649. } // Add the attributes
  3650. for (var attr in this.attributes) {
  3651. if (this.attributes.hasOwnProperty(attr)) {
  3652. markup += " " + attr + "=\"" + utils.escape(this.attributes[attr]) + "\"";
  3653. }
  3654. }
  3655. markup += ">"; // Add the markup of the children, also as markup
  3656. for (var i = 0; i < this.children.length; i++) {
  3657. markup += this.children[i].toMarkup();
  3658. }
  3659. markup += "</" + tagName + ">";
  3660. return markup;
  3661. }; // Making the type below exact with all optional fields doesn't work due to
  3662. // - https://github.com/facebook/flow/issues/4582
  3663. // - https://github.com/facebook/flow/issues/5688
  3664. // However, since *all* fields are optional, $Shape<> works as suggested in 5688
  3665. // above.
  3666. // This type does not include all CSS properties. Additional properties should
  3667. // be added as needed.
  3668. /**
  3669. * This node represents a span node, with a className, a list of children, and
  3670. * an inline style. It also contains information about its height, depth, and
  3671. * maxFontSize.
  3672. *
  3673. * Represents two types with different uses: SvgSpan to wrap an SVG and DomSpan
  3674. * otherwise. This typesafety is important when HTML builders access a span's
  3675. * children.
  3676. */
  3677. class Span {
  3678. constructor(classes, children, options, style) {
  3679. this.children = void 0;
  3680. this.attributes = void 0;
  3681. this.classes = void 0;
  3682. this.height = void 0;
  3683. this.depth = void 0;
  3684. this.width = void 0;
  3685. this.maxFontSize = void 0;
  3686. this.style = void 0;
  3687. initNode.call(this, classes, options, style);
  3688. this.children = children || [];
  3689. }
  3690. /**
  3691. * Sets an arbitrary attribute on the span. Warning: use this wisely. Not
  3692. * all browsers support attributes the same, and having too many custom
  3693. * attributes is probably bad.
  3694. */
  3695. setAttribute(attribute, value) {
  3696. this.attributes[attribute] = value;
  3697. }
  3698. hasClass(className) {
  3699. return utils.contains(this.classes, className);
  3700. }
  3701. toNode() {
  3702. return toNode.call(this, "span");
  3703. }
  3704. toMarkup() {
  3705. return toMarkup.call(this, "span");
  3706. }
  3707. }
  3708. /**
  3709. * This node represents an anchor (<a>) element with a hyperlink. See `span`
  3710. * for further details.
  3711. */
  3712. class Anchor {
  3713. constructor(href, classes, children, options) {
  3714. this.children = void 0;
  3715. this.attributes = void 0;
  3716. this.classes = void 0;
  3717. this.height = void 0;
  3718. this.depth = void 0;
  3719. this.maxFontSize = void 0;
  3720. this.style = void 0;
  3721. initNode.call(this, classes, options);
  3722. this.children = children || [];
  3723. this.setAttribute('href', href);
  3724. }
  3725. setAttribute(attribute, value) {
  3726. this.attributes[attribute] = value;
  3727. }
  3728. hasClass(className) {
  3729. return utils.contains(this.classes, className);
  3730. }
  3731. toNode() {
  3732. return toNode.call(this, "a");
  3733. }
  3734. toMarkup() {
  3735. return toMarkup.call(this, "a");
  3736. }
  3737. }
  3738. /**
  3739. * This node represents an image embed (<img>) element.
  3740. */
  3741. class Img {
  3742. constructor(src, alt, style) {
  3743. this.src = void 0;
  3744. this.alt = void 0;
  3745. this.classes = void 0;
  3746. this.height = void 0;
  3747. this.depth = void 0;
  3748. this.maxFontSize = void 0;
  3749. this.style = void 0;
  3750. this.alt = alt;
  3751. this.src = src;
  3752. this.classes = ["mord"];
  3753. this.style = style;
  3754. }
  3755. hasClass(className) {
  3756. return utils.contains(this.classes, className);
  3757. }
  3758. toNode() {
  3759. var node = document.createElement("img");
  3760. node.src = this.src;
  3761. node.alt = this.alt;
  3762. node.className = "mord"; // Apply inline styles
  3763. for (var style in this.style) {
  3764. if (this.style.hasOwnProperty(style)) {
  3765. // $FlowFixMe
  3766. node.style[style] = this.style[style];
  3767. }
  3768. }
  3769. return node;
  3770. }
  3771. toMarkup() {
  3772. var markup = "<img src='" + this.src + " 'alt='" + this.alt + "' "; // Add the styles, after hyphenation
  3773. var styles = "";
  3774. for (var style in this.style) {
  3775. if (this.style.hasOwnProperty(style)) {
  3776. styles += utils.hyphenate(style) + ":" + this.style[style] + ";";
  3777. }
  3778. }
  3779. if (styles) {
  3780. markup += " style=\"" + utils.escape(styles) + "\"";
  3781. }
  3782. markup += "'/>";
  3783. return markup;
  3784. }
  3785. }
  3786. var iCombinations = {
  3787. 'î': '\u0131\u0302',
  3788. 'ï': '\u0131\u0308',
  3789. 'í': '\u0131\u0301',
  3790. // 'ī': '\u0131\u0304', // enable when we add Extended Latin
  3791. 'ì': '\u0131\u0300'
  3792. };
  3793. /**
  3794. * A symbol node contains information about a single symbol. It either renders
  3795. * to a single text node, or a span with a single text node in it, depending on
  3796. * whether it has CSS classes, styles, or needs italic correction.
  3797. */
  3798. class SymbolNode {
  3799. constructor(text, height, depth, italic, skew, width, classes, style) {
  3800. this.text = void 0;
  3801. this.height = void 0;
  3802. this.depth = void 0;
  3803. this.italic = void 0;
  3804. this.skew = void 0;
  3805. this.width = void 0;
  3806. this.maxFontSize = void 0;
  3807. this.classes = void 0;
  3808. this.style = void 0;
  3809. this.text = text;
  3810. this.height = height || 0;
  3811. this.depth = depth || 0;
  3812. this.italic = italic || 0;
  3813. this.skew = skew || 0;
  3814. this.width = width || 0;
  3815. this.classes = classes || [];
  3816. this.style = style || {};
  3817. this.maxFontSize = 0; // Mark text from non-Latin scripts with specific classes so that we
  3818. // can specify which fonts to use. This allows us to render these
  3819. // characters with a serif font in situations where the browser would
  3820. // either default to a sans serif or render a placeholder character.
  3821. // We use CSS class names like cjk_fallback, hangul_fallback and
  3822. // brahmic_fallback. See ./unicodeScripts.js for the set of possible
  3823. // script names
  3824. var script = scriptFromCodepoint(this.text.charCodeAt(0));
  3825. if (script) {
  3826. this.classes.push(script + "_fallback");
  3827. }
  3828. if (/[îïíì]/.test(this.text)) {
  3829. // add ī when we add Extended Latin
  3830. this.text = iCombinations[this.text];
  3831. }
  3832. }
  3833. hasClass(className) {
  3834. return utils.contains(this.classes, className);
  3835. }
  3836. /**
  3837. * Creates a text node or span from a symbol node. Note that a span is only
  3838. * created if it is needed.
  3839. */
  3840. toNode() {
  3841. var node = document.createTextNode(this.text);
  3842. var span = null;
  3843. if (this.italic > 0) {
  3844. span = document.createElement("span");
  3845. span.style.marginRight = makeEm(this.italic);
  3846. }
  3847. if (this.classes.length > 0) {
  3848. span = span || document.createElement("span");
  3849. span.className = createClass(this.classes);
  3850. }
  3851. for (var style in this.style) {
  3852. if (this.style.hasOwnProperty(style)) {
  3853. span = span || document.createElement("span"); // $FlowFixMe Flow doesn't seem to understand span.style's type.
  3854. span.style[style] = this.style[style];
  3855. }
  3856. }
  3857. if (span) {
  3858. span.appendChild(node);
  3859. return span;
  3860. } else {
  3861. return node;
  3862. }
  3863. }
  3864. /**
  3865. * Creates markup for a symbol node.
  3866. */
  3867. toMarkup() {
  3868. // TODO(alpert): More duplication than I'd like from
  3869. // span.prototype.toMarkup and symbolNode.prototype.toNode...
  3870. var needsSpan = false;
  3871. var markup = "<span";
  3872. if (this.classes.length) {
  3873. needsSpan = true;
  3874. markup += " class=\"";
  3875. markup += utils.escape(createClass(this.classes));
  3876. markup += "\"";
  3877. }
  3878. var styles = "";
  3879. if (this.italic > 0) {
  3880. styles += "margin-right:" + this.italic + "em;";
  3881. }
  3882. for (var style in this.style) {
  3883. if (this.style.hasOwnProperty(style)) {
  3884. styles += utils.hyphenate(style) + ":" + this.style[style] + ";";
  3885. }
  3886. }
  3887. if (styles) {
  3888. needsSpan = true;
  3889. markup += " style=\"" + utils.escape(styles) + "\"";
  3890. }
  3891. var escaped = utils.escape(this.text);
  3892. if (needsSpan) {
  3893. markup += ">";
  3894. markup += escaped;
  3895. markup += "</span>";
  3896. return markup;
  3897. } else {
  3898. return escaped;
  3899. }
  3900. }
  3901. }
  3902. /**
  3903. * SVG nodes are used to render stretchy wide elements.
  3904. */
  3905. class SvgNode {
  3906. constructor(children, attributes) {
  3907. this.children = void 0;
  3908. this.attributes = void 0;
  3909. this.children = children || [];
  3910. this.attributes = attributes || {};
  3911. }
  3912. toNode() {
  3913. var svgNS = "http://www.w3.org/2000/svg";
  3914. var node = document.createElementNS(svgNS, "svg"); // Apply attributes
  3915. for (var attr in this.attributes) {
  3916. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  3917. node.setAttribute(attr, this.attributes[attr]);
  3918. }
  3919. }
  3920. for (var i = 0; i < this.children.length; i++) {
  3921. node.appendChild(this.children[i].toNode());
  3922. }
  3923. return node;
  3924. }
  3925. toMarkup() {
  3926. var markup = "<svg xmlns=\"http://www.w3.org/2000/svg\""; // Apply attributes
  3927. for (var attr in this.attributes) {
  3928. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  3929. markup += " " + attr + "='" + this.attributes[attr] + "'";
  3930. }
  3931. }
  3932. markup += ">";
  3933. for (var i = 0; i < this.children.length; i++) {
  3934. markup += this.children[i].toMarkup();
  3935. }
  3936. markup += "</svg>";
  3937. return markup;
  3938. }
  3939. }
  3940. class PathNode {
  3941. constructor(pathName, alternate) {
  3942. this.pathName = void 0;
  3943. this.alternate = void 0;
  3944. this.pathName = pathName;
  3945. this.alternate = alternate; // Used only for \sqrt, \phase, & tall delims
  3946. }
  3947. toNode() {
  3948. var svgNS = "http://www.w3.org/2000/svg";
  3949. var node = document.createElementNS(svgNS, "path");
  3950. if (this.alternate) {
  3951. node.setAttribute("d", this.alternate);
  3952. } else {
  3953. node.setAttribute("d", path[this.pathName]);
  3954. }
  3955. return node;
  3956. }
  3957. toMarkup() {
  3958. if (this.alternate) {
  3959. return "<path d='" + this.alternate + "'/>";
  3960. } else {
  3961. return "<path d='" + path[this.pathName] + "'/>";
  3962. }
  3963. }
  3964. }
  3965. class LineNode {
  3966. constructor(attributes) {
  3967. this.attributes = void 0;
  3968. this.attributes = attributes || {};
  3969. }
  3970. toNode() {
  3971. var svgNS = "http://www.w3.org/2000/svg";
  3972. var node = document.createElementNS(svgNS, "line"); // Apply attributes
  3973. for (var attr in this.attributes) {
  3974. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  3975. node.setAttribute(attr, this.attributes[attr]);
  3976. }
  3977. }
  3978. return node;
  3979. }
  3980. toMarkup() {
  3981. var markup = "<line";
  3982. for (var attr in this.attributes) {
  3983. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  3984. markup += " " + attr + "='" + this.attributes[attr] + "'";
  3985. }
  3986. }
  3987. markup += "/>";
  3988. return markup;
  3989. }
  3990. }
  3991. function assertSymbolDomNode(group) {
  3992. if (group instanceof SymbolNode) {
  3993. return group;
  3994. } else {
  3995. throw new Error("Expected symbolNode but got " + String(group) + ".");
  3996. }
  3997. }
  3998. function assertSpan(group) {
  3999. if (group instanceof Span) {
  4000. return group;
  4001. } else {
  4002. throw new Error("Expected span<HtmlDomNode> but got " + String(group) + ".");
  4003. }
  4004. }
  4005. /**
  4006. * This file holds a list of all no-argument functions and single-character
  4007. * symbols (like 'a' or ';').
  4008. *
  4009. * For each of the symbols, there are three properties they can have:
  4010. * - font (required): the font to be used for this symbol. Either "main" (the
  4011. normal font), or "ams" (the ams fonts).
  4012. * - group (required): the ParseNode group type the symbol should have (i.e.
  4013. "textord", "mathord", etc).
  4014. See https://github.com/KaTeX/KaTeX/wiki/Examining-TeX#group-types
  4015. * - replace: the character that this symbol or function should be
  4016. * replaced with (i.e. "\phi" has a replace value of "\u03d5", the phi
  4017. * character in the main font).
  4018. *
  4019. * The outermost map in the table indicates what mode the symbols should be
  4020. * accepted in (e.g. "math" or "text").
  4021. */
  4022. // Some of these have a "-token" suffix since these are also used as `ParseNode`
  4023. // types for raw text tokens, and we want to avoid conflicts with higher-level
  4024. // `ParseNode` types. These `ParseNode`s are constructed within `Parser` by
  4025. // looking up the `symbols` map.
  4026. var ATOMS = {
  4027. "bin": 1,
  4028. "close": 1,
  4029. "inner": 1,
  4030. "open": 1,
  4031. "punct": 1,
  4032. "rel": 1
  4033. };
  4034. var NON_ATOMS = {
  4035. "accent-token": 1,
  4036. "mathord": 1,
  4037. "op-token": 1,
  4038. "spacing": 1,
  4039. "textord": 1
  4040. };
  4041. var symbols = {
  4042. "math": {},
  4043. "text": {}
  4044. };
  4045. /** `acceptUnicodeChar = true` is only applicable if `replace` is set. */
  4046. function defineSymbol(mode, font, group, replace, name, acceptUnicodeChar) {
  4047. symbols[mode][name] = {
  4048. font,
  4049. group,
  4050. replace
  4051. };
  4052. if (acceptUnicodeChar && replace) {
  4053. symbols[mode][replace] = symbols[mode][name];
  4054. }
  4055. } // Some abbreviations for commonly used strings.
  4056. // This helps minify the code, and also spotting typos using jshint.
  4057. // modes:
  4058. var math = "math";
  4059. var text = "text"; // fonts:
  4060. var main = "main";
  4061. var ams = "ams"; // groups:
  4062. var accent = "accent-token";
  4063. var bin = "bin";
  4064. var close = "close";
  4065. var inner = "inner";
  4066. var mathord = "mathord";
  4067. var op = "op-token";
  4068. var open = "open";
  4069. var punct = "punct";
  4070. var rel = "rel";
  4071. var spacing = "spacing";
  4072. var textord = "textord"; // Now comes the symbol table
  4073. // Relation Symbols
  4074. defineSymbol(math, main, rel, "\u2261", "\\equiv", true);
  4075. defineSymbol(math, main, rel, "\u227a", "\\prec", true);
  4076. defineSymbol(math, main, rel, "\u227b", "\\succ", true);
  4077. defineSymbol(math, main, rel, "\u223c", "\\sim", true);
  4078. defineSymbol(math, main, rel, "\u22a5", "\\perp");
  4079. defineSymbol(math, main, rel, "\u2aaf", "\\preceq", true);
  4080. defineSymbol(math, main, rel, "\u2ab0", "\\succeq", true);
  4081. defineSymbol(math, main, rel, "\u2243", "\\simeq", true);
  4082. defineSymbol(math, main, rel, "\u2223", "\\mid", true);
  4083. defineSymbol(math, main, rel, "\u226a", "\\ll", true);
  4084. defineSymbol(math, main, rel, "\u226b", "\\gg", true);
  4085. defineSymbol(math, main, rel, "\u224d", "\\asymp", true);
  4086. defineSymbol(math, main, rel, "\u2225", "\\parallel");
  4087. defineSymbol(math, main, rel, "\u22c8", "\\bowtie", true);
  4088. defineSymbol(math, main, rel, "\u2323", "\\smile", true);
  4089. defineSymbol(math, main, rel, "\u2291", "\\sqsubseteq", true);
  4090. defineSymbol(math, main, rel, "\u2292", "\\sqsupseteq", true);
  4091. defineSymbol(math, main, rel, "\u2250", "\\doteq", true);
  4092. defineSymbol(math, main, rel, "\u2322", "\\frown", true);
  4093. defineSymbol(math, main, rel, "\u220b", "\\ni", true);
  4094. defineSymbol(math, main, rel, "\u221d", "\\propto", true);
  4095. defineSymbol(math, main, rel, "\u22a2", "\\vdash", true);
  4096. defineSymbol(math, main, rel, "\u22a3", "\\dashv", true);
  4097. defineSymbol(math, main, rel, "\u220b", "\\owns"); // Punctuation
  4098. defineSymbol(math, main, punct, "\u002e", "\\ldotp");
  4099. defineSymbol(math, main, punct, "\u22c5", "\\cdotp"); // Misc Symbols
  4100. defineSymbol(math, main, textord, "\u0023", "\\#");
  4101. defineSymbol(text, main, textord, "\u0023", "\\#");
  4102. defineSymbol(math, main, textord, "\u0026", "\\&");
  4103. defineSymbol(text, main, textord, "\u0026", "\\&");
  4104. defineSymbol(math, main, textord, "\u2135", "\\aleph", true);
  4105. defineSymbol(math, main, textord, "\u2200", "\\forall", true);
  4106. defineSymbol(math, main, textord, "\u210f", "\\hbar", true);
  4107. defineSymbol(math, main, textord, "\u2203", "\\exists", true);
  4108. defineSymbol(math, main, textord, "\u2207", "\\nabla", true);
  4109. defineSymbol(math, main, textord, "\u266d", "\\flat", true);
  4110. defineSymbol(math, main, textord, "\u2113", "\\ell", true);
  4111. defineSymbol(math, main, textord, "\u266e", "\\natural", true);
  4112. defineSymbol(math, main, textord, "\u2663", "\\clubsuit", true);
  4113. defineSymbol(math, main, textord, "\u2118", "\\wp", true);
  4114. defineSymbol(math, main, textord, "\u266f", "\\sharp", true);
  4115. defineSymbol(math, main, textord, "\u2662", "\\diamondsuit", true);
  4116. defineSymbol(math, main, textord, "\u211c", "\\Re", true);
  4117. defineSymbol(math, main, textord, "\u2661", "\\heartsuit", true);
  4118. defineSymbol(math, main, textord, "\u2111", "\\Im", true);
  4119. defineSymbol(math, main, textord, "\u2660", "\\spadesuit", true);
  4120. defineSymbol(math, main, textord, "\u00a7", "\\S", true);
  4121. defineSymbol(text, main, textord, "\u00a7", "\\S");
  4122. defineSymbol(math, main, textord, "\u00b6", "\\P", true);
  4123. defineSymbol(text, main, textord, "\u00b6", "\\P"); // Math and Text
  4124. defineSymbol(math, main, textord, "\u2020", "\\dag");
  4125. defineSymbol(text, main, textord, "\u2020", "\\dag");
  4126. defineSymbol(text, main, textord, "\u2020", "\\textdagger");
  4127. defineSymbol(math, main, textord, "\u2021", "\\ddag");
  4128. defineSymbol(text, main, textord, "\u2021", "\\ddag");
  4129. defineSymbol(text, main, textord, "\u2021", "\\textdaggerdbl"); // Large Delimiters
  4130. defineSymbol(math, main, close, "\u23b1", "\\rmoustache", true);
  4131. defineSymbol(math, main, open, "\u23b0", "\\lmoustache", true);
  4132. defineSymbol(math, main, close, "\u27ef", "\\rgroup", true);
  4133. defineSymbol(math, main, open, "\u27ee", "\\lgroup", true); // Binary Operators
  4134. defineSymbol(math, main, bin, "\u2213", "\\mp", true);
  4135. defineSymbol(math, main, bin, "\u2296", "\\ominus", true);
  4136. defineSymbol(math, main, bin, "\u228e", "\\uplus", true);
  4137. defineSymbol(math, main, bin, "\u2293", "\\sqcap", true);
  4138. defineSymbol(math, main, bin, "\u2217", "\\ast");
  4139. defineSymbol(math, main, bin, "\u2294", "\\sqcup", true);
  4140. defineSymbol(math, main, bin, "\u25ef", "\\bigcirc", true);
  4141. defineSymbol(math, main, bin, "\u2219", "\\bullet", true);
  4142. defineSymbol(math, main, bin, "\u2021", "\\ddagger");
  4143. defineSymbol(math, main, bin, "\u2240", "\\wr", true);
  4144. defineSymbol(math, main, bin, "\u2a3f", "\\amalg");
  4145. defineSymbol(math, main, bin, "\u0026", "\\And"); // from amsmath
  4146. // Arrow Symbols
  4147. defineSymbol(math, main, rel, "\u27f5", "\\longleftarrow", true);
  4148. defineSymbol(math, main, rel, "\u21d0", "\\Leftarrow", true);
  4149. defineSymbol(math, main, rel, "\u27f8", "\\Longleftarrow", true);
  4150. defineSymbol(math, main, rel, "\u27f6", "\\longrightarrow", true);
  4151. defineSymbol(math, main, rel, "\u21d2", "\\Rightarrow", true);
  4152. defineSymbol(math, main, rel, "\u27f9", "\\Longrightarrow", true);
  4153. defineSymbol(math, main, rel, "\u2194", "\\leftrightarrow", true);
  4154. defineSymbol(math, main, rel, "\u27f7", "\\longleftrightarrow", true);
  4155. defineSymbol(math, main, rel, "\u21d4", "\\Leftrightarrow", true);
  4156. defineSymbol(math, main, rel, "\u27fa", "\\Longleftrightarrow", true);
  4157. defineSymbol(math, main, rel, "\u21a6", "\\mapsto", true);
  4158. defineSymbol(math, main, rel, "\u27fc", "\\longmapsto", true);
  4159. defineSymbol(math, main, rel, "\u2197", "\\nearrow", true);
  4160. defineSymbol(math, main, rel, "\u21a9", "\\hookleftarrow", true);
  4161. defineSymbol(math, main, rel, "\u21aa", "\\hookrightarrow", true);
  4162. defineSymbol(math, main, rel, "\u2198", "\\searrow", true);
  4163. defineSymbol(math, main, rel, "\u21bc", "\\leftharpoonup", true);
  4164. defineSymbol(math, main, rel, "\u21c0", "\\rightharpoonup", true);
  4165. defineSymbol(math, main, rel, "\u2199", "\\swarrow", true);
  4166. defineSymbol(math, main, rel, "\u21bd", "\\leftharpoondown", true);
  4167. defineSymbol(math, main, rel, "\u21c1", "\\rightharpoondown", true);
  4168. defineSymbol(math, main, rel, "\u2196", "\\nwarrow", true);
  4169. defineSymbol(math, main, rel, "\u21cc", "\\rightleftharpoons", true); // AMS Negated Binary Relations
  4170. defineSymbol(math, ams, rel, "\u226e", "\\nless", true); // Symbol names preceeded by "@" each have a corresponding macro.
  4171. defineSymbol(math, ams, rel, "\ue010", "\\@nleqslant");
  4172. defineSymbol(math, ams, rel, "\ue011", "\\@nleqq");
  4173. defineSymbol(math, ams, rel, "\u2a87", "\\lneq", true);
  4174. defineSymbol(math, ams, rel, "\u2268", "\\lneqq", true);
  4175. defineSymbol(math, ams, rel, "\ue00c", "\\@lvertneqq");
  4176. defineSymbol(math, ams, rel, "\u22e6", "\\lnsim", true);
  4177. defineSymbol(math, ams, rel, "\u2a89", "\\lnapprox", true);
  4178. defineSymbol(math, ams, rel, "\u2280", "\\nprec", true); // unicode-math maps \u22e0 to \npreccurlyeq. We'll use the AMS synonym.
  4179. defineSymbol(math, ams, rel, "\u22e0", "\\npreceq", true);
  4180. defineSymbol(math, ams, rel, "\u22e8", "\\precnsim", true);
  4181. defineSymbol(math, ams, rel, "\u2ab9", "\\precnapprox", true);
  4182. defineSymbol(math, ams, rel, "\u2241", "\\nsim", true);
  4183. defineSymbol(math, ams, rel, "\ue006", "\\@nshortmid");
  4184. defineSymbol(math, ams, rel, "\u2224", "\\nmid", true);
  4185. defineSymbol(math, ams, rel, "\u22ac", "\\nvdash", true);
  4186. defineSymbol(math, ams, rel, "\u22ad", "\\nvDash", true);
  4187. defineSymbol(math, ams, rel, "\u22ea", "\\ntriangleleft");
  4188. defineSymbol(math, ams, rel, "\u22ec", "\\ntrianglelefteq", true);
  4189. defineSymbol(math, ams, rel, "\u228a", "\\subsetneq", true);
  4190. defineSymbol(math, ams, rel, "\ue01a", "\\@varsubsetneq");
  4191. defineSymbol(math, ams, rel, "\u2acb", "\\subsetneqq", true);
  4192. defineSymbol(math, ams, rel, "\ue017", "\\@varsubsetneqq");
  4193. defineSymbol(math, ams, rel, "\u226f", "\\ngtr", true);
  4194. defineSymbol(math, ams, rel, "\ue00f", "\\@ngeqslant");
  4195. defineSymbol(math, ams, rel, "\ue00e", "\\@ngeqq");
  4196. defineSymbol(math, ams, rel, "\u2a88", "\\gneq", true);
  4197. defineSymbol(math, ams, rel, "\u2269", "\\gneqq", true);
  4198. defineSymbol(math, ams, rel, "\ue00d", "\\@gvertneqq");
  4199. defineSymbol(math, ams, rel, "\u22e7", "\\gnsim", true);
  4200. defineSymbol(math, ams, rel, "\u2a8a", "\\gnapprox", true);
  4201. defineSymbol(math, ams, rel, "\u2281", "\\nsucc", true); // unicode-math maps \u22e1 to \nsucccurlyeq. We'll use the AMS synonym.
  4202. defineSymbol(math, ams, rel, "\u22e1", "\\nsucceq", true);
  4203. defineSymbol(math, ams, rel, "\u22e9", "\\succnsim", true);
  4204. defineSymbol(math, ams, rel, "\u2aba", "\\succnapprox", true); // unicode-math maps \u2246 to \simneqq. We'll use the AMS synonym.
  4205. defineSymbol(math, ams, rel, "\u2246", "\\ncong", true);
  4206. defineSymbol(math, ams, rel, "\ue007", "\\@nshortparallel");
  4207. defineSymbol(math, ams, rel, "\u2226", "\\nparallel", true);
  4208. defineSymbol(math, ams, rel, "\u22af", "\\nVDash", true);
  4209. defineSymbol(math, ams, rel, "\u22eb", "\\ntriangleright");
  4210. defineSymbol(math, ams, rel, "\u22ed", "\\ntrianglerighteq", true);
  4211. defineSymbol(math, ams, rel, "\ue018", "\\@nsupseteqq");
  4212. defineSymbol(math, ams, rel, "\u228b", "\\supsetneq", true);
  4213. defineSymbol(math, ams, rel, "\ue01b", "\\@varsupsetneq");
  4214. defineSymbol(math, ams, rel, "\u2acc", "\\supsetneqq", true);
  4215. defineSymbol(math, ams, rel, "\ue019", "\\@varsupsetneqq");
  4216. defineSymbol(math, ams, rel, "\u22ae", "\\nVdash", true);
  4217. defineSymbol(math, ams, rel, "\u2ab5", "\\precneqq", true);
  4218. defineSymbol(math, ams, rel, "\u2ab6", "\\succneqq", true);
  4219. defineSymbol(math, ams, rel, "\ue016", "\\@nsubseteqq");
  4220. defineSymbol(math, ams, bin, "\u22b4", "\\unlhd");
  4221. defineSymbol(math, ams, bin, "\u22b5", "\\unrhd"); // AMS Negated Arrows
  4222. defineSymbol(math, ams, rel, "\u219a", "\\nleftarrow", true);
  4223. defineSymbol(math, ams, rel, "\u219b", "\\nrightarrow", true);
  4224. defineSymbol(math, ams, rel, "\u21cd", "\\nLeftarrow", true);
  4225. defineSymbol(math, ams, rel, "\u21cf", "\\nRightarrow", true);
  4226. defineSymbol(math, ams, rel, "\u21ae", "\\nleftrightarrow", true);
  4227. defineSymbol(math, ams, rel, "\u21ce", "\\nLeftrightarrow", true); // AMS Misc
  4228. defineSymbol(math, ams, rel, "\u25b3", "\\vartriangle");
  4229. defineSymbol(math, ams, textord, "\u210f", "\\hslash");
  4230. defineSymbol(math, ams, textord, "\u25bd", "\\triangledown");
  4231. defineSymbol(math, ams, textord, "\u25ca", "\\lozenge");
  4232. defineSymbol(math, ams, textord, "\u24c8", "\\circledS");
  4233. defineSymbol(math, ams, textord, "\u00ae", "\\circledR");
  4234. defineSymbol(text, ams, textord, "\u00ae", "\\circledR");
  4235. defineSymbol(math, ams, textord, "\u2221", "\\measuredangle", true);
  4236. defineSymbol(math, ams, textord, "\u2204", "\\nexists");
  4237. defineSymbol(math, ams, textord, "\u2127", "\\mho");
  4238. defineSymbol(math, ams, textord, "\u2132", "\\Finv", true);
  4239. defineSymbol(math, ams, textord, "\u2141", "\\Game", true);
  4240. defineSymbol(math, ams, textord, "\u2035", "\\backprime");
  4241. defineSymbol(math, ams, textord, "\u25b2", "\\blacktriangle");
  4242. defineSymbol(math, ams, textord, "\u25bc", "\\blacktriangledown");
  4243. defineSymbol(math, ams, textord, "\u25a0", "\\blacksquare");
  4244. defineSymbol(math, ams, textord, "\u29eb", "\\blacklozenge");
  4245. defineSymbol(math, ams, textord, "\u2605", "\\bigstar");
  4246. defineSymbol(math, ams, textord, "\u2222", "\\sphericalangle", true);
  4247. defineSymbol(math, ams, textord, "\u2201", "\\complement", true); // unicode-math maps U+F0 to \matheth. We map to AMS function \eth
  4248. defineSymbol(math, ams, textord, "\u00f0", "\\eth", true);
  4249. defineSymbol(text, main, textord, "\u00f0", "\u00f0");
  4250. defineSymbol(math, ams, textord, "\u2571", "\\diagup");
  4251. defineSymbol(math, ams, textord, "\u2572", "\\diagdown");
  4252. defineSymbol(math, ams, textord, "\u25a1", "\\square");
  4253. defineSymbol(math, ams, textord, "\u25a1", "\\Box");
  4254. defineSymbol(math, ams, textord, "\u25ca", "\\Diamond"); // unicode-math maps U+A5 to \mathyen. We map to AMS function \yen
  4255. defineSymbol(math, ams, textord, "\u00a5", "\\yen", true);
  4256. defineSymbol(text, ams, textord, "\u00a5", "\\yen", true);
  4257. defineSymbol(math, ams, textord, "\u2713", "\\checkmark", true);
  4258. defineSymbol(text, ams, textord, "\u2713", "\\checkmark"); // AMS Hebrew
  4259. defineSymbol(math, ams, textord, "\u2136", "\\beth", true);
  4260. defineSymbol(math, ams, textord, "\u2138", "\\daleth", true);
  4261. defineSymbol(math, ams, textord, "\u2137", "\\gimel", true); // AMS Greek
  4262. defineSymbol(math, ams, textord, "\u03dd", "\\digamma", true);
  4263. defineSymbol(math, ams, textord, "\u03f0", "\\varkappa"); // AMS Delimiters
  4264. defineSymbol(math, ams, open, "\u250c", "\\@ulcorner", true);
  4265. defineSymbol(math, ams, close, "\u2510", "\\@urcorner", true);
  4266. defineSymbol(math, ams, open, "\u2514", "\\@llcorner", true);
  4267. defineSymbol(math, ams, close, "\u2518", "\\@lrcorner", true); // AMS Binary Relations
  4268. defineSymbol(math, ams, rel, "\u2266", "\\leqq", true);
  4269. defineSymbol(math, ams, rel, "\u2a7d", "\\leqslant", true);
  4270. defineSymbol(math, ams, rel, "\u2a95", "\\eqslantless", true);
  4271. defineSymbol(math, ams, rel, "\u2272", "\\lesssim", true);
  4272. defineSymbol(math, ams, rel, "\u2a85", "\\lessapprox", true);
  4273. defineSymbol(math, ams, rel, "\u224a", "\\approxeq", true);
  4274. defineSymbol(math, ams, bin, "\u22d6", "\\lessdot");
  4275. defineSymbol(math, ams, rel, "\u22d8", "\\lll", true);
  4276. defineSymbol(math, ams, rel, "\u2276", "\\lessgtr", true);
  4277. defineSymbol(math, ams, rel, "\u22da", "\\lesseqgtr", true);
  4278. defineSymbol(math, ams, rel, "\u2a8b", "\\lesseqqgtr", true);
  4279. defineSymbol(math, ams, rel, "\u2251", "\\doteqdot");
  4280. defineSymbol(math, ams, rel, "\u2253", "\\risingdotseq", true);
  4281. defineSymbol(math, ams, rel, "\u2252", "\\fallingdotseq", true);
  4282. defineSymbol(math, ams, rel, "\u223d", "\\backsim", true);
  4283. defineSymbol(math, ams, rel, "\u22cd", "\\backsimeq", true);
  4284. defineSymbol(math, ams, rel, "\u2ac5", "\\subseteqq", true);
  4285. defineSymbol(math, ams, rel, "\u22d0", "\\Subset", true);
  4286. defineSymbol(math, ams, rel, "\u228f", "\\sqsubset", true);
  4287. defineSymbol(math, ams, rel, "\u227c", "\\preccurlyeq", true);
  4288. defineSymbol(math, ams, rel, "\u22de", "\\curlyeqprec", true);
  4289. defineSymbol(math, ams, rel, "\u227e", "\\precsim", true);
  4290. defineSymbol(math, ams, rel, "\u2ab7", "\\precapprox", true);
  4291. defineSymbol(math, ams, rel, "\u22b2", "\\vartriangleleft");
  4292. defineSymbol(math, ams, rel, "\u22b4", "\\trianglelefteq");
  4293. defineSymbol(math, ams, rel, "\u22a8", "\\vDash", true);
  4294. defineSymbol(math, ams, rel, "\u22aa", "\\Vvdash", true);
  4295. defineSymbol(math, ams, rel, "\u2323", "\\smallsmile");
  4296. defineSymbol(math, ams, rel, "\u2322", "\\smallfrown");
  4297. defineSymbol(math, ams, rel, "\u224f", "\\bumpeq", true);
  4298. defineSymbol(math, ams, rel, "\u224e", "\\Bumpeq", true);
  4299. defineSymbol(math, ams, rel, "\u2267", "\\geqq", true);
  4300. defineSymbol(math, ams, rel, "\u2a7e", "\\geqslant", true);
  4301. defineSymbol(math, ams, rel, "\u2a96", "\\eqslantgtr", true);
  4302. defineSymbol(math, ams, rel, "\u2273", "\\gtrsim", true);
  4303. defineSymbol(math, ams, rel, "\u2a86", "\\gtrapprox", true);
  4304. defineSymbol(math, ams, bin, "\u22d7", "\\gtrdot");
  4305. defineSymbol(math, ams, rel, "\u22d9", "\\ggg", true);
  4306. defineSymbol(math, ams, rel, "\u2277", "\\gtrless", true);
  4307. defineSymbol(math, ams, rel, "\u22db", "\\gtreqless", true);
  4308. defineSymbol(math, ams, rel, "\u2a8c", "\\gtreqqless", true);
  4309. defineSymbol(math, ams, rel, "\u2256", "\\eqcirc", true);
  4310. defineSymbol(math, ams, rel, "\u2257", "\\circeq", true);
  4311. defineSymbol(math, ams, rel, "\u225c", "\\triangleq", true);
  4312. defineSymbol(math, ams, rel, "\u223c", "\\thicksim");
  4313. defineSymbol(math, ams, rel, "\u2248", "\\thickapprox");
  4314. defineSymbol(math, ams, rel, "\u2ac6", "\\supseteqq", true);
  4315. defineSymbol(math, ams, rel, "\u22d1", "\\Supset", true);
  4316. defineSymbol(math, ams, rel, "\u2290", "\\sqsupset", true);
  4317. defineSymbol(math, ams, rel, "\u227d", "\\succcurlyeq", true);
  4318. defineSymbol(math, ams, rel, "\u22df", "\\curlyeqsucc", true);
  4319. defineSymbol(math, ams, rel, "\u227f", "\\succsim", true);
  4320. defineSymbol(math, ams, rel, "\u2ab8", "\\succapprox", true);
  4321. defineSymbol(math, ams, rel, "\u22b3", "\\vartriangleright");
  4322. defineSymbol(math, ams, rel, "\u22b5", "\\trianglerighteq");
  4323. defineSymbol(math, ams, rel, "\u22a9", "\\Vdash", true);
  4324. defineSymbol(math, ams, rel, "\u2223", "\\shortmid");
  4325. defineSymbol(math, ams, rel, "\u2225", "\\shortparallel");
  4326. defineSymbol(math, ams, rel, "\u226c", "\\between", true);
  4327. defineSymbol(math, ams, rel, "\u22d4", "\\pitchfork", true);
  4328. defineSymbol(math, ams, rel, "\u221d", "\\varpropto");
  4329. defineSymbol(math, ams, rel, "\u25c0", "\\blacktriangleleft"); // unicode-math says that \therefore is a mathord atom.
  4330. // We kept the amssymb atom type, which is rel.
  4331. defineSymbol(math, ams, rel, "\u2234", "\\therefore", true);
  4332. defineSymbol(math, ams, rel, "\u220d", "\\backepsilon");
  4333. defineSymbol(math, ams, rel, "\u25b6", "\\blacktriangleright"); // unicode-math says that \because is a mathord atom.
  4334. // We kept the amssymb atom type, which is rel.
  4335. defineSymbol(math, ams, rel, "\u2235", "\\because", true);
  4336. defineSymbol(math, ams, rel, "\u22d8", "\\llless");
  4337. defineSymbol(math, ams, rel, "\u22d9", "\\gggtr");
  4338. defineSymbol(math, ams, bin, "\u22b2", "\\lhd");
  4339. defineSymbol(math, ams, bin, "\u22b3", "\\rhd");
  4340. defineSymbol(math, ams, rel, "\u2242", "\\eqsim", true);
  4341. defineSymbol(math, main, rel, "\u22c8", "\\Join");
  4342. defineSymbol(math, ams, rel, "\u2251", "\\Doteq", true); // AMS Binary Operators
  4343. defineSymbol(math, ams, bin, "\u2214", "\\dotplus", true);
  4344. defineSymbol(math, ams, bin, "\u2216", "\\smallsetminus");
  4345. defineSymbol(math, ams, bin, "\u22d2", "\\Cap", true);
  4346. defineSymbol(math, ams, bin, "\u22d3", "\\Cup", true);
  4347. defineSymbol(math, ams, bin, "\u2a5e", "\\doublebarwedge", true);
  4348. defineSymbol(math, ams, bin, "\u229f", "\\boxminus", true);
  4349. defineSymbol(math, ams, bin, "\u229e", "\\boxplus", true);
  4350. defineSymbol(math, ams, bin, "\u22c7", "\\divideontimes", true);
  4351. defineSymbol(math, ams, bin, "\u22c9", "\\ltimes", true);
  4352. defineSymbol(math, ams, bin, "\u22ca", "\\rtimes", true);
  4353. defineSymbol(math, ams, bin, "\u22cb", "\\leftthreetimes", true);
  4354. defineSymbol(math, ams, bin, "\u22cc", "\\rightthreetimes", true);
  4355. defineSymbol(math, ams, bin, "\u22cf", "\\curlywedge", true);
  4356. defineSymbol(math, ams, bin, "\u22ce", "\\curlyvee", true);
  4357. defineSymbol(math, ams, bin, "\u229d", "\\circleddash", true);
  4358. defineSymbol(math, ams, bin, "\u229b", "\\circledast", true);
  4359. defineSymbol(math, ams, bin, "\u22c5", "\\centerdot");
  4360. defineSymbol(math, ams, bin, "\u22ba", "\\intercal", true);
  4361. defineSymbol(math, ams, bin, "\u22d2", "\\doublecap");
  4362. defineSymbol(math, ams, bin, "\u22d3", "\\doublecup");
  4363. defineSymbol(math, ams, bin, "\u22a0", "\\boxtimes", true); // AMS Arrows
  4364. // Note: unicode-math maps \u21e2 to their own function \rightdasharrow.
  4365. // We'll map it to AMS function \dashrightarrow. It produces the same atom.
  4366. defineSymbol(math, ams, rel, "\u21e2", "\\dashrightarrow", true); // unicode-math maps \u21e0 to \leftdasharrow. We'll use the AMS synonym.
  4367. defineSymbol(math, ams, rel, "\u21e0", "\\dashleftarrow", true);
  4368. defineSymbol(math, ams, rel, "\u21c7", "\\leftleftarrows", true);
  4369. defineSymbol(math, ams, rel, "\u21c6", "\\leftrightarrows", true);
  4370. defineSymbol(math, ams, rel, "\u21da", "\\Lleftarrow", true);
  4371. defineSymbol(math, ams, rel, "\u219e", "\\twoheadleftarrow", true);
  4372. defineSymbol(math, ams, rel, "\u21a2", "\\leftarrowtail", true);
  4373. defineSymbol(math, ams, rel, "\u21ab", "\\looparrowleft", true);
  4374. defineSymbol(math, ams, rel, "\u21cb", "\\leftrightharpoons", true);
  4375. defineSymbol(math, ams, rel, "\u21b6", "\\curvearrowleft", true); // unicode-math maps \u21ba to \acwopencirclearrow. We'll use the AMS synonym.
  4376. defineSymbol(math, ams, rel, "\u21ba", "\\circlearrowleft", true);
  4377. defineSymbol(math, ams, rel, "\u21b0", "\\Lsh", true);
  4378. defineSymbol(math, ams, rel, "\u21c8", "\\upuparrows", true);
  4379. defineSymbol(math, ams, rel, "\u21bf", "\\upharpoonleft", true);
  4380. defineSymbol(math, ams, rel, "\u21c3", "\\downharpoonleft", true);
  4381. defineSymbol(math, main, rel, "\u22b6", "\\origof", true); // not in font
  4382. defineSymbol(math, main, rel, "\u22b7", "\\imageof", true); // not in font
  4383. defineSymbol(math, ams, rel, "\u22b8", "\\multimap", true);
  4384. defineSymbol(math, ams, rel, "\u21ad", "\\leftrightsquigarrow", true);
  4385. defineSymbol(math, ams, rel, "\u21c9", "\\rightrightarrows", true);
  4386. defineSymbol(math, ams, rel, "\u21c4", "\\rightleftarrows", true);
  4387. defineSymbol(math, ams, rel, "\u21a0", "\\twoheadrightarrow", true);
  4388. defineSymbol(math, ams, rel, "\u21a3", "\\rightarrowtail", true);
  4389. defineSymbol(math, ams, rel, "\u21ac", "\\looparrowright", true);
  4390. defineSymbol(math, ams, rel, "\u21b7", "\\curvearrowright", true); // unicode-math maps \u21bb to \cwopencirclearrow. We'll use the AMS synonym.
  4391. defineSymbol(math, ams, rel, "\u21bb", "\\circlearrowright", true);
  4392. defineSymbol(math, ams, rel, "\u21b1", "\\Rsh", true);
  4393. defineSymbol(math, ams, rel, "\u21ca", "\\downdownarrows", true);
  4394. defineSymbol(math, ams, rel, "\u21be", "\\upharpoonright", true);
  4395. defineSymbol(math, ams, rel, "\u21c2", "\\downharpoonright", true);
  4396. defineSymbol(math, ams, rel, "\u21dd", "\\rightsquigarrow", true);
  4397. defineSymbol(math, ams, rel, "\u21dd", "\\leadsto");
  4398. defineSymbol(math, ams, rel, "\u21db", "\\Rrightarrow", true);
  4399. defineSymbol(math, ams, rel, "\u21be", "\\restriction");
  4400. defineSymbol(math, main, textord, "\u2018", "`");
  4401. defineSymbol(math, main, textord, "$", "\\$");
  4402. defineSymbol(text, main, textord, "$", "\\$");
  4403. defineSymbol(text, main, textord, "$", "\\textdollar");
  4404. defineSymbol(math, main, textord, "%", "\\%");
  4405. defineSymbol(text, main, textord, "%", "\\%");
  4406. defineSymbol(math, main, textord, "_", "\\_");
  4407. defineSymbol(text, main, textord, "_", "\\_");
  4408. defineSymbol(text, main, textord, "_", "\\textunderscore");
  4409. defineSymbol(math, main, textord, "\u2220", "\\angle", true);
  4410. defineSymbol(math, main, textord, "\u221e", "\\infty", true);
  4411. defineSymbol(math, main, textord, "\u2032", "\\prime");
  4412. defineSymbol(math, main, textord, "\u25b3", "\\triangle");
  4413. defineSymbol(math, main, textord, "\u0393", "\\Gamma", true);
  4414. defineSymbol(math, main, textord, "\u0394", "\\Delta", true);
  4415. defineSymbol(math, main, textord, "\u0398", "\\Theta", true);
  4416. defineSymbol(math, main, textord, "\u039b", "\\Lambda", true);
  4417. defineSymbol(math, main, textord, "\u039e", "\\Xi", true);
  4418. defineSymbol(math, main, textord, "\u03a0", "\\Pi", true);
  4419. defineSymbol(math, main, textord, "\u03a3", "\\Sigma", true);
  4420. defineSymbol(math, main, textord, "\u03a5", "\\Upsilon", true);
  4421. defineSymbol(math, main, textord, "\u03a6", "\\Phi", true);
  4422. defineSymbol(math, main, textord, "\u03a8", "\\Psi", true);
  4423. defineSymbol(math, main, textord, "\u03a9", "\\Omega", true);
  4424. defineSymbol(math, main, textord, "A", "\u0391");
  4425. defineSymbol(math, main, textord, "B", "\u0392");
  4426. defineSymbol(math, main, textord, "E", "\u0395");
  4427. defineSymbol(math, main, textord, "Z", "\u0396");
  4428. defineSymbol(math, main, textord, "H", "\u0397");
  4429. defineSymbol(math, main, textord, "I", "\u0399");
  4430. defineSymbol(math, main, textord, "K", "\u039A");
  4431. defineSymbol(math, main, textord, "M", "\u039C");
  4432. defineSymbol(math, main, textord, "N", "\u039D");
  4433. defineSymbol(math, main, textord, "O", "\u039F");
  4434. defineSymbol(math, main, textord, "P", "\u03A1");
  4435. defineSymbol(math, main, textord, "T", "\u03A4");
  4436. defineSymbol(math, main, textord, "X", "\u03A7");
  4437. defineSymbol(math, main, textord, "\u00ac", "\\neg", true);
  4438. defineSymbol(math, main, textord, "\u00ac", "\\lnot");
  4439. defineSymbol(math, main, textord, "\u22a4", "\\top");
  4440. defineSymbol(math, main, textord, "\u22a5", "\\bot");
  4441. defineSymbol(math, main, textord, "\u2205", "\\emptyset");
  4442. defineSymbol(math, ams, textord, "\u2205", "\\varnothing");
  4443. defineSymbol(math, main, mathord, "\u03b1", "\\alpha", true);
  4444. defineSymbol(math, main, mathord, "\u03b2", "\\beta", true);
  4445. defineSymbol(math, main, mathord, "\u03b3", "\\gamma", true);
  4446. defineSymbol(math, main, mathord, "\u03b4", "\\delta", true);
  4447. defineSymbol(math, main, mathord, "\u03f5", "\\epsilon", true);
  4448. defineSymbol(math, main, mathord, "\u03b6", "\\zeta", true);
  4449. defineSymbol(math, main, mathord, "\u03b7", "\\eta", true);
  4450. defineSymbol(math, main, mathord, "\u03b8", "\\theta", true);
  4451. defineSymbol(math, main, mathord, "\u03b9", "\\iota", true);
  4452. defineSymbol(math, main, mathord, "\u03ba", "\\kappa", true);
  4453. defineSymbol(math, main, mathord, "\u03bb", "\\lambda", true);
  4454. defineSymbol(math, main, mathord, "\u03bc", "\\mu", true);
  4455. defineSymbol(math, main, mathord, "\u03bd", "\\nu", true);
  4456. defineSymbol(math, main, mathord, "\u03be", "\\xi", true);
  4457. defineSymbol(math, main, mathord, "\u03bf", "\\omicron", true);
  4458. defineSymbol(math, main, mathord, "\u03c0", "\\pi", true);
  4459. defineSymbol(math, main, mathord, "\u03c1", "\\rho", true);
  4460. defineSymbol(math, main, mathord, "\u03c3", "\\sigma", true);
  4461. defineSymbol(math, main, mathord, "\u03c4", "\\tau", true);
  4462. defineSymbol(math, main, mathord, "\u03c5", "\\upsilon", true);
  4463. defineSymbol(math, main, mathord, "\u03d5", "\\phi", true);
  4464. defineSymbol(math, main, mathord, "\u03c7", "\\chi", true);
  4465. defineSymbol(math, main, mathord, "\u03c8", "\\psi", true);
  4466. defineSymbol(math, main, mathord, "\u03c9", "\\omega", true);
  4467. defineSymbol(math, main, mathord, "\u03b5", "\\varepsilon", true);
  4468. defineSymbol(math, main, mathord, "\u03d1", "\\vartheta", true);
  4469. defineSymbol(math, main, mathord, "\u03d6", "\\varpi", true);
  4470. defineSymbol(math, main, mathord, "\u03f1", "\\varrho", true);
  4471. defineSymbol(math, main, mathord, "\u03c2", "\\varsigma", true);
  4472. defineSymbol(math, main, mathord, "\u03c6", "\\varphi", true);
  4473. defineSymbol(math, main, bin, "\u2217", "*", true);
  4474. defineSymbol(math, main, bin, "+", "+");
  4475. defineSymbol(math, main, bin, "\u2212", "-", true);
  4476. defineSymbol(math, main, bin, "\u22c5", "\\cdot", true);
  4477. defineSymbol(math, main, bin, "\u2218", "\\circ", true);
  4478. defineSymbol(math, main, bin, "\u00f7", "\\div", true);
  4479. defineSymbol(math, main, bin, "\u00b1", "\\pm", true);
  4480. defineSymbol(math, main, bin, "\u00d7", "\\times", true);
  4481. defineSymbol(math, main, bin, "\u2229", "\\cap", true);
  4482. defineSymbol(math, main, bin, "\u222a", "\\cup", true);
  4483. defineSymbol(math, main, bin, "\u2216", "\\setminus", true);
  4484. defineSymbol(math, main, bin, "\u2227", "\\land");
  4485. defineSymbol(math, main, bin, "\u2228", "\\lor");
  4486. defineSymbol(math, main, bin, "\u2227", "\\wedge", true);
  4487. defineSymbol(math, main, bin, "\u2228", "\\vee", true);
  4488. defineSymbol(math, main, textord, "\u221a", "\\surd");
  4489. defineSymbol(math, main, open, "\u27e8", "\\langle", true);
  4490. defineSymbol(math, main, open, "\u2223", "\\lvert");
  4491. defineSymbol(math, main, open, "\u2225", "\\lVert");
  4492. defineSymbol(math, main, close, "?", "?");
  4493. defineSymbol(math, main, close, "!", "!");
  4494. defineSymbol(math, main, close, "\u27e9", "\\rangle", true);
  4495. defineSymbol(math, main, close, "\u2223", "\\rvert");
  4496. defineSymbol(math, main, close, "\u2225", "\\rVert");
  4497. defineSymbol(math, main, rel, "=", "=");
  4498. defineSymbol(math, main, rel, ":", ":");
  4499. defineSymbol(math, main, rel, "\u2248", "\\approx", true);
  4500. defineSymbol(math, main, rel, "\u2245", "\\cong", true);
  4501. defineSymbol(math, main, rel, "\u2265", "\\ge");
  4502. defineSymbol(math, main, rel, "\u2265", "\\geq", true);
  4503. defineSymbol(math, main, rel, "\u2190", "\\gets");
  4504. defineSymbol(math, main, rel, ">", "\\gt", true);
  4505. defineSymbol(math, main, rel, "\u2208", "\\in", true);
  4506. defineSymbol(math, main, rel, "\ue020", "\\@not");
  4507. defineSymbol(math, main, rel, "\u2282", "\\subset", true);
  4508. defineSymbol(math, main, rel, "\u2283", "\\supset", true);
  4509. defineSymbol(math, main, rel, "\u2286", "\\subseteq", true);
  4510. defineSymbol(math, main, rel, "\u2287", "\\supseteq", true);
  4511. defineSymbol(math, ams, rel, "\u2288", "\\nsubseteq", true);
  4512. defineSymbol(math, ams, rel, "\u2289", "\\nsupseteq", true);
  4513. defineSymbol(math, main, rel, "\u22a8", "\\models");
  4514. defineSymbol(math, main, rel, "\u2190", "\\leftarrow", true);
  4515. defineSymbol(math, main, rel, "\u2264", "\\le");
  4516. defineSymbol(math, main, rel, "\u2264", "\\leq", true);
  4517. defineSymbol(math, main, rel, "<", "\\lt", true);
  4518. defineSymbol(math, main, rel, "\u2192", "\\rightarrow", true);
  4519. defineSymbol(math, main, rel, "\u2192", "\\to");
  4520. defineSymbol(math, ams, rel, "\u2271", "\\ngeq", true);
  4521. defineSymbol(math, ams, rel, "\u2270", "\\nleq", true);
  4522. defineSymbol(math, main, spacing, "\u00a0", "\\ ");
  4523. defineSymbol(math, main, spacing, "\u00a0", "\\space"); // Ref: LaTeX Source 2e: \DeclareRobustCommand{\nobreakspace}{%
  4524. defineSymbol(math, main, spacing, "\u00a0", "\\nobreakspace");
  4525. defineSymbol(text, main, spacing, "\u00a0", "\\ ");
  4526. defineSymbol(text, main, spacing, "\u00a0", " ");
  4527. defineSymbol(text, main, spacing, "\u00a0", "\\space");
  4528. defineSymbol(text, main, spacing, "\u00a0", "\\nobreakspace");
  4529. defineSymbol(math, main, spacing, null, "\\nobreak");
  4530. defineSymbol(math, main, spacing, null, "\\allowbreak");
  4531. defineSymbol(math, main, punct, ",", ",");
  4532. defineSymbol(math, main, punct, ";", ";");
  4533. defineSymbol(math, ams, bin, "\u22bc", "\\barwedge", true);
  4534. defineSymbol(math, ams, bin, "\u22bb", "\\veebar", true);
  4535. defineSymbol(math, main, bin, "\u2299", "\\odot", true);
  4536. defineSymbol(math, main, bin, "\u2295", "\\oplus", true);
  4537. defineSymbol(math, main, bin, "\u2297", "\\otimes", true);
  4538. defineSymbol(math, main, textord, "\u2202", "\\partial", true);
  4539. defineSymbol(math, main, bin, "\u2298", "\\oslash", true);
  4540. defineSymbol(math, ams, bin, "\u229a", "\\circledcirc", true);
  4541. defineSymbol(math, ams, bin, "\u22a1", "\\boxdot", true);
  4542. defineSymbol(math, main, bin, "\u25b3", "\\bigtriangleup");
  4543. defineSymbol(math, main, bin, "\u25bd", "\\bigtriangledown");
  4544. defineSymbol(math, main, bin, "\u2020", "\\dagger");
  4545. defineSymbol(math, main, bin, "\u22c4", "\\diamond");
  4546. defineSymbol(math, main, bin, "\u22c6", "\\star");
  4547. defineSymbol(math, main, bin, "\u25c3", "\\triangleleft");
  4548. defineSymbol(math, main, bin, "\u25b9", "\\triangleright");
  4549. defineSymbol(math, main, open, "{", "\\{");
  4550. defineSymbol(text, main, textord, "{", "\\{");
  4551. defineSymbol(text, main, textord, "{", "\\textbraceleft");
  4552. defineSymbol(math, main, close, "}", "\\}");
  4553. defineSymbol(text, main, textord, "}", "\\}");
  4554. defineSymbol(text, main, textord, "}", "\\textbraceright");
  4555. defineSymbol(math, main, open, "{", "\\lbrace");
  4556. defineSymbol(math, main, close, "}", "\\rbrace");
  4557. defineSymbol(math, main, open, "[", "\\lbrack", true);
  4558. defineSymbol(text, main, textord, "[", "\\lbrack", true);
  4559. defineSymbol(math, main, close, "]", "\\rbrack", true);
  4560. defineSymbol(text, main, textord, "]", "\\rbrack", true);
  4561. defineSymbol(math, main, open, "(", "\\lparen", true);
  4562. defineSymbol(math, main, close, ")", "\\rparen", true);
  4563. defineSymbol(text, main, textord, "<", "\\textless", true); // in T1 fontenc
  4564. defineSymbol(text, main, textord, ">", "\\textgreater", true); // in T1 fontenc
  4565. defineSymbol(math, main, open, "\u230a", "\\lfloor", true);
  4566. defineSymbol(math, main, close, "\u230b", "\\rfloor", true);
  4567. defineSymbol(math, main, open, "\u2308", "\\lceil", true);
  4568. defineSymbol(math, main, close, "\u2309", "\\rceil", true);
  4569. defineSymbol(math, main, textord, "\\", "\\backslash");
  4570. defineSymbol(math, main, textord, "\u2223", "|");
  4571. defineSymbol(math, main, textord, "\u2223", "\\vert");
  4572. defineSymbol(text, main, textord, "|", "\\textbar", true); // in T1 fontenc
  4573. defineSymbol(math, main, textord, "\u2225", "\\|");
  4574. defineSymbol(math, main, textord, "\u2225", "\\Vert");
  4575. defineSymbol(text, main, textord, "\u2225", "\\textbardbl");
  4576. defineSymbol(text, main, textord, "~", "\\textasciitilde");
  4577. defineSymbol(text, main, textord, "\\", "\\textbackslash");
  4578. defineSymbol(text, main, textord, "^", "\\textasciicircum");
  4579. defineSymbol(math, main, rel, "\u2191", "\\uparrow", true);
  4580. defineSymbol(math, main, rel, "\u21d1", "\\Uparrow", true);
  4581. defineSymbol(math, main, rel, "\u2193", "\\downarrow", true);
  4582. defineSymbol(math, main, rel, "\u21d3", "\\Downarrow", true);
  4583. defineSymbol(math, main, rel, "\u2195", "\\updownarrow", true);
  4584. defineSymbol(math, main, rel, "\u21d5", "\\Updownarrow", true);
  4585. defineSymbol(math, main, op, "\u2210", "\\coprod");
  4586. defineSymbol(math, main, op, "\u22c1", "\\bigvee");
  4587. defineSymbol(math, main, op, "\u22c0", "\\bigwedge");
  4588. defineSymbol(math, main, op, "\u2a04", "\\biguplus");
  4589. defineSymbol(math, main, op, "\u22c2", "\\bigcap");
  4590. defineSymbol(math, main, op, "\u22c3", "\\bigcup");
  4591. defineSymbol(math, main, op, "\u222b", "\\int");
  4592. defineSymbol(math, main, op, "\u222b", "\\intop");
  4593. defineSymbol(math, main, op, "\u222c", "\\iint");
  4594. defineSymbol(math, main, op, "\u222d", "\\iiint");
  4595. defineSymbol(math, main, op, "\u220f", "\\prod");
  4596. defineSymbol(math, main, op, "\u2211", "\\sum");
  4597. defineSymbol(math, main, op, "\u2a02", "\\bigotimes");
  4598. defineSymbol(math, main, op, "\u2a01", "\\bigoplus");
  4599. defineSymbol(math, main, op, "\u2a00", "\\bigodot");
  4600. defineSymbol(math, main, op, "\u222e", "\\oint");
  4601. defineSymbol(math, main, op, "\u222f", "\\oiint");
  4602. defineSymbol(math, main, op, "\u2230", "\\oiiint");
  4603. defineSymbol(math, main, op, "\u2a06", "\\bigsqcup");
  4604. defineSymbol(math, main, op, "\u222b", "\\smallint");
  4605. defineSymbol(text, main, inner, "\u2026", "\\textellipsis");
  4606. defineSymbol(math, main, inner, "\u2026", "\\mathellipsis");
  4607. defineSymbol(text, main, inner, "\u2026", "\\ldots", true);
  4608. defineSymbol(math, main, inner, "\u2026", "\\ldots", true);
  4609. defineSymbol(math, main, inner, "\u22ef", "\\@cdots", true);
  4610. defineSymbol(math, main, inner, "\u22f1", "\\ddots", true);
  4611. defineSymbol(math, main, textord, "\u22ee", "\\varvdots"); // \vdots is a macro
  4612. defineSymbol(math, main, accent, "\u02ca", "\\acute");
  4613. defineSymbol(math, main, accent, "\u02cb", "\\grave");
  4614. defineSymbol(math, main, accent, "\u00a8", "\\ddot");
  4615. defineSymbol(math, main, accent, "\u007e", "\\tilde");
  4616. defineSymbol(math, main, accent, "\u02c9", "\\bar");
  4617. defineSymbol(math, main, accent, "\u02d8", "\\breve");
  4618. defineSymbol(math, main, accent, "\u02c7", "\\check");
  4619. defineSymbol(math, main, accent, "\u005e", "\\hat");
  4620. defineSymbol(math, main, accent, "\u20d7", "\\vec");
  4621. defineSymbol(math, main, accent, "\u02d9", "\\dot");
  4622. defineSymbol(math, main, accent, "\u02da", "\\mathring"); // \imath and \jmath should be invariant to \mathrm, \mathbf, etc., so use PUA
  4623. defineSymbol(math, main, mathord, "\ue131", "\\@imath");
  4624. defineSymbol(math, main, mathord, "\ue237", "\\@jmath");
  4625. defineSymbol(math, main, textord, "\u0131", "\u0131");
  4626. defineSymbol(math, main, textord, "\u0237", "\u0237");
  4627. defineSymbol(text, main, textord, "\u0131", "\\i", true);
  4628. defineSymbol(text, main, textord, "\u0237", "\\j", true);
  4629. defineSymbol(text, main, textord, "\u00df", "\\ss", true);
  4630. defineSymbol(text, main, textord, "\u00e6", "\\ae", true);
  4631. defineSymbol(text, main, textord, "\u0153", "\\oe", true);
  4632. defineSymbol(text, main, textord, "\u00f8", "\\o", true);
  4633. defineSymbol(text, main, textord, "\u00c6", "\\AE", true);
  4634. defineSymbol(text, main, textord, "\u0152", "\\OE", true);
  4635. defineSymbol(text, main, textord, "\u00d8", "\\O", true);
  4636. defineSymbol(text, main, accent, "\u02ca", "\\'"); // acute
  4637. defineSymbol(text, main, accent, "\u02cb", "\\`"); // grave
  4638. defineSymbol(text, main, accent, "\u02c6", "\\^"); // circumflex
  4639. defineSymbol(text, main, accent, "\u02dc", "\\~"); // tilde
  4640. defineSymbol(text, main, accent, "\u02c9", "\\="); // macron
  4641. defineSymbol(text, main, accent, "\u02d8", "\\u"); // breve
  4642. defineSymbol(text, main, accent, "\u02d9", "\\."); // dot above
  4643. defineSymbol(text, main, accent, "\u00b8", "\\c"); // cedilla
  4644. defineSymbol(text, main, accent, "\u02da", "\\r"); // ring above
  4645. defineSymbol(text, main, accent, "\u02c7", "\\v"); // caron
  4646. defineSymbol(text, main, accent, "\u00a8", '\\"'); // diaresis
  4647. defineSymbol(text, main, accent, "\u02dd", "\\H"); // double acute
  4648. defineSymbol(text, main, accent, "\u25ef", "\\textcircled"); // \bigcirc glyph
  4649. // These ligatures are detected and created in Parser.js's `formLigatures`.
  4650. var ligatures = {
  4651. "--": true,
  4652. "---": true,
  4653. "``": true,
  4654. "''": true
  4655. };
  4656. defineSymbol(text, main, textord, "\u2013", "--", true);
  4657. defineSymbol(text, main, textord, "\u2013", "\\textendash");
  4658. defineSymbol(text, main, textord, "\u2014", "---", true);
  4659. defineSymbol(text, main, textord, "\u2014", "\\textemdash");
  4660. defineSymbol(text, main, textord, "\u2018", "`", true);
  4661. defineSymbol(text, main, textord, "\u2018", "\\textquoteleft");
  4662. defineSymbol(text, main, textord, "\u2019", "'", true);
  4663. defineSymbol(text, main, textord, "\u2019", "\\textquoteright");
  4664. defineSymbol(text, main, textord, "\u201c", "``", true);
  4665. defineSymbol(text, main, textord, "\u201c", "\\textquotedblleft");
  4666. defineSymbol(text, main, textord, "\u201d", "''", true);
  4667. defineSymbol(text, main, textord, "\u201d", "\\textquotedblright"); // \degree from gensymb package
  4668. defineSymbol(math, main, textord, "\u00b0", "\\degree", true);
  4669. defineSymbol(text, main, textord, "\u00b0", "\\degree"); // \textdegree from inputenc package
  4670. defineSymbol(text, main, textord, "\u00b0", "\\textdegree", true); // TODO: In LaTeX, \pounds can generate a different character in text and math
  4671. // mode, but among our fonts, only Main-Regular defines this character "163".
  4672. defineSymbol(math, main, textord, "\u00a3", "\\pounds");
  4673. defineSymbol(math, main, textord, "\u00a3", "\\mathsterling", true);
  4674. defineSymbol(text, main, textord, "\u00a3", "\\pounds");
  4675. defineSymbol(text, main, textord, "\u00a3", "\\textsterling", true);
  4676. defineSymbol(math, ams, textord, "\u2720", "\\maltese");
  4677. defineSymbol(text, ams, textord, "\u2720", "\\maltese"); // There are lots of symbols which are the same, so we add them in afterwards.
  4678. // All of these are textords in math mode
  4679. var mathTextSymbols = "0123456789/@.\"";
  4680. for (var i = 0; i < mathTextSymbols.length; i++) {
  4681. var ch = mathTextSymbols.charAt(i);
  4682. defineSymbol(math, main, textord, ch, ch);
  4683. } // All of these are textords in text mode
  4684. var textSymbols = "0123456789!@*()-=+\";:?/.,";
  4685. for (var _i = 0; _i < textSymbols.length; _i++) {
  4686. var _ch = textSymbols.charAt(_i);
  4687. defineSymbol(text, main, textord, _ch, _ch);
  4688. } // All of these are textords in text mode, and mathords in math mode
  4689. var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  4690. for (var _i2 = 0; _i2 < letters.length; _i2++) {
  4691. var _ch2 = letters.charAt(_i2);
  4692. defineSymbol(math, main, mathord, _ch2, _ch2);
  4693. defineSymbol(text, main, textord, _ch2, _ch2);
  4694. } // Blackboard bold and script letters in Unicode range
  4695. defineSymbol(math, ams, textord, "C", "\u2102"); // blackboard bold
  4696. defineSymbol(text, ams, textord, "C", "\u2102");
  4697. defineSymbol(math, ams, textord, "H", "\u210D");
  4698. defineSymbol(text, ams, textord, "H", "\u210D");
  4699. defineSymbol(math, ams, textord, "N", "\u2115");
  4700. defineSymbol(text, ams, textord, "N", "\u2115");
  4701. defineSymbol(math, ams, textord, "P", "\u2119");
  4702. defineSymbol(text, ams, textord, "P", "\u2119");
  4703. defineSymbol(math, ams, textord, "Q", "\u211A");
  4704. defineSymbol(text, ams, textord, "Q", "\u211A");
  4705. defineSymbol(math, ams, textord, "R", "\u211D");
  4706. defineSymbol(text, ams, textord, "R", "\u211D");
  4707. defineSymbol(math, ams, textord, "Z", "\u2124");
  4708. defineSymbol(text, ams, textord, "Z", "\u2124");
  4709. defineSymbol(math, main, mathord, "h", "\u210E"); // italic h, Planck constant
  4710. defineSymbol(text, main, mathord, "h", "\u210E"); // The next loop loads wide (surrogate pair) characters.
  4711. // We support some letters in the Unicode range U+1D400 to U+1D7FF,
  4712. // Mathematical Alphanumeric Symbols.
  4713. // Some editors do not deal well with wide characters. So don't write the
  4714. // string into this file. Instead, create the string from the surrogate pair.
  4715. var wideChar = "";
  4716. for (var _i3 = 0; _i3 < letters.length; _i3++) {
  4717. var _ch3 = letters.charAt(_i3); // The hex numbers in the next line are a surrogate pair.
  4718. // 0xD835 is the high surrogate for all letters in the range we support.
  4719. // 0xDC00 is the low surrogate for bold A.
  4720. wideChar = String.fromCharCode(0xD835, 0xDC00 + _i3); // A-Z a-z bold
  4721. defineSymbol(math, main, mathord, _ch3, wideChar);
  4722. defineSymbol(text, main, textord, _ch3, wideChar);
  4723. wideChar = String.fromCharCode(0xD835, 0xDC34 + _i3); // A-Z a-z italic
  4724. defineSymbol(math, main, mathord, _ch3, wideChar);
  4725. defineSymbol(text, main, textord, _ch3, wideChar);
  4726. wideChar = String.fromCharCode(0xD835, 0xDC68 + _i3); // A-Z a-z bold italic
  4727. defineSymbol(math, main, mathord, _ch3, wideChar);
  4728. defineSymbol(text, main, textord, _ch3, wideChar);
  4729. wideChar = String.fromCharCode(0xD835, 0xDD04 + _i3); // A-Z a-z Fractur
  4730. defineSymbol(math, main, mathord, _ch3, wideChar);
  4731. defineSymbol(text, main, textord, _ch3, wideChar);
  4732. wideChar = String.fromCharCode(0xD835, 0xDDA0 + _i3); // A-Z a-z sans-serif
  4733. defineSymbol(math, main, mathord, _ch3, wideChar);
  4734. defineSymbol(text, main, textord, _ch3, wideChar);
  4735. wideChar = String.fromCharCode(0xD835, 0xDDD4 + _i3); // A-Z a-z sans bold
  4736. defineSymbol(math, main, mathord, _ch3, wideChar);
  4737. defineSymbol(text, main, textord, _ch3, wideChar);
  4738. wideChar = String.fromCharCode(0xD835, 0xDE08 + _i3); // A-Z a-z sans italic
  4739. defineSymbol(math, main, mathord, _ch3, wideChar);
  4740. defineSymbol(text, main, textord, _ch3, wideChar);
  4741. wideChar = String.fromCharCode(0xD835, 0xDE70 + _i3); // A-Z a-z monospace
  4742. defineSymbol(math, main, mathord, _ch3, wideChar);
  4743. defineSymbol(text, main, textord, _ch3, wideChar);
  4744. if (_i3 < 26) {
  4745. // KaTeX fonts have only capital letters for blackboard bold and script.
  4746. // See exception for k below.
  4747. wideChar = String.fromCharCode(0xD835, 0xDD38 + _i3); // A-Z double struck
  4748. defineSymbol(math, main, mathord, _ch3, wideChar);
  4749. defineSymbol(text, main, textord, _ch3, wideChar);
  4750. wideChar = String.fromCharCode(0xD835, 0xDC9C + _i3); // A-Z script
  4751. defineSymbol(math, main, mathord, _ch3, wideChar);
  4752. defineSymbol(text, main, textord, _ch3, wideChar);
  4753. } // TODO: Add bold script when it is supported by a KaTeX font.
  4754. } // "k" is the only double struck lower case letter in the KaTeX fonts.
  4755. wideChar = String.fromCharCode(0xD835, 0xDD5C); // k double struck
  4756. defineSymbol(math, main, mathord, "k", wideChar);
  4757. defineSymbol(text, main, textord, "k", wideChar); // Next, some wide character numerals
  4758. for (var _i4 = 0; _i4 < 10; _i4++) {
  4759. var _ch4 = _i4.toString();
  4760. wideChar = String.fromCharCode(0xD835, 0xDFCE + _i4); // 0-9 bold
  4761. defineSymbol(math, main, mathord, _ch4, wideChar);
  4762. defineSymbol(text, main, textord, _ch4, wideChar);
  4763. wideChar = String.fromCharCode(0xD835, 0xDFE2 + _i4); // 0-9 sans serif
  4764. defineSymbol(math, main, mathord, _ch4, wideChar);
  4765. defineSymbol(text, main, textord, _ch4, wideChar);
  4766. wideChar = String.fromCharCode(0xD835, 0xDFEC + _i4); // 0-9 bold sans
  4767. defineSymbol(math, main, mathord, _ch4, wideChar);
  4768. defineSymbol(text, main, textord, _ch4, wideChar);
  4769. wideChar = String.fromCharCode(0xD835, 0xDFF6 + _i4); // 0-9 monospace
  4770. defineSymbol(math, main, mathord, _ch4, wideChar);
  4771. defineSymbol(text, main, textord, _ch4, wideChar);
  4772. } // We add these Latin-1 letters as symbols for backwards-compatibility,
  4773. // but they are not actually in the font, nor are they supported by the
  4774. // Unicode accent mechanism, so they fall back to Times font and look ugly.
  4775. // TODO(edemaine): Fix this.
  4776. var extraLatin = "\u00d0\u00de\u00fe";
  4777. for (var _i5 = 0; _i5 < extraLatin.length; _i5++) {
  4778. var _ch5 = extraLatin.charAt(_i5);
  4779. defineSymbol(math, main, mathord, _ch5, _ch5);
  4780. defineSymbol(text, main, textord, _ch5, _ch5);
  4781. }
  4782. /**
  4783. * This file provides support for Unicode range U+1D400 to U+1D7FF,
  4784. * Mathematical Alphanumeric Symbols.
  4785. *
  4786. * Function wideCharacterFont takes a wide character as input and returns
  4787. * the font information necessary to render it properly.
  4788. */
  4789. /**
  4790. * Data below is from https://www.unicode.org/charts/PDF/U1D400.pdf
  4791. * That document sorts characters into groups by font type, say bold or italic.
  4792. *
  4793. * In the arrays below, each subarray consists three elements:
  4794. * * The CSS class of that group when in math mode.
  4795. * * The CSS class of that group when in text mode.
  4796. * * The font name, so that KaTeX can get font metrics.
  4797. */
  4798. var wideLatinLetterData = [["mathbf", "textbf", "Main-Bold"], // A-Z bold upright
  4799. ["mathbf", "textbf", "Main-Bold"], // a-z bold upright
  4800. ["mathnormal", "textit", "Math-Italic"], // A-Z italic
  4801. ["mathnormal", "textit", "Math-Italic"], // a-z italic
  4802. ["boldsymbol", "boldsymbol", "Main-BoldItalic"], // A-Z bold italic
  4803. ["boldsymbol", "boldsymbol", "Main-BoldItalic"], // a-z bold italic
  4804. // Map fancy A-Z letters to script, not calligraphic.
  4805. // This aligns with unicode-math and math fonts (except Cambria Math).
  4806. ["mathscr", "textscr", "Script-Regular"], // A-Z script
  4807. ["", "", ""], // a-z script. No font
  4808. ["", "", ""], // A-Z bold script. No font
  4809. ["", "", ""], // a-z bold script. No font
  4810. ["mathfrak", "textfrak", "Fraktur-Regular"], // A-Z Fraktur
  4811. ["mathfrak", "textfrak", "Fraktur-Regular"], // a-z Fraktur
  4812. ["mathbb", "textbb", "AMS-Regular"], // A-Z double-struck
  4813. ["mathbb", "textbb", "AMS-Regular"], // k double-struck
  4814. ["", "", ""], // A-Z bold Fraktur No font metrics
  4815. ["", "", ""], // a-z bold Fraktur. No font.
  4816. ["mathsf", "textsf", "SansSerif-Regular"], // A-Z sans-serif
  4817. ["mathsf", "textsf", "SansSerif-Regular"], // a-z sans-serif
  4818. ["mathboldsf", "textboldsf", "SansSerif-Bold"], // A-Z bold sans-serif
  4819. ["mathboldsf", "textboldsf", "SansSerif-Bold"], // a-z bold sans-serif
  4820. ["mathitsf", "textitsf", "SansSerif-Italic"], // A-Z italic sans-serif
  4821. ["mathitsf", "textitsf", "SansSerif-Italic"], // a-z italic sans-serif
  4822. ["", "", ""], // A-Z bold italic sans. No font
  4823. ["", "", ""], // a-z bold italic sans. No font
  4824. ["mathtt", "texttt", "Typewriter-Regular"], // A-Z monospace
  4825. ["mathtt", "texttt", "Typewriter-Regular"] // a-z monospace
  4826. ];
  4827. var wideNumeralData = [["mathbf", "textbf", "Main-Bold"], // 0-9 bold
  4828. ["", "", ""], // 0-9 double-struck. No KaTeX font.
  4829. ["mathsf", "textsf", "SansSerif-Regular"], // 0-9 sans-serif
  4830. ["mathboldsf", "textboldsf", "SansSerif-Bold"], // 0-9 bold sans-serif
  4831. ["mathtt", "texttt", "Typewriter-Regular"] // 0-9 monospace
  4832. ];
  4833. var wideCharacterFont = function wideCharacterFont(wideChar, mode) {
  4834. // IE doesn't support codePointAt(). So work with the surrogate pair.
  4835. var H = wideChar.charCodeAt(0); // high surrogate
  4836. var L = wideChar.charCodeAt(1); // low surrogate
  4837. var codePoint = (H - 0xD800) * 0x400 + (L - 0xDC00) + 0x10000;
  4838. var j = mode === "math" ? 0 : 1; // column index for CSS class.
  4839. if (0x1D400 <= codePoint && codePoint < 0x1D6A4) {
  4840. // wideLatinLetterData contains exactly 26 chars on each row.
  4841. // So we can calculate the relevant row. No traverse necessary.
  4842. var i = Math.floor((codePoint - 0x1D400) / 26);
  4843. return [wideLatinLetterData[i][2], wideLatinLetterData[i][j]];
  4844. } else if (0x1D7CE <= codePoint && codePoint <= 0x1D7FF) {
  4845. // Numerals, ten per row.
  4846. var _i = Math.floor((codePoint - 0x1D7CE) / 10);
  4847. return [wideNumeralData[_i][2], wideNumeralData[_i][j]];
  4848. } else if (codePoint === 0x1D6A5 || codePoint === 0x1D6A6) {
  4849. // dotless i or j
  4850. return [wideLatinLetterData[0][2], wideLatinLetterData[0][j]];
  4851. } else if (0x1D6A6 < codePoint && codePoint < 0x1D7CE) {
  4852. // Greek letters. Not supported, yet.
  4853. return ["", ""];
  4854. } else {
  4855. // We don't support any wide characters outside 1D400–1D7FF.
  4856. throw new ParseError("Unsupported character: " + wideChar);
  4857. }
  4858. };
  4859. /* eslint no-console:0 */
  4860. /**
  4861. * Looks up the given symbol in fontMetrics, after applying any symbol
  4862. * replacements defined in symbol.js
  4863. */
  4864. var lookupSymbol = function lookupSymbol(value, // TODO(#963): Use a union type for this.
  4865. fontName, mode) {
  4866. // Replace the value with its replaced value from symbol.js
  4867. if (symbols[mode][value] && symbols[mode][value].replace) {
  4868. value = symbols[mode][value].replace;
  4869. }
  4870. return {
  4871. value: value,
  4872. metrics: getCharacterMetrics(value, fontName, mode)
  4873. };
  4874. };
  4875. /**
  4876. * Makes a symbolNode after translation via the list of symbols in symbols.js.
  4877. * Correctly pulls out metrics for the character, and optionally takes a list of
  4878. * classes to be attached to the node.
  4879. *
  4880. * TODO: make argument order closer to makeSpan
  4881. * TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
  4882. * should if present come first in `classes`.
  4883. * TODO(#953): Make `options` mandatory and always pass it in.
  4884. */
  4885. var makeSymbol = function makeSymbol(value, fontName, mode, options, classes) {
  4886. var lookup = lookupSymbol(value, fontName, mode);
  4887. var metrics = lookup.metrics;
  4888. value = lookup.value;
  4889. var symbolNode;
  4890. if (metrics) {
  4891. var italic = metrics.italic;
  4892. if (mode === "text" || options && options.font === "mathit") {
  4893. italic = 0;
  4894. }
  4895. symbolNode = new SymbolNode(value, metrics.height, metrics.depth, italic, metrics.skew, metrics.width, classes);
  4896. } else {
  4897. // TODO(emily): Figure out a good way to only print this in development
  4898. typeof console !== "undefined" && console.warn("No character metrics " + ("for '" + value + "' in style '" + fontName + "' and mode '" + mode + "'"));
  4899. symbolNode = new SymbolNode(value, 0, 0, 0, 0, 0, classes);
  4900. }
  4901. if (options) {
  4902. symbolNode.maxFontSize = options.sizeMultiplier;
  4903. if (options.style.isTight()) {
  4904. symbolNode.classes.push("mtight");
  4905. }
  4906. var color = options.getColor();
  4907. if (color) {
  4908. symbolNode.style.color = color;
  4909. }
  4910. }
  4911. return symbolNode;
  4912. };
  4913. /**
  4914. * Makes a symbol in Main-Regular or AMS-Regular.
  4915. * Used for rel, bin, open, close, inner, and punct.
  4916. */
  4917. var mathsym = function mathsym(value, mode, options, classes) {
  4918. if (classes === void 0) {
  4919. classes = [];
  4920. }
  4921. // Decide what font to render the symbol in by its entry in the symbols
  4922. // table.
  4923. // Have a special case for when the value = \ because the \ is used as a
  4924. // textord in unsupported command errors but cannot be parsed as a regular
  4925. // text ordinal and is therefore not present as a symbol in the symbols
  4926. // table for text, as well as a special case for boldsymbol because it
  4927. // can be used for bold + and -
  4928. if (options.font === "boldsymbol" && lookupSymbol(value, "Main-Bold", mode).metrics) {
  4929. return makeSymbol(value, "Main-Bold", mode, options, classes.concat(["mathbf"]));
  4930. } else if (value === "\\" || symbols[mode][value].font === "main") {
  4931. return makeSymbol(value, "Main-Regular", mode, options, classes);
  4932. } else {
  4933. return makeSymbol(value, "AMS-Regular", mode, options, classes.concat(["amsrm"]));
  4934. }
  4935. };
  4936. /**
  4937. * Determines which of the two font names (Main-Bold and Math-BoldItalic) and
  4938. * corresponding style tags (mathbf or boldsymbol) to use for font "boldsymbol",
  4939. * depending on the symbol. Use this function instead of fontMap for font
  4940. * "boldsymbol".
  4941. */
  4942. var boldsymbol = function boldsymbol(value, mode, options, classes, type) {
  4943. if (type !== "textord" && lookupSymbol(value, "Math-BoldItalic", mode).metrics) {
  4944. return {
  4945. fontName: "Math-BoldItalic",
  4946. fontClass: "boldsymbol"
  4947. };
  4948. } else {
  4949. // Some glyphs do not exist in Math-BoldItalic so we need to use
  4950. // Main-Bold instead.
  4951. return {
  4952. fontName: "Main-Bold",
  4953. fontClass: "mathbf"
  4954. };
  4955. }
  4956. };
  4957. /**
  4958. * Makes either a mathord or textord in the correct font and color.
  4959. */
  4960. var makeOrd = function makeOrd(group, options, type) {
  4961. var mode = group.mode;
  4962. var text = group.text;
  4963. var classes = ["mord"]; // Math mode or Old font (i.e. \rm)
  4964. var isFont = mode === "math" || mode === "text" && options.font;
  4965. var fontOrFamily = isFont ? options.font : options.fontFamily;
  4966. if (text.charCodeAt(0) === 0xD835) {
  4967. // surrogate pairs get special treatment
  4968. var [wideFontName, wideFontClass] = wideCharacterFont(text, mode);
  4969. return makeSymbol(text, wideFontName, mode, options, classes.concat(wideFontClass));
  4970. } else if (fontOrFamily) {
  4971. var fontName;
  4972. var fontClasses;
  4973. if (fontOrFamily === "boldsymbol") {
  4974. var fontData = boldsymbol(text, mode, options, classes, type);
  4975. fontName = fontData.fontName;
  4976. fontClasses = [fontData.fontClass];
  4977. } else if (isFont) {
  4978. fontName = fontMap[fontOrFamily].fontName;
  4979. fontClasses = [fontOrFamily];
  4980. } else {
  4981. fontName = retrieveTextFontName(fontOrFamily, options.fontWeight, options.fontShape);
  4982. fontClasses = [fontOrFamily, options.fontWeight, options.fontShape];
  4983. }
  4984. if (lookupSymbol(text, fontName, mode).metrics) {
  4985. return makeSymbol(text, fontName, mode, options, classes.concat(fontClasses));
  4986. } else if (ligatures.hasOwnProperty(text) && fontName.substr(0, 10) === "Typewriter") {
  4987. // Deconstruct ligatures in monospace fonts (\texttt, \tt).
  4988. var parts = [];
  4989. for (var i = 0; i < text.length; i++) {
  4990. parts.push(makeSymbol(text[i], fontName, mode, options, classes.concat(fontClasses)));
  4991. }
  4992. return makeFragment(parts);
  4993. }
  4994. } // Makes a symbol in the default font for mathords and textords.
  4995. if (type === "mathord") {
  4996. return makeSymbol(text, "Math-Italic", mode, options, classes.concat(["mathnormal"]));
  4997. } else if (type === "textord") {
  4998. var font = symbols[mode][text] && symbols[mode][text].font;
  4999. if (font === "ams") {
  5000. var _fontName = retrieveTextFontName("amsrm", options.fontWeight, options.fontShape);
  5001. return makeSymbol(text, _fontName, mode, options, classes.concat("amsrm", options.fontWeight, options.fontShape));
  5002. } else if (font === "main" || !font) {
  5003. var _fontName2 = retrieveTextFontName("textrm", options.fontWeight, options.fontShape);
  5004. return makeSymbol(text, _fontName2, mode, options, classes.concat(options.fontWeight, options.fontShape));
  5005. } else {
  5006. // fonts added by plugins
  5007. var _fontName3 = retrieveTextFontName(font, options.fontWeight, options.fontShape); // We add font name as a css class
  5008. return makeSymbol(text, _fontName3, mode, options, classes.concat(_fontName3, options.fontWeight, options.fontShape));
  5009. }
  5010. } else {
  5011. throw new Error("unexpected type: " + type + " in makeOrd");
  5012. }
  5013. };
  5014. /**
  5015. * Returns true if subsequent symbolNodes have the same classes, skew, maxFont,
  5016. * and styles.
  5017. */
  5018. var canCombine = (prev, next) => {
  5019. if (createClass(prev.classes) !== createClass(next.classes) || prev.skew !== next.skew || prev.maxFontSize !== next.maxFontSize) {
  5020. return false;
  5021. } // If prev and next both are just "mbin"s or "mord"s we don't combine them
  5022. // so that the proper spacing can be preserved.
  5023. if (prev.classes.length === 1) {
  5024. var cls = prev.classes[0];
  5025. if (cls === "mbin" || cls === "mord") {
  5026. return false;
  5027. }
  5028. }
  5029. for (var style in prev.style) {
  5030. if (prev.style.hasOwnProperty(style) && prev.style[style] !== next.style[style]) {
  5031. return false;
  5032. }
  5033. }
  5034. for (var _style in next.style) {
  5035. if (next.style.hasOwnProperty(_style) && prev.style[_style] !== next.style[_style]) {
  5036. return false;
  5037. }
  5038. }
  5039. return true;
  5040. };
  5041. /**
  5042. * Combine consecutive domTree.symbolNodes into a single symbolNode.
  5043. * Note: this function mutates the argument.
  5044. */
  5045. var tryCombineChars = chars => {
  5046. for (var i = 0; i < chars.length - 1; i++) {
  5047. var prev = chars[i];
  5048. var next = chars[i + 1];
  5049. if (prev instanceof SymbolNode && next instanceof SymbolNode && canCombine(prev, next)) {
  5050. prev.text += next.text;
  5051. prev.height = Math.max(prev.height, next.height);
  5052. prev.depth = Math.max(prev.depth, next.depth); // Use the last character's italic correction since we use
  5053. // it to add padding to the right of the span created from
  5054. // the combined characters.
  5055. prev.italic = next.italic;
  5056. chars.splice(i + 1, 1);
  5057. i--;
  5058. }
  5059. }
  5060. return chars;
  5061. };
  5062. /**
  5063. * Calculate the height, depth, and maxFontSize of an element based on its
  5064. * children.
  5065. */
  5066. var sizeElementFromChildren = function sizeElementFromChildren(elem) {
  5067. var height = 0;
  5068. var depth = 0;
  5069. var maxFontSize = 0;
  5070. for (var i = 0; i < elem.children.length; i++) {
  5071. var child = elem.children[i];
  5072. if (child.height > height) {
  5073. height = child.height;
  5074. }
  5075. if (child.depth > depth) {
  5076. depth = child.depth;
  5077. }
  5078. if (child.maxFontSize > maxFontSize) {
  5079. maxFontSize = child.maxFontSize;
  5080. }
  5081. }
  5082. elem.height = height;
  5083. elem.depth = depth;
  5084. elem.maxFontSize = maxFontSize;
  5085. };
  5086. /**
  5087. * Makes a span with the given list of classes, list of children, and options.
  5088. *
  5089. * TODO(#953): Ensure that `options` is always provided (currently some call
  5090. * sites don't pass it) and make the type below mandatory.
  5091. * TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
  5092. * should if present come first in `classes`.
  5093. */
  5094. var makeSpan$2 = function makeSpan(classes, children, options, style) {
  5095. var span = new Span(classes, children, options, style);
  5096. sizeElementFromChildren(span);
  5097. return span;
  5098. }; // SVG one is simpler -- doesn't require height, depth, max-font setting.
  5099. // This is also a separate method for typesafety.
  5100. var makeSvgSpan = (classes, children, options, style) => new Span(classes, children, options, style);
  5101. var makeLineSpan = function makeLineSpan(className, options, thickness) {
  5102. var line = makeSpan$2([className], [], options);
  5103. line.height = Math.max(thickness || options.fontMetrics().defaultRuleThickness, options.minRuleThickness);
  5104. line.style.borderBottomWidth = makeEm(line.height);
  5105. line.maxFontSize = 1.0;
  5106. return line;
  5107. };
  5108. /**
  5109. * Makes an anchor with the given href, list of classes, list of children,
  5110. * and options.
  5111. */
  5112. var makeAnchor = function makeAnchor(href, classes, children, options) {
  5113. var anchor = new Anchor(href, classes, children, options);
  5114. sizeElementFromChildren(anchor);
  5115. return anchor;
  5116. };
  5117. /**
  5118. * Makes a document fragment with the given list of children.
  5119. */
  5120. var makeFragment = function makeFragment(children) {
  5121. var fragment = new DocumentFragment(children);
  5122. sizeElementFromChildren(fragment);
  5123. return fragment;
  5124. };
  5125. /**
  5126. * Wraps group in a span if it's a document fragment, allowing to apply classes
  5127. * and styles
  5128. */
  5129. var wrapFragment = function wrapFragment(group, options) {
  5130. if (group instanceof DocumentFragment) {
  5131. return makeSpan$2([], [group], options);
  5132. }
  5133. return group;
  5134. }; // These are exact object types to catch typos in the names of the optional fields.
  5135. // Computes the updated `children` list and the overall depth.
  5136. //
  5137. // This helper function for makeVList makes it easier to enforce type safety by
  5138. // allowing early exits (returns) in the logic.
  5139. var getVListChildrenAndDepth = function getVListChildrenAndDepth(params) {
  5140. if (params.positionType === "individualShift") {
  5141. var oldChildren = params.children;
  5142. var children = [oldChildren[0]]; // Add in kerns to the list of params.children to get each element to be
  5143. // shifted to the correct specified shift
  5144. var _depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
  5145. var currPos = _depth;
  5146. for (var i = 1; i < oldChildren.length; i++) {
  5147. var diff = -oldChildren[i].shift - currPos - oldChildren[i].elem.depth;
  5148. var size = diff - (oldChildren[i - 1].elem.height + oldChildren[i - 1].elem.depth);
  5149. currPos = currPos + diff;
  5150. children.push({
  5151. type: "kern",
  5152. size
  5153. });
  5154. children.push(oldChildren[i]);
  5155. }
  5156. return {
  5157. children,
  5158. depth: _depth
  5159. };
  5160. }
  5161. var depth;
  5162. if (params.positionType === "top") {
  5163. // We always start at the bottom, so calculate the bottom by adding up
  5164. // all the sizes
  5165. var bottom = params.positionData;
  5166. for (var _i = 0; _i < params.children.length; _i++) {
  5167. var child = params.children[_i];
  5168. bottom -= child.type === "kern" ? child.size : child.elem.height + child.elem.depth;
  5169. }
  5170. depth = bottom;
  5171. } else if (params.positionType === "bottom") {
  5172. depth = -params.positionData;
  5173. } else {
  5174. var firstChild = params.children[0];
  5175. if (firstChild.type !== "elem") {
  5176. throw new Error('First child must have type "elem".');
  5177. }
  5178. if (params.positionType === "shift") {
  5179. depth = -firstChild.elem.depth - params.positionData;
  5180. } else if (params.positionType === "firstBaseline") {
  5181. depth = -firstChild.elem.depth;
  5182. } else {
  5183. throw new Error("Invalid positionType " + params.positionType + ".");
  5184. }
  5185. }
  5186. return {
  5187. children: params.children,
  5188. depth
  5189. };
  5190. };
  5191. /**
  5192. * Makes a vertical list by stacking elements and kerns on top of each other.
  5193. * Allows for many different ways of specifying the positioning method.
  5194. *
  5195. * See VListParam documentation above.
  5196. */
  5197. var makeVList = function makeVList(params, options) {
  5198. var {
  5199. children,
  5200. depth
  5201. } = getVListChildrenAndDepth(params); // Create a strut that is taller than any list item. The strut is added to
  5202. // each item, where it will determine the item's baseline. Since it has
  5203. // `overflow:hidden`, the strut's top edge will sit on the item's line box's
  5204. // top edge and the strut's bottom edge will sit on the item's baseline,
  5205. // with no additional line-height spacing. This allows the item baseline to
  5206. // be positioned precisely without worrying about font ascent and
  5207. // line-height.
  5208. var pstrutSize = 0;
  5209. for (var i = 0; i < children.length; i++) {
  5210. var child = children[i];
  5211. if (child.type === "elem") {
  5212. var elem = child.elem;
  5213. pstrutSize = Math.max(pstrutSize, elem.maxFontSize, elem.height);
  5214. }
  5215. }
  5216. pstrutSize += 2;
  5217. var pstrut = makeSpan$2(["pstrut"], []);
  5218. pstrut.style.height = makeEm(pstrutSize); // Create a new list of actual children at the correct offsets
  5219. var realChildren = [];
  5220. var minPos = depth;
  5221. var maxPos = depth;
  5222. var currPos = depth;
  5223. for (var _i2 = 0; _i2 < children.length; _i2++) {
  5224. var _child = children[_i2];
  5225. if (_child.type === "kern") {
  5226. currPos += _child.size;
  5227. } else {
  5228. var _elem = _child.elem;
  5229. var classes = _child.wrapperClasses || [];
  5230. var style = _child.wrapperStyle || {};
  5231. var childWrap = makeSpan$2(classes, [pstrut, _elem], undefined, style);
  5232. childWrap.style.top = makeEm(-pstrutSize - currPos - _elem.depth);
  5233. if (_child.marginLeft) {
  5234. childWrap.style.marginLeft = _child.marginLeft;
  5235. }
  5236. if (_child.marginRight) {
  5237. childWrap.style.marginRight = _child.marginRight;
  5238. }
  5239. realChildren.push(childWrap);
  5240. currPos += _elem.height + _elem.depth;
  5241. }
  5242. minPos = Math.min(minPos, currPos);
  5243. maxPos = Math.max(maxPos, currPos);
  5244. } // The vlist contents go in a table-cell with `vertical-align:bottom`.
  5245. // This cell's bottom edge will determine the containing table's baseline
  5246. // without overly expanding the containing line-box.
  5247. var vlist = makeSpan$2(["vlist"], realChildren);
  5248. vlist.style.height = makeEm(maxPos); // A second row is used if necessary to represent the vlist's depth.
  5249. var rows;
  5250. if (minPos < 0) {
  5251. // We will define depth in an empty span with display: table-cell.
  5252. // It should render with the height that we define. But Chrome, in
  5253. // contenteditable mode only, treats that span as if it contains some
  5254. // text content. And that min-height over-rides our desired height.
  5255. // So we put another empty span inside the depth strut span.
  5256. var emptySpan = makeSpan$2([], []);
  5257. var depthStrut = makeSpan$2(["vlist"], [emptySpan]);
  5258. depthStrut.style.height = makeEm(-minPos); // Safari wants the first row to have inline content; otherwise it
  5259. // puts the bottom of the *second* row on the baseline.
  5260. var topStrut = makeSpan$2(["vlist-s"], [new SymbolNode("\u200b")]);
  5261. rows = [makeSpan$2(["vlist-r"], [vlist, topStrut]), makeSpan$2(["vlist-r"], [depthStrut])];
  5262. } else {
  5263. rows = [makeSpan$2(["vlist-r"], [vlist])];
  5264. }
  5265. var vtable = makeSpan$2(["vlist-t"], rows);
  5266. if (rows.length === 2) {
  5267. vtable.classes.push("vlist-t2");
  5268. }
  5269. vtable.height = maxPos;
  5270. vtable.depth = -minPos;
  5271. return vtable;
  5272. }; // Glue is a concept from TeX which is a flexible space between elements in
  5273. // either a vertical or horizontal list. In KaTeX, at least for now, it's
  5274. // static space between elements in a horizontal layout.
  5275. var makeGlue = (measurement, options) => {
  5276. // Make an empty span for the space
  5277. var rule = makeSpan$2(["mspace"], [], options);
  5278. var size = calculateSize(measurement, options);
  5279. rule.style.marginRight = makeEm(size);
  5280. return rule;
  5281. }; // Takes font options, and returns the appropriate fontLookup name
  5282. var retrieveTextFontName = function retrieveTextFontName(fontFamily, fontWeight, fontShape) {
  5283. var baseFontName = "";
  5284. switch (fontFamily) {
  5285. case "amsrm":
  5286. baseFontName = "AMS";
  5287. break;
  5288. case "textrm":
  5289. baseFontName = "Main";
  5290. break;
  5291. case "textsf":
  5292. baseFontName = "SansSerif";
  5293. break;
  5294. case "texttt":
  5295. baseFontName = "Typewriter";
  5296. break;
  5297. default:
  5298. baseFontName = fontFamily;
  5299. // use fonts added by a plugin
  5300. }
  5301. var fontStylesName;
  5302. if (fontWeight === "textbf" && fontShape === "textit") {
  5303. fontStylesName = "BoldItalic";
  5304. } else if (fontWeight === "textbf") {
  5305. fontStylesName = "Bold";
  5306. } else if (fontWeight === "textit") {
  5307. fontStylesName = "Italic";
  5308. } else {
  5309. fontStylesName = "Regular";
  5310. }
  5311. return baseFontName + "-" + fontStylesName;
  5312. };
  5313. /**
  5314. * Maps TeX font commands to objects containing:
  5315. * - variant: string used for "mathvariant" attribute in buildMathML.js
  5316. * - fontName: the "style" parameter to fontMetrics.getCharacterMetrics
  5317. */
  5318. // A map between tex font commands an MathML mathvariant attribute values
  5319. var fontMap = {
  5320. // styles
  5321. "mathbf": {
  5322. variant: "bold",
  5323. fontName: "Main-Bold"
  5324. },
  5325. "mathrm": {
  5326. variant: "normal",
  5327. fontName: "Main-Regular"
  5328. },
  5329. "textit": {
  5330. variant: "italic",
  5331. fontName: "Main-Italic"
  5332. },
  5333. "mathit": {
  5334. variant: "italic",
  5335. fontName: "Main-Italic"
  5336. },
  5337. "mathnormal": {
  5338. variant: "italic",
  5339. fontName: "Math-Italic"
  5340. },
  5341. // "boldsymbol" is missing because they require the use of multiple fonts:
  5342. // Math-BoldItalic and Main-Bold. This is handled by a special case in
  5343. // makeOrd which ends up calling boldsymbol.
  5344. // families
  5345. "mathbb": {
  5346. variant: "double-struck",
  5347. fontName: "AMS-Regular"
  5348. },
  5349. "mathcal": {
  5350. variant: "script",
  5351. fontName: "Caligraphic-Regular"
  5352. },
  5353. "mathfrak": {
  5354. variant: "fraktur",
  5355. fontName: "Fraktur-Regular"
  5356. },
  5357. "mathscr": {
  5358. variant: "script",
  5359. fontName: "Script-Regular"
  5360. },
  5361. "mathsf": {
  5362. variant: "sans-serif",
  5363. fontName: "SansSerif-Regular"
  5364. },
  5365. "mathtt": {
  5366. variant: "monospace",
  5367. fontName: "Typewriter-Regular"
  5368. }
  5369. };
  5370. var svgData = {
  5371. // path, width, height
  5372. vec: ["vec", 0.471, 0.714],
  5373. // values from the font glyph
  5374. oiintSize1: ["oiintSize1", 0.957, 0.499],
  5375. // oval to overlay the integrand
  5376. oiintSize2: ["oiintSize2", 1.472, 0.659],
  5377. oiiintSize1: ["oiiintSize1", 1.304, 0.499],
  5378. oiiintSize2: ["oiiintSize2", 1.98, 0.659]
  5379. };
  5380. var staticSvg = function staticSvg(value, options) {
  5381. // Create a span with inline SVG for the element.
  5382. var [pathName, width, height] = svgData[value];
  5383. var path = new PathNode(pathName);
  5384. var svgNode = new SvgNode([path], {
  5385. "width": makeEm(width),
  5386. "height": makeEm(height),
  5387. // Override CSS rule `.katex svg { width: 100% }`
  5388. "style": "width:" + makeEm(width),
  5389. "viewBox": "0 0 " + 1000 * width + " " + 1000 * height,
  5390. "preserveAspectRatio": "xMinYMin"
  5391. });
  5392. var span = makeSvgSpan(["overlay"], [svgNode], options);
  5393. span.height = height;
  5394. span.style.height = makeEm(height);
  5395. span.style.width = makeEm(width);
  5396. return span;
  5397. };
  5398. var buildCommon = {
  5399. fontMap,
  5400. makeSymbol,
  5401. mathsym,
  5402. makeSpan: makeSpan$2,
  5403. makeSvgSpan,
  5404. makeLineSpan,
  5405. makeAnchor,
  5406. makeFragment,
  5407. wrapFragment,
  5408. makeVList,
  5409. makeOrd,
  5410. makeGlue,
  5411. staticSvg,
  5412. svgData,
  5413. tryCombineChars
  5414. };
  5415. /**
  5416. * Describes spaces between different classes of atoms.
  5417. */
  5418. var thinspace = {
  5419. number: 3,
  5420. unit: "mu"
  5421. };
  5422. var mediumspace = {
  5423. number: 4,
  5424. unit: "mu"
  5425. };
  5426. var thickspace = {
  5427. number: 5,
  5428. unit: "mu"
  5429. }; // Making the type below exact with all optional fields doesn't work due to
  5430. // - https://github.com/facebook/flow/issues/4582
  5431. // - https://github.com/facebook/flow/issues/5688
  5432. // However, since *all* fields are optional, $Shape<> works as suggested in 5688
  5433. // above.
  5434. // Spacing relationships for display and text styles
  5435. var spacings = {
  5436. mord: {
  5437. mop: thinspace,
  5438. mbin: mediumspace,
  5439. mrel: thickspace,
  5440. minner: thinspace
  5441. },
  5442. mop: {
  5443. mord: thinspace,
  5444. mop: thinspace,
  5445. mrel: thickspace,
  5446. minner: thinspace
  5447. },
  5448. mbin: {
  5449. mord: mediumspace,
  5450. mop: mediumspace,
  5451. mopen: mediumspace,
  5452. minner: mediumspace
  5453. },
  5454. mrel: {
  5455. mord: thickspace,
  5456. mop: thickspace,
  5457. mopen: thickspace,
  5458. minner: thickspace
  5459. },
  5460. mopen: {},
  5461. mclose: {
  5462. mop: thinspace,
  5463. mbin: mediumspace,
  5464. mrel: thickspace,
  5465. minner: thinspace
  5466. },
  5467. mpunct: {
  5468. mord: thinspace,
  5469. mop: thinspace,
  5470. mrel: thickspace,
  5471. mopen: thinspace,
  5472. mclose: thinspace,
  5473. mpunct: thinspace,
  5474. minner: thinspace
  5475. },
  5476. minner: {
  5477. mord: thinspace,
  5478. mop: thinspace,
  5479. mbin: mediumspace,
  5480. mrel: thickspace,
  5481. mopen: thinspace,
  5482. mpunct: thinspace,
  5483. minner: thinspace
  5484. }
  5485. }; // Spacing relationships for script and scriptscript styles
  5486. var tightSpacings = {
  5487. mord: {
  5488. mop: thinspace
  5489. },
  5490. mop: {
  5491. mord: thinspace,
  5492. mop: thinspace
  5493. },
  5494. mbin: {},
  5495. mrel: {},
  5496. mopen: {},
  5497. mclose: {
  5498. mop: thinspace
  5499. },
  5500. mpunct: {},
  5501. minner: {
  5502. mop: thinspace
  5503. }
  5504. };
  5505. /** Context provided to function handlers for error messages. */
  5506. // Note: reverse the order of the return type union will cause a flow error.
  5507. // See https://github.com/facebook/flow/issues/3663.
  5508. // More general version of `HtmlBuilder` for nodes (e.g. \sum, accent types)
  5509. // whose presence impacts super/subscripting. In this case, ParseNode<"supsub">
  5510. // delegates its HTML building to the HtmlBuilder corresponding to these nodes.
  5511. /**
  5512. * Final function spec for use at parse time.
  5513. * This is almost identical to `FunctionPropSpec`, except it
  5514. * 1. includes the function handler, and
  5515. * 2. requires all arguments except argTypes.
  5516. * It is generated by `defineFunction()` below.
  5517. */
  5518. /**
  5519. * All registered functions.
  5520. * `functions.js` just exports this same dictionary again and makes it public.
  5521. * `Parser.js` requires this dictionary.
  5522. */
  5523. var _functions = {};
  5524. /**
  5525. * All HTML builders. Should be only used in the `define*` and the `build*ML`
  5526. * functions.
  5527. */
  5528. var _htmlGroupBuilders = {};
  5529. /**
  5530. * All MathML builders. Should be only used in the `define*` and the `build*ML`
  5531. * functions.
  5532. */
  5533. var _mathmlGroupBuilders = {};
  5534. function defineFunction(_ref) {
  5535. var {
  5536. type,
  5537. names,
  5538. props,
  5539. handler,
  5540. htmlBuilder,
  5541. mathmlBuilder
  5542. } = _ref;
  5543. // Set default values of functions
  5544. var data = {
  5545. type,
  5546. numArgs: props.numArgs,
  5547. argTypes: props.argTypes,
  5548. allowedInArgument: !!props.allowedInArgument,
  5549. allowedInText: !!props.allowedInText,
  5550. allowedInMath: props.allowedInMath === undefined ? true : props.allowedInMath,
  5551. numOptionalArgs: props.numOptionalArgs || 0,
  5552. infix: !!props.infix,
  5553. primitive: !!props.primitive,
  5554. handler: handler
  5555. };
  5556. for (var i = 0; i < names.length; ++i) {
  5557. _functions[names[i]] = data;
  5558. }
  5559. if (type) {
  5560. if (htmlBuilder) {
  5561. _htmlGroupBuilders[type] = htmlBuilder;
  5562. }
  5563. if (mathmlBuilder) {
  5564. _mathmlGroupBuilders[type] = mathmlBuilder;
  5565. }
  5566. }
  5567. }
  5568. /**
  5569. * Use this to register only the HTML and MathML builders for a function (e.g.
  5570. * if the function's ParseNode is generated in Parser.js rather than via a
  5571. * stand-alone handler provided to `defineFunction`).
  5572. */
  5573. function defineFunctionBuilders(_ref2) {
  5574. var {
  5575. type,
  5576. htmlBuilder,
  5577. mathmlBuilder
  5578. } = _ref2;
  5579. defineFunction({
  5580. type,
  5581. names: [],
  5582. props: {
  5583. numArgs: 0
  5584. },
  5585. handler() {
  5586. throw new Error('Should never be called.');
  5587. },
  5588. htmlBuilder,
  5589. mathmlBuilder
  5590. });
  5591. }
  5592. var normalizeArgument = function normalizeArgument(arg) {
  5593. return arg.type === "ordgroup" && arg.body.length === 1 ? arg.body[0] : arg;
  5594. }; // Since the corresponding buildHTML/buildMathML function expects a
  5595. // list of elements, we normalize for different kinds of arguments
  5596. var ordargument = function ordargument(arg) {
  5597. return arg.type === "ordgroup" ? arg.body : [arg];
  5598. };
  5599. /**
  5600. * This file does the main work of building a domTree structure from a parse
  5601. * tree. The entry point is the `buildHTML` function, which takes a parse tree.
  5602. * Then, the buildExpression, buildGroup, and various groupBuilders functions
  5603. * are called, to produce a final HTML tree.
  5604. */
  5605. var makeSpan$1 = buildCommon.makeSpan; // Binary atoms (first class `mbin`) change into ordinary atoms (`mord`)
  5606. // depending on their surroundings. See TeXbook pg. 442-446, Rules 5 and 6,
  5607. // and the text before Rule 19.
  5608. var binLeftCanceller = ["leftmost", "mbin", "mopen", "mrel", "mop", "mpunct"];
  5609. var binRightCanceller = ["rightmost", "mrel", "mclose", "mpunct"];
  5610. var styleMap$1 = {
  5611. "display": Style$1.DISPLAY,
  5612. "text": Style$1.TEXT,
  5613. "script": Style$1.SCRIPT,
  5614. "scriptscript": Style$1.SCRIPTSCRIPT
  5615. };
  5616. var DomEnum = {
  5617. mord: "mord",
  5618. mop: "mop",
  5619. mbin: "mbin",
  5620. mrel: "mrel",
  5621. mopen: "mopen",
  5622. mclose: "mclose",
  5623. mpunct: "mpunct",
  5624. minner: "minner"
  5625. };
  5626. /**
  5627. * Take a list of nodes, build them in order, and return a list of the built
  5628. * nodes. documentFragments are flattened into their contents, so the
  5629. * returned list contains no fragments. `isRealGroup` is true if `expression`
  5630. * is a real group (no atoms will be added on either side), as opposed to
  5631. * a partial group (e.g. one created by \color). `surrounding` is an array
  5632. * consisting type of nodes that will be added to the left and right.
  5633. */
  5634. var buildExpression$1 = function buildExpression(expression, options, isRealGroup, surrounding) {
  5635. if (surrounding === void 0) {
  5636. surrounding = [null, null];
  5637. }
  5638. // Parse expressions into `groups`.
  5639. var groups = [];
  5640. for (var i = 0; i < expression.length; i++) {
  5641. var output = buildGroup$1(expression[i], options);
  5642. if (output instanceof DocumentFragment) {
  5643. var children = output.children;
  5644. groups.push(...children);
  5645. } else {
  5646. groups.push(output);
  5647. }
  5648. } // Combine consecutive domTree.symbolNodes into a single symbolNode.
  5649. buildCommon.tryCombineChars(groups); // If `expression` is a partial group, let the parent handle spacings
  5650. // to avoid processing groups multiple times.
  5651. if (!isRealGroup) {
  5652. return groups;
  5653. }
  5654. var glueOptions = options;
  5655. if (expression.length === 1) {
  5656. var node = expression[0];
  5657. if (node.type === "sizing") {
  5658. glueOptions = options.havingSize(node.size);
  5659. } else if (node.type === "styling") {
  5660. glueOptions = options.havingStyle(styleMap$1[node.style]);
  5661. }
  5662. } // Dummy spans for determining spacings between surrounding atoms.
  5663. // If `expression` has no atoms on the left or right, class "leftmost"
  5664. // or "rightmost", respectively, is used to indicate it.
  5665. var dummyPrev = makeSpan$1([surrounding[0] || "leftmost"], [], options);
  5666. var dummyNext = makeSpan$1([surrounding[1] || "rightmost"], [], options); // TODO: These code assumes that a node's math class is the first element
  5667. // of its `classes` array. A later cleanup should ensure this, for
  5668. // instance by changing the signature of `makeSpan`.
  5669. // Before determining what spaces to insert, perform bin cancellation.
  5670. // Binary operators change to ordinary symbols in some contexts.
  5671. var isRoot = isRealGroup === "root";
  5672. traverseNonSpaceNodes(groups, (node, prev) => {
  5673. var prevType = prev.classes[0];
  5674. var type = node.classes[0];
  5675. if (prevType === "mbin" && utils.contains(binRightCanceller, type)) {
  5676. prev.classes[0] = "mord";
  5677. } else if (type === "mbin" && utils.contains(binLeftCanceller, prevType)) {
  5678. node.classes[0] = "mord";
  5679. }
  5680. }, {
  5681. node: dummyPrev
  5682. }, dummyNext, isRoot);
  5683. traverseNonSpaceNodes(groups, (node, prev) => {
  5684. var prevType = getTypeOfDomTree(prev);
  5685. var type = getTypeOfDomTree(node); // 'mtight' indicates that the node is script or scriptscript style.
  5686. var space = prevType && type ? node.hasClass("mtight") ? tightSpacings[prevType][type] : spacings[prevType][type] : null;
  5687. if (space) {
  5688. // Insert glue (spacing) after the `prev`.
  5689. return buildCommon.makeGlue(space, glueOptions);
  5690. }
  5691. }, {
  5692. node: dummyPrev
  5693. }, dummyNext, isRoot);
  5694. return groups;
  5695. }; // Depth-first traverse non-space `nodes`, calling `callback` with the current and
  5696. // previous node as arguments, optionally returning a node to insert after the
  5697. // previous node. `prev` is an object with the previous node and `insertAfter`
  5698. // function to insert after it. `next` is a node that will be added to the right.
  5699. // Used for bin cancellation and inserting spacings.
  5700. var traverseNonSpaceNodes = function traverseNonSpaceNodes(nodes, callback, prev, next, isRoot) {
  5701. if (next) {
  5702. // temporarily append the right node, if exists
  5703. nodes.push(next);
  5704. }
  5705. var i = 0;
  5706. for (; i < nodes.length; i++) {
  5707. var node = nodes[i];
  5708. var partialGroup = checkPartialGroup(node);
  5709. if (partialGroup) {
  5710. // Recursive DFS
  5711. // $FlowFixMe: make nodes a $ReadOnlyArray by returning a new array
  5712. traverseNonSpaceNodes(partialGroup.children, callback, prev, null, isRoot);
  5713. continue;
  5714. } // Ignore explicit spaces (e.g., \;, \,) when determining what implicit
  5715. // spacing should go between atoms of different classes
  5716. var nonspace = !node.hasClass("mspace");
  5717. if (nonspace) {
  5718. var result = callback(node, prev.node);
  5719. if (result) {
  5720. if (prev.insertAfter) {
  5721. prev.insertAfter(result);
  5722. } else {
  5723. // insert at front
  5724. nodes.unshift(result);
  5725. i++;
  5726. }
  5727. }
  5728. }
  5729. if (nonspace) {
  5730. prev.node = node;
  5731. } else if (isRoot && node.hasClass("newline")) {
  5732. prev.node = makeSpan$1(["leftmost"]); // treat like beginning of line
  5733. }
  5734. prev.insertAfter = (index => n => {
  5735. nodes.splice(index + 1, 0, n);
  5736. i++;
  5737. })(i);
  5738. }
  5739. if (next) {
  5740. nodes.pop();
  5741. }
  5742. }; // Check if given node is a partial group, i.e., does not affect spacing around.
  5743. var checkPartialGroup = function checkPartialGroup(node) {
  5744. if (node instanceof DocumentFragment || node instanceof Anchor || node instanceof Span && node.hasClass("enclosing")) {
  5745. return node;
  5746. }
  5747. return null;
  5748. }; // Return the outermost node of a domTree.
  5749. var getOutermostNode = function getOutermostNode(node, side) {
  5750. var partialGroup = checkPartialGroup(node);
  5751. if (partialGroup) {
  5752. var children = partialGroup.children;
  5753. if (children.length) {
  5754. if (side === "right") {
  5755. return getOutermostNode(children[children.length - 1], "right");
  5756. } else if (side === "left") {
  5757. return getOutermostNode(children[0], "left");
  5758. }
  5759. }
  5760. }
  5761. return node;
  5762. }; // Return math atom class (mclass) of a domTree.
  5763. // If `side` is given, it will get the type of the outermost node at given side.
  5764. var getTypeOfDomTree = function getTypeOfDomTree(node, side) {
  5765. if (!node) {
  5766. return null;
  5767. }
  5768. if (side) {
  5769. node = getOutermostNode(node, side);
  5770. } // This makes a lot of assumptions as to where the type of atom
  5771. // appears. We should do a better job of enforcing this.
  5772. return DomEnum[node.classes[0]] || null;
  5773. };
  5774. var makeNullDelimiter = function makeNullDelimiter(options, classes) {
  5775. var moreClasses = ["nulldelimiter"].concat(options.baseSizingClasses());
  5776. return makeSpan$1(classes.concat(moreClasses));
  5777. };
  5778. /**
  5779. * buildGroup is the function that takes a group and calls the correct groupType
  5780. * function for it. It also handles the interaction of size and style changes
  5781. * between parents and children.
  5782. */
  5783. var buildGroup$1 = function buildGroup(group, options, baseOptions) {
  5784. if (!group) {
  5785. return makeSpan$1();
  5786. }
  5787. if (_htmlGroupBuilders[group.type]) {
  5788. // Call the groupBuilders function
  5789. // $FlowFixMe
  5790. var groupNode = _htmlGroupBuilders[group.type](group, options); // If the size changed between the parent and the current group, account
  5791. // for that size difference.
  5792. if (baseOptions && options.size !== baseOptions.size) {
  5793. groupNode = makeSpan$1(options.sizingClasses(baseOptions), [groupNode], options);
  5794. var multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier;
  5795. groupNode.height *= multiplier;
  5796. groupNode.depth *= multiplier;
  5797. }
  5798. return groupNode;
  5799. } else {
  5800. throw new ParseError("Got group of unknown type: '" + group.type + "'");
  5801. }
  5802. };
  5803. /**
  5804. * Combine an array of HTML DOM nodes (e.g., the output of `buildExpression`)
  5805. * into an unbreakable HTML node of class .base, with proper struts to
  5806. * guarantee correct vertical extent. `buildHTML` calls this repeatedly to
  5807. * make up the entire expression as a sequence of unbreakable units.
  5808. */
  5809. function buildHTMLUnbreakable(children, options) {
  5810. // Compute height and depth of this chunk.
  5811. var body = makeSpan$1(["base"], children, options); // Add strut, which ensures that the top of the HTML element falls at
  5812. // the height of the expression, and the bottom of the HTML element
  5813. // falls at the depth of the expression.
  5814. var strut = makeSpan$1(["strut"]);
  5815. strut.style.height = makeEm(body.height + body.depth);
  5816. if (body.depth) {
  5817. strut.style.verticalAlign = makeEm(-body.depth);
  5818. }
  5819. body.children.unshift(strut);
  5820. return body;
  5821. }
  5822. /**
  5823. * Take an entire parse tree, and build it into an appropriate set of HTML
  5824. * nodes.
  5825. */
  5826. function buildHTML(tree, options) {
  5827. // Strip off outer tag wrapper for processing below.
  5828. var tag = null;
  5829. if (tree.length === 1 && tree[0].type === "tag") {
  5830. tag = tree[0].tag;
  5831. tree = tree[0].body;
  5832. } // Build the expression contained in the tree
  5833. var expression = buildExpression$1(tree, options, "root");
  5834. var eqnNum;
  5835. if (expression.length === 2 && expression[1].hasClass("tag")) {
  5836. // An environment with automatic equation numbers, e.g. {gather}.
  5837. eqnNum = expression.pop();
  5838. }
  5839. var children = []; // Create one base node for each chunk between potential line breaks.
  5840. // The TeXBook [p.173] says "A formula will be broken only after a
  5841. // relation symbol like $=$ or $<$ or $\rightarrow$, or after a binary
  5842. // operation symbol like $+$ or $-$ or $\times$, where the relation or
  5843. // binary operation is on the ``outer level'' of the formula (i.e., not
  5844. // enclosed in {...} and not part of an \over construction)."
  5845. var parts = [];
  5846. for (var i = 0; i < expression.length; i++) {
  5847. parts.push(expression[i]);
  5848. if (expression[i].hasClass("mbin") || expression[i].hasClass("mrel") || expression[i].hasClass("allowbreak")) {
  5849. // Put any post-operator glue on same line as operator.
  5850. // Watch for \nobreak along the way, and stop at \newline.
  5851. var nobreak = false;
  5852. while (i < expression.length - 1 && expression[i + 1].hasClass("mspace") && !expression[i + 1].hasClass("newline")) {
  5853. i++;
  5854. parts.push(expression[i]);
  5855. if (expression[i].hasClass("nobreak")) {
  5856. nobreak = true;
  5857. }
  5858. } // Don't allow break if \nobreak among the post-operator glue.
  5859. if (!nobreak) {
  5860. children.push(buildHTMLUnbreakable(parts, options));
  5861. parts = [];
  5862. }
  5863. } else if (expression[i].hasClass("newline")) {
  5864. // Write the line except the newline
  5865. parts.pop();
  5866. if (parts.length > 0) {
  5867. children.push(buildHTMLUnbreakable(parts, options));
  5868. parts = [];
  5869. } // Put the newline at the top level
  5870. children.push(expression[i]);
  5871. }
  5872. }
  5873. if (parts.length > 0) {
  5874. children.push(buildHTMLUnbreakable(parts, options));
  5875. } // Now, if there was a tag, build it too and append it as a final child.
  5876. var tagChild;
  5877. if (tag) {
  5878. tagChild = buildHTMLUnbreakable(buildExpression$1(tag, options, true));
  5879. tagChild.classes = ["tag"];
  5880. children.push(tagChild);
  5881. } else if (eqnNum) {
  5882. children.push(eqnNum);
  5883. }
  5884. var htmlNode = makeSpan$1(["katex-html"], children);
  5885. htmlNode.setAttribute("aria-hidden", "true"); // Adjust the strut of the tag to be the maximum height of all children
  5886. // (the height of the enclosing htmlNode) for proper vertical alignment.
  5887. if (tagChild) {
  5888. var strut = tagChild.children[0];
  5889. strut.style.height = makeEm(htmlNode.height + htmlNode.depth);
  5890. if (htmlNode.depth) {
  5891. strut.style.verticalAlign = makeEm(-htmlNode.depth);
  5892. }
  5893. }
  5894. return htmlNode;
  5895. }
  5896. /**
  5897. * These objects store data about MathML nodes. This is the MathML equivalent
  5898. * of the types in domTree.js. Since MathML handles its own rendering, and
  5899. * since we're mainly using MathML to improve accessibility, we don't manage
  5900. * any of the styling state that the plain DOM nodes do.
  5901. *
  5902. * The `toNode` and `toMarkup` functions work simlarly to how they do in
  5903. * domTree.js, creating namespaced DOM nodes and HTML text markup respectively.
  5904. */
  5905. function newDocumentFragment(children) {
  5906. return new DocumentFragment(children);
  5907. }
  5908. /**
  5909. * This node represents a general purpose MathML node of any type. The
  5910. * constructor requires the type of node to create (for example, `"mo"` or
  5911. * `"mspace"`, corresponding to `<mo>` and `<mspace>` tags).
  5912. */
  5913. class MathNode {
  5914. constructor(type, children, classes) {
  5915. this.type = void 0;
  5916. this.attributes = void 0;
  5917. this.children = void 0;
  5918. this.classes = void 0;
  5919. this.type = type;
  5920. this.attributes = {};
  5921. this.children = children || [];
  5922. this.classes = classes || [];
  5923. }
  5924. /**
  5925. * Sets an attribute on a MathML node. MathML depends on attributes to convey a
  5926. * semantic content, so this is used heavily.
  5927. */
  5928. setAttribute(name, value) {
  5929. this.attributes[name] = value;
  5930. }
  5931. /**
  5932. * Gets an attribute on a MathML node.
  5933. */
  5934. getAttribute(name) {
  5935. return this.attributes[name];
  5936. }
  5937. /**
  5938. * Converts the math node into a MathML-namespaced DOM element.
  5939. */
  5940. toNode() {
  5941. var node = document.createElementNS("http://www.w3.org/1998/Math/MathML", this.type);
  5942. for (var attr in this.attributes) {
  5943. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  5944. node.setAttribute(attr, this.attributes[attr]);
  5945. }
  5946. }
  5947. if (this.classes.length > 0) {
  5948. node.className = createClass(this.classes);
  5949. }
  5950. for (var i = 0; i < this.children.length; i++) {
  5951. node.appendChild(this.children[i].toNode());
  5952. }
  5953. return node;
  5954. }
  5955. /**
  5956. * Converts the math node into an HTML markup string.
  5957. */
  5958. toMarkup() {
  5959. var markup = "<" + this.type; // Add the attributes
  5960. for (var attr in this.attributes) {
  5961. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  5962. markup += " " + attr + "=\"";
  5963. markup += utils.escape(this.attributes[attr]);
  5964. markup += "\"";
  5965. }
  5966. }
  5967. if (this.classes.length > 0) {
  5968. markup += " class =\"" + utils.escape(createClass(this.classes)) + "\"";
  5969. }
  5970. markup += ">";
  5971. for (var i = 0; i < this.children.length; i++) {
  5972. markup += this.children[i].toMarkup();
  5973. }
  5974. markup += "</" + this.type + ">";
  5975. return markup;
  5976. }
  5977. /**
  5978. * Converts the math node into a string, similar to innerText, but escaped.
  5979. */
  5980. toText() {
  5981. return this.children.map(child => child.toText()).join("");
  5982. }
  5983. }
  5984. /**
  5985. * This node represents a piece of text.
  5986. */
  5987. class TextNode {
  5988. constructor(text) {
  5989. this.text = void 0;
  5990. this.text = text;
  5991. }
  5992. /**
  5993. * Converts the text node into a DOM text node.
  5994. */
  5995. toNode() {
  5996. return document.createTextNode(this.text);
  5997. }
  5998. /**
  5999. * Converts the text node into escaped HTML markup
  6000. * (representing the text itself).
  6001. */
  6002. toMarkup() {
  6003. return utils.escape(this.toText());
  6004. }
  6005. /**
  6006. * Converts the text node into a string
  6007. * (representing the text iteself).
  6008. */
  6009. toText() {
  6010. return this.text;
  6011. }
  6012. }
  6013. /**
  6014. * This node represents a space, but may render as <mspace.../> or as text,
  6015. * depending on the width.
  6016. */
  6017. class SpaceNode {
  6018. /**
  6019. * Create a Space node with width given in CSS ems.
  6020. */
  6021. constructor(width) {
  6022. this.width = void 0;
  6023. this.character = void 0;
  6024. this.width = width; // See https://www.w3.org/TR/2000/WD-MathML2-20000328/chapter6.html
  6025. // for a table of space-like characters. We use Unicode
  6026. // representations instead of &LongNames; as it's not clear how to
  6027. // make the latter via document.createTextNode.
  6028. if (width >= 0.05555 && width <= 0.05556) {
  6029. this.character = "\u200a"; // &VeryThinSpace;
  6030. } else if (width >= 0.1666 && width <= 0.1667) {
  6031. this.character = "\u2009"; // &ThinSpace;
  6032. } else if (width >= 0.2222 && width <= 0.2223) {
  6033. this.character = "\u2005"; // &MediumSpace;
  6034. } else if (width >= 0.2777 && width <= 0.2778) {
  6035. this.character = "\u2005\u200a"; // &ThickSpace;
  6036. } else if (width >= -0.05556 && width <= -0.05555) {
  6037. this.character = "\u200a\u2063"; // &NegativeVeryThinSpace;
  6038. } else if (width >= -0.1667 && width <= -0.1666) {
  6039. this.character = "\u2009\u2063"; // &NegativeThinSpace;
  6040. } else if (width >= -0.2223 && width <= -0.2222) {
  6041. this.character = "\u205f\u2063"; // &NegativeMediumSpace;
  6042. } else if (width >= -0.2778 && width <= -0.2777) {
  6043. this.character = "\u2005\u2063"; // &NegativeThickSpace;
  6044. } else {
  6045. this.character = null;
  6046. }
  6047. }
  6048. /**
  6049. * Converts the math node into a MathML-namespaced DOM element.
  6050. */
  6051. toNode() {
  6052. if (this.character) {
  6053. return document.createTextNode(this.character);
  6054. } else {
  6055. var node = document.createElementNS("http://www.w3.org/1998/Math/MathML", "mspace");
  6056. node.setAttribute("width", makeEm(this.width));
  6057. return node;
  6058. }
  6059. }
  6060. /**
  6061. * Converts the math node into an HTML markup string.
  6062. */
  6063. toMarkup() {
  6064. if (this.character) {
  6065. return "<mtext>" + this.character + "</mtext>";
  6066. } else {
  6067. return "<mspace width=\"" + makeEm(this.width) + "\"/>";
  6068. }
  6069. }
  6070. /**
  6071. * Converts the math node into a string, similar to innerText.
  6072. */
  6073. toText() {
  6074. if (this.character) {
  6075. return this.character;
  6076. } else {
  6077. return " ";
  6078. }
  6079. }
  6080. }
  6081. var mathMLTree = {
  6082. MathNode,
  6083. TextNode,
  6084. SpaceNode,
  6085. newDocumentFragment
  6086. };
  6087. /**
  6088. * This file converts a parse tree into a cooresponding MathML tree. The main
  6089. * entry point is the `buildMathML` function, which takes a parse tree from the
  6090. * parser.
  6091. */
  6092. /**
  6093. * Takes a symbol and converts it into a MathML text node after performing
  6094. * optional replacement from symbols.js.
  6095. */
  6096. var makeText = function makeText(text, mode, options) {
  6097. if (symbols[mode][text] && symbols[mode][text].replace && text.charCodeAt(0) !== 0xD835 && !(ligatures.hasOwnProperty(text) && options && (options.fontFamily && options.fontFamily.substr(4, 2) === "tt" || options.font && options.font.substr(4, 2) === "tt"))) {
  6098. text = symbols[mode][text].replace;
  6099. }
  6100. return new mathMLTree.TextNode(text);
  6101. };
  6102. /**
  6103. * Wrap the given array of nodes in an <mrow> node if needed, i.e.,
  6104. * unless the array has length 1. Always returns a single node.
  6105. */
  6106. var makeRow = function makeRow(body) {
  6107. if (body.length === 1) {
  6108. return body[0];
  6109. } else {
  6110. return new mathMLTree.MathNode("mrow", body);
  6111. }
  6112. };
  6113. /**
  6114. * Returns the math variant as a string or null if none is required.
  6115. */
  6116. var getVariant = function getVariant(group, options) {
  6117. // Handle \text... font specifiers as best we can.
  6118. // MathML has a limited list of allowable mathvariant specifiers; see
  6119. // https://www.w3.org/TR/MathML3/chapter3.html#presm.commatt
  6120. if (options.fontFamily === "texttt") {
  6121. return "monospace";
  6122. } else if (options.fontFamily === "textsf") {
  6123. if (options.fontShape === "textit" && options.fontWeight === "textbf") {
  6124. return "sans-serif-bold-italic";
  6125. } else if (options.fontShape === "textit") {
  6126. return "sans-serif-italic";
  6127. } else if (options.fontWeight === "textbf") {
  6128. return "bold-sans-serif";
  6129. } else {
  6130. return "sans-serif";
  6131. }
  6132. } else if (options.fontShape === "textit" && options.fontWeight === "textbf") {
  6133. return "bold-italic";
  6134. } else if (options.fontShape === "textit") {
  6135. return "italic";
  6136. } else if (options.fontWeight === "textbf") {
  6137. return "bold";
  6138. }
  6139. var font = options.font;
  6140. if (!font || font === "mathnormal") {
  6141. return null;
  6142. }
  6143. var mode = group.mode;
  6144. if (font === "mathit") {
  6145. return "italic";
  6146. } else if (font === "boldsymbol") {
  6147. return group.type === "textord" ? "bold" : "bold-italic";
  6148. } else if (font === "mathbf") {
  6149. return "bold";
  6150. } else if (font === "mathbb") {
  6151. return "double-struck";
  6152. } else if (font === "mathfrak") {
  6153. return "fraktur";
  6154. } else if (font === "mathscr" || font === "mathcal") {
  6155. // MathML makes no distinction between script and caligrahpic
  6156. return "script";
  6157. } else if (font === "mathsf") {
  6158. return "sans-serif";
  6159. } else if (font === "mathtt") {
  6160. return "monospace";
  6161. }
  6162. var text = group.text;
  6163. if (utils.contains(["\\imath", "\\jmath"], text)) {
  6164. return null;
  6165. }
  6166. if (symbols[mode][text] && symbols[mode][text].replace) {
  6167. text = symbols[mode][text].replace;
  6168. }
  6169. var fontName = buildCommon.fontMap[font].fontName;
  6170. if (getCharacterMetrics(text, fontName, mode)) {
  6171. return buildCommon.fontMap[font].variant;
  6172. }
  6173. return null;
  6174. };
  6175. /**
  6176. * Takes a list of nodes, builds them, and returns a list of the generated
  6177. * MathML nodes. Also combine consecutive <mtext> outputs into a single
  6178. * <mtext> tag.
  6179. */
  6180. var buildExpression = function buildExpression(expression, options, isOrdgroup) {
  6181. if (expression.length === 1) {
  6182. var group = buildGroup(expression[0], options);
  6183. if (isOrdgroup && group instanceof MathNode && group.type === "mo") {
  6184. // When TeX writers want to suppress spacing on an operator,
  6185. // they often put the operator by itself inside braces.
  6186. group.setAttribute("lspace", "0em");
  6187. group.setAttribute("rspace", "0em");
  6188. }
  6189. return [group];
  6190. }
  6191. var groups = [];
  6192. var lastGroup;
  6193. for (var i = 0; i < expression.length; i++) {
  6194. var _group = buildGroup(expression[i], options);
  6195. if (_group instanceof MathNode && lastGroup instanceof MathNode) {
  6196. // Concatenate adjacent <mtext>s
  6197. if (_group.type === 'mtext' && lastGroup.type === 'mtext' && _group.getAttribute('mathvariant') === lastGroup.getAttribute('mathvariant')) {
  6198. lastGroup.children.push(..._group.children);
  6199. continue; // Concatenate adjacent <mn>s
  6200. } else if (_group.type === 'mn' && lastGroup.type === 'mn') {
  6201. lastGroup.children.push(..._group.children);
  6202. continue; // Concatenate <mn>...</mn> followed by <mi>.</mi>
  6203. } else if (_group.type === 'mi' && _group.children.length === 1 && lastGroup.type === 'mn') {
  6204. var child = _group.children[0];
  6205. if (child instanceof TextNode && child.text === '.') {
  6206. lastGroup.children.push(..._group.children);
  6207. continue;
  6208. }
  6209. } else if (lastGroup.type === 'mi' && lastGroup.children.length === 1) {
  6210. var lastChild = lastGroup.children[0];
  6211. if (lastChild instanceof TextNode && lastChild.text === '\u0338' && (_group.type === 'mo' || _group.type === 'mi' || _group.type === 'mn')) {
  6212. var _child = _group.children[0];
  6213. if (_child instanceof TextNode && _child.text.length > 0) {
  6214. // Overlay with combining character long solidus
  6215. _child.text = _child.text.slice(0, 1) + "\u0338" + _child.text.slice(1);
  6216. groups.pop();
  6217. }
  6218. }
  6219. }
  6220. }
  6221. groups.push(_group);
  6222. lastGroup = _group;
  6223. }
  6224. return groups;
  6225. };
  6226. /**
  6227. * Equivalent to buildExpression, but wraps the elements in an <mrow>
  6228. * if there's more than one. Returns a single node instead of an array.
  6229. */
  6230. var buildExpressionRow = function buildExpressionRow(expression, options, isOrdgroup) {
  6231. return makeRow(buildExpression(expression, options, isOrdgroup));
  6232. };
  6233. /**
  6234. * Takes a group from the parser and calls the appropriate groupBuilders function
  6235. * on it to produce a MathML node.
  6236. */
  6237. var buildGroup = function buildGroup(group, options) {
  6238. if (!group) {
  6239. return new mathMLTree.MathNode("mrow");
  6240. }
  6241. if (_mathmlGroupBuilders[group.type]) {
  6242. // Call the groupBuilders function
  6243. // $FlowFixMe
  6244. var result = _mathmlGroupBuilders[group.type](group, options); // $FlowFixMe
  6245. return result;
  6246. } else {
  6247. throw new ParseError("Got group of unknown type: '" + group.type + "'");
  6248. }
  6249. };
  6250. /**
  6251. * Takes a full parse tree and settings and builds a MathML representation of
  6252. * it. In particular, we put the elements from building the parse tree into a
  6253. * <semantics> tag so we can also include that TeX source as an annotation.
  6254. *
  6255. * Note that we actually return a domTree element with a `<math>` inside it so
  6256. * we can do appropriate styling.
  6257. */
  6258. function buildMathML(tree, texExpression, options, isDisplayMode, forMathmlOnly) {
  6259. var expression = buildExpression(tree, options); // TODO: Make a pass thru the MathML similar to buildHTML.traverseNonSpaceNodes
  6260. // and add spacing nodes. This is necessary only adjacent to math operators
  6261. // like \sin or \lim or to subsup elements that contain math operators.
  6262. // MathML takes care of the other spacing issues.
  6263. // Wrap up the expression in an mrow so it is presented in the semantics
  6264. // tag correctly, unless it's a single <mrow> or <mtable>.
  6265. var wrapper;
  6266. if (expression.length === 1 && expression[0] instanceof MathNode && utils.contains(["mrow", "mtable"], expression[0].type)) {
  6267. wrapper = expression[0];
  6268. } else {
  6269. wrapper = new mathMLTree.MathNode("mrow", expression);
  6270. } // Build a TeX annotation of the source
  6271. var annotation = new mathMLTree.MathNode("annotation", [new mathMLTree.TextNode(texExpression)]);
  6272. annotation.setAttribute("encoding", "application/x-tex");
  6273. var semantics = new mathMLTree.MathNode("semantics", [wrapper, annotation]);
  6274. var math = new mathMLTree.MathNode("math", [semantics]);
  6275. math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
  6276. if (isDisplayMode) {
  6277. math.setAttribute("display", "block");
  6278. } // You can't style <math> nodes, so we wrap the node in a span.
  6279. // NOTE: The span class is not typed to have <math> nodes as children, and
  6280. // we don't want to make the children type more generic since the children
  6281. // of span are expected to have more fields in `buildHtml` contexts.
  6282. var wrapperClass = forMathmlOnly ? "katex" : "katex-mathml"; // $FlowFixMe
  6283. return buildCommon.makeSpan([wrapperClass], [math]);
  6284. }
  6285. var optionsFromSettings = function optionsFromSettings(settings) {
  6286. return new Options({
  6287. style: settings.displayMode ? Style$1.DISPLAY : Style$1.TEXT,
  6288. maxSize: settings.maxSize,
  6289. minRuleThickness: settings.minRuleThickness
  6290. });
  6291. };
  6292. var displayWrap = function displayWrap(node, settings) {
  6293. if (settings.displayMode) {
  6294. var classes = ["katex-display"];
  6295. if (settings.leqno) {
  6296. classes.push("leqno");
  6297. }
  6298. if (settings.fleqn) {
  6299. classes.push("fleqn");
  6300. }
  6301. node = buildCommon.makeSpan(classes, [node]);
  6302. }
  6303. return node;
  6304. };
  6305. var buildTree = function buildTree(tree, expression, settings) {
  6306. var options = optionsFromSettings(settings);
  6307. var katexNode;
  6308. if (settings.output === "mathml") {
  6309. return buildMathML(tree, expression, options, settings.displayMode, true);
  6310. } else if (settings.output === "html") {
  6311. var htmlNode = buildHTML(tree, options);
  6312. katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
  6313. } else {
  6314. var mathMLNode = buildMathML(tree, expression, options, settings.displayMode, false);
  6315. var _htmlNode = buildHTML(tree, options);
  6316. katexNode = buildCommon.makeSpan(["katex"], [mathMLNode, _htmlNode]);
  6317. }
  6318. return displayWrap(katexNode, settings);
  6319. };
  6320. var buildHTMLTree = function buildHTMLTree(tree, expression, settings) {
  6321. var options = optionsFromSettings(settings);
  6322. var htmlNode = buildHTML(tree, options);
  6323. var katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
  6324. return displayWrap(katexNode, settings);
  6325. };
  6326. /**
  6327. * This file provides support to buildMathML.js and buildHTML.js
  6328. * for stretchy wide elements rendered from SVG files
  6329. * and other CSS trickery.
  6330. */
  6331. var stretchyCodePoint = {
  6332. widehat: "^",
  6333. widecheck: "ˇ",
  6334. widetilde: "~",
  6335. utilde: "~",
  6336. overleftarrow: "\u2190",
  6337. underleftarrow: "\u2190",
  6338. xleftarrow: "\u2190",
  6339. overrightarrow: "\u2192",
  6340. underrightarrow: "\u2192",
  6341. xrightarrow: "\u2192",
  6342. underbrace: "\u23df",
  6343. overbrace: "\u23de",
  6344. overgroup: "\u23e0",
  6345. undergroup: "\u23e1",
  6346. overleftrightarrow: "\u2194",
  6347. underleftrightarrow: "\u2194",
  6348. xleftrightarrow: "\u2194",
  6349. Overrightarrow: "\u21d2",
  6350. xRightarrow: "\u21d2",
  6351. overleftharpoon: "\u21bc",
  6352. xleftharpoonup: "\u21bc",
  6353. overrightharpoon: "\u21c0",
  6354. xrightharpoonup: "\u21c0",
  6355. xLeftarrow: "\u21d0",
  6356. xLeftrightarrow: "\u21d4",
  6357. xhookleftarrow: "\u21a9",
  6358. xhookrightarrow: "\u21aa",
  6359. xmapsto: "\u21a6",
  6360. xrightharpoondown: "\u21c1",
  6361. xleftharpoondown: "\u21bd",
  6362. xrightleftharpoons: "\u21cc",
  6363. xleftrightharpoons: "\u21cb",
  6364. xtwoheadleftarrow: "\u219e",
  6365. xtwoheadrightarrow: "\u21a0",
  6366. xlongequal: "=",
  6367. xtofrom: "\u21c4",
  6368. xrightleftarrows: "\u21c4",
  6369. xrightequilibrium: "\u21cc",
  6370. // Not a perfect match.
  6371. xleftequilibrium: "\u21cb",
  6372. // None better available.
  6373. "\\cdrightarrow": "\u2192",
  6374. "\\cdleftarrow": "\u2190",
  6375. "\\cdlongequal": "="
  6376. };
  6377. var mathMLnode = function mathMLnode(label) {
  6378. var node = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode(stretchyCodePoint[label.replace(/^\\/, '')])]);
  6379. node.setAttribute("stretchy", "true");
  6380. return node;
  6381. }; // Many of the KaTeX SVG images have been adapted from glyphs in KaTeX fonts.
  6382. // Copyright (c) 2009-2010, Design Science, Inc. (<www.mathjax.org>)
  6383. // Copyright (c) 2014-2017 Khan Academy (<www.khanacademy.org>)
  6384. // Licensed under the SIL Open Font License, Version 1.1.
  6385. // See \nhttp://scripts.sil.org/OFL
  6386. // Very Long SVGs
  6387. // Many of the KaTeX stretchy wide elements use a long SVG image and an
  6388. // overflow: hidden tactic to achieve a stretchy image while avoiding
  6389. // distortion of arrowheads or brace corners.
  6390. // The SVG typically contains a very long (400 em) arrow.
  6391. // The SVG is in a container span that has overflow: hidden, so the span
  6392. // acts like a window that exposes only part of the SVG.
  6393. // The SVG always has a longer, thinner aspect ratio than the container span.
  6394. // After the SVG fills 100% of the height of the container span,
  6395. // there is a long arrow shaft left over. That left-over shaft is not shown.
  6396. // Instead, it is sliced off because the span's CSS has overflow: hidden.
  6397. // Thus, the reader sees an arrow that matches the subject matter width
  6398. // without distortion.
  6399. // Some functions, such as \cancel, need to vary their aspect ratio. These
  6400. // functions do not get the overflow SVG treatment.
  6401. // Second Brush Stroke
  6402. // Low resolution monitors struggle to display images in fine detail.
  6403. // So browsers apply anti-aliasing. A long straight arrow shaft therefore
  6404. // will sometimes appear as if it has a blurred edge.
  6405. // To mitigate this, these SVG files contain a second "brush-stroke" on the
  6406. // arrow shafts. That is, a second long thin rectangular SVG path has been
  6407. // written directly on top of each arrow shaft. This reinforcement causes
  6408. // some of the screen pixels to display as black instead of the anti-aliased
  6409. // gray pixel that a single path would generate. So we get arrow shafts
  6410. // whose edges appear to be sharper.
  6411. // In the katexImagesData object just below, the dimensions all
  6412. // correspond to path geometry inside the relevant SVG.
  6413. // For example, \overrightarrow uses the same arrowhead as glyph U+2192
  6414. // from the KaTeX Main font. The scaling factor is 1000.
  6415. // That is, inside the font, that arrowhead is 522 units tall, which
  6416. // corresponds to 0.522 em inside the document.
  6417. var katexImagesData = {
  6418. // path(s), minWidth, height, align
  6419. overrightarrow: [["rightarrow"], 0.888, 522, "xMaxYMin"],
  6420. overleftarrow: [["leftarrow"], 0.888, 522, "xMinYMin"],
  6421. underrightarrow: [["rightarrow"], 0.888, 522, "xMaxYMin"],
  6422. underleftarrow: [["leftarrow"], 0.888, 522, "xMinYMin"],
  6423. xrightarrow: [["rightarrow"], 1.469, 522, "xMaxYMin"],
  6424. "\\cdrightarrow": [["rightarrow"], 3.0, 522, "xMaxYMin"],
  6425. // CD minwwidth2.5pc
  6426. xleftarrow: [["leftarrow"], 1.469, 522, "xMinYMin"],
  6427. "\\cdleftarrow": [["leftarrow"], 3.0, 522, "xMinYMin"],
  6428. Overrightarrow: [["doublerightarrow"], 0.888, 560, "xMaxYMin"],
  6429. xRightarrow: [["doublerightarrow"], 1.526, 560, "xMaxYMin"],
  6430. xLeftarrow: [["doubleleftarrow"], 1.526, 560, "xMinYMin"],
  6431. overleftharpoon: [["leftharpoon"], 0.888, 522, "xMinYMin"],
  6432. xleftharpoonup: [["leftharpoon"], 0.888, 522, "xMinYMin"],
  6433. xleftharpoondown: [["leftharpoondown"], 0.888, 522, "xMinYMin"],
  6434. overrightharpoon: [["rightharpoon"], 0.888, 522, "xMaxYMin"],
  6435. xrightharpoonup: [["rightharpoon"], 0.888, 522, "xMaxYMin"],
  6436. xrightharpoondown: [["rightharpoondown"], 0.888, 522, "xMaxYMin"],
  6437. xlongequal: [["longequal"], 0.888, 334, "xMinYMin"],
  6438. "\\cdlongequal": [["longequal"], 3.0, 334, "xMinYMin"],
  6439. xtwoheadleftarrow: [["twoheadleftarrow"], 0.888, 334, "xMinYMin"],
  6440. xtwoheadrightarrow: [["twoheadrightarrow"], 0.888, 334, "xMaxYMin"],
  6441. overleftrightarrow: [["leftarrow", "rightarrow"], 0.888, 522],
  6442. overbrace: [["leftbrace", "midbrace", "rightbrace"], 1.6, 548],
  6443. underbrace: [["leftbraceunder", "midbraceunder", "rightbraceunder"], 1.6, 548],
  6444. underleftrightarrow: [["leftarrow", "rightarrow"], 0.888, 522],
  6445. xleftrightarrow: [["leftarrow", "rightarrow"], 1.75, 522],
  6446. xLeftrightarrow: [["doubleleftarrow", "doublerightarrow"], 1.75, 560],
  6447. xrightleftharpoons: [["leftharpoondownplus", "rightharpoonplus"], 1.75, 716],
  6448. xleftrightharpoons: [["leftharpoonplus", "rightharpoondownplus"], 1.75, 716],
  6449. xhookleftarrow: [["leftarrow", "righthook"], 1.08, 522],
  6450. xhookrightarrow: [["lefthook", "rightarrow"], 1.08, 522],
  6451. overlinesegment: [["leftlinesegment", "rightlinesegment"], 0.888, 522],
  6452. underlinesegment: [["leftlinesegment", "rightlinesegment"], 0.888, 522],
  6453. overgroup: [["leftgroup", "rightgroup"], 0.888, 342],
  6454. undergroup: [["leftgroupunder", "rightgroupunder"], 0.888, 342],
  6455. xmapsto: [["leftmapsto", "rightarrow"], 1.5, 522],
  6456. xtofrom: [["leftToFrom", "rightToFrom"], 1.75, 528],
  6457. // The next three arrows are from the mhchem package.
  6458. // In mhchem.sty, min-length is 2.0em. But these arrows might appear in the
  6459. // document as \xrightarrow or \xrightleftharpoons. Those have
  6460. // min-length = 1.75em, so we set min-length on these next three to match.
  6461. xrightleftarrows: [["baraboveleftarrow", "rightarrowabovebar"], 1.75, 901],
  6462. xrightequilibrium: [["baraboveshortleftharpoon", "rightharpoonaboveshortbar"], 1.75, 716],
  6463. xleftequilibrium: [["shortbaraboveleftharpoon", "shortrightharpoonabovebar"], 1.75, 716]
  6464. };
  6465. var groupLength = function groupLength(arg) {
  6466. if (arg.type === "ordgroup") {
  6467. return arg.body.length;
  6468. } else {
  6469. return 1;
  6470. }
  6471. };
  6472. var svgSpan = function svgSpan(group, options) {
  6473. // Create a span with inline SVG for the element.
  6474. function buildSvgSpan_() {
  6475. var viewBoxWidth = 400000; // default
  6476. var label = group.label.substr(1);
  6477. if (utils.contains(["widehat", "widecheck", "widetilde", "utilde"], label)) {
  6478. // Each type in the `if` statement corresponds to one of the ParseNode
  6479. // types below. This narrowing is required to access `grp.base`.
  6480. // $FlowFixMe
  6481. var grp = group; // There are four SVG images available for each function.
  6482. // Choose a taller image when there are more characters.
  6483. var numChars = groupLength(grp.base);
  6484. var viewBoxHeight;
  6485. var pathName;
  6486. var _height;
  6487. if (numChars > 5) {
  6488. if (label === "widehat" || label === "widecheck") {
  6489. viewBoxHeight = 420;
  6490. viewBoxWidth = 2364;
  6491. _height = 0.42;
  6492. pathName = label + "4";
  6493. } else {
  6494. viewBoxHeight = 312;
  6495. viewBoxWidth = 2340;
  6496. _height = 0.34;
  6497. pathName = "tilde4";
  6498. }
  6499. } else {
  6500. var imgIndex = [1, 1, 2, 2, 3, 3][numChars];
  6501. if (label === "widehat" || label === "widecheck") {
  6502. viewBoxWidth = [0, 1062, 2364, 2364, 2364][imgIndex];
  6503. viewBoxHeight = [0, 239, 300, 360, 420][imgIndex];
  6504. _height = [0, 0.24, 0.3, 0.3, 0.36, 0.42][imgIndex];
  6505. pathName = label + imgIndex;
  6506. } else {
  6507. viewBoxWidth = [0, 600, 1033, 2339, 2340][imgIndex];
  6508. viewBoxHeight = [0, 260, 286, 306, 312][imgIndex];
  6509. _height = [0, 0.26, 0.286, 0.3, 0.306, 0.34][imgIndex];
  6510. pathName = "tilde" + imgIndex;
  6511. }
  6512. }
  6513. var path = new PathNode(pathName);
  6514. var svgNode = new SvgNode([path], {
  6515. "width": "100%",
  6516. "height": makeEm(_height),
  6517. "viewBox": "0 0 " + viewBoxWidth + " " + viewBoxHeight,
  6518. "preserveAspectRatio": "none"
  6519. });
  6520. return {
  6521. span: buildCommon.makeSvgSpan([], [svgNode], options),
  6522. minWidth: 0,
  6523. height: _height
  6524. };
  6525. } else {
  6526. var spans = [];
  6527. var data = katexImagesData[label];
  6528. var [paths, _minWidth, _viewBoxHeight] = data;
  6529. var _height2 = _viewBoxHeight / 1000;
  6530. var numSvgChildren = paths.length;
  6531. var widthClasses;
  6532. var aligns;
  6533. if (numSvgChildren === 1) {
  6534. // $FlowFixMe: All these cases must be of the 4-tuple type.
  6535. var align1 = data[3];
  6536. widthClasses = ["hide-tail"];
  6537. aligns = [align1];
  6538. } else if (numSvgChildren === 2) {
  6539. widthClasses = ["halfarrow-left", "halfarrow-right"];
  6540. aligns = ["xMinYMin", "xMaxYMin"];
  6541. } else if (numSvgChildren === 3) {
  6542. widthClasses = ["brace-left", "brace-center", "brace-right"];
  6543. aligns = ["xMinYMin", "xMidYMin", "xMaxYMin"];
  6544. } else {
  6545. throw new Error("Correct katexImagesData or update code here to support\n " + numSvgChildren + " children.");
  6546. }
  6547. for (var i = 0; i < numSvgChildren; i++) {
  6548. var _path = new PathNode(paths[i]);
  6549. var _svgNode = new SvgNode([_path], {
  6550. "width": "400em",
  6551. "height": makeEm(_height2),
  6552. "viewBox": "0 0 " + viewBoxWidth + " " + _viewBoxHeight,
  6553. "preserveAspectRatio": aligns[i] + " slice"
  6554. });
  6555. var _span = buildCommon.makeSvgSpan([widthClasses[i]], [_svgNode], options);
  6556. if (numSvgChildren === 1) {
  6557. return {
  6558. span: _span,
  6559. minWidth: _minWidth,
  6560. height: _height2
  6561. };
  6562. } else {
  6563. _span.style.height = makeEm(_height2);
  6564. spans.push(_span);
  6565. }
  6566. }
  6567. return {
  6568. span: buildCommon.makeSpan(["stretchy"], spans, options),
  6569. minWidth: _minWidth,
  6570. height: _height2
  6571. };
  6572. }
  6573. } // buildSvgSpan_()
  6574. var {
  6575. span,
  6576. minWidth,
  6577. height
  6578. } = buildSvgSpan_(); // Note that we are returning span.depth = 0.
  6579. // Any adjustments relative to the baseline must be done in buildHTML.
  6580. span.height = height;
  6581. span.style.height = makeEm(height);
  6582. if (minWidth > 0) {
  6583. span.style.minWidth = makeEm(minWidth);
  6584. }
  6585. return span;
  6586. };
  6587. var encloseSpan = function encloseSpan(inner, label, topPad, bottomPad, options) {
  6588. // Return an image span for \cancel, \bcancel, \xcancel, \fbox, or \angl
  6589. var img;
  6590. var totalHeight = inner.height + inner.depth + topPad + bottomPad;
  6591. if (/fbox|color|angl/.test(label)) {
  6592. img = buildCommon.makeSpan(["stretchy", label], [], options);
  6593. if (label === "fbox") {
  6594. var color = options.color && options.getColor();
  6595. if (color) {
  6596. img.style.borderColor = color;
  6597. }
  6598. }
  6599. } else {
  6600. // \cancel, \bcancel, or \xcancel
  6601. // Since \cancel's SVG is inline and it omits the viewBox attribute,
  6602. // its stroke-width will not vary with span area.
  6603. var lines = [];
  6604. if (/^[bx]cancel$/.test(label)) {
  6605. lines.push(new LineNode({
  6606. "x1": "0",
  6607. "y1": "0",
  6608. "x2": "100%",
  6609. "y2": "100%",
  6610. "stroke-width": "0.046em"
  6611. }));
  6612. }
  6613. if (/^x?cancel$/.test(label)) {
  6614. lines.push(new LineNode({
  6615. "x1": "0",
  6616. "y1": "100%",
  6617. "x2": "100%",
  6618. "y2": "0",
  6619. "stroke-width": "0.046em"
  6620. }));
  6621. }
  6622. var svgNode = new SvgNode(lines, {
  6623. "width": "100%",
  6624. "height": makeEm(totalHeight)
  6625. });
  6626. img = buildCommon.makeSvgSpan([], [svgNode], options);
  6627. }
  6628. img.height = totalHeight;
  6629. img.style.height = makeEm(totalHeight);
  6630. return img;
  6631. };
  6632. var stretchy = {
  6633. encloseSpan,
  6634. mathMLnode,
  6635. svgSpan
  6636. };
  6637. /**
  6638. * Asserts that the node is of the given type and returns it with stricter
  6639. * typing. Throws if the node's type does not match.
  6640. */
  6641. function assertNodeType(node, type) {
  6642. if (!node || node.type !== type) {
  6643. throw new Error("Expected node of type " + type + ", but got " + (node ? "node of type " + node.type : String(node)));
  6644. } // $FlowFixMe, >=0.125
  6645. return node;
  6646. }
  6647. /**
  6648. * Returns the node more strictly typed iff it is of the given type. Otherwise,
  6649. * returns null.
  6650. */
  6651. function assertSymbolNodeType(node) {
  6652. var typedNode = checkSymbolNodeType(node);
  6653. if (!typedNode) {
  6654. throw new Error("Expected node of symbol group type, but got " + (node ? "node of type " + node.type : String(node)));
  6655. }
  6656. return typedNode;
  6657. }
  6658. /**
  6659. * Returns the node more strictly typed iff it is of the given type. Otherwise,
  6660. * returns null.
  6661. */
  6662. function checkSymbolNodeType(node) {
  6663. if (node && (node.type === "atom" || NON_ATOMS.hasOwnProperty(node.type))) {
  6664. // $FlowFixMe
  6665. return node;
  6666. }
  6667. return null;
  6668. }
  6669. // NOTE: Unlike most `htmlBuilder`s, this one handles not only "accent", but
  6670. // also "supsub" since an accent can affect super/subscripting.
  6671. var htmlBuilder$a = (grp, options) => {
  6672. // Accents are handled in the TeXbook pg. 443, rule 12.
  6673. var base;
  6674. var group;
  6675. var supSubGroup;
  6676. if (grp && grp.type === "supsub") {
  6677. // If our base is a character box, and we have superscripts and
  6678. // subscripts, the supsub will defer to us. In particular, we want
  6679. // to attach the superscripts and subscripts to the inner body (so
  6680. // that the position of the superscripts and subscripts won't be
  6681. // affected by the height of the accent). We accomplish this by
  6682. // sticking the base of the accent into the base of the supsub, and
  6683. // rendering that, while keeping track of where the accent is.
  6684. // The real accent group is the base of the supsub group
  6685. group = assertNodeType(grp.base, "accent"); // The character box is the base of the accent group
  6686. base = group.base; // Stick the character box into the base of the supsub group
  6687. grp.base = base; // Rerender the supsub group with its new base, and store that
  6688. // result.
  6689. supSubGroup = assertSpan(buildGroup$1(grp, options)); // reset original base
  6690. grp.base = group;
  6691. } else {
  6692. group = assertNodeType(grp, "accent");
  6693. base = group.base;
  6694. } // Build the base group
  6695. var body = buildGroup$1(base, options.havingCrampedStyle()); // Does the accent need to shift for the skew of a character?
  6696. var mustShift = group.isShifty && utils.isCharacterBox(base); // Calculate the skew of the accent. This is based on the line "If the
  6697. // nucleus is not a single character, let s = 0; otherwise set s to the
  6698. // kern amount for the nucleus followed by the \skewchar of its font."
  6699. // Note that our skew metrics are just the kern between each character
  6700. // and the skewchar.
  6701. var skew = 0;
  6702. if (mustShift) {
  6703. // If the base is a character box, then we want the skew of the
  6704. // innermost character. To do that, we find the innermost character:
  6705. var baseChar = utils.getBaseElem(base); // Then, we render its group to get the symbol inside it
  6706. var baseGroup = buildGroup$1(baseChar, options.havingCrampedStyle()); // Finally, we pull the skew off of the symbol.
  6707. skew = assertSymbolDomNode(baseGroup).skew; // Note that we now throw away baseGroup, because the layers we
  6708. // removed with getBaseElem might contain things like \color which
  6709. // we can't get rid of.
  6710. // TODO(emily): Find a better way to get the skew
  6711. }
  6712. var accentBelow = group.label === "\\c"; // calculate the amount of space between the body and the accent
  6713. var clearance = accentBelow ? body.height + body.depth : Math.min(body.height, options.fontMetrics().xHeight); // Build the accent
  6714. var accentBody;
  6715. if (!group.isStretchy) {
  6716. var accent;
  6717. var width;
  6718. if (group.label === "\\vec") {
  6719. // Before version 0.9, \vec used the combining font glyph U+20D7.
  6720. // But browsers, especially Safari, are not consistent in how they
  6721. // render combining characters when not preceded by a character.
  6722. // So now we use an SVG.
  6723. // If Safari reforms, we should consider reverting to the glyph.
  6724. accent = buildCommon.staticSvg("vec", options);
  6725. width = buildCommon.svgData.vec[1];
  6726. } else {
  6727. accent = buildCommon.makeOrd({
  6728. mode: group.mode,
  6729. text: group.label
  6730. }, options, "textord");
  6731. accent = assertSymbolDomNode(accent); // Remove the italic correction of the accent, because it only serves to
  6732. // shift the accent over to a place we don't want.
  6733. accent.italic = 0;
  6734. width = accent.width;
  6735. if (accentBelow) {
  6736. clearance += accent.depth;
  6737. }
  6738. }
  6739. accentBody = buildCommon.makeSpan(["accent-body"], [accent]); // "Full" accents expand the width of the resulting symbol to be
  6740. // at least the width of the accent, and overlap directly onto the
  6741. // character without any vertical offset.
  6742. var accentFull = group.label === "\\textcircled";
  6743. if (accentFull) {
  6744. accentBody.classes.push('accent-full');
  6745. clearance = body.height;
  6746. } // Shift the accent over by the skew.
  6747. var left = skew; // CSS defines `.katex .accent .accent-body:not(.accent-full) { width: 0 }`
  6748. // so that the accent doesn't contribute to the bounding box.
  6749. // We need to shift the character by its width (effectively half
  6750. // its width) to compensate.
  6751. if (!accentFull) {
  6752. left -= width / 2;
  6753. }
  6754. accentBody.style.left = makeEm(left); // \textcircled uses the \bigcirc glyph, so it needs some
  6755. // vertical adjustment to match LaTeX.
  6756. if (group.label === "\\textcircled") {
  6757. accentBody.style.top = ".2em";
  6758. }
  6759. accentBody = buildCommon.makeVList({
  6760. positionType: "firstBaseline",
  6761. children: [{
  6762. type: "elem",
  6763. elem: body
  6764. }, {
  6765. type: "kern",
  6766. size: -clearance
  6767. }, {
  6768. type: "elem",
  6769. elem: accentBody
  6770. }]
  6771. }, options);
  6772. } else {
  6773. accentBody = stretchy.svgSpan(group, options);
  6774. accentBody = buildCommon.makeVList({
  6775. positionType: "firstBaseline",
  6776. children: [{
  6777. type: "elem",
  6778. elem: body
  6779. }, {
  6780. type: "elem",
  6781. elem: accentBody,
  6782. wrapperClasses: ["svg-align"],
  6783. wrapperStyle: skew > 0 ? {
  6784. width: "calc(100% - " + makeEm(2 * skew) + ")",
  6785. marginLeft: makeEm(2 * skew)
  6786. } : undefined
  6787. }]
  6788. }, options);
  6789. }
  6790. var accentWrap = buildCommon.makeSpan(["mord", "accent"], [accentBody], options);
  6791. if (supSubGroup) {
  6792. // Here, we replace the "base" child of the supsub with our newly
  6793. // generated accent.
  6794. supSubGroup.children[0] = accentWrap; // Since we don't rerun the height calculation after replacing the
  6795. // accent, we manually recalculate height.
  6796. supSubGroup.height = Math.max(accentWrap.height, supSubGroup.height); // Accents should always be ords, even when their innards are not.
  6797. supSubGroup.classes[0] = "mord";
  6798. return supSubGroup;
  6799. } else {
  6800. return accentWrap;
  6801. }
  6802. };
  6803. var mathmlBuilder$9 = (group, options) => {
  6804. var accentNode = group.isStretchy ? stretchy.mathMLnode(group.label) : new mathMLTree.MathNode("mo", [makeText(group.label, group.mode)]);
  6805. var node = new mathMLTree.MathNode("mover", [buildGroup(group.base, options), accentNode]);
  6806. node.setAttribute("accent", "true");
  6807. return node;
  6808. };
  6809. var NON_STRETCHY_ACCENT_REGEX = new RegExp(["\\acute", "\\grave", "\\ddot", "\\tilde", "\\bar", "\\breve", "\\check", "\\hat", "\\vec", "\\dot", "\\mathring"].map(accent => "\\" + accent).join("|")); // Accents
  6810. defineFunction({
  6811. type: "accent",
  6812. names: ["\\acute", "\\grave", "\\ddot", "\\tilde", "\\bar", "\\breve", "\\check", "\\hat", "\\vec", "\\dot", "\\mathring", "\\widecheck", "\\widehat", "\\widetilde", "\\overrightarrow", "\\overleftarrow", "\\Overrightarrow", "\\overleftrightarrow", "\\overgroup", "\\overlinesegment", "\\overleftharpoon", "\\overrightharpoon"],
  6813. props: {
  6814. numArgs: 1
  6815. },
  6816. handler: (context, args) => {
  6817. var base = normalizeArgument(args[0]);
  6818. var isStretchy = !NON_STRETCHY_ACCENT_REGEX.test(context.funcName);
  6819. var isShifty = !isStretchy || context.funcName === "\\widehat" || context.funcName === "\\widetilde" || context.funcName === "\\widecheck";
  6820. return {
  6821. type: "accent",
  6822. mode: context.parser.mode,
  6823. label: context.funcName,
  6824. isStretchy: isStretchy,
  6825. isShifty: isShifty,
  6826. base: base
  6827. };
  6828. },
  6829. htmlBuilder: htmlBuilder$a,
  6830. mathmlBuilder: mathmlBuilder$9
  6831. }); // Text-mode accents
  6832. defineFunction({
  6833. type: "accent",
  6834. names: ["\\'", "\\`", "\\^", "\\~", "\\=", "\\u", "\\.", '\\"', "\\c", "\\r", "\\H", "\\v", "\\textcircled"],
  6835. props: {
  6836. numArgs: 1,
  6837. allowedInText: true,
  6838. allowedInMath: true,
  6839. // unless in strict mode
  6840. argTypes: ["primitive"]
  6841. },
  6842. handler: (context, args) => {
  6843. var base = args[0];
  6844. var mode = context.parser.mode;
  6845. if (mode === "math") {
  6846. context.parser.settings.reportNonstrict("mathVsTextAccents", "LaTeX's accent " + context.funcName + " works only in text mode");
  6847. mode = "text";
  6848. }
  6849. return {
  6850. type: "accent",
  6851. mode: mode,
  6852. label: context.funcName,
  6853. isStretchy: false,
  6854. isShifty: true,
  6855. base: base
  6856. };
  6857. },
  6858. htmlBuilder: htmlBuilder$a,
  6859. mathmlBuilder: mathmlBuilder$9
  6860. });
  6861. // Horizontal overlap functions
  6862. defineFunction({
  6863. type: "accentUnder",
  6864. names: ["\\underleftarrow", "\\underrightarrow", "\\underleftrightarrow", "\\undergroup", "\\underlinesegment", "\\utilde"],
  6865. props: {
  6866. numArgs: 1
  6867. },
  6868. handler: (_ref, args) => {
  6869. var {
  6870. parser,
  6871. funcName
  6872. } = _ref;
  6873. var base = args[0];
  6874. return {
  6875. type: "accentUnder",
  6876. mode: parser.mode,
  6877. label: funcName,
  6878. base: base
  6879. };
  6880. },
  6881. htmlBuilder: (group, options) => {
  6882. // Treat under accents much like underlines.
  6883. var innerGroup = buildGroup$1(group.base, options);
  6884. var accentBody = stretchy.svgSpan(group, options);
  6885. var kern = group.label === "\\utilde" ? 0.12 : 0; // Generate the vlist, with the appropriate kerns
  6886. var vlist = buildCommon.makeVList({
  6887. positionType: "top",
  6888. positionData: innerGroup.height,
  6889. children: [{
  6890. type: "elem",
  6891. elem: accentBody,
  6892. wrapperClasses: ["svg-align"]
  6893. }, {
  6894. type: "kern",
  6895. size: kern
  6896. }, {
  6897. type: "elem",
  6898. elem: innerGroup
  6899. }]
  6900. }, options);
  6901. return buildCommon.makeSpan(["mord", "accentunder"], [vlist], options);
  6902. },
  6903. mathmlBuilder: (group, options) => {
  6904. var accentNode = stretchy.mathMLnode(group.label);
  6905. var node = new mathMLTree.MathNode("munder", [buildGroup(group.base, options), accentNode]);
  6906. node.setAttribute("accentunder", "true");
  6907. return node;
  6908. }
  6909. });
  6910. // Helper function
  6911. var paddedNode = group => {
  6912. var node = new mathMLTree.MathNode("mpadded", group ? [group] : []);
  6913. node.setAttribute("width", "+0.6em");
  6914. node.setAttribute("lspace", "0.3em");
  6915. return node;
  6916. }; // Stretchy arrows with an optional argument
  6917. defineFunction({
  6918. type: "xArrow",
  6919. names: ["\\xleftarrow", "\\xrightarrow", "\\xLeftarrow", "\\xRightarrow", "\\xleftrightarrow", "\\xLeftrightarrow", "\\xhookleftarrow", "\\xhookrightarrow", "\\xmapsto", "\\xrightharpoondown", "\\xrightharpoonup", "\\xleftharpoondown", "\\xleftharpoonup", "\\xrightleftharpoons", "\\xleftrightharpoons", "\\xlongequal", "\\xtwoheadrightarrow", "\\xtwoheadleftarrow", "\\xtofrom", // The next 3 functions are here to support the mhchem extension.
  6920. // Direct use of these functions is discouraged and may break someday.
  6921. "\\xrightleftarrows", "\\xrightequilibrium", "\\xleftequilibrium", // The next 3 functions are here only to support the {CD} environment.
  6922. "\\\\cdrightarrow", "\\\\cdleftarrow", "\\\\cdlongequal"],
  6923. props: {
  6924. numArgs: 1,
  6925. numOptionalArgs: 1
  6926. },
  6927. handler(_ref, args, optArgs) {
  6928. var {
  6929. parser,
  6930. funcName
  6931. } = _ref;
  6932. return {
  6933. type: "xArrow",
  6934. mode: parser.mode,
  6935. label: funcName,
  6936. body: args[0],
  6937. below: optArgs[0]
  6938. };
  6939. },
  6940. // Flow is unable to correctly infer the type of `group`, even though it's
  6941. // unamibiguously determined from the passed-in `type` above.
  6942. htmlBuilder(group, options) {
  6943. var style = options.style; // Build the argument groups in the appropriate style.
  6944. // Ref: amsmath.dtx: \hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}%
  6945. // Some groups can return document fragments. Handle those by wrapping
  6946. // them in a span.
  6947. var newOptions = options.havingStyle(style.sup());
  6948. var upperGroup = buildCommon.wrapFragment(buildGroup$1(group.body, newOptions, options), options);
  6949. var arrowPrefix = group.label.slice(0, 2) === "\\x" ? "x" : "cd";
  6950. upperGroup.classes.push(arrowPrefix + "-arrow-pad");
  6951. var lowerGroup;
  6952. if (group.below) {
  6953. // Build the lower group
  6954. newOptions = options.havingStyle(style.sub());
  6955. lowerGroup = buildCommon.wrapFragment(buildGroup$1(group.below, newOptions, options), options);
  6956. lowerGroup.classes.push(arrowPrefix + "-arrow-pad");
  6957. }
  6958. var arrowBody = stretchy.svgSpan(group, options); // Re shift: Note that stretchy.svgSpan returned arrowBody.depth = 0.
  6959. // The point we want on the math axis is at 0.5 * arrowBody.height.
  6960. var arrowShift = -options.fontMetrics().axisHeight + 0.5 * arrowBody.height; // 2 mu kern. Ref: amsmath.dtx: #7\if0#2\else\mkern#2mu\fi
  6961. var upperShift = -options.fontMetrics().axisHeight - 0.5 * arrowBody.height - 0.111; // 0.111 em = 2 mu
  6962. if (upperGroup.depth > 0.25 || group.label === "\\xleftequilibrium") {
  6963. upperShift -= upperGroup.depth; // shift up if depth encroaches
  6964. } // Generate the vlist
  6965. var vlist;
  6966. if (lowerGroup) {
  6967. var lowerShift = -options.fontMetrics().axisHeight + lowerGroup.height + 0.5 * arrowBody.height + 0.111;
  6968. vlist = buildCommon.makeVList({
  6969. positionType: "individualShift",
  6970. children: [{
  6971. type: "elem",
  6972. elem: upperGroup,
  6973. shift: upperShift
  6974. }, {
  6975. type: "elem",
  6976. elem: arrowBody,
  6977. shift: arrowShift
  6978. }, {
  6979. type: "elem",
  6980. elem: lowerGroup,
  6981. shift: lowerShift
  6982. }]
  6983. }, options);
  6984. } else {
  6985. vlist = buildCommon.makeVList({
  6986. positionType: "individualShift",
  6987. children: [{
  6988. type: "elem",
  6989. elem: upperGroup,
  6990. shift: upperShift
  6991. }, {
  6992. type: "elem",
  6993. elem: arrowBody,
  6994. shift: arrowShift
  6995. }]
  6996. }, options);
  6997. } // $FlowFixMe: Replace this with passing "svg-align" into makeVList.
  6998. vlist.children[0].children[0].children[1].classes.push("svg-align");
  6999. return buildCommon.makeSpan(["mrel", "x-arrow"], [vlist], options);
  7000. },
  7001. mathmlBuilder(group, options) {
  7002. var arrowNode = stretchy.mathMLnode(group.label);
  7003. arrowNode.setAttribute("minsize", group.label.charAt(0) === "x" ? "1.75em" : "3.0em");
  7004. var node;
  7005. if (group.body) {
  7006. var upperNode = paddedNode(buildGroup(group.body, options));
  7007. if (group.below) {
  7008. var lowerNode = paddedNode(buildGroup(group.below, options));
  7009. node = new mathMLTree.MathNode("munderover", [arrowNode, lowerNode, upperNode]);
  7010. } else {
  7011. node = new mathMLTree.MathNode("mover", [arrowNode, upperNode]);
  7012. }
  7013. } else if (group.below) {
  7014. var _lowerNode = paddedNode(buildGroup(group.below, options));
  7015. node = new mathMLTree.MathNode("munder", [arrowNode, _lowerNode]);
  7016. } else {
  7017. // This should never happen.
  7018. // Parser.js throws an error if there is no argument.
  7019. node = paddedNode();
  7020. node = new mathMLTree.MathNode("mover", [arrowNode, node]);
  7021. }
  7022. return node;
  7023. }
  7024. });
  7025. var cdArrowFunctionName = {
  7026. ">": "\\\\cdrightarrow",
  7027. "<": "\\\\cdleftarrow",
  7028. "=": "\\\\cdlongequal",
  7029. "A": "\\uparrow",
  7030. "V": "\\downarrow",
  7031. "|": "\\Vert",
  7032. ".": "no arrow"
  7033. };
  7034. var newCell = () => {
  7035. // Create an empty cell, to be filled below with parse nodes.
  7036. // The parseTree from this module must be constructed like the
  7037. // one created by parseArray(), so an empty CD cell must
  7038. // be a ParseNode<"styling">. And CD is always displaystyle.
  7039. // So these values are fixed and flow can do implicit typing.
  7040. return {
  7041. type: "styling",
  7042. body: [],
  7043. mode: "math",
  7044. style: "display"
  7045. };
  7046. };
  7047. var isStartOfArrow = node => {
  7048. return node.type === "textord" && node.text === "@";
  7049. };
  7050. var isLabelEnd = (node, endChar) => {
  7051. return (node.type === "mathord" || node.type === "atom") && node.text === endChar;
  7052. };
  7053. function cdArrow(arrowChar, labels, parser) {
  7054. // Return a parse tree of an arrow and its labels.
  7055. // This acts in a way similar to a macro expansion.
  7056. var funcName = cdArrowFunctionName[arrowChar];
  7057. switch (funcName) {
  7058. case "\\\\cdrightarrow":
  7059. case "\\\\cdleftarrow":
  7060. return parser.callFunction(funcName, [labels[0]], [labels[1]]);
  7061. case "\\uparrow":
  7062. case "\\downarrow":
  7063. {
  7064. var leftLabel = parser.callFunction("\\\\cdleft", [labels[0]], []);
  7065. var bareArrow = {
  7066. type: "atom",
  7067. text: funcName,
  7068. mode: "math",
  7069. family: "rel"
  7070. };
  7071. var sizedArrow = parser.callFunction("\\Big", [bareArrow], []);
  7072. var rightLabel = parser.callFunction("\\\\cdright", [labels[1]], []);
  7073. var arrowGroup = {
  7074. type: "ordgroup",
  7075. mode: "math",
  7076. body: [leftLabel, sizedArrow, rightLabel]
  7077. };
  7078. return parser.callFunction("\\\\cdparent", [arrowGroup], []);
  7079. }
  7080. case "\\\\cdlongequal":
  7081. return parser.callFunction("\\\\cdlongequal", [], []);
  7082. case "\\Vert":
  7083. {
  7084. var arrow = {
  7085. type: "textord",
  7086. text: "\\Vert",
  7087. mode: "math"
  7088. };
  7089. return parser.callFunction("\\Big", [arrow], []);
  7090. }
  7091. default:
  7092. return {
  7093. type: "textord",
  7094. text: " ",
  7095. mode: "math"
  7096. };
  7097. }
  7098. }
  7099. function parseCD(parser) {
  7100. // Get the array's parse nodes with \\ temporarily mapped to \cr.
  7101. var parsedRows = [];
  7102. parser.gullet.beginGroup();
  7103. parser.gullet.macros.set("\\cr", "\\\\\\relax");
  7104. parser.gullet.beginGroup();
  7105. while (true) {
  7106. // eslint-disable-line no-constant-condition
  7107. // Get the parse nodes for the next row.
  7108. parsedRows.push(parser.parseExpression(false, "\\\\"));
  7109. parser.gullet.endGroup();
  7110. parser.gullet.beginGroup();
  7111. var next = parser.fetch().text;
  7112. if (next === "&" || next === "\\\\") {
  7113. parser.consume();
  7114. } else if (next === "\\end") {
  7115. if (parsedRows[parsedRows.length - 1].length === 0) {
  7116. parsedRows.pop(); // final row ended in \\
  7117. }
  7118. break;
  7119. } else {
  7120. throw new ParseError("Expected \\\\ or \\cr or \\end", parser.nextToken);
  7121. }
  7122. }
  7123. var row = [];
  7124. var body = [row]; // Loop thru the parse nodes. Collect them into cells and arrows.
  7125. for (var i = 0; i < parsedRows.length; i++) {
  7126. // Start a new row.
  7127. var rowNodes = parsedRows[i]; // Create the first cell.
  7128. var cell = newCell();
  7129. for (var j = 0; j < rowNodes.length; j++) {
  7130. if (!isStartOfArrow(rowNodes[j])) {
  7131. // If a parseNode is not an arrow, it goes into a cell.
  7132. cell.body.push(rowNodes[j]);
  7133. } else {
  7134. // Parse node j is an "@", the start of an arrow.
  7135. // Before starting on the arrow, push the cell into `row`.
  7136. row.push(cell); // Now collect parseNodes into an arrow.
  7137. // The character after "@" defines the arrow type.
  7138. j += 1;
  7139. var arrowChar = assertSymbolNodeType(rowNodes[j]).text; // Create two empty label nodes. We may or may not use them.
  7140. var labels = new Array(2);
  7141. labels[0] = {
  7142. type: "ordgroup",
  7143. mode: "math",
  7144. body: []
  7145. };
  7146. labels[1] = {
  7147. type: "ordgroup",
  7148. mode: "math",
  7149. body: []
  7150. }; // Process the arrow.
  7151. if ("=|.".indexOf(arrowChar) > -1) ; else if ("<>AV".indexOf(arrowChar) > -1) {
  7152. // Four arrows, `@>>>`, `@<<<`, `@AAA`, and `@VVV`, each take
  7153. // two optional labels. E.g. the right-point arrow syntax is
  7154. // really: @>{optional label}>{optional label}>
  7155. // Collect parseNodes into labels.
  7156. for (var labelNum = 0; labelNum < 2; labelNum++) {
  7157. var inLabel = true;
  7158. for (var k = j + 1; k < rowNodes.length; k++) {
  7159. if (isLabelEnd(rowNodes[k], arrowChar)) {
  7160. inLabel = false;
  7161. j = k;
  7162. break;
  7163. }
  7164. if (isStartOfArrow(rowNodes[k])) {
  7165. throw new ParseError("Missing a " + arrowChar + " character to complete a CD arrow.", rowNodes[k]);
  7166. }
  7167. labels[labelNum].body.push(rowNodes[k]);
  7168. }
  7169. if (inLabel) {
  7170. // isLabelEnd never returned a true.
  7171. throw new ParseError("Missing a " + arrowChar + " character to complete a CD arrow.", rowNodes[j]);
  7172. }
  7173. }
  7174. } else {
  7175. throw new ParseError("Expected one of \"<>AV=|.\" after @", rowNodes[j]);
  7176. } // Now join the arrow to its labels.
  7177. var arrow = cdArrow(arrowChar, labels, parser); // Wrap the arrow in ParseNode<"styling">.
  7178. // This is done to match parseArray() behavior.
  7179. var wrappedArrow = {
  7180. type: "styling",
  7181. body: [arrow],
  7182. mode: "math",
  7183. style: "display" // CD is always displaystyle.
  7184. };
  7185. row.push(wrappedArrow); // In CD's syntax, cells are implicit. That is, everything that
  7186. // is not an arrow gets collected into a cell. So create an empty
  7187. // cell now. It will collect upcoming parseNodes.
  7188. cell = newCell();
  7189. }
  7190. }
  7191. if (i % 2 === 0) {
  7192. // Even-numbered rows consist of: cell, arrow, cell, arrow, ... cell
  7193. // The last cell is not yet pushed into `row`, so:
  7194. row.push(cell);
  7195. } else {
  7196. // Odd-numbered rows consist of: vert arrow, empty cell, ... vert arrow
  7197. // Remove the empty cell that was placed at the beginning of `row`.
  7198. row.shift();
  7199. }
  7200. row = [];
  7201. body.push(row);
  7202. } // End row group
  7203. parser.gullet.endGroup(); // End array group defining \\
  7204. parser.gullet.endGroup(); // define column separation.
  7205. var cols = new Array(body[0].length).fill({
  7206. type: "align",
  7207. align: "c",
  7208. pregap: 0.25,
  7209. // CD package sets \enskip between columns.
  7210. postgap: 0.25 // So pre and post each get half an \enskip, i.e. 0.25em.
  7211. });
  7212. return {
  7213. type: "array",
  7214. mode: "math",
  7215. body,
  7216. arraystretch: 1,
  7217. addJot: true,
  7218. rowGaps: [null],
  7219. cols,
  7220. colSeparationType: "CD",
  7221. hLinesBeforeRow: new Array(body.length + 1).fill([])
  7222. };
  7223. } // The functions below are not available for general use.
  7224. // They are here only for internal use by the {CD} environment in placing labels
  7225. // next to vertical arrows.
  7226. // We don't need any such functions for horizontal arrows because we can reuse
  7227. // the functionality that already exists for extensible arrows.
  7228. defineFunction({
  7229. type: "cdlabel",
  7230. names: ["\\\\cdleft", "\\\\cdright"],
  7231. props: {
  7232. numArgs: 1
  7233. },
  7234. handler(_ref, args) {
  7235. var {
  7236. parser,
  7237. funcName
  7238. } = _ref;
  7239. return {
  7240. type: "cdlabel",
  7241. mode: parser.mode,
  7242. side: funcName.slice(4),
  7243. label: args[0]
  7244. };
  7245. },
  7246. htmlBuilder(group, options) {
  7247. var newOptions = options.havingStyle(options.style.sup());
  7248. var label = buildCommon.wrapFragment(buildGroup$1(group.label, newOptions, options), options);
  7249. label.classes.push("cd-label-" + group.side);
  7250. label.style.bottom = makeEm(0.8 - label.depth); // Zero out label height & depth, so vertical align of arrow is set
  7251. // by the arrow height, not by the label.
  7252. label.height = 0;
  7253. label.depth = 0;
  7254. return label;
  7255. },
  7256. mathmlBuilder(group, options) {
  7257. var label = new mathMLTree.MathNode("mrow", [buildGroup(group.label, options)]);
  7258. label = new mathMLTree.MathNode("mpadded", [label]);
  7259. label.setAttribute("width", "0");
  7260. if (group.side === "left") {
  7261. label.setAttribute("lspace", "-1width");
  7262. } // We have to guess at vertical alignment. We know the arrow is 1.8em tall,
  7263. // But we don't know the height or depth of the label.
  7264. label.setAttribute("voffset", "0.7em");
  7265. label = new mathMLTree.MathNode("mstyle", [label]);
  7266. label.setAttribute("displaystyle", "false");
  7267. label.setAttribute("scriptlevel", "1");
  7268. return label;
  7269. }
  7270. });
  7271. defineFunction({
  7272. type: "cdlabelparent",
  7273. names: ["\\\\cdparent"],
  7274. props: {
  7275. numArgs: 1
  7276. },
  7277. handler(_ref2, args) {
  7278. var {
  7279. parser
  7280. } = _ref2;
  7281. return {
  7282. type: "cdlabelparent",
  7283. mode: parser.mode,
  7284. fragment: args[0]
  7285. };
  7286. },
  7287. htmlBuilder(group, options) {
  7288. // Wrap the vertical arrow and its labels.
  7289. // The parent gets position: relative. The child gets position: absolute.
  7290. // So CSS can locate the label correctly.
  7291. var parent = buildCommon.wrapFragment(buildGroup$1(group.fragment, options), options);
  7292. parent.classes.push("cd-vert-arrow");
  7293. return parent;
  7294. },
  7295. mathmlBuilder(group, options) {
  7296. return new mathMLTree.MathNode("mrow", [buildGroup(group.fragment, options)]);
  7297. }
  7298. });
  7299. // {123} and converts into symbol with code 123. It is used by the *macro*
  7300. // \char defined in macros.js.
  7301. defineFunction({
  7302. type: "textord",
  7303. names: ["\\@char"],
  7304. props: {
  7305. numArgs: 1,
  7306. allowedInText: true
  7307. },
  7308. handler(_ref, args) {
  7309. var {
  7310. parser
  7311. } = _ref;
  7312. var arg = assertNodeType(args[0], "ordgroup");
  7313. var group = arg.body;
  7314. var number = "";
  7315. for (var i = 0; i < group.length; i++) {
  7316. var node = assertNodeType(group[i], "textord");
  7317. number += node.text;
  7318. }
  7319. var code = parseInt(number);
  7320. var text;
  7321. if (isNaN(code)) {
  7322. throw new ParseError("\\@char has non-numeric argument " + number); // If we drop IE support, the following code could be replaced with
  7323. // text = String.fromCodePoint(code)
  7324. } else if (code < 0 || code >= 0x10ffff) {
  7325. throw new ParseError("\\@char with invalid code point " + number);
  7326. } else if (code <= 0xffff) {
  7327. text = String.fromCharCode(code);
  7328. } else {
  7329. // Astral code point; split into surrogate halves
  7330. code -= 0x10000;
  7331. text = String.fromCharCode((code >> 10) + 0xd800, (code & 0x3ff) + 0xdc00);
  7332. }
  7333. return {
  7334. type: "textord",
  7335. mode: parser.mode,
  7336. text: text
  7337. };
  7338. }
  7339. });
  7340. var htmlBuilder$9 = (group, options) => {
  7341. var elements = buildExpression$1(group.body, options.withColor(group.color), false); // \color isn't supposed to affect the type of the elements it contains.
  7342. // To accomplish this, we wrap the results in a fragment, so the inner
  7343. // elements will be able to directly interact with their neighbors. For
  7344. // example, `\color{red}{2 +} 3` has the same spacing as `2 + 3`
  7345. return buildCommon.makeFragment(elements);
  7346. };
  7347. var mathmlBuilder$8 = (group, options) => {
  7348. var inner = buildExpression(group.body, options.withColor(group.color));
  7349. var node = new mathMLTree.MathNode("mstyle", inner);
  7350. node.setAttribute("mathcolor", group.color);
  7351. return node;
  7352. };
  7353. defineFunction({
  7354. type: "color",
  7355. names: ["\\textcolor"],
  7356. props: {
  7357. numArgs: 2,
  7358. allowedInText: true,
  7359. argTypes: ["color", "original"]
  7360. },
  7361. handler(_ref, args) {
  7362. var {
  7363. parser
  7364. } = _ref;
  7365. var color = assertNodeType(args[0], "color-token").color;
  7366. var body = args[1];
  7367. return {
  7368. type: "color",
  7369. mode: parser.mode,
  7370. color,
  7371. body: ordargument(body)
  7372. };
  7373. },
  7374. htmlBuilder: htmlBuilder$9,
  7375. mathmlBuilder: mathmlBuilder$8
  7376. });
  7377. defineFunction({
  7378. type: "color",
  7379. names: ["\\color"],
  7380. props: {
  7381. numArgs: 1,
  7382. allowedInText: true,
  7383. argTypes: ["color"]
  7384. },
  7385. handler(_ref2, args) {
  7386. var {
  7387. parser,
  7388. breakOnTokenText
  7389. } = _ref2;
  7390. var color = assertNodeType(args[0], "color-token").color; // Set macro \current@color in current namespace to store the current
  7391. // color, mimicking the behavior of color.sty.
  7392. // This is currently used just to correctly color a \right
  7393. // that follows a \color command.
  7394. parser.gullet.macros.set("\\current@color", color); // Parse out the implicit body that should be colored.
  7395. var body = parser.parseExpression(true, breakOnTokenText);
  7396. return {
  7397. type: "color",
  7398. mode: parser.mode,
  7399. color,
  7400. body
  7401. };
  7402. },
  7403. htmlBuilder: htmlBuilder$9,
  7404. mathmlBuilder: mathmlBuilder$8
  7405. });
  7406. // Row breaks within tabular environments, and line breaks at top level
  7407. defineFunction({
  7408. type: "cr",
  7409. names: ["\\\\"],
  7410. props: {
  7411. numArgs: 0,
  7412. numOptionalArgs: 1,
  7413. argTypes: ["size"],
  7414. allowedInText: true
  7415. },
  7416. handler(_ref, args, optArgs) {
  7417. var {
  7418. parser
  7419. } = _ref;
  7420. var size = optArgs[0];
  7421. var newLine = !parser.settings.displayMode || !parser.settings.useStrictBehavior("newLineInDisplayMode", "In LaTeX, \\\\ or \\newline " + "does nothing in display mode");
  7422. return {
  7423. type: "cr",
  7424. mode: parser.mode,
  7425. newLine,
  7426. size: size && assertNodeType(size, "size").value
  7427. };
  7428. },
  7429. // The following builders are called only at the top level,
  7430. // not within tabular/array environments.
  7431. htmlBuilder(group, options) {
  7432. var span = buildCommon.makeSpan(["mspace"], [], options);
  7433. if (group.newLine) {
  7434. span.classes.push("newline");
  7435. if (group.size) {
  7436. span.style.marginTop = makeEm(calculateSize(group.size, options));
  7437. }
  7438. }
  7439. return span;
  7440. },
  7441. mathmlBuilder(group, options) {
  7442. var node = new mathMLTree.MathNode("mspace");
  7443. if (group.newLine) {
  7444. node.setAttribute("linebreak", "newline");
  7445. if (group.size) {
  7446. node.setAttribute("height", makeEm(calculateSize(group.size, options)));
  7447. }
  7448. }
  7449. return node;
  7450. }
  7451. });
  7452. var globalMap = {
  7453. "\\global": "\\global",
  7454. "\\long": "\\\\globallong",
  7455. "\\\\globallong": "\\\\globallong",
  7456. "\\def": "\\gdef",
  7457. "\\gdef": "\\gdef",
  7458. "\\edef": "\\xdef",
  7459. "\\xdef": "\\xdef",
  7460. "\\let": "\\\\globallet",
  7461. "\\futurelet": "\\\\globalfuture"
  7462. };
  7463. var checkControlSequence = tok => {
  7464. var name = tok.text;
  7465. if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
  7466. throw new ParseError("Expected a control sequence", tok);
  7467. }
  7468. return name;
  7469. };
  7470. var getRHS = parser => {
  7471. var tok = parser.gullet.popToken();
  7472. if (tok.text === "=") {
  7473. // consume optional equals
  7474. tok = parser.gullet.popToken();
  7475. if (tok.text === " ") {
  7476. // consume one optional space
  7477. tok = parser.gullet.popToken();
  7478. }
  7479. }
  7480. return tok;
  7481. };
  7482. var letCommand = (parser, name, tok, global) => {
  7483. var macro = parser.gullet.macros.get(tok.text);
  7484. if (macro == null) {
  7485. // don't expand it later even if a macro with the same name is defined
  7486. // e.g., \let\foo=\frac \def\frac{\relax} \frac12
  7487. tok.noexpand = true;
  7488. macro = {
  7489. tokens: [tok],
  7490. numArgs: 0,
  7491. // reproduce the same behavior in expansion
  7492. unexpandable: !parser.gullet.isExpandable(tok.text)
  7493. };
  7494. }
  7495. parser.gullet.macros.set(name, macro, global);
  7496. }; // <assignment> -> <non-macro assignment>|<macro assignment>
  7497. // <non-macro assignment> -> <simple assignment>|\global<non-macro assignment>
  7498. // <macro assignment> -> <definition>|<prefix><macro assignment>
  7499. // <prefix> -> \global|\long|\outer
  7500. defineFunction({
  7501. type: "internal",
  7502. names: ["\\global", "\\long", "\\\\globallong" // can’t be entered directly
  7503. ],
  7504. props: {
  7505. numArgs: 0,
  7506. allowedInText: true
  7507. },
  7508. handler(_ref) {
  7509. var {
  7510. parser,
  7511. funcName
  7512. } = _ref;
  7513. parser.consumeSpaces();
  7514. var token = parser.fetch();
  7515. if (globalMap[token.text]) {
  7516. // KaTeX doesn't have \par, so ignore \long
  7517. if (funcName === "\\global" || funcName === "\\\\globallong") {
  7518. token.text = globalMap[token.text];
  7519. }
  7520. return assertNodeType(parser.parseFunction(), "internal");
  7521. }
  7522. throw new ParseError("Invalid token after macro prefix", token);
  7523. }
  7524. }); // Basic support for macro definitions: \def, \gdef, \edef, \xdef
  7525. // <definition> -> <def><control sequence><definition text>
  7526. // <def> -> \def|\gdef|\edef|\xdef
  7527. // <definition text> -> <parameter text><left brace><balanced text><right brace>
  7528. defineFunction({
  7529. type: "internal",
  7530. names: ["\\def", "\\gdef", "\\edef", "\\xdef"],
  7531. props: {
  7532. numArgs: 0,
  7533. allowedInText: true,
  7534. primitive: true
  7535. },
  7536. handler(_ref2) {
  7537. var {
  7538. parser,
  7539. funcName
  7540. } = _ref2;
  7541. var tok = parser.gullet.popToken();
  7542. var name = tok.text;
  7543. if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
  7544. throw new ParseError("Expected a control sequence", tok);
  7545. }
  7546. var numArgs = 0;
  7547. var insert;
  7548. var delimiters = [[]]; // <parameter text> contains no braces
  7549. while (parser.gullet.future().text !== "{") {
  7550. tok = parser.gullet.popToken();
  7551. if (tok.text === "#") {
  7552. // If the very last character of the <parameter text> is #, so that
  7553. // this # is immediately followed by {, TeX will behave as if the {
  7554. // had been inserted at the right end of both the parameter text
  7555. // and the replacement text.
  7556. if (parser.gullet.future().text === "{") {
  7557. insert = parser.gullet.future();
  7558. delimiters[numArgs].push("{");
  7559. break;
  7560. } // A parameter, the first appearance of # must be followed by 1,
  7561. // the next by 2, and so on; up to nine #’s are allowed
  7562. tok = parser.gullet.popToken();
  7563. if (!/^[1-9]$/.test(tok.text)) {
  7564. throw new ParseError("Invalid argument number \"" + tok.text + "\"");
  7565. }
  7566. if (parseInt(tok.text) !== numArgs + 1) {
  7567. throw new ParseError("Argument number \"" + tok.text + "\" out of order");
  7568. }
  7569. numArgs++;
  7570. delimiters.push([]);
  7571. } else if (tok.text === "EOF") {
  7572. throw new ParseError("Expected a macro definition");
  7573. } else {
  7574. delimiters[numArgs].push(tok.text);
  7575. }
  7576. } // replacement text, enclosed in '{' and '}' and properly nested
  7577. var {
  7578. tokens
  7579. } = parser.gullet.consumeArg();
  7580. if (insert) {
  7581. tokens.unshift(insert);
  7582. }
  7583. if (funcName === "\\edef" || funcName === "\\xdef") {
  7584. tokens = parser.gullet.expandTokens(tokens);
  7585. tokens.reverse(); // to fit in with stack order
  7586. } // Final arg is the expansion of the macro
  7587. parser.gullet.macros.set(name, {
  7588. tokens,
  7589. numArgs,
  7590. delimiters
  7591. }, funcName === globalMap[funcName]);
  7592. return {
  7593. type: "internal",
  7594. mode: parser.mode
  7595. };
  7596. }
  7597. }); // <simple assignment> -> <let assignment>
  7598. // <let assignment> -> \futurelet<control sequence><token><token>
  7599. // | \let<control sequence><equals><one optional space><token>
  7600. // <equals> -> <optional spaces>|<optional spaces>=
  7601. defineFunction({
  7602. type: "internal",
  7603. names: ["\\let", "\\\\globallet" // can’t be entered directly
  7604. ],
  7605. props: {
  7606. numArgs: 0,
  7607. allowedInText: true,
  7608. primitive: true
  7609. },
  7610. handler(_ref3) {
  7611. var {
  7612. parser,
  7613. funcName
  7614. } = _ref3;
  7615. var name = checkControlSequence(parser.gullet.popToken());
  7616. parser.gullet.consumeSpaces();
  7617. var tok = getRHS(parser);
  7618. letCommand(parser, name, tok, funcName === "\\\\globallet");
  7619. return {
  7620. type: "internal",
  7621. mode: parser.mode
  7622. };
  7623. }
  7624. }); // ref: https://www.tug.org/TUGboat/tb09-3/tb22bechtolsheim.pdf
  7625. defineFunction({
  7626. type: "internal",
  7627. names: ["\\futurelet", "\\\\globalfuture" // can’t be entered directly
  7628. ],
  7629. props: {
  7630. numArgs: 0,
  7631. allowedInText: true,
  7632. primitive: true
  7633. },
  7634. handler(_ref4) {
  7635. var {
  7636. parser,
  7637. funcName
  7638. } = _ref4;
  7639. var name = checkControlSequence(parser.gullet.popToken());
  7640. var middle = parser.gullet.popToken();
  7641. var tok = parser.gullet.popToken();
  7642. letCommand(parser, name, tok, funcName === "\\\\globalfuture");
  7643. parser.gullet.pushToken(tok);
  7644. parser.gullet.pushToken(middle);
  7645. return {
  7646. type: "internal",
  7647. mode: parser.mode
  7648. };
  7649. }
  7650. });
  7651. /**
  7652. * This file deals with creating delimiters of various sizes. The TeXbook
  7653. * discusses these routines on page 441-442, in the "Another subroutine sets box
  7654. * x to a specified variable delimiter" paragraph.
  7655. *
  7656. * There are three main routines here. `makeSmallDelim` makes a delimiter in the
  7657. * normal font, but in either text, script, or scriptscript style.
  7658. * `makeLargeDelim` makes a delimiter in textstyle, but in one of the Size1,
  7659. * Size2, Size3, or Size4 fonts. `makeStackedDelim` makes a delimiter out of
  7660. * smaller pieces that are stacked on top of one another.
  7661. *
  7662. * The functions take a parameter `center`, which determines if the delimiter
  7663. * should be centered around the axis.
  7664. *
  7665. * Then, there are three exposed functions. `sizedDelim` makes a delimiter in
  7666. * one of the given sizes. This is used for things like `\bigl`.
  7667. * `customSizedDelim` makes a delimiter with a given total height+depth. It is
  7668. * called in places like `\sqrt`. `leftRightDelim` makes an appropriate
  7669. * delimiter which surrounds an expression of a given height an depth. It is
  7670. * used in `\left` and `\right`.
  7671. */
  7672. /**
  7673. * Get the metrics for a given symbol and font, after transformation (i.e.
  7674. * after following replacement from symbols.js)
  7675. */
  7676. var getMetrics = function getMetrics(symbol, font, mode) {
  7677. var replace = symbols.math[symbol] && symbols.math[symbol].replace;
  7678. var metrics = getCharacterMetrics(replace || symbol, font, mode);
  7679. if (!metrics) {
  7680. throw new Error("Unsupported symbol " + symbol + " and font size " + font + ".");
  7681. }
  7682. return metrics;
  7683. };
  7684. /**
  7685. * Puts a delimiter span in a given style, and adds appropriate height, depth,
  7686. * and maxFontSizes.
  7687. */
  7688. var styleWrap = function styleWrap(delim, toStyle, options, classes) {
  7689. var newOptions = options.havingBaseStyle(toStyle);
  7690. var span = buildCommon.makeSpan(classes.concat(newOptions.sizingClasses(options)), [delim], options);
  7691. var delimSizeMultiplier = newOptions.sizeMultiplier / options.sizeMultiplier;
  7692. span.height *= delimSizeMultiplier;
  7693. span.depth *= delimSizeMultiplier;
  7694. span.maxFontSize = newOptions.sizeMultiplier;
  7695. return span;
  7696. };
  7697. var centerSpan = function centerSpan(span, options, style) {
  7698. var newOptions = options.havingBaseStyle(style);
  7699. var shift = (1 - options.sizeMultiplier / newOptions.sizeMultiplier) * options.fontMetrics().axisHeight;
  7700. span.classes.push("delimcenter");
  7701. span.style.top = makeEm(shift);
  7702. span.height -= shift;
  7703. span.depth += shift;
  7704. };
  7705. /**
  7706. * Makes a small delimiter. This is a delimiter that comes in the Main-Regular
  7707. * font, but is restyled to either be in textstyle, scriptstyle, or
  7708. * scriptscriptstyle.
  7709. */
  7710. var makeSmallDelim = function makeSmallDelim(delim, style, center, options, mode, classes) {
  7711. var text = buildCommon.makeSymbol(delim, "Main-Regular", mode, options);
  7712. var span = styleWrap(text, style, options, classes);
  7713. if (center) {
  7714. centerSpan(span, options, style);
  7715. }
  7716. return span;
  7717. };
  7718. /**
  7719. * Builds a symbol in the given font size (note size is an integer)
  7720. */
  7721. var mathrmSize = function mathrmSize(value, size, mode, options) {
  7722. return buildCommon.makeSymbol(value, "Size" + size + "-Regular", mode, options);
  7723. };
  7724. /**
  7725. * Makes a large delimiter. This is a delimiter that comes in the Size1, Size2,
  7726. * Size3, or Size4 fonts. It is always rendered in textstyle.
  7727. */
  7728. var makeLargeDelim = function makeLargeDelim(delim, size, center, options, mode, classes) {
  7729. var inner = mathrmSize(delim, size, mode, options);
  7730. var span = styleWrap(buildCommon.makeSpan(["delimsizing", "size" + size], [inner], options), Style$1.TEXT, options, classes);
  7731. if (center) {
  7732. centerSpan(span, options, Style$1.TEXT);
  7733. }
  7734. return span;
  7735. };
  7736. /**
  7737. * Make a span from a font glyph with the given offset and in the given font.
  7738. * This is used in makeStackedDelim to make the stacking pieces for the delimiter.
  7739. */
  7740. var makeGlyphSpan = function makeGlyphSpan(symbol, font, mode) {
  7741. var sizeClass; // Apply the correct CSS class to choose the right font.
  7742. if (font === "Size1-Regular") {
  7743. sizeClass = "delim-size1";
  7744. } else
  7745. /* if (font === "Size4-Regular") */
  7746. {
  7747. sizeClass = "delim-size4";
  7748. }
  7749. var corner = buildCommon.makeSpan(["delimsizinginner", sizeClass], [buildCommon.makeSpan([], [buildCommon.makeSymbol(symbol, font, mode)])]); // Since this will be passed into `makeVList` in the end, wrap the element
  7750. // in the appropriate tag that VList uses.
  7751. return {
  7752. type: "elem",
  7753. elem: corner
  7754. };
  7755. };
  7756. var makeInner = function makeInner(ch, height, options) {
  7757. // Create a span with inline SVG for the inner part of a tall stacked delimiter.
  7758. var width = fontMetricsData['Size4-Regular'][ch.charCodeAt(0)] ? fontMetricsData['Size4-Regular'][ch.charCodeAt(0)][4] : fontMetricsData['Size1-Regular'][ch.charCodeAt(0)][4];
  7759. var path = new PathNode("inner", innerPath(ch, Math.round(1000 * height)));
  7760. var svgNode = new SvgNode([path], {
  7761. "width": makeEm(width),
  7762. "height": makeEm(height),
  7763. // Override CSS rule `.katex svg { width: 100% }`
  7764. "style": "width:" + makeEm(width),
  7765. "viewBox": "0 0 " + 1000 * width + " " + Math.round(1000 * height),
  7766. "preserveAspectRatio": "xMinYMin"
  7767. });
  7768. var span = buildCommon.makeSvgSpan([], [svgNode], options);
  7769. span.height = height;
  7770. span.style.height = makeEm(height);
  7771. span.style.width = makeEm(width);
  7772. return {
  7773. type: "elem",
  7774. elem: span
  7775. };
  7776. }; // Helpers for makeStackedDelim
  7777. var lapInEms = 0.008;
  7778. var lap = {
  7779. type: "kern",
  7780. size: -1 * lapInEms
  7781. };
  7782. var verts = ["|", "\\lvert", "\\rvert", "\\vert"];
  7783. var doubleVerts = ["\\|", "\\lVert", "\\rVert", "\\Vert"];
  7784. /**
  7785. * Make a stacked delimiter out of a given delimiter, with the total height at
  7786. * least `heightTotal`. This routine is mentioned on page 442 of the TeXbook.
  7787. */
  7788. var makeStackedDelim = function makeStackedDelim(delim, heightTotal, center, options, mode, classes) {
  7789. // There are four parts, the top, an optional middle, a repeated part, and a
  7790. // bottom.
  7791. var top;
  7792. var middle;
  7793. var repeat;
  7794. var bottom;
  7795. top = repeat = bottom = delim;
  7796. middle = null; // Also keep track of what font the delimiters are in
  7797. var font = "Size1-Regular"; // We set the parts and font based on the symbol. Note that we use
  7798. // '\u23d0' instead of '|' and '\u2016' instead of '\\|' for the
  7799. // repeats of the arrows
  7800. if (delim === "\\uparrow") {
  7801. repeat = bottom = "\u23d0";
  7802. } else if (delim === "\\Uparrow") {
  7803. repeat = bottom = "\u2016";
  7804. } else if (delim === "\\downarrow") {
  7805. top = repeat = "\u23d0";
  7806. } else if (delim === "\\Downarrow") {
  7807. top = repeat = "\u2016";
  7808. } else if (delim === "\\updownarrow") {
  7809. top = "\\uparrow";
  7810. repeat = "\u23d0";
  7811. bottom = "\\downarrow";
  7812. } else if (delim === "\\Updownarrow") {
  7813. top = "\\Uparrow";
  7814. repeat = "\u2016";
  7815. bottom = "\\Downarrow";
  7816. } else if (utils.contains(verts, delim)) {
  7817. repeat = "\u2223";
  7818. } else if (utils.contains(doubleVerts, delim)) {
  7819. repeat = "\u2225";
  7820. } else if (delim === "[" || delim === "\\lbrack") {
  7821. top = "\u23a1";
  7822. repeat = "\u23a2";
  7823. bottom = "\u23a3";
  7824. font = "Size4-Regular";
  7825. } else if (delim === "]" || delim === "\\rbrack") {
  7826. top = "\u23a4";
  7827. repeat = "\u23a5";
  7828. bottom = "\u23a6";
  7829. font = "Size4-Regular";
  7830. } else if (delim === "\\lfloor" || delim === "\u230a") {
  7831. repeat = top = "\u23a2";
  7832. bottom = "\u23a3";
  7833. font = "Size4-Regular";
  7834. } else if (delim === "\\lceil" || delim === "\u2308") {
  7835. top = "\u23a1";
  7836. repeat = bottom = "\u23a2";
  7837. font = "Size4-Regular";
  7838. } else if (delim === "\\rfloor" || delim === "\u230b") {
  7839. repeat = top = "\u23a5";
  7840. bottom = "\u23a6";
  7841. font = "Size4-Regular";
  7842. } else if (delim === "\\rceil" || delim === "\u2309") {
  7843. top = "\u23a4";
  7844. repeat = bottom = "\u23a5";
  7845. font = "Size4-Regular";
  7846. } else if (delim === "(" || delim === "\\lparen") {
  7847. top = "\u239b";
  7848. repeat = "\u239c";
  7849. bottom = "\u239d";
  7850. font = "Size4-Regular";
  7851. } else if (delim === ")" || delim === "\\rparen") {
  7852. top = "\u239e";
  7853. repeat = "\u239f";
  7854. bottom = "\u23a0";
  7855. font = "Size4-Regular";
  7856. } else if (delim === "\\{" || delim === "\\lbrace") {
  7857. top = "\u23a7";
  7858. middle = "\u23a8";
  7859. bottom = "\u23a9";
  7860. repeat = "\u23aa";
  7861. font = "Size4-Regular";
  7862. } else if (delim === "\\}" || delim === "\\rbrace") {
  7863. top = "\u23ab";
  7864. middle = "\u23ac";
  7865. bottom = "\u23ad";
  7866. repeat = "\u23aa";
  7867. font = "Size4-Regular";
  7868. } else if (delim === "\\lgroup" || delim === "\u27ee") {
  7869. top = "\u23a7";
  7870. bottom = "\u23a9";
  7871. repeat = "\u23aa";
  7872. font = "Size4-Regular";
  7873. } else if (delim === "\\rgroup" || delim === "\u27ef") {
  7874. top = "\u23ab";
  7875. bottom = "\u23ad";
  7876. repeat = "\u23aa";
  7877. font = "Size4-Regular";
  7878. } else if (delim === "\\lmoustache" || delim === "\u23b0") {
  7879. top = "\u23a7";
  7880. bottom = "\u23ad";
  7881. repeat = "\u23aa";
  7882. font = "Size4-Regular";
  7883. } else if (delim === "\\rmoustache" || delim === "\u23b1") {
  7884. top = "\u23ab";
  7885. bottom = "\u23a9";
  7886. repeat = "\u23aa";
  7887. font = "Size4-Regular";
  7888. } // Get the metrics of the four sections
  7889. var topMetrics = getMetrics(top, font, mode);
  7890. var topHeightTotal = topMetrics.height + topMetrics.depth;
  7891. var repeatMetrics = getMetrics(repeat, font, mode);
  7892. var repeatHeightTotal = repeatMetrics.height + repeatMetrics.depth;
  7893. var bottomMetrics = getMetrics(bottom, font, mode);
  7894. var bottomHeightTotal = bottomMetrics.height + bottomMetrics.depth;
  7895. var middleHeightTotal = 0;
  7896. var middleFactor = 1;
  7897. if (middle !== null) {
  7898. var middleMetrics = getMetrics(middle, font, mode);
  7899. middleHeightTotal = middleMetrics.height + middleMetrics.depth;
  7900. middleFactor = 2; // repeat symmetrically above and below middle
  7901. } // Calcuate the minimal height that the delimiter can have.
  7902. // It is at least the size of the top, bottom, and optional middle combined.
  7903. var minHeight = topHeightTotal + bottomHeightTotal + middleHeightTotal; // Compute the number of copies of the repeat symbol we will need
  7904. var repeatCount = Math.max(0, Math.ceil((heightTotal - minHeight) / (middleFactor * repeatHeightTotal))); // Compute the total height of the delimiter including all the symbols
  7905. var realHeightTotal = minHeight + repeatCount * middleFactor * repeatHeightTotal; // The center of the delimiter is placed at the center of the axis. Note
  7906. // that in this context, "center" means that the delimiter should be
  7907. // centered around the axis in the current style, while normally it is
  7908. // centered around the axis in textstyle.
  7909. var axisHeight = options.fontMetrics().axisHeight;
  7910. if (center) {
  7911. axisHeight *= options.sizeMultiplier;
  7912. } // Calculate the depth
  7913. var depth = realHeightTotal / 2 - axisHeight; // Now, we start building the pieces that will go into the vlist
  7914. // Keep a list of the pieces of the stacked delimiter
  7915. var stack = []; // Add the bottom symbol
  7916. stack.push(makeGlyphSpan(bottom, font, mode));
  7917. stack.push(lap); // overlap
  7918. if (middle === null) {
  7919. // The middle section will be an SVG. Make it an extra 0.016em tall.
  7920. // We'll overlap by 0.008em at top and bottom.
  7921. var innerHeight = realHeightTotal - topHeightTotal - bottomHeightTotal + 2 * lapInEms;
  7922. stack.push(makeInner(repeat, innerHeight, options));
  7923. } else {
  7924. // When there is a middle bit, we need the middle part and two repeated
  7925. // sections
  7926. var _innerHeight = (realHeightTotal - topHeightTotal - bottomHeightTotal - middleHeightTotal) / 2 + 2 * lapInEms;
  7927. stack.push(makeInner(repeat, _innerHeight, options)); // Now insert the middle of the brace.
  7928. stack.push(lap);
  7929. stack.push(makeGlyphSpan(middle, font, mode));
  7930. stack.push(lap);
  7931. stack.push(makeInner(repeat, _innerHeight, options));
  7932. } // Add the top symbol
  7933. stack.push(lap);
  7934. stack.push(makeGlyphSpan(top, font, mode)); // Finally, build the vlist
  7935. var newOptions = options.havingBaseStyle(Style$1.TEXT);
  7936. var inner = buildCommon.makeVList({
  7937. positionType: "bottom",
  7938. positionData: depth,
  7939. children: stack
  7940. }, newOptions);
  7941. return styleWrap(buildCommon.makeSpan(["delimsizing", "mult"], [inner], newOptions), Style$1.TEXT, options, classes);
  7942. }; // All surds have 0.08em padding above the viniculum inside the SVG.
  7943. // That keeps browser span height rounding error from pinching the line.
  7944. var vbPad = 80; // padding above the surd, measured inside the viewBox.
  7945. var emPad = 0.08; // padding, in ems, measured in the document.
  7946. var sqrtSvg = function sqrtSvg(sqrtName, height, viewBoxHeight, extraViniculum, options) {
  7947. var path = sqrtPath(sqrtName, extraViniculum, viewBoxHeight);
  7948. var pathNode = new PathNode(sqrtName, path);
  7949. var svg = new SvgNode([pathNode], {
  7950. // Note: 1000:1 ratio of viewBox to document em width.
  7951. "width": "400em",
  7952. "height": makeEm(height),
  7953. "viewBox": "0 0 400000 " + viewBoxHeight,
  7954. "preserveAspectRatio": "xMinYMin slice"
  7955. });
  7956. return buildCommon.makeSvgSpan(["hide-tail"], [svg], options);
  7957. };
  7958. /**
  7959. * Make a sqrt image of the given height,
  7960. */
  7961. var makeSqrtImage = function makeSqrtImage(height, options) {
  7962. // Define a newOptions that removes the effect of size changes such as \Huge.
  7963. // We don't pick different a height surd for \Huge. For it, we scale up.
  7964. var newOptions = options.havingBaseSizing(); // Pick the desired surd glyph from a sequence of surds.
  7965. var delim = traverseSequence("\\surd", height * newOptions.sizeMultiplier, stackLargeDelimiterSequence, newOptions);
  7966. var sizeMultiplier = newOptions.sizeMultiplier; // default
  7967. // The standard sqrt SVGs each have a 0.04em thick viniculum.
  7968. // If Settings.minRuleThickness is larger than that, we add extraViniculum.
  7969. var extraViniculum = Math.max(0, options.minRuleThickness - options.fontMetrics().sqrtRuleThickness); // Create a span containing an SVG image of a sqrt symbol.
  7970. var span;
  7971. var spanHeight = 0;
  7972. var texHeight = 0;
  7973. var viewBoxHeight = 0;
  7974. var advanceWidth; // We create viewBoxes with 80 units of "padding" above each surd.
  7975. // Then browser rounding error on the parent span height will not
  7976. // encroach on the ink of the viniculum. But that padding is not
  7977. // included in the TeX-like `height` used for calculation of
  7978. // vertical alignment. So texHeight = span.height < span.style.height.
  7979. if (delim.type === "small") {
  7980. // Get an SVG that is derived from glyph U+221A in font KaTeX-Main.
  7981. // 1000 unit normal glyph height.
  7982. viewBoxHeight = 1000 + 1000 * extraViniculum + vbPad;
  7983. if (height < 1.0) {
  7984. sizeMultiplier = 1.0; // mimic a \textfont radical
  7985. } else if (height < 1.4) {
  7986. sizeMultiplier = 0.7; // mimic a \scriptfont radical
  7987. }
  7988. spanHeight = (1.0 + extraViniculum + emPad) / sizeMultiplier;
  7989. texHeight = (1.00 + extraViniculum) / sizeMultiplier;
  7990. span = sqrtSvg("sqrtMain", spanHeight, viewBoxHeight, extraViniculum, options);
  7991. span.style.minWidth = "0.853em";
  7992. advanceWidth = 0.833 / sizeMultiplier; // from the font.
  7993. } else if (delim.type === "large") {
  7994. // These SVGs come from fonts: KaTeX_Size1, _Size2, etc.
  7995. viewBoxHeight = (1000 + vbPad) * sizeToMaxHeight[delim.size];
  7996. texHeight = (sizeToMaxHeight[delim.size] + extraViniculum) / sizeMultiplier;
  7997. spanHeight = (sizeToMaxHeight[delim.size] + extraViniculum + emPad) / sizeMultiplier;
  7998. span = sqrtSvg("sqrtSize" + delim.size, spanHeight, viewBoxHeight, extraViniculum, options);
  7999. span.style.minWidth = "1.02em";
  8000. advanceWidth = 1.0 / sizeMultiplier; // 1.0 from the font.
  8001. } else {
  8002. // Tall sqrt. In TeX, this would be stacked using multiple glyphs.
  8003. // We'll use a single SVG to accomplish the same thing.
  8004. spanHeight = height + extraViniculum + emPad;
  8005. texHeight = height + extraViniculum;
  8006. viewBoxHeight = Math.floor(1000 * height + extraViniculum) + vbPad;
  8007. span = sqrtSvg("sqrtTall", spanHeight, viewBoxHeight, extraViniculum, options);
  8008. span.style.minWidth = "0.742em";
  8009. advanceWidth = 1.056;
  8010. }
  8011. span.height = texHeight;
  8012. span.style.height = makeEm(spanHeight);
  8013. return {
  8014. span,
  8015. advanceWidth,
  8016. // Calculate the actual line width.
  8017. // This actually should depend on the chosen font -- e.g. \boldmath
  8018. // should use the thicker surd symbols from e.g. KaTeX_Main-Bold, and
  8019. // have thicker rules.
  8020. ruleWidth: (options.fontMetrics().sqrtRuleThickness + extraViniculum) * sizeMultiplier
  8021. };
  8022. }; // There are three kinds of delimiters, delimiters that stack when they become
  8023. // too large
  8024. var stackLargeDelimiters = ["(", "\\lparen", ")", "\\rparen", "[", "\\lbrack", "]", "\\rbrack", "\\{", "\\lbrace", "\\}", "\\rbrace", "\\lfloor", "\\rfloor", "\u230a", "\u230b", "\\lceil", "\\rceil", "\u2308", "\u2309", "\\surd"]; // delimiters that always stack
  8025. var stackAlwaysDelimiters = ["\\uparrow", "\\downarrow", "\\updownarrow", "\\Uparrow", "\\Downarrow", "\\Updownarrow", "|", "\\|", "\\vert", "\\Vert", "\\lvert", "\\rvert", "\\lVert", "\\rVert", "\\lgroup", "\\rgroup", "\u27ee", "\u27ef", "\\lmoustache", "\\rmoustache", "\u23b0", "\u23b1"]; // and delimiters that never stack
  8026. var stackNeverDelimiters = ["<", ">", "\\langle", "\\rangle", "/", "\\backslash", "\\lt", "\\gt"]; // Metrics of the different sizes. Found by looking at TeX's output of
  8027. // $\bigl| // \Bigl| \biggl| \Biggl| \showlists$
  8028. // Used to create stacked delimiters of appropriate sizes in makeSizedDelim.
  8029. var sizeToMaxHeight = [0, 1.2, 1.8, 2.4, 3.0];
  8030. /**
  8031. * Used to create a delimiter of a specific size, where `size` is 1, 2, 3, or 4.
  8032. */
  8033. var makeSizedDelim = function makeSizedDelim(delim, size, options, mode, classes) {
  8034. // < and > turn into \langle and \rangle in delimiters
  8035. if (delim === "<" || delim === "\\lt" || delim === "\u27e8") {
  8036. delim = "\\langle";
  8037. } else if (delim === ">" || delim === "\\gt" || delim === "\u27e9") {
  8038. delim = "\\rangle";
  8039. } // Sized delimiters are never centered.
  8040. if (utils.contains(stackLargeDelimiters, delim) || utils.contains(stackNeverDelimiters, delim)) {
  8041. return makeLargeDelim(delim, size, false, options, mode, classes);
  8042. } else if (utils.contains(stackAlwaysDelimiters, delim)) {
  8043. return makeStackedDelim(delim, sizeToMaxHeight[size], false, options, mode, classes);
  8044. } else {
  8045. throw new ParseError("Illegal delimiter: '" + delim + "'");
  8046. }
  8047. };
  8048. /**
  8049. * There are three different sequences of delimiter sizes that the delimiters
  8050. * follow depending on the kind of delimiter. This is used when creating custom
  8051. * sized delimiters to decide whether to create a small, large, or stacked
  8052. * delimiter.
  8053. *
  8054. * In real TeX, these sequences aren't explicitly defined, but are instead
  8055. * defined inside the font metrics. Since there are only three sequences that
  8056. * are possible for the delimiters that TeX defines, it is easier to just encode
  8057. * them explicitly here.
  8058. */
  8059. // Delimiters that never stack try small delimiters and large delimiters only
  8060. var stackNeverDelimiterSequence = [{
  8061. type: "small",
  8062. style: Style$1.SCRIPTSCRIPT
  8063. }, {
  8064. type: "small",
  8065. style: Style$1.SCRIPT
  8066. }, {
  8067. type: "small",
  8068. style: Style$1.TEXT
  8069. }, {
  8070. type: "large",
  8071. size: 1
  8072. }, {
  8073. type: "large",
  8074. size: 2
  8075. }, {
  8076. type: "large",
  8077. size: 3
  8078. }, {
  8079. type: "large",
  8080. size: 4
  8081. }]; // Delimiters that always stack try the small delimiters first, then stack
  8082. var stackAlwaysDelimiterSequence = [{
  8083. type: "small",
  8084. style: Style$1.SCRIPTSCRIPT
  8085. }, {
  8086. type: "small",
  8087. style: Style$1.SCRIPT
  8088. }, {
  8089. type: "small",
  8090. style: Style$1.TEXT
  8091. }, {
  8092. type: "stack"
  8093. }]; // Delimiters that stack when large try the small and then large delimiters, and
  8094. // stack afterwards
  8095. var stackLargeDelimiterSequence = [{
  8096. type: "small",
  8097. style: Style$1.SCRIPTSCRIPT
  8098. }, {
  8099. type: "small",
  8100. style: Style$1.SCRIPT
  8101. }, {
  8102. type: "small",
  8103. style: Style$1.TEXT
  8104. }, {
  8105. type: "large",
  8106. size: 1
  8107. }, {
  8108. type: "large",
  8109. size: 2
  8110. }, {
  8111. type: "large",
  8112. size: 3
  8113. }, {
  8114. type: "large",
  8115. size: 4
  8116. }, {
  8117. type: "stack"
  8118. }];
  8119. /**
  8120. * Get the font used in a delimiter based on what kind of delimiter it is.
  8121. * TODO(#963) Use more specific font family return type once that is introduced.
  8122. */
  8123. var delimTypeToFont = function delimTypeToFont(type) {
  8124. if (type.type === "small") {
  8125. return "Main-Regular";
  8126. } else if (type.type === "large") {
  8127. return "Size" + type.size + "-Regular";
  8128. } else if (type.type === "stack") {
  8129. return "Size4-Regular";
  8130. } else {
  8131. throw new Error("Add support for delim type '" + type.type + "' here.");
  8132. }
  8133. };
  8134. /**
  8135. * Traverse a sequence of types of delimiters to decide what kind of delimiter
  8136. * should be used to create a delimiter of the given height+depth.
  8137. */
  8138. var traverseSequence = function traverseSequence(delim, height, sequence, options) {
  8139. // Here, we choose the index we should start at in the sequences. In smaller
  8140. // sizes (which correspond to larger numbers in style.size) we start earlier
  8141. // in the sequence. Thus, scriptscript starts at index 3-3=0, script starts
  8142. // at index 3-2=1, text starts at 3-1=2, and display starts at min(2,3-0)=2
  8143. var start = Math.min(2, 3 - options.style.size);
  8144. for (var i = start; i < sequence.length; i++) {
  8145. if (sequence[i].type === "stack") {
  8146. // This is always the last delimiter, so we just break the loop now.
  8147. break;
  8148. }
  8149. var metrics = getMetrics(delim, delimTypeToFont(sequence[i]), "math");
  8150. var heightDepth = metrics.height + metrics.depth; // Small delimiters are scaled down versions of the same font, so we
  8151. // account for the style change size.
  8152. if (sequence[i].type === "small") {
  8153. var newOptions = options.havingBaseStyle(sequence[i].style);
  8154. heightDepth *= newOptions.sizeMultiplier;
  8155. } // Check if the delimiter at this size works for the given height.
  8156. if (heightDepth > height) {
  8157. return sequence[i];
  8158. }
  8159. } // If we reached the end of the sequence, return the last sequence element.
  8160. return sequence[sequence.length - 1];
  8161. };
  8162. /**
  8163. * Make a delimiter of a given height+depth, with optional centering. Here, we
  8164. * traverse the sequences, and create a delimiter that the sequence tells us to.
  8165. */
  8166. var makeCustomSizedDelim = function makeCustomSizedDelim(delim, height, center, options, mode, classes) {
  8167. if (delim === "<" || delim === "\\lt" || delim === "\u27e8") {
  8168. delim = "\\langle";
  8169. } else if (delim === ">" || delim === "\\gt" || delim === "\u27e9") {
  8170. delim = "\\rangle";
  8171. } // Decide what sequence to use
  8172. var sequence;
  8173. if (utils.contains(stackNeverDelimiters, delim)) {
  8174. sequence = stackNeverDelimiterSequence;
  8175. } else if (utils.contains(stackLargeDelimiters, delim)) {
  8176. sequence = stackLargeDelimiterSequence;
  8177. } else {
  8178. sequence = stackAlwaysDelimiterSequence;
  8179. } // Look through the sequence
  8180. var delimType = traverseSequence(delim, height, sequence, options); // Get the delimiter from font glyphs.
  8181. // Depending on the sequence element we decided on, call the
  8182. // appropriate function.
  8183. if (delimType.type === "small") {
  8184. return makeSmallDelim(delim, delimType.style, center, options, mode, classes);
  8185. } else if (delimType.type === "large") {
  8186. return makeLargeDelim(delim, delimType.size, center, options, mode, classes);
  8187. } else
  8188. /* if (delimType.type === "stack") */
  8189. {
  8190. return makeStackedDelim(delim, height, center, options, mode, classes);
  8191. }
  8192. };
  8193. /**
  8194. * Make a delimiter for use with `\left` and `\right`, given a height and depth
  8195. * of an expression that the delimiters surround.
  8196. */
  8197. var makeLeftRightDelim = function makeLeftRightDelim(delim, height, depth, options, mode, classes) {
  8198. // We always center \left/\right delimiters, so the axis is always shifted
  8199. var axisHeight = options.fontMetrics().axisHeight * options.sizeMultiplier; // Taken from TeX source, tex.web, function make_left_right
  8200. var delimiterFactor = 901;
  8201. var delimiterExtend = 5.0 / options.fontMetrics().ptPerEm;
  8202. var maxDistFromAxis = Math.max(height - axisHeight, depth + axisHeight);
  8203. var totalHeight = Math.max( // In real TeX, calculations are done using integral values which are
  8204. // 65536 per pt, or 655360 per em. So, the division here truncates in
  8205. // TeX but doesn't here, producing different results. If we wanted to
  8206. // exactly match TeX's calculation, we could do
  8207. // Math.floor(655360 * maxDistFromAxis / 500) *
  8208. // delimiterFactor / 655360
  8209. // (To see the difference, compare
  8210. // x^{x^{\left(\rule{0.1em}{0.68em}\right)}}
  8211. // in TeX and KaTeX)
  8212. maxDistFromAxis / 500 * delimiterFactor, 2 * maxDistFromAxis - delimiterExtend); // Finally, we defer to `makeCustomSizedDelim` with our calculated total
  8213. // height
  8214. return makeCustomSizedDelim(delim, totalHeight, true, options, mode, classes);
  8215. };
  8216. var delimiter = {
  8217. sqrtImage: makeSqrtImage,
  8218. sizedDelim: makeSizedDelim,
  8219. sizeToMaxHeight: sizeToMaxHeight,
  8220. customSizedDelim: makeCustomSizedDelim,
  8221. leftRightDelim: makeLeftRightDelim
  8222. };
  8223. // Extra data needed for the delimiter handler down below
  8224. var delimiterSizes = {
  8225. "\\bigl": {
  8226. mclass: "mopen",
  8227. size: 1
  8228. },
  8229. "\\Bigl": {
  8230. mclass: "mopen",
  8231. size: 2
  8232. },
  8233. "\\biggl": {
  8234. mclass: "mopen",
  8235. size: 3
  8236. },
  8237. "\\Biggl": {
  8238. mclass: "mopen",
  8239. size: 4
  8240. },
  8241. "\\bigr": {
  8242. mclass: "mclose",
  8243. size: 1
  8244. },
  8245. "\\Bigr": {
  8246. mclass: "mclose",
  8247. size: 2
  8248. },
  8249. "\\biggr": {
  8250. mclass: "mclose",
  8251. size: 3
  8252. },
  8253. "\\Biggr": {
  8254. mclass: "mclose",
  8255. size: 4
  8256. },
  8257. "\\bigm": {
  8258. mclass: "mrel",
  8259. size: 1
  8260. },
  8261. "\\Bigm": {
  8262. mclass: "mrel",
  8263. size: 2
  8264. },
  8265. "\\biggm": {
  8266. mclass: "mrel",
  8267. size: 3
  8268. },
  8269. "\\Biggm": {
  8270. mclass: "mrel",
  8271. size: 4
  8272. },
  8273. "\\big": {
  8274. mclass: "mord",
  8275. size: 1
  8276. },
  8277. "\\Big": {
  8278. mclass: "mord",
  8279. size: 2
  8280. },
  8281. "\\bigg": {
  8282. mclass: "mord",
  8283. size: 3
  8284. },
  8285. "\\Bigg": {
  8286. mclass: "mord",
  8287. size: 4
  8288. }
  8289. };
  8290. var delimiters = ["(", "\\lparen", ")", "\\rparen", "[", "\\lbrack", "]", "\\rbrack", "\\{", "\\lbrace", "\\}", "\\rbrace", "\\lfloor", "\\rfloor", "\u230a", "\u230b", "\\lceil", "\\rceil", "\u2308", "\u2309", "<", ">", "\\langle", "\u27e8", "\\rangle", "\u27e9", "\\lt", "\\gt", "\\lvert", "\\rvert", "\\lVert", "\\rVert", "\\lgroup", "\\rgroup", "\u27ee", "\u27ef", "\\lmoustache", "\\rmoustache", "\u23b0", "\u23b1", "/", "\\backslash", "|", "\\vert", "\\|", "\\Vert", "\\uparrow", "\\Uparrow", "\\downarrow", "\\Downarrow", "\\updownarrow", "\\Updownarrow", "."];
  8291. // Delimiter functions
  8292. function checkDelimiter(delim, context) {
  8293. var symDelim = checkSymbolNodeType(delim);
  8294. if (symDelim && utils.contains(delimiters, symDelim.text)) {
  8295. return symDelim;
  8296. } else if (symDelim) {
  8297. throw new ParseError("Invalid delimiter '" + symDelim.text + "' after '" + context.funcName + "'", delim);
  8298. } else {
  8299. throw new ParseError("Invalid delimiter type '" + delim.type + "'", delim);
  8300. }
  8301. }
  8302. defineFunction({
  8303. type: "delimsizing",
  8304. names: ["\\bigl", "\\Bigl", "\\biggl", "\\Biggl", "\\bigr", "\\Bigr", "\\biggr", "\\Biggr", "\\bigm", "\\Bigm", "\\biggm", "\\Biggm", "\\big", "\\Big", "\\bigg", "\\Bigg"],
  8305. props: {
  8306. numArgs: 1,
  8307. argTypes: ["primitive"]
  8308. },
  8309. handler: (context, args) => {
  8310. var delim = checkDelimiter(args[0], context);
  8311. return {
  8312. type: "delimsizing",
  8313. mode: context.parser.mode,
  8314. size: delimiterSizes[context.funcName].size,
  8315. mclass: delimiterSizes[context.funcName].mclass,
  8316. delim: delim.text
  8317. };
  8318. },
  8319. htmlBuilder: (group, options) => {
  8320. if (group.delim === ".") {
  8321. // Empty delimiters still count as elements, even though they don't
  8322. // show anything.
  8323. return buildCommon.makeSpan([group.mclass]);
  8324. } // Use delimiter.sizedDelim to generate the delimiter.
  8325. return delimiter.sizedDelim(group.delim, group.size, options, group.mode, [group.mclass]);
  8326. },
  8327. mathmlBuilder: group => {
  8328. var children = [];
  8329. if (group.delim !== ".") {
  8330. children.push(makeText(group.delim, group.mode));
  8331. }
  8332. var node = new mathMLTree.MathNode("mo", children);
  8333. if (group.mclass === "mopen" || group.mclass === "mclose") {
  8334. // Only some of the delimsizing functions act as fences, and they
  8335. // return "mopen" or "mclose" mclass.
  8336. node.setAttribute("fence", "true");
  8337. } else {
  8338. // Explicitly disable fencing if it's not a fence, to override the
  8339. // defaults.
  8340. node.setAttribute("fence", "false");
  8341. }
  8342. node.setAttribute("stretchy", "true");
  8343. var size = makeEm(delimiter.sizeToMaxHeight[group.size]);
  8344. node.setAttribute("minsize", size);
  8345. node.setAttribute("maxsize", size);
  8346. return node;
  8347. }
  8348. });
  8349. function assertParsed(group) {
  8350. if (!group.body) {
  8351. throw new Error("Bug: The leftright ParseNode wasn't fully parsed.");
  8352. }
  8353. }
  8354. defineFunction({
  8355. type: "leftright-right",
  8356. names: ["\\right"],
  8357. props: {
  8358. numArgs: 1,
  8359. primitive: true
  8360. },
  8361. handler: (context, args) => {
  8362. // \left case below triggers parsing of \right in
  8363. // `const right = parser.parseFunction();`
  8364. // uses this return value.
  8365. var color = context.parser.gullet.macros.get("\\current@color");
  8366. if (color && typeof color !== "string") {
  8367. throw new ParseError("\\current@color set to non-string in \\right");
  8368. }
  8369. return {
  8370. type: "leftright-right",
  8371. mode: context.parser.mode,
  8372. delim: checkDelimiter(args[0], context).text,
  8373. color // undefined if not set via \color
  8374. };
  8375. }
  8376. });
  8377. defineFunction({
  8378. type: "leftright",
  8379. names: ["\\left"],
  8380. props: {
  8381. numArgs: 1,
  8382. primitive: true
  8383. },
  8384. handler: (context, args) => {
  8385. var delim = checkDelimiter(args[0], context);
  8386. var parser = context.parser; // Parse out the implicit body
  8387. ++parser.leftrightDepth; // parseExpression stops before '\\right'
  8388. var body = parser.parseExpression(false);
  8389. --parser.leftrightDepth; // Check the next token
  8390. parser.expect("\\right", false);
  8391. var right = assertNodeType(parser.parseFunction(), "leftright-right");
  8392. return {
  8393. type: "leftright",
  8394. mode: parser.mode,
  8395. body,
  8396. left: delim.text,
  8397. right: right.delim,
  8398. rightColor: right.color
  8399. };
  8400. },
  8401. htmlBuilder: (group, options) => {
  8402. assertParsed(group); // Build the inner expression
  8403. var inner = buildExpression$1(group.body, options, true, ["mopen", "mclose"]);
  8404. var innerHeight = 0;
  8405. var innerDepth = 0;
  8406. var hadMiddle = false; // Calculate its height and depth
  8407. for (var i = 0; i < inner.length; i++) {
  8408. // Property `isMiddle` not defined on `span`. See comment in
  8409. // "middle"'s htmlBuilder.
  8410. // $FlowFixMe
  8411. if (inner[i].isMiddle) {
  8412. hadMiddle = true;
  8413. } else {
  8414. innerHeight = Math.max(inner[i].height, innerHeight);
  8415. innerDepth = Math.max(inner[i].depth, innerDepth);
  8416. }
  8417. } // The size of delimiters is the same, regardless of what style we are
  8418. // in. Thus, to correctly calculate the size of delimiter we need around
  8419. // a group, we scale down the inner size based on the size.
  8420. innerHeight *= options.sizeMultiplier;
  8421. innerDepth *= options.sizeMultiplier;
  8422. var leftDelim;
  8423. if (group.left === ".") {
  8424. // Empty delimiters in \left and \right make null delimiter spaces.
  8425. leftDelim = makeNullDelimiter(options, ["mopen"]);
  8426. } else {
  8427. // Otherwise, use leftRightDelim to generate the correct sized
  8428. // delimiter.
  8429. leftDelim = delimiter.leftRightDelim(group.left, innerHeight, innerDepth, options, group.mode, ["mopen"]);
  8430. } // Add it to the beginning of the expression
  8431. inner.unshift(leftDelim); // Handle middle delimiters
  8432. if (hadMiddle) {
  8433. for (var _i = 1; _i < inner.length; _i++) {
  8434. var middleDelim = inner[_i]; // Property `isMiddle` not defined on `span`. See comment in
  8435. // "middle"'s htmlBuilder.
  8436. // $FlowFixMe
  8437. var isMiddle = middleDelim.isMiddle;
  8438. if (isMiddle) {
  8439. // Apply the options that were active when \middle was called
  8440. inner[_i] = delimiter.leftRightDelim(isMiddle.delim, innerHeight, innerDepth, isMiddle.options, group.mode, []);
  8441. }
  8442. }
  8443. }
  8444. var rightDelim; // Same for the right delimiter, but using color specified by \color
  8445. if (group.right === ".") {
  8446. rightDelim = makeNullDelimiter(options, ["mclose"]);
  8447. } else {
  8448. var colorOptions = group.rightColor ? options.withColor(group.rightColor) : options;
  8449. rightDelim = delimiter.leftRightDelim(group.right, innerHeight, innerDepth, colorOptions, group.mode, ["mclose"]);
  8450. } // Add it to the end of the expression.
  8451. inner.push(rightDelim);
  8452. return buildCommon.makeSpan(["minner"], inner, options);
  8453. },
  8454. mathmlBuilder: (group, options) => {
  8455. assertParsed(group);
  8456. var inner = buildExpression(group.body, options);
  8457. if (group.left !== ".") {
  8458. var leftNode = new mathMLTree.MathNode("mo", [makeText(group.left, group.mode)]);
  8459. leftNode.setAttribute("fence", "true");
  8460. inner.unshift(leftNode);
  8461. }
  8462. if (group.right !== ".") {
  8463. var rightNode = new mathMLTree.MathNode("mo", [makeText(group.right, group.mode)]);
  8464. rightNode.setAttribute("fence", "true");
  8465. if (group.rightColor) {
  8466. rightNode.setAttribute("mathcolor", group.rightColor);
  8467. }
  8468. inner.push(rightNode);
  8469. }
  8470. return makeRow(inner);
  8471. }
  8472. });
  8473. defineFunction({
  8474. type: "middle",
  8475. names: ["\\middle"],
  8476. props: {
  8477. numArgs: 1,
  8478. primitive: true
  8479. },
  8480. handler: (context, args) => {
  8481. var delim = checkDelimiter(args[0], context);
  8482. if (!context.parser.leftrightDepth) {
  8483. throw new ParseError("\\middle without preceding \\left", delim);
  8484. }
  8485. return {
  8486. type: "middle",
  8487. mode: context.parser.mode,
  8488. delim: delim.text
  8489. };
  8490. },
  8491. htmlBuilder: (group, options) => {
  8492. var middleDelim;
  8493. if (group.delim === ".") {
  8494. middleDelim = makeNullDelimiter(options, []);
  8495. } else {
  8496. middleDelim = delimiter.sizedDelim(group.delim, 1, options, group.mode, []);
  8497. var isMiddle = {
  8498. delim: group.delim,
  8499. options
  8500. }; // Property `isMiddle` not defined on `span`. It is only used in
  8501. // this file above.
  8502. // TODO: Fix this violation of the `span` type and possibly rename
  8503. // things since `isMiddle` sounds like a boolean, but is a struct.
  8504. // $FlowFixMe
  8505. middleDelim.isMiddle = isMiddle;
  8506. }
  8507. return middleDelim;
  8508. },
  8509. mathmlBuilder: (group, options) => {
  8510. // A Firefox \middle will strech a character vertically only if it
  8511. // is in the fence part of the operator dictionary at:
  8512. // https://www.w3.org/TR/MathML3/appendixc.html.
  8513. // So we need to avoid U+2223 and use plain "|" instead.
  8514. var textNode = group.delim === "\\vert" || group.delim === "|" ? makeText("|", "text") : makeText(group.delim, group.mode);
  8515. var middleNode = new mathMLTree.MathNode("mo", [textNode]);
  8516. middleNode.setAttribute("fence", "true"); // MathML gives 5/18em spacing to each <mo> element.
  8517. // \middle should get delimiter spacing instead.
  8518. middleNode.setAttribute("lspace", "0.05em");
  8519. middleNode.setAttribute("rspace", "0.05em");
  8520. return middleNode;
  8521. }
  8522. });
  8523. var htmlBuilder$8 = (group, options) => {
  8524. // \cancel, \bcancel, \xcancel, \sout, \fbox, \colorbox, \fcolorbox, \phase
  8525. // Some groups can return document fragments. Handle those by wrapping
  8526. // them in a span.
  8527. var inner = buildCommon.wrapFragment(buildGroup$1(group.body, options), options);
  8528. var label = group.label.substr(1);
  8529. var scale = options.sizeMultiplier;
  8530. var img;
  8531. var imgShift = 0; // In the LaTeX cancel package, line geometry is slightly different
  8532. // depending on whether the subject is wider than it is tall, or vice versa.
  8533. // We don't know the width of a group, so as a proxy, we test if
  8534. // the subject is a single character. This captures most of the
  8535. // subjects that should get the "tall" treatment.
  8536. var isSingleChar = utils.isCharacterBox(group.body);
  8537. if (label === "sout") {
  8538. img = buildCommon.makeSpan(["stretchy", "sout"]);
  8539. img.height = options.fontMetrics().defaultRuleThickness / scale;
  8540. imgShift = -0.5 * options.fontMetrics().xHeight;
  8541. } else if (label === "phase") {
  8542. // Set a couple of dimensions from the steinmetz package.
  8543. var lineWeight = calculateSize({
  8544. number: 0.6,
  8545. unit: "pt"
  8546. }, options);
  8547. var clearance = calculateSize({
  8548. number: 0.35,
  8549. unit: "ex"
  8550. }, options); // Prevent size changes like \Huge from affecting line thickness
  8551. var newOptions = options.havingBaseSizing();
  8552. scale = scale / newOptions.sizeMultiplier;
  8553. var angleHeight = inner.height + inner.depth + lineWeight + clearance; // Reserve a left pad for the angle.
  8554. inner.style.paddingLeft = makeEm(angleHeight / 2 + lineWeight); // Create an SVG
  8555. var viewBoxHeight = Math.floor(1000 * angleHeight * scale);
  8556. var path = phasePath(viewBoxHeight);
  8557. var svgNode = new SvgNode([new PathNode("phase", path)], {
  8558. "width": "400em",
  8559. "height": makeEm(viewBoxHeight / 1000),
  8560. "viewBox": "0 0 400000 " + viewBoxHeight,
  8561. "preserveAspectRatio": "xMinYMin slice"
  8562. }); // Wrap it in a span with overflow: hidden.
  8563. img = buildCommon.makeSvgSpan(["hide-tail"], [svgNode], options);
  8564. img.style.height = makeEm(angleHeight);
  8565. imgShift = inner.depth + lineWeight + clearance;
  8566. } else {
  8567. // Add horizontal padding
  8568. if (/cancel/.test(label)) {
  8569. if (!isSingleChar) {
  8570. inner.classes.push("cancel-pad");
  8571. }
  8572. } else if (label === "angl") {
  8573. inner.classes.push("anglpad");
  8574. } else {
  8575. inner.classes.push("boxpad");
  8576. } // Add vertical padding
  8577. var topPad = 0;
  8578. var bottomPad = 0;
  8579. var ruleThickness = 0; // ref: cancel package: \advance\totalheight2\p@ % "+2"
  8580. if (/box/.test(label)) {
  8581. ruleThickness = Math.max(options.fontMetrics().fboxrule, // default
  8582. options.minRuleThickness // User override.
  8583. );
  8584. topPad = options.fontMetrics().fboxsep + (label === "colorbox" ? 0 : ruleThickness);
  8585. bottomPad = topPad;
  8586. } else if (label === "angl") {
  8587. ruleThickness = Math.max(options.fontMetrics().defaultRuleThickness, options.minRuleThickness);
  8588. topPad = 4 * ruleThickness; // gap = 3 × line, plus the line itself.
  8589. bottomPad = Math.max(0, 0.25 - inner.depth);
  8590. } else {
  8591. topPad = isSingleChar ? 0.2 : 0;
  8592. bottomPad = topPad;
  8593. }
  8594. img = stretchy.encloseSpan(inner, label, topPad, bottomPad, options);
  8595. if (/fbox|boxed|fcolorbox/.test(label)) {
  8596. img.style.borderStyle = "solid";
  8597. img.style.borderWidth = makeEm(ruleThickness);
  8598. } else if (label === "angl" && ruleThickness !== 0.049) {
  8599. img.style.borderTopWidth = makeEm(ruleThickness);
  8600. img.style.borderRightWidth = makeEm(ruleThickness);
  8601. }
  8602. imgShift = inner.depth + bottomPad;
  8603. if (group.backgroundColor) {
  8604. img.style.backgroundColor = group.backgroundColor;
  8605. if (group.borderColor) {
  8606. img.style.borderColor = group.borderColor;
  8607. }
  8608. }
  8609. }
  8610. var vlist;
  8611. if (group.backgroundColor) {
  8612. vlist = buildCommon.makeVList({
  8613. positionType: "individualShift",
  8614. children: [// Put the color background behind inner;
  8615. {
  8616. type: "elem",
  8617. elem: img,
  8618. shift: imgShift
  8619. }, {
  8620. type: "elem",
  8621. elem: inner,
  8622. shift: 0
  8623. }]
  8624. }, options);
  8625. } else {
  8626. var classes = /cancel|phase/.test(label) ? ["svg-align"] : [];
  8627. vlist = buildCommon.makeVList({
  8628. positionType: "individualShift",
  8629. children: [// Write the \cancel stroke on top of inner.
  8630. {
  8631. type: "elem",
  8632. elem: inner,
  8633. shift: 0
  8634. }, {
  8635. type: "elem",
  8636. elem: img,
  8637. shift: imgShift,
  8638. wrapperClasses: classes
  8639. }]
  8640. }, options);
  8641. }
  8642. if (/cancel/.test(label)) {
  8643. // The cancel package documentation says that cancel lines add their height
  8644. // to the expression, but tests show that isn't how it actually works.
  8645. vlist.height = inner.height;
  8646. vlist.depth = inner.depth;
  8647. }
  8648. if (/cancel/.test(label) && !isSingleChar) {
  8649. // cancel does not create horiz space for its line extension.
  8650. return buildCommon.makeSpan(["mord", "cancel-lap"], [vlist], options);
  8651. } else {
  8652. return buildCommon.makeSpan(["mord"], [vlist], options);
  8653. }
  8654. };
  8655. var mathmlBuilder$7 = (group, options) => {
  8656. var fboxsep = 0;
  8657. var node = new mathMLTree.MathNode(group.label.indexOf("colorbox") > -1 ? "mpadded" : "menclose", [buildGroup(group.body, options)]);
  8658. switch (group.label) {
  8659. case "\\cancel":
  8660. node.setAttribute("notation", "updiagonalstrike");
  8661. break;
  8662. case "\\bcancel":
  8663. node.setAttribute("notation", "downdiagonalstrike");
  8664. break;
  8665. case "\\phase":
  8666. node.setAttribute("notation", "phasorangle");
  8667. break;
  8668. case "\\sout":
  8669. node.setAttribute("notation", "horizontalstrike");
  8670. break;
  8671. case "\\fbox":
  8672. node.setAttribute("notation", "box");
  8673. break;
  8674. case "\\angl":
  8675. node.setAttribute("notation", "actuarial");
  8676. break;
  8677. case "\\fcolorbox":
  8678. case "\\colorbox":
  8679. // <menclose> doesn't have a good notation option. So use <mpadded>
  8680. // instead. Set some attributes that come included with <menclose>.
  8681. fboxsep = options.fontMetrics().fboxsep * options.fontMetrics().ptPerEm;
  8682. node.setAttribute("width", "+" + 2 * fboxsep + "pt");
  8683. node.setAttribute("height", "+" + 2 * fboxsep + "pt");
  8684. node.setAttribute("lspace", fboxsep + "pt"); //
  8685. node.setAttribute("voffset", fboxsep + "pt");
  8686. if (group.label === "\\fcolorbox") {
  8687. var thk = Math.max(options.fontMetrics().fboxrule, // default
  8688. options.minRuleThickness // user override
  8689. );
  8690. node.setAttribute("style", "border: " + thk + "em solid " + String(group.borderColor));
  8691. }
  8692. break;
  8693. case "\\xcancel":
  8694. node.setAttribute("notation", "updiagonalstrike downdiagonalstrike");
  8695. break;
  8696. }
  8697. if (group.backgroundColor) {
  8698. node.setAttribute("mathbackground", group.backgroundColor);
  8699. }
  8700. return node;
  8701. };
  8702. defineFunction({
  8703. type: "enclose",
  8704. names: ["\\colorbox"],
  8705. props: {
  8706. numArgs: 2,
  8707. allowedInText: true,
  8708. argTypes: ["color", "text"]
  8709. },
  8710. handler(_ref, args, optArgs) {
  8711. var {
  8712. parser,
  8713. funcName
  8714. } = _ref;
  8715. var color = assertNodeType(args[0], "color-token").color;
  8716. var body = args[1];
  8717. return {
  8718. type: "enclose",
  8719. mode: parser.mode,
  8720. label: funcName,
  8721. backgroundColor: color,
  8722. body
  8723. };
  8724. },
  8725. htmlBuilder: htmlBuilder$8,
  8726. mathmlBuilder: mathmlBuilder$7
  8727. });
  8728. defineFunction({
  8729. type: "enclose",
  8730. names: ["\\fcolorbox"],
  8731. props: {
  8732. numArgs: 3,
  8733. allowedInText: true,
  8734. argTypes: ["color", "color", "text"]
  8735. },
  8736. handler(_ref2, args, optArgs) {
  8737. var {
  8738. parser,
  8739. funcName
  8740. } = _ref2;
  8741. var borderColor = assertNodeType(args[0], "color-token").color;
  8742. var backgroundColor = assertNodeType(args[1], "color-token").color;
  8743. var body = args[2];
  8744. return {
  8745. type: "enclose",
  8746. mode: parser.mode,
  8747. label: funcName,
  8748. backgroundColor,
  8749. borderColor,
  8750. body
  8751. };
  8752. },
  8753. htmlBuilder: htmlBuilder$8,
  8754. mathmlBuilder: mathmlBuilder$7
  8755. });
  8756. defineFunction({
  8757. type: "enclose",
  8758. names: ["\\fbox"],
  8759. props: {
  8760. numArgs: 1,
  8761. argTypes: ["hbox"],
  8762. allowedInText: true
  8763. },
  8764. handler(_ref3, args) {
  8765. var {
  8766. parser
  8767. } = _ref3;
  8768. return {
  8769. type: "enclose",
  8770. mode: parser.mode,
  8771. label: "\\fbox",
  8772. body: args[0]
  8773. };
  8774. }
  8775. });
  8776. defineFunction({
  8777. type: "enclose",
  8778. names: ["\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\phase"],
  8779. props: {
  8780. numArgs: 1
  8781. },
  8782. handler(_ref4, args) {
  8783. var {
  8784. parser,
  8785. funcName
  8786. } = _ref4;
  8787. var body = args[0];
  8788. return {
  8789. type: "enclose",
  8790. mode: parser.mode,
  8791. label: funcName,
  8792. body
  8793. };
  8794. },
  8795. htmlBuilder: htmlBuilder$8,
  8796. mathmlBuilder: mathmlBuilder$7
  8797. });
  8798. defineFunction({
  8799. type: "enclose",
  8800. names: ["\\angl"],
  8801. props: {
  8802. numArgs: 1,
  8803. argTypes: ["hbox"],
  8804. allowedInText: false
  8805. },
  8806. handler(_ref5, args) {
  8807. var {
  8808. parser
  8809. } = _ref5;
  8810. return {
  8811. type: "enclose",
  8812. mode: parser.mode,
  8813. label: "\\angl",
  8814. body: args[0]
  8815. };
  8816. }
  8817. });
  8818. /**
  8819. * All registered environments.
  8820. * `environments.js` exports this same dictionary again and makes it public.
  8821. * `Parser.js` requires this dictionary via `environments.js`.
  8822. */
  8823. var _environments = {};
  8824. function defineEnvironment(_ref) {
  8825. var {
  8826. type,
  8827. names,
  8828. props,
  8829. handler,
  8830. htmlBuilder,
  8831. mathmlBuilder
  8832. } = _ref;
  8833. // Set default values of environments.
  8834. var data = {
  8835. type,
  8836. numArgs: props.numArgs || 0,
  8837. allowedInText: false,
  8838. numOptionalArgs: 0,
  8839. handler
  8840. };
  8841. for (var i = 0; i < names.length; ++i) {
  8842. // TODO: The value type of _environments should be a type union of all
  8843. // possible `EnvSpec<>` possibilities instead of `EnvSpec<*>`, which is
  8844. // an existential type.
  8845. _environments[names[i]] = data;
  8846. }
  8847. if (htmlBuilder) {
  8848. _htmlGroupBuilders[type] = htmlBuilder;
  8849. }
  8850. if (mathmlBuilder) {
  8851. _mathmlGroupBuilders[type] = mathmlBuilder;
  8852. }
  8853. }
  8854. /**
  8855. * All registered global/built-in macros.
  8856. * `macros.js` exports this same dictionary again and makes it public.
  8857. * `Parser.js` requires this dictionary via `macros.js`.
  8858. */
  8859. var _macros = {}; // This function might one day accept an additional argument and do more things.
  8860. function defineMacro(name, body) {
  8861. _macros[name] = body;
  8862. }
  8863. // Helper functions
  8864. function getHLines(parser) {
  8865. // Return an array. The array length = number of hlines.
  8866. // Each element in the array tells if the line is dashed.
  8867. var hlineInfo = [];
  8868. parser.consumeSpaces();
  8869. var nxt = parser.fetch().text;
  8870. while (nxt === "\\hline" || nxt === "\\hdashline") {
  8871. parser.consume();
  8872. hlineInfo.push(nxt === "\\hdashline");
  8873. parser.consumeSpaces();
  8874. nxt = parser.fetch().text;
  8875. }
  8876. return hlineInfo;
  8877. }
  8878. var validateAmsEnvironmentContext = context => {
  8879. var settings = context.parser.settings;
  8880. if (!settings.displayMode) {
  8881. throw new ParseError("{" + context.envName + "} can be used only in" + " display mode.");
  8882. }
  8883. }; // autoTag (an argument to parseArray) can be one of three values:
  8884. // * undefined: Regular (not-top-level) array; no tags on each row
  8885. // * true: Automatic equation numbering, overridable by \tag
  8886. // * false: Tags allowed on each row, but no automatic numbering
  8887. // This function *doesn't* work with the "split" environment name.
  8888. function getAutoTag(name) {
  8889. if (name.indexOf("ed") === -1) {
  8890. return name.indexOf("*") === -1;
  8891. } // return undefined;
  8892. }
  8893. /**
  8894. * Parse the body of the environment, with rows delimited by \\ and
  8895. * columns delimited by &, and create a nested list in row-major order
  8896. * with one group per cell. If given an optional argument style
  8897. * ("text", "display", etc.), then each cell is cast into that style.
  8898. */
  8899. function parseArray(parser, _ref, style) {
  8900. var {
  8901. hskipBeforeAndAfter,
  8902. addJot,
  8903. cols,
  8904. arraystretch,
  8905. colSeparationType,
  8906. autoTag,
  8907. singleRow,
  8908. emptySingleRow,
  8909. maxNumCols,
  8910. leqno
  8911. } = _ref;
  8912. parser.gullet.beginGroup();
  8913. if (!singleRow) {
  8914. // \cr is equivalent to \\ without the optional size argument (see below)
  8915. // TODO: provide helpful error when \cr is used outside array environment
  8916. parser.gullet.macros.set("\\cr", "\\\\\\relax");
  8917. } // Get current arraystretch if it's not set by the environment
  8918. if (!arraystretch) {
  8919. var stretch = parser.gullet.expandMacroAsText("\\arraystretch");
  8920. if (stretch == null) {
  8921. // Default \arraystretch from lttab.dtx
  8922. arraystretch = 1;
  8923. } else {
  8924. arraystretch = parseFloat(stretch);
  8925. if (!arraystretch || arraystretch < 0) {
  8926. throw new ParseError("Invalid \\arraystretch: " + stretch);
  8927. }
  8928. }
  8929. } // Start group for first cell
  8930. parser.gullet.beginGroup();
  8931. var row = [];
  8932. var body = [row];
  8933. var rowGaps = [];
  8934. var hLinesBeforeRow = [];
  8935. var tags = autoTag != null ? [] : undefined; // amsmath uses \global\@eqnswtrue and \global\@eqnswfalse to represent
  8936. // whether this row should have an equation number. Simulate this with
  8937. // a \@eqnsw macro set to 1 or 0.
  8938. function beginRow() {
  8939. if (autoTag) {
  8940. parser.gullet.macros.set("\\@eqnsw", "1", true);
  8941. }
  8942. }
  8943. function endRow() {
  8944. if (tags) {
  8945. if (parser.gullet.macros.get("\\df@tag")) {
  8946. tags.push(parser.subparse([new Token("\\df@tag")]));
  8947. parser.gullet.macros.set("\\df@tag", undefined, true);
  8948. } else {
  8949. tags.push(Boolean(autoTag) && parser.gullet.macros.get("\\@eqnsw") === "1");
  8950. }
  8951. }
  8952. }
  8953. beginRow(); // Test for \hline at the top of the array.
  8954. hLinesBeforeRow.push(getHLines(parser));
  8955. while (true) {
  8956. // eslint-disable-line no-constant-condition
  8957. // Parse each cell in its own group (namespace)
  8958. var cell = parser.parseExpression(false, singleRow ? "\\end" : "\\\\");
  8959. parser.gullet.endGroup();
  8960. parser.gullet.beginGroup();
  8961. cell = {
  8962. type: "ordgroup",
  8963. mode: parser.mode,
  8964. body: cell
  8965. };
  8966. if (style) {
  8967. cell = {
  8968. type: "styling",
  8969. mode: parser.mode,
  8970. style,
  8971. body: [cell]
  8972. };
  8973. }
  8974. row.push(cell);
  8975. var next = parser.fetch().text;
  8976. if (next === "&") {
  8977. if (maxNumCols && row.length === maxNumCols) {
  8978. if (singleRow || colSeparationType) {
  8979. // {equation} or {split}
  8980. throw new ParseError("Too many tab characters: &", parser.nextToken);
  8981. } else {
  8982. // {array} environment
  8983. parser.settings.reportNonstrict("textEnv", "Too few columns " + "specified in the {array} column argument.");
  8984. }
  8985. }
  8986. parser.consume();
  8987. } else if (next === "\\end") {
  8988. endRow(); // Arrays terminate newlines with `\crcr` which consumes a `\cr` if
  8989. // the last line is empty. However, AMS environments keep the
  8990. // empty row if it's the only one.
  8991. // NOTE: Currently, `cell` is the last item added into `row`.
  8992. if (row.length === 1 && cell.type === "styling" && cell.body[0].body.length === 0 && (body.length > 1 || !emptySingleRow)) {
  8993. body.pop();
  8994. }
  8995. if (hLinesBeforeRow.length < body.length + 1) {
  8996. hLinesBeforeRow.push([]);
  8997. }
  8998. break;
  8999. } else if (next === "\\\\") {
  9000. parser.consume();
  9001. var size = void 0; // \def\Let@{\let\\\math@cr}
  9002. // \def\math@cr{...\math@cr@}
  9003. // \def\math@cr@{\new@ifnextchar[\math@cr@@{\math@cr@@[\z@]}}
  9004. // \def\math@cr@@[#1]{...\math@cr@@@...}
  9005. // \def\math@cr@@@{\cr}
  9006. if (parser.gullet.future().text !== " ") {
  9007. size = parser.parseSizeGroup(true);
  9008. }
  9009. rowGaps.push(size ? size.value : null);
  9010. endRow(); // check for \hline(s) following the row separator
  9011. hLinesBeforeRow.push(getHLines(parser));
  9012. row = [];
  9013. body.push(row);
  9014. beginRow();
  9015. } else {
  9016. throw new ParseError("Expected & or \\\\ or \\cr or \\end", parser.nextToken);
  9017. }
  9018. } // End cell group
  9019. parser.gullet.endGroup(); // End array group defining \cr
  9020. parser.gullet.endGroup();
  9021. return {
  9022. type: "array",
  9023. mode: parser.mode,
  9024. addJot,
  9025. arraystretch,
  9026. body,
  9027. cols,
  9028. rowGaps,
  9029. hskipBeforeAndAfter,
  9030. hLinesBeforeRow,
  9031. colSeparationType,
  9032. tags,
  9033. leqno
  9034. };
  9035. } // Decides on a style for cells in an array according to whether the given
  9036. // environment name starts with the letter 'd'.
  9037. function dCellStyle(envName) {
  9038. if (envName.substr(0, 1) === "d") {
  9039. return "display";
  9040. } else {
  9041. return "text";
  9042. }
  9043. }
  9044. var htmlBuilder$7 = function htmlBuilder(group, options) {
  9045. var r;
  9046. var c;
  9047. var nr = group.body.length;
  9048. var hLinesBeforeRow = group.hLinesBeforeRow;
  9049. var nc = 0;
  9050. var body = new Array(nr);
  9051. var hlines = [];
  9052. var ruleThickness = Math.max( // From LaTeX \showthe\arrayrulewidth. Equals 0.04 em.
  9053. options.fontMetrics().arrayRuleWidth, options.minRuleThickness // User override.
  9054. ); // Horizontal spacing
  9055. var pt = 1 / options.fontMetrics().ptPerEm;
  9056. var arraycolsep = 5 * pt; // default value, i.e. \arraycolsep in article.cls
  9057. if (group.colSeparationType && group.colSeparationType === "small") {
  9058. // We're in a {smallmatrix}. Default column space is \thickspace,
  9059. // i.e. 5/18em = 0.2778em, per amsmath.dtx for {smallmatrix}.
  9060. // But that needs adjustment because LaTeX applies \scriptstyle to the
  9061. // entire array, including the colspace, but this function applies
  9062. // \scriptstyle only inside each element.
  9063. var localMultiplier = options.havingStyle(Style$1.SCRIPT).sizeMultiplier;
  9064. arraycolsep = 0.2778 * (localMultiplier / options.sizeMultiplier);
  9065. } // Vertical spacing
  9066. var baselineskip = group.colSeparationType === "CD" ? calculateSize({
  9067. number: 3,
  9068. unit: "ex"
  9069. }, options) : 12 * pt; // see size10.clo
  9070. // Default \jot from ltmath.dtx
  9071. // TODO(edemaine): allow overriding \jot via \setlength (#687)
  9072. var jot = 3 * pt;
  9073. var arrayskip = group.arraystretch * baselineskip;
  9074. var arstrutHeight = 0.7 * arrayskip; // \strutbox in ltfsstrc.dtx and
  9075. var arstrutDepth = 0.3 * arrayskip; // \@arstrutbox in lttab.dtx
  9076. var totalHeight = 0; // Set a position for \hline(s) at the top of the array, if any.
  9077. function setHLinePos(hlinesInGap) {
  9078. for (var i = 0; i < hlinesInGap.length; ++i) {
  9079. if (i > 0) {
  9080. totalHeight += 0.25;
  9081. }
  9082. hlines.push({
  9083. pos: totalHeight,
  9084. isDashed: hlinesInGap[i]
  9085. });
  9086. }
  9087. }
  9088. setHLinePos(hLinesBeforeRow[0]);
  9089. for (r = 0; r < group.body.length; ++r) {
  9090. var inrow = group.body[r];
  9091. var height = arstrutHeight; // \@array adds an \@arstrut
  9092. var depth = arstrutDepth; // to each tow (via the template)
  9093. if (nc < inrow.length) {
  9094. nc = inrow.length;
  9095. }
  9096. var outrow = new Array(inrow.length);
  9097. for (c = 0; c < inrow.length; ++c) {
  9098. var elt = buildGroup$1(inrow[c], options);
  9099. if (depth < elt.depth) {
  9100. depth = elt.depth;
  9101. }
  9102. if (height < elt.height) {
  9103. height = elt.height;
  9104. }
  9105. outrow[c] = elt;
  9106. }
  9107. var rowGap = group.rowGaps[r];
  9108. var gap = 0;
  9109. if (rowGap) {
  9110. gap = calculateSize(rowGap, options);
  9111. if (gap > 0) {
  9112. // \@argarraycr
  9113. gap += arstrutDepth;
  9114. if (depth < gap) {
  9115. depth = gap; // \@xargarraycr
  9116. }
  9117. gap = 0;
  9118. }
  9119. } // In AMS multiline environments such as aligned and gathered, rows
  9120. // correspond to lines that have additional \jot added to the
  9121. // \baselineskip via \openup.
  9122. if (group.addJot) {
  9123. depth += jot;
  9124. }
  9125. outrow.height = height;
  9126. outrow.depth = depth;
  9127. totalHeight += height;
  9128. outrow.pos = totalHeight;
  9129. totalHeight += depth + gap; // \@yargarraycr
  9130. body[r] = outrow; // Set a position for \hline(s), if any.
  9131. setHLinePos(hLinesBeforeRow[r + 1]);
  9132. }
  9133. var offset = totalHeight / 2 + options.fontMetrics().axisHeight;
  9134. var colDescriptions = group.cols || [];
  9135. var cols = [];
  9136. var colSep;
  9137. var colDescrNum;
  9138. var tagSpans = [];
  9139. if (group.tags && group.tags.some(tag => tag)) {
  9140. // An environment with manual tags and/or automatic equation numbers.
  9141. // Create node(s), the latter of which trigger CSS counter increment.
  9142. for (r = 0; r < nr; ++r) {
  9143. var rw = body[r];
  9144. var shift = rw.pos - offset;
  9145. var tag = group.tags[r];
  9146. var tagSpan = void 0;
  9147. if (tag === true) {
  9148. // automatic numbering
  9149. tagSpan = buildCommon.makeSpan(["eqn-num"], [], options);
  9150. } else if (tag === false) {
  9151. // \nonumber/\notag or starred environment
  9152. tagSpan = buildCommon.makeSpan([], [], options);
  9153. } else {
  9154. // manual \tag
  9155. tagSpan = buildCommon.makeSpan([], buildExpression$1(tag, options, true), options);
  9156. }
  9157. tagSpan.depth = rw.depth;
  9158. tagSpan.height = rw.height;
  9159. tagSpans.push({
  9160. type: "elem",
  9161. elem: tagSpan,
  9162. shift
  9163. });
  9164. }
  9165. }
  9166. for (c = 0, colDescrNum = 0; // Continue while either there are more columns or more column
  9167. // descriptions, so trailing separators don't get lost.
  9168. c < nc || colDescrNum < colDescriptions.length; ++c, ++colDescrNum) {
  9169. var colDescr = colDescriptions[colDescrNum] || {};
  9170. var firstSeparator = true;
  9171. while (colDescr.type === "separator") {
  9172. // If there is more than one separator in a row, add a space
  9173. // between them.
  9174. if (!firstSeparator) {
  9175. colSep = buildCommon.makeSpan(["arraycolsep"], []);
  9176. colSep.style.width = makeEm(options.fontMetrics().doubleRuleSep);
  9177. cols.push(colSep);
  9178. }
  9179. if (colDescr.separator === "|" || colDescr.separator === ":") {
  9180. var lineType = colDescr.separator === "|" ? "solid" : "dashed";
  9181. var separator = buildCommon.makeSpan(["vertical-separator"], [], options);
  9182. separator.style.height = makeEm(totalHeight);
  9183. separator.style.borderRightWidth = makeEm(ruleThickness);
  9184. separator.style.borderRightStyle = lineType;
  9185. separator.style.margin = "0 " + makeEm(-ruleThickness / 2);
  9186. var _shift = totalHeight - offset;
  9187. if (_shift) {
  9188. separator.style.verticalAlign = makeEm(-_shift);
  9189. }
  9190. cols.push(separator);
  9191. } else {
  9192. throw new ParseError("Invalid separator type: " + colDescr.separator);
  9193. }
  9194. colDescrNum++;
  9195. colDescr = colDescriptions[colDescrNum] || {};
  9196. firstSeparator = false;
  9197. }
  9198. if (c >= nc) {
  9199. continue;
  9200. }
  9201. var sepwidth = void 0;
  9202. if (c > 0 || group.hskipBeforeAndAfter) {
  9203. sepwidth = utils.deflt(colDescr.pregap, arraycolsep);
  9204. if (sepwidth !== 0) {
  9205. colSep = buildCommon.makeSpan(["arraycolsep"], []);
  9206. colSep.style.width = makeEm(sepwidth);
  9207. cols.push(colSep);
  9208. }
  9209. }
  9210. var col = [];
  9211. for (r = 0; r < nr; ++r) {
  9212. var row = body[r];
  9213. var elem = row[c];
  9214. if (!elem) {
  9215. continue;
  9216. }
  9217. var _shift2 = row.pos - offset;
  9218. elem.depth = row.depth;
  9219. elem.height = row.height;
  9220. col.push({
  9221. type: "elem",
  9222. elem: elem,
  9223. shift: _shift2
  9224. });
  9225. }
  9226. col = buildCommon.makeVList({
  9227. positionType: "individualShift",
  9228. children: col
  9229. }, options);
  9230. col = buildCommon.makeSpan(["col-align-" + (colDescr.align || "c")], [col]);
  9231. cols.push(col);
  9232. if (c < nc - 1 || group.hskipBeforeAndAfter) {
  9233. sepwidth = utils.deflt(colDescr.postgap, arraycolsep);
  9234. if (sepwidth !== 0) {
  9235. colSep = buildCommon.makeSpan(["arraycolsep"], []);
  9236. colSep.style.width = makeEm(sepwidth);
  9237. cols.push(colSep);
  9238. }
  9239. }
  9240. }
  9241. body = buildCommon.makeSpan(["mtable"], cols); // Add \hline(s), if any.
  9242. if (hlines.length > 0) {
  9243. var line = buildCommon.makeLineSpan("hline", options, ruleThickness);
  9244. var dashes = buildCommon.makeLineSpan("hdashline", options, ruleThickness);
  9245. var vListElems = [{
  9246. type: "elem",
  9247. elem: body,
  9248. shift: 0
  9249. }];
  9250. while (hlines.length > 0) {
  9251. var hline = hlines.pop();
  9252. var lineShift = hline.pos - offset;
  9253. if (hline.isDashed) {
  9254. vListElems.push({
  9255. type: "elem",
  9256. elem: dashes,
  9257. shift: lineShift
  9258. });
  9259. } else {
  9260. vListElems.push({
  9261. type: "elem",
  9262. elem: line,
  9263. shift: lineShift
  9264. });
  9265. }
  9266. }
  9267. body = buildCommon.makeVList({
  9268. positionType: "individualShift",
  9269. children: vListElems
  9270. }, options);
  9271. }
  9272. if (tagSpans.length === 0) {
  9273. return buildCommon.makeSpan(["mord"], [body], options);
  9274. } else {
  9275. var eqnNumCol = buildCommon.makeVList({
  9276. positionType: "individualShift",
  9277. children: tagSpans
  9278. }, options);
  9279. eqnNumCol = buildCommon.makeSpan(["tag"], [eqnNumCol], options);
  9280. return buildCommon.makeFragment([body, eqnNumCol]);
  9281. }
  9282. };
  9283. var alignMap = {
  9284. c: "center ",
  9285. l: "left ",
  9286. r: "right "
  9287. };
  9288. var mathmlBuilder$6 = function mathmlBuilder(group, options) {
  9289. var tbl = [];
  9290. var glue = new mathMLTree.MathNode("mtd", [], ["mtr-glue"]);
  9291. var tag = new mathMLTree.MathNode("mtd", [], ["mml-eqn-num"]);
  9292. for (var i = 0; i < group.body.length; i++) {
  9293. var rw = group.body[i];
  9294. var row = [];
  9295. for (var j = 0; j < rw.length; j++) {
  9296. row.push(new mathMLTree.MathNode("mtd", [buildGroup(rw[j], options)]));
  9297. }
  9298. if (group.tags && group.tags[i]) {
  9299. row.unshift(glue);
  9300. row.push(glue);
  9301. if (group.leqno) {
  9302. row.unshift(tag);
  9303. } else {
  9304. row.push(tag);
  9305. }
  9306. }
  9307. tbl.push(new mathMLTree.MathNode("mtr", row));
  9308. }
  9309. var table = new mathMLTree.MathNode("mtable", tbl); // Set column alignment, row spacing, column spacing, and
  9310. // array lines by setting attributes on the table element.
  9311. // Set the row spacing. In MathML, we specify a gap distance.
  9312. // We do not use rowGap[] because MathML automatically increases
  9313. // cell height with the height/depth of the element content.
  9314. // LaTeX \arraystretch multiplies the row baseline-to-baseline distance.
  9315. // We simulate this by adding (arraystretch - 1)em to the gap. This
  9316. // does a reasonable job of adjusting arrays containing 1 em tall content.
  9317. // The 0.16 and 0.09 values are found emprically. They produce an array
  9318. // similar to LaTeX and in which content does not interfere with \hines.
  9319. var gap = group.arraystretch === 0.5 ? 0.1 // {smallmatrix}, {subarray}
  9320. : 0.16 + group.arraystretch - 1 + (group.addJot ? 0.09 : 0);
  9321. table.setAttribute("rowspacing", makeEm(gap)); // MathML table lines go only between cells.
  9322. // To place a line on an edge we'll use <menclose>, if necessary.
  9323. var menclose = "";
  9324. var align = "";
  9325. if (group.cols && group.cols.length > 0) {
  9326. // Find column alignment, column spacing, and vertical lines.
  9327. var cols = group.cols;
  9328. var columnLines = "";
  9329. var prevTypeWasAlign = false;
  9330. var iStart = 0;
  9331. var iEnd = cols.length;
  9332. if (cols[0].type === "separator") {
  9333. menclose += "top ";
  9334. iStart = 1;
  9335. }
  9336. if (cols[cols.length - 1].type === "separator") {
  9337. menclose += "bottom ";
  9338. iEnd -= 1;
  9339. }
  9340. for (var _i = iStart; _i < iEnd; _i++) {
  9341. if (cols[_i].type === "align") {
  9342. align += alignMap[cols[_i].align];
  9343. if (prevTypeWasAlign) {
  9344. columnLines += "none ";
  9345. }
  9346. prevTypeWasAlign = true;
  9347. } else if (cols[_i].type === "separator") {
  9348. // MathML accepts only single lines between cells.
  9349. // So we read only the first of consecutive separators.
  9350. if (prevTypeWasAlign) {
  9351. columnLines += cols[_i].separator === "|" ? "solid " : "dashed ";
  9352. prevTypeWasAlign = false;
  9353. }
  9354. }
  9355. }
  9356. table.setAttribute("columnalign", align.trim());
  9357. if (/[sd]/.test(columnLines)) {
  9358. table.setAttribute("columnlines", columnLines.trim());
  9359. }
  9360. } // Set column spacing.
  9361. if (group.colSeparationType === "align") {
  9362. var _cols = group.cols || [];
  9363. var spacing = "";
  9364. for (var _i2 = 1; _i2 < _cols.length; _i2++) {
  9365. spacing += _i2 % 2 ? "0em " : "1em ";
  9366. }
  9367. table.setAttribute("columnspacing", spacing.trim());
  9368. } else if (group.colSeparationType === "alignat" || group.colSeparationType === "gather") {
  9369. table.setAttribute("columnspacing", "0em");
  9370. } else if (group.colSeparationType === "small") {
  9371. table.setAttribute("columnspacing", "0.2778em");
  9372. } else if (group.colSeparationType === "CD") {
  9373. table.setAttribute("columnspacing", "0.5em");
  9374. } else {
  9375. table.setAttribute("columnspacing", "1em");
  9376. } // Address \hline and \hdashline
  9377. var rowLines = "";
  9378. var hlines = group.hLinesBeforeRow;
  9379. menclose += hlines[0].length > 0 ? "left " : "";
  9380. menclose += hlines[hlines.length - 1].length > 0 ? "right " : "";
  9381. for (var _i3 = 1; _i3 < hlines.length - 1; _i3++) {
  9382. rowLines += hlines[_i3].length === 0 ? "none " // MathML accepts only a single line between rows. Read one element.
  9383. : hlines[_i3][0] ? "dashed " : "solid ";
  9384. }
  9385. if (/[sd]/.test(rowLines)) {
  9386. table.setAttribute("rowlines", rowLines.trim());
  9387. }
  9388. if (menclose !== "") {
  9389. table = new mathMLTree.MathNode("menclose", [table]);
  9390. table.setAttribute("notation", menclose.trim());
  9391. }
  9392. if (group.arraystretch && group.arraystretch < 1) {
  9393. // A small array. Wrap in scriptstyle so row gap is not too large.
  9394. table = new mathMLTree.MathNode("mstyle", [table]);
  9395. table.setAttribute("scriptlevel", "1");
  9396. }
  9397. return table;
  9398. }; // Convenience function for align, align*, aligned, alignat, alignat*, alignedat.
  9399. var alignedHandler = function alignedHandler(context, args) {
  9400. if (context.envName.indexOf("ed") === -1) {
  9401. validateAmsEnvironmentContext(context);
  9402. }
  9403. var cols = [];
  9404. var separationType = context.envName.indexOf("at") > -1 ? "alignat" : "align";
  9405. var isSplit = context.envName === "split";
  9406. var res = parseArray(context.parser, {
  9407. cols,
  9408. addJot: true,
  9409. autoTag: isSplit ? undefined : getAutoTag(context.envName),
  9410. emptySingleRow: true,
  9411. colSeparationType: separationType,
  9412. maxNumCols: isSplit ? 2 : undefined,
  9413. leqno: context.parser.settings.leqno
  9414. }, "display"); // Determining number of columns.
  9415. // 1. If the first argument is given, we use it as a number of columns,
  9416. // and makes sure that each row doesn't exceed that number.
  9417. // 2. Otherwise, just count number of columns = maximum number
  9418. // of cells in each row ("aligned" mode -- isAligned will be true).
  9419. //
  9420. // At the same time, prepend empty group {} at beginning of every second
  9421. // cell in each row (starting with second cell) so that operators become
  9422. // binary. This behavior is implemented in amsmath's \start@aligned.
  9423. var numMaths;
  9424. var numCols = 0;
  9425. var emptyGroup = {
  9426. type: "ordgroup",
  9427. mode: context.mode,
  9428. body: []
  9429. };
  9430. if (args[0] && args[0].type === "ordgroup") {
  9431. var arg0 = "";
  9432. for (var i = 0; i < args[0].body.length; i++) {
  9433. var textord = assertNodeType(args[0].body[i], "textord");
  9434. arg0 += textord.text;
  9435. }
  9436. numMaths = Number(arg0);
  9437. numCols = numMaths * 2;
  9438. }
  9439. var isAligned = !numCols;
  9440. res.body.forEach(function (row) {
  9441. for (var _i4 = 1; _i4 < row.length; _i4 += 2) {
  9442. // Modify ordgroup node within styling node
  9443. var styling = assertNodeType(row[_i4], "styling");
  9444. var ordgroup = assertNodeType(styling.body[0], "ordgroup");
  9445. ordgroup.body.unshift(emptyGroup);
  9446. }
  9447. if (!isAligned) {
  9448. // Case 1
  9449. var curMaths = row.length / 2;
  9450. if (numMaths < curMaths) {
  9451. throw new ParseError("Too many math in a row: " + ("expected " + numMaths + ", but got " + curMaths), row[0]);
  9452. }
  9453. } else if (numCols < row.length) {
  9454. // Case 2
  9455. numCols = row.length;
  9456. }
  9457. }); // Adjusting alignment.
  9458. // In aligned mode, we add one \qquad between columns;
  9459. // otherwise we add nothing.
  9460. for (var _i5 = 0; _i5 < numCols; ++_i5) {
  9461. var align = "r";
  9462. var pregap = 0;
  9463. if (_i5 % 2 === 1) {
  9464. align = "l";
  9465. } else if (_i5 > 0 && isAligned) {
  9466. // "aligned" mode.
  9467. pregap = 1; // add one \quad
  9468. }
  9469. cols[_i5] = {
  9470. type: "align",
  9471. align: align,
  9472. pregap: pregap,
  9473. postgap: 0
  9474. };
  9475. }
  9476. res.colSeparationType = isAligned ? "align" : "alignat";
  9477. return res;
  9478. }; // Arrays are part of LaTeX, defined in lttab.dtx so its documentation
  9479. // is part of the source2e.pdf file of LaTeX2e source documentation.
  9480. // {darray} is an {array} environment where cells are set in \displaystyle,
  9481. // as defined in nccmath.sty.
  9482. defineEnvironment({
  9483. type: "array",
  9484. names: ["array", "darray"],
  9485. props: {
  9486. numArgs: 1
  9487. },
  9488. handler(context, args) {
  9489. // Since no types are specified above, the two possibilities are
  9490. // - The argument is wrapped in {} or [], in which case Parser's
  9491. // parseGroup() returns an "ordgroup" wrapping some symbol node.
  9492. // - The argument is a bare symbol node.
  9493. var symNode = checkSymbolNodeType(args[0]);
  9494. var colalign = symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body;
  9495. var cols = colalign.map(function (nde) {
  9496. var node = assertSymbolNodeType(nde);
  9497. var ca = node.text;
  9498. if ("lcr".indexOf(ca) !== -1) {
  9499. return {
  9500. type: "align",
  9501. align: ca
  9502. };
  9503. } else if (ca === "|") {
  9504. return {
  9505. type: "separator",
  9506. separator: "|"
  9507. };
  9508. } else if (ca === ":") {
  9509. return {
  9510. type: "separator",
  9511. separator: ":"
  9512. };
  9513. }
  9514. throw new ParseError("Unknown column alignment: " + ca, nde);
  9515. });
  9516. var res = {
  9517. cols,
  9518. hskipBeforeAndAfter: true,
  9519. // \@preamble in lttab.dtx
  9520. maxNumCols: cols.length
  9521. };
  9522. return parseArray(context.parser, res, dCellStyle(context.envName));
  9523. },
  9524. htmlBuilder: htmlBuilder$7,
  9525. mathmlBuilder: mathmlBuilder$6
  9526. }); // The matrix environments of amsmath builds on the array environment
  9527. // of LaTeX, which is discussed above.
  9528. // The mathtools package adds starred versions of the same environments.
  9529. // These have an optional argument to choose left|center|right justification.
  9530. defineEnvironment({
  9531. type: "array",
  9532. names: ["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix", "matrix*", "pmatrix*", "bmatrix*", "Bmatrix*", "vmatrix*", "Vmatrix*"],
  9533. props: {
  9534. numArgs: 0
  9535. },
  9536. handler(context) {
  9537. var delimiters = {
  9538. "matrix": null,
  9539. "pmatrix": ["(", ")"],
  9540. "bmatrix": ["[", "]"],
  9541. "Bmatrix": ["\\{", "\\}"],
  9542. "vmatrix": ["|", "|"],
  9543. "Vmatrix": ["\\Vert", "\\Vert"]
  9544. }[context.envName.replace("*", "")]; // \hskip -\arraycolsep in amsmath
  9545. var colAlign = "c";
  9546. var payload = {
  9547. hskipBeforeAndAfter: false,
  9548. cols: [{
  9549. type: "align",
  9550. align: colAlign
  9551. }]
  9552. };
  9553. if (context.envName.charAt(context.envName.length - 1) === "*") {
  9554. // It's one of the mathtools starred functions.
  9555. // Parse the optional alignment argument.
  9556. var parser = context.parser;
  9557. parser.consumeSpaces();
  9558. if (parser.fetch().text === "[") {
  9559. parser.consume();
  9560. parser.consumeSpaces();
  9561. colAlign = parser.fetch().text;
  9562. if ("lcr".indexOf(colAlign) === -1) {
  9563. throw new ParseError("Expected l or c or r", parser.nextToken);
  9564. }
  9565. parser.consume();
  9566. parser.consumeSpaces();
  9567. parser.expect("]");
  9568. parser.consume();
  9569. payload.cols = [{
  9570. type: "align",
  9571. align: colAlign
  9572. }];
  9573. }
  9574. }
  9575. var res = parseArray(context.parser, payload, dCellStyle(context.envName)); // Populate cols with the correct number of column alignment specs.
  9576. var numCols = Math.max(0, ...res.body.map(row => row.length));
  9577. res.cols = new Array(numCols).fill({
  9578. type: "align",
  9579. align: colAlign
  9580. });
  9581. return delimiters ? {
  9582. type: "leftright",
  9583. mode: context.mode,
  9584. body: [res],
  9585. left: delimiters[0],
  9586. right: delimiters[1],
  9587. rightColor: undefined // \right uninfluenced by \color in array
  9588. } : res;
  9589. },
  9590. htmlBuilder: htmlBuilder$7,
  9591. mathmlBuilder: mathmlBuilder$6
  9592. });
  9593. defineEnvironment({
  9594. type: "array",
  9595. names: ["smallmatrix"],
  9596. props: {
  9597. numArgs: 0
  9598. },
  9599. handler(context) {
  9600. var payload = {
  9601. arraystretch: 0.5
  9602. };
  9603. var res = parseArray(context.parser, payload, "script");
  9604. res.colSeparationType = "small";
  9605. return res;
  9606. },
  9607. htmlBuilder: htmlBuilder$7,
  9608. mathmlBuilder: mathmlBuilder$6
  9609. });
  9610. defineEnvironment({
  9611. type: "array",
  9612. names: ["subarray"],
  9613. props: {
  9614. numArgs: 1
  9615. },
  9616. handler(context, args) {
  9617. // Parsing of {subarray} is similar to {array}
  9618. var symNode = checkSymbolNodeType(args[0]);
  9619. var colalign = symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body;
  9620. var cols = colalign.map(function (nde) {
  9621. var node = assertSymbolNodeType(nde);
  9622. var ca = node.text; // {subarray} only recognizes "l" & "c"
  9623. if ("lc".indexOf(ca) !== -1) {
  9624. return {
  9625. type: "align",
  9626. align: ca
  9627. };
  9628. }
  9629. throw new ParseError("Unknown column alignment: " + ca, nde);
  9630. });
  9631. if (cols.length > 1) {
  9632. throw new ParseError("{subarray} can contain only one column");
  9633. }
  9634. var res = {
  9635. cols,
  9636. hskipBeforeAndAfter: false,
  9637. arraystretch: 0.5
  9638. };
  9639. res = parseArray(context.parser, res, "script");
  9640. if (res.body.length > 0 && res.body[0].length > 1) {
  9641. throw new ParseError("{subarray} can contain only one column");
  9642. }
  9643. return res;
  9644. },
  9645. htmlBuilder: htmlBuilder$7,
  9646. mathmlBuilder: mathmlBuilder$6
  9647. }); // A cases environment (in amsmath.sty) is almost equivalent to
  9648. // \def\arraystretch{1.2}%
  9649. // \left\{\begin{array}{@{}l@{\quad}l@{}} … \end{array}\right.
  9650. // {dcases} is a {cases} environment where cells are set in \displaystyle,
  9651. // as defined in mathtools.sty.
  9652. // {rcases} is another mathtools environment. It's brace is on the right side.
  9653. defineEnvironment({
  9654. type: "array",
  9655. names: ["cases", "dcases", "rcases", "drcases"],
  9656. props: {
  9657. numArgs: 0
  9658. },
  9659. handler(context) {
  9660. var payload = {
  9661. arraystretch: 1.2,
  9662. cols: [{
  9663. type: "align",
  9664. align: "l",
  9665. pregap: 0,
  9666. // TODO(kevinb) get the current style.
  9667. // For now we use the metrics for TEXT style which is what we were
  9668. // doing before. Before attempting to get the current style we
  9669. // should look at TeX's behavior especially for \over and matrices.
  9670. postgap: 1.0
  9671. /* 1em quad */
  9672. }, {
  9673. type: "align",
  9674. align: "l",
  9675. pregap: 0,
  9676. postgap: 0
  9677. }]
  9678. };
  9679. var res = parseArray(context.parser, payload, dCellStyle(context.envName));
  9680. return {
  9681. type: "leftright",
  9682. mode: context.mode,
  9683. body: [res],
  9684. left: context.envName.indexOf("r") > -1 ? "." : "\\{",
  9685. right: context.envName.indexOf("r") > -1 ? "\\}" : ".",
  9686. rightColor: undefined
  9687. };
  9688. },
  9689. htmlBuilder: htmlBuilder$7,
  9690. mathmlBuilder: mathmlBuilder$6
  9691. }); // In the align environment, one uses ampersands, &, to specify number of
  9692. // columns in each row, and to locate spacing between each column.
  9693. // align gets automatic numbering. align* and aligned do not.
  9694. // The alignedat environment can be used in math mode.
  9695. // Note that we assume \nomallineskiplimit to be zero,
  9696. // so that \strut@ is the same as \strut.
  9697. defineEnvironment({
  9698. type: "array",
  9699. names: ["align", "align*", "aligned", "split"],
  9700. props: {
  9701. numArgs: 0
  9702. },
  9703. handler: alignedHandler,
  9704. htmlBuilder: htmlBuilder$7,
  9705. mathmlBuilder: mathmlBuilder$6
  9706. }); // A gathered environment is like an array environment with one centered
  9707. // column, but where rows are considered lines so get \jot line spacing
  9708. // and contents are set in \displaystyle.
  9709. defineEnvironment({
  9710. type: "array",
  9711. names: ["gathered", "gather", "gather*"],
  9712. props: {
  9713. numArgs: 0
  9714. },
  9715. handler(context) {
  9716. if (utils.contains(["gather", "gather*"], context.envName)) {
  9717. validateAmsEnvironmentContext(context);
  9718. }
  9719. var res = {
  9720. cols: [{
  9721. type: "align",
  9722. align: "c"
  9723. }],
  9724. addJot: true,
  9725. colSeparationType: "gather",
  9726. autoTag: getAutoTag(context.envName),
  9727. emptySingleRow: true,
  9728. leqno: context.parser.settings.leqno
  9729. };
  9730. return parseArray(context.parser, res, "display");
  9731. },
  9732. htmlBuilder: htmlBuilder$7,
  9733. mathmlBuilder: mathmlBuilder$6
  9734. }); // alignat environment is like an align environment, but one must explicitly
  9735. // specify maximum number of columns in each row, and can adjust spacing between
  9736. // each columns.
  9737. defineEnvironment({
  9738. type: "array",
  9739. names: ["alignat", "alignat*", "alignedat"],
  9740. props: {
  9741. numArgs: 1
  9742. },
  9743. handler: alignedHandler,
  9744. htmlBuilder: htmlBuilder$7,
  9745. mathmlBuilder: mathmlBuilder$6
  9746. });
  9747. defineEnvironment({
  9748. type: "array",
  9749. names: ["equation", "equation*"],
  9750. props: {
  9751. numArgs: 0
  9752. },
  9753. handler(context) {
  9754. validateAmsEnvironmentContext(context);
  9755. var res = {
  9756. autoTag: getAutoTag(context.envName),
  9757. emptySingleRow: true,
  9758. singleRow: true,
  9759. maxNumCols: 1,
  9760. leqno: context.parser.settings.leqno
  9761. };
  9762. return parseArray(context.parser, res, "display");
  9763. },
  9764. htmlBuilder: htmlBuilder$7,
  9765. mathmlBuilder: mathmlBuilder$6
  9766. });
  9767. defineEnvironment({
  9768. type: "array",
  9769. names: ["CD"],
  9770. props: {
  9771. numArgs: 0
  9772. },
  9773. handler(context) {
  9774. validateAmsEnvironmentContext(context);
  9775. return parseCD(context.parser);
  9776. },
  9777. htmlBuilder: htmlBuilder$7,
  9778. mathmlBuilder: mathmlBuilder$6
  9779. });
  9780. defineMacro("\\nonumber", "\\gdef\\@eqnsw{0}");
  9781. defineMacro("\\notag", "\\nonumber"); // Catch \hline outside array environment
  9782. defineFunction({
  9783. type: "text",
  9784. // Doesn't matter what this is.
  9785. names: ["\\hline", "\\hdashline"],
  9786. props: {
  9787. numArgs: 0,
  9788. allowedInText: true,
  9789. allowedInMath: true
  9790. },
  9791. handler(context, args) {
  9792. throw new ParseError(context.funcName + " valid only within array environment");
  9793. }
  9794. });
  9795. var environments = _environments;
  9796. // defineEnvironment definitions.
  9797. defineFunction({
  9798. type: "environment",
  9799. names: ["\\begin", "\\end"],
  9800. props: {
  9801. numArgs: 1,
  9802. argTypes: ["text"]
  9803. },
  9804. handler(_ref, args) {
  9805. var {
  9806. parser,
  9807. funcName
  9808. } = _ref;
  9809. var nameGroup = args[0];
  9810. if (nameGroup.type !== "ordgroup") {
  9811. throw new ParseError("Invalid environment name", nameGroup);
  9812. }
  9813. var envName = "";
  9814. for (var i = 0; i < nameGroup.body.length; ++i) {
  9815. envName += assertNodeType(nameGroup.body[i], "textord").text;
  9816. }
  9817. if (funcName === "\\begin") {
  9818. // begin...end is similar to left...right
  9819. if (!environments.hasOwnProperty(envName)) {
  9820. throw new ParseError("No such environment: " + envName, nameGroup);
  9821. } // Build the environment object. Arguments and other information will
  9822. // be made available to the begin and end methods using properties.
  9823. var env = environments[envName];
  9824. var {
  9825. args: _args,
  9826. optArgs
  9827. } = parser.parseArguments("\\begin{" + envName + "}", env);
  9828. var context = {
  9829. mode: parser.mode,
  9830. envName,
  9831. parser
  9832. };
  9833. var result = env.handler(context, _args, optArgs);
  9834. parser.expect("\\end", false);
  9835. var endNameToken = parser.nextToken;
  9836. var end = assertNodeType(parser.parseFunction(), "environment");
  9837. if (end.name !== envName) {
  9838. throw new ParseError("Mismatch: \\begin{" + envName + "} matched by \\end{" + end.name + "}", endNameToken);
  9839. } // $FlowFixMe, "environment" handler returns an environment ParseNode
  9840. return result;
  9841. }
  9842. return {
  9843. type: "environment",
  9844. mode: parser.mode,
  9845. name: envName,
  9846. nameGroup
  9847. };
  9848. }
  9849. });
  9850. var makeSpan = buildCommon.makeSpan;
  9851. function htmlBuilder$6(group, options) {
  9852. var elements = buildExpression$1(group.body, options, true);
  9853. return makeSpan([group.mclass], elements, options);
  9854. }
  9855. function mathmlBuilder$5(group, options) {
  9856. var node;
  9857. var inner = buildExpression(group.body, options);
  9858. if (group.mclass === "minner") {
  9859. node = new mathMLTree.MathNode("mpadded", inner);
  9860. } else if (group.mclass === "mord") {
  9861. if (group.isCharacterBox) {
  9862. node = inner[0];
  9863. node.type = "mi";
  9864. } else {
  9865. node = new mathMLTree.MathNode("mi", inner);
  9866. }
  9867. } else {
  9868. if (group.isCharacterBox) {
  9869. node = inner[0];
  9870. node.type = "mo";
  9871. } else {
  9872. node = new mathMLTree.MathNode("mo", inner);
  9873. } // Set spacing based on what is the most likely adjacent atom type.
  9874. // See TeXbook p170.
  9875. if (group.mclass === "mbin") {
  9876. node.attributes.lspace = "0.22em"; // medium space
  9877. node.attributes.rspace = "0.22em";
  9878. } else if (group.mclass === "mpunct") {
  9879. node.attributes.lspace = "0em";
  9880. node.attributes.rspace = "0.17em"; // thinspace
  9881. } else if (group.mclass === "mopen" || group.mclass === "mclose") {
  9882. node.attributes.lspace = "0em";
  9883. node.attributes.rspace = "0em";
  9884. } else if (group.mclass === "minner") {
  9885. node.attributes.lspace = "0.0556em"; // 1 mu is the most likely option
  9886. node.attributes.width = "+0.1111em";
  9887. } // MathML <mo> default space is 5/18 em, so <mrel> needs no action.
  9888. // Ref: https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo
  9889. }
  9890. return node;
  9891. } // Math class commands except \mathop
  9892. defineFunction({
  9893. type: "mclass",
  9894. names: ["\\mathord", "\\mathbin", "\\mathrel", "\\mathopen", "\\mathclose", "\\mathpunct", "\\mathinner"],
  9895. props: {
  9896. numArgs: 1,
  9897. primitive: true
  9898. },
  9899. handler(_ref, args) {
  9900. var {
  9901. parser,
  9902. funcName
  9903. } = _ref;
  9904. var body = args[0];
  9905. return {
  9906. type: "mclass",
  9907. mode: parser.mode,
  9908. mclass: "m" + funcName.substr(5),
  9909. // TODO(kevinb): don't prefix with 'm'
  9910. body: ordargument(body),
  9911. isCharacterBox: utils.isCharacterBox(body)
  9912. };
  9913. },
  9914. htmlBuilder: htmlBuilder$6,
  9915. mathmlBuilder: mathmlBuilder$5
  9916. });
  9917. var binrelClass = arg => {
  9918. // \binrel@ spacing varies with (bin|rel|ord) of the atom in the argument.
  9919. // (by rendering separately and with {}s before and after, and measuring
  9920. // the change in spacing). We'll do roughly the same by detecting the
  9921. // atom type directly.
  9922. var atom = arg.type === "ordgroup" && arg.body.length ? arg.body[0] : arg;
  9923. if (atom.type === "atom" && (atom.family === "bin" || atom.family === "rel")) {
  9924. return "m" + atom.family;
  9925. } else {
  9926. return "mord";
  9927. }
  9928. }; // \@binrel{x}{y} renders like y but as mbin/mrel/mord if x is mbin/mrel/mord.
  9929. // This is equivalent to \binrel@{x}\binrel@@{y} in AMSTeX.
  9930. defineFunction({
  9931. type: "mclass",
  9932. names: ["\\@binrel"],
  9933. props: {
  9934. numArgs: 2
  9935. },
  9936. handler(_ref2, args) {
  9937. var {
  9938. parser
  9939. } = _ref2;
  9940. return {
  9941. type: "mclass",
  9942. mode: parser.mode,
  9943. mclass: binrelClass(args[0]),
  9944. body: ordargument(args[1]),
  9945. isCharacterBox: utils.isCharacterBox(args[1])
  9946. };
  9947. }
  9948. }); // Build a relation or stacked op by placing one symbol on top of another
  9949. defineFunction({
  9950. type: "mclass",
  9951. names: ["\\stackrel", "\\overset", "\\underset"],
  9952. props: {
  9953. numArgs: 2
  9954. },
  9955. handler(_ref3, args) {
  9956. var {
  9957. parser,
  9958. funcName
  9959. } = _ref3;
  9960. var baseArg = args[1];
  9961. var shiftedArg = args[0];
  9962. var mclass;
  9963. if (funcName !== "\\stackrel") {
  9964. // LaTeX applies \binrel spacing to \overset and \underset.
  9965. mclass = binrelClass(baseArg);
  9966. } else {
  9967. mclass = "mrel"; // for \stackrel
  9968. }
  9969. var baseOp = {
  9970. type: "op",
  9971. mode: baseArg.mode,
  9972. limits: true,
  9973. alwaysHandleSupSub: true,
  9974. parentIsSupSub: false,
  9975. symbol: false,
  9976. suppressBaseShift: funcName !== "\\stackrel",
  9977. body: ordargument(baseArg)
  9978. };
  9979. var supsub = {
  9980. type: "supsub",
  9981. mode: shiftedArg.mode,
  9982. base: baseOp,
  9983. sup: funcName === "\\underset" ? null : shiftedArg,
  9984. sub: funcName === "\\underset" ? shiftedArg : null
  9985. };
  9986. return {
  9987. type: "mclass",
  9988. mode: parser.mode,
  9989. mclass,
  9990. body: [supsub],
  9991. isCharacterBox: utils.isCharacterBox(supsub)
  9992. };
  9993. },
  9994. htmlBuilder: htmlBuilder$6,
  9995. mathmlBuilder: mathmlBuilder$5
  9996. });
  9997. // TODO(kevinb): implement \\sl and \\sc
  9998. var htmlBuilder$5 = (group, options) => {
  9999. var font = group.font;
  10000. var newOptions = options.withFont(font);
  10001. return buildGroup$1(group.body, newOptions);
  10002. };
  10003. var mathmlBuilder$4 = (group, options) => {
  10004. var font = group.font;
  10005. var newOptions = options.withFont(font);
  10006. return buildGroup(group.body, newOptions);
  10007. };
  10008. var fontAliases = {
  10009. "\\Bbb": "\\mathbb",
  10010. "\\bold": "\\mathbf",
  10011. "\\frak": "\\mathfrak",
  10012. "\\bm": "\\boldsymbol"
  10013. };
  10014. defineFunction({
  10015. type: "font",
  10016. names: [// styles, except \boldsymbol defined below
  10017. "\\mathrm", "\\mathit", "\\mathbf", "\\mathnormal", // families
  10018. "\\mathbb", "\\mathcal", "\\mathfrak", "\\mathscr", "\\mathsf", "\\mathtt", // aliases, except \bm defined below
  10019. "\\Bbb", "\\bold", "\\frak"],
  10020. props: {
  10021. numArgs: 1,
  10022. allowedInArgument: true
  10023. },
  10024. handler: (_ref, args) => {
  10025. var {
  10026. parser,
  10027. funcName
  10028. } = _ref;
  10029. var body = normalizeArgument(args[0]);
  10030. var func = funcName;
  10031. if (func in fontAliases) {
  10032. func = fontAliases[func];
  10033. }
  10034. return {
  10035. type: "font",
  10036. mode: parser.mode,
  10037. font: func.slice(1),
  10038. body
  10039. };
  10040. },
  10041. htmlBuilder: htmlBuilder$5,
  10042. mathmlBuilder: mathmlBuilder$4
  10043. });
  10044. defineFunction({
  10045. type: "mclass",
  10046. names: ["\\boldsymbol", "\\bm"],
  10047. props: {
  10048. numArgs: 1
  10049. },
  10050. handler: (_ref2, args) => {
  10051. var {
  10052. parser
  10053. } = _ref2;
  10054. var body = args[0];
  10055. var isCharacterBox = utils.isCharacterBox(body); // amsbsy.sty's \boldsymbol uses \binrel spacing to inherit the
  10056. // argument's bin|rel|ord status
  10057. return {
  10058. type: "mclass",
  10059. mode: parser.mode,
  10060. mclass: binrelClass(body),
  10061. body: [{
  10062. type: "font",
  10063. mode: parser.mode,
  10064. font: "boldsymbol",
  10065. body
  10066. }],
  10067. isCharacterBox: isCharacterBox
  10068. };
  10069. }
  10070. }); // Old font changing functions
  10071. defineFunction({
  10072. type: "font",
  10073. names: ["\\rm", "\\sf", "\\tt", "\\bf", "\\it", "\\cal"],
  10074. props: {
  10075. numArgs: 0,
  10076. allowedInText: true
  10077. },
  10078. handler: (_ref3, args) => {
  10079. var {
  10080. parser,
  10081. funcName,
  10082. breakOnTokenText
  10083. } = _ref3;
  10084. var {
  10085. mode
  10086. } = parser;
  10087. var body = parser.parseExpression(true, breakOnTokenText);
  10088. var style = "math" + funcName.slice(1);
  10089. return {
  10090. type: "font",
  10091. mode: mode,
  10092. font: style,
  10093. body: {
  10094. type: "ordgroup",
  10095. mode: parser.mode,
  10096. body
  10097. }
  10098. };
  10099. },
  10100. htmlBuilder: htmlBuilder$5,
  10101. mathmlBuilder: mathmlBuilder$4
  10102. });
  10103. var adjustStyle = (size, originalStyle) => {
  10104. // Figure out what style this fraction should be in based on the
  10105. // function used
  10106. var style = originalStyle;
  10107. if (size === "display") {
  10108. // Get display style as a default.
  10109. // If incoming style is sub/sup, use style.text() to get correct size.
  10110. style = style.id >= Style$1.SCRIPT.id ? style.text() : Style$1.DISPLAY;
  10111. } else if (size === "text" && style.size === Style$1.DISPLAY.size) {
  10112. // We're in a \tfrac but incoming style is displaystyle, so:
  10113. style = Style$1.TEXT;
  10114. } else if (size === "script") {
  10115. style = Style$1.SCRIPT;
  10116. } else if (size === "scriptscript") {
  10117. style = Style$1.SCRIPTSCRIPT;
  10118. }
  10119. return style;
  10120. };
  10121. var htmlBuilder$4 = (group, options) => {
  10122. // Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
  10123. var style = adjustStyle(group.size, options.style);
  10124. var nstyle = style.fracNum();
  10125. var dstyle = style.fracDen();
  10126. var newOptions;
  10127. newOptions = options.havingStyle(nstyle);
  10128. var numerm = buildGroup$1(group.numer, newOptions, options);
  10129. if (group.continued) {
  10130. // \cfrac inserts a \strut into the numerator.
  10131. // Get \strut dimensions from TeXbook page 353.
  10132. var hStrut = 8.5 / options.fontMetrics().ptPerEm;
  10133. var dStrut = 3.5 / options.fontMetrics().ptPerEm;
  10134. numerm.height = numerm.height < hStrut ? hStrut : numerm.height;
  10135. numerm.depth = numerm.depth < dStrut ? dStrut : numerm.depth;
  10136. }
  10137. newOptions = options.havingStyle(dstyle);
  10138. var denomm = buildGroup$1(group.denom, newOptions, options);
  10139. var rule;
  10140. var ruleWidth;
  10141. var ruleSpacing;
  10142. if (group.hasBarLine) {
  10143. if (group.barSize) {
  10144. ruleWidth = calculateSize(group.barSize, options);
  10145. rule = buildCommon.makeLineSpan("frac-line", options, ruleWidth);
  10146. } else {
  10147. rule = buildCommon.makeLineSpan("frac-line", options);
  10148. }
  10149. ruleWidth = rule.height;
  10150. ruleSpacing = rule.height;
  10151. } else {
  10152. rule = null;
  10153. ruleWidth = 0;
  10154. ruleSpacing = options.fontMetrics().defaultRuleThickness;
  10155. } // Rule 15b
  10156. var numShift;
  10157. var clearance;
  10158. var denomShift;
  10159. if (style.size === Style$1.DISPLAY.size || group.size === "display") {
  10160. numShift = options.fontMetrics().num1;
  10161. if (ruleWidth > 0) {
  10162. clearance = 3 * ruleSpacing;
  10163. } else {
  10164. clearance = 7 * ruleSpacing;
  10165. }
  10166. denomShift = options.fontMetrics().denom1;
  10167. } else {
  10168. if (ruleWidth > 0) {
  10169. numShift = options.fontMetrics().num2;
  10170. clearance = ruleSpacing;
  10171. } else {
  10172. numShift = options.fontMetrics().num3;
  10173. clearance = 3 * ruleSpacing;
  10174. }
  10175. denomShift = options.fontMetrics().denom2;
  10176. }
  10177. var frac;
  10178. if (!rule) {
  10179. // Rule 15c
  10180. var candidateClearance = numShift - numerm.depth - (denomm.height - denomShift);
  10181. if (candidateClearance < clearance) {
  10182. numShift += 0.5 * (clearance - candidateClearance);
  10183. denomShift += 0.5 * (clearance - candidateClearance);
  10184. }
  10185. frac = buildCommon.makeVList({
  10186. positionType: "individualShift",
  10187. children: [{
  10188. type: "elem",
  10189. elem: denomm,
  10190. shift: denomShift
  10191. }, {
  10192. type: "elem",
  10193. elem: numerm,
  10194. shift: -numShift
  10195. }]
  10196. }, options);
  10197. } else {
  10198. // Rule 15d
  10199. var axisHeight = options.fontMetrics().axisHeight;
  10200. if (numShift - numerm.depth - (axisHeight + 0.5 * ruleWidth) < clearance) {
  10201. numShift += clearance - (numShift - numerm.depth - (axisHeight + 0.5 * ruleWidth));
  10202. }
  10203. if (axisHeight - 0.5 * ruleWidth - (denomm.height - denomShift) < clearance) {
  10204. denomShift += clearance - (axisHeight - 0.5 * ruleWidth - (denomm.height - denomShift));
  10205. }
  10206. var midShift = -(axisHeight - 0.5 * ruleWidth);
  10207. frac = buildCommon.makeVList({
  10208. positionType: "individualShift",
  10209. children: [{
  10210. type: "elem",
  10211. elem: denomm,
  10212. shift: denomShift
  10213. }, {
  10214. type: "elem",
  10215. elem: rule,
  10216. shift: midShift
  10217. }, {
  10218. type: "elem",
  10219. elem: numerm,
  10220. shift: -numShift
  10221. }]
  10222. }, options);
  10223. } // Since we manually change the style sometimes (with \dfrac or \tfrac),
  10224. // account for the possible size change here.
  10225. newOptions = options.havingStyle(style);
  10226. frac.height *= newOptions.sizeMultiplier / options.sizeMultiplier;
  10227. frac.depth *= newOptions.sizeMultiplier / options.sizeMultiplier; // Rule 15e
  10228. var delimSize;
  10229. if (style.size === Style$1.DISPLAY.size) {
  10230. delimSize = options.fontMetrics().delim1;
  10231. } else if (style.size === Style$1.SCRIPTSCRIPT.size) {
  10232. delimSize = options.havingStyle(Style$1.SCRIPT).fontMetrics().delim2;
  10233. } else {
  10234. delimSize = options.fontMetrics().delim2;
  10235. }
  10236. var leftDelim;
  10237. var rightDelim;
  10238. if (group.leftDelim == null) {
  10239. leftDelim = makeNullDelimiter(options, ["mopen"]);
  10240. } else {
  10241. leftDelim = delimiter.customSizedDelim(group.leftDelim, delimSize, true, options.havingStyle(style), group.mode, ["mopen"]);
  10242. }
  10243. if (group.continued) {
  10244. rightDelim = buildCommon.makeSpan([]); // zero width for \cfrac
  10245. } else if (group.rightDelim == null) {
  10246. rightDelim = makeNullDelimiter(options, ["mclose"]);
  10247. } else {
  10248. rightDelim = delimiter.customSizedDelim(group.rightDelim, delimSize, true, options.havingStyle(style), group.mode, ["mclose"]);
  10249. }
  10250. return buildCommon.makeSpan(["mord"].concat(newOptions.sizingClasses(options)), [leftDelim, buildCommon.makeSpan(["mfrac"], [frac]), rightDelim], options);
  10251. };
  10252. var mathmlBuilder$3 = (group, options) => {
  10253. var node = new mathMLTree.MathNode("mfrac", [buildGroup(group.numer, options), buildGroup(group.denom, options)]);
  10254. if (!group.hasBarLine) {
  10255. node.setAttribute("linethickness", "0px");
  10256. } else if (group.barSize) {
  10257. var ruleWidth = calculateSize(group.barSize, options);
  10258. node.setAttribute("linethickness", makeEm(ruleWidth));
  10259. }
  10260. var style = adjustStyle(group.size, options.style);
  10261. if (style.size !== options.style.size) {
  10262. node = new mathMLTree.MathNode("mstyle", [node]);
  10263. var isDisplay = style.size === Style$1.DISPLAY.size ? "true" : "false";
  10264. node.setAttribute("displaystyle", isDisplay);
  10265. node.setAttribute("scriptlevel", "0");
  10266. }
  10267. if (group.leftDelim != null || group.rightDelim != null) {
  10268. var withDelims = [];
  10269. if (group.leftDelim != null) {
  10270. var leftOp = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode(group.leftDelim.replace("\\", ""))]);
  10271. leftOp.setAttribute("fence", "true");
  10272. withDelims.push(leftOp);
  10273. }
  10274. withDelims.push(node);
  10275. if (group.rightDelim != null) {
  10276. var rightOp = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode(group.rightDelim.replace("\\", ""))]);
  10277. rightOp.setAttribute("fence", "true");
  10278. withDelims.push(rightOp);
  10279. }
  10280. return makeRow(withDelims);
  10281. }
  10282. return node;
  10283. };
  10284. defineFunction({
  10285. type: "genfrac",
  10286. names: ["\\dfrac", "\\frac", "\\tfrac", "\\dbinom", "\\binom", "\\tbinom", "\\\\atopfrac", // can’t be entered directly
  10287. "\\\\bracefrac", "\\\\brackfrac" // ditto
  10288. ],
  10289. props: {
  10290. numArgs: 2,
  10291. allowedInArgument: true
  10292. },
  10293. handler: (_ref, args) => {
  10294. var {
  10295. parser,
  10296. funcName
  10297. } = _ref;
  10298. var numer = args[0];
  10299. var denom = args[1];
  10300. var hasBarLine;
  10301. var leftDelim = null;
  10302. var rightDelim = null;
  10303. var size = "auto";
  10304. switch (funcName) {
  10305. case "\\dfrac":
  10306. case "\\frac":
  10307. case "\\tfrac":
  10308. hasBarLine = true;
  10309. break;
  10310. case "\\\\atopfrac":
  10311. hasBarLine = false;
  10312. break;
  10313. case "\\dbinom":
  10314. case "\\binom":
  10315. case "\\tbinom":
  10316. hasBarLine = false;
  10317. leftDelim = "(";
  10318. rightDelim = ")";
  10319. break;
  10320. case "\\\\bracefrac":
  10321. hasBarLine = false;
  10322. leftDelim = "\\{";
  10323. rightDelim = "\\}";
  10324. break;
  10325. case "\\\\brackfrac":
  10326. hasBarLine = false;
  10327. leftDelim = "[";
  10328. rightDelim = "]";
  10329. break;
  10330. default:
  10331. throw new Error("Unrecognized genfrac command");
  10332. }
  10333. switch (funcName) {
  10334. case "\\dfrac":
  10335. case "\\dbinom":
  10336. size = "display";
  10337. break;
  10338. case "\\tfrac":
  10339. case "\\tbinom":
  10340. size = "text";
  10341. break;
  10342. }
  10343. return {
  10344. type: "genfrac",
  10345. mode: parser.mode,
  10346. continued: false,
  10347. numer,
  10348. denom,
  10349. hasBarLine,
  10350. leftDelim,
  10351. rightDelim,
  10352. size,
  10353. barSize: null
  10354. };
  10355. },
  10356. htmlBuilder: htmlBuilder$4,
  10357. mathmlBuilder: mathmlBuilder$3
  10358. });
  10359. defineFunction({
  10360. type: "genfrac",
  10361. names: ["\\cfrac"],
  10362. props: {
  10363. numArgs: 2
  10364. },
  10365. handler: (_ref2, args) => {
  10366. var {
  10367. parser,
  10368. funcName
  10369. } = _ref2;
  10370. var numer = args[0];
  10371. var denom = args[1];
  10372. return {
  10373. type: "genfrac",
  10374. mode: parser.mode,
  10375. continued: true,
  10376. numer,
  10377. denom,
  10378. hasBarLine: true,
  10379. leftDelim: null,
  10380. rightDelim: null,
  10381. size: "display",
  10382. barSize: null
  10383. };
  10384. }
  10385. }); // Infix generalized fractions -- these are not rendered directly, but replaced
  10386. // immediately by one of the variants above.
  10387. defineFunction({
  10388. type: "infix",
  10389. names: ["\\over", "\\choose", "\\atop", "\\brace", "\\brack"],
  10390. props: {
  10391. numArgs: 0,
  10392. infix: true
  10393. },
  10394. handler(_ref3) {
  10395. var {
  10396. parser,
  10397. funcName,
  10398. token
  10399. } = _ref3;
  10400. var replaceWith;
  10401. switch (funcName) {
  10402. case "\\over":
  10403. replaceWith = "\\frac";
  10404. break;
  10405. case "\\choose":
  10406. replaceWith = "\\binom";
  10407. break;
  10408. case "\\atop":
  10409. replaceWith = "\\\\atopfrac";
  10410. break;
  10411. case "\\brace":
  10412. replaceWith = "\\\\bracefrac";
  10413. break;
  10414. case "\\brack":
  10415. replaceWith = "\\\\brackfrac";
  10416. break;
  10417. default:
  10418. throw new Error("Unrecognized infix genfrac command");
  10419. }
  10420. return {
  10421. type: "infix",
  10422. mode: parser.mode,
  10423. replaceWith,
  10424. token
  10425. };
  10426. }
  10427. });
  10428. var stylArray = ["display", "text", "script", "scriptscript"];
  10429. var delimFromValue = function delimFromValue(delimString) {
  10430. var delim = null;
  10431. if (delimString.length > 0) {
  10432. delim = delimString;
  10433. delim = delim === "." ? null : delim;
  10434. }
  10435. return delim;
  10436. };
  10437. defineFunction({
  10438. type: "genfrac",
  10439. names: ["\\genfrac"],
  10440. props: {
  10441. numArgs: 6,
  10442. allowedInArgument: true,
  10443. argTypes: ["math", "math", "size", "text", "math", "math"]
  10444. },
  10445. handler(_ref4, args) {
  10446. var {
  10447. parser
  10448. } = _ref4;
  10449. var numer = args[4];
  10450. var denom = args[5]; // Look into the parse nodes to get the desired delimiters.
  10451. var leftNode = normalizeArgument(args[0]);
  10452. var leftDelim = leftNode.type === "atom" && leftNode.family === "open" ? delimFromValue(leftNode.text) : null;
  10453. var rightNode = normalizeArgument(args[1]);
  10454. var rightDelim = rightNode.type === "atom" && rightNode.family === "close" ? delimFromValue(rightNode.text) : null;
  10455. var barNode = assertNodeType(args[2], "size");
  10456. var hasBarLine;
  10457. var barSize = null;
  10458. if (barNode.isBlank) {
  10459. // \genfrac acts differently than \above.
  10460. // \genfrac treats an empty size group as a signal to use a
  10461. // standard bar size. \above would see size = 0 and omit the bar.
  10462. hasBarLine = true;
  10463. } else {
  10464. barSize = barNode.value;
  10465. hasBarLine = barSize.number > 0;
  10466. } // Find out if we want displaystyle, textstyle, etc.
  10467. var size = "auto";
  10468. var styl = args[3];
  10469. if (styl.type === "ordgroup") {
  10470. if (styl.body.length > 0) {
  10471. var textOrd = assertNodeType(styl.body[0], "textord");
  10472. size = stylArray[Number(textOrd.text)];
  10473. }
  10474. } else {
  10475. styl = assertNodeType(styl, "textord");
  10476. size = stylArray[Number(styl.text)];
  10477. }
  10478. return {
  10479. type: "genfrac",
  10480. mode: parser.mode,
  10481. numer,
  10482. denom,
  10483. continued: false,
  10484. hasBarLine,
  10485. barSize,
  10486. leftDelim,
  10487. rightDelim,
  10488. size
  10489. };
  10490. },
  10491. htmlBuilder: htmlBuilder$4,
  10492. mathmlBuilder: mathmlBuilder$3
  10493. }); // \above is an infix fraction that also defines a fraction bar size.
  10494. defineFunction({
  10495. type: "infix",
  10496. names: ["\\above"],
  10497. props: {
  10498. numArgs: 1,
  10499. argTypes: ["size"],
  10500. infix: true
  10501. },
  10502. handler(_ref5, args) {
  10503. var {
  10504. parser,
  10505. funcName,
  10506. token
  10507. } = _ref5;
  10508. return {
  10509. type: "infix",
  10510. mode: parser.mode,
  10511. replaceWith: "\\\\abovefrac",
  10512. size: assertNodeType(args[0], "size").value,
  10513. token
  10514. };
  10515. }
  10516. });
  10517. defineFunction({
  10518. type: "genfrac",
  10519. names: ["\\\\abovefrac"],
  10520. props: {
  10521. numArgs: 3,
  10522. argTypes: ["math", "size", "math"]
  10523. },
  10524. handler: (_ref6, args) => {
  10525. var {
  10526. parser,
  10527. funcName
  10528. } = _ref6;
  10529. var numer = args[0];
  10530. var barSize = assert(assertNodeType(args[1], "infix").size);
  10531. var denom = args[2];
  10532. var hasBarLine = barSize.number > 0;
  10533. return {
  10534. type: "genfrac",
  10535. mode: parser.mode,
  10536. numer,
  10537. denom,
  10538. continued: false,
  10539. hasBarLine,
  10540. barSize,
  10541. leftDelim: null,
  10542. rightDelim: null,
  10543. size: "auto"
  10544. };
  10545. },
  10546. htmlBuilder: htmlBuilder$4,
  10547. mathmlBuilder: mathmlBuilder$3
  10548. });
  10549. // NOTE: Unlike most `htmlBuilder`s, this one handles not only "horizBrace", but
  10550. // also "supsub" since an over/underbrace can affect super/subscripting.
  10551. var htmlBuilder$3 = (grp, options) => {
  10552. var style = options.style; // Pull out the `ParseNode<"horizBrace">` if `grp` is a "supsub" node.
  10553. var supSubGroup;
  10554. var group;
  10555. if (grp.type === "supsub") {
  10556. // Ref: LaTeX source2e: }}}}\limits}
  10557. // i.e. LaTeX treats the brace similar to an op and passes it
  10558. // with \limits, so we need to assign supsub style.
  10559. supSubGroup = grp.sup ? buildGroup$1(grp.sup, options.havingStyle(style.sup()), options) : buildGroup$1(grp.sub, options.havingStyle(style.sub()), options);
  10560. group = assertNodeType(grp.base, "horizBrace");
  10561. } else {
  10562. group = assertNodeType(grp, "horizBrace");
  10563. } // Build the base group
  10564. var body = buildGroup$1(group.base, options.havingBaseStyle(Style$1.DISPLAY)); // Create the stretchy element
  10565. var braceBody = stretchy.svgSpan(group, options); // Generate the vlist, with the appropriate kerns ┏━━━━━━━━┓
  10566. // This first vlist contains the content and the brace: equation
  10567. var vlist;
  10568. if (group.isOver) {
  10569. vlist = buildCommon.makeVList({
  10570. positionType: "firstBaseline",
  10571. children: [{
  10572. type: "elem",
  10573. elem: body
  10574. }, {
  10575. type: "kern",
  10576. size: 0.1
  10577. }, {
  10578. type: "elem",
  10579. elem: braceBody
  10580. }]
  10581. }, options); // $FlowFixMe: Replace this with passing "svg-align" into makeVList.
  10582. vlist.children[0].children[0].children[1].classes.push("svg-align");
  10583. } else {
  10584. vlist = buildCommon.makeVList({
  10585. positionType: "bottom",
  10586. positionData: body.depth + 0.1 + braceBody.height,
  10587. children: [{
  10588. type: "elem",
  10589. elem: braceBody
  10590. }, {
  10591. type: "kern",
  10592. size: 0.1
  10593. }, {
  10594. type: "elem",
  10595. elem: body
  10596. }]
  10597. }, options); // $FlowFixMe: Replace this with passing "svg-align" into makeVList.
  10598. vlist.children[0].children[0].children[0].classes.push("svg-align");
  10599. }
  10600. if (supSubGroup) {
  10601. // To write the supsub, wrap the first vlist in another vlist:
  10602. // They can't all go in the same vlist, because the note might be
  10603. // wider than the equation. We want the equation to control the
  10604. // brace width.
  10605. // note long note long note
  10606. // ┏━━━━━━━━┓ or ┏━━━┓ not ┏━━━━━━━━━┓
  10607. // equation eqn eqn
  10608. var vSpan = buildCommon.makeSpan(["mord", group.isOver ? "mover" : "munder"], [vlist], options);
  10609. if (group.isOver) {
  10610. vlist = buildCommon.makeVList({
  10611. positionType: "firstBaseline",
  10612. children: [{
  10613. type: "elem",
  10614. elem: vSpan
  10615. }, {
  10616. type: "kern",
  10617. size: 0.2
  10618. }, {
  10619. type: "elem",
  10620. elem: supSubGroup
  10621. }]
  10622. }, options);
  10623. } else {
  10624. vlist = buildCommon.makeVList({
  10625. positionType: "bottom",
  10626. positionData: vSpan.depth + 0.2 + supSubGroup.height + supSubGroup.depth,
  10627. children: [{
  10628. type: "elem",
  10629. elem: supSubGroup
  10630. }, {
  10631. type: "kern",
  10632. size: 0.2
  10633. }, {
  10634. type: "elem",
  10635. elem: vSpan
  10636. }]
  10637. }, options);
  10638. }
  10639. }
  10640. return buildCommon.makeSpan(["mord", group.isOver ? "mover" : "munder"], [vlist], options);
  10641. };
  10642. var mathmlBuilder$2 = (group, options) => {
  10643. var accentNode = stretchy.mathMLnode(group.label);
  10644. return new mathMLTree.MathNode(group.isOver ? "mover" : "munder", [buildGroup(group.base, options), accentNode]);
  10645. }; // Horizontal stretchy braces
  10646. defineFunction({
  10647. type: "horizBrace",
  10648. names: ["\\overbrace", "\\underbrace"],
  10649. props: {
  10650. numArgs: 1
  10651. },
  10652. handler(_ref, args) {
  10653. var {
  10654. parser,
  10655. funcName
  10656. } = _ref;
  10657. return {
  10658. type: "horizBrace",
  10659. mode: parser.mode,
  10660. label: funcName,
  10661. isOver: /^\\over/.test(funcName),
  10662. base: args[0]
  10663. };
  10664. },
  10665. htmlBuilder: htmlBuilder$3,
  10666. mathmlBuilder: mathmlBuilder$2
  10667. });
  10668. defineFunction({
  10669. type: "href",
  10670. names: ["\\href"],
  10671. props: {
  10672. numArgs: 2,
  10673. argTypes: ["url", "original"],
  10674. allowedInText: true
  10675. },
  10676. handler: (_ref, args) => {
  10677. var {
  10678. parser
  10679. } = _ref;
  10680. var body = args[1];
  10681. var href = assertNodeType(args[0], "url").url;
  10682. if (!parser.settings.isTrusted({
  10683. command: "\\href",
  10684. url: href
  10685. })) {
  10686. return parser.formatUnsupportedCmd("\\href");
  10687. }
  10688. return {
  10689. type: "href",
  10690. mode: parser.mode,
  10691. href,
  10692. body: ordargument(body)
  10693. };
  10694. },
  10695. htmlBuilder: (group, options) => {
  10696. var elements = buildExpression$1(group.body, options, false);
  10697. return buildCommon.makeAnchor(group.href, [], elements, options);
  10698. },
  10699. mathmlBuilder: (group, options) => {
  10700. var math = buildExpressionRow(group.body, options);
  10701. if (!(math instanceof MathNode)) {
  10702. math = new MathNode("mrow", [math]);
  10703. }
  10704. math.setAttribute("href", group.href);
  10705. return math;
  10706. }
  10707. });
  10708. defineFunction({
  10709. type: "href",
  10710. names: ["\\url"],
  10711. props: {
  10712. numArgs: 1,
  10713. argTypes: ["url"],
  10714. allowedInText: true
  10715. },
  10716. handler: (_ref2, args) => {
  10717. var {
  10718. parser
  10719. } = _ref2;
  10720. var href = assertNodeType(args[0], "url").url;
  10721. if (!parser.settings.isTrusted({
  10722. command: "\\url",
  10723. url: href
  10724. })) {
  10725. return parser.formatUnsupportedCmd("\\url");
  10726. }
  10727. var chars = [];
  10728. for (var i = 0; i < href.length; i++) {
  10729. var c = href[i];
  10730. if (c === "~") {
  10731. c = "\\textasciitilde";
  10732. }
  10733. chars.push({
  10734. type: "textord",
  10735. mode: "text",
  10736. text: c
  10737. });
  10738. }
  10739. var body = {
  10740. type: "text",
  10741. mode: parser.mode,
  10742. font: "\\texttt",
  10743. body: chars
  10744. };
  10745. return {
  10746. type: "href",
  10747. mode: parser.mode,
  10748. href,
  10749. body: ordargument(body)
  10750. };
  10751. }
  10752. });
  10753. // In LaTeX, \vcenter can act only on a box, as in
  10754. // \vcenter{\hbox{$\frac{a+b}{\dfrac{c}{d}}$}}
  10755. // This function by itself doesn't do anything but prevent a soft line break.
  10756. defineFunction({
  10757. type: "hbox",
  10758. names: ["\\hbox"],
  10759. props: {
  10760. numArgs: 1,
  10761. argTypes: ["text"],
  10762. allowedInText: true,
  10763. primitive: true
  10764. },
  10765. handler(_ref, args) {
  10766. var {
  10767. parser
  10768. } = _ref;
  10769. return {
  10770. type: "hbox",
  10771. mode: parser.mode,
  10772. body: ordargument(args[0])
  10773. };
  10774. },
  10775. htmlBuilder(group, options) {
  10776. var elements = buildExpression$1(group.body, options, false);
  10777. return buildCommon.makeFragment(elements);
  10778. },
  10779. mathmlBuilder(group, options) {
  10780. return new mathMLTree.MathNode("mrow", buildExpression(group.body, options));
  10781. }
  10782. });
  10783. defineFunction({
  10784. type: "html",
  10785. names: ["\\htmlClass", "\\htmlId", "\\htmlStyle", "\\htmlData"],
  10786. props: {
  10787. numArgs: 2,
  10788. argTypes: ["raw", "original"],
  10789. allowedInText: true
  10790. },
  10791. handler: (_ref, args) => {
  10792. var {
  10793. parser,
  10794. funcName,
  10795. token
  10796. } = _ref;
  10797. var value = assertNodeType(args[0], "raw").string;
  10798. var body = args[1];
  10799. if (parser.settings.strict) {
  10800. parser.settings.reportNonstrict("htmlExtension", "HTML extension is disabled on strict mode");
  10801. }
  10802. var trustContext;
  10803. var attributes = {};
  10804. switch (funcName) {
  10805. case "\\htmlClass":
  10806. attributes.class = value;
  10807. trustContext = {
  10808. command: "\\htmlClass",
  10809. class: value
  10810. };
  10811. break;
  10812. case "\\htmlId":
  10813. attributes.id = value;
  10814. trustContext = {
  10815. command: "\\htmlId",
  10816. id: value
  10817. };
  10818. break;
  10819. case "\\htmlStyle":
  10820. attributes.style = value;
  10821. trustContext = {
  10822. command: "\\htmlStyle",
  10823. style: value
  10824. };
  10825. break;
  10826. case "\\htmlData":
  10827. {
  10828. var data = value.split(",");
  10829. for (var i = 0; i < data.length; i++) {
  10830. var keyVal = data[i].split("=");
  10831. if (keyVal.length !== 2) {
  10832. throw new ParseError("Error parsing key-value for \\htmlData");
  10833. }
  10834. attributes["data-" + keyVal[0].trim()] = keyVal[1].trim();
  10835. }
  10836. trustContext = {
  10837. command: "\\htmlData",
  10838. attributes
  10839. };
  10840. break;
  10841. }
  10842. default:
  10843. throw new Error("Unrecognized html command");
  10844. }
  10845. if (!parser.settings.isTrusted(trustContext)) {
  10846. return parser.formatUnsupportedCmd(funcName);
  10847. }
  10848. return {
  10849. type: "html",
  10850. mode: parser.mode,
  10851. attributes,
  10852. body: ordargument(body)
  10853. };
  10854. },
  10855. htmlBuilder: (group, options) => {
  10856. var elements = buildExpression$1(group.body, options, false);
  10857. var classes = ["enclosing"];
  10858. if (group.attributes.class) {
  10859. classes.push(...group.attributes.class.trim().split(/\s+/));
  10860. }
  10861. var span = buildCommon.makeSpan(classes, elements, options);
  10862. for (var attr in group.attributes) {
  10863. if (attr !== "class" && group.attributes.hasOwnProperty(attr)) {
  10864. span.setAttribute(attr, group.attributes[attr]);
  10865. }
  10866. }
  10867. return span;
  10868. },
  10869. mathmlBuilder: (group, options) => {
  10870. return buildExpressionRow(group.body, options);
  10871. }
  10872. });
  10873. defineFunction({
  10874. type: "htmlmathml",
  10875. names: ["\\html@mathml"],
  10876. props: {
  10877. numArgs: 2,
  10878. allowedInText: true
  10879. },
  10880. handler: (_ref, args) => {
  10881. var {
  10882. parser
  10883. } = _ref;
  10884. return {
  10885. type: "htmlmathml",
  10886. mode: parser.mode,
  10887. html: ordargument(args[0]),
  10888. mathml: ordargument(args[1])
  10889. };
  10890. },
  10891. htmlBuilder: (group, options) => {
  10892. var elements = buildExpression$1(group.html, options, false);
  10893. return buildCommon.makeFragment(elements);
  10894. },
  10895. mathmlBuilder: (group, options) => {
  10896. return buildExpressionRow(group.mathml, options);
  10897. }
  10898. });
  10899. var sizeData = function sizeData(str) {
  10900. if (/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(str)) {
  10901. // str is a number with no unit specified.
  10902. // default unit is bp, per graphix package.
  10903. return {
  10904. number: +str,
  10905. unit: "bp"
  10906. };
  10907. } else {
  10908. var match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(str);
  10909. if (!match) {
  10910. throw new ParseError("Invalid size: '" + str + "' in \\includegraphics");
  10911. }
  10912. var data = {
  10913. number: +(match[1] + match[2]),
  10914. // sign + magnitude, cast to number
  10915. unit: match[3]
  10916. };
  10917. if (!validUnit(data)) {
  10918. throw new ParseError("Invalid unit: '" + data.unit + "' in \\includegraphics.");
  10919. }
  10920. return data;
  10921. }
  10922. };
  10923. defineFunction({
  10924. type: "includegraphics",
  10925. names: ["\\includegraphics"],
  10926. props: {
  10927. numArgs: 1,
  10928. numOptionalArgs: 1,
  10929. argTypes: ["raw", "url"],
  10930. allowedInText: false
  10931. },
  10932. handler: (_ref, args, optArgs) => {
  10933. var {
  10934. parser
  10935. } = _ref;
  10936. var width = {
  10937. number: 0,
  10938. unit: "em"
  10939. };
  10940. var height = {
  10941. number: 0.9,
  10942. unit: "em"
  10943. }; // sorta character sized.
  10944. var totalheight = {
  10945. number: 0,
  10946. unit: "em"
  10947. };
  10948. var alt = "";
  10949. if (optArgs[0]) {
  10950. var attributeStr = assertNodeType(optArgs[0], "raw").string; // Parser.js does not parse key/value pairs. We get a string.
  10951. var attributes = attributeStr.split(",");
  10952. for (var i = 0; i < attributes.length; i++) {
  10953. var keyVal = attributes[i].split("=");
  10954. if (keyVal.length === 2) {
  10955. var str = keyVal[1].trim();
  10956. switch (keyVal[0].trim()) {
  10957. case "alt":
  10958. alt = str;
  10959. break;
  10960. case "width":
  10961. width = sizeData(str);
  10962. break;
  10963. case "height":
  10964. height = sizeData(str);
  10965. break;
  10966. case "totalheight":
  10967. totalheight = sizeData(str);
  10968. break;
  10969. default:
  10970. throw new ParseError("Invalid key: '" + keyVal[0] + "' in \\includegraphics.");
  10971. }
  10972. }
  10973. }
  10974. }
  10975. var src = assertNodeType(args[0], "url").url;
  10976. if (alt === "") {
  10977. // No alt given. Use the file name. Strip away the path.
  10978. alt = src;
  10979. alt = alt.replace(/^.*[\\/]/, '');
  10980. alt = alt.substring(0, alt.lastIndexOf('.'));
  10981. }
  10982. if (!parser.settings.isTrusted({
  10983. command: "\\includegraphics",
  10984. url: src
  10985. })) {
  10986. return parser.formatUnsupportedCmd("\\includegraphics");
  10987. }
  10988. return {
  10989. type: "includegraphics",
  10990. mode: parser.mode,
  10991. alt: alt,
  10992. width: width,
  10993. height: height,
  10994. totalheight: totalheight,
  10995. src: src
  10996. };
  10997. },
  10998. htmlBuilder: (group, options) => {
  10999. var height = calculateSize(group.height, options);
  11000. var depth = 0;
  11001. if (group.totalheight.number > 0) {
  11002. depth = calculateSize(group.totalheight, options) - height;
  11003. }
  11004. var width = 0;
  11005. if (group.width.number > 0) {
  11006. width = calculateSize(group.width, options);
  11007. }
  11008. var style = {
  11009. height: makeEm(height + depth)
  11010. };
  11011. if (width > 0) {
  11012. style.width = makeEm(width);
  11013. }
  11014. if (depth > 0) {
  11015. style.verticalAlign = makeEm(-depth);
  11016. }
  11017. var node = new Img(group.src, group.alt, style);
  11018. node.height = height;
  11019. node.depth = depth;
  11020. return node;
  11021. },
  11022. mathmlBuilder: (group, options) => {
  11023. var node = new mathMLTree.MathNode("mglyph", []);
  11024. node.setAttribute("alt", group.alt);
  11025. var height = calculateSize(group.height, options);
  11026. var depth = 0;
  11027. if (group.totalheight.number > 0) {
  11028. depth = calculateSize(group.totalheight, options) - height;
  11029. node.setAttribute("valign", makeEm(-depth));
  11030. }
  11031. node.setAttribute("height", makeEm(height + depth));
  11032. if (group.width.number > 0) {
  11033. var width = calculateSize(group.width, options);
  11034. node.setAttribute("width", makeEm(width));
  11035. }
  11036. node.setAttribute("src", group.src);
  11037. return node;
  11038. }
  11039. });
  11040. // Horizontal spacing commands
  11041. defineFunction({
  11042. type: "kern",
  11043. names: ["\\kern", "\\mkern", "\\hskip", "\\mskip"],
  11044. props: {
  11045. numArgs: 1,
  11046. argTypes: ["size"],
  11047. primitive: true,
  11048. allowedInText: true
  11049. },
  11050. handler(_ref, args) {
  11051. var {
  11052. parser,
  11053. funcName
  11054. } = _ref;
  11055. var size = assertNodeType(args[0], "size");
  11056. if (parser.settings.strict) {
  11057. var mathFunction = funcName[1] === 'm'; // \mkern, \mskip
  11058. var muUnit = size.value.unit === 'mu';
  11059. if (mathFunction) {
  11060. if (!muUnit) {
  11061. parser.settings.reportNonstrict("mathVsTextUnits", "LaTeX's " + funcName + " supports only mu units, " + ("not " + size.value.unit + " units"));
  11062. }
  11063. if (parser.mode !== "math") {
  11064. parser.settings.reportNonstrict("mathVsTextUnits", "LaTeX's " + funcName + " works only in math mode");
  11065. }
  11066. } else {
  11067. // !mathFunction
  11068. if (muUnit) {
  11069. parser.settings.reportNonstrict("mathVsTextUnits", "LaTeX's " + funcName + " doesn't support mu units");
  11070. }
  11071. }
  11072. }
  11073. return {
  11074. type: "kern",
  11075. mode: parser.mode,
  11076. dimension: size.value
  11077. };
  11078. },
  11079. htmlBuilder(group, options) {
  11080. return buildCommon.makeGlue(group.dimension, options);
  11081. },
  11082. mathmlBuilder(group, options) {
  11083. var dimension = calculateSize(group.dimension, options);
  11084. return new mathMLTree.SpaceNode(dimension);
  11085. }
  11086. });
  11087. // Horizontal overlap functions
  11088. defineFunction({
  11089. type: "lap",
  11090. names: ["\\mathllap", "\\mathrlap", "\\mathclap"],
  11091. props: {
  11092. numArgs: 1,
  11093. allowedInText: true
  11094. },
  11095. handler: (_ref, args) => {
  11096. var {
  11097. parser,
  11098. funcName
  11099. } = _ref;
  11100. var body = args[0];
  11101. return {
  11102. type: "lap",
  11103. mode: parser.mode,
  11104. alignment: funcName.slice(5),
  11105. body
  11106. };
  11107. },
  11108. htmlBuilder: (group, options) => {
  11109. // mathllap, mathrlap, mathclap
  11110. var inner;
  11111. if (group.alignment === "clap") {
  11112. // ref: https://www.math.lsu.edu/~aperlis/publications/mathclap/
  11113. inner = buildCommon.makeSpan([], [buildGroup$1(group.body, options)]); // wrap, since CSS will center a .clap > .inner > span
  11114. inner = buildCommon.makeSpan(["inner"], [inner], options);
  11115. } else {
  11116. inner = buildCommon.makeSpan(["inner"], [buildGroup$1(group.body, options)]);
  11117. }
  11118. var fix = buildCommon.makeSpan(["fix"], []);
  11119. var node = buildCommon.makeSpan([group.alignment], [inner, fix], options); // At this point, we have correctly set horizontal alignment of the
  11120. // two items involved in the lap.
  11121. // Next, use a strut to set the height of the HTML bounding box.
  11122. // Otherwise, a tall argument may be misplaced.
  11123. // This code resolved issue #1153
  11124. var strut = buildCommon.makeSpan(["strut"]);
  11125. strut.style.height = makeEm(node.height + node.depth);
  11126. if (node.depth) {
  11127. strut.style.verticalAlign = makeEm(-node.depth);
  11128. }
  11129. node.children.unshift(strut); // Next, prevent vertical misplacement when next to something tall.
  11130. // This code resolves issue #1234
  11131. node = buildCommon.makeSpan(["thinbox"], [node], options);
  11132. return buildCommon.makeSpan(["mord", "vbox"], [node], options);
  11133. },
  11134. mathmlBuilder: (group, options) => {
  11135. // mathllap, mathrlap, mathclap
  11136. var node = new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)]);
  11137. if (group.alignment !== "rlap") {
  11138. var offset = group.alignment === "llap" ? "-1" : "-0.5";
  11139. node.setAttribute("lspace", offset + "width");
  11140. }
  11141. node.setAttribute("width", "0px");
  11142. return node;
  11143. }
  11144. });
  11145. defineFunction({
  11146. type: "styling",
  11147. names: ["\\(", "$"],
  11148. props: {
  11149. numArgs: 0,
  11150. allowedInText: true,
  11151. allowedInMath: false
  11152. },
  11153. handler(_ref, args) {
  11154. var {
  11155. funcName,
  11156. parser
  11157. } = _ref;
  11158. var outerMode = parser.mode;
  11159. parser.switchMode("math");
  11160. var close = funcName === "\\(" ? "\\)" : "$";
  11161. var body = parser.parseExpression(false, close);
  11162. parser.expect(close);
  11163. parser.switchMode(outerMode);
  11164. return {
  11165. type: "styling",
  11166. mode: parser.mode,
  11167. style: "text",
  11168. body
  11169. };
  11170. }
  11171. }); // Check for extra closing math delimiters
  11172. defineFunction({
  11173. type: "text",
  11174. // Doesn't matter what this is.
  11175. names: ["\\)", "\\]"],
  11176. props: {
  11177. numArgs: 0,
  11178. allowedInText: true,
  11179. allowedInMath: false
  11180. },
  11181. handler(context, args) {
  11182. throw new ParseError("Mismatched " + context.funcName);
  11183. }
  11184. });
  11185. var chooseMathStyle = (group, options) => {
  11186. switch (options.style.size) {
  11187. case Style$1.DISPLAY.size:
  11188. return group.display;
  11189. case Style$1.TEXT.size:
  11190. return group.text;
  11191. case Style$1.SCRIPT.size:
  11192. return group.script;
  11193. case Style$1.SCRIPTSCRIPT.size:
  11194. return group.scriptscript;
  11195. default:
  11196. return group.text;
  11197. }
  11198. };
  11199. defineFunction({
  11200. type: "mathchoice",
  11201. names: ["\\mathchoice"],
  11202. props: {
  11203. numArgs: 4,
  11204. primitive: true
  11205. },
  11206. handler: (_ref, args) => {
  11207. var {
  11208. parser
  11209. } = _ref;
  11210. return {
  11211. type: "mathchoice",
  11212. mode: parser.mode,
  11213. display: ordargument(args[0]),
  11214. text: ordargument(args[1]),
  11215. script: ordargument(args[2]),
  11216. scriptscript: ordargument(args[3])
  11217. };
  11218. },
  11219. htmlBuilder: (group, options) => {
  11220. var body = chooseMathStyle(group, options);
  11221. var elements = buildExpression$1(body, options, false);
  11222. return buildCommon.makeFragment(elements);
  11223. },
  11224. mathmlBuilder: (group, options) => {
  11225. var body = chooseMathStyle(group, options);
  11226. return buildExpressionRow(body, options);
  11227. }
  11228. });
  11229. var assembleSupSub = (base, supGroup, subGroup, options, style, slant, baseShift) => {
  11230. base = buildCommon.makeSpan([], [base]);
  11231. var subIsSingleCharacter = subGroup && utils.isCharacterBox(subGroup);
  11232. var sub;
  11233. var sup; // We manually have to handle the superscripts and subscripts. This,
  11234. // aside from the kern calculations, is copied from supsub.
  11235. if (supGroup) {
  11236. var elem = buildGroup$1(supGroup, options.havingStyle(style.sup()), options);
  11237. sup = {
  11238. elem,
  11239. kern: Math.max(options.fontMetrics().bigOpSpacing1, options.fontMetrics().bigOpSpacing3 - elem.depth)
  11240. };
  11241. }
  11242. if (subGroup) {
  11243. var _elem = buildGroup$1(subGroup, options.havingStyle(style.sub()), options);
  11244. sub = {
  11245. elem: _elem,
  11246. kern: Math.max(options.fontMetrics().bigOpSpacing2, options.fontMetrics().bigOpSpacing4 - _elem.height)
  11247. };
  11248. } // Build the final group as a vlist of the possible subscript, base,
  11249. // and possible superscript.
  11250. var finalGroup;
  11251. if (sup && sub) {
  11252. var bottom = options.fontMetrics().bigOpSpacing5 + sub.elem.height + sub.elem.depth + sub.kern + base.depth + baseShift;
  11253. finalGroup = buildCommon.makeVList({
  11254. positionType: "bottom",
  11255. positionData: bottom,
  11256. children: [{
  11257. type: "kern",
  11258. size: options.fontMetrics().bigOpSpacing5
  11259. }, {
  11260. type: "elem",
  11261. elem: sub.elem,
  11262. marginLeft: makeEm(-slant)
  11263. }, {
  11264. type: "kern",
  11265. size: sub.kern
  11266. }, {
  11267. type: "elem",
  11268. elem: base
  11269. }, {
  11270. type: "kern",
  11271. size: sup.kern
  11272. }, {
  11273. type: "elem",
  11274. elem: sup.elem,
  11275. marginLeft: makeEm(slant)
  11276. }, {
  11277. type: "kern",
  11278. size: options.fontMetrics().bigOpSpacing5
  11279. }]
  11280. }, options);
  11281. } else if (sub) {
  11282. var top = base.height - baseShift; // Shift the limits by the slant of the symbol. Note
  11283. // that we are supposed to shift the limits by 1/2 of the slant,
  11284. // but since we are centering the limits adding a full slant of
  11285. // margin will shift by 1/2 that.
  11286. finalGroup = buildCommon.makeVList({
  11287. positionType: "top",
  11288. positionData: top,
  11289. children: [{
  11290. type: "kern",
  11291. size: options.fontMetrics().bigOpSpacing5
  11292. }, {
  11293. type: "elem",
  11294. elem: sub.elem,
  11295. marginLeft: makeEm(-slant)
  11296. }, {
  11297. type: "kern",
  11298. size: sub.kern
  11299. }, {
  11300. type: "elem",
  11301. elem: base
  11302. }]
  11303. }, options);
  11304. } else if (sup) {
  11305. var _bottom = base.depth + baseShift;
  11306. finalGroup = buildCommon.makeVList({
  11307. positionType: "bottom",
  11308. positionData: _bottom,
  11309. children: [{
  11310. type: "elem",
  11311. elem: base
  11312. }, {
  11313. type: "kern",
  11314. size: sup.kern
  11315. }, {
  11316. type: "elem",
  11317. elem: sup.elem,
  11318. marginLeft: makeEm(slant)
  11319. }, {
  11320. type: "kern",
  11321. size: options.fontMetrics().bigOpSpacing5
  11322. }]
  11323. }, options);
  11324. } else {
  11325. // This case probably shouldn't occur (this would mean the
  11326. // supsub was sending us a group with no superscript or
  11327. // subscript) but be safe.
  11328. return base;
  11329. }
  11330. var parts = [finalGroup];
  11331. if (sub && slant !== 0 && !subIsSingleCharacter) {
  11332. // A negative margin-left was applied to the lower limit.
  11333. // Avoid an overlap by placing a spacer on the left on the group.
  11334. var spacer = buildCommon.makeSpan(["mspace"], [], options);
  11335. spacer.style.marginRight = makeEm(slant);
  11336. parts.unshift(spacer);
  11337. }
  11338. return buildCommon.makeSpan(["mop", "op-limits"], parts, options);
  11339. };
  11340. // Limits, symbols
  11341. // Most operators have a large successor symbol, but these don't.
  11342. var noSuccessor = ["\\smallint"]; // NOTE: Unlike most `htmlBuilder`s, this one handles not only "op", but also
  11343. // "supsub" since some of them (like \int) can affect super/subscripting.
  11344. var htmlBuilder$2 = (grp, options) => {
  11345. // Operators are handled in the TeXbook pg. 443-444, rule 13(a).
  11346. var supGroup;
  11347. var subGroup;
  11348. var hasLimits = false;
  11349. var group;
  11350. if (grp.type === "supsub") {
  11351. // If we have limits, supsub will pass us its group to handle. Pull
  11352. // out the superscript and subscript and set the group to the op in
  11353. // its base.
  11354. supGroup = grp.sup;
  11355. subGroup = grp.sub;
  11356. group = assertNodeType(grp.base, "op");
  11357. hasLimits = true;
  11358. } else {
  11359. group = assertNodeType(grp, "op");
  11360. }
  11361. var style = options.style;
  11362. var large = false;
  11363. if (style.size === Style$1.DISPLAY.size && group.symbol && !utils.contains(noSuccessor, group.name)) {
  11364. // Most symbol operators get larger in displaystyle (rule 13)
  11365. large = true;
  11366. }
  11367. var base;
  11368. if (group.symbol) {
  11369. // If this is a symbol, create the symbol.
  11370. var fontName = large ? "Size2-Regular" : "Size1-Regular";
  11371. var stash = "";
  11372. if (group.name === "\\oiint" || group.name === "\\oiiint") {
  11373. // No font glyphs yet, so use a glyph w/o the oval.
  11374. // TODO: When font glyphs are available, delete this code.
  11375. stash = group.name.substr(1);
  11376. group.name = stash === "oiint" ? "\\iint" : "\\iiint";
  11377. }
  11378. base = buildCommon.makeSymbol(group.name, fontName, "math", options, ["mop", "op-symbol", large ? "large-op" : "small-op"]);
  11379. if (stash.length > 0) {
  11380. // We're in \oiint or \oiiint. Overlay the oval.
  11381. // TODO: When font glyphs are available, delete this code.
  11382. var italic = base.italic;
  11383. var oval = buildCommon.staticSvg(stash + "Size" + (large ? "2" : "1"), options);
  11384. base = buildCommon.makeVList({
  11385. positionType: "individualShift",
  11386. children: [{
  11387. type: "elem",
  11388. elem: base,
  11389. shift: 0
  11390. }, {
  11391. type: "elem",
  11392. elem: oval,
  11393. shift: large ? 0.08 : 0
  11394. }]
  11395. }, options);
  11396. group.name = "\\" + stash;
  11397. base.classes.unshift("mop"); // $FlowFixMe
  11398. base.italic = italic;
  11399. }
  11400. } else if (group.body) {
  11401. // If this is a list, compose that list.
  11402. var inner = buildExpression$1(group.body, options, true);
  11403. if (inner.length === 1 && inner[0] instanceof SymbolNode) {
  11404. base = inner[0];
  11405. base.classes[0] = "mop"; // replace old mclass
  11406. } else {
  11407. base = buildCommon.makeSpan(["mop"], inner, options);
  11408. }
  11409. } else {
  11410. // Otherwise, this is a text operator. Build the text from the
  11411. // operator's name.
  11412. var output = [];
  11413. for (var i = 1; i < group.name.length; i++) {
  11414. output.push(buildCommon.mathsym(group.name[i], group.mode, options));
  11415. }
  11416. base = buildCommon.makeSpan(["mop"], output, options);
  11417. } // If content of op is a single symbol, shift it vertically.
  11418. var baseShift = 0;
  11419. var slant = 0;
  11420. if ((base instanceof SymbolNode || group.name === "\\oiint" || group.name === "\\oiiint") && !group.suppressBaseShift) {
  11421. // We suppress the shift of the base of \overset and \underset. Otherwise,
  11422. // shift the symbol so its center lies on the axis (rule 13). It
  11423. // appears that our fonts have the centers of the symbols already
  11424. // almost on the axis, so these numbers are very small. Note we
  11425. // don't actually apply this here, but instead it is used either in
  11426. // the vlist creation or separately when there are no limits.
  11427. baseShift = (base.height - base.depth) / 2 - options.fontMetrics().axisHeight; // The slant of the symbol is just its italic correction.
  11428. // $FlowFixMe
  11429. slant = base.italic;
  11430. }
  11431. if (hasLimits) {
  11432. return assembleSupSub(base, supGroup, subGroup, options, style, slant, baseShift);
  11433. } else {
  11434. if (baseShift) {
  11435. base.style.position = "relative";
  11436. base.style.top = makeEm(baseShift);
  11437. }
  11438. return base;
  11439. }
  11440. };
  11441. var mathmlBuilder$1 = (group, options) => {
  11442. var node;
  11443. if (group.symbol) {
  11444. // This is a symbol. Just add the symbol.
  11445. node = new MathNode("mo", [makeText(group.name, group.mode)]);
  11446. if (utils.contains(noSuccessor, group.name)) {
  11447. node.setAttribute("largeop", "false");
  11448. }
  11449. } else if (group.body) {
  11450. // This is an operator with children. Add them.
  11451. node = new MathNode("mo", buildExpression(group.body, options));
  11452. } else {
  11453. // This is a text operator. Add all of the characters from the
  11454. // operator's name.
  11455. node = new MathNode("mi", [new TextNode(group.name.slice(1))]); // Append an <mo>&ApplyFunction;</mo>.
  11456. // ref: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.4
  11457. var operator = new MathNode("mo", [makeText("\u2061", "text")]);
  11458. if (group.parentIsSupSub) {
  11459. node = new MathNode("mrow", [node, operator]);
  11460. } else {
  11461. node = newDocumentFragment([node, operator]);
  11462. }
  11463. }
  11464. return node;
  11465. };
  11466. var singleCharBigOps = {
  11467. "\u220F": "\\prod",
  11468. "\u2210": "\\coprod",
  11469. "\u2211": "\\sum",
  11470. "\u22c0": "\\bigwedge",
  11471. "\u22c1": "\\bigvee",
  11472. "\u22c2": "\\bigcap",
  11473. "\u22c3": "\\bigcup",
  11474. "\u2a00": "\\bigodot",
  11475. "\u2a01": "\\bigoplus",
  11476. "\u2a02": "\\bigotimes",
  11477. "\u2a04": "\\biguplus",
  11478. "\u2a06": "\\bigsqcup"
  11479. };
  11480. defineFunction({
  11481. type: "op",
  11482. names: ["\\coprod", "\\bigvee", "\\bigwedge", "\\biguplus", "\\bigcap", "\\bigcup", "\\intop", "\\prod", "\\sum", "\\bigotimes", "\\bigoplus", "\\bigodot", "\\bigsqcup", "\\smallint", "\u220F", "\u2210", "\u2211", "\u22c0", "\u22c1", "\u22c2", "\u22c3", "\u2a00", "\u2a01", "\u2a02", "\u2a04", "\u2a06"],
  11483. props: {
  11484. numArgs: 0
  11485. },
  11486. handler: (_ref, args) => {
  11487. var {
  11488. parser,
  11489. funcName
  11490. } = _ref;
  11491. var fName = funcName;
  11492. if (fName.length === 1) {
  11493. fName = singleCharBigOps[fName];
  11494. }
  11495. return {
  11496. type: "op",
  11497. mode: parser.mode,
  11498. limits: true,
  11499. parentIsSupSub: false,
  11500. symbol: true,
  11501. name: fName
  11502. };
  11503. },
  11504. htmlBuilder: htmlBuilder$2,
  11505. mathmlBuilder: mathmlBuilder$1
  11506. }); // Note: calling defineFunction with a type that's already been defined only
  11507. // works because the same htmlBuilder and mathmlBuilder are being used.
  11508. defineFunction({
  11509. type: "op",
  11510. names: ["\\mathop"],
  11511. props: {
  11512. numArgs: 1,
  11513. primitive: true
  11514. },
  11515. handler: (_ref2, args) => {
  11516. var {
  11517. parser
  11518. } = _ref2;
  11519. var body = args[0];
  11520. return {
  11521. type: "op",
  11522. mode: parser.mode,
  11523. limits: false,
  11524. parentIsSupSub: false,
  11525. symbol: false,
  11526. body: ordargument(body)
  11527. };
  11528. },
  11529. htmlBuilder: htmlBuilder$2,
  11530. mathmlBuilder: mathmlBuilder$1
  11531. }); // There are 2 flags for operators; whether they produce limits in
  11532. // displaystyle, and whether they are symbols and should grow in
  11533. // displaystyle. These four groups cover the four possible choices.
  11534. var singleCharIntegrals = {
  11535. "\u222b": "\\int",
  11536. "\u222c": "\\iint",
  11537. "\u222d": "\\iiint",
  11538. "\u222e": "\\oint",
  11539. "\u222f": "\\oiint",
  11540. "\u2230": "\\oiiint"
  11541. }; // No limits, not symbols
  11542. defineFunction({
  11543. type: "op",
  11544. names: ["\\arcsin", "\\arccos", "\\arctan", "\\arctg", "\\arcctg", "\\arg", "\\ch", "\\cos", "\\cosec", "\\cosh", "\\cot", "\\cotg", "\\coth", "\\csc", "\\ctg", "\\cth", "\\deg", "\\dim", "\\exp", "\\hom", "\\ker", "\\lg", "\\ln", "\\log", "\\sec", "\\sin", "\\sinh", "\\sh", "\\tan", "\\tanh", "\\tg", "\\th"],
  11545. props: {
  11546. numArgs: 0
  11547. },
  11548. handler(_ref3) {
  11549. var {
  11550. parser,
  11551. funcName
  11552. } = _ref3;
  11553. return {
  11554. type: "op",
  11555. mode: parser.mode,
  11556. limits: false,
  11557. parentIsSupSub: false,
  11558. symbol: false,
  11559. name: funcName
  11560. };
  11561. },
  11562. htmlBuilder: htmlBuilder$2,
  11563. mathmlBuilder: mathmlBuilder$1
  11564. }); // Limits, not symbols
  11565. defineFunction({
  11566. type: "op",
  11567. names: ["\\det", "\\gcd", "\\inf", "\\lim", "\\max", "\\min", "\\Pr", "\\sup"],
  11568. props: {
  11569. numArgs: 0
  11570. },
  11571. handler(_ref4) {
  11572. var {
  11573. parser,
  11574. funcName
  11575. } = _ref4;
  11576. return {
  11577. type: "op",
  11578. mode: parser.mode,
  11579. limits: true,
  11580. parentIsSupSub: false,
  11581. symbol: false,
  11582. name: funcName
  11583. };
  11584. },
  11585. htmlBuilder: htmlBuilder$2,
  11586. mathmlBuilder: mathmlBuilder$1
  11587. }); // No limits, symbols
  11588. defineFunction({
  11589. type: "op",
  11590. names: ["\\int", "\\iint", "\\iiint", "\\oint", "\\oiint", "\\oiiint", "\u222b", "\u222c", "\u222d", "\u222e", "\u222f", "\u2230"],
  11591. props: {
  11592. numArgs: 0
  11593. },
  11594. handler(_ref5) {
  11595. var {
  11596. parser,
  11597. funcName
  11598. } = _ref5;
  11599. var fName = funcName;
  11600. if (fName.length === 1) {
  11601. fName = singleCharIntegrals[fName];
  11602. }
  11603. return {
  11604. type: "op",
  11605. mode: parser.mode,
  11606. limits: false,
  11607. parentIsSupSub: false,
  11608. symbol: true,
  11609. name: fName
  11610. };
  11611. },
  11612. htmlBuilder: htmlBuilder$2,
  11613. mathmlBuilder: mathmlBuilder$1
  11614. });
  11615. // NOTE: Unlike most `htmlBuilder`s, this one handles not only
  11616. // "operatorname", but also "supsub" since \operatorname* can
  11617. // affect super/subscripting.
  11618. var htmlBuilder$1 = (grp, options) => {
  11619. // Operators are handled in the TeXbook pg. 443-444, rule 13(a).
  11620. var supGroup;
  11621. var subGroup;
  11622. var hasLimits = false;
  11623. var group;
  11624. if (grp.type === "supsub") {
  11625. // If we have limits, supsub will pass us its group to handle. Pull
  11626. // out the superscript and subscript and set the group to the op in
  11627. // its base.
  11628. supGroup = grp.sup;
  11629. subGroup = grp.sub;
  11630. group = assertNodeType(grp.base, "operatorname");
  11631. hasLimits = true;
  11632. } else {
  11633. group = assertNodeType(grp, "operatorname");
  11634. }
  11635. var base;
  11636. if (group.body.length > 0) {
  11637. var body = group.body.map(child => {
  11638. // $FlowFixMe: Check if the node has a string `text` property.
  11639. var childText = child.text;
  11640. if (typeof childText === "string") {
  11641. return {
  11642. type: "textord",
  11643. mode: child.mode,
  11644. text: childText
  11645. };
  11646. } else {
  11647. return child;
  11648. }
  11649. }); // Consolidate function names into symbol characters.
  11650. var expression = buildExpression$1(body, options.withFont("mathrm"), true);
  11651. for (var i = 0; i < expression.length; i++) {
  11652. var child = expression[i];
  11653. if (child instanceof SymbolNode) {
  11654. // Per amsopn package,
  11655. // change minus to hyphen and \ast to asterisk
  11656. child.text = child.text.replace(/\u2212/, "-").replace(/\u2217/, "*");
  11657. }
  11658. }
  11659. base = buildCommon.makeSpan(["mop"], expression, options);
  11660. } else {
  11661. base = buildCommon.makeSpan(["mop"], [], options);
  11662. }
  11663. if (hasLimits) {
  11664. return assembleSupSub(base, supGroup, subGroup, options, options.style, 0, 0);
  11665. } else {
  11666. return base;
  11667. }
  11668. };
  11669. var mathmlBuilder = (group, options) => {
  11670. // The steps taken here are similar to the html version.
  11671. var expression = buildExpression(group.body, options.withFont("mathrm")); // Is expression a string or has it something like a fraction?
  11672. var isAllString = true; // default
  11673. for (var i = 0; i < expression.length; i++) {
  11674. var node = expression[i];
  11675. if (node instanceof mathMLTree.SpaceNode) ; else if (node instanceof mathMLTree.MathNode) {
  11676. switch (node.type) {
  11677. case "mi":
  11678. case "mn":
  11679. case "ms":
  11680. case "mspace":
  11681. case "mtext":
  11682. break;
  11683. // Do nothing yet.
  11684. case "mo":
  11685. {
  11686. var child = node.children[0];
  11687. if (node.children.length === 1 && child instanceof mathMLTree.TextNode) {
  11688. child.text = child.text.replace(/\u2212/, "-").replace(/\u2217/, "*");
  11689. } else {
  11690. isAllString = false;
  11691. }
  11692. break;
  11693. }
  11694. default:
  11695. isAllString = false;
  11696. }
  11697. } else {
  11698. isAllString = false;
  11699. }
  11700. }
  11701. if (isAllString) {
  11702. // Write a single TextNode instead of multiple nested tags.
  11703. var word = expression.map(node => node.toText()).join("");
  11704. expression = [new mathMLTree.TextNode(word)];
  11705. }
  11706. var identifier = new mathMLTree.MathNode("mi", expression);
  11707. identifier.setAttribute("mathvariant", "normal"); // \u2061 is the same as &ApplyFunction;
  11708. // ref: https://www.w3schools.com/charsets/ref_html_entities_a.asp
  11709. var operator = new mathMLTree.MathNode("mo", [makeText("\u2061", "text")]);
  11710. if (group.parentIsSupSub) {
  11711. return new mathMLTree.MathNode("mrow", [identifier, operator]);
  11712. } else {
  11713. return mathMLTree.newDocumentFragment([identifier, operator]);
  11714. }
  11715. }; // \operatorname
  11716. // amsopn.dtx: \mathop{#1\kern\z@\operator@font#3}\newmcodes@
  11717. defineFunction({
  11718. type: "operatorname",
  11719. names: ["\\operatorname@", "\\operatornamewithlimits"],
  11720. props: {
  11721. numArgs: 1
  11722. },
  11723. handler: (_ref, args) => {
  11724. var {
  11725. parser,
  11726. funcName
  11727. } = _ref;
  11728. var body = args[0];
  11729. return {
  11730. type: "operatorname",
  11731. mode: parser.mode,
  11732. body: ordargument(body),
  11733. alwaysHandleSupSub: funcName === "\\operatornamewithlimits",
  11734. limits: false,
  11735. parentIsSupSub: false
  11736. };
  11737. },
  11738. htmlBuilder: htmlBuilder$1,
  11739. mathmlBuilder
  11740. });
  11741. defineMacro("\\operatorname", "\\@ifstar\\operatornamewithlimits\\operatorname@");
  11742. defineFunctionBuilders({
  11743. type: "ordgroup",
  11744. htmlBuilder(group, options) {
  11745. if (group.semisimple) {
  11746. return buildCommon.makeFragment(buildExpression$1(group.body, options, false));
  11747. }
  11748. return buildCommon.makeSpan(["mord"], buildExpression$1(group.body, options, true), options);
  11749. },
  11750. mathmlBuilder(group, options) {
  11751. return buildExpressionRow(group.body, options, true);
  11752. }
  11753. });
  11754. defineFunction({
  11755. type: "overline",
  11756. names: ["\\overline"],
  11757. props: {
  11758. numArgs: 1
  11759. },
  11760. handler(_ref, args) {
  11761. var {
  11762. parser
  11763. } = _ref;
  11764. var body = args[0];
  11765. return {
  11766. type: "overline",
  11767. mode: parser.mode,
  11768. body
  11769. };
  11770. },
  11771. htmlBuilder(group, options) {
  11772. // Overlines are handled in the TeXbook pg 443, Rule 9.
  11773. // Build the inner group in the cramped style.
  11774. var innerGroup = buildGroup$1(group.body, options.havingCrampedStyle()); // Create the line above the body
  11775. var line = buildCommon.makeLineSpan("overline-line", options); // Generate the vlist, with the appropriate kerns
  11776. var defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
  11777. var vlist = buildCommon.makeVList({
  11778. positionType: "firstBaseline",
  11779. children: [{
  11780. type: "elem",
  11781. elem: innerGroup
  11782. }, {
  11783. type: "kern",
  11784. size: 3 * defaultRuleThickness
  11785. }, {
  11786. type: "elem",
  11787. elem: line
  11788. }, {
  11789. type: "kern",
  11790. size: defaultRuleThickness
  11791. }]
  11792. }, options);
  11793. return buildCommon.makeSpan(["mord", "overline"], [vlist], options);
  11794. },
  11795. mathmlBuilder(group, options) {
  11796. var operator = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode("\u203e")]);
  11797. operator.setAttribute("stretchy", "true");
  11798. var node = new mathMLTree.MathNode("mover", [buildGroup(group.body, options), operator]);
  11799. node.setAttribute("accent", "true");
  11800. return node;
  11801. }
  11802. });
  11803. defineFunction({
  11804. type: "phantom",
  11805. names: ["\\phantom"],
  11806. props: {
  11807. numArgs: 1,
  11808. allowedInText: true
  11809. },
  11810. handler: (_ref, args) => {
  11811. var {
  11812. parser
  11813. } = _ref;
  11814. var body = args[0];
  11815. return {
  11816. type: "phantom",
  11817. mode: parser.mode,
  11818. body: ordargument(body)
  11819. };
  11820. },
  11821. htmlBuilder: (group, options) => {
  11822. var elements = buildExpression$1(group.body, options.withPhantom(), false); // \phantom isn't supposed to affect the elements it contains.
  11823. // See "color" for more details.
  11824. return buildCommon.makeFragment(elements);
  11825. },
  11826. mathmlBuilder: (group, options) => {
  11827. var inner = buildExpression(group.body, options);
  11828. return new mathMLTree.MathNode("mphantom", inner);
  11829. }
  11830. });
  11831. defineFunction({
  11832. type: "hphantom",
  11833. names: ["\\hphantom"],
  11834. props: {
  11835. numArgs: 1,
  11836. allowedInText: true
  11837. },
  11838. handler: (_ref2, args) => {
  11839. var {
  11840. parser
  11841. } = _ref2;
  11842. var body = args[0];
  11843. return {
  11844. type: "hphantom",
  11845. mode: parser.mode,
  11846. body
  11847. };
  11848. },
  11849. htmlBuilder: (group, options) => {
  11850. var node = buildCommon.makeSpan([], [buildGroup$1(group.body, options.withPhantom())]);
  11851. node.height = 0;
  11852. node.depth = 0;
  11853. if (node.children) {
  11854. for (var i = 0; i < node.children.length; i++) {
  11855. node.children[i].height = 0;
  11856. node.children[i].depth = 0;
  11857. }
  11858. } // See smash for comment re: use of makeVList
  11859. node = buildCommon.makeVList({
  11860. positionType: "firstBaseline",
  11861. children: [{
  11862. type: "elem",
  11863. elem: node
  11864. }]
  11865. }, options); // For spacing, TeX treats \smash as a math group (same spacing as ord).
  11866. return buildCommon.makeSpan(["mord"], [node], options);
  11867. },
  11868. mathmlBuilder: (group, options) => {
  11869. var inner = buildExpression(ordargument(group.body), options);
  11870. var phantom = new mathMLTree.MathNode("mphantom", inner);
  11871. var node = new mathMLTree.MathNode("mpadded", [phantom]);
  11872. node.setAttribute("height", "0px");
  11873. node.setAttribute("depth", "0px");
  11874. return node;
  11875. }
  11876. });
  11877. defineFunction({
  11878. type: "vphantom",
  11879. names: ["\\vphantom"],
  11880. props: {
  11881. numArgs: 1,
  11882. allowedInText: true
  11883. },
  11884. handler: (_ref3, args) => {
  11885. var {
  11886. parser
  11887. } = _ref3;
  11888. var body = args[0];
  11889. return {
  11890. type: "vphantom",
  11891. mode: parser.mode,
  11892. body
  11893. };
  11894. },
  11895. htmlBuilder: (group, options) => {
  11896. var inner = buildCommon.makeSpan(["inner"], [buildGroup$1(group.body, options.withPhantom())]);
  11897. var fix = buildCommon.makeSpan(["fix"], []);
  11898. return buildCommon.makeSpan(["mord", "rlap"], [inner, fix], options);
  11899. },
  11900. mathmlBuilder: (group, options) => {
  11901. var inner = buildExpression(ordargument(group.body), options);
  11902. var phantom = new mathMLTree.MathNode("mphantom", inner);
  11903. var node = new mathMLTree.MathNode("mpadded", [phantom]);
  11904. node.setAttribute("width", "0px");
  11905. return node;
  11906. }
  11907. });
  11908. defineFunction({
  11909. type: "raisebox",
  11910. names: ["\\raisebox"],
  11911. props: {
  11912. numArgs: 2,
  11913. argTypes: ["size", "hbox"],
  11914. allowedInText: true
  11915. },
  11916. handler(_ref, args) {
  11917. var {
  11918. parser
  11919. } = _ref;
  11920. var amount = assertNodeType(args[0], "size").value;
  11921. var body = args[1];
  11922. return {
  11923. type: "raisebox",
  11924. mode: parser.mode,
  11925. dy: amount,
  11926. body
  11927. };
  11928. },
  11929. htmlBuilder(group, options) {
  11930. var body = buildGroup$1(group.body, options);
  11931. var dy = calculateSize(group.dy, options);
  11932. return buildCommon.makeVList({
  11933. positionType: "shift",
  11934. positionData: -dy,
  11935. children: [{
  11936. type: "elem",
  11937. elem: body
  11938. }]
  11939. }, options);
  11940. },
  11941. mathmlBuilder(group, options) {
  11942. var node = new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)]);
  11943. var dy = group.dy.number + group.dy.unit;
  11944. node.setAttribute("voffset", dy);
  11945. return node;
  11946. }
  11947. });
  11948. defineFunction({
  11949. type: "internal",
  11950. names: ["\\relax"],
  11951. props: {
  11952. numArgs: 0,
  11953. allowedInText: true
  11954. },
  11955. handler(_ref) {
  11956. var {
  11957. parser
  11958. } = _ref;
  11959. return {
  11960. type: "internal",
  11961. mode: parser.mode
  11962. };
  11963. }
  11964. });
  11965. defineFunction({
  11966. type: "rule",
  11967. names: ["\\rule"],
  11968. props: {
  11969. numArgs: 2,
  11970. numOptionalArgs: 1,
  11971. argTypes: ["size", "size", "size"]
  11972. },
  11973. handler(_ref, args, optArgs) {
  11974. var {
  11975. parser
  11976. } = _ref;
  11977. var shift = optArgs[0];
  11978. var width = assertNodeType(args[0], "size");
  11979. var height = assertNodeType(args[1], "size");
  11980. return {
  11981. type: "rule",
  11982. mode: parser.mode,
  11983. shift: shift && assertNodeType(shift, "size").value,
  11984. width: width.value,
  11985. height: height.value
  11986. };
  11987. },
  11988. htmlBuilder(group, options) {
  11989. // Make an empty span for the rule
  11990. var rule = buildCommon.makeSpan(["mord", "rule"], [], options); // Calculate the shift, width, and height of the rule, and account for units
  11991. var width = calculateSize(group.width, options);
  11992. var height = calculateSize(group.height, options);
  11993. var shift = group.shift ? calculateSize(group.shift, options) : 0; // Style the rule to the right size
  11994. rule.style.borderRightWidth = makeEm(width);
  11995. rule.style.borderTopWidth = makeEm(height);
  11996. rule.style.bottom = makeEm(shift); // Record the height and width
  11997. rule.width = width;
  11998. rule.height = height + shift;
  11999. rule.depth = -shift; // Font size is the number large enough that the browser will
  12000. // reserve at least `absHeight` space above the baseline.
  12001. // The 1.125 factor was empirically determined
  12002. rule.maxFontSize = height * 1.125 * options.sizeMultiplier;
  12003. return rule;
  12004. },
  12005. mathmlBuilder(group, options) {
  12006. var width = calculateSize(group.width, options);
  12007. var height = calculateSize(group.height, options);
  12008. var shift = group.shift ? calculateSize(group.shift, options) : 0;
  12009. var color = options.color && options.getColor() || "black";
  12010. var rule = new mathMLTree.MathNode("mspace");
  12011. rule.setAttribute("mathbackground", color);
  12012. rule.setAttribute("width", makeEm(width));
  12013. rule.setAttribute("height", makeEm(height));
  12014. var wrapper = new mathMLTree.MathNode("mpadded", [rule]);
  12015. if (shift >= 0) {
  12016. wrapper.setAttribute("height", makeEm(shift));
  12017. } else {
  12018. wrapper.setAttribute("height", makeEm(shift));
  12019. wrapper.setAttribute("depth", makeEm(-shift));
  12020. }
  12021. wrapper.setAttribute("voffset", makeEm(shift));
  12022. return wrapper;
  12023. }
  12024. });
  12025. function sizingGroup(value, options, baseOptions) {
  12026. var inner = buildExpression$1(value, options, false);
  12027. var multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier; // Add size-resetting classes to the inner list and set maxFontSize
  12028. // manually. Handle nested size changes.
  12029. for (var i = 0; i < inner.length; i++) {
  12030. var pos = inner[i].classes.indexOf("sizing");
  12031. if (pos < 0) {
  12032. Array.prototype.push.apply(inner[i].classes, options.sizingClasses(baseOptions));
  12033. } else if (inner[i].classes[pos + 1] === "reset-size" + options.size) {
  12034. // This is a nested size change: e.g., inner[i] is the "b" in
  12035. // `\Huge a \small b`. Override the old size (the `reset-` class)
  12036. // but not the new size.
  12037. inner[i].classes[pos + 1] = "reset-size" + baseOptions.size;
  12038. }
  12039. inner[i].height *= multiplier;
  12040. inner[i].depth *= multiplier;
  12041. }
  12042. return buildCommon.makeFragment(inner);
  12043. }
  12044. var sizeFuncs = ["\\tiny", "\\sixptsize", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize", "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge"];
  12045. var htmlBuilder = (group, options) => {
  12046. // Handle sizing operators like \Huge. Real TeX doesn't actually allow
  12047. // these functions inside of math expressions, so we do some special
  12048. // handling.
  12049. var newOptions = options.havingSize(group.size);
  12050. return sizingGroup(group.body, newOptions, options);
  12051. };
  12052. defineFunction({
  12053. type: "sizing",
  12054. names: sizeFuncs,
  12055. props: {
  12056. numArgs: 0,
  12057. allowedInText: true
  12058. },
  12059. handler: (_ref, args) => {
  12060. var {
  12061. breakOnTokenText,
  12062. funcName,
  12063. parser
  12064. } = _ref;
  12065. var body = parser.parseExpression(false, breakOnTokenText);
  12066. return {
  12067. type: "sizing",
  12068. mode: parser.mode,
  12069. // Figure out what size to use based on the list of functions above
  12070. size: sizeFuncs.indexOf(funcName) + 1,
  12071. body
  12072. };
  12073. },
  12074. htmlBuilder,
  12075. mathmlBuilder: (group, options) => {
  12076. var newOptions = options.havingSize(group.size);
  12077. var inner = buildExpression(group.body, newOptions);
  12078. var node = new mathMLTree.MathNode("mstyle", inner); // TODO(emily): This doesn't produce the correct size for nested size
  12079. // changes, because we don't keep state of what style we're currently
  12080. // in, so we can't reset the size to normal before changing it. Now
  12081. // that we're passing an options parameter we should be able to fix
  12082. // this.
  12083. node.setAttribute("mathsize", makeEm(newOptions.sizeMultiplier));
  12084. return node;
  12085. }
  12086. });
  12087. // smash, with optional [tb], as in AMS
  12088. defineFunction({
  12089. type: "smash",
  12090. names: ["\\smash"],
  12091. props: {
  12092. numArgs: 1,
  12093. numOptionalArgs: 1,
  12094. allowedInText: true
  12095. },
  12096. handler: (_ref, args, optArgs) => {
  12097. var {
  12098. parser
  12099. } = _ref;
  12100. var smashHeight = false;
  12101. var smashDepth = false;
  12102. var tbArg = optArgs[0] && assertNodeType(optArgs[0], "ordgroup");
  12103. if (tbArg) {
  12104. // Optional [tb] argument is engaged.
  12105. // ref: amsmath: \renewcommand{\smash}[1][tb]{%
  12106. // def\mb@t{\ht}\def\mb@b{\dp}\def\mb@tb{\ht\z@\z@\dp}%
  12107. var letter = "";
  12108. for (var i = 0; i < tbArg.body.length; ++i) {
  12109. var node = tbArg.body[i]; // $FlowFixMe: Not every node type has a `text` property.
  12110. letter = node.text;
  12111. if (letter === "t") {
  12112. smashHeight = true;
  12113. } else if (letter === "b") {
  12114. smashDepth = true;
  12115. } else {
  12116. smashHeight = false;
  12117. smashDepth = false;
  12118. break;
  12119. }
  12120. }
  12121. } else {
  12122. smashHeight = true;
  12123. smashDepth = true;
  12124. }
  12125. var body = args[0];
  12126. return {
  12127. type: "smash",
  12128. mode: parser.mode,
  12129. body,
  12130. smashHeight,
  12131. smashDepth
  12132. };
  12133. },
  12134. htmlBuilder: (group, options) => {
  12135. var node = buildCommon.makeSpan([], [buildGroup$1(group.body, options)]);
  12136. if (!group.smashHeight && !group.smashDepth) {
  12137. return node;
  12138. }
  12139. if (group.smashHeight) {
  12140. node.height = 0; // In order to influence makeVList, we have to reset the children.
  12141. if (node.children) {
  12142. for (var i = 0; i < node.children.length; i++) {
  12143. node.children[i].height = 0;
  12144. }
  12145. }
  12146. }
  12147. if (group.smashDepth) {
  12148. node.depth = 0;
  12149. if (node.children) {
  12150. for (var _i = 0; _i < node.children.length; _i++) {
  12151. node.children[_i].depth = 0;
  12152. }
  12153. }
  12154. } // At this point, we've reset the TeX-like height and depth values.
  12155. // But the span still has an HTML line height.
  12156. // makeVList applies "display: table-cell", which prevents the browser
  12157. // from acting on that line height. So we'll call makeVList now.
  12158. var smashedNode = buildCommon.makeVList({
  12159. positionType: "firstBaseline",
  12160. children: [{
  12161. type: "elem",
  12162. elem: node
  12163. }]
  12164. }, options); // For spacing, TeX treats \hphantom as a math group (same spacing as ord).
  12165. return buildCommon.makeSpan(["mord"], [smashedNode], options);
  12166. },
  12167. mathmlBuilder: (group, options) => {
  12168. var node = new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)]);
  12169. if (group.smashHeight) {
  12170. node.setAttribute("height", "0px");
  12171. }
  12172. if (group.smashDepth) {
  12173. node.setAttribute("depth", "0px");
  12174. }
  12175. return node;
  12176. }
  12177. });
  12178. defineFunction({
  12179. type: "sqrt",
  12180. names: ["\\sqrt"],
  12181. props: {
  12182. numArgs: 1,
  12183. numOptionalArgs: 1
  12184. },
  12185. handler(_ref, args, optArgs) {
  12186. var {
  12187. parser
  12188. } = _ref;
  12189. var index = optArgs[0];
  12190. var body = args[0];
  12191. return {
  12192. type: "sqrt",
  12193. mode: parser.mode,
  12194. body,
  12195. index
  12196. };
  12197. },
  12198. htmlBuilder(group, options) {
  12199. // Square roots are handled in the TeXbook pg. 443, Rule 11.
  12200. // First, we do the same steps as in overline to build the inner group
  12201. // and line
  12202. var inner = buildGroup$1(group.body, options.havingCrampedStyle());
  12203. if (inner.height === 0) {
  12204. // Render a small surd.
  12205. inner.height = options.fontMetrics().xHeight;
  12206. } // Some groups can return document fragments. Handle those by wrapping
  12207. // them in a span.
  12208. inner = buildCommon.wrapFragment(inner, options); // Calculate the minimum size for the \surd delimiter
  12209. var metrics = options.fontMetrics();
  12210. var theta = metrics.defaultRuleThickness;
  12211. var phi = theta;
  12212. if (options.style.id < Style$1.TEXT.id) {
  12213. phi = options.fontMetrics().xHeight;
  12214. } // Calculate the clearance between the body and line
  12215. var lineClearance = theta + phi / 4;
  12216. var minDelimiterHeight = inner.height + inner.depth + lineClearance + theta; // Create a sqrt SVG of the required minimum size
  12217. var {
  12218. span: img,
  12219. ruleWidth,
  12220. advanceWidth
  12221. } = delimiter.sqrtImage(minDelimiterHeight, options);
  12222. var delimDepth = img.height - ruleWidth; // Adjust the clearance based on the delimiter size
  12223. if (delimDepth > inner.height + inner.depth + lineClearance) {
  12224. lineClearance = (lineClearance + delimDepth - inner.height - inner.depth) / 2;
  12225. } // Shift the sqrt image
  12226. var imgShift = img.height - inner.height - lineClearance - ruleWidth;
  12227. inner.style.paddingLeft = makeEm(advanceWidth); // Overlay the image and the argument.
  12228. var body = buildCommon.makeVList({
  12229. positionType: "firstBaseline",
  12230. children: [{
  12231. type: "elem",
  12232. elem: inner,
  12233. wrapperClasses: ["svg-align"]
  12234. }, {
  12235. type: "kern",
  12236. size: -(inner.height + imgShift)
  12237. }, {
  12238. type: "elem",
  12239. elem: img
  12240. }, {
  12241. type: "kern",
  12242. size: ruleWidth
  12243. }]
  12244. }, options);
  12245. if (!group.index) {
  12246. return buildCommon.makeSpan(["mord", "sqrt"], [body], options);
  12247. } else {
  12248. // Handle the optional root index
  12249. // The index is always in scriptscript style
  12250. var newOptions = options.havingStyle(Style$1.SCRIPTSCRIPT);
  12251. var rootm = buildGroup$1(group.index, newOptions, options); // The amount the index is shifted by. This is taken from the TeX
  12252. // source, in the definition of `\r@@t`.
  12253. var toShift = 0.6 * (body.height - body.depth); // Build a VList with the superscript shifted up correctly
  12254. var rootVList = buildCommon.makeVList({
  12255. positionType: "shift",
  12256. positionData: -toShift,
  12257. children: [{
  12258. type: "elem",
  12259. elem: rootm
  12260. }]
  12261. }, options); // Add a class surrounding it so we can add on the appropriate
  12262. // kerning
  12263. var rootVListWrap = buildCommon.makeSpan(["root"], [rootVList]);
  12264. return buildCommon.makeSpan(["mord", "sqrt"], [rootVListWrap, body], options);
  12265. }
  12266. },
  12267. mathmlBuilder(group, options) {
  12268. var {
  12269. body,
  12270. index
  12271. } = group;
  12272. return index ? new mathMLTree.MathNode("mroot", [buildGroup(body, options), buildGroup(index, options)]) : new mathMLTree.MathNode("msqrt", [buildGroup(body, options)]);
  12273. }
  12274. });
  12275. var styleMap = {
  12276. "display": Style$1.DISPLAY,
  12277. "text": Style$1.TEXT,
  12278. "script": Style$1.SCRIPT,
  12279. "scriptscript": Style$1.SCRIPTSCRIPT
  12280. };
  12281. defineFunction({
  12282. type: "styling",
  12283. names: ["\\displaystyle", "\\textstyle", "\\scriptstyle", "\\scriptscriptstyle"],
  12284. props: {
  12285. numArgs: 0,
  12286. allowedInText: true,
  12287. primitive: true
  12288. },
  12289. handler(_ref, args) {
  12290. var {
  12291. breakOnTokenText,
  12292. funcName,
  12293. parser
  12294. } = _ref;
  12295. // parse out the implicit body
  12296. var body = parser.parseExpression(true, breakOnTokenText); // TODO: Refactor to avoid duplicating styleMap in multiple places (e.g.
  12297. // here and in buildHTML and de-dupe the enumeration of all the styles).
  12298. // $FlowFixMe: The names above exactly match the styles.
  12299. var style = funcName.slice(1, funcName.length - 5);
  12300. return {
  12301. type: "styling",
  12302. mode: parser.mode,
  12303. // Figure out what style to use by pulling out the style from
  12304. // the function name
  12305. style,
  12306. body
  12307. };
  12308. },
  12309. htmlBuilder(group, options) {
  12310. // Style changes are handled in the TeXbook on pg. 442, Rule 3.
  12311. var newStyle = styleMap[group.style];
  12312. var newOptions = options.havingStyle(newStyle).withFont('');
  12313. return sizingGroup(group.body, newOptions, options);
  12314. },
  12315. mathmlBuilder(group, options) {
  12316. // Figure out what style we're changing to.
  12317. var newStyle = styleMap[group.style];
  12318. var newOptions = options.havingStyle(newStyle);
  12319. var inner = buildExpression(group.body, newOptions);
  12320. var node = new mathMLTree.MathNode("mstyle", inner);
  12321. var styleAttributes = {
  12322. "display": ["0", "true"],
  12323. "text": ["0", "false"],
  12324. "script": ["1", "false"],
  12325. "scriptscript": ["2", "false"]
  12326. };
  12327. var attr = styleAttributes[group.style];
  12328. node.setAttribute("scriptlevel", attr[0]);
  12329. node.setAttribute("displaystyle", attr[1]);
  12330. return node;
  12331. }
  12332. });
  12333. /**
  12334. * Sometimes, groups perform special rules when they have superscripts or
  12335. * subscripts attached to them. This function lets the `supsub` group know that
  12336. * Sometimes, groups perform special rules when they have superscripts or
  12337. * its inner element should handle the superscripts and subscripts instead of
  12338. * handling them itself.
  12339. */
  12340. var htmlBuilderDelegate = function htmlBuilderDelegate(group, options) {
  12341. var base = group.base;
  12342. if (!base) {
  12343. return null;
  12344. } else if (base.type === "op") {
  12345. // Operators handle supsubs differently when they have limits
  12346. // (e.g. `\displaystyle\sum_2^3`)
  12347. var delegate = base.limits && (options.style.size === Style$1.DISPLAY.size || base.alwaysHandleSupSub);
  12348. return delegate ? htmlBuilder$2 : null;
  12349. } else if (base.type === "operatorname") {
  12350. var _delegate = base.alwaysHandleSupSub && (options.style.size === Style$1.DISPLAY.size || base.limits);
  12351. return _delegate ? htmlBuilder$1 : null;
  12352. } else if (base.type === "accent") {
  12353. return utils.isCharacterBox(base.base) ? htmlBuilder$a : null;
  12354. } else if (base.type === "horizBrace") {
  12355. var isSup = !group.sub;
  12356. return isSup === base.isOver ? htmlBuilder$3 : null;
  12357. } else {
  12358. return null;
  12359. }
  12360. }; // Super scripts and subscripts, whose precise placement can depend on other
  12361. // functions that precede them.
  12362. defineFunctionBuilders({
  12363. type: "supsub",
  12364. htmlBuilder(group, options) {
  12365. // Superscript and subscripts are handled in the TeXbook on page
  12366. // 445-446, rules 18(a-f).
  12367. // Here is where we defer to the inner group if it should handle
  12368. // superscripts and subscripts itself.
  12369. var builderDelegate = htmlBuilderDelegate(group, options);
  12370. if (builderDelegate) {
  12371. return builderDelegate(group, options);
  12372. }
  12373. var {
  12374. base: valueBase,
  12375. sup: valueSup,
  12376. sub: valueSub
  12377. } = group;
  12378. var base = buildGroup$1(valueBase, options);
  12379. var supm;
  12380. var subm;
  12381. var metrics = options.fontMetrics(); // Rule 18a
  12382. var supShift = 0;
  12383. var subShift = 0;
  12384. var isCharacterBox = valueBase && utils.isCharacterBox(valueBase);
  12385. if (valueSup) {
  12386. var newOptions = options.havingStyle(options.style.sup());
  12387. supm = buildGroup$1(valueSup, newOptions, options);
  12388. if (!isCharacterBox) {
  12389. supShift = base.height - newOptions.fontMetrics().supDrop * newOptions.sizeMultiplier / options.sizeMultiplier;
  12390. }
  12391. }
  12392. if (valueSub) {
  12393. var _newOptions = options.havingStyle(options.style.sub());
  12394. subm = buildGroup$1(valueSub, _newOptions, options);
  12395. if (!isCharacterBox) {
  12396. subShift = base.depth + _newOptions.fontMetrics().subDrop * _newOptions.sizeMultiplier / options.sizeMultiplier;
  12397. }
  12398. } // Rule 18c
  12399. var minSupShift;
  12400. if (options.style === Style$1.DISPLAY) {
  12401. minSupShift = metrics.sup1;
  12402. } else if (options.style.cramped) {
  12403. minSupShift = metrics.sup3;
  12404. } else {
  12405. minSupShift = metrics.sup2;
  12406. } // scriptspace is a font-size-independent size, so scale it
  12407. // appropriately for use as the marginRight.
  12408. var multiplier = options.sizeMultiplier;
  12409. var marginRight = makeEm(0.5 / metrics.ptPerEm / multiplier);
  12410. var marginLeft = null;
  12411. if (subm) {
  12412. // Subscripts shouldn't be shifted by the base's italic correction.
  12413. // Account for that by shifting the subscript back the appropriate
  12414. // amount. Note we only do this when the base is a single symbol.
  12415. var isOiint = group.base && group.base.type === "op" && group.base.name && (group.base.name === "\\oiint" || group.base.name === "\\oiiint");
  12416. if (base instanceof SymbolNode || isOiint) {
  12417. // $FlowFixMe
  12418. marginLeft = makeEm(-base.italic);
  12419. }
  12420. }
  12421. var supsub;
  12422. if (supm && subm) {
  12423. supShift = Math.max(supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
  12424. subShift = Math.max(subShift, metrics.sub2);
  12425. var ruleWidth = metrics.defaultRuleThickness; // Rule 18e
  12426. var maxWidth = 4 * ruleWidth;
  12427. if (supShift - supm.depth - (subm.height - subShift) < maxWidth) {
  12428. subShift = maxWidth - (supShift - supm.depth) + subm.height;
  12429. var psi = 0.8 * metrics.xHeight - (supShift - supm.depth);
  12430. if (psi > 0) {
  12431. supShift += psi;
  12432. subShift -= psi;
  12433. }
  12434. }
  12435. var vlistElem = [{
  12436. type: "elem",
  12437. elem: subm,
  12438. shift: subShift,
  12439. marginRight,
  12440. marginLeft
  12441. }, {
  12442. type: "elem",
  12443. elem: supm,
  12444. shift: -supShift,
  12445. marginRight
  12446. }];
  12447. supsub = buildCommon.makeVList({
  12448. positionType: "individualShift",
  12449. children: vlistElem
  12450. }, options);
  12451. } else if (subm) {
  12452. // Rule 18b
  12453. subShift = Math.max(subShift, metrics.sub1, subm.height - 0.8 * metrics.xHeight);
  12454. var _vlistElem = [{
  12455. type: "elem",
  12456. elem: subm,
  12457. marginLeft,
  12458. marginRight
  12459. }];
  12460. supsub = buildCommon.makeVList({
  12461. positionType: "shift",
  12462. positionData: subShift,
  12463. children: _vlistElem
  12464. }, options);
  12465. } else if (supm) {
  12466. // Rule 18c, d
  12467. supShift = Math.max(supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
  12468. supsub = buildCommon.makeVList({
  12469. positionType: "shift",
  12470. positionData: -supShift,
  12471. children: [{
  12472. type: "elem",
  12473. elem: supm,
  12474. marginRight
  12475. }]
  12476. }, options);
  12477. } else {
  12478. throw new Error("supsub must have either sup or sub.");
  12479. } // Wrap the supsub vlist in a span.msupsub to reset text-align.
  12480. var mclass = getTypeOfDomTree(base, "right") || "mord";
  12481. return buildCommon.makeSpan([mclass], [base, buildCommon.makeSpan(["msupsub"], [supsub])], options);
  12482. },
  12483. mathmlBuilder(group, options) {
  12484. // Is the inner group a relevant horizonal brace?
  12485. var isBrace = false;
  12486. var isOver;
  12487. var isSup;
  12488. if (group.base && group.base.type === "horizBrace") {
  12489. isSup = !!group.sup;
  12490. if (isSup === group.base.isOver) {
  12491. isBrace = true;
  12492. isOver = group.base.isOver;
  12493. }
  12494. }
  12495. if (group.base && (group.base.type === "op" || group.base.type === "operatorname")) {
  12496. group.base.parentIsSupSub = true;
  12497. }
  12498. var children = [buildGroup(group.base, options)];
  12499. if (group.sub) {
  12500. children.push(buildGroup(group.sub, options));
  12501. }
  12502. if (group.sup) {
  12503. children.push(buildGroup(group.sup, options));
  12504. }
  12505. var nodeType;
  12506. if (isBrace) {
  12507. nodeType = isOver ? "mover" : "munder";
  12508. } else if (!group.sub) {
  12509. var base = group.base;
  12510. if (base && base.type === "op" && base.limits && (options.style === Style$1.DISPLAY || base.alwaysHandleSupSub)) {
  12511. nodeType = "mover";
  12512. } else if (base && base.type === "operatorname" && base.alwaysHandleSupSub && (base.limits || options.style === Style$1.DISPLAY)) {
  12513. nodeType = "mover";
  12514. } else {
  12515. nodeType = "msup";
  12516. }
  12517. } else if (!group.sup) {
  12518. var _base = group.base;
  12519. if (_base && _base.type === "op" && _base.limits && (options.style === Style$1.DISPLAY || _base.alwaysHandleSupSub)) {
  12520. nodeType = "munder";
  12521. } else if (_base && _base.type === "operatorname" && _base.alwaysHandleSupSub && (_base.limits || options.style === Style$1.DISPLAY)) {
  12522. nodeType = "munder";
  12523. } else {
  12524. nodeType = "msub";
  12525. }
  12526. } else {
  12527. var _base2 = group.base;
  12528. if (_base2 && _base2.type === "op" && _base2.limits && options.style === Style$1.DISPLAY) {
  12529. nodeType = "munderover";
  12530. } else if (_base2 && _base2.type === "operatorname" && _base2.alwaysHandleSupSub && (options.style === Style$1.DISPLAY || _base2.limits)) {
  12531. nodeType = "munderover";
  12532. } else {
  12533. nodeType = "msubsup";
  12534. }
  12535. }
  12536. return new mathMLTree.MathNode(nodeType, children);
  12537. }
  12538. });
  12539. defineFunctionBuilders({
  12540. type: "atom",
  12541. htmlBuilder(group, options) {
  12542. return buildCommon.mathsym(group.text, group.mode, options, ["m" + group.family]);
  12543. },
  12544. mathmlBuilder(group, options) {
  12545. var node = new mathMLTree.MathNode("mo", [makeText(group.text, group.mode)]);
  12546. if (group.family === "bin") {
  12547. var variant = getVariant(group, options);
  12548. if (variant === "bold-italic") {
  12549. node.setAttribute("mathvariant", variant);
  12550. }
  12551. } else if (group.family === "punct") {
  12552. node.setAttribute("separator", "true");
  12553. } else if (group.family === "open" || group.family === "close") {
  12554. // Delims built here should not stretch vertically.
  12555. // See delimsizing.js for stretchy delims.
  12556. node.setAttribute("stretchy", "false");
  12557. }
  12558. return node;
  12559. }
  12560. });
  12561. // "mathord" and "textord" ParseNodes created in Parser.js from symbol Groups in
  12562. // src/symbols.js.
  12563. var defaultVariant = {
  12564. "mi": "italic",
  12565. "mn": "normal",
  12566. "mtext": "normal"
  12567. };
  12568. defineFunctionBuilders({
  12569. type: "mathord",
  12570. htmlBuilder(group, options) {
  12571. return buildCommon.makeOrd(group, options, "mathord");
  12572. },
  12573. mathmlBuilder(group, options) {
  12574. var node = new mathMLTree.MathNode("mi", [makeText(group.text, group.mode, options)]);
  12575. var variant = getVariant(group, options) || "italic";
  12576. if (variant !== defaultVariant[node.type]) {
  12577. node.setAttribute("mathvariant", variant);
  12578. }
  12579. return node;
  12580. }
  12581. });
  12582. defineFunctionBuilders({
  12583. type: "textord",
  12584. htmlBuilder(group, options) {
  12585. return buildCommon.makeOrd(group, options, "textord");
  12586. },
  12587. mathmlBuilder(group, options) {
  12588. var text = makeText(group.text, group.mode, options);
  12589. var variant = getVariant(group, options) || "normal";
  12590. var node;
  12591. if (group.mode === 'text') {
  12592. node = new mathMLTree.MathNode("mtext", [text]);
  12593. } else if (/[0-9]/.test(group.text)) {
  12594. node = new mathMLTree.MathNode("mn", [text]);
  12595. } else if (group.text === "\\prime") {
  12596. node = new mathMLTree.MathNode("mo", [text]);
  12597. } else {
  12598. node = new mathMLTree.MathNode("mi", [text]);
  12599. }
  12600. if (variant !== defaultVariant[node.type]) {
  12601. node.setAttribute("mathvariant", variant);
  12602. }
  12603. return node;
  12604. }
  12605. });
  12606. var cssSpace = {
  12607. "\\nobreak": "nobreak",
  12608. "\\allowbreak": "allowbreak"
  12609. }; // A lookup table to determine whether a spacing function/symbol should be
  12610. // treated like a regular space character. If a symbol or command is a key
  12611. // in this table, then it should be a regular space character. Furthermore,
  12612. // the associated value may have a `className` specifying an extra CSS class
  12613. // to add to the created `span`.
  12614. var regularSpace = {
  12615. " ": {},
  12616. "\\ ": {},
  12617. "~": {
  12618. className: "nobreak"
  12619. },
  12620. "\\space": {},
  12621. "\\nobreakspace": {
  12622. className: "nobreak"
  12623. }
  12624. }; // ParseNode<"spacing"> created in Parser.js from the "spacing" symbol Groups in
  12625. // src/symbols.js.
  12626. defineFunctionBuilders({
  12627. type: "spacing",
  12628. htmlBuilder(group, options) {
  12629. if (regularSpace.hasOwnProperty(group.text)) {
  12630. var className = regularSpace[group.text].className || ""; // Spaces are generated by adding an actual space. Each of these
  12631. // things has an entry in the symbols table, so these will be turned
  12632. // into appropriate outputs.
  12633. if (group.mode === "text") {
  12634. var ord = buildCommon.makeOrd(group, options, "textord");
  12635. ord.classes.push(className);
  12636. return ord;
  12637. } else {
  12638. return buildCommon.makeSpan(["mspace", className], [buildCommon.mathsym(group.text, group.mode, options)], options);
  12639. }
  12640. } else if (cssSpace.hasOwnProperty(group.text)) {
  12641. // Spaces based on just a CSS class.
  12642. return buildCommon.makeSpan(["mspace", cssSpace[group.text]], [], options);
  12643. } else {
  12644. throw new ParseError("Unknown type of space \"" + group.text + "\"");
  12645. }
  12646. },
  12647. mathmlBuilder(group, options) {
  12648. var node;
  12649. if (regularSpace.hasOwnProperty(group.text)) {
  12650. node = new mathMLTree.MathNode("mtext", [new mathMLTree.TextNode("\u00a0")]);
  12651. } else if (cssSpace.hasOwnProperty(group.text)) {
  12652. // CSS-based MathML spaces (\nobreak, \allowbreak) are ignored
  12653. return new mathMLTree.MathNode("mspace");
  12654. } else {
  12655. throw new ParseError("Unknown type of space \"" + group.text + "\"");
  12656. }
  12657. return node;
  12658. }
  12659. });
  12660. var pad = () => {
  12661. var padNode = new mathMLTree.MathNode("mtd", []);
  12662. padNode.setAttribute("width", "50%");
  12663. return padNode;
  12664. };
  12665. defineFunctionBuilders({
  12666. type: "tag",
  12667. mathmlBuilder(group, options) {
  12668. var table = new mathMLTree.MathNode("mtable", [new mathMLTree.MathNode("mtr", [pad(), new mathMLTree.MathNode("mtd", [buildExpressionRow(group.body, options)]), pad(), new mathMLTree.MathNode("mtd", [buildExpressionRow(group.tag, options)])])]);
  12669. table.setAttribute("width", "100%");
  12670. return table; // TODO: Left-aligned tags.
  12671. // Currently, the group and options passed here do not contain
  12672. // enough info to set tag alignment. `leqno` is in Settings but it is
  12673. // not passed to Options. On the HTML side, leqno is
  12674. // set by a CSS class applied in buildTree.js. That would have worked
  12675. // in MathML if browsers supported <mlabeledtr>. Since they don't, we
  12676. // need to rewrite the way this function is called.
  12677. }
  12678. });
  12679. var textFontFamilies = {
  12680. "\\text": undefined,
  12681. "\\textrm": "textrm",
  12682. "\\textsf": "textsf",
  12683. "\\texttt": "texttt",
  12684. "\\textnormal": "textrm"
  12685. };
  12686. var textFontWeights = {
  12687. "\\textbf": "textbf",
  12688. "\\textmd": "textmd"
  12689. };
  12690. var textFontShapes = {
  12691. "\\textit": "textit",
  12692. "\\textup": "textup"
  12693. };
  12694. var optionsWithFont = (group, options) => {
  12695. var font = group.font; // Checks if the argument is a font family or a font style.
  12696. if (!font) {
  12697. return options;
  12698. } else if (textFontFamilies[font]) {
  12699. return options.withTextFontFamily(textFontFamilies[font]);
  12700. } else if (textFontWeights[font]) {
  12701. return options.withTextFontWeight(textFontWeights[font]);
  12702. } else {
  12703. return options.withTextFontShape(textFontShapes[font]);
  12704. }
  12705. };
  12706. defineFunction({
  12707. type: "text",
  12708. names: [// Font families
  12709. "\\text", "\\textrm", "\\textsf", "\\texttt", "\\textnormal", // Font weights
  12710. "\\textbf", "\\textmd", // Font Shapes
  12711. "\\textit", "\\textup"],
  12712. props: {
  12713. numArgs: 1,
  12714. argTypes: ["text"],
  12715. allowedInArgument: true,
  12716. allowedInText: true
  12717. },
  12718. handler(_ref, args) {
  12719. var {
  12720. parser,
  12721. funcName
  12722. } = _ref;
  12723. var body = args[0];
  12724. return {
  12725. type: "text",
  12726. mode: parser.mode,
  12727. body: ordargument(body),
  12728. font: funcName
  12729. };
  12730. },
  12731. htmlBuilder(group, options) {
  12732. var newOptions = optionsWithFont(group, options);
  12733. var inner = buildExpression$1(group.body, newOptions, true);
  12734. return buildCommon.makeSpan(["mord", "text"], inner, newOptions);
  12735. },
  12736. mathmlBuilder(group, options) {
  12737. var newOptions = optionsWithFont(group, options);
  12738. return buildExpressionRow(group.body, newOptions);
  12739. }
  12740. });
  12741. defineFunction({
  12742. type: "underline",
  12743. names: ["\\underline"],
  12744. props: {
  12745. numArgs: 1,
  12746. allowedInText: true
  12747. },
  12748. handler(_ref, args) {
  12749. var {
  12750. parser
  12751. } = _ref;
  12752. return {
  12753. type: "underline",
  12754. mode: parser.mode,
  12755. body: args[0]
  12756. };
  12757. },
  12758. htmlBuilder(group, options) {
  12759. // Underlines are handled in the TeXbook pg 443, Rule 10.
  12760. // Build the inner group.
  12761. var innerGroup = buildGroup$1(group.body, options); // Create the line to go below the body
  12762. var line = buildCommon.makeLineSpan("underline-line", options); // Generate the vlist, with the appropriate kerns
  12763. var defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
  12764. var vlist = buildCommon.makeVList({
  12765. positionType: "top",
  12766. positionData: innerGroup.height,
  12767. children: [{
  12768. type: "kern",
  12769. size: defaultRuleThickness
  12770. }, {
  12771. type: "elem",
  12772. elem: line
  12773. }, {
  12774. type: "kern",
  12775. size: 3 * defaultRuleThickness
  12776. }, {
  12777. type: "elem",
  12778. elem: innerGroup
  12779. }]
  12780. }, options);
  12781. return buildCommon.makeSpan(["mord", "underline"], [vlist], options);
  12782. },
  12783. mathmlBuilder(group, options) {
  12784. var operator = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode("\u203e")]);
  12785. operator.setAttribute("stretchy", "true");
  12786. var node = new mathMLTree.MathNode("munder", [buildGroup(group.body, options), operator]);
  12787. node.setAttribute("accentunder", "true");
  12788. return node;
  12789. }
  12790. });
  12791. defineFunction({
  12792. type: "vcenter",
  12793. names: ["\\vcenter"],
  12794. props: {
  12795. numArgs: 1,
  12796. argTypes: ["original"],
  12797. // In LaTeX, \vcenter can act only on a box.
  12798. allowedInText: false
  12799. },
  12800. handler(_ref, args) {
  12801. var {
  12802. parser
  12803. } = _ref;
  12804. return {
  12805. type: "vcenter",
  12806. mode: parser.mode,
  12807. body: args[0]
  12808. };
  12809. },
  12810. htmlBuilder(group, options) {
  12811. var body = buildGroup$1(group.body, options);
  12812. var axisHeight = options.fontMetrics().axisHeight;
  12813. var dy = 0.5 * (body.height - axisHeight - (body.depth + axisHeight));
  12814. return buildCommon.makeVList({
  12815. positionType: "shift",
  12816. positionData: dy,
  12817. children: [{
  12818. type: "elem",
  12819. elem: body
  12820. }]
  12821. }, options);
  12822. },
  12823. mathmlBuilder(group, options) {
  12824. // There is no way to do this in MathML.
  12825. // Write a class as a breadcrumb in case some post-processor wants
  12826. // to perform a vcenter adjustment.
  12827. return new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)], ["vcenter"]);
  12828. }
  12829. });
  12830. defineFunction({
  12831. type: "verb",
  12832. names: ["\\verb"],
  12833. props: {
  12834. numArgs: 0,
  12835. allowedInText: true
  12836. },
  12837. handler(context, args, optArgs) {
  12838. // \verb and \verb* are dealt with directly in Parser.js.
  12839. // If we end up here, it's because of a failure to match the two delimiters
  12840. // in the regex in Lexer.js. LaTeX raises the following error when \verb is
  12841. // terminated by end of line (or file).
  12842. throw new ParseError("\\verb ended by end of line instead of matching delimiter");
  12843. },
  12844. htmlBuilder(group, options) {
  12845. var text = makeVerb(group);
  12846. var body = []; // \verb enters text mode and therefore is sized like \textstyle
  12847. var newOptions = options.havingStyle(options.style.text());
  12848. for (var i = 0; i < text.length; i++) {
  12849. var c = text[i];
  12850. if (c === '~') {
  12851. c = '\\textasciitilde';
  12852. }
  12853. body.push(buildCommon.makeSymbol(c, "Typewriter-Regular", group.mode, newOptions, ["mord", "texttt"]));
  12854. }
  12855. return buildCommon.makeSpan(["mord", "text"].concat(newOptions.sizingClasses(options)), buildCommon.tryCombineChars(body), newOptions);
  12856. },
  12857. mathmlBuilder(group, options) {
  12858. var text = new mathMLTree.TextNode(makeVerb(group));
  12859. var node = new mathMLTree.MathNode("mtext", [text]);
  12860. node.setAttribute("mathvariant", "monospace");
  12861. return node;
  12862. }
  12863. });
  12864. /**
  12865. * Converts verb group into body string.
  12866. *
  12867. * \verb* replaces each space with an open box \u2423
  12868. * \verb replaces each space with a no-break space \xA0
  12869. */
  12870. var makeVerb = group => group.body.replace(/ /g, group.star ? '\u2423' : '\xA0');
  12871. /** Include this to ensure that all functions are defined. */
  12872. var functions = _functions;
  12873. /**
  12874. * The Lexer class handles tokenizing the input in various ways. Since our
  12875. * parser expects us to be able to backtrack, the lexer allows lexing from any
  12876. * given starting point.
  12877. *
  12878. * Its main exposed function is the `lex` function, which takes a position to
  12879. * lex from and a type of token to lex. It defers to the appropriate `_innerLex`
  12880. * function.
  12881. *
  12882. * The various `_innerLex` functions perform the actual lexing of different
  12883. * kinds.
  12884. */
  12885. /* The following tokenRegex
  12886. * - matches typical whitespace (but not NBSP etc.) using its first group
  12887. * - does not match any control character \x00-\x1f except whitespace
  12888. * - does not match a bare backslash
  12889. * - matches any ASCII character except those just mentioned
  12890. * - does not match the BMP private use area \uE000-\uF8FF
  12891. * - does not match bare surrogate code units
  12892. * - matches any BMP character except for those just described
  12893. * - matches any valid Unicode surrogate pair
  12894. * - matches a backslash followed by one or more whitespace characters
  12895. * - matches a backslash followed by one or more letters then whitespace
  12896. * - matches a backslash followed by any BMP character
  12897. * Capturing groups:
  12898. * [1] regular whitespace
  12899. * [2] backslash followed by whitespace
  12900. * [3] anything else, which may include:
  12901. * [4] left character of \verb*
  12902. * [5] left character of \verb
  12903. * [6] backslash followed by word, excluding any trailing whitespace
  12904. * Just because the Lexer matches something doesn't mean it's valid input:
  12905. * If there is no matching function or symbol definition, the Parser will
  12906. * still reject the input.
  12907. */
  12908. var spaceRegexString = "[ \r\n\t]";
  12909. var controlWordRegexString = "\\\\[a-zA-Z@]+";
  12910. var controlSymbolRegexString = "\\\\[^\uD800-\uDFFF]";
  12911. var controlWordWhitespaceRegexString = "(" + controlWordRegexString + ")" + spaceRegexString + "*";
  12912. var controlSpaceRegexString = "\\\\(\n|[ \r\t]+\n?)[ \r\t]*";
  12913. var combiningDiacriticalMarkString = "[\u0300-\u036f]";
  12914. var combiningDiacriticalMarksEndRegex = new RegExp(combiningDiacriticalMarkString + "+$");
  12915. var tokenRegexString = "(" + spaceRegexString + "+)|" + ( // whitespace
  12916. controlSpaceRegexString + "|") + // \whitespace
  12917. "([!-\\[\\]-\u2027\u202A-\uD7FF\uF900-\uFFFF]" + ( // single codepoint
  12918. combiningDiacriticalMarkString + "*") + // ...plus accents
  12919. "|[\uD800-\uDBFF][\uDC00-\uDFFF]" + ( // surrogate pair
  12920. combiningDiacriticalMarkString + "*") + // ...plus accents
  12921. "|\\\\verb\\*([^]).*?\\4" + // \verb*
  12922. "|\\\\verb([^*a-zA-Z]).*?\\5" + ( // \verb unstarred
  12923. "|" + controlWordWhitespaceRegexString) + ( // \macroName + spaces
  12924. "|" + controlSymbolRegexString + ")"); // \\, \', etc.
  12925. /** Main Lexer class */
  12926. class Lexer {
  12927. // Category codes. The lexer only supports comment characters (14) for now.
  12928. // MacroExpander additionally distinguishes active (13).
  12929. constructor(input, settings) {
  12930. this.input = void 0;
  12931. this.settings = void 0;
  12932. this.tokenRegex = void 0;
  12933. this.catcodes = void 0;
  12934. // Separate accents from characters
  12935. this.input = input;
  12936. this.settings = settings;
  12937. this.tokenRegex = new RegExp(tokenRegexString, 'g');
  12938. this.catcodes = {
  12939. "%": 14,
  12940. // comment character
  12941. "~": 13 // active character
  12942. };
  12943. }
  12944. setCatcode(char, code) {
  12945. this.catcodes[char] = code;
  12946. }
  12947. /**
  12948. * This function lexes a single token.
  12949. */
  12950. lex() {
  12951. var input = this.input;
  12952. var pos = this.tokenRegex.lastIndex;
  12953. if (pos === input.length) {
  12954. return new Token("EOF", new SourceLocation(this, pos, pos));
  12955. }
  12956. var match = this.tokenRegex.exec(input);
  12957. if (match === null || match.index !== pos) {
  12958. throw new ParseError("Unexpected character: '" + input[pos] + "'", new Token(input[pos], new SourceLocation(this, pos, pos + 1)));
  12959. }
  12960. var text = match[6] || match[3] || (match[2] ? "\\ " : " ");
  12961. if (this.catcodes[text] === 14) {
  12962. // comment character
  12963. var nlIndex = input.indexOf('\n', this.tokenRegex.lastIndex);
  12964. if (nlIndex === -1) {
  12965. this.tokenRegex.lastIndex = input.length; // EOF
  12966. this.settings.reportNonstrict("commentAtEnd", "% comment has no terminating newline; LaTeX would " + "fail because of commenting the end of math mode (e.g. $)");
  12967. } else {
  12968. this.tokenRegex.lastIndex = nlIndex + 1;
  12969. }
  12970. return this.lex();
  12971. }
  12972. return new Token(text, new SourceLocation(this, pos, this.tokenRegex.lastIndex));
  12973. }
  12974. }
  12975. /**
  12976. * A `Namespace` refers to a space of nameable things like macros or lengths,
  12977. * which can be `set` either globally or local to a nested group, using an
  12978. * undo stack similar to how TeX implements this functionality.
  12979. * Performance-wise, `get` and local `set` take constant time, while global
  12980. * `set` takes time proportional to the depth of group nesting.
  12981. */
  12982. class Namespace {
  12983. /**
  12984. * Both arguments are optional. The first argument is an object of
  12985. * built-in mappings which never change. The second argument is an object
  12986. * of initial (global-level) mappings, which will constantly change
  12987. * according to any global/top-level `set`s done.
  12988. */
  12989. constructor(builtins, globalMacros) {
  12990. if (builtins === void 0) {
  12991. builtins = {};
  12992. }
  12993. if (globalMacros === void 0) {
  12994. globalMacros = {};
  12995. }
  12996. this.current = void 0;
  12997. this.builtins = void 0;
  12998. this.undefStack = void 0;
  12999. this.current = globalMacros;
  13000. this.builtins = builtins;
  13001. this.undefStack = [];
  13002. }
  13003. /**
  13004. * Start a new nested group, affecting future local `set`s.
  13005. */
  13006. beginGroup() {
  13007. this.undefStack.push({});
  13008. }
  13009. /**
  13010. * End current nested group, restoring values before the group began.
  13011. */
  13012. endGroup() {
  13013. if (this.undefStack.length === 0) {
  13014. throw new ParseError("Unbalanced namespace destruction: attempt " + "to pop global namespace; please report this as a bug");
  13015. }
  13016. var undefs = this.undefStack.pop();
  13017. for (var undef in undefs) {
  13018. if (undefs.hasOwnProperty(undef)) {
  13019. if (undefs[undef] == null) {
  13020. delete this.current[undef];
  13021. } else {
  13022. this.current[undef] = undefs[undef];
  13023. }
  13024. }
  13025. }
  13026. }
  13027. /**
  13028. * Ends all currently nested groups (if any), restoring values before the
  13029. * groups began. Useful in case of an error in the middle of parsing.
  13030. */
  13031. endGroups() {
  13032. while (this.undefStack.length > 0) {
  13033. this.endGroup();
  13034. }
  13035. }
  13036. /**
  13037. * Detect whether `name` has a definition. Equivalent to
  13038. * `get(name) != null`.
  13039. */
  13040. has(name) {
  13041. return this.current.hasOwnProperty(name) || this.builtins.hasOwnProperty(name);
  13042. }
  13043. /**
  13044. * Get the current value of a name, or `undefined` if there is no value.
  13045. *
  13046. * Note: Do not use `if (namespace.get(...))` to detect whether a macro
  13047. * is defined, as the definition may be the empty string which evaluates
  13048. * to `false` in JavaScript. Use `if (namespace.get(...) != null)` or
  13049. * `if (namespace.has(...))`.
  13050. */
  13051. get(name) {
  13052. if (this.current.hasOwnProperty(name)) {
  13053. return this.current[name];
  13054. } else {
  13055. return this.builtins[name];
  13056. }
  13057. }
  13058. /**
  13059. * Set the current value of a name, and optionally set it globally too.
  13060. * Local set() sets the current value and (when appropriate) adds an undo
  13061. * operation to the undo stack. Global set() may change the undo
  13062. * operation at every level, so takes time linear in their number.
  13063. * A value of undefined means to delete existing definitions.
  13064. */
  13065. set(name, value, global) {
  13066. if (global === void 0) {
  13067. global = false;
  13068. }
  13069. if (global) {
  13070. // Global set is equivalent to setting in all groups. Simulate this
  13071. // by destroying any undos currently scheduled for this name,
  13072. // and adding an undo with the *new* value (in case it later gets
  13073. // locally reset within this environment).
  13074. for (var i = 0; i < this.undefStack.length; i++) {
  13075. delete this.undefStack[i][name];
  13076. }
  13077. if (this.undefStack.length > 0) {
  13078. this.undefStack[this.undefStack.length - 1][name] = value;
  13079. }
  13080. } else {
  13081. // Undo this set at end of this group (possibly to `undefined`),
  13082. // unless an undo is already in place, in which case that older
  13083. // value is the correct one.
  13084. var top = this.undefStack[this.undefStack.length - 1];
  13085. if (top && !top.hasOwnProperty(name)) {
  13086. top[name] = this.current[name];
  13087. }
  13088. }
  13089. if (value == null) {
  13090. delete this.current[name];
  13091. } else {
  13092. this.current[name] = value;
  13093. }
  13094. }
  13095. }
  13096. /**
  13097. * Predefined macros for KaTeX.
  13098. * This can be used to define some commands in terms of others.
  13099. */
  13100. var macros = _macros;
  13101. // macro tools
  13102. defineMacro("\\noexpand", function (context) {
  13103. // The expansion is the token itself; but that token is interpreted
  13104. // as if its meaning were ‘\relax’ if it is a control sequence that
  13105. // would ordinarily be expanded by TeX’s expansion rules.
  13106. var t = context.popToken();
  13107. if (context.isExpandable(t.text)) {
  13108. t.noexpand = true;
  13109. t.treatAsRelax = true;
  13110. }
  13111. return {
  13112. tokens: [t],
  13113. numArgs: 0
  13114. };
  13115. });
  13116. defineMacro("\\expandafter", function (context) {
  13117. // TeX first reads the token that comes immediately after \expandafter,
  13118. // without expanding it; let’s call this token t. Then TeX reads the
  13119. // token that comes after t (and possibly more tokens, if that token
  13120. // has an argument), replacing it by its expansion. Finally TeX puts
  13121. // t back in front of that expansion.
  13122. var t = context.popToken();
  13123. context.expandOnce(true); // expand only an expandable token
  13124. return {
  13125. tokens: [t],
  13126. numArgs: 0
  13127. };
  13128. }); // LaTeX's \@firstoftwo{#1}{#2} expands to #1, skipping #2
  13129. // TeX source: \long\def\@firstoftwo#1#2{#1}
  13130. defineMacro("\\@firstoftwo", function (context) {
  13131. var args = context.consumeArgs(2);
  13132. return {
  13133. tokens: args[0],
  13134. numArgs: 0
  13135. };
  13136. }); // LaTeX's \@secondoftwo{#1}{#2} expands to #2, skipping #1
  13137. // TeX source: \long\def\@secondoftwo#1#2{#2}
  13138. defineMacro("\\@secondoftwo", function (context) {
  13139. var args = context.consumeArgs(2);
  13140. return {
  13141. tokens: args[1],
  13142. numArgs: 0
  13143. };
  13144. }); // LaTeX's \@ifnextchar{#1}{#2}{#3} looks ahead to the next (unexpanded)
  13145. // symbol that isn't a space, consuming any spaces but not consuming the
  13146. // first nonspace character. If that nonspace character matches #1, then
  13147. // the macro expands to #2; otherwise, it expands to #3.
  13148. defineMacro("\\@ifnextchar", function (context) {
  13149. var args = context.consumeArgs(3); // symbol, if, else
  13150. context.consumeSpaces();
  13151. var nextToken = context.future();
  13152. if (args[0].length === 1 && args[0][0].text === nextToken.text) {
  13153. return {
  13154. tokens: args[1],
  13155. numArgs: 0
  13156. };
  13157. } else {
  13158. return {
  13159. tokens: args[2],
  13160. numArgs: 0
  13161. };
  13162. }
  13163. }); // LaTeX's \@ifstar{#1}{#2} looks ahead to the next (unexpanded) symbol.
  13164. // If it is `*`, then it consumes the symbol, and the macro expands to #1;
  13165. // otherwise, the macro expands to #2 (without consuming the symbol).
  13166. // TeX source: \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
  13167. defineMacro("\\@ifstar", "\\@ifnextchar *{\\@firstoftwo{#1}}"); // LaTeX's \TextOrMath{#1}{#2} expands to #1 in text mode, #2 in math mode
  13168. defineMacro("\\TextOrMath", function (context) {
  13169. var args = context.consumeArgs(2);
  13170. if (context.mode === 'text') {
  13171. return {
  13172. tokens: args[0],
  13173. numArgs: 0
  13174. };
  13175. } else {
  13176. return {
  13177. tokens: args[1],
  13178. numArgs: 0
  13179. };
  13180. }
  13181. }); // Lookup table for parsing numbers in base 8 through 16
  13182. var digitToNumber = {
  13183. "0": 0,
  13184. "1": 1,
  13185. "2": 2,
  13186. "3": 3,
  13187. "4": 4,
  13188. "5": 5,
  13189. "6": 6,
  13190. "7": 7,
  13191. "8": 8,
  13192. "9": 9,
  13193. "a": 10,
  13194. "A": 10,
  13195. "b": 11,
  13196. "B": 11,
  13197. "c": 12,
  13198. "C": 12,
  13199. "d": 13,
  13200. "D": 13,
  13201. "e": 14,
  13202. "E": 14,
  13203. "f": 15,
  13204. "F": 15
  13205. }; // TeX \char makes a literal character (catcode 12) using the following forms:
  13206. // (see The TeXBook, p. 43)
  13207. // \char123 -- decimal
  13208. // \char'123 -- octal
  13209. // \char"123 -- hex
  13210. // \char`x -- character that can be written (i.e. isn't active)
  13211. // \char`\x -- character that cannot be written (e.g. %)
  13212. // These all refer to characters from the font, so we turn them into special
  13213. // calls to a function \@char dealt with in the Parser.
  13214. defineMacro("\\char", function (context) {
  13215. var token = context.popToken();
  13216. var base;
  13217. var number = '';
  13218. if (token.text === "'") {
  13219. base = 8;
  13220. token = context.popToken();
  13221. } else if (token.text === '"') {
  13222. base = 16;
  13223. token = context.popToken();
  13224. } else if (token.text === "`") {
  13225. token = context.popToken();
  13226. if (token.text[0] === "\\") {
  13227. number = token.text.charCodeAt(1);
  13228. } else if (token.text === "EOF") {
  13229. throw new ParseError("\\char` missing argument");
  13230. } else {
  13231. number = token.text.charCodeAt(0);
  13232. }
  13233. } else {
  13234. base = 10;
  13235. }
  13236. if (base) {
  13237. // Parse a number in the given base, starting with first `token`.
  13238. number = digitToNumber[token.text];
  13239. if (number == null || number >= base) {
  13240. throw new ParseError("Invalid base-" + base + " digit " + token.text);
  13241. }
  13242. var digit;
  13243. while ((digit = digitToNumber[context.future().text]) != null && digit < base) {
  13244. number *= base;
  13245. number += digit;
  13246. context.popToken();
  13247. }
  13248. }
  13249. return "\\@char{" + number + "}";
  13250. }); // \newcommand{\macro}[args]{definition}
  13251. // \renewcommand{\macro}[args]{definition}
  13252. // TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
  13253. var newcommand = (context, existsOK, nonexistsOK) => {
  13254. var arg = context.consumeArg().tokens;
  13255. if (arg.length !== 1) {
  13256. throw new ParseError("\\newcommand's first argument must be a macro name");
  13257. }
  13258. var name = arg[0].text;
  13259. var exists = context.isDefined(name);
  13260. if (exists && !existsOK) {
  13261. throw new ParseError("\\newcommand{" + name + "} attempting to redefine " + (name + "; use \\renewcommand"));
  13262. }
  13263. if (!exists && !nonexistsOK) {
  13264. throw new ParseError("\\renewcommand{" + name + "} when command " + name + " " + "does not yet exist; use \\newcommand");
  13265. }
  13266. var numArgs = 0;
  13267. arg = context.consumeArg().tokens;
  13268. if (arg.length === 1 && arg[0].text === "[") {
  13269. var argText = '';
  13270. var token = context.expandNextToken();
  13271. while (token.text !== "]" && token.text !== "EOF") {
  13272. // TODO: Should properly expand arg, e.g., ignore {}s
  13273. argText += token.text;
  13274. token = context.expandNextToken();
  13275. }
  13276. if (!argText.match(/^\s*[0-9]+\s*$/)) {
  13277. throw new ParseError("Invalid number of arguments: " + argText);
  13278. }
  13279. numArgs = parseInt(argText);
  13280. arg = context.consumeArg().tokens;
  13281. } // Final arg is the expansion of the macro
  13282. context.macros.set(name, {
  13283. tokens: arg,
  13284. numArgs
  13285. });
  13286. return '';
  13287. };
  13288. defineMacro("\\newcommand", context => newcommand(context, false, true));
  13289. defineMacro("\\renewcommand", context => newcommand(context, true, false));
  13290. defineMacro("\\providecommand", context => newcommand(context, true, true)); // terminal (console) tools
  13291. defineMacro("\\message", context => {
  13292. var arg = context.consumeArgs(1)[0]; // eslint-disable-next-line no-console
  13293. console.log(arg.reverse().map(token => token.text).join(""));
  13294. return '';
  13295. });
  13296. defineMacro("\\errmessage", context => {
  13297. var arg = context.consumeArgs(1)[0]; // eslint-disable-next-line no-console
  13298. console.error(arg.reverse().map(token => token.text).join(""));
  13299. return '';
  13300. });
  13301. defineMacro("\\show", context => {
  13302. var tok = context.popToken();
  13303. var name = tok.text; // eslint-disable-next-line no-console
  13304. console.log(tok, context.macros.get(name), functions[name], symbols.math[name], symbols.text[name]);
  13305. return '';
  13306. }); //////////////////////////////////////////////////////////////////////
  13307. // Grouping
  13308. // \let\bgroup={ \let\egroup=}
  13309. defineMacro("\\bgroup", "{");
  13310. defineMacro("\\egroup", "}"); // Symbols from latex.ltx:
  13311. // \def~{\nobreakspace{}}
  13312. // \def\lq{`}
  13313. // \def\rq{'}
  13314. // \def \aa {\r a}
  13315. // \def \AA {\r A}
  13316. defineMacro("~", "\\nobreakspace");
  13317. defineMacro("\\lq", "`");
  13318. defineMacro("\\rq", "'");
  13319. defineMacro("\\aa", "\\r a");
  13320. defineMacro("\\AA", "\\r A"); // Copyright (C) and registered (R) symbols. Use raw symbol in MathML.
  13321. // \DeclareTextCommandDefault{\textcopyright}{\textcircled{c}}
  13322. // \DeclareTextCommandDefault{\textregistered}{\textcircled{%
  13323. // \check@mathfonts\fontsize\sf@size\z@\math@fontsfalse\selectfont R}}
  13324. // \DeclareRobustCommand{\copyright}{%
  13325. // \ifmmode{\nfss@text{\textcopyright}}\else\textcopyright\fi}
  13326. defineMacro("\\textcopyright", "\\html@mathml{\\textcircled{c}}{\\char`©}");
  13327. defineMacro("\\copyright", "\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}");
  13328. defineMacro("\\textregistered", "\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}"); // Characters omitted from Unicode range 1D400–1D7FF
  13329. defineMacro("\u212C", "\\mathscr{B}"); // script
  13330. defineMacro("\u2130", "\\mathscr{E}");
  13331. defineMacro("\u2131", "\\mathscr{F}");
  13332. defineMacro("\u210B", "\\mathscr{H}");
  13333. defineMacro("\u2110", "\\mathscr{I}");
  13334. defineMacro("\u2112", "\\mathscr{L}");
  13335. defineMacro("\u2133", "\\mathscr{M}");
  13336. defineMacro("\u211B", "\\mathscr{R}");
  13337. defineMacro("\u212D", "\\mathfrak{C}"); // Fraktur
  13338. defineMacro("\u210C", "\\mathfrak{H}");
  13339. defineMacro("\u2128", "\\mathfrak{Z}"); // Define \Bbbk with a macro that works in both HTML and MathML.
  13340. defineMacro("\\Bbbk", "\\Bbb{k}"); // Unicode middle dot
  13341. // The KaTeX fonts do not contain U+00B7. Instead, \cdotp displays
  13342. // the dot at U+22C5 and gives it punct spacing.
  13343. defineMacro("\u00b7", "\\cdotp"); // \llap and \rlap render their contents in text mode
  13344. defineMacro("\\llap", "\\mathllap{\\textrm{#1}}");
  13345. defineMacro("\\rlap", "\\mathrlap{\\textrm{#1}}");
  13346. defineMacro("\\clap", "\\mathclap{\\textrm{#1}}"); // \mathstrut from the TeXbook, p 360
  13347. defineMacro("\\mathstrut", "\\vphantom{(}"); // \underbar from TeXbook p 353
  13348. defineMacro("\\underbar", "\\underline{\\text{#1}}"); // \not is defined by base/fontmath.ltx via
  13349. // \DeclareMathSymbol{\not}{\mathrel}{symbols}{"36}
  13350. // It's thus treated like a \mathrel, but defined by a symbol that has zero
  13351. // width but extends to the right. We use \rlap to get that spacing.
  13352. // For MathML we write U+0338 here. buildMathML.js will then do the overlay.
  13353. defineMacro("\\not", '\\html@mathml{\\mathrel{\\mathrlap\\@not}}{\\char"338}'); // Negated symbols from base/fontmath.ltx:
  13354. // \def\neq{\not=} \let\ne=\neq
  13355. // \DeclareRobustCommand
  13356. // \notin{\mathrel{\m@th\mathpalette\c@ncel\in}}
  13357. // \def\c@ncel#1#2{\m@th\ooalign{$\hfil#1\mkern1mu/\hfil$\crcr$#1#2$}}
  13358. defineMacro("\\neq", "\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}");
  13359. defineMacro("\\ne", "\\neq");
  13360. defineMacro("\u2260", "\\neq");
  13361. defineMacro("\\notin", "\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}" + "{\\mathrel{\\char`∉}}");
  13362. defineMacro("\u2209", "\\notin"); // Unicode stacked relations
  13363. defineMacro("\u2258", "\\html@mathml{" + "\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}" + "}{\\mathrel{\\char`\u2258}}");
  13364. defineMacro("\u2259", "\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`\u2258}}");
  13365. defineMacro("\u225A", "\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`\u225A}}");
  13366. defineMacro("\u225B", "\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}" + "{\\mathrel{\\char`\u225B}}");
  13367. defineMacro("\u225D", "\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}" + "{\\mathrel{\\char`\u225D}}");
  13368. defineMacro("\u225E", "\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}" + "{\\mathrel{\\char`\u225E}}");
  13369. defineMacro("\u225F", "\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`\u225F}}"); // Misc Unicode
  13370. defineMacro("\u27C2", "\\perp");
  13371. defineMacro("\u203C", "\\mathclose{!\\mkern-0.8mu!}");
  13372. defineMacro("\u220C", "\\notni");
  13373. defineMacro("\u231C", "\\ulcorner");
  13374. defineMacro("\u231D", "\\urcorner");
  13375. defineMacro("\u231E", "\\llcorner");
  13376. defineMacro("\u231F", "\\lrcorner");
  13377. defineMacro("\u00A9", "\\copyright");
  13378. defineMacro("\u00AE", "\\textregistered");
  13379. defineMacro("\uFE0F", "\\textregistered"); // The KaTeX fonts have corners at codepoints that don't match Unicode.
  13380. // For MathML purposes, use the Unicode code point.
  13381. defineMacro("\\ulcorner", "\\html@mathml{\\@ulcorner}{\\mathop{\\char\"231c}}");
  13382. defineMacro("\\urcorner", "\\html@mathml{\\@urcorner}{\\mathop{\\char\"231d}}");
  13383. defineMacro("\\llcorner", "\\html@mathml{\\@llcorner}{\\mathop{\\char\"231e}}");
  13384. defineMacro("\\lrcorner", "\\html@mathml{\\@lrcorner}{\\mathop{\\char\"231f}}"); //////////////////////////////////////////////////////////////////////
  13385. // LaTeX_2ε
  13386. // \vdots{\vbox{\baselineskip4\p@ \lineskiplimit\z@
  13387. // \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
  13388. // We'll call \varvdots, which gets a glyph from symbols.js.
  13389. // The zero-width rule gets us an equivalent to the vertical 6pt kern.
  13390. defineMacro("\\vdots", "\\mathord{\\varvdots\\rule{0pt}{15pt}}");
  13391. defineMacro("\u22ee", "\\vdots"); //////////////////////////////////////////////////////////////////////
  13392. // amsmath.sty
  13393. // http://mirrors.concertpass.com/tex-archive/macros/latex/required/amsmath/amsmath.pdf
  13394. // Italic Greek capital letters. AMS defines these with \DeclareMathSymbol,
  13395. // but they are equivalent to \mathit{\Letter}.
  13396. defineMacro("\\varGamma", "\\mathit{\\Gamma}");
  13397. defineMacro("\\varDelta", "\\mathit{\\Delta}");
  13398. defineMacro("\\varTheta", "\\mathit{\\Theta}");
  13399. defineMacro("\\varLambda", "\\mathit{\\Lambda}");
  13400. defineMacro("\\varXi", "\\mathit{\\Xi}");
  13401. defineMacro("\\varPi", "\\mathit{\\Pi}");
  13402. defineMacro("\\varSigma", "\\mathit{\\Sigma}");
  13403. defineMacro("\\varUpsilon", "\\mathit{\\Upsilon}");
  13404. defineMacro("\\varPhi", "\\mathit{\\Phi}");
  13405. defineMacro("\\varPsi", "\\mathit{\\Psi}");
  13406. defineMacro("\\varOmega", "\\mathit{\\Omega}"); //\newcommand{\substack}[1]{\subarray{c}#1\endsubarray}
  13407. defineMacro("\\substack", "\\begin{subarray}{c}#1\\end{subarray}"); // \renewcommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
  13408. // \mkern-\thinmuskip{:}\mskip6muplus1mu\relax}
  13409. defineMacro("\\colon", "\\nobreak\\mskip2mu\\mathpunct{}" + "\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax"); // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
  13410. defineMacro("\\boxed", "\\fbox{$\\displaystyle{#1}$}"); // \def\iff{\DOTSB\;\Longleftrightarrow\;}
  13411. // \def\implies{\DOTSB\;\Longrightarrow\;}
  13412. // \def\impliedby{\DOTSB\;\Longleftarrow\;}
  13413. defineMacro("\\iff", "\\DOTSB\\;\\Longleftrightarrow\\;");
  13414. defineMacro("\\implies", "\\DOTSB\\;\\Longrightarrow\\;");
  13415. defineMacro("\\impliedby", "\\DOTSB\\;\\Longleftarrow\\;"); // AMSMath's automatic \dots, based on \mdots@@ macro.
  13416. var dotsByToken = {
  13417. ',': '\\dotsc',
  13418. '\\not': '\\dotsb',
  13419. // \keybin@ checks for the following:
  13420. '+': '\\dotsb',
  13421. '=': '\\dotsb',
  13422. '<': '\\dotsb',
  13423. '>': '\\dotsb',
  13424. '-': '\\dotsb',
  13425. '*': '\\dotsb',
  13426. ':': '\\dotsb',
  13427. // Symbols whose definition starts with \DOTSB:
  13428. '\\DOTSB': '\\dotsb',
  13429. '\\coprod': '\\dotsb',
  13430. '\\bigvee': '\\dotsb',
  13431. '\\bigwedge': '\\dotsb',
  13432. '\\biguplus': '\\dotsb',
  13433. '\\bigcap': '\\dotsb',
  13434. '\\bigcup': '\\dotsb',
  13435. '\\prod': '\\dotsb',
  13436. '\\sum': '\\dotsb',
  13437. '\\bigotimes': '\\dotsb',
  13438. '\\bigoplus': '\\dotsb',
  13439. '\\bigodot': '\\dotsb',
  13440. '\\bigsqcup': '\\dotsb',
  13441. '\\And': '\\dotsb',
  13442. '\\longrightarrow': '\\dotsb',
  13443. '\\Longrightarrow': '\\dotsb',
  13444. '\\longleftarrow': '\\dotsb',
  13445. '\\Longleftarrow': '\\dotsb',
  13446. '\\longleftrightarrow': '\\dotsb',
  13447. '\\Longleftrightarrow': '\\dotsb',
  13448. '\\mapsto': '\\dotsb',
  13449. '\\longmapsto': '\\dotsb',
  13450. '\\hookrightarrow': '\\dotsb',
  13451. '\\doteq': '\\dotsb',
  13452. // Symbols whose definition starts with \mathbin:
  13453. '\\mathbin': '\\dotsb',
  13454. // Symbols whose definition starts with \mathrel:
  13455. '\\mathrel': '\\dotsb',
  13456. '\\relbar': '\\dotsb',
  13457. '\\Relbar': '\\dotsb',
  13458. '\\xrightarrow': '\\dotsb',
  13459. '\\xleftarrow': '\\dotsb',
  13460. // Symbols whose definition starts with \DOTSI:
  13461. '\\DOTSI': '\\dotsi',
  13462. '\\int': '\\dotsi',
  13463. '\\oint': '\\dotsi',
  13464. '\\iint': '\\dotsi',
  13465. '\\iiint': '\\dotsi',
  13466. '\\iiiint': '\\dotsi',
  13467. '\\idotsint': '\\dotsi',
  13468. // Symbols whose definition starts with \DOTSX:
  13469. '\\DOTSX': '\\dotsx'
  13470. };
  13471. defineMacro("\\dots", function (context) {
  13472. // TODO: If used in text mode, should expand to \textellipsis.
  13473. // However, in KaTeX, \textellipsis and \ldots behave the same
  13474. // (in text mode), and it's unlikely we'd see any of the math commands
  13475. // that affect the behavior of \dots when in text mode. So fine for now
  13476. // (until we support \ifmmode ... \else ... \fi).
  13477. var thedots = '\\dotso';
  13478. var next = context.expandAfterFuture().text;
  13479. if (next in dotsByToken) {
  13480. thedots = dotsByToken[next];
  13481. } else if (next.substr(0, 4) === '\\not') {
  13482. thedots = '\\dotsb';
  13483. } else if (next in symbols.math) {
  13484. if (utils.contains(['bin', 'rel'], symbols.math[next].group)) {
  13485. thedots = '\\dotsb';
  13486. }
  13487. }
  13488. return thedots;
  13489. });
  13490. var spaceAfterDots = {
  13491. // \rightdelim@ checks for the following:
  13492. ')': true,
  13493. ']': true,
  13494. '\\rbrack': true,
  13495. '\\}': true,
  13496. '\\rbrace': true,
  13497. '\\rangle': true,
  13498. '\\rceil': true,
  13499. '\\rfloor': true,
  13500. '\\rgroup': true,
  13501. '\\rmoustache': true,
  13502. '\\right': true,
  13503. '\\bigr': true,
  13504. '\\biggr': true,
  13505. '\\Bigr': true,
  13506. '\\Biggr': true,
  13507. // \extra@ also tests for the following:
  13508. '$': true,
  13509. // \extrap@ checks for the following:
  13510. ';': true,
  13511. '.': true,
  13512. ',': true
  13513. };
  13514. defineMacro("\\dotso", function (context) {
  13515. var next = context.future().text;
  13516. if (next in spaceAfterDots) {
  13517. return "\\ldots\\,";
  13518. } else {
  13519. return "\\ldots";
  13520. }
  13521. });
  13522. defineMacro("\\dotsc", function (context) {
  13523. var next = context.future().text; // \dotsc uses \extra@ but not \extrap@, instead specially checking for
  13524. // ';' and '.', but doesn't check for ','.
  13525. if (next in spaceAfterDots && next !== ',') {
  13526. return "\\ldots\\,";
  13527. } else {
  13528. return "\\ldots";
  13529. }
  13530. });
  13531. defineMacro("\\cdots", function (context) {
  13532. var next = context.future().text;
  13533. if (next in spaceAfterDots) {
  13534. return "\\@cdots\\,";
  13535. } else {
  13536. return "\\@cdots";
  13537. }
  13538. });
  13539. defineMacro("\\dotsb", "\\cdots");
  13540. defineMacro("\\dotsm", "\\cdots");
  13541. defineMacro("\\dotsi", "\\!\\cdots"); // amsmath doesn't actually define \dotsx, but \dots followed by a macro
  13542. // starting with \DOTSX implies \dotso, and then \extra@ detects this case
  13543. // and forces the added `\,`.
  13544. defineMacro("\\dotsx", "\\ldots\\,"); // \let\DOTSI\relax
  13545. // \let\DOTSB\relax
  13546. // \let\DOTSX\relax
  13547. defineMacro("\\DOTSI", "\\relax");
  13548. defineMacro("\\DOTSB", "\\relax");
  13549. defineMacro("\\DOTSX", "\\relax"); // Spacing, based on amsmath.sty's override of LaTeX defaults
  13550. // \DeclareRobustCommand{\tmspace}[3]{%
  13551. // \ifmmode\mskip#1#2\else\kern#1#3\fi\relax}
  13552. defineMacro("\\tmspace", "\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax"); // \renewcommand{\,}{\tmspace+\thinmuskip{.1667em}}
  13553. // TODO: math mode should use \thinmuskip
  13554. defineMacro("\\,", "\\tmspace+{3mu}{.1667em}"); // \let\thinspace\,
  13555. defineMacro("\\thinspace", "\\,"); // \def\>{\mskip\medmuskip}
  13556. // \renewcommand{\:}{\tmspace+\medmuskip{.2222em}}
  13557. // TODO: \> and math mode of \: should use \medmuskip = 4mu plus 2mu minus 4mu
  13558. defineMacro("\\>", "\\mskip{4mu}");
  13559. defineMacro("\\:", "\\tmspace+{4mu}{.2222em}"); // \let\medspace\:
  13560. defineMacro("\\medspace", "\\:"); // \renewcommand{\;}{\tmspace+\thickmuskip{.2777em}}
  13561. // TODO: math mode should use \thickmuskip = 5mu plus 5mu
  13562. defineMacro("\\;", "\\tmspace+{5mu}{.2777em}"); // \let\thickspace\;
  13563. defineMacro("\\thickspace", "\\;"); // \renewcommand{\!}{\tmspace-\thinmuskip{.1667em}}
  13564. // TODO: math mode should use \thinmuskip
  13565. defineMacro("\\!", "\\tmspace-{3mu}{.1667em}"); // \let\negthinspace\!
  13566. defineMacro("\\negthinspace", "\\!"); // \newcommand{\negmedspace}{\tmspace-\medmuskip{.2222em}}
  13567. // TODO: math mode should use \medmuskip
  13568. defineMacro("\\negmedspace", "\\tmspace-{4mu}{.2222em}"); // \newcommand{\negthickspace}{\tmspace-\thickmuskip{.2777em}}
  13569. // TODO: math mode should use \thickmuskip
  13570. defineMacro("\\negthickspace", "\\tmspace-{5mu}{.277em}"); // \def\enspace{\kern.5em }
  13571. defineMacro("\\enspace", "\\kern.5em "); // \def\enskip{\hskip.5em\relax}
  13572. defineMacro("\\enskip", "\\hskip.5em\\relax"); // \def\quad{\hskip1em\relax}
  13573. defineMacro("\\quad", "\\hskip1em\\relax"); // \def\qquad{\hskip2em\relax}
  13574. defineMacro("\\qquad", "\\hskip2em\\relax"); // \tag@in@display form of \tag
  13575. defineMacro("\\tag", "\\@ifstar\\tag@literal\\tag@paren");
  13576. defineMacro("\\tag@paren", "\\tag@literal{({#1})}");
  13577. defineMacro("\\tag@literal", context => {
  13578. if (context.macros.get("\\df@tag")) {
  13579. throw new ParseError("Multiple \\tag");
  13580. }
  13581. return "\\gdef\\df@tag{\\text{#1}}";
  13582. }); // \renewcommand{\bmod}{\nonscript\mskip-\medmuskip\mkern5mu\mathbin
  13583. // {\operator@font mod}\penalty900
  13584. // \mkern5mu\nonscript\mskip-\medmuskip}
  13585. // \newcommand{\pod}[1]{\allowbreak
  13586. // \if@display\mkern18mu\else\mkern8mu\fi(#1)}
  13587. // \renewcommand{\pmod}[1]{\pod{{\operator@font mod}\mkern6mu#1}}
  13588. // \newcommand{\mod}[1]{\allowbreak\if@display\mkern18mu
  13589. // \else\mkern12mu\fi{\operator@font mod}\,\,#1}
  13590. // TODO: math mode should use \medmuskip = 4mu plus 2mu minus 4mu
  13591. defineMacro("\\bmod", "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}" + "\\mathbin{\\rm mod}" + "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}");
  13592. defineMacro("\\pod", "\\allowbreak" + "\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)");
  13593. defineMacro("\\pmod", "\\pod{{\\rm mod}\\mkern6mu#1}");
  13594. defineMacro("\\mod", "\\allowbreak" + "\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}" + "{\\rm mod}\\,\\,#1"); // \pmb -- A simulation of bold.
  13595. // The version in ambsy.sty works by typesetting three copies of the argument
  13596. // with small offsets. We use two copies. We omit the vertical offset because
  13597. // of rendering problems that makeVList encounters in Safari.
  13598. defineMacro("\\pmb", "\\html@mathml{" + "\\@binrel{#1}{\\mathrlap{#1}\\kern0.5px#1}}" + "{\\mathbf{#1}}"); //////////////////////////////////////////////////////////////////////
  13599. // LaTeX source2e
  13600. // \expandafter\let\expandafter\@normalcr
  13601. // \csname\expandafter\@gobble\string\\ \endcsname
  13602. // \DeclareRobustCommand\newline{\@normalcr\relax}
  13603. defineMacro("\\newline", "\\\\\\relax"); // \def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}
  13604. // TODO: Doesn't normally work in math mode because \@ fails. KaTeX doesn't
  13605. // support \@ yet, so that's omitted, and we add \text so that the result
  13606. // doesn't look funny in math mode.
  13607. defineMacro("\\TeX", "\\textrm{\\html@mathml{" + "T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX" + "}{TeX}}"); // \DeclareRobustCommand{\LaTeX}{L\kern-.36em%
  13608. // {\sbox\z@ T%
  13609. // \vbox to\ht\z@{\hbox{\check@mathfonts
  13610. // \fontsize\sf@size\z@
  13611. // \math@fontsfalse\selectfont
  13612. // A}%
  13613. // \vss}%
  13614. // }%
  13615. // \kern-.15em%
  13616. // \TeX}
  13617. // This code aligns the top of the A with the T (from the perspective of TeX's
  13618. // boxes, though visually the A appears to extend above slightly).
  13619. // We compute the corresponding \raisebox when A is rendered in \normalsize
  13620. // \scriptstyle, which has a scale factor of 0.7 (see Options.js).
  13621. var latexRaiseA = makeEm(fontMetricsData['Main-Regular']["T".charCodeAt(0)][1] - 0.7 * fontMetricsData['Main-Regular']["A".charCodeAt(0)][1]);
  13622. defineMacro("\\LaTeX", "\\textrm{\\html@mathml{" + ("L\\kern-.36em\\raisebox{" + latexRaiseA + "}{\\scriptstyle A}") + "\\kern-.15em\\TeX}{LaTeX}}"); // New KaTeX logo based on tweaking LaTeX logo
  13623. defineMacro("\\KaTeX", "\\textrm{\\html@mathml{" + ("K\\kern-.17em\\raisebox{" + latexRaiseA + "}{\\scriptstyle A}") + "\\kern-.15em\\TeX}{KaTeX}}"); // \DeclareRobustCommand\hspace{\@ifstar\@hspacer\@hspace}
  13624. // \def\@hspace#1{\hskip #1\relax}
  13625. // \def\@hspacer#1{\vrule \@width\z@\nobreak
  13626. // \hskip #1\hskip \z@skip}
  13627. defineMacro("\\hspace", "\\@ifstar\\@hspacer\\@hspace");
  13628. defineMacro("\\@hspace", "\\hskip #1\\relax");
  13629. defineMacro("\\@hspacer", "\\rule{0pt}{0pt}\\hskip #1\\relax"); //////////////////////////////////////////////////////////////////////
  13630. // mathtools.sty
  13631. //\providecommand\ordinarycolon{:}
  13632. defineMacro("\\ordinarycolon", ":"); //\def\vcentcolon{\mathrel{\mathop\ordinarycolon}}
  13633. //TODO(edemaine): Not yet centered. Fix via \raisebox or #726
  13634. defineMacro("\\vcentcolon", "\\mathrel{\\mathop\\ordinarycolon}"); // \providecommand*\dblcolon{\vcentcolon\mathrel{\mkern-.9mu}\vcentcolon}
  13635. defineMacro("\\dblcolon", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}" + "{\\mathop{\\char\"2237}}"); // \providecommand*\coloneqq{\vcentcolon\mathrel{\mkern-1.2mu}=}
  13636. defineMacro("\\coloneqq", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}" + "{\\mathop{\\char\"2254}}"); // ≔
  13637. // \providecommand*\Coloneqq{\dblcolon\mathrel{\mkern-1.2mu}=}
  13638. defineMacro("\\Coloneqq", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}" + "{\\mathop{\\char\"2237\\char\"3d}}"); // \providecommand*\coloneq{\vcentcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
  13639. defineMacro("\\coloneq", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" + "{\\mathop{\\char\"3a\\char\"2212}}"); // \providecommand*\Coloneq{\dblcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
  13640. defineMacro("\\Coloneq", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" + "{\\mathop{\\char\"2237\\char\"2212}}"); // \providecommand*\eqqcolon{=\mathrel{\mkern-1.2mu}\vcentcolon}
  13641. defineMacro("\\eqqcolon", "\\html@mathml{" + "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" + "{\\mathop{\\char\"2255}}"); // ≕
  13642. // \providecommand*\Eqqcolon{=\mathrel{\mkern-1.2mu}\dblcolon}
  13643. defineMacro("\\Eqqcolon", "\\html@mathml{" + "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}" + "{\\mathop{\\char\"3d\\char\"2237}}"); // \providecommand*\eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\vcentcolon}
  13644. defineMacro("\\eqcolon", "\\html@mathml{" + "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" + "{\\mathop{\\char\"2239}}"); // \providecommand*\Eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\dblcolon}
  13645. defineMacro("\\Eqcolon", "\\html@mathml{" + "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}" + "{\\mathop{\\char\"2212\\char\"2237}}"); // \providecommand*\colonapprox{\vcentcolon\mathrel{\mkern-1.2mu}\approx}
  13646. defineMacro("\\colonapprox", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}" + "{\\mathop{\\char\"3a\\char\"2248}}"); // \providecommand*\Colonapprox{\dblcolon\mathrel{\mkern-1.2mu}\approx}
  13647. defineMacro("\\Colonapprox", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}" + "{\\mathop{\\char\"2237\\char\"2248}}"); // \providecommand*\colonsim{\vcentcolon\mathrel{\mkern-1.2mu}\sim}
  13648. defineMacro("\\colonsim", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}" + "{\\mathop{\\char\"3a\\char\"223c}}"); // \providecommand*\Colonsim{\dblcolon\mathrel{\mkern-1.2mu}\sim}
  13649. defineMacro("\\Colonsim", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}" + "{\\mathop{\\char\"2237\\char\"223c}}"); // Some Unicode characters are implemented with macros to mathtools functions.
  13650. defineMacro("\u2237", "\\dblcolon"); // ::
  13651. defineMacro("\u2239", "\\eqcolon"); // -:
  13652. defineMacro("\u2254", "\\coloneqq"); // :=
  13653. defineMacro("\u2255", "\\eqqcolon"); // =:
  13654. defineMacro("\u2A74", "\\Coloneqq"); // ::=
  13655. //////////////////////////////////////////////////////////////////////
  13656. // colonequals.sty
  13657. // Alternate names for mathtools's macros:
  13658. defineMacro("\\ratio", "\\vcentcolon");
  13659. defineMacro("\\coloncolon", "\\dblcolon");
  13660. defineMacro("\\colonequals", "\\coloneqq");
  13661. defineMacro("\\coloncolonequals", "\\Coloneqq");
  13662. defineMacro("\\equalscolon", "\\eqqcolon");
  13663. defineMacro("\\equalscoloncolon", "\\Eqqcolon");
  13664. defineMacro("\\colonminus", "\\coloneq");
  13665. defineMacro("\\coloncolonminus", "\\Coloneq");
  13666. defineMacro("\\minuscolon", "\\eqcolon");
  13667. defineMacro("\\minuscoloncolon", "\\Eqcolon"); // \colonapprox name is same in mathtools and colonequals.
  13668. defineMacro("\\coloncolonapprox", "\\Colonapprox"); // \colonsim name is same in mathtools and colonequals.
  13669. defineMacro("\\coloncolonsim", "\\Colonsim"); // Additional macros, implemented by analogy with mathtools definitions:
  13670. defineMacro("\\simcolon", "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
  13671. defineMacro("\\simcoloncolon", "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}");
  13672. defineMacro("\\approxcolon", "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
  13673. defineMacro("\\approxcoloncolon", "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}"); // Present in newtxmath, pxfonts and txfonts
  13674. defineMacro("\\notni", "\\html@mathml{\\not\\ni}{\\mathrel{\\char`\u220C}}");
  13675. defineMacro("\\limsup", "\\DOTSB\\operatorname*{lim\\,sup}");
  13676. defineMacro("\\liminf", "\\DOTSB\\operatorname*{lim\\,inf}"); //////////////////////////////////////////////////////////////////////
  13677. // From amsopn.sty
  13678. defineMacro("\\injlim", "\\DOTSB\\operatorname*{inj\\,lim}");
  13679. defineMacro("\\projlim", "\\DOTSB\\operatorname*{proj\\,lim}");
  13680. defineMacro("\\varlimsup", "\\DOTSB\\operatorname*{\\overline{lim}}");
  13681. defineMacro("\\varliminf", "\\DOTSB\\operatorname*{\\underline{lim}}");
  13682. defineMacro("\\varinjlim", "\\DOTSB\\operatorname*{\\underrightarrow{lim}}");
  13683. defineMacro("\\varprojlim", "\\DOTSB\\operatorname*{\\underleftarrow{lim}}"); //////////////////////////////////////////////////////////////////////
  13684. // MathML alternates for KaTeX glyphs in the Unicode private area
  13685. defineMacro("\\gvertneqq", "\\html@mathml{\\@gvertneqq}{\u2269}");
  13686. defineMacro("\\lvertneqq", "\\html@mathml{\\@lvertneqq}{\u2268}");
  13687. defineMacro("\\ngeqq", "\\html@mathml{\\@ngeqq}{\u2271}");
  13688. defineMacro("\\ngeqslant", "\\html@mathml{\\@ngeqslant}{\u2271}");
  13689. defineMacro("\\nleqq", "\\html@mathml{\\@nleqq}{\u2270}");
  13690. defineMacro("\\nleqslant", "\\html@mathml{\\@nleqslant}{\u2270}");
  13691. defineMacro("\\nshortmid", "\\html@mathml{\\@nshortmid}{∤}");
  13692. defineMacro("\\nshortparallel", "\\html@mathml{\\@nshortparallel}{∦}");
  13693. defineMacro("\\nsubseteqq", "\\html@mathml{\\@nsubseteqq}{\u2288}");
  13694. defineMacro("\\nsupseteqq", "\\html@mathml{\\@nsupseteqq}{\u2289}");
  13695. defineMacro("\\varsubsetneq", "\\html@mathml{\\@varsubsetneq}{⊊}");
  13696. defineMacro("\\varsubsetneqq", "\\html@mathml{\\@varsubsetneqq}{⫋}");
  13697. defineMacro("\\varsupsetneq", "\\html@mathml{\\@varsupsetneq}{⊋}");
  13698. defineMacro("\\varsupsetneqq", "\\html@mathml{\\@varsupsetneqq}{⫌}");
  13699. defineMacro("\\imath", "\\html@mathml{\\@imath}{\u0131}");
  13700. defineMacro("\\jmath", "\\html@mathml{\\@jmath}{\u0237}"); //////////////////////////////////////////////////////////////////////
  13701. // stmaryrd and semantic
  13702. // The stmaryrd and semantic packages render the next four items by calling a
  13703. // glyph. Those glyphs do not exist in the KaTeX fonts. Hence the macros.
  13704. defineMacro("\\llbracket", "\\html@mathml{" + "\\mathopen{[\\mkern-3.2mu[}}" + "{\\mathopen{\\char`\u27e6}}");
  13705. defineMacro("\\rrbracket", "\\html@mathml{" + "\\mathclose{]\\mkern-3.2mu]}}" + "{\\mathclose{\\char`\u27e7}}");
  13706. defineMacro("\u27e6", "\\llbracket"); // blackboard bold [
  13707. defineMacro("\u27e7", "\\rrbracket"); // blackboard bold ]
  13708. defineMacro("\\lBrace", "\\html@mathml{" + "\\mathopen{\\{\\mkern-3.2mu[}}" + "{\\mathopen{\\char`\u2983}}");
  13709. defineMacro("\\rBrace", "\\html@mathml{" + "\\mathclose{]\\mkern-3.2mu\\}}}" + "{\\mathclose{\\char`\u2984}}");
  13710. defineMacro("\u2983", "\\lBrace"); // blackboard bold {
  13711. defineMacro("\u2984", "\\rBrace"); // blackboard bold }
  13712. // TODO: Create variable sized versions of the last two items. I believe that
  13713. // will require new font glyphs.
  13714. // The stmaryrd function `\minuso` provides a "Plimsoll" symbol that
  13715. // superimposes the characters \circ and \mathminus. Used in chemistry.
  13716. defineMacro("\\minuso", "\\mathbin{\\html@mathml{" + "{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}" + "{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}" + "{\\char`⦵}}");
  13717. defineMacro("⦵", "\\minuso"); //////////////////////////////////////////////////////////////////////
  13718. // texvc.sty
  13719. // The texvc package contains macros available in mediawiki pages.
  13720. // We omit the functions deprecated at
  13721. // https://en.wikipedia.org/wiki/Help:Displaying_a_formula#Deprecated_syntax
  13722. // We also omit texvc's \O, which conflicts with \text{\O}
  13723. defineMacro("\\darr", "\\downarrow");
  13724. defineMacro("\\dArr", "\\Downarrow");
  13725. defineMacro("\\Darr", "\\Downarrow");
  13726. defineMacro("\\lang", "\\langle");
  13727. defineMacro("\\rang", "\\rangle");
  13728. defineMacro("\\uarr", "\\uparrow");
  13729. defineMacro("\\uArr", "\\Uparrow");
  13730. defineMacro("\\Uarr", "\\Uparrow");
  13731. defineMacro("\\N", "\\mathbb{N}");
  13732. defineMacro("\\R", "\\mathbb{R}");
  13733. defineMacro("\\Z", "\\mathbb{Z}");
  13734. defineMacro("\\alef", "\\aleph");
  13735. defineMacro("\\alefsym", "\\aleph");
  13736. defineMacro("\\Alpha", "\\mathrm{A}");
  13737. defineMacro("\\Beta", "\\mathrm{B}");
  13738. defineMacro("\\bull", "\\bullet");
  13739. defineMacro("\\Chi", "\\mathrm{X}");
  13740. defineMacro("\\clubs", "\\clubsuit");
  13741. defineMacro("\\cnums", "\\mathbb{C}");
  13742. defineMacro("\\Complex", "\\mathbb{C}");
  13743. defineMacro("\\Dagger", "\\ddagger");
  13744. defineMacro("\\diamonds", "\\diamondsuit");
  13745. defineMacro("\\empty", "\\emptyset");
  13746. defineMacro("\\Epsilon", "\\mathrm{E}");
  13747. defineMacro("\\Eta", "\\mathrm{H}");
  13748. defineMacro("\\exist", "\\exists");
  13749. defineMacro("\\harr", "\\leftrightarrow");
  13750. defineMacro("\\hArr", "\\Leftrightarrow");
  13751. defineMacro("\\Harr", "\\Leftrightarrow");
  13752. defineMacro("\\hearts", "\\heartsuit");
  13753. defineMacro("\\image", "\\Im");
  13754. defineMacro("\\infin", "\\infty");
  13755. defineMacro("\\Iota", "\\mathrm{I}");
  13756. defineMacro("\\isin", "\\in");
  13757. defineMacro("\\Kappa", "\\mathrm{K}");
  13758. defineMacro("\\larr", "\\leftarrow");
  13759. defineMacro("\\lArr", "\\Leftarrow");
  13760. defineMacro("\\Larr", "\\Leftarrow");
  13761. defineMacro("\\lrarr", "\\leftrightarrow");
  13762. defineMacro("\\lrArr", "\\Leftrightarrow");
  13763. defineMacro("\\Lrarr", "\\Leftrightarrow");
  13764. defineMacro("\\Mu", "\\mathrm{M}");
  13765. defineMacro("\\natnums", "\\mathbb{N}");
  13766. defineMacro("\\Nu", "\\mathrm{N}");
  13767. defineMacro("\\Omicron", "\\mathrm{O}");
  13768. defineMacro("\\plusmn", "\\pm");
  13769. defineMacro("\\rarr", "\\rightarrow");
  13770. defineMacro("\\rArr", "\\Rightarrow");
  13771. defineMacro("\\Rarr", "\\Rightarrow");
  13772. defineMacro("\\real", "\\Re");
  13773. defineMacro("\\reals", "\\mathbb{R}");
  13774. defineMacro("\\Reals", "\\mathbb{R}");
  13775. defineMacro("\\Rho", "\\mathrm{P}");
  13776. defineMacro("\\sdot", "\\cdot");
  13777. defineMacro("\\sect", "\\S");
  13778. defineMacro("\\spades", "\\spadesuit");
  13779. defineMacro("\\sub", "\\subset");
  13780. defineMacro("\\sube", "\\subseteq");
  13781. defineMacro("\\supe", "\\supseteq");
  13782. defineMacro("\\Tau", "\\mathrm{T}");
  13783. defineMacro("\\thetasym", "\\vartheta"); // TODO: defineMacro("\\varcoppa", "\\\mbox{\\coppa}");
  13784. defineMacro("\\weierp", "\\wp");
  13785. defineMacro("\\Zeta", "\\mathrm{Z}"); //////////////////////////////////////////////////////////////////////
  13786. // statmath.sty
  13787. // https://ctan.math.illinois.edu/macros/latex/contrib/statmath/statmath.pdf
  13788. defineMacro("\\argmin", "\\DOTSB\\operatorname*{arg\\,min}");
  13789. defineMacro("\\argmax", "\\DOTSB\\operatorname*{arg\\,max}");
  13790. defineMacro("\\plim", "\\DOTSB\\mathop{\\operatorname{plim}}\\limits"); //////////////////////////////////////////////////////////////////////
  13791. // braket.sty
  13792. // http://ctan.math.washington.edu/tex-archive/macros/latex/contrib/braket/braket.pdf
  13793. defineMacro("\\bra", "\\mathinner{\\langle{#1}|}");
  13794. defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
  13795. defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
  13796. defineMacro("\\Bra", "\\left\\langle#1\\right|");
  13797. defineMacro("\\Ket", "\\left|#1\\right\\rangle"); //////////////////////////////////////////////////////////////////////
  13798. // actuarialangle.dtx
  13799. defineMacro("\\angln", "{\\angl n}"); // Custom Khan Academy colors, should be moved to an optional package
  13800. defineMacro("\\blue", "\\textcolor{##6495ed}{#1}");
  13801. defineMacro("\\orange", "\\textcolor{##ffa500}{#1}");
  13802. defineMacro("\\pink", "\\textcolor{##ff00af}{#1}");
  13803. defineMacro("\\red", "\\textcolor{##df0030}{#1}");
  13804. defineMacro("\\green", "\\textcolor{##28ae7b}{#1}");
  13805. defineMacro("\\gray", "\\textcolor{gray}{#1}");
  13806. defineMacro("\\purple", "\\textcolor{##9d38bd}{#1}");
  13807. defineMacro("\\blueA", "\\textcolor{##ccfaff}{#1}");
  13808. defineMacro("\\blueB", "\\textcolor{##80f6ff}{#1}");
  13809. defineMacro("\\blueC", "\\textcolor{##63d9ea}{#1}");
  13810. defineMacro("\\blueD", "\\textcolor{##11accd}{#1}");
  13811. defineMacro("\\blueE", "\\textcolor{##0c7f99}{#1}");
  13812. defineMacro("\\tealA", "\\textcolor{##94fff5}{#1}");
  13813. defineMacro("\\tealB", "\\textcolor{##26edd5}{#1}");
  13814. defineMacro("\\tealC", "\\textcolor{##01d1c1}{#1}");
  13815. defineMacro("\\tealD", "\\textcolor{##01a995}{#1}");
  13816. defineMacro("\\tealE", "\\textcolor{##208170}{#1}");
  13817. defineMacro("\\greenA", "\\textcolor{##b6ffb0}{#1}");
  13818. defineMacro("\\greenB", "\\textcolor{##8af281}{#1}");
  13819. defineMacro("\\greenC", "\\textcolor{##74cf70}{#1}");
  13820. defineMacro("\\greenD", "\\textcolor{##1fab54}{#1}");
  13821. defineMacro("\\greenE", "\\textcolor{##0d923f}{#1}");
  13822. defineMacro("\\goldA", "\\textcolor{##ffd0a9}{#1}");
  13823. defineMacro("\\goldB", "\\textcolor{##ffbb71}{#1}");
  13824. defineMacro("\\goldC", "\\textcolor{##ff9c39}{#1}");
  13825. defineMacro("\\goldD", "\\textcolor{##e07d10}{#1}");
  13826. defineMacro("\\goldE", "\\textcolor{##a75a05}{#1}");
  13827. defineMacro("\\redA", "\\textcolor{##fca9a9}{#1}");
  13828. defineMacro("\\redB", "\\textcolor{##ff8482}{#1}");
  13829. defineMacro("\\redC", "\\textcolor{##f9685d}{#1}");
  13830. defineMacro("\\redD", "\\textcolor{##e84d39}{#1}");
  13831. defineMacro("\\redE", "\\textcolor{##bc2612}{#1}");
  13832. defineMacro("\\maroonA", "\\textcolor{##ffbde0}{#1}");
  13833. defineMacro("\\maroonB", "\\textcolor{##ff92c6}{#1}");
  13834. defineMacro("\\maroonC", "\\textcolor{##ed5fa6}{#1}");
  13835. defineMacro("\\maroonD", "\\textcolor{##ca337c}{#1}");
  13836. defineMacro("\\maroonE", "\\textcolor{##9e034e}{#1}");
  13837. defineMacro("\\purpleA", "\\textcolor{##ddd7ff}{#1}");
  13838. defineMacro("\\purpleB", "\\textcolor{##c6b9fc}{#1}");
  13839. defineMacro("\\purpleC", "\\textcolor{##aa87ff}{#1}");
  13840. defineMacro("\\purpleD", "\\textcolor{##7854ab}{#1}");
  13841. defineMacro("\\purpleE", "\\textcolor{##543b78}{#1}");
  13842. defineMacro("\\mintA", "\\textcolor{##f5f9e8}{#1}");
  13843. defineMacro("\\mintB", "\\textcolor{##edf2df}{#1}");
  13844. defineMacro("\\mintC", "\\textcolor{##e0e5cc}{#1}");
  13845. defineMacro("\\grayA", "\\textcolor{##f6f7f7}{#1}");
  13846. defineMacro("\\grayB", "\\textcolor{##f0f1f2}{#1}");
  13847. defineMacro("\\grayC", "\\textcolor{##e3e5e6}{#1}");
  13848. defineMacro("\\grayD", "\\textcolor{##d6d8da}{#1}");
  13849. defineMacro("\\grayE", "\\textcolor{##babec2}{#1}");
  13850. defineMacro("\\grayF", "\\textcolor{##888d93}{#1}");
  13851. defineMacro("\\grayG", "\\textcolor{##626569}{#1}");
  13852. defineMacro("\\grayH", "\\textcolor{##3b3e40}{#1}");
  13853. defineMacro("\\grayI", "\\textcolor{##21242c}{#1}");
  13854. defineMacro("\\kaBlue", "\\textcolor{##314453}{#1}");
  13855. defineMacro("\\kaGreen", "\\textcolor{##71B307}{#1}");
  13856. /**
  13857. * This file contains the “gullet” where macros are expanded
  13858. * until only non-macro tokens remain.
  13859. */
  13860. // List of commands that act like macros but aren't defined as a macro,
  13861. // function, or symbol. Used in `isDefined`.
  13862. var implicitCommands = {
  13863. "^": true,
  13864. // Parser.js
  13865. "_": true,
  13866. // Parser.js
  13867. "\\limits": true,
  13868. // Parser.js
  13869. "\\nolimits": true // Parser.js
  13870. };
  13871. class MacroExpander {
  13872. constructor(input, settings, mode) {
  13873. this.settings = void 0;
  13874. this.expansionCount = void 0;
  13875. this.lexer = void 0;
  13876. this.macros = void 0;
  13877. this.stack = void 0;
  13878. this.mode = void 0;
  13879. this.settings = settings;
  13880. this.expansionCount = 0;
  13881. this.feed(input); // Make new global namespace
  13882. this.macros = new Namespace(macros, settings.macros);
  13883. this.mode = mode;
  13884. this.stack = []; // contains tokens in REVERSE order
  13885. }
  13886. /**
  13887. * Feed a new input string to the same MacroExpander
  13888. * (with existing macros etc.).
  13889. */
  13890. feed(input) {
  13891. this.lexer = new Lexer(input, this.settings);
  13892. }
  13893. /**
  13894. * Switches between "text" and "math" modes.
  13895. */
  13896. switchMode(newMode) {
  13897. this.mode = newMode;
  13898. }
  13899. /**
  13900. * Start a new group nesting within all namespaces.
  13901. */
  13902. beginGroup() {
  13903. this.macros.beginGroup();
  13904. }
  13905. /**
  13906. * End current group nesting within all namespaces.
  13907. */
  13908. endGroup() {
  13909. this.macros.endGroup();
  13910. }
  13911. /**
  13912. * Ends all currently nested groups (if any), restoring values before the
  13913. * groups began. Useful in case of an error in the middle of parsing.
  13914. */
  13915. endGroups() {
  13916. this.macros.endGroups();
  13917. }
  13918. /**
  13919. * Returns the topmost token on the stack, without expanding it.
  13920. * Similar in behavior to TeX's `\futurelet`.
  13921. */
  13922. future() {
  13923. if (this.stack.length === 0) {
  13924. this.pushToken(this.lexer.lex());
  13925. }
  13926. return this.stack[this.stack.length - 1];
  13927. }
  13928. /**
  13929. * Remove and return the next unexpanded token.
  13930. */
  13931. popToken() {
  13932. this.future(); // ensure non-empty stack
  13933. return this.stack.pop();
  13934. }
  13935. /**
  13936. * Add a given token to the token stack. In particular, this get be used
  13937. * to put back a token returned from one of the other methods.
  13938. */
  13939. pushToken(token) {
  13940. this.stack.push(token);
  13941. }
  13942. /**
  13943. * Append an array of tokens to the token stack.
  13944. */
  13945. pushTokens(tokens) {
  13946. this.stack.push(...tokens);
  13947. }
  13948. /**
  13949. * Find an macro argument without expanding tokens and append the array of
  13950. * tokens to the token stack. Uses Token as a container for the result.
  13951. */
  13952. scanArgument(isOptional) {
  13953. var start;
  13954. var end;
  13955. var tokens;
  13956. if (isOptional) {
  13957. this.consumeSpaces(); // \@ifnextchar gobbles any space following it
  13958. if (this.future().text !== "[") {
  13959. return null;
  13960. }
  13961. start = this.popToken(); // don't include [ in tokens
  13962. ({
  13963. tokens,
  13964. end
  13965. } = this.consumeArg(["]"]));
  13966. } else {
  13967. ({
  13968. tokens,
  13969. start,
  13970. end
  13971. } = this.consumeArg());
  13972. } // indicate the end of an argument
  13973. this.pushToken(new Token("EOF", end.loc));
  13974. this.pushTokens(tokens);
  13975. return start.range(end, "");
  13976. }
  13977. /**
  13978. * Consume all following space tokens, without expansion.
  13979. */
  13980. consumeSpaces() {
  13981. for (;;) {
  13982. var token = this.future();
  13983. if (token.text === " ") {
  13984. this.stack.pop();
  13985. } else {
  13986. break;
  13987. }
  13988. }
  13989. }
  13990. /**
  13991. * Consume an argument from the token stream, and return the resulting array
  13992. * of tokens and start/end token.
  13993. */
  13994. consumeArg(delims) {
  13995. // The argument for a delimited parameter is the shortest (possibly
  13996. // empty) sequence of tokens with properly nested {...} groups that is
  13997. // followed ... by this particular list of non-parameter tokens.
  13998. // The argument for an undelimited parameter is the next nonblank
  13999. // token, unless that token is ‘{’, when the argument will be the
  14000. // entire {...} group that follows.
  14001. var tokens = [];
  14002. var isDelimited = delims && delims.length > 0;
  14003. if (!isDelimited) {
  14004. // Ignore spaces between arguments. As the TeXbook says:
  14005. // "After you have said ‘\def\row#1#2{...}’, you are allowed to
  14006. // put spaces between the arguments (e.g., ‘\row x n’), because
  14007. // TeX doesn’t use single spaces as undelimited arguments."
  14008. this.consumeSpaces();
  14009. }
  14010. var start = this.future();
  14011. var tok;
  14012. var depth = 0;
  14013. var match = 0;
  14014. do {
  14015. tok = this.popToken();
  14016. tokens.push(tok);
  14017. if (tok.text === "{") {
  14018. ++depth;
  14019. } else if (tok.text === "}") {
  14020. --depth;
  14021. if (depth === -1) {
  14022. throw new ParseError("Extra }", tok);
  14023. }
  14024. } else if (tok.text === "EOF") {
  14025. throw new ParseError("Unexpected end of input in a macro argument" + ", expected '" + (delims && isDelimited ? delims[match] : "}") + "'", tok);
  14026. }
  14027. if (delims && isDelimited) {
  14028. if ((depth === 0 || depth === 1 && delims[match] === "{") && tok.text === delims[match]) {
  14029. ++match;
  14030. if (match === delims.length) {
  14031. // don't include delims in tokens
  14032. tokens.splice(-match, match);
  14033. break;
  14034. }
  14035. } else {
  14036. match = 0;
  14037. }
  14038. }
  14039. } while (depth !== 0 || isDelimited); // If the argument found ... has the form ‘{<nested tokens>}’,
  14040. // ... the outermost braces enclosing the argument are removed
  14041. if (start.text === "{" && tokens[tokens.length - 1].text === "}") {
  14042. tokens.pop();
  14043. tokens.shift();
  14044. }
  14045. tokens.reverse(); // to fit in with stack order
  14046. return {
  14047. tokens,
  14048. start,
  14049. end: tok
  14050. };
  14051. }
  14052. /**
  14053. * Consume the specified number of (delimited) arguments from the token
  14054. * stream and return the resulting array of arguments.
  14055. */
  14056. consumeArgs(numArgs, delimiters) {
  14057. if (delimiters) {
  14058. if (delimiters.length !== numArgs + 1) {
  14059. throw new ParseError("The length of delimiters doesn't match the number of args!");
  14060. }
  14061. var delims = delimiters[0];
  14062. for (var i = 0; i < delims.length; i++) {
  14063. var tok = this.popToken();
  14064. if (delims[i] !== tok.text) {
  14065. throw new ParseError("Use of the macro doesn't match its definition", tok);
  14066. }
  14067. }
  14068. }
  14069. var args = [];
  14070. for (var _i = 0; _i < numArgs; _i++) {
  14071. args.push(this.consumeArg(delimiters && delimiters[_i + 1]).tokens);
  14072. }
  14073. return args;
  14074. }
  14075. /**
  14076. * Expand the next token only once if possible.
  14077. *
  14078. * If the token is expanded, the resulting tokens will be pushed onto
  14079. * the stack in reverse order and will be returned as an array,
  14080. * also in reverse order.
  14081. *
  14082. * If not, the next token will be returned without removing it
  14083. * from the stack. This case can be detected by a `Token` return value
  14084. * instead of an `Array` return value.
  14085. *
  14086. * In either case, the next token will be on the top of the stack,
  14087. * or the stack will be empty.
  14088. *
  14089. * Used to implement `expandAfterFuture` and `expandNextToken`.
  14090. *
  14091. * If expandableOnly, only expandable tokens are expanded and
  14092. * an undefined control sequence results in an error.
  14093. */
  14094. expandOnce(expandableOnly) {
  14095. var topToken = this.popToken();
  14096. var name = topToken.text;
  14097. var expansion = !topToken.noexpand ? this._getExpansion(name) : null;
  14098. if (expansion == null || expandableOnly && expansion.unexpandable) {
  14099. if (expandableOnly && expansion == null && name[0] === "\\" && !this.isDefined(name)) {
  14100. throw new ParseError("Undefined control sequence: " + name);
  14101. }
  14102. this.pushToken(topToken);
  14103. return topToken;
  14104. }
  14105. this.expansionCount++;
  14106. if (this.expansionCount > this.settings.maxExpand) {
  14107. throw new ParseError("Too many expansions: infinite loop or " + "need to increase maxExpand setting");
  14108. }
  14109. var tokens = expansion.tokens;
  14110. var args = this.consumeArgs(expansion.numArgs, expansion.delimiters);
  14111. if (expansion.numArgs) {
  14112. // paste arguments in place of the placeholders
  14113. tokens = tokens.slice(); // make a shallow copy
  14114. for (var i = tokens.length - 1; i >= 0; --i) {
  14115. var tok = tokens[i];
  14116. if (tok.text === "#") {
  14117. if (i === 0) {
  14118. throw new ParseError("Incomplete placeholder at end of macro body", tok);
  14119. }
  14120. tok = tokens[--i]; // next token on stack
  14121. if (tok.text === "#") {
  14122. // ## → #
  14123. tokens.splice(i + 1, 1); // drop first #
  14124. } else if (/^[1-9]$/.test(tok.text)) {
  14125. // replace the placeholder with the indicated argument
  14126. tokens.splice(i, 2, ...args[+tok.text - 1]);
  14127. } else {
  14128. throw new ParseError("Not a valid argument number", tok);
  14129. }
  14130. }
  14131. }
  14132. } // Concatenate expansion onto top of stack.
  14133. this.pushTokens(tokens);
  14134. return tokens;
  14135. }
  14136. /**
  14137. * Expand the next token only once (if possible), and return the resulting
  14138. * top token on the stack (without removing anything from the stack).
  14139. * Similar in behavior to TeX's `\expandafter\futurelet`.
  14140. * Equivalent to expandOnce() followed by future().
  14141. */
  14142. expandAfterFuture() {
  14143. this.expandOnce();
  14144. return this.future();
  14145. }
  14146. /**
  14147. * Recursively expand first token, then return first non-expandable token.
  14148. */
  14149. expandNextToken() {
  14150. for (;;) {
  14151. var expanded = this.expandOnce(); // expandOnce returns Token if and only if it's fully expanded.
  14152. if (expanded instanceof Token) {
  14153. // the token after \noexpand is interpreted as if its meaning
  14154. // were ‘\relax’
  14155. if (expanded.treatAsRelax) {
  14156. expanded.text = "\\relax";
  14157. }
  14158. return this.stack.pop(); // === expanded
  14159. }
  14160. } // Flow unable to figure out that this pathway is impossible.
  14161. // https://github.com/facebook/flow/issues/4808
  14162. throw new Error(); // eslint-disable-line no-unreachable
  14163. }
  14164. /**
  14165. * Fully expand the given macro name and return the resulting list of
  14166. * tokens, or return `undefined` if no such macro is defined.
  14167. */
  14168. expandMacro(name) {
  14169. return this.macros.has(name) ? this.expandTokens([new Token(name)]) : undefined;
  14170. }
  14171. /**
  14172. * Fully expand the given token stream and return the resulting list of tokens
  14173. */
  14174. expandTokens(tokens) {
  14175. var output = [];
  14176. var oldStackLength = this.stack.length;
  14177. this.pushTokens(tokens);
  14178. while (this.stack.length > oldStackLength) {
  14179. var expanded = this.expandOnce(true); // expand only expandable tokens
  14180. // expandOnce returns Token if and only if it's fully expanded.
  14181. if (expanded instanceof Token) {
  14182. if (expanded.treatAsRelax) {
  14183. // the expansion of \noexpand is the token itself
  14184. expanded.noexpand = false;
  14185. expanded.treatAsRelax = false;
  14186. }
  14187. output.push(this.stack.pop());
  14188. }
  14189. }
  14190. return output;
  14191. }
  14192. /**
  14193. * Fully expand the given macro name and return the result as a string,
  14194. * or return `undefined` if no such macro is defined.
  14195. */
  14196. expandMacroAsText(name) {
  14197. var tokens = this.expandMacro(name);
  14198. if (tokens) {
  14199. return tokens.map(token => token.text).join("");
  14200. } else {
  14201. return tokens;
  14202. }
  14203. }
  14204. /**
  14205. * Returns the expanded macro as a reversed array of tokens and a macro
  14206. * argument count. Or returns `null` if no such macro.
  14207. */
  14208. _getExpansion(name) {
  14209. var definition = this.macros.get(name);
  14210. if (definition == null) {
  14211. // mainly checking for undefined here
  14212. return definition;
  14213. } // If a single character has an associated catcode other than 13
  14214. // (active character), then don't expand it.
  14215. if (name.length === 1) {
  14216. var catcode = this.lexer.catcodes[name];
  14217. if (catcode != null && catcode !== 13) {
  14218. return;
  14219. }
  14220. }
  14221. var expansion = typeof definition === "function" ? definition(this) : definition;
  14222. if (typeof expansion === "string") {
  14223. var numArgs = 0;
  14224. if (expansion.indexOf("#") !== -1) {
  14225. var stripped = expansion.replace(/##/g, "");
  14226. while (stripped.indexOf("#" + (numArgs + 1)) !== -1) {
  14227. ++numArgs;
  14228. }
  14229. }
  14230. var bodyLexer = new Lexer(expansion, this.settings);
  14231. var tokens = [];
  14232. var tok = bodyLexer.lex();
  14233. while (tok.text !== "EOF") {
  14234. tokens.push(tok);
  14235. tok = bodyLexer.lex();
  14236. }
  14237. tokens.reverse(); // to fit in with stack using push and pop
  14238. var expanded = {
  14239. tokens,
  14240. numArgs
  14241. };
  14242. return expanded;
  14243. }
  14244. return expansion;
  14245. }
  14246. /**
  14247. * Determine whether a command is currently "defined" (has some
  14248. * functionality), meaning that it's a macro (in the current group),
  14249. * a function, a symbol, or one of the special commands listed in
  14250. * `implicitCommands`.
  14251. */
  14252. isDefined(name) {
  14253. return this.macros.has(name) || functions.hasOwnProperty(name) || symbols.math.hasOwnProperty(name) || symbols.text.hasOwnProperty(name) || implicitCommands.hasOwnProperty(name);
  14254. }
  14255. /**
  14256. * Determine whether a command is expandable.
  14257. */
  14258. isExpandable(name) {
  14259. var macro = this.macros.get(name);
  14260. return macro != null ? typeof macro === "string" || typeof macro === "function" || !macro.unexpandable : functions.hasOwnProperty(name) && !functions[name].primitive;
  14261. }
  14262. }
  14263. /* eslint no-constant-condition:0 */
  14264. var unicodeAccents = {
  14265. "́": {
  14266. "text": "\\'",
  14267. "math": "\\acute"
  14268. },
  14269. "̀": {
  14270. "text": "\\`",
  14271. "math": "\\grave"
  14272. },
  14273. "̈": {
  14274. "text": "\\\"",
  14275. "math": "\\ddot"
  14276. },
  14277. "̃": {
  14278. "text": "\\~",
  14279. "math": "\\tilde"
  14280. },
  14281. "̄": {
  14282. "text": "\\=",
  14283. "math": "\\bar"
  14284. },
  14285. "̆": {
  14286. "text": "\\u",
  14287. "math": "\\breve"
  14288. },
  14289. "̌": {
  14290. "text": "\\v",
  14291. "math": "\\check"
  14292. },
  14293. "̂": {
  14294. "text": "\\^",
  14295. "math": "\\hat"
  14296. },
  14297. "̇": {
  14298. "text": "\\.",
  14299. "math": "\\dot"
  14300. },
  14301. "̊": {
  14302. "text": "\\r",
  14303. "math": "\\mathring"
  14304. },
  14305. "̋": {
  14306. "text": "\\H"
  14307. },
  14308. "̧": {
  14309. "text": "\\c"
  14310. }
  14311. };
  14312. var unicodeSymbols = {
  14313. "á": "á",
  14314. "à": "à",
  14315. "ä": "ä",
  14316. "ǟ": "ǟ",
  14317. "ã": "ã",
  14318. "ā": "ā",
  14319. "ă": "ă",
  14320. "ắ": "ắ",
  14321. "ằ": "ằ",
  14322. "ẵ": "ẵ",
  14323. "ǎ": "ǎ",
  14324. "â": "â",
  14325. "ấ": "ấ",
  14326. "ầ": "ầ",
  14327. "ẫ": "ẫ",
  14328. "ȧ": "ȧ",
  14329. "ǡ": "ǡ",
  14330. "å": "å",
  14331. "ǻ": "ǻ",
  14332. "ḃ": "ḃ",
  14333. "ć": "ć",
  14334. "ḉ": "ḉ",
  14335. "č": "č",
  14336. "ĉ": "ĉ",
  14337. "ċ": "ċ",
  14338. "ç": "ç",
  14339. "ď": "ď",
  14340. "ḋ": "ḋ",
  14341. "ḑ": "ḑ",
  14342. "é": "é",
  14343. "è": "è",
  14344. "ë": "ë",
  14345. "ẽ": "ẽ",
  14346. "ē": "ē",
  14347. "ḗ": "ḗ",
  14348. "ḕ": "ḕ",
  14349. "ĕ": "ĕ",
  14350. "ḝ": "ḝ",
  14351. "ě": "ě",
  14352. "ê": "ê",
  14353. "ế": "ế",
  14354. "ề": "ề",
  14355. "ễ": "ễ",
  14356. "ė": "ė",
  14357. "ȩ": "ȩ",
  14358. "ḟ": "ḟ",
  14359. "ǵ": "ǵ",
  14360. "ḡ": "ḡ",
  14361. "ğ": "ğ",
  14362. "ǧ": "ǧ",
  14363. "ĝ": "ĝ",
  14364. "ġ": "ġ",
  14365. "ģ": "ģ",
  14366. "ḧ": "ḧ",
  14367. "ȟ": "ȟ",
  14368. "ĥ": "ĥ",
  14369. "ḣ": "ḣ",
  14370. "ḩ": "ḩ",
  14371. "í": "í",
  14372. "ì": "ì",
  14373. "ï": "ï",
  14374. "ḯ": "ḯ",
  14375. "ĩ": "ĩ",
  14376. "ī": "ī",
  14377. "ĭ": "ĭ",
  14378. "ǐ": "ǐ",
  14379. "î": "î",
  14380. "ǰ": "ǰ",
  14381. "ĵ": "ĵ",
  14382. "ḱ": "ḱ",
  14383. "ǩ": "ǩ",
  14384. "ķ": "ķ",
  14385. "ĺ": "ĺ",
  14386. "ľ": "ľ",
  14387. "ļ": "ļ",
  14388. "ḿ": "ḿ",
  14389. "ṁ": "ṁ",
  14390. "ń": "ń",
  14391. "ǹ": "ǹ",
  14392. "ñ": "ñ",
  14393. "ň": "ň",
  14394. "ṅ": "ṅ",
  14395. "ņ": "ņ",
  14396. "ó": "ó",
  14397. "ò": "ò",
  14398. "ö": "ö",
  14399. "ȫ": "ȫ",
  14400. "õ": "õ",
  14401. "ṍ": "ṍ",
  14402. "ṏ": "ṏ",
  14403. "ȭ": "ȭ",
  14404. "ō": "ō",
  14405. "ṓ": "ṓ",
  14406. "ṑ": "ṑ",
  14407. "ŏ": "ŏ",
  14408. "ǒ": "ǒ",
  14409. "ô": "ô",
  14410. "ố": "ố",
  14411. "ồ": "ồ",
  14412. "ỗ": "ỗ",
  14413. "ȯ": "ȯ",
  14414. "ȱ": "ȱ",
  14415. "ő": "ő",
  14416. "ṕ": "ṕ",
  14417. "ṗ": "ṗ",
  14418. "ŕ": "ŕ",
  14419. "ř": "ř",
  14420. "ṙ": "ṙ",
  14421. "ŗ": "ŗ",
  14422. "ś": "ś",
  14423. "ṥ": "ṥ",
  14424. "š": "š",
  14425. "ṧ": "ṧ",
  14426. "ŝ": "ŝ",
  14427. "ṡ": "ṡ",
  14428. "ş": "ş",
  14429. "ẗ": "ẗ",
  14430. "ť": "ť",
  14431. "ṫ": "ṫ",
  14432. "ţ": "ţ",
  14433. "ú": "ú",
  14434. "ù": "ù",
  14435. "ü": "ü",
  14436. "ǘ": "ǘ",
  14437. "ǜ": "ǜ",
  14438. "ǖ": "ǖ",
  14439. "ǚ": "ǚ",
  14440. "ũ": "ũ",
  14441. "ṹ": "ṹ",
  14442. "ū": "ū",
  14443. "ṻ": "ṻ",
  14444. "ŭ": "ŭ",
  14445. "ǔ": "ǔ",
  14446. "û": "û",
  14447. "ů": "ů",
  14448. "ű": "ű",
  14449. "ṽ": "ṽ",
  14450. "ẃ": "ẃ",
  14451. "ẁ": "ẁ",
  14452. "ẅ": "ẅ",
  14453. "ŵ": "ŵ",
  14454. "ẇ": "ẇ",
  14455. "ẘ": "ẘ",
  14456. "ẍ": "ẍ",
  14457. "ẋ": "ẋ",
  14458. "ý": "ý",
  14459. "ỳ": "ỳ",
  14460. "ÿ": "ÿ",
  14461. "ỹ": "ỹ",
  14462. "ȳ": "ȳ",
  14463. "ŷ": "ŷ",
  14464. "ẏ": "ẏ",
  14465. "ẙ": "ẙ",
  14466. "ź": "ź",
  14467. "ž": "ž",
  14468. "ẑ": "ẑ",
  14469. "ż": "ż",
  14470. "Á": "Á",
  14471. "À": "À",
  14472. "Ä": "Ä",
  14473. "Ǟ": "Ǟ",
  14474. "Ã": "Ã",
  14475. "Ā": "Ā",
  14476. "Ă": "Ă",
  14477. "Ắ": "Ắ",
  14478. "Ằ": "Ằ",
  14479. "Ẵ": "Ẵ",
  14480. "Ǎ": "Ǎ",
  14481. "Â": "Â",
  14482. "Ấ": "Ấ",
  14483. "Ầ": "Ầ",
  14484. "Ẫ": "Ẫ",
  14485. "Ȧ": "Ȧ",
  14486. "Ǡ": "Ǡ",
  14487. "Å": "Å",
  14488. "Ǻ": "Ǻ",
  14489. "Ḃ": "Ḃ",
  14490. "Ć": "Ć",
  14491. "Ḉ": "Ḉ",
  14492. "Č": "Č",
  14493. "Ĉ": "Ĉ",
  14494. "Ċ": "Ċ",
  14495. "Ç": "Ç",
  14496. "Ď": "Ď",
  14497. "Ḋ": "Ḋ",
  14498. "Ḑ": "Ḑ",
  14499. "É": "É",
  14500. "È": "È",
  14501. "Ë": "Ë",
  14502. "Ẽ": "Ẽ",
  14503. "Ē": "Ē",
  14504. "Ḗ": "Ḗ",
  14505. "Ḕ": "Ḕ",
  14506. "Ĕ": "Ĕ",
  14507. "Ḝ": "Ḝ",
  14508. "Ě": "Ě",
  14509. "Ê": "Ê",
  14510. "Ế": "Ế",
  14511. "Ề": "Ề",
  14512. "Ễ": "Ễ",
  14513. "Ė": "Ė",
  14514. "Ȩ": "Ȩ",
  14515. "Ḟ": "Ḟ",
  14516. "Ǵ": "Ǵ",
  14517. "Ḡ": "Ḡ",
  14518. "Ğ": "Ğ",
  14519. "Ǧ": "Ǧ",
  14520. "Ĝ": "Ĝ",
  14521. "Ġ": "Ġ",
  14522. "Ģ": "Ģ",
  14523. "Ḧ": "Ḧ",
  14524. "Ȟ": "Ȟ",
  14525. "Ĥ": "Ĥ",
  14526. "Ḣ": "Ḣ",
  14527. "Ḩ": "Ḩ",
  14528. "Í": "Í",
  14529. "Ì": "Ì",
  14530. "Ï": "Ï",
  14531. "Ḯ": "Ḯ",
  14532. "Ĩ": "Ĩ",
  14533. "Ī": "Ī",
  14534. "Ĭ": "Ĭ",
  14535. "Ǐ": "Ǐ",
  14536. "Î": "Î",
  14537. "İ": "İ",
  14538. "Ĵ": "Ĵ",
  14539. "Ḱ": "Ḱ",
  14540. "Ǩ": "Ǩ",
  14541. "Ķ": "Ķ",
  14542. "Ĺ": "Ĺ",
  14543. "Ľ": "Ľ",
  14544. "Ļ": "Ļ",
  14545. "Ḿ": "Ḿ",
  14546. "Ṁ": "Ṁ",
  14547. "Ń": "Ń",
  14548. "Ǹ": "Ǹ",
  14549. "Ñ": "Ñ",
  14550. "Ň": "Ň",
  14551. "Ṅ": "Ṅ",
  14552. "Ņ": "Ņ",
  14553. "Ó": "Ó",
  14554. "Ò": "Ò",
  14555. "Ö": "Ö",
  14556. "Ȫ": "Ȫ",
  14557. "Õ": "Õ",
  14558. "Ṍ": "Ṍ",
  14559. "Ṏ": "Ṏ",
  14560. "Ȭ": "Ȭ",
  14561. "Ō": "Ō",
  14562. "Ṓ": "Ṓ",
  14563. "Ṑ": "Ṑ",
  14564. "Ŏ": "Ŏ",
  14565. "Ǒ": "Ǒ",
  14566. "Ô": "Ô",
  14567. "Ố": "Ố",
  14568. "Ồ": "Ồ",
  14569. "Ỗ": "Ỗ",
  14570. "Ȯ": "Ȯ",
  14571. "Ȱ": "Ȱ",
  14572. "Ő": "Ő",
  14573. "Ṕ": "Ṕ",
  14574. "Ṗ": "Ṗ",
  14575. "Ŕ": "Ŕ",
  14576. "Ř": "Ř",
  14577. "Ṙ": "Ṙ",
  14578. "Ŗ": "Ŗ",
  14579. "Ś": "Ś",
  14580. "Ṥ": "Ṥ",
  14581. "Š": "Š",
  14582. "Ṧ": "Ṧ",
  14583. "Ŝ": "Ŝ",
  14584. "Ṡ": "Ṡ",
  14585. "Ş": "Ş",
  14586. "Ť": "Ť",
  14587. "Ṫ": "Ṫ",
  14588. "Ţ": "Ţ",
  14589. "Ú": "Ú",
  14590. "Ù": "Ù",
  14591. "Ü": "Ü",
  14592. "Ǘ": "Ǘ",
  14593. "Ǜ": "Ǜ",
  14594. "Ǖ": "Ǖ",
  14595. "Ǚ": "Ǚ",
  14596. "Ũ": "Ũ",
  14597. "Ṹ": "Ṹ",
  14598. "Ū": "Ū",
  14599. "Ṻ": "Ṻ",
  14600. "Ŭ": "Ŭ",
  14601. "Ǔ": "Ǔ",
  14602. "Û": "Û",
  14603. "Ů": "Ů",
  14604. "Ű": "Ű",
  14605. "Ṽ": "Ṽ",
  14606. "Ẃ": "Ẃ",
  14607. "Ẁ": "Ẁ",
  14608. "Ẅ": "Ẅ",
  14609. "Ŵ": "Ŵ",
  14610. "Ẇ": "Ẇ",
  14611. "Ẍ": "Ẍ",
  14612. "Ẋ": "Ẋ",
  14613. "Ý": "Ý",
  14614. "Ỳ": "Ỳ",
  14615. "Ÿ": "Ÿ",
  14616. "Ỹ": "Ỹ",
  14617. "Ȳ": "Ȳ",
  14618. "Ŷ": "Ŷ",
  14619. "Ẏ": "Ẏ",
  14620. "Ź": "Ź",
  14621. "Ž": "Ž",
  14622. "Ẑ": "Ẑ",
  14623. "Ż": "Ż",
  14624. "ά": "ά",
  14625. "ὰ": "ὰ",
  14626. "ᾱ": "ᾱ",
  14627. "ᾰ": "ᾰ",
  14628. "έ": "έ",
  14629. "ὲ": "ὲ",
  14630. "ή": "ή",
  14631. "ὴ": "ὴ",
  14632. "ί": "ί",
  14633. "ὶ": "ὶ",
  14634. "ϊ": "ϊ",
  14635. "ΐ": "ΐ",
  14636. "ῒ": "ῒ",
  14637. "ῑ": "ῑ",
  14638. "ῐ": "ῐ",
  14639. "ό": "ό",
  14640. "ὸ": "ὸ",
  14641. "ύ": "ύ",
  14642. "ὺ": "ὺ",
  14643. "ϋ": "ϋ",
  14644. "ΰ": "ΰ",
  14645. "ῢ": "ῢ",
  14646. "ῡ": "ῡ",
  14647. "ῠ": "ῠ",
  14648. "ώ": "ώ",
  14649. "ὼ": "ὼ",
  14650. "Ύ": "Ύ",
  14651. "Ὺ": "Ὺ",
  14652. "Ϋ": "Ϋ",
  14653. "Ῡ": "Ῡ",
  14654. "Ῠ": "Ῠ",
  14655. "Ώ": "Ώ",
  14656. "Ὼ": "Ὼ"
  14657. };
  14658. /**
  14659. * This file contains the parser used to parse out a TeX expression from the
  14660. * input. Since TeX isn't context-free, standard parsers don't work particularly
  14661. * well.
  14662. *
  14663. * The strategy of this parser is as such:
  14664. *
  14665. * The main functions (the `.parse...` ones) take a position in the current
  14666. * parse string to parse tokens from. The lexer (found in Lexer.js, stored at
  14667. * this.gullet.lexer) also supports pulling out tokens at arbitrary places. When
  14668. * individual tokens are needed at a position, the lexer is called to pull out a
  14669. * token, which is then used.
  14670. *
  14671. * The parser has a property called "mode" indicating the mode that
  14672. * the parser is currently in. Currently it has to be one of "math" or
  14673. * "text", which denotes whether the current environment is a math-y
  14674. * one or a text-y one (e.g. inside \text). Currently, this serves to
  14675. * limit the functions which can be used in text mode.
  14676. *
  14677. * The main functions then return an object which contains the useful data that
  14678. * was parsed at its given point, and a new position at the end of the parsed
  14679. * data. The main functions can call each other and continue the parsing by
  14680. * using the returned position as a new starting point.
  14681. *
  14682. * There are also extra `.handle...` functions, which pull out some reused
  14683. * functionality into self-contained functions.
  14684. *
  14685. * The functions return ParseNodes.
  14686. */
  14687. class Parser {
  14688. constructor(input, settings) {
  14689. this.mode = void 0;
  14690. this.gullet = void 0;
  14691. this.settings = void 0;
  14692. this.leftrightDepth = void 0;
  14693. this.nextToken = void 0;
  14694. // Start in math mode
  14695. this.mode = "math"; // Create a new macro expander (gullet) and (indirectly via that) also a
  14696. // new lexer (mouth) for this parser (stomach, in the language of TeX)
  14697. this.gullet = new MacroExpander(input, settings, this.mode); // Store the settings for use in parsing
  14698. this.settings = settings; // Count leftright depth (for \middle errors)
  14699. this.leftrightDepth = 0;
  14700. }
  14701. /**
  14702. * Checks a result to make sure it has the right type, and throws an
  14703. * appropriate error otherwise.
  14704. */
  14705. expect(text, consume) {
  14706. if (consume === void 0) {
  14707. consume = true;
  14708. }
  14709. if (this.fetch().text !== text) {
  14710. throw new ParseError("Expected '" + text + "', got '" + this.fetch().text + "'", this.fetch());
  14711. }
  14712. if (consume) {
  14713. this.consume();
  14714. }
  14715. }
  14716. /**
  14717. * Discards the current lookahead token, considering it consumed.
  14718. */
  14719. consume() {
  14720. this.nextToken = null;
  14721. }
  14722. /**
  14723. * Return the current lookahead token, or if there isn't one (at the
  14724. * beginning, or if the previous lookahead token was consume()d),
  14725. * fetch the next token as the new lookahead token and return it.
  14726. */
  14727. fetch() {
  14728. if (this.nextToken == null) {
  14729. this.nextToken = this.gullet.expandNextToken();
  14730. }
  14731. return this.nextToken;
  14732. }
  14733. /**
  14734. * Switches between "text" and "math" modes.
  14735. */
  14736. switchMode(newMode) {
  14737. this.mode = newMode;
  14738. this.gullet.switchMode(newMode);
  14739. }
  14740. /**
  14741. * Main parsing function, which parses an entire input.
  14742. */
  14743. parse() {
  14744. if (!this.settings.globalGroup) {
  14745. // Create a group namespace for the math expression.
  14746. // (LaTeX creates a new group for every $...$, $$...$$, \[...\].)
  14747. this.gullet.beginGroup();
  14748. } // Use old \color behavior (same as LaTeX's \textcolor) if requested.
  14749. // We do this within the group for the math expression, so it doesn't
  14750. // pollute settings.macros.
  14751. if (this.settings.colorIsTextColor) {
  14752. this.gullet.macros.set("\\color", "\\textcolor");
  14753. }
  14754. try {
  14755. // Try to parse the input
  14756. var parse = this.parseExpression(false); // If we succeeded, make sure there's an EOF at the end
  14757. this.expect("EOF"); // End the group namespace for the expression
  14758. if (!this.settings.globalGroup) {
  14759. this.gullet.endGroup();
  14760. }
  14761. return parse; // Close any leftover groups in case of a parse error.
  14762. } finally {
  14763. this.gullet.endGroups();
  14764. }
  14765. }
  14766. /**
  14767. * Fully parse a separate sequence of tokens as a separate job.
  14768. * Tokens should be specified in reverse order, as in a MacroDefinition.
  14769. */
  14770. subparse(tokens) {
  14771. // Save the next token from the current job.
  14772. var oldToken = this.nextToken;
  14773. this.consume(); // Run the new job, terminating it with an excess '}'
  14774. this.gullet.pushToken(new Token("}"));
  14775. this.gullet.pushTokens(tokens);
  14776. var parse = this.parseExpression(false);
  14777. this.expect("}"); // Restore the next token from the current job.
  14778. this.nextToken = oldToken;
  14779. return parse;
  14780. }
  14781. /**
  14782. * Parses an "expression", which is a list of atoms.
  14783. *
  14784. * `breakOnInfix`: Should the parsing stop when we hit infix nodes? This
  14785. * happens when functions have higher precendence han infix
  14786. * nodes in implicit parses.
  14787. *
  14788. * `breakOnTokenText`: The text of the token that the expression should end
  14789. * with, or `null` if something else should end the
  14790. * expression.
  14791. */
  14792. parseExpression(breakOnInfix, breakOnTokenText) {
  14793. var body = []; // Keep adding atoms to the body until we can't parse any more atoms (either
  14794. // we reached the end, a }, or a \right)
  14795. while (true) {
  14796. // Ignore spaces in math mode
  14797. if (this.mode === "math") {
  14798. this.consumeSpaces();
  14799. }
  14800. var lex = this.fetch();
  14801. if (Parser.endOfExpression.indexOf(lex.text) !== -1) {
  14802. break;
  14803. }
  14804. if (breakOnTokenText && lex.text === breakOnTokenText) {
  14805. break;
  14806. }
  14807. if (breakOnInfix && functions[lex.text] && functions[lex.text].infix) {
  14808. break;
  14809. }
  14810. var atom = this.parseAtom(breakOnTokenText);
  14811. if (!atom) {
  14812. break;
  14813. } else if (atom.type === "internal") {
  14814. continue;
  14815. }
  14816. body.push(atom);
  14817. }
  14818. if (this.mode === "text") {
  14819. this.formLigatures(body);
  14820. }
  14821. return this.handleInfixNodes(body);
  14822. }
  14823. /**
  14824. * Rewrites infix operators such as \over with corresponding commands such
  14825. * as \frac.
  14826. *
  14827. * There can only be one infix operator per group. If there's more than one
  14828. * then the expression is ambiguous. This can be resolved by adding {}.
  14829. */
  14830. handleInfixNodes(body) {
  14831. var overIndex = -1;
  14832. var funcName;
  14833. for (var i = 0; i < body.length; i++) {
  14834. if (body[i].type === "infix") {
  14835. if (overIndex !== -1) {
  14836. throw new ParseError("only one infix operator per group", body[i].token);
  14837. }
  14838. overIndex = i;
  14839. funcName = body[i].replaceWith;
  14840. }
  14841. }
  14842. if (overIndex !== -1 && funcName) {
  14843. var numerNode;
  14844. var denomNode;
  14845. var numerBody = body.slice(0, overIndex);
  14846. var denomBody = body.slice(overIndex + 1);
  14847. if (numerBody.length === 1 && numerBody[0].type === "ordgroup") {
  14848. numerNode = numerBody[0];
  14849. } else {
  14850. numerNode = {
  14851. type: "ordgroup",
  14852. mode: this.mode,
  14853. body: numerBody
  14854. };
  14855. }
  14856. if (denomBody.length === 1 && denomBody[0].type === "ordgroup") {
  14857. denomNode = denomBody[0];
  14858. } else {
  14859. denomNode = {
  14860. type: "ordgroup",
  14861. mode: this.mode,
  14862. body: denomBody
  14863. };
  14864. }
  14865. var node;
  14866. if (funcName === "\\\\abovefrac") {
  14867. node = this.callFunction(funcName, [numerNode, body[overIndex], denomNode], []);
  14868. } else {
  14869. node = this.callFunction(funcName, [numerNode, denomNode], []);
  14870. }
  14871. return [node];
  14872. } else {
  14873. return body;
  14874. }
  14875. }
  14876. /**
  14877. * Handle a subscript or superscript with nice errors.
  14878. */
  14879. handleSupSubscript(name // For error reporting.
  14880. ) {
  14881. var symbolToken = this.fetch();
  14882. var symbol = symbolToken.text;
  14883. this.consume();
  14884. this.consumeSpaces(); // ignore spaces before sup/subscript argument
  14885. var group = this.parseGroup(name);
  14886. if (!group) {
  14887. throw new ParseError("Expected group after '" + symbol + "'", symbolToken);
  14888. }
  14889. return group;
  14890. }
  14891. /**
  14892. * Converts the textual input of an unsupported command into a text node
  14893. * contained within a color node whose color is determined by errorColor
  14894. */
  14895. formatUnsupportedCmd(text) {
  14896. var textordArray = [];
  14897. for (var i = 0; i < text.length; i++) {
  14898. textordArray.push({
  14899. type: "textord",
  14900. mode: "text",
  14901. text: text[i]
  14902. });
  14903. }
  14904. var textNode = {
  14905. type: "text",
  14906. mode: this.mode,
  14907. body: textordArray
  14908. };
  14909. var colorNode = {
  14910. type: "color",
  14911. mode: this.mode,
  14912. color: this.settings.errorColor,
  14913. body: [textNode]
  14914. };
  14915. return colorNode;
  14916. }
  14917. /**
  14918. * Parses a group with optional super/subscripts.
  14919. */
  14920. parseAtom(breakOnTokenText) {
  14921. // The body of an atom is an implicit group, so that things like
  14922. // \left(x\right)^2 work correctly.
  14923. var base = this.parseGroup("atom", breakOnTokenText); // In text mode, we don't have superscripts or subscripts
  14924. if (this.mode === "text") {
  14925. return base;
  14926. } // Note that base may be empty (i.e. null) at this point.
  14927. var superscript;
  14928. var subscript;
  14929. while (true) {
  14930. // Guaranteed in math mode, so eat any spaces first.
  14931. this.consumeSpaces(); // Lex the first token
  14932. var lex = this.fetch();
  14933. if (lex.text === "\\limits" || lex.text === "\\nolimits") {
  14934. // We got a limit control
  14935. if (base && base.type === "op") {
  14936. var limits = lex.text === "\\limits";
  14937. base.limits = limits;
  14938. base.alwaysHandleSupSub = true;
  14939. } else if (base && base.type === "operatorname") {
  14940. if (base.alwaysHandleSupSub) {
  14941. base.limits = lex.text === "\\limits";
  14942. }
  14943. } else {
  14944. throw new ParseError("Limit controls must follow a math operator", lex);
  14945. }
  14946. this.consume();
  14947. } else if (lex.text === "^") {
  14948. // We got a superscript start
  14949. if (superscript) {
  14950. throw new ParseError("Double superscript", lex);
  14951. }
  14952. superscript = this.handleSupSubscript("superscript");
  14953. } else if (lex.text === "_") {
  14954. // We got a subscript start
  14955. if (subscript) {
  14956. throw new ParseError("Double subscript", lex);
  14957. }
  14958. subscript = this.handleSupSubscript("subscript");
  14959. } else if (lex.text === "'") {
  14960. // We got a prime
  14961. if (superscript) {
  14962. throw new ParseError("Double superscript", lex);
  14963. }
  14964. var prime = {
  14965. type: "textord",
  14966. mode: this.mode,
  14967. text: "\\prime"
  14968. }; // Many primes can be grouped together, so we handle this here
  14969. var primes = [prime];
  14970. this.consume(); // Keep lexing tokens until we get something that's not a prime
  14971. while (this.fetch().text === "'") {
  14972. // For each one, add another prime to the list
  14973. primes.push(prime);
  14974. this.consume();
  14975. } // If there's a superscript following the primes, combine that
  14976. // superscript in with the primes.
  14977. if (this.fetch().text === "^") {
  14978. primes.push(this.handleSupSubscript("superscript"));
  14979. } // Put everything into an ordgroup as the superscript
  14980. superscript = {
  14981. type: "ordgroup",
  14982. mode: this.mode,
  14983. body: primes
  14984. };
  14985. } else {
  14986. // If it wasn't ^, _, or ', stop parsing super/subscripts
  14987. break;
  14988. }
  14989. } // Base must be set if superscript or subscript are set per logic above,
  14990. // but need to check here for type check to pass.
  14991. if (superscript || subscript) {
  14992. // If we got either a superscript or subscript, create a supsub
  14993. return {
  14994. type: "supsub",
  14995. mode: this.mode,
  14996. base: base,
  14997. sup: superscript,
  14998. sub: subscript
  14999. };
  15000. } else {
  15001. // Otherwise return the original body
  15002. return base;
  15003. }
  15004. }
  15005. /**
  15006. * Parses an entire function, including its base and all of its arguments.
  15007. */
  15008. parseFunction(breakOnTokenText, name // For determining its context
  15009. ) {
  15010. var token = this.fetch();
  15011. var func = token.text;
  15012. var funcData = functions[func];
  15013. if (!funcData) {
  15014. return null;
  15015. }
  15016. this.consume(); // consume command token
  15017. if (name && name !== "atom" && !funcData.allowedInArgument) {
  15018. throw new ParseError("Got function '" + func + "' with no arguments" + (name ? " as " + name : ""), token);
  15019. } else if (this.mode === "text" && !funcData.allowedInText) {
  15020. throw new ParseError("Can't use function '" + func + "' in text mode", token);
  15021. } else if (this.mode === "math" && funcData.allowedInMath === false) {
  15022. throw new ParseError("Can't use function '" + func + "' in math mode", token);
  15023. }
  15024. var {
  15025. args,
  15026. optArgs
  15027. } = this.parseArguments(func, funcData);
  15028. return this.callFunction(func, args, optArgs, token, breakOnTokenText);
  15029. }
  15030. /**
  15031. * Call a function handler with a suitable context and arguments.
  15032. */
  15033. callFunction(name, args, optArgs, token, breakOnTokenText) {
  15034. var context = {
  15035. funcName: name,
  15036. parser: this,
  15037. token,
  15038. breakOnTokenText
  15039. };
  15040. var func = functions[name];
  15041. if (func && func.handler) {
  15042. return func.handler(context, args, optArgs);
  15043. } else {
  15044. throw new ParseError("No function handler for " + name);
  15045. }
  15046. }
  15047. /**
  15048. * Parses the arguments of a function or environment
  15049. */
  15050. parseArguments(func, // Should look like "\name" or "\begin{name}".
  15051. funcData) {
  15052. var totalArgs = funcData.numArgs + funcData.numOptionalArgs;
  15053. if (totalArgs === 0) {
  15054. return {
  15055. args: [],
  15056. optArgs: []
  15057. };
  15058. }
  15059. var args = [];
  15060. var optArgs = [];
  15061. for (var i = 0; i < totalArgs; i++) {
  15062. var argType = funcData.argTypes && funcData.argTypes[i];
  15063. var isOptional = i < funcData.numOptionalArgs;
  15064. if (funcData.primitive && argType == null || // \sqrt expands into primitive if optional argument doesn't exist
  15065. funcData.type === "sqrt" && i === 1 && optArgs[0] == null) {
  15066. argType = "primitive";
  15067. }
  15068. var arg = this.parseGroupOfType("argument to '" + func + "'", argType, isOptional);
  15069. if (isOptional) {
  15070. optArgs.push(arg);
  15071. } else if (arg != null) {
  15072. args.push(arg);
  15073. } else {
  15074. // should be unreachable
  15075. throw new ParseError("Null argument, please report this as a bug");
  15076. }
  15077. }
  15078. return {
  15079. args,
  15080. optArgs
  15081. };
  15082. }
  15083. /**
  15084. * Parses a group when the mode is changing.
  15085. */
  15086. parseGroupOfType(name, type, optional) {
  15087. switch (type) {
  15088. case "color":
  15089. return this.parseColorGroup(optional);
  15090. case "size":
  15091. return this.parseSizeGroup(optional);
  15092. case "url":
  15093. return this.parseUrlGroup(optional);
  15094. case "math":
  15095. case "text":
  15096. return this.parseArgumentGroup(optional, type);
  15097. case "hbox":
  15098. {
  15099. // hbox argument type wraps the argument in the equivalent of
  15100. // \hbox, which is like \text but switching to \textstyle size.
  15101. var group = this.parseArgumentGroup(optional, "text");
  15102. return group != null ? {
  15103. type: "styling",
  15104. mode: group.mode,
  15105. body: [group],
  15106. style: "text" // simulate \textstyle
  15107. } : null;
  15108. }
  15109. case "raw":
  15110. {
  15111. var token = this.parseStringGroup("raw", optional);
  15112. return token != null ? {
  15113. type: "raw",
  15114. mode: "text",
  15115. string: token.text
  15116. } : null;
  15117. }
  15118. case "primitive":
  15119. {
  15120. if (optional) {
  15121. throw new ParseError("A primitive argument cannot be optional");
  15122. }
  15123. var _group = this.parseGroup(name);
  15124. if (_group == null) {
  15125. throw new ParseError("Expected group as " + name, this.fetch());
  15126. }
  15127. return _group;
  15128. }
  15129. case "original":
  15130. case null:
  15131. case undefined:
  15132. return this.parseArgumentGroup(optional);
  15133. default:
  15134. throw new ParseError("Unknown group type as " + name, this.fetch());
  15135. }
  15136. }
  15137. /**
  15138. * Discard any space tokens, fetching the next non-space token.
  15139. */
  15140. consumeSpaces() {
  15141. while (this.fetch().text === " ") {
  15142. this.consume();
  15143. }
  15144. }
  15145. /**
  15146. * Parses a group, essentially returning the string formed by the
  15147. * brace-enclosed tokens plus some position information.
  15148. */
  15149. parseStringGroup(modeName, // Used to describe the mode in error messages.
  15150. optional) {
  15151. var argToken = this.gullet.scanArgument(optional);
  15152. if (argToken == null) {
  15153. return null;
  15154. }
  15155. var str = "";
  15156. var nextToken;
  15157. while ((nextToken = this.fetch()).text !== "EOF") {
  15158. str += nextToken.text;
  15159. this.consume();
  15160. }
  15161. this.consume(); // consume the end of the argument
  15162. argToken.text = str;
  15163. return argToken;
  15164. }
  15165. /**
  15166. * Parses a regex-delimited group: the largest sequence of tokens
  15167. * whose concatenated strings match `regex`. Returns the string
  15168. * formed by the tokens plus some position information.
  15169. */
  15170. parseRegexGroup(regex, modeName // Used to describe the mode in error messages.
  15171. ) {
  15172. var firstToken = this.fetch();
  15173. var lastToken = firstToken;
  15174. var str = "";
  15175. var nextToken;
  15176. while ((nextToken = this.fetch()).text !== "EOF" && regex.test(str + nextToken.text)) {
  15177. lastToken = nextToken;
  15178. str += lastToken.text;
  15179. this.consume();
  15180. }
  15181. if (str === "") {
  15182. throw new ParseError("Invalid " + modeName + ": '" + firstToken.text + "'", firstToken);
  15183. }
  15184. return firstToken.range(lastToken, str);
  15185. }
  15186. /**
  15187. * Parses a color description.
  15188. */
  15189. parseColorGroup(optional) {
  15190. var res = this.parseStringGroup("color", optional);
  15191. if (res == null) {
  15192. return null;
  15193. }
  15194. var match = /^(#[a-f0-9]{3}|#?[a-f0-9]{6}|[a-z]+)$/i.exec(res.text);
  15195. if (!match) {
  15196. throw new ParseError("Invalid color: '" + res.text + "'", res);
  15197. }
  15198. var color = match[0];
  15199. if (/^[0-9a-f]{6}$/i.test(color)) {
  15200. // We allow a 6-digit HTML color spec without a leading "#".
  15201. // This follows the xcolor package's HTML color model.
  15202. // Predefined color names are all missed by this RegEx pattern.
  15203. color = "#" + color;
  15204. }
  15205. return {
  15206. type: "color-token",
  15207. mode: this.mode,
  15208. color
  15209. };
  15210. }
  15211. /**
  15212. * Parses a size specification, consisting of magnitude and unit.
  15213. */
  15214. parseSizeGroup(optional) {
  15215. var res;
  15216. var isBlank = false; // don't expand before parseStringGroup
  15217. this.gullet.consumeSpaces();
  15218. if (!optional && this.gullet.future().text !== "{") {
  15219. res = this.parseRegexGroup(/^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2} *$/, "size");
  15220. } else {
  15221. res = this.parseStringGroup("size", optional);
  15222. }
  15223. if (!res) {
  15224. return null;
  15225. }
  15226. if (!optional && res.text.length === 0) {
  15227. // Because we've tested for what is !optional, this block won't
  15228. // affect \kern, \hspace, etc. It will capture the mandatory arguments
  15229. // to \genfrac and \above.
  15230. res.text = "0pt"; // Enable \above{}
  15231. isBlank = true; // This is here specifically for \genfrac
  15232. }
  15233. var match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(res.text);
  15234. if (!match) {
  15235. throw new ParseError("Invalid size: '" + res.text + "'", res);
  15236. }
  15237. var data = {
  15238. number: +(match[1] + match[2]),
  15239. // sign + magnitude, cast to number
  15240. unit: match[3]
  15241. };
  15242. if (!validUnit(data)) {
  15243. throw new ParseError("Invalid unit: '" + data.unit + "'", res);
  15244. }
  15245. return {
  15246. type: "size",
  15247. mode: this.mode,
  15248. value: data,
  15249. isBlank
  15250. };
  15251. }
  15252. /**
  15253. * Parses an URL, checking escaped letters and allowed protocols,
  15254. * and setting the catcode of % as an active character (as in \hyperref).
  15255. */
  15256. parseUrlGroup(optional) {
  15257. this.gullet.lexer.setCatcode("%", 13); // active character
  15258. this.gullet.lexer.setCatcode("~", 12); // other character
  15259. var res = this.parseStringGroup("url", optional);
  15260. this.gullet.lexer.setCatcode("%", 14); // comment character
  15261. this.gullet.lexer.setCatcode("~", 13); // active character
  15262. if (res == null) {
  15263. return null;
  15264. } // hyperref package allows backslashes alone in href, but doesn't
  15265. // generate valid links in such cases; we interpret this as
  15266. // "undefined" behaviour, and keep them as-is. Some browser will
  15267. // replace backslashes with forward slashes.
  15268. var url = res.text.replace(/\\([#$%&~_^{}])/g, '$1');
  15269. return {
  15270. type: "url",
  15271. mode: this.mode,
  15272. url
  15273. };
  15274. }
  15275. /**
  15276. * Parses an argument with the mode specified.
  15277. */
  15278. parseArgumentGroup(optional, mode) {
  15279. var argToken = this.gullet.scanArgument(optional);
  15280. if (argToken == null) {
  15281. return null;
  15282. }
  15283. var outerMode = this.mode;
  15284. if (mode) {
  15285. // Switch to specified mode
  15286. this.switchMode(mode);
  15287. }
  15288. this.gullet.beginGroup();
  15289. var expression = this.parseExpression(false, "EOF"); // TODO: find an alternative way to denote the end
  15290. this.expect("EOF"); // expect the end of the argument
  15291. this.gullet.endGroup();
  15292. var result = {
  15293. type: "ordgroup",
  15294. mode: this.mode,
  15295. loc: argToken.loc,
  15296. body: expression
  15297. };
  15298. if (mode) {
  15299. // Switch mode back
  15300. this.switchMode(outerMode);
  15301. }
  15302. return result;
  15303. }
  15304. /**
  15305. * Parses an ordinary group, which is either a single nucleus (like "x")
  15306. * or an expression in braces (like "{x+y}") or an implicit group, a group
  15307. * that starts at the current position, and ends right before a higher explicit
  15308. * group ends, or at EOF.
  15309. */
  15310. parseGroup(name, // For error reporting.
  15311. breakOnTokenText) {
  15312. var firstToken = this.fetch();
  15313. var text = firstToken.text;
  15314. var result; // Try to parse an open brace or \begingroup
  15315. if (text === "{" || text === "\\begingroup") {
  15316. this.consume();
  15317. var groupEnd = text === "{" ? "}" : "\\endgroup";
  15318. this.gullet.beginGroup(); // If we get a brace, parse an expression
  15319. var expression = this.parseExpression(false, groupEnd);
  15320. var lastToken = this.fetch();
  15321. this.expect(groupEnd); // Check that we got a matching closing brace
  15322. this.gullet.endGroup();
  15323. result = {
  15324. type: "ordgroup",
  15325. mode: this.mode,
  15326. loc: SourceLocation.range(firstToken, lastToken),
  15327. body: expression,
  15328. // A group formed by \begingroup...\endgroup is a semi-simple group
  15329. // which doesn't affect spacing in math mode, i.e., is transparent.
  15330. // https://tex.stackexchange.com/questions/1930/when-should-one-
  15331. // use-begingroup-instead-of-bgroup
  15332. semisimple: text === "\\begingroup" || undefined
  15333. };
  15334. } else {
  15335. // If there exists a function with this name, parse the function.
  15336. // Otherwise, just return a nucleus
  15337. result = this.parseFunction(breakOnTokenText, name) || this.parseSymbol();
  15338. if (result == null && text[0] === "\\" && !implicitCommands.hasOwnProperty(text)) {
  15339. if (this.settings.throwOnError) {
  15340. throw new ParseError("Undefined control sequence: " + text, firstToken);
  15341. }
  15342. result = this.formatUnsupportedCmd(text);
  15343. this.consume();
  15344. }
  15345. }
  15346. return result;
  15347. }
  15348. /**
  15349. * Form ligature-like combinations of characters for text mode.
  15350. * This includes inputs like "--", "---", "``" and "''".
  15351. * The result will simply replace multiple textord nodes with a single
  15352. * character in each value by a single textord node having multiple
  15353. * characters in its value. The representation is still ASCII source.
  15354. * The group will be modified in place.
  15355. */
  15356. formLigatures(group) {
  15357. var n = group.length - 1;
  15358. for (var i = 0; i < n; ++i) {
  15359. var a = group[i]; // $FlowFixMe: Not every node type has a `text` property.
  15360. var v = a.text;
  15361. if (v === "-" && group[i + 1].text === "-") {
  15362. if (i + 1 < n && group[i + 2].text === "-") {
  15363. group.splice(i, 3, {
  15364. type: "textord",
  15365. mode: "text",
  15366. loc: SourceLocation.range(a, group[i + 2]),
  15367. text: "---"
  15368. });
  15369. n -= 2;
  15370. } else {
  15371. group.splice(i, 2, {
  15372. type: "textord",
  15373. mode: "text",
  15374. loc: SourceLocation.range(a, group[i + 1]),
  15375. text: "--"
  15376. });
  15377. n -= 1;
  15378. }
  15379. }
  15380. if ((v === "'" || v === "`") && group[i + 1].text === v) {
  15381. group.splice(i, 2, {
  15382. type: "textord",
  15383. mode: "text",
  15384. loc: SourceLocation.range(a, group[i + 1]),
  15385. text: v + v
  15386. });
  15387. n -= 1;
  15388. }
  15389. }
  15390. }
  15391. /**
  15392. * Parse a single symbol out of the string. Here, we handle single character
  15393. * symbols and special functions like \verb.
  15394. */
  15395. parseSymbol() {
  15396. var nucleus = this.fetch();
  15397. var text = nucleus.text;
  15398. if (/^\\verb[^a-zA-Z]/.test(text)) {
  15399. this.consume();
  15400. var arg = text.slice(5);
  15401. var star = arg.charAt(0) === "*";
  15402. if (star) {
  15403. arg = arg.slice(1);
  15404. } // Lexer's tokenRegex is constructed to always have matching
  15405. // first/last characters.
  15406. if (arg.length < 2 || arg.charAt(0) !== arg.slice(-1)) {
  15407. throw new ParseError("\\verb assertion failed --\n please report what input caused this bug");
  15408. }
  15409. arg = arg.slice(1, -1); // remove first and last char
  15410. return {
  15411. type: "verb",
  15412. mode: "text",
  15413. body: arg,
  15414. star
  15415. };
  15416. } // At this point, we should have a symbol, possibly with accents.
  15417. // First expand any accented base symbol according to unicodeSymbols.
  15418. if (unicodeSymbols.hasOwnProperty(text[0]) && !symbols[this.mode][text[0]]) {
  15419. // This behavior is not strict (XeTeX-compatible) in math mode.
  15420. if (this.settings.strict && this.mode === "math") {
  15421. this.settings.reportNonstrict("unicodeTextInMathMode", "Accented Unicode text character \"" + text[0] + "\" used in " + "math mode", nucleus);
  15422. }
  15423. text = unicodeSymbols[text[0]] + text.substr(1);
  15424. } // Strip off any combining characters
  15425. var match = combiningDiacriticalMarksEndRegex.exec(text);
  15426. if (match) {
  15427. text = text.substring(0, match.index);
  15428. if (text === 'i') {
  15429. text = '\u0131'; // dotless i, in math and text mode
  15430. } else if (text === 'j') {
  15431. text = '\u0237'; // dotless j, in math and text mode
  15432. }
  15433. } // Recognize base symbol
  15434. var symbol;
  15435. if (symbols[this.mode][text]) {
  15436. if (this.settings.strict && this.mode === 'math' && extraLatin.indexOf(text) >= 0) {
  15437. this.settings.reportNonstrict("unicodeTextInMathMode", "Latin-1/Unicode text character \"" + text[0] + "\" used in " + "math mode", nucleus);
  15438. }
  15439. var group = symbols[this.mode][text].group;
  15440. var loc = SourceLocation.range(nucleus);
  15441. var s;
  15442. if (ATOMS.hasOwnProperty(group)) {
  15443. // $FlowFixMe
  15444. var family = group;
  15445. s = {
  15446. type: "atom",
  15447. mode: this.mode,
  15448. family,
  15449. loc,
  15450. text
  15451. };
  15452. } else {
  15453. // $FlowFixMe
  15454. s = {
  15455. type: group,
  15456. mode: this.mode,
  15457. loc,
  15458. text
  15459. };
  15460. } // $FlowFixMe
  15461. symbol = s;
  15462. } else if (text.charCodeAt(0) >= 0x80) {
  15463. // no symbol for e.g. ^
  15464. if (this.settings.strict) {
  15465. if (!supportedCodepoint(text.charCodeAt(0))) {
  15466. this.settings.reportNonstrict("unknownSymbol", "Unrecognized Unicode character \"" + text[0] + "\"" + (" (" + text.charCodeAt(0) + ")"), nucleus);
  15467. } else if (this.mode === "math") {
  15468. this.settings.reportNonstrict("unicodeTextInMathMode", "Unicode text character \"" + text[0] + "\" used in math mode", nucleus);
  15469. }
  15470. } // All nonmathematical Unicode characters are rendered as if they
  15471. // are in text mode (wrapped in \text) because that's what it
  15472. // takes to render them in LaTeX. Setting `mode: this.mode` is
  15473. // another natural choice (the user requested math mode), but
  15474. // this makes it more difficult for getCharacterMetrics() to
  15475. // distinguish Unicode characters without metrics and those for
  15476. // which we want to simulate the letter M.
  15477. symbol = {
  15478. type: "textord",
  15479. mode: "text",
  15480. loc: SourceLocation.range(nucleus),
  15481. text
  15482. };
  15483. } else {
  15484. return null; // EOF, ^, _, {, }, etc.
  15485. }
  15486. this.consume(); // Transform combining characters into accents
  15487. if (match) {
  15488. for (var i = 0; i < match[0].length; i++) {
  15489. var accent = match[0][i];
  15490. if (!unicodeAccents[accent]) {
  15491. throw new ParseError("Unknown accent ' " + accent + "'", nucleus);
  15492. }
  15493. var command = unicodeAccents[accent][this.mode] || unicodeAccents[accent].text;
  15494. if (!command) {
  15495. throw new ParseError("Accent " + accent + " unsupported in " + this.mode + " mode", nucleus);
  15496. }
  15497. symbol = {
  15498. type: "accent",
  15499. mode: this.mode,
  15500. loc: SourceLocation.range(nucleus),
  15501. label: command,
  15502. isStretchy: false,
  15503. isShifty: true,
  15504. // $FlowFixMe
  15505. base: symbol
  15506. };
  15507. }
  15508. } // $FlowFixMe
  15509. return symbol;
  15510. }
  15511. }
  15512. Parser.endOfExpression = ["}", "\\endgroup", "\\end", "\\right", "&"];
  15513. /**
  15514. * Provides a single function for parsing an expression using a Parser
  15515. * TODO(emily): Remove this
  15516. */
  15517. /**
  15518. * Parses an expression using a Parser, then returns the parsed result.
  15519. */
  15520. var parseTree = function parseTree(toParse, settings) {
  15521. if (!(typeof toParse === 'string' || toParse instanceof String)) {
  15522. throw new TypeError('KaTeX can only parse string typed expression');
  15523. }
  15524. var parser = new Parser(toParse, settings); // Blank out any \df@tag to avoid spurious "Duplicate \tag" errors
  15525. delete parser.gullet.macros.current["\\df@tag"];
  15526. var tree = parser.parse(); // Prevent a color definition from persisting between calls to katex.render().
  15527. delete parser.gullet.macros.current["\\current@color"];
  15528. delete parser.gullet.macros.current["\\color"]; // If the input used \tag, it will set the \df@tag macro to the tag.
  15529. // In this case, we separately parse the tag and wrap the tree.
  15530. if (parser.gullet.macros.get("\\df@tag")) {
  15531. if (!settings.displayMode) {
  15532. throw new ParseError("\\tag works only in display equations");
  15533. }
  15534. tree = [{
  15535. type: "tag",
  15536. mode: "text",
  15537. body: tree,
  15538. tag: parser.subparse([new Token("\\df@tag")])
  15539. }];
  15540. }
  15541. return tree;
  15542. };
  15543. /* eslint no-console:0 */
  15544. /**
  15545. * Parse and build an expression, and place that expression in the DOM node
  15546. * given.
  15547. */
  15548. var render = function render(expression, baseNode, options) {
  15549. baseNode.textContent = "";
  15550. var node = renderToDomTree(expression, options).toNode();
  15551. baseNode.appendChild(node);
  15552. }; // KaTeX's styles don't work properly in quirks mode. Print out an error, and
  15553. // disable rendering.
  15554. if (typeof document !== "undefined") {
  15555. if (document.compatMode !== "CSS1Compat") {
  15556. typeof console !== "undefined" && console.warn("Warning: KaTeX doesn't work in quirks mode. Make sure your " + "website has a suitable doctype.");
  15557. render = function render() {
  15558. throw new ParseError("KaTeX doesn't work in quirks mode.");
  15559. };
  15560. }
  15561. }
  15562. /**
  15563. * Parse and build an expression, and return the markup for that.
  15564. */
  15565. var renderToString = function renderToString(expression, options) {
  15566. var markup = renderToDomTree(expression, options).toMarkup();
  15567. return markup;
  15568. };
  15569. /**
  15570. * Parse an expression and return the parse tree.
  15571. */
  15572. var generateParseTree = function generateParseTree(expression, options) {
  15573. var settings = new Settings(options);
  15574. return parseTree(expression, settings);
  15575. };
  15576. /**
  15577. * If the given error is a KaTeX ParseError and options.throwOnError is false,
  15578. * renders the invalid LaTeX as a span with hover title giving the KaTeX
  15579. * error message. Otherwise, simply throws the error.
  15580. */
  15581. var renderError = function renderError(error, expression, options) {
  15582. if (options.throwOnError || !(error instanceof ParseError)) {
  15583. throw error;
  15584. }
  15585. var node = buildCommon.makeSpan(["katex-error"], [new SymbolNode(expression)]);
  15586. node.setAttribute("title", error.toString());
  15587. node.setAttribute("style", "color:" + options.errorColor);
  15588. return node;
  15589. };
  15590. /**
  15591. * Generates and returns the katex build tree. This is used for advanced
  15592. * use cases (like rendering to custom output).
  15593. */
  15594. var renderToDomTree = function renderToDomTree(expression, options) {
  15595. var settings = new Settings(options);
  15596. try {
  15597. var tree = parseTree(expression, settings);
  15598. return buildTree(tree, expression, settings);
  15599. } catch (error) {
  15600. return renderError(error, expression, settings);
  15601. }
  15602. };
  15603. /**
  15604. * Generates and returns the katex build tree, with just HTML (no MathML).
  15605. * This is used for advanced use cases (like rendering to custom output).
  15606. */
  15607. var renderToHTMLTree = function renderToHTMLTree(expression, options) {
  15608. var settings = new Settings(options);
  15609. try {
  15610. var tree = parseTree(expression, settings);
  15611. return buildHTMLTree(tree, expression, settings);
  15612. } catch (error) {
  15613. return renderError(error, expression, settings);
  15614. }
  15615. };
  15616. var katex = {
  15617. /**
  15618. * Current KaTeX version
  15619. */
  15620. version: "0.15.3",
  15621. /**
  15622. * Renders the given LaTeX into an HTML+MathML combination, and adds
  15623. * it as a child to the specified DOM node.
  15624. */
  15625. render,
  15626. /**
  15627. * Renders the given LaTeX into an HTML+MathML combination string,
  15628. * for sending to the client.
  15629. */
  15630. renderToString,
  15631. /**
  15632. * KaTeX error, usually during parsing.
  15633. */
  15634. ParseError,
  15635. /**
  15636. * The shema of Settings
  15637. */
  15638. SETTINGS_SCHEMA,
  15639. /**
  15640. * Parses the given LaTeX into KaTeX's internal parse tree structure,
  15641. * without rendering to HTML or MathML.
  15642. *
  15643. * NOTE: This method is not currently recommended for public use.
  15644. * The internal tree representation is unstable and is very likely
  15645. * to change. Use at your own risk.
  15646. */
  15647. __parse: generateParseTree,
  15648. /**
  15649. * Renders the given LaTeX into an HTML+MathML internal DOM tree
  15650. * representation, without flattening that representation to a string.
  15651. *
  15652. * NOTE: This method is not currently recommended for public use.
  15653. * The internal tree representation is unstable and is very likely
  15654. * to change. Use at your own risk.
  15655. */
  15656. __renderToDomTree: renderToDomTree,
  15657. /**
  15658. * Renders the given LaTeX into an HTML internal DOM tree representation,
  15659. * without MathML and without flattening that representation to a string.
  15660. *
  15661. * NOTE: This method is not currently recommended for public use.
  15662. * The internal tree representation is unstable and is very likely
  15663. * to change. Use at your own risk.
  15664. */
  15665. __renderToHTMLTree: renderToHTMLTree,
  15666. /**
  15667. * extends internal font metrics object with a new object
  15668. * each key in the new object represents a font name
  15669. */
  15670. __setFontMetrics: setFontMetrics,
  15671. /**
  15672. * adds a new symbol to builtin symbols table
  15673. */
  15674. __defineSymbol: defineSymbol,
  15675. /**
  15676. * adds a new macro to builtin macro list
  15677. */
  15678. __defineMacro: defineMacro,
  15679. /**
  15680. * Expose the dom tree node types, which can be useful for type checking nodes.
  15681. *
  15682. * NOTE: This method is not currently recommended for public use.
  15683. * The internal tree representation is unstable and is very likely
  15684. * to change. Use at your own risk.
  15685. */
  15686. __domTree: {
  15687. Span,
  15688. Anchor,
  15689. SymbolNode,
  15690. SvgNode,
  15691. PathNode,
  15692. LineNode
  15693. }
  15694. };
  15695. export { katex as default };