| 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/unicode.js |
| 7 |
* |
| 8 |
* Implements the \unicode extension to TeX to allow arbitrary unicode |
| 9 |
* code points to be entered into the TeX file. You can specify |
| 10 |
* the height and depth of the character (the width is determined by |
| 11 |
* the browser), and the default font from which to take the character. |
| 12 |
* |
| 13 |
* Examples: |
| 14 |
* \unicode{65} % the character 'A' |
| 15 |
* \unicode{x41} % the character 'A' |
| 16 |
* \unicode[.55,0.05]{x22D6} % less-than with dot, with height .55 and depth 0.05 |
| 17 |
* \unicode[.55,0.05][Geramond]{x22D6} % same taken from Geramond font |
| 18 |
* \unicode[Garamond]{x22D6} % same, but with default height, depth of .8,.2 |
| 19 |
* |
| 20 |
* Once a size and font are provided for a given code point, they need |
| 21 |
* not be specified again in subsequent \unicode calls for that character. |
| 22 |
* Note that a font list can be given, but Internet Explorer has a buggy |
| 23 |
* implementation of font-family where it only looks in the first |
| 24 |
* available font and if the glyph is not in that, it does not look at |
| 25 |
* later fonts, but goes directly to the default font as set in the |
| 26 |
* Internet-Options/Font panel. For this reason, the default font list is |
| 27 |
* "STIXGeneral,'Arial Unicode MS'", so if the user has STIX fonts, the |
| 28 |
* symbol will be taken from that (almost all the symbols are in |
| 29 |
* STIXGeneral), otherwise Arial Unicode MS is tried. |
| 30 |
* |
| 31 |
* To configure the default font list, use |
| 32 |
* |
| 33 |
* MathJax.Hub.Config({ |
| 34 |
* TeX: { |
| 35 |
* unicode: { |
| 36 |
* fonts: "STIXGeneral,'Arial Unicode MS'" |
| 37 |
* } |
| 38 |
* } |
| 39 |
* }); |
| 40 |
* |
| 41 |
* The result of \unicode will have TeX class ORD (i.e., it will act like a |
| 42 |
* variable). Use \mathbin, \mathrel, etc, to specify a different class. |
| 43 |
* |
| 44 |
* --------------------------------------------------------------------- |
| 45 |
* |
| 46 |
* Copyright (c) 2009-2020 The MathJax Consortium |
| 47 |
* |
| 48 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 49 |
* you may not use this file except in compliance with the License. |
| 50 |
* You may obtain a copy of the License at |
| 51 |
* |
| 52 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 53 |
* |
| 54 |
* Unless required by applicable law or agreed to in writing, software |
| 55 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 56 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 57 |
* See the License for the specific language governing permissions and |
| 58 |
* limitations under the License. |
| 59 |
*/ |
| 60 |
|
| 61 |
// |
| 62 |
// The configuration defaults, augmented by the user settings |
| 63 |
// |
| 64 |
MathJax.Extension["TeX/unicode"] = { |
| 65 |
version: "2.7.9", |
| 66 |
unicode: {}, |
| 67 |
config: MathJax.Hub.CombineConfig("TeX.unicode",{ |
| 68 |
fonts: "STIXGeneral,'Arial Unicode MS'" |
| 69 |
}) |
| 70 |
}; |
| 71 |
|
| 72 |
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { |
| 73 |
var TEX = MathJax.InputJax.TeX; |
| 74 |
var MML = MathJax.ElementJax.mml; |
| 75 |
var UNICODE = MathJax.Extension["TeX/unicode"].unicode; |
| 76 |
|
| 77 |
// |
| 78 |
// Add \unicode macro |
| 79 |
// |
| 80 |
TEX.Definitions.Add({macros: {unicode: 'Unicode'}},null,true); |
| 81 |
// |
| 82 |
// Implementation of \unicode in parser |
| 83 |
// |
| 84 |
TEX.Parse.Augment({ |
| 85 |
Unicode: function(name) { |
| 86 |
var HD = this.GetBrackets(name), font; |
| 87 |
if (HD) { |
| 88 |
if (HD.replace(/ /g,"").match(/^(\d+(\.\d*)?|\.\d+),(\d+(\.\d*)?|\.\d+)$/)) |
| 89 |
{HD = HD.replace(/ /g,"").split(/,/); font = this.GetBrackets(name)} |
| 90 |
else {font = HD; HD = null} |
| 91 |
} |
| 92 |
var n = this.trimSpaces(this.GetArgument(name)).replace(/^0x/,"x"); |
| 93 |
if (!n.match(/^(x[0-9A-Fa-f]+|[0-9]+)$/)) { |
| 94 |
TEX.Error(["BadUnicode","Argument to \\unicode must be a number"]); |
| 95 |
} |
| 96 |
var N = parseInt(n.match(/^x/) ? "0"+n : n); |
| 97 |
if (!UNICODE[N]) {UNICODE[N] = [800,200,font,N]} |
| 98 |
else if (!font) {font = UNICODE[N][2]} |
| 99 |
if (HD) { |
| 100 |
UNICODE[N][0] = Math.floor(HD[0]*1000); |
| 101 |
UNICODE[N][1] = Math.floor(HD[1]*1000); |
| 102 |
} |
| 103 |
var variant = this.stack.env.font, def = {}; |
| 104 |
if (font) { |
| 105 |
UNICODE[N][2] = def.fontfamily = font.replace(/"/g,"'"); |
| 106 |
if (variant) { |
| 107 |
if (variant.match(/bold/)) {def.fontweight = "bold"} |
| 108 |
if (variant.match(/italic|-mathit/)) {def.fontstyle = "italic"} |
| 109 |
} |
| 110 |
} else if (variant) {def.mathvariant = variant} |
| 111 |
def.unicode = [].concat(UNICODE[N]); // make a copy |
| 112 |
this.Push(MML.mtext(MML.entity("#"+n)).With(def)); |
| 113 |
} |
| 114 |
}); |
| 115 |
|
| 116 |
MathJax.Hub.Startup.signal.Post("TeX unicode Ready"); |
| 117 |
|
| 118 |
}); |
| 119 |
|
| 120 |
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () { |
| 121 |
var MML = MathJax.ElementJax.mml; |
| 122 |
var FONTS = MathJax.Extension["TeX/unicode"].config.fonts; |
| 123 |
|
| 124 |
// |
| 125 |
// Override getVariant to make one that includes the font and size |
| 126 |
// |
| 127 |
var GETVARIANT = MML.mbase.prototype.HTMLgetVariant; |
| 128 |
MML.mbase.Augment({ |
| 129 |
HTMLgetVariant: function () { |
| 130 |
var variant = GETVARIANT.apply(this,arguments); |
| 131 |
if (variant.unicode) {delete variant.unicode; delete variant.FONTS} // clear font cache in case of restart |
| 132 |
if (!this.unicode) {return variant} |
| 133 |
variant.unicode = true; |
| 134 |
if (!variant.defaultFont) { |
| 135 |
variant = MathJax.Hub.Insert({},variant); // make a copy |
| 136 |
variant.defaultFont = {family:FONTS}; |
| 137 |
} |
| 138 |
var family = this.unicode[2]; if (family) {family += ","+FONTS} else {family = FONTS} |
| 139 |
variant.defaultFont[this.unicode[3]] = [ |
| 140 |
this.unicode[0],this.unicode[1],500,0,500, |
| 141 |
{isUnknown:true, isUnicode:true, font:family} |
| 142 |
]; |
| 143 |
return variant; |
| 144 |
} |
| 145 |
}); |
| 146 |
}); |
| 147 |
|
| 148 |
MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () { |
| 149 |
var MML = MathJax.ElementJax.mml; |
| 150 |
var FONTS = MathJax.Extension["TeX/unicode"].config.fonts; |
| 151 |
|
| 152 |
// |
| 153 |
// Override getVariant to make one that includes the font and size |
| 154 |
// |
| 155 |
var GETVARIANT = MML.mbase.prototype.SVGgetVariant; |
| 156 |
MML.mbase.Augment({ |
| 157 |
SVGgetVariant: function () { |
| 158 |
var variant = GETVARIANT.call(this); |
| 159 |
if (variant.unicode) {delete variant.unicode; delete variant.FONTS} // clear font cache in case of restart |
| 160 |
if (!this.unicode) {return variant} |
| 161 |
variant.unicode = true; |
| 162 |
if (!variant.forceFamily) {variant = MathJax.Hub.Insert({},variant)} // make a copy |
| 163 |
variant.defaultFamily = FONTS; variant.noRemap = true; |
| 164 |
variant.h = this.unicode[0]; variant.d = this.unicode[1]; |
| 165 |
return variant; |
| 166 |
} |
| 167 |
}); |
| 168 |
}); |
| 169 |
|
| 170 |
MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/unicode.js"); |