extpfeil.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/extpfeil.js
  6. *
  7. * Implements additional stretchy arrow macros.
  8. *
  9. * ---------------------------------------------------------------------
  10. *
  11. * Copyright (c) 2011-2015 The MathJax Consortium
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License");
  14. * you may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. MathJax.Extension["TeX/extpfeil"] = {
  26. version: "2.5.0"
  27. };
  28. MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
  29. var TEX = MathJax.InputJax.TeX,
  30. TEXDEF = TEX.Definitions;
  31. //
  32. // Define the arrows to load the AMSmath extension
  33. // (since they need its xArrow method)
  34. //
  35. TEXDEF.Add({
  36. macros: {
  37. xtwoheadrightarrow: ['Extension','AMSmath'],
  38. xtwoheadleftarrow: ['Extension','AMSmath'],
  39. xmapsto: ['Extension','AMSmath'],
  40. xlongequal: ['Extension','AMSmath'],
  41. xtofrom: ['Extension','AMSmath'],
  42. Newextarrow: ['Extension','AMSmath']
  43. }
  44. },null,true);
  45. //
  46. // Redefine the macros when AMSmath is loaded
  47. //
  48. MathJax.Hub.Register.StartupHook("TeX AMSmath Ready",function () {
  49. MathJax.Hub.Insert(TEXDEF,{
  50. macros: {
  51. xtwoheadrightarrow: ['xArrow',0x21A0,12,16],
  52. xtwoheadleftarrow: ['xArrow',0x219E,17,13],
  53. xmapsto: ['xArrow',0x21A6,6,7],
  54. xlongequal: ['xArrow',0x003D,7,7],
  55. xtofrom: ['xArrow',0x21C4,12,12],
  56. Newextarrow: 'NewExtArrow'
  57. }
  58. });
  59. });
  60. //
  61. // Implements \Newextarrow to define a new arrow (not compatible with \newextarrow, but
  62. // the equivalent for MathJax)
  63. //
  64. TEX.Parse.Augment({
  65. NewExtArrow: function (name) {
  66. var cs = this.GetArgument(name),
  67. space = this.GetArgument(name),
  68. chr = this.GetArgument(name);
  69. if (!cs.match(/^\\([a-z]+|.)$/i)) {
  70. TEX.Error(["NewextarrowArg1",
  71. "First argument to %1 must be a control sequence name",name]);
  72. }
  73. if (!space.match(/^(\d+),(\d+)$/)) {
  74. TEX.Error(
  75. ["NewextarrowArg2",
  76. "Second argument to %1 must be two integers separated by a comma",
  77. name]
  78. );
  79. }
  80. if (!chr.match(/^(\d+|0x[0-9A-F]+)$/i)) {
  81. TEX.Error(
  82. ["NewextarrowArg3",
  83. "Third argument to %1 must be a unicode character number",
  84. name]
  85. );
  86. }
  87. cs = cs.substr(1); space = space.split(","); chr = parseInt(chr);
  88. TEXDEF.macros[cs] = ['xArrow',chr,parseInt(space[0]),parseInt(space[1])];
  89. }
  90. });
  91. MathJax.Hub.Startup.signal.Post("TeX extpfeil Ready");
  92. });
  93. MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/extpfeil.js");