| 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/cancel.js |
| 7 |
* |
| 8 |
* Implements the \cancel, \bcancel, \xcancel, and \cancelto macros. |
| 9 |
* |
| 10 |
* Usage: |
| 11 |
* |
| 12 |
* \cancel{math} % strikeout math from lower left to upper right |
| 13 |
* \bcancel{math} % strikeout from upper left to lower right |
| 14 |
* \xcancel{math} % strikeout with an X |
| 15 |
* \cancelto{value}{math} % strikeout with arrow going to value |
| 16 |
* |
| 17 |
* --------------------------------------------------------------------- |
| 18 |
* |
| 19 |
* Copyright (c) 2011-2020 The MathJax Consortium |
| 20 |
* |
| 21 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 22 |
* you may not use this file except in compliance with the License. |
| 23 |
* You may obtain a copy of the License at |
| 24 |
* |
| 25 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 26 |
* |
| 27 |
* Unless required by applicable law or agreed to in writing, software |
| 28 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 29 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 30 |
* See the License for the specific language governing permissions and |
| 31 |
* limitations under the License. |
| 32 |
*/ |
| 33 |
|
| 34 |
MathJax.Extension["TeX/cancel"] = { |
| 35 |
version: "2.7.9", |
| 36 |
|
| 37 |
// |
| 38 |
// The attributes allowed in \enclose{notation}[attributes]{math} |
| 39 |
// |
| 40 |
ALLOWED: { |
| 41 |
color: 1, mathcolor: 1, |
| 42 |
background: 1, mathbackground: 1, |
| 43 |
padding: 1, |
| 44 |
thickness: 1 |
| 45 |
} |
| 46 |
}; |
| 47 |
|
| 48 |
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { |
| 49 |
var TEX = MathJax.InputJax.TeX, |
| 50 |
MML = MathJax.ElementJax.mml, |
| 51 |
CANCEL = MathJax.Extension["TeX/cancel"]; |
| 52 |
|
| 53 |
CANCEL.setAttributes = function (def,attr) { |
| 54 |
if (attr !== "") { |
| 55 |
attr = attr.replace(/ /g,"").split(/,/); |
| 56 |
for (var i = 0, m = attr.length; i < m; i++) { |
| 57 |
var keyvalue = attr[i].split(/[:=]/); |
| 58 |
if (CANCEL.ALLOWED[keyvalue[0]]) { |
| 59 |
if (keyvalue[1] === "true") {keyvalue[1] = true} |
| 60 |
if (keyvalue[1] === "false") {keyvalue[1] = false} |
| 61 |
def[keyvalue[0]] = keyvalue[1]; |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
return def; |
| 66 |
}; |
| 67 |
|
| 68 |
// |
| 69 |
// Set up macros |
| 70 |
// |
| 71 |
TEX.Definitions.Add({ |
| 72 |
macros: { |
| 73 |
cancel: ['Cancel',MML.NOTATION.UPDIAGONALSTRIKE], |
| 74 |
bcancel: ['Cancel',MML.NOTATION.DOWNDIAGONALSTRIKE], |
| 75 |
xcancel: ['Cancel',MML.NOTATION.UPDIAGONALSTRIKE+" "+MML.NOTATION.DOWNDIAGONALSTRIKE], |
| 76 |
cancelto: 'CancelTo' |
| 77 |
} |
| 78 |
},null,true); |
| 79 |
|
| 80 |
TEX.Parse.Augment({ |
| 81 |
// |
| 82 |
// Implement \cancel[attributes]{math}, |
| 83 |
// \bcancel[attributes]{math}, and |
| 84 |
// \xcancel[attributes]{math} |
| 85 |
// |
| 86 |
Cancel: function(name,notation) { |
| 87 |
var attr = this.GetBrackets(name,""), math = this.ParseArg(name); |
| 88 |
var def = CANCEL.setAttributes({notation: notation},attr); |
| 89 |
this.Push(MML.menclose(math).With(def)); |
| 90 |
}, |
| 91 |
|
| 92 |
// |
| 93 |
// Implement \cancelto{value}[attributes]{math} |
| 94 |
// |
| 95 |
CancelTo: function(name,notation) { |
| 96 |
var value = this.ParseArg(name), |
| 97 |
attr = this.GetBrackets(name,""), |
| 98 |
math = this.ParseArg(name); |
| 99 |
var def = CANCEL.setAttributes({notation: MML.NOTATION.UPDIAGONALSTRIKE+" "+MML.NOTATION.UPDIAGONALARROW},attr); |
| 100 |
value = MML.mpadded(value).With({depth:"-.1em",height:"+.1em",voffset:".1em"}); |
| 101 |
this.Push(MML.msup(MML.menclose(math).With(def),value)); |
| 102 |
} |
| 103 |
|
| 104 |
}); |
| 105 |
|
| 106 |
MathJax.Hub.Startup.signal.Post("TeX cancel Ready"); |
| 107 |
|
| 108 |
}); |
| 109 |
|
| 110 |
MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/cancel.js"); |