tex.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 {FontDataClass, CharOptions, VariantData, DelimiterData, CssFontMap} from '../FontData.js';
  23. /*****************************************************************/
  24. /**
  25. * The CommonTeXFont mixin for the CommonTeXFont object
  26. *
  27. * @template C The CharOptions class for this font
  28. * @template V The VariantData class for this font
  29. * @template B The FontData class to extend
  30. */
  31. export function CommonTeXFontMixin<
  32. C extends CharOptions,
  33. V extends VariantData<C>,
  34. D extends DelimiterData,
  35. B extends FontDataClass<C, V, D>
  36. >(Base: B): FontDataClass<C, V, D> & B {
  37. return class extends Base {
  38. /**
  39. * @override
  40. */
  41. public static NAME = 'TeX';
  42. /**
  43. * Add the extra variants for the TeX fonts
  44. */
  45. protected static defaultVariants = [
  46. ...Base.defaultVariants,
  47. ['-smallop', 'normal'],
  48. ['-largeop', 'normal'],
  49. ['-size3', 'normal'],
  50. ['-size4', 'normal'],
  51. ['-tex-calligraphic', 'italic'],
  52. ['-tex-bold-calligraphic', 'bold-italic'],
  53. ['-tex-oldstyle', 'normal'],
  54. ['-tex-bold-oldstyle', 'bold'],
  55. ['-tex-mathit', 'italic'],
  56. ['-tex-variant', 'normal']
  57. ];
  58. /**
  59. * The data used for CSS for undefined characters for each variant
  60. */
  61. protected static defaultCssFonts: CssFontMap = {
  62. ...Base.defaultCssFonts,
  63. '-smallop': ['serif', false, false],
  64. '-largeop': ['serif', false, false],
  65. '-size3': ['serif', false, false],
  66. '-size4': ['serif', false, false],
  67. '-tex-calligraphic': ['cursive', true, false],
  68. '-tex-bold-calligraphic': ['cursive', true, true],
  69. '-tex-oldstyle': ['serif', false, false],
  70. '-tex-bold-oldstyle': ['serif', false, true],
  71. '-tex-mathit': ['serif', true, false]
  72. };
  73. /**
  74. * The default variants for the standard stretchy sizes
  75. */
  76. protected static defaultSizeVariants = ['normal', '-smallop', '-largeop', '-size3', '-size4', '-tex-variant'];
  77. /**
  78. * The default variants for the standard stretchy assmebly parts
  79. */
  80. protected static defaultStretchVariants = ['-size4'];
  81. /**
  82. * @override
  83. */
  84. protected getDelimiterData(n: number) {
  85. return this.getChar('-smallop', n) || this.getChar('-size4', n);
  86. }
  87. };
  88. }