boldsymbol.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
  2. /* vim: set ts=2 et sw=2 tw=80: */
  3. /*************************************************************
  4. *
  5. * MathJax/extensions/TeX/boldsymbol.js
  6. *
  7. * Implements the \boldsymbol{...} command to make bold
  8. * versions of all math characters (not just variables).
  9. *
  10. * ---------------------------------------------------------------------
  11. *
  12. * Copyright (c) 2009-2013 The MathJax Consortium
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License");
  15. * you may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. MathJax.Extension["TeX/boldsymbol"] = {
  27. version: "2.2"
  28. };
  29. MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
  30. var MML = MathJax.ElementJax.mml;
  31. var TEX = MathJax.InputJax.TeX;
  32. var TEXDEF = TEX.Definitions;
  33. var BOLDVARIANT = {};
  34. BOLDVARIANT[MML.VARIANT.NORMAL] = MML.VARIANT.BOLD;
  35. BOLDVARIANT[MML.VARIANT.ITALIC] = MML.VARIANT.BOLDITALIC;
  36. BOLDVARIANT[MML.VARIANT.FRAKTUR] = MML.VARIANT.BOLDFRAKTUR;
  37. BOLDVARIANT[MML.VARIANT.SCRIPT] = MML.VARIANT.BOLDSCRIPT;
  38. BOLDVARIANT[MML.VARIANT.SANSSERIF] = MML.VARIANT.BOLDSANSSERIF;
  39. BOLDVARIANT["-tex-caligraphic"] = "-tex-caligraphic-bold";
  40. BOLDVARIANT["-tex-oldstyle"] = "-tex-oldstyle-bold";
  41. TEXDEF.Add({macros: {boldsymbol: 'Boldsymbol'}},null,true);
  42. TEX.Parse.Augment({
  43. mmlToken: function (token) {
  44. if (this.stack.env.boldsymbol) {
  45. var variant = token.Get("mathvariant");
  46. if (variant == null) {token.mathvariant = MML.VARIANT.BOLD}
  47. else {token.mathvariant = (BOLDVARIANT[variant]||variant)}
  48. }
  49. return token;
  50. },
  51. Boldsymbol: function (name) {
  52. var boldsymbol = this.stack.env.boldsymbol,
  53. font = this.stack.env.font;
  54. this.stack.env.boldsymbol = true;
  55. this.stack.env.font = null;
  56. var mml = this.ParseArg(name);
  57. this.stack.env.font = font;
  58. this.stack.env.boldsymbol = boldsymbol;
  59. this.Push(mml);
  60. }
  61. });
  62. MathJax.Hub.Startup.signal.Post("TeX boldsymbol Ready");
  63. });
  64. MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
  65. var HTMLCSS = MathJax.OutputJax["HTML-CSS"];
  66. var FONTS = HTMLCSS.FONTDATA.FONTS;
  67. var VARIANT = HTMLCSS.FONTDATA.VARIANT;
  68. if (HTMLCSS.fontInUse === "TeX") {
  69. FONTS["MathJax_Caligraphic-bold"] = "Caligraphic/Bold/Main.js";
  70. VARIANT["-tex-caligraphic-bold"] =
  71. {fonts:["MathJax_Caligraphic-bold","MathJax_Main-bold","MathJax_Main","MathJax_Math","MathJax_Size1"],
  72. offsetA: 0x41, variantA: "bold-italic"};
  73. VARIANT["-tex-oldstyle-bold"] =
  74. {fonts:["MathJax_Caligraphic-bold","MathJax_Main-bold","MathJax_Main","MathJax_Math","MathJax_Size1"]};
  75. if (HTMLCSS.msieCheckGreek && HTMLCSS.Font.testFont({
  76. family:"MathJax_Greek", weight:"bold", style:"italic", testString: HTMLCSS.msieCheckGreek
  77. })) {
  78. VARIANT["bold-italic"].offsetG = 0x391; VARIANT["bold-italic"].variantG = "-Greek-Bold-Italic";
  79. VARIANT["-Greek-Bold-Italic"] = {fonts:["MathJax_Greek-bold-italic"]};
  80. FONTS["MathJax_Greek-bold-italic"] = "Greek/BoldItalic/Main.js";
  81. }
  82. if (MathJax.Hub.Browser.isChrome && !MathJax.Hub.Browser.versionAtLeast("5.0")) {
  83. VARIANT["-tex-caligraphic-bold"].remap = {0x54: [0xE2F0,"-WinChrome"]};
  84. }
  85. } else if (HTMLCSS.fontInUse === "STIX") {
  86. VARIANT["-tex-caligraphic-bold"] = {
  87. fonts:["STIXGeneral-bold-italic","STIXNonUnicode-bold-italic","STIXNonUnicode","STIXGeneral","STIXSizeOneSym"],
  88. offsetA: 0xE247, noLowerCase: 1
  89. };
  90. VARIANT["-tex-oldstyle-bold"] = {
  91. fonts:["STIXGeneral-bold","STIXNonUnicode-bold","STIXGeneral","STIXSizeOneSym"], offsetN: 0xE263,
  92. remap: {0xE264: 0xE267, 0xE265: 0xE26B, 0xE266: 0xE26F, 0xE267: 0xE273,
  93. 0xE268: 0xE277, 0xE269: 0xE27B, 0xE26A: 0xE27F, 0xE26B: 0xE283,
  94. 0xE26C: 0xE287}
  95. };
  96. }
  97. });
  98. MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
  99. var SVG = MathJax.OutputJax.SVG;
  100. var FONTS = SVG.FONTDATA.FONTS;
  101. var VARIANT = SVG.FONTDATA.VARIANT;
  102. FONTS["MathJax_Caligraphic-bold"] = "Caligraphic/Bold/Main.js";
  103. VARIANT["-tex-caligraphic-bold"] =
  104. {fonts:["MathJax_Caligraphic-bold","MathJax_Main-bold","MathJax_Main","MathJax_Math","MathJax_Size1"],
  105. offsetA: 0x41, variantA: "bold-italic"};
  106. VARIANT["-tex-oldstyle-bold"] =
  107. {fonts:["MathJax_Caligraphic-bold","MathJax_Main-bold","MathJax_Main","MathJax_Math","MathJax_Size1"]};
  108. });
  109. MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/boldsymbol.js");