| 1 |
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */ |
| 2 |
/* vim: set ts=2 et sw=2 tw=80: */ |
| 3 |
|
| 4 |
/************************************************************* |
| 5 |
* |
| 6 |
* MathJax/extensions/TeX/extpfeil.js |
| 7 |
* |
| 8 |
* Implements additional stretchy arrow macros. |
| 9 |
* |
| 10 |
* --------------------------------------------------------------------- |
| 11 |
* |
| 12 |
* Copyright (c) 2011-2020 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 |
|
| 27 |
MathJax.Extension["TeX/extpfeil"] = { |
| 28 |
version: "2.7.9" |
| 29 |
}; |
| 30 |
|
| 31 |
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { |
| 32 |
|
| 33 |
var TEX = MathJax.InputJax.TeX, |
| 34 |
TEXDEF = TEX.Definitions; |
| 35 |
|
| 36 |
// |
| 37 |
// Define the arrows to load the AMSmath extension |
| 38 |
// (since they need its xArrow method) |
| 39 |
// |
| 40 |
TEXDEF.Add({ |
| 41 |
macros: { |
| 42 |
xtwoheadrightarrow: ['Extension','AMSmath'], |
| 43 |
xtwoheadleftarrow: ['Extension','AMSmath'], |
| 44 |
xmapsto: ['Extension','AMSmath'], |
| 45 |
xlongequal: ['Extension','AMSmath'], |
| 46 |
xtofrom: ['Extension','AMSmath'], |
| 47 |
Newextarrow: ['Extension','AMSmath'] |
| 48 |
} |
| 49 |
},null,true); |
| 50 |
|
| 51 |
// |
| 52 |
// Redefine the macros when AMSmath is loaded |
| 53 |
// |
| 54 |
MathJax.Hub.Register.StartupHook("TeX AMSmath Ready",function () { |
| 55 |
MathJax.Hub.Insert(TEXDEF,{ |
| 56 |
macros: { |
| 57 |
xtwoheadrightarrow: ['xArrow',0x21A0,12,16], |
| 58 |
xtwoheadleftarrow: ['xArrow',0x219E,17,13], |
| 59 |
xmapsto: ['xArrow',0x21A6,6,7], |
| 60 |
xlongequal: ['xArrow',0x003D,7,7], |
| 61 |
xtofrom: ['xArrow',0x21C4,12,12], |
| 62 |
Newextarrow: 'NewExtArrow' |
| 63 |
} |
| 64 |
}); |
| 65 |
}); |
| 66 |
|
| 67 |
// |
| 68 |
// Implements \Newextarrow to define a new arrow (not compatible with \newextarrow, but |
| 69 |
// the equivalent for MathJax) |
| 70 |
// |
| 71 |
TEX.Parse.Augment({ |
| 72 |
NewExtArrow: function (name) { |
| 73 |
var cs = this.GetArgument(name), |
| 74 |
space = this.GetArgument(name), |
| 75 |
chr = this.GetArgument(name); |
| 76 |
if (!cs.match(/^\\([a-z]+|.)$/i)) { |
| 77 |
TEX.Error(["NewextarrowArg1", |
| 78 |
"First argument to %1 must be a control sequence name",name]); |
| 79 |
} |
| 80 |
if (!space.match(/^(\d+),(\d+)$/)) { |
| 81 |
TEX.Error( |
| 82 |
["NewextarrowArg2", |
| 83 |
"Second argument to %1 must be two integers separated by a comma", |
| 84 |
name] |
| 85 |
); |
| 86 |
} |
| 87 |
if (!chr.match(/^(\d+|0x[0-9A-F]+)$/i)) { |
| 88 |
TEX.Error( |
| 89 |
["NewextarrowArg3", |
| 90 |
"Third argument to %1 must be a unicode character number", |
| 91 |
name] |
| 92 |
); |
| 93 |
} |
| 94 |
cs = cs.substr(1); space = space.split(","); chr = parseInt(chr); |
| 95 |
this.setDef(cs, ['xArrow', chr, parseInt(space[0]), parseInt(space[1])]); |
| 96 |
} |
| 97 |
}); |
| 98 |
|
| 99 |
MathJax.Hub.Startup.signal.Post("TeX extpfeil Ready"); |
| 100 |
}); |
| 101 |
|
| 102 |
MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/extpfeil.js"); |