TextMacrosMappings.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*************************************************************
  2. *
  3. * Copyright (c) 2020-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 Character and Macro mappings for the textmacros package
  19. *
  20. * @author dpvc@mathjax.org (Davide P. Cervone)
  21. */
  22. import {MacroMap, CommandMap} from '../SymbolMap.js';
  23. import {TexConstant} from '../TexConstants.js';
  24. import {TextMacrosMethods} from './TextMacrosMethods.js';
  25. import {MATHSPACE} from '../../../util/lengths.js';
  26. //
  27. // The special characters in text-mode
  28. //
  29. new MacroMap('text-special', {
  30. '$': 'Math',
  31. '%': 'Comment',
  32. '^': 'MathModeOnly',
  33. '_': 'MathModeOnly',
  34. '&': 'Misplaced',
  35. '#': 'Misplaced',
  36. '~': 'Tilde',
  37. ' ': 'Space',
  38. '\t': 'Space',
  39. '\r': 'Space',
  40. '\n': 'Space',
  41. '\u00A0': 'Tilde',
  42. '{': 'OpenBrace',
  43. '}': 'CloseBrace',
  44. '`': 'OpenQuote',
  45. '\'': 'CloseQuote'
  46. }, TextMacrosMethods);
  47. //
  48. // The text-mode macro mappings
  49. //
  50. new CommandMap('text-macros', {
  51. '(': 'Math',
  52. '$': 'SelfQuote',
  53. '_': 'SelfQuote',
  54. '%': 'SelfQuote',
  55. '{': 'SelfQuote',
  56. '}': 'SelfQuote',
  57. ' ': 'SelfQuote',
  58. '&': 'SelfQuote',
  59. '#': 'SelfQuote',
  60. '\\': 'SelfQuote',
  61. '\'': ['Accent', '\u00B4'],
  62. '\u2019': ['Accent', '\u00B4'],
  63. '`': ['Accent', '\u0060'],
  64. '\u2018': ['Accent', '\u0060'],
  65. '^': ['Accent', '^'],
  66. '\"': ['Accent', '\u00A8'],
  67. '~': ['Accent', '~'],
  68. '=': ['Accent', '\u00AF'],
  69. '.': ['Accent', '\u02D9'],
  70. 'u': ['Accent', '\u02D8'],
  71. 'v': ['Accent', '\u02C7'],
  72. emph: 'Emph',
  73. rm: ['SetFont', TexConstant.Variant.NORMAL],
  74. mit: ['SetFont', TexConstant.Variant.ITALIC],
  75. oldstyle: ['SetFont', TexConstant.Variant.OLDSTYLE],
  76. cal: ['SetFont', TexConstant.Variant.CALLIGRAPHIC],
  77. it: ['SetFont', '-tex-mathit'], // needs special handling
  78. bf: ['SetFont', TexConstant.Variant.BOLD],
  79. bbFont: ['SetFont', TexConstant.Variant.DOUBLESTRUCK],
  80. scr: ['SetFont', TexConstant.Variant.SCRIPT],
  81. frak: ['SetFont', TexConstant.Variant.FRAKTUR],
  82. sf: ['SetFont', TexConstant.Variant.SANSSERIF],
  83. tt: ['SetFont', TexConstant.Variant.MONOSPACE],
  84. tiny: ['SetSize', 0.5],
  85. Tiny: ['SetSize', 0.6], // non-standard
  86. scriptsize: ['SetSize', 0.7],
  87. small: ['SetSize', 0.85],
  88. normalsize: ['SetSize', 1.0],
  89. large: ['SetSize', 1.2],
  90. Large: ['SetSize', 1.44],
  91. LARGE: ['SetSize', 1.73],
  92. huge: ['SetSize', 2.07],
  93. Huge: ['SetSize', 2.49],
  94. Bbb: ['Macro', '{\\bbFont #1}', 1],
  95. textnormal: ['Macro', '{\\rm #1}', 1],
  96. textup: ['Macro', '{\\rm #1}', 1],
  97. textrm: ['Macro', '{\\rm #1}', 1],
  98. textit: ['Macro', '{\\it #1}', 1],
  99. textbf: ['Macro', '{\\bf #1}', 1],
  100. textsf: ['Macro', '{\\sf #1}', 1],
  101. texttt: ['Macro', '{\\tt #1}', 1],
  102. dagger: ['Insert', '\u2020'],
  103. ddagger: ['Insert', '\u2021'],
  104. S: ['Insert', '\u00A7'],
  105. ',': ['Spacer', MATHSPACE.thinmathspace],
  106. ':': ['Spacer', MATHSPACE.mediummathspace],
  107. '>': ['Spacer', MATHSPACE.mediummathspace],
  108. ';': ['Spacer', MATHSPACE.thickmathspace],
  109. '!': ['Spacer', MATHSPACE.negativethinmathspace],
  110. enspace: ['Spacer', .5],
  111. quad: ['Spacer', 1],
  112. qquad: ['Spacer', 2],
  113. thinspace: ['Spacer', MATHSPACE.thinmathspace],
  114. negthinspace: ['Spacer', MATHSPACE.negativethinmathspace],
  115. hskip: 'Hskip',
  116. hspace: 'Hskip',
  117. kern: 'Hskip',
  118. mskip: 'Hskip',
  119. mspace: 'Hskip',
  120. mkern: 'Hskip',
  121. rule: 'rule',
  122. Rule: ['Rule'],
  123. Space: ['Rule', 'blank'],
  124. color: 'CheckAutoload',
  125. textcolor: 'CheckAutoload',
  126. colorbox: 'CheckAutoload',
  127. fcolorbox: 'CheckAutoload',
  128. href: 'CheckAutoload',
  129. style: 'CheckAutoload',
  130. class: 'CheckAutoload',
  131. cssId: 'CheckAutoload',
  132. unicode: 'CheckAutoload',
  133. ref: ['HandleRef', false],
  134. eqref: ['HandleRef', true],
  135. }, TextMacrosMethods);