tex.ts 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 The MathJax TeXFont object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {CHTMLFontData, CHTMLCharOptions, CHTMLVariantData, CHTMLDelimiterData, CHTMLFontDataClass,
  23. DelimiterMap, CharMapMap} from '../FontData.js';
  24. import {CommonTeXFontMixin} from '../../common/fonts/tex.js';
  25. import {StringMap} from '../Wrapper.js';
  26. import {boldItalic} from './tex/bold-italic.js';
  27. import {bold} from './tex/bold.js';
  28. import {doubleStruck} from './tex/double-struck.js';
  29. import {frakturBold} from './tex/fraktur-bold.js';
  30. import {fraktur} from './tex/fraktur.js';
  31. import {italic} from './tex/italic.js';
  32. import {largeop} from './tex/largeop.js';
  33. import {monospace} from './tex/monospace.js';
  34. import {normal} from './tex/normal.js';
  35. import {sansSerifBoldItalic} from './tex/sans-serif-bold-italic.js';
  36. import {sansSerifBold} from './tex/sans-serif-bold.js';
  37. import {sansSerifItalic} from './tex/sans-serif-italic.js';
  38. import {sansSerif} from './tex/sans-serif.js';
  39. import {scriptBold} from './tex/script-bold.js';
  40. import {script} from './tex/script.js';
  41. import {smallop} from './tex/smallop.js';
  42. import {texCalligraphicBold} from './tex/tex-calligraphic-bold.js';
  43. import {texCalligraphic} from './tex/tex-calligraphic.js';
  44. import {texMathit} from './tex/tex-mathit.js';
  45. import {texOldstyleBold} from './tex/tex-oldstyle-bold.js';
  46. import {texOldstyle} from './tex/tex-oldstyle.js';
  47. import {texSize3} from './tex/tex-size3.js';
  48. import {texSize4} from './tex/tex-size4.js';
  49. import {texVariant} from './tex/tex-variant.js';
  50. import {delimiters} from '../../common/fonts/tex/delimiters.js';
  51. /*=================================================================================*/
  52. /**
  53. * The TeXFont class
  54. */
  55. export class TeXFont extends
  56. CommonTeXFontMixin<CHTMLCharOptions, CHTMLVariantData, CHTMLDelimiterData, CHTMLFontDataClass>(CHTMLFontData) {
  57. /**
  58. * Fonts to prefix any explicit ones
  59. */
  60. protected static defaultCssFamilyPrefix = 'MJXZERO';
  61. /**
  62. * The classes to use for each variant
  63. */
  64. protected static defaultVariantClasses: StringMap = {
  65. 'normal': 'mjx-n',
  66. 'bold': 'mjx-b',
  67. 'italic': 'mjx-i',
  68. 'bold-italic': 'mjx-b mjx-i',
  69. 'double-struck': 'mjx-ds mjx-b',
  70. 'fraktur': 'mjx-fr',
  71. 'bold-fraktur': 'mjx-fr mjx-b',
  72. 'script': 'mjx-sc mjx-i',
  73. 'bold-script': 'mjx-sc mjx-b mjx-i',
  74. 'sans-serif': 'mjx-ss',
  75. 'bold-sans-serif': 'mjx-ss mjx-b',
  76. 'sans-serif-italic': 'mjx-ss mjx-i',
  77. 'sans-serif-bold-italic': 'mjx-ss mjx-b mjx-i',
  78. 'monospace': 'mjx-ty',
  79. '-smallop': 'mjx-sop',
  80. '-largeop': 'mjx-lop',
  81. '-size3': 'mjx-s3',
  82. '-size4': 'mjx-s4',
  83. '-tex-calligraphic': 'mjx-cal mjx-i',
  84. '-tex-bold-calligraphic': 'mjx-cal mjx-b',
  85. '-tex-mathit': 'mjx-mit mjx-i',
  86. '-tex-oldstyle': 'mjx-os',
  87. '-tex-bold-oldstyle': 'mjx-os mjx-b',
  88. '-tex-variant': 'mjx-var'
  89. };
  90. /**
  91. * The letters that identify the default font for each varaint
  92. */
  93. protected static defaultVariantLetters: StringMap = {
  94. 'normal': '',
  95. 'bold': 'B',
  96. 'italic': 'MI',
  97. 'bold-italic': 'BI',
  98. 'double-struck': 'A',
  99. 'fraktur': 'FR',
  100. 'bold-fraktur': 'FRB',
  101. 'script': 'SC',
  102. 'bold-script': 'SCB',
  103. 'sans-serif': 'SS',
  104. 'bold-sans-serif': 'SSB',
  105. 'sans-serif-italic': 'SSI',
  106. 'sans-serif-bold-italic': 'SSBI',
  107. 'monospace': 'T',
  108. '-smallop': 'S1',
  109. '-largeop': 'S2',
  110. '-size3': 'S3',
  111. '-size4': 'S4',
  112. '-tex-calligraphic': 'C',
  113. '-tex-bold-calligraphic': 'CB',
  114. '-tex-mathit': 'MI',
  115. '-tex-oldstyle': 'C',
  116. '-tex-bold-oldstyle': 'CB',
  117. '-tex-variant': 'A'
  118. };
  119. /**
  120. * The stretchy delimiter data
  121. */
  122. protected static defaultDelimiters: DelimiterMap<CHTMLDelimiterData> = delimiters;
  123. /**
  124. * The character data by variant
  125. */
  126. protected static defaultChars: CharMapMap<CHTMLCharOptions> = {
  127. 'normal': normal,
  128. 'bold': bold,
  129. 'italic': italic,
  130. 'bold-italic': boldItalic,
  131. 'double-struck': doubleStruck,
  132. 'fraktur': fraktur,
  133. 'bold-fraktur': frakturBold,
  134. 'script': script,
  135. 'bold-script': scriptBold,
  136. 'sans-serif': sansSerif,
  137. 'bold-sans-serif': sansSerifBold,
  138. 'sans-serif-italic': sansSerifItalic,
  139. 'sans-serif-bold-italic': sansSerifBoldItalic,
  140. 'monospace': monospace,
  141. '-smallop': smallop,
  142. '-largeop': largeop,
  143. '-size3': texSize3,
  144. '-size4': texSize4,
  145. '-tex-calligraphic': texCalligraphic,
  146. '-tex-bold-calligraphic': texCalligraphicBold,
  147. '-tex-mathit': texMathit,
  148. '-tex-oldstyle': texOldstyle,
  149. '-tex-bold-oldstyle': texOldstyleBold,
  150. '-tex-variant': texVariant
  151. };
  152. /*=====================================================*/
  153. /**
  154. * The CSS styles needed for this font.
  155. */
  156. protected static defaultStyles = {
  157. ...CHTMLFontData.defaultStyles,
  158. '.MJX-TEX': {
  159. 'font-family': 'MJXZERO, MJXTEX'
  160. },
  161. '.TEX-B': {
  162. 'font-family': 'MJXZERO, MJXTEX-B'
  163. },
  164. '.TEX-I': {
  165. 'font-family': 'MJXZERO, MJXTEX-I'
  166. },
  167. '.TEX-MI': {
  168. 'font-family': 'MJXZERO, MJXTEX-MI'
  169. },
  170. '.TEX-BI': {
  171. 'font-family': 'MJXZERO, MJXTEX-BI'
  172. },
  173. '.TEX-S1': {
  174. 'font-family': 'MJXZERO, MJXTEX-S1'
  175. },
  176. '.TEX-S2': {
  177. 'font-family': 'MJXZERO, MJXTEX-S2'
  178. },
  179. '.TEX-S3': {
  180. 'font-family': 'MJXZERO, MJXTEX-S3'
  181. },
  182. '.TEX-S4': {
  183. 'font-family': 'MJXZERO, MJXTEX-S4'
  184. },
  185. '.TEX-A': {
  186. 'font-family': 'MJXZERO, MJXTEX-A'
  187. },
  188. '.TEX-C': {
  189. 'font-family': 'MJXZERO, MJXTEX-C'
  190. },
  191. '.TEX-CB': {
  192. 'font-family': 'MJXZERO, MJXTEX-CB'
  193. },
  194. '.TEX-FR': {
  195. 'font-family': 'MJXZERO, MJXTEX-FR'
  196. },
  197. '.TEX-FRB': {
  198. 'font-family': 'MJXZERO, MJXTEX-FRB'
  199. },
  200. '.TEX-SS': {
  201. 'font-family': 'MJXZERO, MJXTEX-SS'
  202. },
  203. '.TEX-SSB': {
  204. 'font-family': 'MJXZERO, MJXTEX-SSB'
  205. },
  206. '.TEX-SSI': {
  207. 'font-family': 'MJXZERO, MJXTEX-SSI'
  208. },
  209. '.TEX-SC': {
  210. 'font-family': 'MJXZERO, MJXTEX-SC'
  211. },
  212. '.TEX-T': {
  213. 'font-family': 'MJXZERO, MJXTEX-T'
  214. },
  215. '.TEX-V': {
  216. 'font-family': 'MJXZERO, MJXTEX-V'
  217. },
  218. '.TEX-VB': {
  219. 'font-family': 'MJXZERO, MJXTEX-VB'
  220. },
  221. 'mjx-stretchy-v mjx-c, mjx-stretchy-h mjx-c': {
  222. 'font-family': 'MJXZERO, MJXTEX-S1, MJXTEX-S4, MJXTEX, MJXTEX-A ! important'
  223. }
  224. };
  225. /**
  226. * The default @font-face declarations with %%URL%% where the font path should go
  227. */
  228. protected static defaultFonts = {
  229. ...CHTMLFontData.defaultFonts,
  230. '@font-face /* 1 */': {
  231. 'font-family': 'MJXTEX',
  232. src: 'url("%%URL%%/MathJax_Main-Regular.woff") format("woff")'
  233. },
  234. '@font-face /* 2 */': {
  235. 'font-family': 'MJXTEX-B',
  236. src: 'url("%%URL%%/MathJax_Main-Bold.woff") format("woff")'
  237. },
  238. '@font-face /* 3 */': {
  239. 'font-family': 'MJXTEX-I',
  240. src: 'url("%%URL%%/MathJax_Math-Italic.woff") format("woff")'
  241. },
  242. '@font-face /* 4 */': {
  243. 'font-family': 'MJXTEX-MI',
  244. src: 'url("%%URL%%/MathJax_Main-Italic.woff") format("woff")'
  245. },
  246. '@font-face /* 5 */': {
  247. 'font-family': 'MJXTEX-BI',
  248. src: 'url("%%URL%%/MathJax_Math-BoldItalic.woff") format("woff")'
  249. },
  250. '@font-face /* 6 */': {
  251. 'font-family': 'MJXTEX-S1',
  252. src: 'url("%%URL%%/MathJax_Size1-Regular.woff") format("woff")'
  253. },
  254. '@font-face /* 7 */': {
  255. 'font-family': 'MJXTEX-S2',
  256. src: 'url("%%URL%%/MathJax_Size2-Regular.woff") format("woff")'
  257. },
  258. '@font-face /* 8 */': {
  259. 'font-family': 'MJXTEX-S3',
  260. src: 'url("%%URL%%/MathJax_Size3-Regular.woff") format("woff")'
  261. },
  262. '@font-face /* 9 */': {
  263. 'font-family': 'MJXTEX-S4',
  264. src: 'url("%%URL%%/MathJax_Size4-Regular.woff") format("woff")'
  265. },
  266. '@font-face /* 10 */': {
  267. 'font-family': 'MJXTEX-A',
  268. src: 'url("%%URL%%/MathJax_AMS-Regular.woff") format("woff")'
  269. },
  270. '@font-face /* 11 */': {
  271. 'font-family': 'MJXTEX-C',
  272. src: 'url("%%URL%%/MathJax_Calligraphic-Regular.woff") format("woff")'
  273. },
  274. '@font-face /* 12 */': {
  275. 'font-family': 'MJXTEX-CB',
  276. src: 'url("%%URL%%/MathJax_Calligraphic-Bold.woff") format("woff")'
  277. },
  278. '@font-face /* 13 */': {
  279. 'font-family': 'MJXTEX-FR',
  280. src: 'url("%%URL%%/MathJax_Fraktur-Regular.woff") format("woff")'
  281. },
  282. '@font-face /* 14 */': {
  283. 'font-family': 'MJXTEX-FRB',
  284. src: 'url("%%URL%%/MathJax_Fraktur-Bold.woff") format("woff")'
  285. },
  286. '@font-face /* 15 */': {
  287. 'font-family': 'MJXTEX-SS',
  288. src: 'url("%%URL%%/MathJax_SansSerif-Regular.woff") format("woff")'
  289. },
  290. '@font-face /* 16 */': {
  291. 'font-family': 'MJXTEX-SSB',
  292. src: 'url("%%URL%%/MathJax_SansSerif-Bold.woff") format("woff")'
  293. },
  294. '@font-face /* 17 */': {
  295. 'font-family': 'MJXTEX-SSI',
  296. src: 'url("%%URL%%/MathJax_SansSerif-Italic.woff") format("woff")'
  297. },
  298. '@font-face /* 18 */': {
  299. 'font-family': 'MJXTEX-SC',
  300. src: 'url("%%URL%%/MathJax_Script-Regular.woff") format("woff")'
  301. },
  302. '@font-face /* 19 */': {
  303. 'font-family': 'MJXTEX-T',
  304. src: 'url("%%URL%%/MathJax_Typewriter-Regular.woff") format("woff")'
  305. },
  306. '@font-face /* 20 */': {
  307. 'font-family': 'MJXTEX-V',
  308. src: 'url("%%URL%%/MathJax_Vector-Regular.woff") format("woff")'
  309. },
  310. '@font-face /* 21 */': {
  311. 'font-family': 'MJXTEX-VB',
  312. src: 'url("%%URL%%/MathJax_Vector-Bold.woff") format("woff")'
  313. },
  314. };
  315. }