| 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/enclose.js |
| 7 |
* |
| 8 |
* Implements the \enclose macros, which give access from TeX to the |
| 9 |
* <menclose> tag in the MathML that underlies MathJax's internal format. |
| 10 |
* |
| 11 |
* Usage: |
| 12 |
* |
| 13 |
* \enclose{notation}{math} % enclose math using given notation |
| 14 |
* \enclose{notation,notation,...}{math} % enclose with several notations |
| 15 |
* \enclose{notation}[attributes]{math} % enclose with attributes |
| 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/enclose"] = { |
| 35 |
version: "2.7.9", |
| 36 |
|
| 37 |
// |
| 38 |
// The attributes allowed in \enclose{notation}[attributes]{math} |
| 39 |
// |
| 40 |
ALLOWED: { |
| 41 |
arrow: 1, |
| 42 |
color: 1, mathcolor: 1, |
| 43 |
background: 1, mathbackground: 1, |
| 44 |
padding: 1, |
| 45 |
thickness: 1 |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { |
| 50 |
var TEX = MathJax.InputJax.TeX, |
| 51 |
MML = MathJax.ElementJax.mml, |
| 52 |
ALLOW = MathJax.Extension["TeX/enclose"].ALLOWED; |
| 53 |
|
| 54 |
// |
| 55 |
// Set up macro |
| 56 |
// |
| 57 |
TEX.Definitions.Add({macros: {enclose: 'Enclose'}},null,true); |
| 58 |
|
| 59 |
TEX.Parse.Augment({ |
| 60 |
// |
| 61 |
// Implement \enclose{notation}[attr]{math} |
| 62 |
// (create <menclose notation="notation">math</menclose>) |
| 63 |
// |
| 64 |
Enclose: function(name) { |
| 65 |
var notation = this.GetArgument(name), |
| 66 |
attr = this.GetBrackets(name), |
| 67 |
math = this.ParseArg(name); |
| 68 |
var def = {notation: notation.replace(/,/g," ")}; |
| 69 |
if (attr) { |
| 70 |
attr = attr.replace(/ /g,"").split(/,/); |
| 71 |
for (var i = 0, m = attr.length; i < m; i++) { |
| 72 |
var keyvalue = attr[i].split(/[:=]/); |
| 73 |
if (ALLOW[keyvalue[0]]) { |
| 74 |
keyvalue[1] = keyvalue[1].replace(/^"(.*)"$/,"$1"); |
| 75 |
if (keyvalue[1] === "true") {keyvalue[1] = true} |
| 76 |
if (keyvalue[1] === "false") {keyvalue[1] = false} |
| 77 |
if (keyvalue[0] === "arrow" && keyvalue[1]) |
| 78 |
{def.notation = def.notation + " updiagonalarrow"} else |
| 79 |
{def[keyvalue[0]] = keyvalue[1]} |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
this.Push(MML.menclose(math).With(def)); |
| 84 |
} |
| 85 |
}); |
| 86 |
|
| 87 |
MathJax.Hub.Startup.signal.Post("TeX enclose Ready"); |
| 88 |
|
| 89 |
}); |
| 90 |
|
| 91 |
MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/enclose.js"); |