AmsMappings.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /*************************************************************
  2. *
  3. * Copyright (c) 2017-2022 The MathJax Consortium
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @fileoverview Mappings for TeX parsing of the AMS math package.
  19. *
  20. * @author v.sorge@mathjax.org (Volker Sorge)
  21. */
  22. import {AmsMethods} from './AmsMethods.js';
  23. import * as sm from '../SymbolMap.js';
  24. import {TexConstant} from '../TexConstants.js';
  25. import ParseMethods from '../ParseMethods.js';
  26. import ParseUtil from '../ParseUtil.js';
  27. import {TEXCLASS} from '../../../core/MmlTree/MmlNode.js';
  28. import {MATHSPACE} from '../../../util/lengths.js';
  29. /**
  30. * Operators from the AMS Math package.
  31. */
  32. new sm.CharacterMap('AMSmath-mathchar0mo', ParseMethods.mathchar0mo, {
  33. iiiint: ['\u2A0C', {texClass: TEXCLASS.OP}]
  34. });
  35. /**
  36. * Extra characters that are letters in \operatorname
  37. */
  38. new sm.RegExpMap('AMSmath-operatorLetter', AmsMethods.operatorLetter, /[-*]/i);
  39. /**
  40. * Macros from the AMS Math package.
  41. */
  42. new sm.CommandMap('AMSmath-macros', {
  43. mathring: ['Accent', '02DA'], // or 0x30A
  44. nobreakspace: 'Tilde',
  45. negmedspace: ['Spacer', MATHSPACE.negativemediummathspace],
  46. negthickspace: ['Spacer', MATHSPACE.negativethickmathspace],
  47. idotsint: ['MultiIntegral', '\\int\\cdots\\int'],
  48. dddot: ['Accent', '20DB'],
  49. ddddot: ['Accent', '20DC'],
  50. sideset: 'SideSet',
  51. boxed: ['Macro', '\\fbox{$\\displaystyle{#1}$}', 1],
  52. tag: 'HandleTag',
  53. notag: 'HandleNoTag',
  54. eqref: ['HandleRef', true],
  55. substack: ['Macro', '\\begin{subarray}{c}#1\\end{subarray}', 1],
  56. injlim: ['NamedOp', 'inj lim'],
  57. projlim: ['NamedOp', 'proj lim'],
  58. varliminf: ['Macro', '\\mathop{\\underline{\\mmlToken{mi}{lim}}}'],
  59. varlimsup: ['Macro', '\\mathop{\\overline{\\mmlToken{mi}{lim}}}'],
  60. varinjlim: ['Macro', '\\mathop{\\underrightarrow{\\mmlToken{mi}{lim}}}'],
  61. varprojlim: ['Macro', '\\mathop{\\underleftarrow{\\mmlToken{mi}{lim}}}'],
  62. DeclareMathOperator: 'HandleDeclareOp',
  63. operatorname: 'HandleOperatorName',
  64. genfrac: 'Genfrac',
  65. frac: ['Genfrac', '', '', '', ''],
  66. tfrac: ['Genfrac', '', '', '', '1'],
  67. dfrac: ['Genfrac', '', '', '', '0'],
  68. binom: ['Genfrac', '(', ')', '0', ''],
  69. tbinom: ['Genfrac', '(', ')', '0', '1'],
  70. dbinom: ['Genfrac', '(', ')', '0', '0'],
  71. cfrac: 'CFrac',
  72. shoveleft: ['HandleShove', TexConstant.Align.LEFT],
  73. shoveright: ['HandleShove', TexConstant.Align.RIGHT],
  74. xrightarrow: ['xArrow', 0x2192, 5, 10],
  75. xleftarrow: ['xArrow', 0x2190, 10, 5]
  76. }, AmsMethods);
  77. /**
  78. * Environments from the AMS Math package.
  79. */
  80. new sm.EnvironmentMap('AMSmath-environment', ParseMethods.environment, {
  81. 'equation*': ['Equation', null, false],
  82. 'eqnarray*': ['EqnArray', null, false, true, 'rcl',
  83. ParseUtil.cols(0, MATHSPACE.thickmathspace), '.5em'],
  84. align: ['EqnArray', null, true, true, 'rl', ParseUtil.cols(0, 2)],
  85. 'align*': ['EqnArray', null, false, true, 'rl', ParseUtil.cols(0, 2)],
  86. multline: ['Multline', null, true],
  87. 'multline*': ['Multline', null, false],
  88. split: ['EqnArray', null, false, false, 'rl', ParseUtil.cols(0)],
  89. gather: ['EqnArray', null, true, true, 'c'],
  90. 'gather*': ['EqnArray', null, false, true, 'c'],
  91. alignat: ['AlignAt', null, true, true],
  92. 'alignat*': ['AlignAt', null, false, true],
  93. alignedat: ['AlignAt', null, false, false],
  94. aligned: ['AmsEqnArray', null, null, null, 'rl', ParseUtil.cols(0, 2), '.5em', 'D'],
  95. gathered: ['AmsEqnArray', null, null, null, 'c', null, '.5em', 'D'],
  96. xalignat: ['XalignAt', null, true, true],
  97. 'xalignat*': ['XalignAt', null, false, true],
  98. xxalignat: ['XalignAt', null, false, false],
  99. flalign: ['FlalignArray', null, true, false, true, 'rlc', 'auto auto fit'],
  100. 'flalign*': ['FlalignArray', null, false, false, true, 'rlc', 'auto auto fit'],
  101. subarray: ['Array', null, null, null, null, ParseUtil.cols(0), '0.1em', 'S', 1],
  102. smallmatrix: ['Array', null, null, null, 'c', ParseUtil.cols(1 / 3),
  103. '.2em', 'S', 1],
  104. matrix: ['Array', null, null, null, 'c'],
  105. pmatrix: ['Array', null, '(', ')', 'c'],
  106. bmatrix: ['Array', null, '[', ']', 'c'],
  107. Bmatrix: ['Array', null, '\\{', '\\}', 'c'],
  108. vmatrix: ['Array', null, '\\vert', '\\vert', 'c'],
  109. Vmatrix: ['Array', null, '\\Vert', '\\Vert', 'c'],
  110. cases: ['Array', null, '\\{', '.', 'll', null, '.2em', 'T']
  111. }, AmsMethods);
  112. /**
  113. * Delimiters from the AMS Math package.
  114. */
  115. new sm.DelimiterMap('AMSmath-delimiter', ParseMethods.delimiter, {
  116. '\\lvert': ['\u007C', {texClass: TEXCLASS.OPEN}],
  117. '\\rvert': ['\u007C', {texClass: TEXCLASS.CLOSE}],
  118. '\\lVert': ['\u2016', {texClass: TEXCLASS.OPEN}],
  119. '\\rVert': ['\u2016', {texClass: TEXCLASS.CLOSE}]
  120. });
  121. /**
  122. * Identifiers from the AMS Symbols package.
  123. */
  124. new sm.CharacterMap('AMSsymbols-mathchar0mi', ParseMethods.mathchar0mi, {
  125. // Lowercase Greek letters
  126. digamma: '\u03DD',
  127. varkappa: '\u03F0',
  128. // Uppercase Greek letters
  129. varGamma: ['\u0393', {mathvariant: TexConstant.Variant.ITALIC}],
  130. varDelta: ['\u0394', {mathvariant: TexConstant.Variant.ITALIC}],
  131. varTheta: ['\u0398', {mathvariant: TexConstant.Variant.ITALIC}],
  132. varLambda: ['\u039B', {mathvariant: TexConstant.Variant.ITALIC}],
  133. varXi: ['\u039E', {mathvariant: TexConstant.Variant.ITALIC}],
  134. varPi: ['\u03A0', {mathvariant: TexConstant.Variant.ITALIC}],
  135. varSigma: ['\u03A3', {mathvariant: TexConstant.Variant.ITALIC}],
  136. varUpsilon: ['\u03A5', {mathvariant: TexConstant.Variant.ITALIC}],
  137. varPhi: ['\u03A6', {mathvariant: TexConstant.Variant.ITALIC}],
  138. varPsi: ['\u03A8', {mathvariant: TexConstant.Variant.ITALIC}],
  139. varOmega: ['\u03A9', {mathvariant: TexConstant.Variant.ITALIC}],
  140. // Hebrew letters
  141. beth: '\u2136',
  142. gimel: '\u2137',
  143. daleth: '\u2138',
  144. // Miscellaneous symbols
  145. // hbar: '\u0127', // in TeX/jax.js
  146. backprime: ['\u2035', {variantForm: true}],
  147. hslash: '\u210F',
  148. varnothing: ['\u2205', {variantForm: true}],
  149. blacktriangle: '\u25B4',
  150. triangledown: ['\u25BD', {variantForm: true}],
  151. blacktriangledown: '\u25BE',
  152. square: '\u25FB',
  153. Box: '\u25FB',
  154. blacksquare: '\u25FC',
  155. lozenge: '\u25CA',
  156. Diamond: '\u25CA',
  157. blacklozenge: '\u29EB',
  158. circledS: ['\u24C8', {mathvariant: TexConstant.Variant.NORMAL}],
  159. bigstar: '\u2605',
  160. // angle: '\u2220', // in TeX/jax.js
  161. sphericalangle: '\u2222',
  162. measuredangle: '\u2221',
  163. nexists: '\u2204',
  164. complement: '\u2201',
  165. mho: '\u2127',
  166. eth: ['\u00F0', {mathvariant: TexConstant.Variant.NORMAL}],
  167. Finv: '\u2132',
  168. diagup: '\u2571',
  169. Game: '\u2141',
  170. diagdown: '\u2572',
  171. Bbbk: ['\u006B',
  172. {mathvariant: TexConstant.Variant.DOUBLESTRUCK}],
  173. yen: '\u00A5',
  174. circledR: '\u00AE',
  175. checkmark: '\u2713',
  176. maltese: '\u2720'
  177. });
  178. /**
  179. * Operators from the AMS Symbols package.
  180. */
  181. new sm.CharacterMap('AMSsymbols-mathchar0mo', ParseMethods.mathchar0mo, {
  182. // Binary operators
  183. dotplus: '\u2214',
  184. ltimes: '\u22C9',
  185. smallsetminus: ['\u2216', {variantForm: true}],
  186. rtimes: '\u22CA',
  187. Cap: '\u22D2',
  188. doublecap: '\u22D2',
  189. leftthreetimes: '\u22CB',
  190. Cup: '\u22D3',
  191. doublecup: '\u22D3',
  192. rightthreetimes: '\u22CC',
  193. barwedge: '\u22BC',
  194. curlywedge: '\u22CF',
  195. veebar: '\u22BB',
  196. curlyvee: '\u22CE',
  197. doublebarwedge: '\u2A5E',
  198. boxminus: '\u229F',
  199. circleddash: '\u229D',
  200. boxtimes: '\u22A0',
  201. circledast: '\u229B',
  202. boxdot: '\u22A1',
  203. circledcirc: '\u229A',
  204. boxplus: '\u229E',
  205. centerdot: ['\u22C5', {variantForm: true}],
  206. divideontimes: '\u22C7',
  207. intercal: '\u22BA',
  208. // Binary relations
  209. leqq: '\u2266',
  210. geqq: '\u2267',
  211. leqslant: '\u2A7D',
  212. geqslant: '\u2A7E',
  213. eqslantless: '\u2A95',
  214. eqslantgtr: '\u2A96',
  215. lesssim: '\u2272',
  216. gtrsim: '\u2273',
  217. lessapprox: '\u2A85',
  218. gtrapprox: '\u2A86',
  219. approxeq: '\u224A',
  220. lessdot: '\u22D6',
  221. gtrdot: '\u22D7',
  222. lll: '\u22D8',
  223. llless: '\u22D8',
  224. ggg: '\u22D9',
  225. gggtr: '\u22D9',
  226. lessgtr: '\u2276',
  227. gtrless: '\u2277',
  228. lesseqgtr: '\u22DA',
  229. gtreqless: '\u22DB',
  230. lesseqqgtr: '\u2A8B',
  231. gtreqqless: '\u2A8C',
  232. doteqdot: '\u2251',
  233. Doteq: '\u2251',
  234. eqcirc: '\u2256',
  235. risingdotseq: '\u2253',
  236. circeq: '\u2257',
  237. fallingdotseq: '\u2252',
  238. triangleq: '\u225C',
  239. backsim: '\u223D',
  240. thicksim: ['\u223C', {variantForm: true}],
  241. backsimeq: '\u22CD',
  242. thickapprox: ['\u2248', {variantForm: true}],
  243. subseteqq: '\u2AC5',
  244. supseteqq: '\u2AC6',
  245. Subset: '\u22D0',
  246. Supset: '\u22D1',
  247. sqsubset: '\u228F',
  248. sqsupset: '\u2290',
  249. preccurlyeq: '\u227C',
  250. succcurlyeq: '\u227D',
  251. curlyeqprec: '\u22DE',
  252. curlyeqsucc: '\u22DF',
  253. precsim: '\u227E',
  254. succsim: '\u227F',
  255. precapprox: '\u2AB7',
  256. succapprox: '\u2AB8',
  257. vartriangleleft: '\u22B2',
  258. lhd: '\u22B2',
  259. vartriangleright: '\u22B3',
  260. rhd: '\u22B3',
  261. trianglelefteq: '\u22B4',
  262. unlhd: '\u22B4',
  263. trianglerighteq: '\u22B5',
  264. unrhd: '\u22B5',
  265. vDash: ['\u22A8', {variantForm: true}],
  266. Vdash: '\u22A9',
  267. Vvdash: '\u22AA',
  268. smallsmile: ['\u2323', {variantForm: true}],
  269. shortmid: ['\u2223', {variantForm: true}],
  270. smallfrown: ['\u2322', {variantForm: true}],
  271. shortparallel: ['\u2225', {variantForm: true}],
  272. bumpeq: '\u224F',
  273. between: '\u226C',
  274. Bumpeq: '\u224E',
  275. pitchfork: '\u22D4',
  276. varpropto: ['\u221D', {variantForm: true}],
  277. backepsilon: '\u220D',
  278. blacktriangleleft: '\u25C2',
  279. blacktriangleright: '\u25B8',
  280. therefore: '\u2234',
  281. because: '\u2235',
  282. eqsim: '\u2242',
  283. vartriangle: ['\u25B3', {variantForm: true}],
  284. Join: '\u22C8',
  285. // Negated relations
  286. nless: '\u226E',
  287. ngtr: '\u226F',
  288. nleq: '\u2270',
  289. ngeq: '\u2271',
  290. nleqslant: ['\u2A87', {variantForm: true}],
  291. ngeqslant: ['\u2A88', {variantForm: true}],
  292. nleqq: ['\u2270', {variantForm: true}],
  293. ngeqq: ['\u2271', {variantForm: true}],
  294. lneq: '\u2A87',
  295. gneq: '\u2A88',
  296. lneqq: '\u2268',
  297. gneqq: '\u2269',
  298. lvertneqq: ['\u2268', {variantForm: true}],
  299. gvertneqq: ['\u2269', {variantForm: true}],
  300. lnsim: '\u22E6',
  301. gnsim: '\u22E7',
  302. lnapprox: '\u2A89',
  303. gnapprox: '\u2A8A',
  304. nprec: '\u2280',
  305. nsucc: '\u2281',
  306. npreceq: ['\u22E0', {variantForm: true}],
  307. nsucceq: ['\u22E1', {variantForm: true}],
  308. precneqq: '\u2AB5',
  309. succneqq: '\u2AB6',
  310. precnsim: '\u22E8',
  311. succnsim: '\u22E9',
  312. precnapprox: '\u2AB9',
  313. succnapprox: '\u2ABA',
  314. nsim: '\u2241',
  315. ncong: '\u2247',
  316. nshortmid: ['\u2224', {variantForm: true}],
  317. nshortparallel: ['\u2226', {variantForm: true}],
  318. nmid: '\u2224',
  319. nparallel: '\u2226',
  320. nvdash: '\u22AC',
  321. nvDash: '\u22AD',
  322. nVdash: '\u22AE',
  323. nVDash: '\u22AF',
  324. ntriangleleft: '\u22EA',
  325. ntriangleright: '\u22EB',
  326. ntrianglelefteq: '\u22EC',
  327. ntrianglerighteq: '\u22ED',
  328. nsubseteq: '\u2288',
  329. nsupseteq: '\u2289',
  330. nsubseteqq: ['\u2288', {variantForm: true}],
  331. nsupseteqq: ['\u2289', {variantForm: true}],
  332. subsetneq: '\u228A',
  333. supsetneq: '\u228B',
  334. varsubsetneq: ['\u228A', {variantForm: true}],
  335. varsupsetneq: ['\u228B', {variantForm: true}],
  336. subsetneqq: '\u2ACB',
  337. supsetneqq: '\u2ACC',
  338. varsubsetneqq: ['\u2ACB', {variantForm: true}],
  339. varsupsetneqq: ['\u2ACC', {variantForm: true}],
  340. // Arrows
  341. leftleftarrows: '\u21C7',
  342. rightrightarrows: '\u21C9',
  343. leftrightarrows: '\u21C6',
  344. rightleftarrows: '\u21C4',
  345. Lleftarrow: '\u21DA',
  346. Rrightarrow: '\u21DB',
  347. twoheadleftarrow: '\u219E',
  348. twoheadrightarrow: '\u21A0',
  349. leftarrowtail: '\u21A2',
  350. rightarrowtail: '\u21A3',
  351. looparrowleft: '\u21AB',
  352. looparrowright: '\u21AC',
  353. leftrightharpoons: '\u21CB',
  354. rightleftharpoons: ['\u21CC', {variantForm: true}],
  355. curvearrowleft: '\u21B6',
  356. curvearrowright: '\u21B7',
  357. circlearrowleft: '\u21BA',
  358. circlearrowright: '\u21BB',
  359. Lsh: '\u21B0',
  360. Rsh: '\u21B1',
  361. upuparrows: '\u21C8',
  362. downdownarrows: '\u21CA',
  363. upharpoonleft: '\u21BF',
  364. upharpoonright: '\u21BE',
  365. downharpoonleft: '\u21C3',
  366. restriction: '\u21BE',
  367. multimap: '\u22B8',
  368. downharpoonright: '\u21C2',
  369. leftrightsquigarrow: '\u21AD',
  370. rightsquigarrow: '\u21DD',
  371. leadsto: '\u21DD',
  372. dashrightarrow: '\u21E2',
  373. dashleftarrow: '\u21E0',
  374. // Negated arrows
  375. nleftarrow: '\u219A',
  376. nrightarrow: '\u219B',
  377. nLeftarrow: '\u21CD',
  378. nRightarrow: '\u21CF',
  379. nleftrightarrow: '\u21AE',
  380. nLeftrightarrow: '\u21CE'
  381. });
  382. /**
  383. * Delimiters from the AMS Symbols package.
  384. */
  385. new sm.DelimiterMap('AMSsymbols-delimiter', ParseMethods.delimiter, {
  386. // corners
  387. '\\ulcorner': '\u231C',
  388. '\\urcorner': '\u231D',
  389. '\\llcorner': '\u231E',
  390. '\\lrcorner': '\u231F'
  391. });
  392. /**
  393. * Macros from the AMS Symbols package.
  394. */
  395. new sm.CommandMap('AMSsymbols-macros', {
  396. implies: ['Macro', '\\;\\Longrightarrow\\;'],
  397. impliedby: ['Macro', '\\;\\Longleftarrow\\;']
  398. }, AmsMethods);