PhysicsMappings.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*************************************************************
  2. *
  3. * Copyright (c) 2018-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 physics package.
  19. *
  20. * @author v.sorge@mathjax.org (Volker Sorge)
  21. */
  22. import {EnvironmentMap, CommandMap, MacroMap, CharacterMap} from '../SymbolMap.js';
  23. import PhysicsMethods from './PhysicsMethods.js';
  24. import {TexConstant} from '../TexConstants.js';
  25. import ParseMethods from '../ParseMethods.js';
  26. import {TEXCLASS} from '../../../core/MmlTree/MmlNode.js';
  27. /**
  28. * Macros for physics package (section 2.1).
  29. */
  30. new CommandMap('Physics-automatic-bracing-macros', {
  31. 'quantity': 'Quantity',
  32. 'qty': 'Quantity',
  33. 'pqty': ['Quantity', '(', ')', true],
  34. 'bqty': ['Quantity', '[', ']', true],
  35. 'vqty': ['Quantity', '|', '|', true],
  36. 'Bqty': ['Quantity', '\\{', '\\}', true],
  37. 'absolutevalue': ['Quantity', '|', '|', true],
  38. 'abs': ['Quantity', '|', '|', true],
  39. 'norm': ['Quantity', '\\|', '\\|', true],
  40. 'evaluated': 'Eval',
  41. 'eval': 'Eval',
  42. 'order': ['Quantity', '(', ')', true, 'O',
  43. TexConstant.Variant.CALLIGRAPHIC],
  44. 'commutator': 'Commutator',
  45. 'comm': 'Commutator',
  46. 'anticommutator': ['Commutator', '\\{', '\\}'],
  47. 'acomm': ['Commutator', '\\{', '\\}'],
  48. 'poissonbracket': ['Commutator', '\\{', '\\}'],
  49. 'pb': ['Commutator', '\\{', '\\}']
  50. }, PhysicsMethods);
  51. /**
  52. * Macros for physics package (section 2.2).
  53. */
  54. new CharacterMap('Physics-vector-mo', ParseMethods.mathchar0mo, {
  55. dotproduct: ['\u22C5', {mathvariant: TexConstant.Variant.BOLD}],
  56. vdot: ['\u22C5', {mathvariant: TexConstant.Variant.BOLD}],
  57. crossproduct: '\u00D7',
  58. cross: '\u00D7',
  59. cp: '\u00D7',
  60. // This is auxiliary!
  61. gradientnabla: ['\u2207', {mathvariant: TexConstant.Variant.BOLD}]
  62. });
  63. new CharacterMap('Physics-vector-mi', ParseMethods.mathchar0mi, {
  64. real: ['\u211C', {mathvariant: TexConstant.Variant.NORMAL}],
  65. imaginary: ['\u2111', {mathvariant: TexConstant.Variant.NORMAL}]
  66. });
  67. new CommandMap('Physics-vector-macros', {
  68. 'vnabla': 'Vnabla',
  69. 'vectorbold': 'VectorBold',
  70. 'vb': 'VectorBold',
  71. 'vectorarrow': ['StarMacro', 1, '\\vec{\\vb', '{#1}}'],
  72. 'va': ['StarMacro', 1, '\\vec{\\vb', '{#1}}'],
  73. 'vectorunit': ['StarMacro', 1, '\\hat{\\vb', '{#1}}'],
  74. 'vu': ['StarMacro', 1, '\\hat{\\vb', '{#1}}'],
  75. 'gradient': ['OperatorApplication', '\\vnabla', '(', '['],
  76. 'grad': ['OperatorApplication', '\\vnabla', '(', '['],
  77. 'divergence': ['VectorOperator', '\\vnabla\\vdot', '(', '['],
  78. 'div': ['VectorOperator', '\\vnabla\\vdot', '(', '['],
  79. 'curl': ['VectorOperator', '\\vnabla\\crossproduct', '(', '['],
  80. 'laplacian': ['OperatorApplication', '\\nabla^2', '(', '['],
  81. }, PhysicsMethods);
  82. /**
  83. * Macros for physics package (section 2.3).
  84. */
  85. new CommandMap('Physics-expressions-macros', {
  86. 'sin': 'Expression',
  87. 'sinh': 'Expression',
  88. 'arcsin': 'Expression',
  89. 'asin': 'Expression',
  90. 'cos': 'Expression',
  91. 'cosh': 'Expression',
  92. 'arccos': 'Expression',
  93. 'acos': 'Expression',
  94. 'tan': 'Expression',
  95. 'tanh': 'Expression',
  96. 'arctan': 'Expression',
  97. 'atan': 'Expression',
  98. 'csc': 'Expression',
  99. 'csch': 'Expression',
  100. 'arccsc': 'Expression',
  101. 'acsc': 'Expression',
  102. 'sec': 'Expression',
  103. 'sech': 'Expression',
  104. 'arcsec': 'Expression',
  105. 'asec': 'Expression',
  106. 'cot': 'Expression',
  107. 'coth': 'Expression',
  108. 'arccot': 'Expression',
  109. 'acot': 'Expression',
  110. 'exp': ['Expression', false],
  111. 'log': 'Expression',
  112. 'ln': 'Expression',
  113. 'det': ['Expression', false],
  114. 'Pr': ['Expression', false],
  115. // New expressions.
  116. 'tr': ['Expression', false],
  117. 'trace': ['Expression', false, 'tr'],
  118. 'Tr': ['Expression', false],
  119. 'Trace': ['Expression', false, 'Tr'],
  120. 'rank': 'NamedFn',
  121. 'erf': ['Expression', false],
  122. 'Residue': ['Macro', '\\mathrm{Res}'],
  123. 'Res': ['OperatorApplication', '\\Residue', '(', '[', '{'],
  124. 'principalvalue': ['OperatorApplication', '{\\cal P}'],
  125. 'pv': ['OperatorApplication', '{\\cal P}'],
  126. 'PV': ['OperatorApplication', '{\\rm P.V.}'],
  127. 'Re': ['OperatorApplication', '\\mathrm{Re}', '{'],
  128. 'Im': ['OperatorApplication', '\\mathrm{Im}', '{'],
  129. // Old named functions.
  130. 'sine': ['NamedFn', 'sin'],
  131. 'hypsine': ['NamedFn', 'sinh'],
  132. 'arcsine': ['NamedFn', 'arcsin'],
  133. 'asine': ['NamedFn', 'asin'],
  134. 'cosine': ['NamedFn', 'cos'],
  135. 'hypcosine': ['NamedFn', 'cosh'],
  136. 'arccosine': ['NamedFn', 'arccos'],
  137. 'acosine': ['NamedFn', 'acos'],
  138. 'tangent': ['NamedFn', 'tan'],
  139. 'hyptangent': ['NamedFn', 'tanh'],
  140. 'arctangent': ['NamedFn', 'arctan'],
  141. 'atangent': ['NamedFn', 'atan'],
  142. 'cosecant': ['NamedFn', 'csc'],
  143. 'hypcosecant': ['NamedFn', 'csch'],
  144. 'arccosecant': ['NamedFn', 'arccsc'],
  145. 'acosecant': ['NamedFn', 'acsc'],
  146. 'secant': ['NamedFn', 'sec'],
  147. 'hypsecant': ['NamedFn', 'sech'],
  148. 'arcsecant': ['NamedFn', 'arcsec'],
  149. 'asecant': ['NamedFn', 'asec'],
  150. 'cotangent': ['NamedFn', 'cot'],
  151. 'hypcotangent': ['NamedFn', 'coth'],
  152. 'arccotangent': ['NamedFn', 'arccot'],
  153. 'acotangent': ['NamedFn', 'acot'],
  154. 'exponential': ['NamedFn', 'exp'],
  155. 'logarithm': ['NamedFn', 'log'],
  156. 'naturallogarithm': ['NamedFn', 'ln'],
  157. 'determinant': ['NamedFn', 'det'],
  158. 'Probability': ['NamedFn', 'Pr'],
  159. }, PhysicsMethods);
  160. /**
  161. * Macros for physics package (section 2.4).
  162. */
  163. new CommandMap('Physics-quick-quad-macros', {
  164. 'qqtext': 'Qqtext',
  165. 'qq': 'Qqtext',
  166. 'qcomma': ['Macro', '\\qqtext*{,}'],
  167. 'qc': ['Macro', '\\qqtext*{,}'],
  168. 'qcc': ['Qqtext', 'c.c.'],
  169. 'qif': ['Qqtext', 'if'],
  170. 'qthen': ['Qqtext', 'then'],
  171. 'qelse': ['Qqtext', 'else'],
  172. 'qotherwise': ['Qqtext', 'otherwise'],
  173. 'qunless': ['Qqtext', 'unless'],
  174. 'qgiven': ['Qqtext', 'given'],
  175. 'qusing': ['Qqtext', 'using'],
  176. 'qassume': ['Qqtext', 'assume'],
  177. 'qsince': ['Qqtext', 'since'],
  178. 'qlet': ['Qqtext', 'let'],
  179. 'qfor': ['Qqtext', 'for'],
  180. 'qall': ['Qqtext', 'all'],
  181. 'qeven': ['Qqtext', 'even'],
  182. 'qodd': ['Qqtext', 'odd'],
  183. 'qinteger': ['Qqtext', 'integer'],
  184. 'qand': ['Qqtext', 'and'],
  185. 'qor': ['Qqtext', 'or'],
  186. 'qas': ['Qqtext', 'as'],
  187. 'qin': ['Qqtext', 'in'],
  188. }, PhysicsMethods);
  189. /**
  190. * Macros for physics package (section 2.5).
  191. */
  192. new CommandMap('Physics-derivative-macros', {
  193. 'diffd': 'DiffD',
  194. 'flatfrac': ['Macro', '\\left.#1\\middle/#2\\right.', 2],
  195. 'differential': ['Differential', '\\diffd'],
  196. 'dd': ['Differential', '\\diffd'],
  197. 'variation': ['Differential', '\\delta'],
  198. 'var': ['Differential', '\\delta'],
  199. 'derivative': ['Derivative', 2, '\\diffd'],
  200. 'dv': ['Derivative', 2, '\\diffd'],
  201. 'partialderivative': ['Derivative', 3, '\\partial'],
  202. 'pderivative': ['Derivative', 3, '\\partial'],
  203. 'pdv': ['Derivative', 3, '\\partial'],
  204. 'functionalderivative': ['Derivative', 2, '\\delta'],
  205. 'fderivative': ['Derivative', 2, '\\delta'],
  206. 'fdv': ['Derivative', 2, '\\delta'],
  207. }, PhysicsMethods);
  208. /**
  209. * Macros for physics package (section 2.6).
  210. */
  211. new CommandMap('Physics-bra-ket-macros', {
  212. 'bra': 'Bra',
  213. 'ket': 'Ket',
  214. 'innerproduct': 'BraKet',
  215. 'ip': 'BraKet',
  216. 'braket': 'BraKet',
  217. 'outerproduct': 'KetBra',
  218. 'dyad': 'KetBra',
  219. 'ketbra': 'KetBra',
  220. 'op': 'KetBra',
  221. 'expectationvalue': 'Expectation',
  222. 'expval': 'Expectation',
  223. 'ev': 'Expectation',
  224. 'matrixelement': 'MatrixElement',
  225. 'matrixel': 'MatrixElement',
  226. 'mel': 'MatrixElement',
  227. }, PhysicsMethods);
  228. /**
  229. * Macros for physics package (section 2.7).
  230. */
  231. new CommandMap('Physics-matrix-macros', {
  232. 'matrixquantity': 'MatrixQuantity',
  233. 'mqty' : 'MatrixQuantity',
  234. 'pmqty': ['Macro', '\\mqty(#1)', 1],
  235. 'Pmqty': ['Macro', '\\mqty*(#1)', 1],
  236. 'bmqty': ['Macro', '\\mqty[#1]', 1],
  237. 'vmqty': ['Macro', '\\mqty|#1|', 1],
  238. // Smallmatrices
  239. 'smallmatrixquantity': ['MatrixQuantity', true],
  240. 'smqty': ['MatrixQuantity', true],
  241. 'spmqty': ['Macro', '\\smqty(#1)', 1],
  242. 'sPmqty': ['Macro', '\\smqty*(#1)', 1],
  243. 'sbmqty': ['Macro', '\\smqty[#1]', 1],
  244. 'svmqty': ['Macro', '\\smqty|#1|', 1],
  245. 'matrixdeterminant': ['Macro', '\\vmqty{#1}', 1],
  246. 'mdet': ['Macro', '\\vmqty{#1}', 1],
  247. 'smdet': ['Macro', '\\svmqty{#1}', 1],
  248. 'identitymatrix': 'IdentityMatrix',
  249. 'imat': 'IdentityMatrix',
  250. 'xmatrix': 'XMatrix',
  251. 'xmat': 'XMatrix',
  252. 'zeromatrix': ['Macro', '\\xmat{0}{#1}{#2}', 2],
  253. 'zmat': ['Macro', '\\xmat{0}{#1}{#2}', 2],
  254. 'paulimatrix': 'PauliMatrix',
  255. 'pmat': 'PauliMatrix',
  256. 'diagonalmatrix': 'DiagonalMatrix',
  257. 'dmat': 'DiagonalMatrix',
  258. 'antidiagonalmatrix': ['DiagonalMatrix', true],
  259. 'admat': ['DiagonalMatrix', true]
  260. }, PhysicsMethods);
  261. /**
  262. * Auxiliary environment map to define smallmatrix. This makes Physics
  263. * independent of AmsMath.
  264. */
  265. new EnvironmentMap('Physics-aux-envs', ParseMethods.environment, {
  266. smallmatrix: ['Array', null, null, null, 'c', '0.333em', '.2em', 'S', 1]
  267. }, PhysicsMethods);
  268. /**
  269. * Character map for braket package.
  270. */
  271. new MacroMap('Physics-characters', {
  272. '|': ['AutoClose', TEXCLASS.ORD], // texClass: TEXCLASS.ORD, // Have to push the closer as mml with special property
  273. ')': 'AutoClose',
  274. ']': 'AutoClose'
  275. }, PhysicsMethods);