| 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/jax/input/TeX/jax.js |
| 7 |
* |
| 8 |
* Implements the TeX InputJax that reads mathematics in |
| 9 |
* TeX and LaTeX format and converts it to the MML ElementJax |
| 10 |
* internal format. |
| 11 |
* |
| 12 |
* --------------------------------------------------------------------- |
| 13 |
* |
| 14 |
* Copyright (c) 2009-2020 The MathJax Consortium |
| 15 |
* |
| 16 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 17 |
* you may not use this file except in compliance with the License. |
| 18 |
* You may obtain a copy of the License at |
| 19 |
* |
| 20 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 21 |
* |
| 22 |
* Unless required by applicable law or agreed to in writing, software |
| 23 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 24 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 25 |
* See the License for the specific language governing permissions and |
| 26 |
* limitations under the License. |
| 27 |
*/ |
| 28 |
|
| 29 |
(function (TEX,HUB,AJAX) { |
| 30 |
var MML, NBSP = "\u00A0"; |
| 31 |
|
| 32 |
var _ = function (id) { |
| 33 |
return MathJax.Localization._.apply(MathJax.Localization, |
| 34 |
[["TeX", id]].concat([].slice.call(arguments,1))); |
| 35 |
}; |
| 36 |
|
| 37 |
var isArray = MathJax.Object.isArray; |
| 38 |
|
| 39 |
var STACK = MathJax.Object.Subclass({ |
| 40 |
Init: function (env,inner) { |
| 41 |
this.global = {isInner: inner}; |
| 42 |
this.data = [STACKITEM.start(this.global)]; |
| 43 |
if (env) {this.data[0].env = env} |
| 44 |
this.env = this.data[0].env; |
| 45 |
}, |
| 46 |
Push: function () { |
| 47 |
var i, m, item, top; |
| 48 |
for (i = 0, m = arguments.length; i < m; i++) { |
| 49 |
item = arguments[i]; if (!item) continue; |
| 50 |
if (item instanceof MML.mbase) {item = STACKITEM.mml(item)} |
| 51 |
item.global = this.global; |
| 52 |
top = (this.data.length ? this.Top().checkItem(item) : true); |
| 53 |
if (top instanceof Array) {this.Pop(); this.Push.apply(this,top)} |
| 54 |
else if (top instanceof STACKITEM) {this.Pop(); this.Push(top)} |
| 55 |
else if (top) { |
| 56 |
this.data.push(item); |
| 57 |
if (item.env) { |
| 58 |
if (item.copyEnv !== false) { |
| 59 |
for (var id in this.env) |
| 60 |
{if (this.env.hasOwnProperty(id)) {item.env[id] = this.env[id]}} |
| 61 |
} |
| 62 |
this.env = item.env; |
| 63 |
} else {item.env = this.env} |
| 64 |
} |
| 65 |
} |
| 66 |
}, |
| 67 |
Pop: function () { |
| 68 |
var item = this.data.pop(); if (!item.isOpen) {delete item.env} |
| 69 |
this.env = (this.data.length ? this.Top().env : {}); |
| 70 |
return item; |
| 71 |
}, |
| 72 |
Top: function (n) { |
| 73 |
if (n == null) {n = 1} |
| 74 |
if (this.data.length < n) {return null} |
| 75 |
return this.data[this.data.length-n]; |
| 76 |
}, |
| 77 |
Prev: function (noPop) { |
| 78 |
var top = this.Top(); |
| 79 |
if (noPop) {return top.data[top.data.length-1]} |
| 80 |
else {return top.Pop()} |
| 81 |
}, |
| 82 |
toString: function () {return "stack[\n "+this.data.join("\n ")+"\n]"} |
| 83 |
}); |
| 84 |
|
| 85 |
var STACKITEM = STACK.Item = MathJax.Object.Subclass({ |
| 86 |
type: "base", |
| 87 |
endError: /*_()*/ ["ExtraOpenMissingClose","Extra open brace or missing close brace"], |
| 88 |
closeError: /*_()*/ ["ExtraCloseMissingOpen","Extra close brace or missing open brace"], |
| 89 |
rightError: /*_()*/ ["MissingLeftExtraRight","Missing \\left or extra \\right"], |
| 90 |
Init: function () { |
| 91 |
if (this.isOpen) {this.env = {}} |
| 92 |
this.data = []; |
| 93 |
this.Push.apply(this,arguments); |
| 94 |
}, |
| 95 |
Push: function () {this.data.push.apply(this.data,arguments)}, |
| 96 |
Pop: function () {return this.data.pop()}, |
| 97 |
mmlData: function (inferred,forceRow) { |
| 98 |
if (inferred == null) {inferred = true} |
| 99 |
if (this.data.length === 1 && !forceRow) {return this.data[0]} |
| 100 |
return MML.mrow.apply(MML,this.data).With((inferred ? {inferred: true}: {})); |
| 101 |
}, |
| 102 |
checkItem: function (item) { |
| 103 |
if (item.type === "over" && this.isOpen) {item.num = this.mmlData(false); this.data = []} |
| 104 |
if (item.type === "cell" && this.isOpen) { |
| 105 |
if (item.linebreak) {return false} |
| 106 |
TEX.Error(["Misplaced","Misplaced %1",item.name]); |
| 107 |
} |
| 108 |
if (item.isClose && this[item.type+"Error"]) {TEX.Error(this[item.type+"Error"])} |
| 109 |
if (!item.isNotStack) {return true} |
| 110 |
this.Push(item.data[0]); return false; |
| 111 |
}, |
| 112 |
With: function (def) { |
| 113 |
for (var id in def) {if (def.hasOwnProperty(id)) {this[id] = def[id]}} |
| 114 |
return this; |
| 115 |
}, |
| 116 |
toString: function () {return this.type+"["+this.data.join("; ")+"]"} |
| 117 |
}); |
| 118 |
|
| 119 |
STACKITEM.start = STACKITEM.Subclass({ |
| 120 |
type: "start", isOpen: true, |
| 121 |
Init: function (global) { |
| 122 |
this.SUPER(arguments).Init.call(this); |
| 123 |
this.global = global; |
| 124 |
}, |
| 125 |
checkItem: function (item) { |
| 126 |
if (item.type === "stop") {return STACKITEM.mml(this.mmlData())} |
| 127 |
return this.SUPER(arguments).checkItem.call(this,item); |
| 128 |
} |
| 129 |
}); |
| 130 |
|
| 131 |
STACKITEM.stop = STACKITEM.Subclass({ |
| 132 |
type: "stop", isClose: true |
| 133 |
}); |
| 134 |
|
| 135 |
STACKITEM.open = STACKITEM.Subclass({ |
| 136 |
type: "open", isOpen: true, |
| 137 |
stopError: /*_()*/ ["ExtraOpenMissingClose","Extra open brace or missing close brace"], |
| 138 |
checkItem: function (item) { |
| 139 |
if (item.type === "close") { |
| 140 |
var mml = this.mmlData(); |
| 141 |
return STACKITEM.mml(MML.TeXAtom(mml)); // TeXAtom make it an ORD to prevent spacing (FIXME: should be another way) |
| 142 |
} |
| 143 |
return this.SUPER(arguments).checkItem.call(this,item); |
| 144 |
} |
| 145 |
}); |
| 146 |
|
| 147 |
STACKITEM.close = STACKITEM.Subclass({ |
| 148 |
type: "close", isClose: true |
| 149 |
}); |
| 150 |
|
| 151 |
STACKITEM.prime = STACKITEM.Subclass({ |
| 152 |
type: "prime", |
| 153 |
checkItem: function (item) { |
| 154 |
if (this.data[0].type !== "msubsup") |
| 155 |
{return [MML.msup(this.data[0],this.data[1]),item]} |
| 156 |
this.data[0].SetData(this.data[0].sup,this.data[1]); |
| 157 |
return [this.data[0],item]; |
| 158 |
} |
| 159 |
}); |
| 160 |
|
| 161 |
STACKITEM.subsup = STACKITEM.Subclass({ |
| 162 |
type: "subsup", |
| 163 |
stopError: /*_()*/ ["MissingScript","Missing superscript or subscript argument"], |
| 164 |
supError: /*_()*/ ["MissingOpenForSup","Missing open brace for superscript"], |
| 165 |
subError: /*_()*/ ["MissingOpenForSub","Missing open brace for subscript"], |
| 166 |
checkItem: function (item) { |
| 167 |
if (item.type === "open" || item.type === "left") {return true} |
| 168 |
if (item.type === "mml") { |
| 169 |
if (this.primes) { |
| 170 |
if (this.position !== 2) {this.data[0].SetData(2,this.primes)} |
| 171 |
else {item.data[0] = MML.mrow(this.primes.With({variantForm:true}),item.data[0])} |
| 172 |
} |
| 173 |
this.data[0].SetData(this.position,item.data[0]); |
| 174 |
if (this.movesupsub != null) {this.data[0].movesupsub = this.movesupsub} |
| 175 |
return STACKITEM.mml(this.data[0]); |
| 176 |
} |
| 177 |
if (this.SUPER(arguments).checkItem.call(this,item)) |
| 178 |
{TEX.Error(this[["","subError","supError"][this.position]])} |
| 179 |
}, |
| 180 |
Pop: function () {} |
| 181 |
}); |
| 182 |
|
| 183 |
STACKITEM.over = STACKITEM.Subclass({ |
| 184 |
type: "over", isClose: true, name: "\\over", |
| 185 |
checkItem: function (item,stack) { |
| 186 |
if (item.type === "over") |
| 187 |
{TEX.Error(["AmbiguousUseOf","Ambiguous use of %1",item.name])} |
| 188 |
if (item.isClose) { |
| 189 |
var mml = MML.mfrac(this.num,this.mmlData(false)); |
| 190 |
if (this.thickness != null) {mml.linethickness = this.thickness} |
| 191 |
if (this.open || this.close) { |
| 192 |
mml.texWithDelims = true; |
| 193 |
mml = TEX.fixedFence(this.open,mml,this.close); |
| 194 |
} |
| 195 |
return [STACKITEM.mml(mml), item]; |
| 196 |
} |
| 197 |
return this.SUPER(arguments).checkItem.call(this,item); |
| 198 |
}, |
| 199 |
toString: function () {return "over["+this.num+" / "+this.data.join("; ")+"]"} |
| 200 |
}); |
| 201 |
|
| 202 |
STACKITEM.left = STACKITEM.Subclass({ |
| 203 |
type: "left", isOpen: true, delim: '(', |
| 204 |
stopError: /*_()*/ ["ExtraLeftMissingRight", "Extra \\left or missing \\right"], |
| 205 |
checkItem: function (item) { |
| 206 |
if (item.type === "right") |
| 207 |
{return STACKITEM.mml(TEX.fenced(this.delim,this.mmlData(),item.delim))} |
| 208 |
return this.SUPER(arguments).checkItem.call(this,item); |
| 209 |
} |
| 210 |
}); |
| 211 |
|
| 212 |
STACKITEM.right = STACKITEM.Subclass({ |
| 213 |
type: "right", isClose: true, delim: ')' |
| 214 |
}); |
| 215 |
|
| 216 |
STACKITEM.begin = STACKITEM.Subclass({ |
| 217 |
type: "begin", isOpen: true, |
| 218 |
checkItem: function (item) { |
| 219 |
if (item.type === "end") { |
| 220 |
if (item.name !== this.name) |
| 221 |
{TEX.Error(["EnvBadEnd","\\begin{%1} ended with \\end{%2}",this.name,item.name])} |
| 222 |
if (!this.end) {return STACKITEM.mml(this.mmlData())} |
| 223 |
return this.parse[this.end].call(this.parse,this,this.data); |
| 224 |
} |
| 225 |
if (item.type === "stop") |
| 226 |
{TEX.Error(["EnvMissingEnd","Missing \\end{%1}",this.name])} |
| 227 |
return this.SUPER(arguments).checkItem.call(this,item); |
| 228 |
} |
| 229 |
}); |
| 230 |
|
| 231 |
STACKITEM.end = STACKITEM.Subclass({ |
| 232 |
type: "end", isClose: true |
| 233 |
}); |
| 234 |
|
| 235 |
STACKITEM.style = STACKITEM.Subclass({ |
| 236 |
type: "style", |
| 237 |
checkItem: function (item) { |
| 238 |
if (!item.isClose) {return this.SUPER(arguments).checkItem.call(this,item)} |
| 239 |
var mml = MML.mstyle.apply(MML,this.data).With(this.styles); |
| 240 |
return [STACKITEM.mml(mml),item]; |
| 241 |
} |
| 242 |
}); |
| 243 |
|
| 244 |
STACKITEM.position = STACKITEM.Subclass({ |
| 245 |
type: "position", |
| 246 |
checkItem: function (item) { |
| 247 |
if (item.isClose) {TEX.Error(["MissingBoxFor","Missing box for %1",this.name])} |
| 248 |
if (item.isNotStack) { |
| 249 |
var mml = item.mmlData(); |
| 250 |
switch (this.move) { |
| 251 |
case 'vertical': |
| 252 |
mml = MML.mpadded(mml).With({height: this.dh, depth: this.dd, voffset: this.dh}); |
| 253 |
return [STACKITEM.mml(mml)]; |
| 254 |
case 'horizontal': |
| 255 |
return [STACKITEM.mml(this.left),item,STACKITEM.mml(this.right)]; |
| 256 |
} |
| 257 |
} |
| 258 |
return this.SUPER(arguments).checkItem.call(this,item); |
| 259 |
} |
| 260 |
}); |
| 261 |
|
| 262 |
STACKITEM.array = STACKITEM.Subclass({ |
| 263 |
type: "array", isOpen: true, copyEnv: false, arraydef: {}, |
| 264 |
Init: function () { |
| 265 |
this.table = []; this.row = []; this.frame = []; this.hfill = []; |
| 266 |
this.SUPER(arguments).Init.apply(this,arguments); |
| 267 |
}, |
| 268 |
checkItem: function (item) { |
| 269 |
if (item.isClose && item.type !== "over") { |
| 270 |
if (item.isEntry) {this.EndEntry(); this.clearEnv(); return false} |
| 271 |
if (item.isCR) {this.EndEntry(); this.EndRow(); this.clearEnv(); return false} |
| 272 |
this.EndTable(); this.clearEnv(); |
| 273 |
var scriptlevel = this.arraydef.scriptlevel; delete this.arraydef.scriptlevel; |
| 274 |
var mml = MML.mtable.apply(MML,this.table).With(this.arraydef); |
| 275 |
if (this.frame.length === 4) { |
| 276 |
mml.frame = (this.frame.dashed ? "dashed" : "solid"); |
| 277 |
} else if (this.frame.length) { |
| 278 |
mml.hasFrame = true; |
| 279 |
if (this.arraydef.rowlines) {this.arraydef.rowlines = this.arraydef.rowlines.replace(/none( none)+$/,"none")} |
| 280 |
mml = MML.menclose(mml).With({notation: this.frame.join(" "), isFrame: true}); |
| 281 |
if ((this.arraydef.columnlines||"none") != "none" || |
| 282 |
(this.arraydef.rowlines||"none") != "none") {mml.padding = 0} // HTML-CSS jax implements this |
| 283 |
} |
| 284 |
if (scriptlevel) {mml = MML.mstyle(mml).With({scriptlevel: scriptlevel})} |
| 285 |
if (this.open || this.close) {mml = TEX.fenced(this.open,mml,this.close)} |
| 286 |
mml = STACKITEM.mml(mml); |
| 287 |
if (this.requireClose) { |
| 288 |
if (item.type === 'close') {return mml} |
| 289 |
TEX.Error(["MissingCloseBrace","Missing close brace"]); |
| 290 |
} |
| 291 |
return [mml,item]; |
| 292 |
} |
| 293 |
return this.SUPER(arguments).checkItem.call(this,item); |
| 294 |
}, |
| 295 |
EndEntry: function () { |
| 296 |
var mtd = MML.mtd.apply(MML,this.data); |
| 297 |
if (this.hfill.length) { |
| 298 |
if (this.hfill[0] === 0) mtd.columnalign = "right"; |
| 299 |
if (this.hfill[this.hfill.length-1] === this.data.length) |
| 300 |
mtd.columnalign = (mtd.columnalign ? "center" : "left"); |
| 301 |
} |
| 302 |
this.row.push(mtd); this.data = []; this.hfill = []; |
| 303 |
}, |
| 304 |
EndRow: function () { |
| 305 |
var mtr = MML.mtr; |
| 306 |
if (this.isNumbered && this.row.length === 3) { |
| 307 |
this.row.unshift(this.row.pop()); // move equation number to first position |
| 308 |
mtr = MML.mlabeledtr; |
| 309 |
} |
| 310 |
this.table.push(mtr.apply(MML,this.row)); this.row = []; |
| 311 |
}, |
| 312 |
EndTable: function () { |
| 313 |
if (this.data.length || this.row.length) {this.EndEntry(); this.EndRow()} |
| 314 |
this.checkLines(); |
| 315 |
}, |
| 316 |
checkLines: function () { |
| 317 |
if (this.arraydef.rowlines) { |
| 318 |
var lines = this.arraydef.rowlines.split(/ /); |
| 319 |
if (lines.length === this.table.length) { |
| 320 |
this.frame.push("bottom"); lines.pop(); |
| 321 |
this.arraydef.rowlines = lines.join(' '); |
| 322 |
} else if (lines.length < this.table.length-1) { |
| 323 |
this.arraydef.rowlines += " none"; |
| 324 |
} |
| 325 |
} |
| 326 |
if (this.rowspacing) { |
| 327 |
var rows = this.arraydef.rowspacing.split(/ /); |
| 328 |
while (rows.length < this.table.length) {rows.push(this.rowspacing+"em")} |
| 329 |
this.arraydef.rowspacing = rows.join(' '); |
| 330 |
} |
| 331 |
}, |
| 332 |
clearEnv: function () { |
| 333 |
for (var id in this.env) {if (this.env.hasOwnProperty(id)) {delete this.env[id]}} |
| 334 |
} |
| 335 |
}); |
| 336 |
|
| 337 |
STACKITEM.cell = STACKITEM.Subclass({ |
| 338 |
type: "cell", isClose: true |
| 339 |
}); |
| 340 |
|
| 341 |
STACKITEM.mml = STACKITEM.Subclass({ |
| 342 |
type: "mml", isNotStack: true, |
| 343 |
Add: function () {this.data.push.apply(this.data,arguments); return this} |
| 344 |
}); |
| 345 |
|
| 346 |
STACKITEM.fn = STACKITEM.Subclass({ |
| 347 |
type: "fn", |
| 348 |
checkItem: function (item) { |
| 349 |
if (this.data[0]) { |
| 350 |
if (item.isOpen) {return true} |
| 351 |
if (item.type !== "fn") { |
| 352 |
if (item.type !== "mml" || !item.data[0]) {return [this.data[0],item]} |
| 353 |
if (item.data[0].isa(MML.mspace)) {return [this.data[0],item]} |
| 354 |
var mml = item.data[0]; if (mml.isEmbellished()) {mml = mml.CoreMO()} |
| 355 |
if ([0,0,1,1,0,1,1,0,0,0][mml.Get("texClass")]) {return [this.data[0],item]} |
| 356 |
} |
| 357 |
return [this.data[0],MML.mo(MML.entity("#x2061")).With({texClass:MML.TEXCLASS.NONE}),item]; |
| 358 |
} |
| 359 |
return this.SUPER(arguments).checkItem.apply(this,arguments); |
| 360 |
} |
| 361 |
}); |
| 362 |
|
| 363 |
STACKITEM.not = STACKITEM.Subclass({ |
| 364 |
type: "not", |
| 365 |
checkItem: function (item) { |
| 366 |
var mml, c; |
| 367 |
if (item.type === "open" || item.type === "left") {return true} |
| 368 |
if (item.type === "mml" && item.data[0].type.match(/^(mo|mi|mtext)$/)) { |
| 369 |
mml = item.data[0], c = mml.data.join(""); |
| 370 |
if (c.length === 1 && !mml.movesupsub && mml.data.length === 1) { |
| 371 |
c = STACKITEM.not.remap[c.charCodeAt(0)]; |
| 372 |
if (c) {mml.SetData(0,MML.chars(String.fromCharCode(c)))} |
| 373 |
else {mml.Append(MML.chars("\u0338"))} |
| 374 |
return item; |
| 375 |
} |
| 376 |
} |
| 377 |
// \mathrel{\rlap{\notChar}} |
| 378 |
mml = MML.mpadded(MML.mtext("\u29F8")).With({width:0}); |
| 379 |
mml = MML.TeXAtom(mml).With({texClass:MML.TEXCLASS.REL}); |
| 380 |
return [mml,item]; |
| 381 |
} |
| 382 |
}); |
| 383 |
STACKITEM.not.remap = { |
| 384 |
0x2190:0x219A, 0x2192:0x219B, 0x2194:0x21AE, |
| 385 |
0x21D0:0x21CD, 0x21D2:0x21CF, 0x21D4:0x21CE, |
| 386 |
0x2208:0x2209, 0x220B:0x220C, 0x2223:0x2224, 0x2225:0x2226, |
| 387 |
0x223C:0x2241, 0x007E:0x2241, 0x2243:0x2244, 0x2245:0x2247, |
| 388 |
0x2248:0x2249, 0x224D:0x226D, 0x003D:0x2260, 0x2261:0x2262, |
| 389 |
0x003C:0x226E, 0x003E:0x226F, 0x2264:0x2270, 0x2265:0x2271, |
| 390 |
0x2272:0x2274, 0x2273:0x2275, 0x2276:0x2278, 0x2277:0x2279, |
| 391 |
0x227A:0x2280, 0x227B:0x2281, 0x2282:0x2284, 0x2283:0x2285, |
| 392 |
0x2286:0x2288, 0x2287:0x2289, 0x22A2:0x22AC, 0x22A8:0x22AD, |
| 393 |
0x22A9:0x22AE, 0x22AB:0x22AF, 0x227C:0x22E0, 0x227D:0x22E1, |
| 394 |
0x2291:0x22E2, 0x2292:0x22E3, 0x22B2:0x22EA, 0x22B3:0x22EB, |
| 395 |
0x22B4:0x22EC, 0x22B5:0x22ED, 0x2203:0x2204 |
| 396 |
}; |
| 397 |
|
| 398 |
STACKITEM.dots = STACKITEM.Subclass({ |
| 399 |
type: "dots", |
| 400 |
checkItem: function (item) { |
| 401 |
if (item.type === "open" || item.type === "left") {return true} |
| 402 |
var dots = this.ldots; |
| 403 |
if (item.type === "mml" && item.data[0].isEmbellished()) { |
| 404 |
var tclass = item.data[0].CoreMO().Get("texClass"); |
| 405 |
if (tclass === MML.TEXCLASS.BIN || tclass === MML.TEXCLASS.REL) {dots = this.cdots} |
| 406 |
} |
| 407 |
return [dots,item]; |
| 408 |
} |
| 409 |
}); |
| 410 |
|
| 411 |
|
| 412 |
var TEXDEF = { |
| 413 |
// |
| 414 |
// Add new definitions without overriding user-defined ones |
| 415 |
// |
| 416 |
Add: function (src,dst,nouser) { |
| 417 |
if (!dst) {dst = this} |
| 418 |
for (var id in src) {if (src.hasOwnProperty(id)) { |
| 419 |
if (typeof src[id] === 'object' && !isArray(src[id]) && |
| 420 |
(typeof dst[id] === 'object' || typeof dst[id] === 'function')) |
| 421 |
{this.Add(src[id],dst[id],src[id],nouser)} |
| 422 |
else if (!dst[id] || !dst[id].isUser || !nouser) {dst[id] = src[id]} |
| 423 |
}} |
| 424 |
return dst; |
| 425 |
} |
| 426 |
}; |
| 427 |
var STARTUP = function () { |
| 428 |
MML = MathJax.ElementJax.mml; |
| 429 |
HUB.Insert(TEXDEF,{ |
| 430 |
|
| 431 |
// patterns for letters and numbers |
| 432 |
letter: /[a-z]/i, |
| 433 |
digit: /[0-9.]/, |
| 434 |
number: /^(?:[0-9]+(?:\{,\}[0-9]{3})*(?:\.[0-9]*)*|\.[0-9]+)/, |
| 435 |
|
| 436 |
special: { |
| 437 |
'\\': 'ControlSequence', |
| 438 |
'{': 'Open', |
| 439 |
'}': 'Close', |
| 440 |
'~': 'Tilde', |
| 441 |
'^': 'Superscript', |
| 442 |
'_': 'Subscript', |
| 443 |
' ': 'Space', |
| 444 |
"\t": 'Space', |
| 445 |
"\r": 'Space', |
| 446 |
"\n": 'Space', |
| 447 |
"'": 'Prime', |
| 448 |
'%': 'Comment', |
| 449 |
'&': 'Entry', |
| 450 |
'#': 'Hash', |
| 451 |
'\u00A0': 'Space', |
| 452 |
'\u2019': 'Prime' |
| 453 |
}, |
| 454 |
|
| 455 |
remap: { |
| 456 |
'-': '2212', |
| 457 |
'*': '2217', |
| 458 |
'`': '2018' // map ` to back quote |
| 459 |
}, |
| 460 |
|
| 461 |
mathchar0mi: { |
| 462 |
// Lower-case greek |
| 463 |
alpha: '03B1', |
| 464 |
beta: '03B2', |
| 465 |
gamma: '03B3', |
| 466 |
delta: '03B4', |
| 467 |
epsilon: '03F5', |
| 468 |
zeta: '03B6', |
| 469 |
eta: '03B7', |
| 470 |
theta: '03B8', |
| 471 |
iota: '03B9', |
| 472 |
kappa: '03BA', |
| 473 |
lambda: '03BB', |
| 474 |
mu: '03BC', |
| 475 |
nu: '03BD', |
| 476 |
xi: '03BE', |
| 477 |
omicron: '03BF', // added for completeness |
| 478 |
pi: '03C0', |
| 479 |
rho: '03C1', |
| 480 |
sigma: '03C3', |
| 481 |
tau: '03C4', |
| 482 |
upsilon: '03C5', |
| 483 |
phi: '03D5', |
| 484 |
chi: '03C7', |
| 485 |
psi: '03C8', |
| 486 |
omega: '03C9', |
| 487 |
varepsilon: '03B5', |
| 488 |
vartheta: '03D1', |
| 489 |
varpi: '03D6', |
| 490 |
varrho: '03F1', |
| 491 |
varsigma: '03C2', |
| 492 |
varphi: '03C6', |
| 493 |
|
| 494 |
// Ord symbols |
| 495 |
S: ['00A7',{mathvariant: MML.VARIANT.NORMAL}], |
| 496 |
aleph: ['2135',{mathvariant: MML.VARIANT.NORMAL}], |
| 497 |
hbar: ['210F',{variantForm:true}], |
| 498 |
imath: '0131', |
| 499 |
jmath: '0237', |
| 500 |
ell: '2113', |
| 501 |
wp: ['2118',{mathvariant: MML.VARIANT.NORMAL}], |
| 502 |
Re: ['211C',{mathvariant: MML.VARIANT.NORMAL}], |
| 503 |
Im: ['2111',{mathvariant: MML.VARIANT.NORMAL}], |
| 504 |
partial: ['2202',{mathvariant: MML.VARIANT.NORMAL}], |
| 505 |
infty: ['221E',{mathvariant: MML.VARIANT.NORMAL}], |
| 506 |
prime: ['2032',{mathvariant: MML.VARIANT.NORMAL, variantForm:true}], |
| 507 |
emptyset: ['2205',{mathvariant: MML.VARIANT.NORMAL}], |
| 508 |
nabla: ['2207',{mathvariant: MML.VARIANT.NORMAL}], |
| 509 |
top: ['22A4',{mathvariant: MML.VARIANT.NORMAL}], |
| 510 |
bot: ['22A5',{mathvariant: MML.VARIANT.NORMAL}], |
| 511 |
angle: ['2220',{mathvariant: MML.VARIANT.NORMAL}], |
| 512 |
triangle: ['25B3',{mathvariant: MML.VARIANT.NORMAL}], |
| 513 |
backslash: ['2216',{mathvariant: MML.VARIANT.NORMAL, variantForm:true}], |
| 514 |
forall: ['2200',{mathvariant: MML.VARIANT.NORMAL}], |
| 515 |
exists: ['2203',{mathvariant: MML.VARIANT.NORMAL}], |
| 516 |
neg: ['00AC',{mathvariant: MML.VARIANT.NORMAL}], |
| 517 |
lnot: ['00AC',{mathvariant: MML.VARIANT.NORMAL}], |
| 518 |
flat: ['266D',{mathvariant: MML.VARIANT.NORMAL}], |
| 519 |
natural: ['266E',{mathvariant: MML.VARIANT.NORMAL}], |
| 520 |
sharp: ['266F',{mathvariant: MML.VARIANT.NORMAL}], |
| 521 |
clubsuit: ['2663',{mathvariant: MML.VARIANT.NORMAL}], |
| 522 |
diamondsuit: ['2662',{mathvariant: MML.VARIANT.NORMAL}], |
| 523 |
heartsuit: ['2661',{mathvariant: MML.VARIANT.NORMAL}], |
| 524 |
spadesuit: ['2660',{mathvariant: MML.VARIANT.NORMAL}] |
| 525 |
}, |
| 526 |
|
| 527 |
mathchar0mo: { |
| 528 |
surd: '221A', |
| 529 |
|
| 530 |
// big ops |
| 531 |
coprod: ['2210',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 532 |
bigvee: ['22C1',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 533 |
bigwedge: ['22C0',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 534 |
biguplus: ['2A04',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 535 |
bigcap: ['22C2',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 536 |
bigcup: ['22C3',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 537 |
'int': ['222B',{texClass: MML.TEXCLASS.OP}], |
| 538 |
intop: ['222B',{texClass: MML.TEXCLASS.OP, movesupsub:true, movablelimits:true}], |
| 539 |
iint: ['222C',{texClass: MML.TEXCLASS.OP}], |
| 540 |
iiint: ['222D',{texClass: MML.TEXCLASS.OP}], |
| 541 |
prod: ['220F',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 542 |
sum: ['2211',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 543 |
bigotimes: ['2A02',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 544 |
bigoplus: ['2A01',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 545 |
bigodot: ['2A00',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 546 |
oint: ['222E',{texClass: MML.TEXCLASS.OP}], |
| 547 |
bigsqcup: ['2A06',{texClass: MML.TEXCLASS.OP, movesupsub:true}], |
| 548 |
smallint: ['222B',{largeop:false}], |
| 549 |
|
| 550 |
// binary operations |
| 551 |
triangleleft: '25C3', |
| 552 |
triangleright: '25B9', |
| 553 |
bigtriangleup: '25B3', |
| 554 |
bigtriangledown: '25BD', |
| 555 |
wedge: '2227', |
| 556 |
land: '2227', |
| 557 |
vee: '2228', |
| 558 |
lor: '2228', |
| 559 |
cap: '2229', |
| 560 |
cup: '222A', |
| 561 |
ddagger: '2021', |
| 562 |
dagger: '2020', |
| 563 |
sqcap: '2293', |
| 564 |
sqcup: '2294', |
| 565 |
uplus: '228E', |
| 566 |
amalg: '2A3F', |
| 567 |
diamond: '22C4', |
| 568 |
bullet: '2219', |
| 569 |
wr: '2240', |
| 570 |
div: '00F7', |
| 571 |
odot: ['2299',{largeop: false}], |
| 572 |
oslash: ['2298',{largeop: false}], |
| 573 |
otimes: ['2297',{largeop: false}], |
| 574 |
ominus: ['2296',{largeop: false}], |
| 575 |
oplus: ['2295',{largeop: false}], |
| 576 |
mp: '2213', |
| 577 |
pm: '00B1', |
| 578 |
circ: '2218', |
| 579 |
bigcirc: '25EF', |
| 580 |
setminus: ['2216',{variantForm:true}], |
| 581 |
cdot: '22C5', |
| 582 |
ast: '2217', |
| 583 |
times: '00D7', |
| 584 |
star: '22C6', |
| 585 |
|
| 586 |
// Relations |
| 587 |
propto: '221D', |
| 588 |
sqsubseteq: '2291', |
| 589 |
sqsupseteq: '2292', |
| 590 |
parallel: '2225', |
| 591 |
mid: '2223', |
| 592 |
dashv: '22A3', |
| 593 |
vdash: '22A2', |
| 594 |
leq: '2264', |
| 595 |
le: '2264', |
| 596 |
geq: '2265', |
| 597 |
ge: '2265', |
| 598 |
lt: '003C', |
| 599 |
gt: '003E', |
| 600 |
succ: '227B', |
| 601 |
prec: '227A', |
| 602 |
approx: '2248', |
| 603 |
succeq: '2AB0', // or '227C', |
| 604 |
preceq: '2AAF', // or '227D', |
| 605 |
supset: '2283', |
| 606 |
subset: '2282', |
| 607 |
supseteq: '2287', |
| 608 |
subseteq: '2286', |
| 609 |
'in': '2208', |
| 610 |
ni: '220B', |
| 611 |
notin: '2209', |
| 612 |
owns: '220B', |
| 613 |
gg: '226B', |
| 614 |
ll: '226A', |
| 615 |
sim: '223C', |
| 616 |
simeq: '2243', |
| 617 |
perp: '22A5', |
| 618 |
equiv: '2261', |
| 619 |
asymp: '224D', |
| 620 |
smile: '2323', |
| 621 |
frown: '2322', |
| 622 |
ne: '2260', |
| 623 |
neq: '2260', |
| 624 |
cong: '2245', |
| 625 |
doteq: '2250', |
| 626 |
bowtie: '22C8', |
| 627 |
models: '22A8', |
| 628 |
|
| 629 |
notChar: '29F8', |
| 630 |
|
| 631 |
|
| 632 |
// Arrows |
| 633 |
Leftrightarrow: '21D4', |
| 634 |
Leftarrow: '21D0', |
| 635 |
Rightarrow: '21D2', |
| 636 |
leftrightarrow: '2194', |
| 637 |
leftarrow: '2190', |
| 638 |
gets: '2190', |
| 639 |
rightarrow: '2192', |
| 640 |
to: '2192', |
| 641 |
mapsto: '21A6', |
| 642 |
leftharpoonup: '21BC', |
| 643 |
leftharpoondown: '21BD', |
| 644 |
rightharpoonup: '21C0', |
| 645 |
rightharpoondown: '21C1', |
| 646 |
nearrow: '2197', |
| 647 |
searrow: '2198', |
| 648 |
nwarrow: '2196', |
| 649 |
swarrow: '2199', |
| 650 |
rightleftharpoons: '21CC', |
| 651 |
hookrightarrow: '21AA', |
| 652 |
hookleftarrow: '21A9', |
| 653 |
longleftarrow: '27F5', |
| 654 |
Longleftarrow: '27F8', |
| 655 |
longrightarrow: '27F6', |
| 656 |
Longrightarrow: '27F9', |
| 657 |
Longleftrightarrow: '27FA', |
| 658 |
longleftrightarrow: '27F7', |
| 659 |
longmapsto: '27FC', |
| 660 |
|
| 661 |
|
| 662 |
// Misc. |
| 663 |
ldots: '2026', |
| 664 |
cdots: '22EF', |
| 665 |
vdots: '22EE', |
| 666 |
ddots: '22F1', |
| 667 |
dotsc: '2026', // dots with commas |
| 668 |
dotsb: '22EF', // dots with binary ops and relations |
| 669 |
dotsm: '22EF', // dots with multiplication |
| 670 |
dotsi: '22EF', // dots with integrals |
| 671 |
dotso: '2026', // other dots |
| 672 |
|
| 673 |
ldotp: ['002E', {texClass: MML.TEXCLASS.PUNCT}], |
| 674 |
cdotp: ['22C5', {texClass: MML.TEXCLASS.PUNCT}], |
| 675 |
colon: ['003A', {texClass: MML.TEXCLASS.PUNCT}] |
| 676 |
}, |
| 677 |
|
| 678 |
mathchar7: { |
| 679 |
Gamma: '0393', |
| 680 |
Delta: '0394', |
| 681 |
Theta: '0398', |
| 682 |
Lambda: '039B', |
| 683 |
Xi: '039E', |
| 684 |
Pi: '03A0', |
| 685 |
Sigma: '03A3', |
| 686 |
Upsilon: '03A5', |
| 687 |
Phi: '03A6', |
| 688 |
Psi: '03A8', |
| 689 |
Omega: '03A9', |
| 690 |
|
| 691 |
'_': '005F', |
| 692 |
'#': '0023', |
| 693 |
'$': '0024', |
| 694 |
'%': '0025', |
| 695 |
'&': '0026', |
| 696 |
And: '0026' |
| 697 |
}, |
| 698 |
|
| 699 |
delimiter: { |
| 700 |
'(': '(', |
| 701 |
')': ')', |
| 702 |
'[': '[', |
| 703 |
']': ']', |
| 704 |
'<': '27E8', |
| 705 |
'>': '27E9', |
| 706 |
'\\lt': '27E8', |
| 707 |
'\\gt': '27E9', |
| 708 |
'/': '/', |
| 709 |
'|': ['|',{texClass:MML.TEXCLASS.ORD}], |
| 710 |
'.': '', |
| 711 |
'\\\\': '\\', |
| 712 |
'\\lmoustache': '23B0', // non-standard |
| 713 |
'\\rmoustache': '23B1', // non-standard |
| 714 |
'\\lgroup': '27EE', // non-standard |
| 715 |
'\\rgroup': '27EF', // non-standard |
| 716 |
'\\arrowvert': '23D0', |
| 717 |
'\\Arrowvert': '2016', |
| 718 |
'\\bracevert': '23AA', // non-standard |
| 719 |
'\\Vert': ['2016',{texClass:MML.TEXCLASS.ORD}], |
| 720 |
'\\|': ['2016',{texClass:MML.TEXCLASS.ORD}], |
| 721 |
'\\vert': ['|',{texClass:MML.TEXCLASS.ORD}], |
| 722 |
'\\uparrow': '2191', |
| 723 |
'\\downarrow': '2193', |
| 724 |
'\\updownarrow': '2195', |
| 725 |
'\\Uparrow': '21D1', |
| 726 |
'\\Downarrow': '21D3', |
| 727 |
'\\Updownarrow': '21D5', |
| 728 |
'\\backslash': '\\', |
| 729 |
'\\rangle': '27E9', |
| 730 |
'\\langle': '27E8', |
| 731 |
'\\rbrace': '}', |
| 732 |
'\\lbrace': '{', |
| 733 |
'\\}': '}', |
| 734 |
'\\{': '{', |
| 735 |
'\\rceil': '2309', |
| 736 |
'\\lceil': '2308', |
| 737 |
'\\rfloor': '230B', |
| 738 |
'\\lfloor': '230A', |
| 739 |
'\\lbrack': '[', |
| 740 |
'\\rbrack': ']' |
| 741 |
}, |
| 742 |
|
| 743 |
macros: { |
| 744 |
displaystyle: ['SetStyle','D',true,0], |
| 745 |
textstyle: ['SetStyle','T',false,0], |
| 746 |
scriptstyle: ['SetStyle','S',false,1], |
| 747 |
scriptscriptstyle: ['SetStyle','SS',false,2], |
| 748 |
|
| 749 |
rm: ['SetFont',MML.VARIANT.NORMAL], |
| 750 |
mit: ['SetFont',MML.VARIANT.ITALIC], |
| 751 |
oldstyle: ['SetFont',MML.VARIANT.OLDSTYLE], |
| 752 |
cal: ['SetFont',MML.VARIANT.CALIGRAPHIC], |
| 753 |
it: ['SetFont',"-tex-mathit"], // needs special handling |
| 754 |
bf: ['SetFont',MML.VARIANT.BOLD], |
| 755 |
bbFont: ['SetFont',MML.VARIANT.DOUBLESTRUCK], |
| 756 |
scr: ['SetFont',MML.VARIANT.SCRIPT], |
| 757 |
frak: ['SetFont',MML.VARIANT.FRAKTUR], |
| 758 |
sf: ['SetFont',MML.VARIANT.SANSSERIF], |
| 759 |
tt: ['SetFont',MML.VARIANT.MONOSPACE], |
| 760 |
|
| 761 |
// font: |
| 762 |
|
| 763 |
tiny: ['SetSize',0.5], |
| 764 |
Tiny: ['SetSize',0.6], // non-standard |
| 765 |
scriptsize: ['SetSize',0.7], |
| 766 |
small: ['SetSize',0.85], |
| 767 |
normalsize: ['SetSize',1.0], |
| 768 |
large: ['SetSize',1.2], |
| 769 |
Large: ['SetSize',1.44], |
| 770 |
LARGE: ['SetSize',1.73], |
| 771 |
huge: ['SetSize',2.07], |
| 772 |
Huge: ['SetSize',2.49], |
| 773 |
|
| 774 |
arcsin: ['NamedFn'], |
| 775 |
arccos: ['NamedFn'], |
| 776 |
arctan: ['NamedFn'], |
| 777 |
arg: ['NamedFn'], |
| 778 |
cos: ['NamedFn'], |
| 779 |
cosh: ['NamedFn'], |
| 780 |
cot: ['NamedFn'], |
| 781 |
coth: ['NamedFn'], |
| 782 |
csc: ['NamedFn'], |
| 783 |
deg: ['NamedFn'], |
| 784 |
det: 'NamedOp', |
| 785 |
dim: ['NamedFn'], |
| 786 |
exp: ['NamedFn'], |
| 787 |
gcd: 'NamedOp', |
| 788 |
hom: ['NamedFn'], |
| 789 |
inf: 'NamedOp', |
| 790 |
ker: ['NamedFn'], |
| 791 |
lg: ['NamedFn'], |
| 792 |
lim: 'NamedOp', |
| 793 |
liminf: ['NamedOp','lim inf'], |
| 794 |
limsup: ['NamedOp','lim sup'], |
| 795 |
ln: ['NamedFn'], |
| 796 |
log: ['NamedFn'], |
| 797 |
max: 'NamedOp', |
| 798 |
min: 'NamedOp', |
| 799 |
Pr: 'NamedOp', |
| 800 |
sec: ['NamedFn'], |
| 801 |
sin: ['NamedFn'], |
| 802 |
sinh: ['NamedFn'], |
| 803 |
sup: 'NamedOp', |
| 804 |
tan: ['NamedFn'], |
| 805 |
tanh: ['NamedFn'], |
| 806 |
|
| 807 |
limits: ['Limits',1], |
| 808 |
nolimits: ['Limits',0], |
| 809 |
|
| 810 |
overline: ['UnderOver','00AF',null,1], |
| 811 |
underline: ['UnderOver','005F'], |
| 812 |
overbrace: ['UnderOver','23DE',1], |
| 813 |
underbrace: ['UnderOver','23DF',1], |
| 814 |
overparen: ['UnderOver','23DC'], |
| 815 |
underparen: ['UnderOver','23DD'], |
| 816 |
overrightarrow: ['UnderOver','2192'], |
| 817 |
underrightarrow: ['UnderOver','2192'], |
| 818 |
overleftarrow: ['UnderOver','2190'], |
| 819 |
underleftarrow: ['UnderOver','2190'], |
| 820 |
overleftrightarrow: ['UnderOver','2194'], |
| 821 |
underleftrightarrow: ['UnderOver','2194'], |
| 822 |
|
| 823 |
overset: 'Overset', |
| 824 |
underset: 'Underset', |
| 825 |
stackrel: ['Macro','\\mathrel{\\mathop{#2}\\limits^{#1}}',2], |
| 826 |
|
| 827 |
over: 'Over', |
| 828 |
overwithdelims: 'Over', |
| 829 |
atop: 'Over', |
| 830 |
atopwithdelims: 'Over', |
| 831 |
above: 'Over', |
| 832 |
abovewithdelims: 'Over', |
| 833 |
brace: ['Over','{','}'], |
| 834 |
brack: ['Over','[',']'], |
| 835 |
choose: ['Over','(',')'], |
| 836 |
|
| 837 |
frac: 'Frac', |
| 838 |
sqrt: 'Sqrt', |
| 839 |
root: 'Root', |
| 840 |
uproot: ['MoveRoot','upRoot'], |
| 841 |
leftroot: ['MoveRoot','leftRoot'], |
| 842 |
|
| 843 |
left: 'LeftRight', |
| 844 |
right: 'LeftRight', |
| 845 |
middle: 'Middle', |
| 846 |
|
| 847 |
llap: 'Lap', |
| 848 |
rlap: 'Lap', |
| 849 |
raise: 'RaiseLower', |
| 850 |
lower: 'RaiseLower', |
| 851 |
moveleft: 'MoveLeftRight', |
| 852 |
moveright: 'MoveLeftRight', |
| 853 |
|
| 854 |
',': ['Spacer',MML.LENGTH.THINMATHSPACE], |
| 855 |
':': ['Spacer',MML.LENGTH.MEDIUMMATHSPACE], // for LaTeX |
| 856 |
'>': ['Spacer',MML.LENGTH.MEDIUMMATHSPACE], |
| 857 |
';': ['Spacer',MML.LENGTH.THICKMATHSPACE], |
| 858 |
'!': ['Spacer',MML.LENGTH.NEGATIVETHINMATHSPACE], |
| 859 |
enspace: ['Spacer',".5em"], |
| 860 |
quad: ['Spacer',"1em"], |
| 861 |
qquad: ['Spacer',"2em"], |
| 862 |
thinspace: ['Spacer',MML.LENGTH.THINMATHSPACE], |
| 863 |
negthinspace: ['Spacer',MML.LENGTH.NEGATIVETHINMATHSPACE], |
| 864 |
|
| 865 |
hskip: 'Hskip', |
| 866 |
hspace: 'Hskip', |
| 867 |
kern: 'Hskip', |
| 868 |
mskip: 'Hskip', |
| 869 |
mspace: 'Hskip', |
| 870 |
mkern: 'Hskip', |
| 871 |
rule: 'rule', |
| 872 |
Rule: ['Rule'], |
| 873 |
Space: ['Rule','blank'], |
| 874 |
|
| 875 |
big: ['MakeBig',MML.TEXCLASS.ORD,0.85], |
| 876 |
Big: ['MakeBig',MML.TEXCLASS.ORD,1.15], |
| 877 |
bigg: ['MakeBig',MML.TEXCLASS.ORD,1.45], |
| 878 |
Bigg: ['MakeBig',MML.TEXCLASS.ORD,1.75], |
| 879 |
bigl: ['MakeBig',MML.TEXCLASS.OPEN,0.85], |
| 880 |
Bigl: ['MakeBig',MML.TEXCLASS.OPEN,1.15], |
| 881 |
biggl: ['MakeBig',MML.TEXCLASS.OPEN,1.45], |
| 882 |
Biggl: ['MakeBig',MML.TEXCLASS.OPEN,1.75], |
| 883 |
bigr: ['MakeBig',MML.TEXCLASS.CLOSE,0.85], |
| 884 |
Bigr: ['MakeBig',MML.TEXCLASS.CLOSE,1.15], |
| 885 |
biggr: ['MakeBig',MML.TEXCLASS.CLOSE,1.45], |
| 886 |
Biggr: ['MakeBig',MML.TEXCLASS.CLOSE,1.75], |
| 887 |
bigm: ['MakeBig',MML.TEXCLASS.REL,0.85], |
| 888 |
Bigm: ['MakeBig',MML.TEXCLASS.REL,1.15], |
| 889 |
biggm: ['MakeBig',MML.TEXCLASS.REL,1.45], |
| 890 |
Biggm: ['MakeBig',MML.TEXCLASS.REL,1.75], |
| 891 |
|
| 892 |
mathord: ['TeXAtom',MML.TEXCLASS.ORD], |
| 893 |
mathop: ['TeXAtom',MML.TEXCLASS.OP], |
| 894 |
mathopen: ['TeXAtom',MML.TEXCLASS.OPEN], |
| 895 |
mathclose: ['TeXAtom',MML.TEXCLASS.CLOSE], |
| 896 |
mathbin: ['TeXAtom',MML.TEXCLASS.BIN], |
| 897 |
mathrel: ['TeXAtom',MML.TEXCLASS.REL], |
| 898 |
mathpunct: ['TeXAtom',MML.TEXCLASS.PUNCT], |
| 899 |
mathinner: ['TeXAtom',MML.TEXCLASS.INNER], |
| 900 |
|
| 901 |
vcenter: ['TeXAtom',MML.TEXCLASS.VCENTER], |
| 902 |
|
| 903 |
mathchoice: ['Extension','mathchoice'], |
| 904 |
buildrel: 'BuildRel', |
| 905 |
|
| 906 |
hbox: ['HBox',0], |
| 907 |
text: 'HBox', |
| 908 |
mbox: ['HBox',0], |
| 909 |
fbox: 'FBox', |
| 910 |
|
| 911 |
strut: 'Strut', |
| 912 |
mathstrut: ['Macro','\\vphantom{(}'], |
| 913 |
phantom: 'Phantom', |
| 914 |
vphantom: ['Phantom',1,0], |
| 915 |
hphantom: ['Phantom',0,1], |
| 916 |
smash: 'Smash', |
| 917 |
|
| 918 |
acute: ['Accent', "00B4"], // or 0301 or 02CA |
| 919 |
grave: ['Accent', "0060"], // or 0300 or 02CB |
| 920 |
ddot: ['Accent', "00A8"], // or 0308 |
| 921 |
tilde: ['Accent', "007E"], // or 0303 or 02DC |
| 922 |
bar: ['Accent', "00AF"], // or 0304 or 02C9 |
| 923 |
breve: ['Accent', "02D8"], // or 0306 |
| 924 |
check: ['Accent', "02C7"], // or 030C |
| 925 |
hat: ['Accent', "005E"], // or 0302 or 02C6 |
| 926 |
vec: ['Accent', "2192"], // or 20D7 |
| 927 |
dot: ['Accent', "02D9"], // or 0307 |
| 928 |
widetilde: ['Accent', "007E",1], // or 0303 or 02DC |
| 929 |
widehat: ['Accent', "005E",1], // or 0302 or 02C6 |
| 930 |
|
| 931 |
matrix: 'Matrix', |
| 932 |
array: 'Matrix', |
| 933 |
pmatrix: ['Matrix','(',')'], |
| 934 |
cases: ['Matrix','{','',"left left",null,".1em",null,true], |
| 935 |
eqalign: ['Matrix',null,null,"right left",MML.LENGTH.THICKMATHSPACE,".5em",'D'], |
| 936 |
displaylines: ['Matrix',null,null,"center",null,".5em",'D'], |
| 937 |
cr: 'Cr', |
| 938 |
'\\': 'CrLaTeX', |
| 939 |
newline: ['CrLaTeX',true], |
| 940 |
hline: ['HLine','solid'], |
| 941 |
hdashline: ['HLine','dashed'], |
| 942 |
// noalign: 'HandleNoAlign', |
| 943 |
eqalignno: ['Matrix',null,null,"right left",MML.LENGTH.THICKMATHSPACE,".5em",'D',null,"right"], |
| 944 |
leqalignno: ['Matrix',null,null,"right left",MML.LENGTH.THICKMATHSPACE,".5em",'D',null,"left"], |
| 945 |
hfill: 'HFill', |
| 946 |
hfil: 'HFill', // \hfil treated as \hfill for now |
| 947 |
hfilll: 'HFill', // \hfilll treated as \hfill for now |
| 948 |
|
| 949 |
// TeX substitution macros |
| 950 |
bmod: ['Macro','\\mmlToken{mo}[lspace="thickmathspace" rspace="thickmathspace"]{mod}'], |
| 951 |
pmod: ['Macro','\\pod{\\mmlToken{mi}{mod}\\kern 6mu #1}',1], |
| 952 |
mod: ['Macro','\\mathchoice{\\kern18mu}{\\kern12mu}{\\kern12mu}{\\kern12mu}\\mmlToken{mi}{mod}\\,\\,#1',1], |
| 953 |
pod: ['Macro','\\mathchoice{\\kern18mu}{\\kern8mu}{\\kern8mu}{\\kern8mu}(#1)',1], |
| 954 |
iff: ['Macro','\\;\\Longleftrightarrow\\;'], |
| 955 |
skew: ['Macro','{{#2{#3\\mkern#1mu}\\mkern-#1mu}{}}',3], |
| 956 |
mathcal: ['Macro','{\\cal #1}',1], |
| 957 |
mathscr: ['Macro','{\\scr #1}',1], |
| 958 |
mathrm: ['Macro','{\\rm #1}',1], |
| 959 |
mathbf: ['Macro','{\\bf #1}',1], |
| 960 |
mathbb: ['Macro','{\\bbFont #1}',1], |
| 961 |
Bbb: ['Macro','{\\bbFont #1}',1], |
| 962 |
mathit: ['Macro','{\\it #1}',1], |
| 963 |
mathfrak: ['Macro','{\\frak #1}',1], |
| 964 |
mathsf: ['Macro','{\\sf #1}',1], |
| 965 |
mathtt: ['Macro','{\\tt #1}',1], |
| 966 |
textrm: ['Macro','\\mathord{\\rm\\text{#1}}',1], |
| 967 |
textit: ['Macro','\\mathord{\\it\\text{#1}}',1], |
| 968 |
textbf: ['Macro','\\mathord{\\bf\\text{#1}}',1], |
| 969 |
textsf: ['Macro','\\mathord{\\sf\\text{#1}}',1], |
| 970 |
texttt: ['Macro','\\mathord{\\tt\\text{#1}}',1], |
| 971 |
pmb: ['Macro','\\rlap{#1}\\kern1px{#1}',1], |
| 972 |
TeX: ['Macro','T\\kern-.14em\\lower.5ex{E}\\kern-.115em X'], |
| 973 |
LaTeX: ['Macro','L\\kern-.325em\\raise.21em{\\scriptstyle{A}}\\kern-.17em\\TeX'], |
| 974 |
' ': ['Macro','\\text{ }'], |
| 975 |
|
| 976 |
// Specially handled |
| 977 |
not: 'Not', |
| 978 |
dots: 'Dots', |
| 979 |
space: 'Tilde', |
| 980 |
'\u00A0': 'Tilde', |
| 981 |
|
| 982 |
|
| 983 |
// LaTeX |
| 984 |
begin: 'BeginEnd', |
| 985 |
end: 'BeginEnd', |
| 986 |
|
| 987 |
newcommand: ['Extension','newcommand'], |
| 988 |
renewcommand: ['Extension','newcommand'], |
| 989 |
newenvironment: ['Extension','newcommand'], |
| 990 |
renewenvironment: ['Extension','newcommand'], |
| 991 |
def: ['Extension','newcommand'], |
| 992 |
'let': ['Extension','newcommand'], |
| 993 |
|
| 994 |
verb: ['Extension','verb'], |
| 995 |
|
| 996 |
boldsymbol: ['Extension','boldsymbol'], |
| 997 |
|
| 998 |
tag: ['Extension','AMSmath'], |
| 999 |
notag: ['Extension','AMSmath'], |
| 1000 |
label: ['Extension','AMSmath'], |
| 1001 |
ref: ['Extension','AMSmath'], |
| 1002 |
eqref: ['Extension','AMSmath'], |
| 1003 |
nonumber: ['Macro','\\notag'], |
| 1004 |
|
| 1005 |
// Extensions to TeX |
| 1006 |
unicode: ['Extension','unicode'], |
| 1007 |
color: 'Color', |
| 1008 |
|
| 1009 |
href: ['Extension','HTML'], |
| 1010 |
'class': ['Extension','HTML'], |
| 1011 |
style: ['Extension','HTML'], |
| 1012 |
cssId: ['Extension','HTML'], |
| 1013 |
bbox: ['Extension','bbox'], |
| 1014 |
|
| 1015 |
mmlToken: 'MmlToken', |
| 1016 |
|
| 1017 |
require: 'Require' |
| 1018 |
|
| 1019 |
}, |
| 1020 |
|
| 1021 |
environment: { |
| 1022 |
array: ['AlignedArray'], |
| 1023 |
matrix: ['Array',null,null,null,'c'], |
| 1024 |
pmatrix: ['Array',null,'(',')','c'], |
| 1025 |
bmatrix: ['Array',null,'[',']','c'], |
| 1026 |
Bmatrix: ['Array',null,'\\{','\\}','c'], |
| 1027 |
vmatrix: ['Array',null,'\\vert','\\vert','c'], |
| 1028 |
Vmatrix: ['Array',null,'\\Vert','\\Vert','c'], |
| 1029 |
cases: ['Array',null,'\\{','.','ll',null,".2em",'T'], |
| 1030 |
|
| 1031 |
equation: [null,'Equation'], |
| 1032 |
'equation*': [null,'Equation'], |
| 1033 |
|
| 1034 |
eqnarray: ['ExtensionEnv',null,'AMSmath'], |
| 1035 |
'eqnarray*': ['ExtensionEnv',null,'AMSmath'], |
| 1036 |
|
| 1037 |
align: ['ExtensionEnv',null,'AMSmath'], |
| 1038 |
'align*': ['ExtensionEnv',null,'AMSmath'], |
| 1039 |
aligned: ['ExtensionEnv',null,'AMSmath'], |
| 1040 |
multline: ['ExtensionEnv',null,'AMSmath'], |
| 1041 |
'multline*': ['ExtensionEnv',null,'AMSmath'], |
| 1042 |
split: ['ExtensionEnv',null,'AMSmath'], |
| 1043 |
gather: ['ExtensionEnv',null,'AMSmath'], |
| 1044 |
'gather*': ['ExtensionEnv',null,'AMSmath'], |
| 1045 |
gathered: ['ExtensionEnv',null,'AMSmath'], |
| 1046 |
alignat: ['ExtensionEnv',null,'AMSmath'], |
| 1047 |
'alignat*': ['ExtensionEnv',null,'AMSmath'], |
| 1048 |
alignedat: ['ExtensionEnv',null,'AMSmath'] |
| 1049 |
}, |
| 1050 |
|
| 1051 |
p_height: 1.2 / .85 // cmex10 height plus depth over .85 |
| 1052 |
|
| 1053 |
}); |
| 1054 |
|
| 1055 |
// |
| 1056 |
// Add macros defined in the configuration |
| 1057 |
// |
| 1058 |
if (this.config.Macros) { |
| 1059 |
var MACROS = this.config.Macros; |
| 1060 |
for (var id in MACROS) {if (MACROS.hasOwnProperty(id)) { |
| 1061 |
if (typeof(MACROS[id]) === "string") {TEXDEF.macros[id] = ['Macro',MACROS[id]]} |
| 1062 |
else {TEXDEF.macros[id] = ["Macro"].concat(MACROS[id])} |
| 1063 |
TEXDEF.macros[id].isUser = true; |
| 1064 |
}} |
| 1065 |
} |
| 1066 |
}; |
| 1067 |
|
| 1068 |
/************************************************************************/ |
| 1069 |
/* |
| 1070 |
* The TeX Parser |
| 1071 |
*/ |
| 1072 |
|
| 1073 |
var PARSE = MathJax.Object.Subclass({ |
| 1074 |
Init: function (string,env) { |
| 1075 |
this.string = string; this.i = 0; this.macroCount = 0; |
| 1076 |
var ENV; if (env) {ENV = {}; for (var id in env) {if (env.hasOwnProperty(id)) {ENV[id] = env[id]}}} |
| 1077 |
this.stack = TEX.Stack(ENV,!!env); |
| 1078 |
this.Parse(); this.Push(STACKITEM.stop()); |
| 1079 |
}, |
| 1080 |
Parse: function () { |
| 1081 |
var c, n; |
| 1082 |
while (this.i < this.string.length) { |
| 1083 |
c = this.string.charAt(this.i++); n = c.charCodeAt(0); |
| 1084 |
if (n >= 0xD800 && n < 0xDC00) {c += this.string.charAt(this.i++)} |
| 1085 |
if (TEXDEF.special.hasOwnProperty(c)) {this[TEXDEF.special[c]](c)} |
| 1086 |
else if (TEXDEF.letter.test(c)) {this.Variable(c)} |
| 1087 |
else if (TEXDEF.digit.test(c)) {this.Number(c)} |
| 1088 |
else {this.Other(c)} |
| 1089 |
} |
| 1090 |
}, |
| 1091 |
Push: function () {this.stack.Push.apply(this.stack,arguments)}, |
| 1092 |
mml: function () { |
| 1093 |
if (this.stack.Top().type !== "mml") {return null} |
| 1094 |
return this.stack.Top().data[0]; |
| 1095 |
}, |
| 1096 |
mmlToken: function (token) {return token}, // used by boldsymbol extension |
| 1097 |
|
| 1098 |
/************************************************************************/ |
| 1099 |
/* |
| 1100 |
* Handle various token classes |
| 1101 |
*/ |
| 1102 |
|
| 1103 |
/* |
| 1104 |
* Lookup a control-sequence and process it |
| 1105 |
*/ |
| 1106 |
ControlSequence: function (c) { |
| 1107 |
var name = this.GetCS(), macro = this.csFindMacro(name); |
| 1108 |
if (macro) { |
| 1109 |
if (!isArray(macro)) {macro = [macro]} |
| 1110 |
var fn = macro[0]; if (!(fn instanceof Function)) {fn = this[fn]} |
| 1111 |
fn.apply(this,[c+name].concat(macro.slice(1))); |
| 1112 |
} else if (TEXDEF.mathchar0mi.hasOwnProperty(name)) {this.csMathchar0mi(name,TEXDEF.mathchar0mi[name])} |
| 1113 |
else if (TEXDEF.mathchar0mo.hasOwnProperty(name)) {this.csMathchar0mo(name,TEXDEF.mathchar0mo[name])} |
| 1114 |
else if (TEXDEF.mathchar7.hasOwnProperty(name)) {this.csMathchar7(name,TEXDEF.mathchar7[name])} |
| 1115 |
else if (TEXDEF.delimiter.hasOwnProperty("\\"+name)) {this.csDelimiter(name,TEXDEF.delimiter["\\"+name])} |
| 1116 |
else {this.csUndefined(c+name)} |
| 1117 |
}, |
| 1118 |
// |
| 1119 |
// Look up a macro in the macros list |
| 1120 |
// (overridden in begingroup extension) |
| 1121 |
// |
| 1122 |
csFindMacro: function (name) { |
| 1123 |
return (TEXDEF.macros.hasOwnProperty(name) ? TEXDEF.macros[name] : null); |
| 1124 |
}, |
| 1125 |
// |
| 1126 |
// Handle normal mathchar (as an mi) |
| 1127 |
// |
| 1128 |
csMathchar0mi: function (name,mchar) { |
| 1129 |
var def = {mathvariant: MML.VARIANT.ITALIC}; |
| 1130 |
if (isArray(mchar)) {def = mchar[1]; mchar = mchar[0]} |
| 1131 |
this.Push(this.mmlToken(MML.mi(MML.entity("#x"+mchar)).With(def))); |
| 1132 |
}, |
| 1133 |
// |
| 1134 |
// Handle normal mathchar (as an mo) |
| 1135 |
// |
| 1136 |
csMathchar0mo: function (name,mchar) { |
| 1137 |
var def = {stretchy: false}; |
| 1138 |
if (isArray(mchar)) {def = mchar[1]; def.stretchy = false; mchar = mchar[0]} |
| 1139 |
this.Push(this.mmlToken(MML.mo(MML.entity("#x"+mchar)).With(def))); |
| 1140 |
}, |
| 1141 |
// |
| 1142 |
// Handle mathchar in current family |
| 1143 |
// |
| 1144 |
csMathchar7: function (name,mchar) { |
| 1145 |
var def = {mathvariant: MML.VARIANT.NORMAL}; |
| 1146 |
if (isArray(mchar)) {def = mchar[1]; mchar = mchar[0]} |
| 1147 |
if (this.stack.env.font) {def.mathvariant = this.stack.env.font} |
| 1148 |
this.Push(this.mmlToken(MML.mi(MML.entity("#x"+mchar)).With(def))); |
| 1149 |
}, |
| 1150 |
// |
| 1151 |
// Handle delimiter |
| 1152 |
// |
| 1153 |
csDelimiter: function (name,delim) { |
| 1154 |
var def = {}; |
| 1155 |
if (isArray(delim)) {def = delim[1]; delim = delim[0]} |
| 1156 |
if (delim.length === 4) {delim = MML.entity('#x'+delim)} else {delim = MML.chars(delim)} |
| 1157 |
this.Push(this.mmlToken(MML.mo(delim).With({fence: false, stretchy: false}).With(def))); |
| 1158 |
}, |
| 1159 |
// |
| 1160 |
// Handle undefined control sequence |
| 1161 |
// (overridden in noUndefined extension) |
| 1162 |
// |
| 1163 |
csUndefined: function (name) { |
| 1164 |
TEX.Error(["UndefinedControlSequence","Undefined control sequence %1",name]); |
| 1165 |
}, |
| 1166 |
|
| 1167 |
/* |
| 1168 |
* Handle a variable (a single letter) |
| 1169 |
*/ |
| 1170 |
Variable: function (c) { |
| 1171 |
var def = {}; if (this.stack.env.font) {def.mathvariant = this.stack.env.font} |
| 1172 |
this.Push(this.mmlToken(MML.mi(MML.chars(c)).With(def))); |
| 1173 |
}, |
| 1174 |
|
| 1175 |
/* |
| 1176 |
* Determine the extent of a number (pattern may need work) |
| 1177 |
*/ |
| 1178 |
Number: function (c) { |
| 1179 |
var mml, n = this.string.slice(this.i-1).match(TEXDEF.number); |
| 1180 |
if (n) {mml = MML.mn(n[0].replace(/[{}]/g,"")); this.i += n[0].length - 1} |
| 1181 |
else {mml = MML.mo(MML.chars(c))} |
| 1182 |
if (this.stack.env.font) {mml.mathvariant = this.stack.env.font} |
| 1183 |
this.Push(this.mmlToken(mml)); |
| 1184 |
}, |
| 1185 |
|
| 1186 |
/* |
| 1187 |
* Handle { and } |
| 1188 |
*/ |
| 1189 |
Open: function (c) {this.Push(STACKITEM.open())}, |
| 1190 |
Close: function (c) {this.Push(STACKITEM.close())}, |
| 1191 |
|
| 1192 |
/* |
| 1193 |
* Handle tilde and spaces |
| 1194 |
*/ |
| 1195 |
Tilde: function (c) {this.Push(MML.mtext(MML.chars(NBSP)))}, |
| 1196 |
Space: function (c) {}, |
| 1197 |
|
| 1198 |
/* |
| 1199 |
* Handle ^, _, and ' |
| 1200 |
*/ |
| 1201 |
Superscript: function (c) { |
| 1202 |
if (this.GetNext().match(/\d/)) // don't treat numbers as a unit |
| 1203 |
{this.string = this.string.substr(0,this.i+1)+" "+this.string.substr(this.i+1)} |
| 1204 |
var primes, base, top = this.stack.Top(); |
| 1205 |
if (top.type === "prime") {base = top.data[0]; primes = top.data[1]; this.stack.Pop()} |
| 1206 |
else {base = this.stack.Prev(); if (!base) {base = MML.mi("")}} |
| 1207 |
if (base.isEmbellishedWrapper) {base = base.data[0].data[0]} |
| 1208 |
var movesupsub = base.movesupsub, position = base.sup; |
| 1209 |
if ((base.type === "msubsup" && base.data[base.sup]) || |
| 1210 |
(base.type === "munderover" && base.data[base.over] && !base.subsupOK)) |
| 1211 |
{TEX.Error(["DoubleExponent","Double exponent: use braces to clarify"])} |
| 1212 |
if (base.type !== "msubsup") { |
| 1213 |
if (movesupsub) { |
| 1214 |
if (base.type !== "munderover" || base.data[base.over]) { |
| 1215 |
if (base.movablelimits && base.isa(MML.mi)) {base = this.mi2mo(base)} |
| 1216 |
base = MML.munderover(base,null,null).With({movesupsub:true}) |
| 1217 |
} |
| 1218 |
position = base.over; |
| 1219 |
} else { |
| 1220 |
base = MML.msubsup(base,null,null); |
| 1221 |
position = base.sup; |
| 1222 |
} |
| 1223 |
} |
| 1224 |
this.Push(STACKITEM.subsup(base).With({ |
| 1225 |
position: position, primes: primes, movesupsub: movesupsub |
| 1226 |
})); |
| 1227 |
}, |
| 1228 |
Subscript: function (c) { |
| 1229 |
if (this.GetNext().match(/\d/)) // don't treat numbers as a unit |
| 1230 |
{this.string = this.string.substr(0,this.i+1)+" "+this.string.substr(this.i+1)} |
| 1231 |
var primes, base, top = this.stack.Top(); |
| 1232 |
if (top.type === "prime") {base = top.data[0]; primes = top.data[1]; this.stack.Pop()} |
| 1233 |
else {base = this.stack.Prev(); if (!base) {base = MML.mi("")}} |
| 1234 |
if (base.isEmbellishedWrapper) {base = base.data[0].data[0]} |
| 1235 |
var movesupsub = base.movesupsub, position = base.sub; |
| 1236 |
if ((base.type === "msubsup" && base.data[base.sub]) || |
| 1237 |
(base.type === "munderover" && base.data[base.under] && !base.subsupOK)) |
| 1238 |
{TEX.Error(["DoubleSubscripts","Double subscripts: use braces to clarify"])} |
| 1239 |
if (base.type !== "msubsup") { |
| 1240 |
if (movesupsub) { |
| 1241 |
if (base.type !== "munderover" || base.data[base.under]) { |
| 1242 |
if (base.movablelimits && base.isa(MML.mi)) {base = this.mi2mo(base)} |
| 1243 |
base = MML.munderover(base,null,null).With({movesupsub:true}) |
| 1244 |
} |
| 1245 |
position = base.under; |
| 1246 |
} else { |
| 1247 |
base = MML.msubsup(base,null,null); |
| 1248 |
position = base.sub; |
| 1249 |
} |
| 1250 |
} |
| 1251 |
this.Push(STACKITEM.subsup(base).With({ |
| 1252 |
position: position, primes: primes, movesupsub: movesupsub |
| 1253 |
})); |
| 1254 |
}, |
| 1255 |
PRIME: "\u2032", SMARTQUOTE: "\u2019", |
| 1256 |
Prime: function (c) { |
| 1257 |
var base = this.stack.Prev(); if (!base) {base = MML.mi()} |
| 1258 |
if (base.type === "msubsup" && base.data[base.sup]) { |
| 1259 |
TEX.Error(["DoubleExponentPrime", |
| 1260 |
"Prime causes double exponent: use braces to clarify"]); |
| 1261 |
} |
| 1262 |
var sup = ""; this.i--; |
| 1263 |
do {sup += this.PRIME; this.i++, c = this.GetNext()} |
| 1264 |
while (c === "'" || c === this.SMARTQUOTE); |
| 1265 |
sup = ["","\u2032","\u2033","\u2034","\u2057"][sup.length] || sup; |
| 1266 |
this.Push(STACKITEM.prime(base,this.mmlToken(MML.mo(sup)))); |
| 1267 |
}, |
| 1268 |
mi2mo: function (mi) { |
| 1269 |
var mo = MML.mo(); mo.Append.apply(mo,mi.data); var id; |
| 1270 |
for (id in mo.defaults) |
| 1271 |
{if (mo.defaults.hasOwnProperty(id) && mi[id] != null) {mo[id] = mi[id]}} |
| 1272 |
for (id in MML.copyAttributes) |
| 1273 |
{if (MML.copyAttributes.hasOwnProperty(id) && mi[id] != null) {mo[id] = mi[id]}} |
| 1274 |
mo.lspace = mo.rspace = "0"; // prevent mo from having space in NativeMML |
| 1275 |
mo.useMMLspacing &= ~(mo.SPACE_ATTR.lspace | mo.SPACE_ATTR.rspace); // don't count these explicit settings |
| 1276 |
return mo; |
| 1277 |
}, |
| 1278 |
|
| 1279 |
/* |
| 1280 |
* Handle comments |
| 1281 |
*/ |
| 1282 |
Comment: function (c) { |
| 1283 |
while (this.i < this.string.length && this.string.charAt(this.i) != "\n") {this.i++} |
| 1284 |
}, |
| 1285 |
|
| 1286 |
/* |
| 1287 |
* Handle hash marks outside of definitions |
| 1288 |
*/ |
| 1289 |
Hash: function (c) { |
| 1290 |
TEX.Error(["CantUseHash1", |
| 1291 |
"You can't use 'macro parameter character #' in math mode"]); |
| 1292 |
}, |
| 1293 |
|
| 1294 |
/* |
| 1295 |
* Handle other characters (as <mo> elements) |
| 1296 |
*/ |
| 1297 |
Other: function (c) { |
| 1298 |
var def, mo; |
| 1299 |
if (this.stack.env.font) {def = {mathvariant: this.stack.env.font}} |
| 1300 |
if (TEXDEF.remap.hasOwnProperty(c)) { |
| 1301 |
c = TEXDEF.remap[c]; |
| 1302 |
if (isArray(c)) {def = c[1]; c = c[0]} |
| 1303 |
mo = MML.mo(MML.entity('#x'+c)).With(def); |
| 1304 |
} else { |
| 1305 |
mo = MML.mo(c).With(def); |
| 1306 |
} |
| 1307 |
if (mo.autoDefault("stretchy",true)) {mo.stretchy = false} |
| 1308 |
if (mo.autoDefault("texClass",true) == "") {mo = MML.TeXAtom(mo)} |
| 1309 |
this.Push(this.mmlToken(mo)); |
| 1310 |
}, |
| 1311 |
|
| 1312 |
/************************************************************************/ |
| 1313 |
/* |
| 1314 |
* Macros |
| 1315 |
*/ |
| 1316 |
|
| 1317 |
SetFont: function (name,font) {this.stack.env.font = font}, |
| 1318 |
SetStyle: function (name,texStyle,style,level) { |
| 1319 |
this.stack.env.style = texStyle; this.stack.env.level = level; |
| 1320 |
this.Push(STACKITEM.style().With({styles: {displaystyle: style, scriptlevel: level}})); |
| 1321 |
}, |
| 1322 |
SetSize: function (name,size) { |
| 1323 |
this.stack.env.size = size; |
| 1324 |
this.Push(STACKITEM.style().With({styles: {mathsize: size+"em"}})); // convert to absolute? |
| 1325 |
}, |
| 1326 |
|
| 1327 |
Color: function (name) { |
| 1328 |
var color = this.GetArgument(name); |
| 1329 |
var old = this.stack.env.color; this.stack.env.color = color; |
| 1330 |
var math = this.ParseArg(name); |
| 1331 |
if (old) {this.stack.env.color = old} else {delete this.stack.env.color} |
| 1332 |
this.Push(MML.mstyle(math).With({mathcolor: color})); |
| 1333 |
}, |
| 1334 |
|
| 1335 |
Spacer: function (name,space) { |
| 1336 |
this.Push(MML.mspace().With({width: space, mathsize: MML.SIZE.NORMAL, scriptlevel:0})); |
| 1337 |
}, |
| 1338 |
|
| 1339 |
LeftRight: function (name) { |
| 1340 |
this.Push(STACKITEM[name.substr(1)]().With({delim: this.GetDelimiter(name)})); |
| 1341 |
}, |
| 1342 |
|
| 1343 |
Middle: function (name) { |
| 1344 |
var delim = this.GetDelimiter(name); |
| 1345 |
this.Push(MML.TeXAtom().With({texClass:MML.TEXCLASS.CLOSE})); |
| 1346 |
if (this.stack.Top().type !== "left") |
| 1347 |
{TEX.Error(["MisplacedMiddle","%1 must be within \\left and \\right",name])} |
| 1348 |
this.Push(MML.mo(delim).With({stretchy:true})); |
| 1349 |
this.Push(MML.TeXAtom().With({texClass:MML.TEXCLASS.OPEN})); |
| 1350 |
}, |
| 1351 |
|
| 1352 |
NamedFn: function (name,id) { |
| 1353 |
if (!id) {id = name.substr(1)}; |
| 1354 |
var mml = MML.mi(id).With({texClass: MML.TEXCLASS.OP}); |
| 1355 |
this.Push(STACKITEM.fn(this.mmlToken(mml))); |
| 1356 |
}, |
| 1357 |
NamedOp: function (name,id) { |
| 1358 |
if (!id) {id = name.substr(1)}; |
| 1359 |
id = id.replace(/ /,"\u2006"); |
| 1360 |
var mml = MML.mo(id).With({ |
| 1361 |
movablelimits: true, |
| 1362 |
movesupsub: true, |
| 1363 |
form: MML.FORM.PREFIX, |
| 1364 |
texClass: MML.TEXCLASS.OP |
| 1365 |
}); |
| 1366 |
this.Push(this.mmlToken(mml)); |
| 1367 |
}, |
| 1368 |
Limits: function (name,limits) { |
| 1369 |
var op = this.stack.Prev("nopop"); |
| 1370 |
if (!op || (op.Get("texClass") !== MML.TEXCLASS.OP && op.movesupsub == null)) |
| 1371 |
{TEX.Error(["MisplacedLimits","%1 is allowed only on operators",name])} |
| 1372 |
var top = this.stack.Top(); |
| 1373 |
if (op.type === "munderover" && !limits) { |
| 1374 |
op = top.data[top.data.length-1] = MML.msubsup.apply(MML.subsup,op.data); |
| 1375 |
} else if (op.type === "msubsup" && limits) { |
| 1376 |
op = top.data[top.data.length-1] = MML.munderover.apply(MML.underover,op.data); |
| 1377 |
} |
| 1378 |
op.movesupsub = (limits ? true : false); |
| 1379 |
op.Core().movablelimits = false; |
| 1380 |
if (op.movablelimits) op.movablelimits = false; |
| 1381 |
}, |
| 1382 |
|
| 1383 |
Over: function (name,open,close) { |
| 1384 |
var mml = STACKITEM.over().With({name: name}); |
| 1385 |
if (open || close) { |
| 1386 |
mml.open = open; mml.close = close; |
| 1387 |
} else if (name.match(/withdelims$/)) { |
| 1388 |
mml.open = this.GetDelimiter(name); |
| 1389 |
mml.close = this.GetDelimiter(name); |
| 1390 |
} |
| 1391 |
if (name.match(/^\\above/)) {mml.thickness = this.GetDimen(name)} |
| 1392 |
else if (name.match(/^\\atop/) || open || close) {mml.thickness = 0} |
| 1393 |
this.Push(mml); |
| 1394 |
}, |
| 1395 |
|
| 1396 |
Frac: function (name) { |
| 1397 |
var num = this.ParseArg(name); |
| 1398 |
var den = this.ParseArg(name); |
| 1399 |
this.Push(MML.mfrac(num,den)); |
| 1400 |
}, |
| 1401 |
|
| 1402 |
Sqrt: function (name) { |
| 1403 |
var n = this.GetBrackets(name), arg = this.GetArgument(name); |
| 1404 |
if (arg === "\\frac") {arg += "{"+this.GetArgument(arg)+"}{"+this.GetArgument(arg)+"}"} |
| 1405 |
var mml = TEX.Parse(arg,this.stack.env).mml(); |
| 1406 |
if (!n) {mml = MML.msqrt.apply(MML,mml.array())} |
| 1407 |
else {mml = MML.mroot(mml,this.parseRoot(n))} |
| 1408 |
this.Push(mml); |
| 1409 |
}, |
| 1410 |
Root: function (name) { |
| 1411 |
var n = this.GetUpTo(name,"\\of"); |
| 1412 |
var arg = this.ParseArg(name); |
| 1413 |
this.Push(MML.mroot(arg,this.parseRoot(n))); |
| 1414 |
}, |
| 1415 |
parseRoot: function (n) { |
| 1416 |
var env = this.stack.env, inRoot = env.inRoot; env.inRoot = true; |
| 1417 |
var parser = TEX.Parse(n,env); n = parser.mml(); var global = parser.stack.global; |
| 1418 |
if (global.leftRoot || global.upRoot) { |
| 1419 |
n = MML.mpadded(n); |
| 1420 |
if (global.leftRoot) {n.width = global.leftRoot} |
| 1421 |
if (global.upRoot) {n.voffset = global.upRoot; n.height = global.upRoot} |
| 1422 |
} |
| 1423 |
env.inRoot = inRoot; |
| 1424 |
return n; |
| 1425 |
}, |
| 1426 |
MoveRoot: function (name,id) { |
| 1427 |
if (!this.stack.env.inRoot) |
| 1428 |
{TEX.Error(["MisplacedMoveRoot","%1 can appear only within a root",name])} |
| 1429 |
if (this.stack.global[id]) |
| 1430 |
{TEX.Error(["MultipleMoveRoot","Multiple use of %1",name])} |
| 1431 |
var n = this.GetArgument(name); |
| 1432 |
if (!n.match(/-?[0-9]+/)) |
| 1433 |
{TEX.Error(["IntegerArg","The argument to %1 must be an integer",name])} |
| 1434 |
n = (n/15)+"em"; |
| 1435 |
if (n.substr(0,1) !== "-") {n = "+"+n} |
| 1436 |
this.stack.global[id] = n; |
| 1437 |
}, |
| 1438 |
|
| 1439 |
Accent: function (name,accent,stretchy) { |
| 1440 |
var c = this.ParseArg(name); |
| 1441 |
var def = {accent: true}; if (this.stack.env.font) {def.mathvariant = this.stack.env.font} |
| 1442 |
var mml = this.mmlToken(MML.mo(MML.entity("#x"+accent)).With(def)); |
| 1443 |
mml.stretchy = (stretchy ? true : false); |
| 1444 |
var mo = (c.isEmbellished() ? c.CoreMO() : c); |
| 1445 |
if (mo.isa(MML.mo)) mo.movablelimits = false; |
| 1446 |
this.Push(MML.TeXAtom(MML.munderover(c,null,mml).With({accent: true}))); |
| 1447 |
}, |
| 1448 |
|
| 1449 |
UnderOver: function (name,c,stack,noaccent) { |
| 1450 |
var pos = {o: "over", u: "under"}[name.charAt(1)]; |
| 1451 |
var base = this.ParseArg(name); |
| 1452 |
if (base.Get("movablelimits")) {base.movablelimits = false} |
| 1453 |
if (base.isa(MML.munderover) && base.isEmbellished()) { |
| 1454 |
base.Core().With({lspace:0,rspace:0}); // get spacing right for NativeMML |
| 1455 |
base = MML.mrow(MML.mo().With({rspace:0}),base); // add an empty <mi> so it's not embellished any more |
| 1456 |
} |
| 1457 |
var mml = MML.munderover(base,null,null); |
| 1458 |
mml.SetData( |
| 1459 |
mml[pos], |
| 1460 |
this.mmlToken(MML.mo(MML.entity("#x"+c)).With({stretchy:true, accent:!noaccent})) |
| 1461 |
); |
| 1462 |
if (stack) {mml = MML.TeXAtom(mml).With({texClass:MML.TEXCLASS.OP, movesupsub:true})} |
| 1463 |
this.Push(mml.With({subsupOK:true})); |
| 1464 |
}, |
| 1465 |
|
| 1466 |
Overset: function (name) { |
| 1467 |
var top = this.ParseArg(name), base = this.ParseArg(name); |
| 1468 |
base.movablelimits = false; |
| 1469 |
this.Push(MML.mover(base,top)); |
| 1470 |
}, |
| 1471 |
Underset: function (name) { |
| 1472 |
var bot = this.ParseArg(name), base = this.ParseArg(name); |
| 1473 |
base.movablelimits = false; |
| 1474 |
this.Push(MML.munder(base,bot)); |
| 1475 |
}, |
| 1476 |
|
| 1477 |
TeXAtom: function (name,mclass) { |
| 1478 |
var def = {texClass: mclass}, mml; |
| 1479 |
if (mclass == MML.TEXCLASS.OP) { |
| 1480 |
def.movesupsub = def.movablelimits = true; |
| 1481 |
var arg = this.GetArgument(name); |
| 1482 |
var match = arg.match(/^\s*\\rm\s+([a-zA-Z0-9 ]+)$/); |
| 1483 |
if (match) { |
| 1484 |
def.mathvariant = MML.VARIANT.NORMAL; |
| 1485 |
mml = STACKITEM.fn(this.mmlToken(MML.mi(match[1]).With(def))); |
| 1486 |
} else { |
| 1487 |
mml = STACKITEM.fn(MML.TeXAtom(TEX.Parse(arg,this.stack.env).mml()).With(def)); |
| 1488 |
} |
| 1489 |
} else {mml = MML.TeXAtom(this.ParseArg(name)).With(def)} |
| 1490 |
this.Push(mml); |
| 1491 |
}, |
| 1492 |
|
| 1493 |
MmlToken: function (name) { |
| 1494 |
var type = this.GetArgument(name), |
| 1495 |
attr = this.GetBrackets(name,"").replace(/^\s+/,""), |
| 1496 |
data = this.GetArgument(name), |
| 1497 |
def = {attrNames:[]}, match; |
| 1498 |
if (!MML[type] || !MML[type].prototype.isToken) |
| 1499 |
{TEX.Error(["NotMathMLToken","%1 is not a token element",type])} |
| 1500 |
while (attr !== "") { |
| 1501 |
match = attr.match(/^([a-z]+)\s*=\s*('[^']*'|"[^"]*"|[^ ,]*)\s*,?\s*/i); |
| 1502 |
if (!match) |
| 1503 |
{TEX.Error(["InvalidMathMLAttr","Invalid MathML attribute: %1",attr])} |
| 1504 |
if (MML[type].prototype.defaults[match[1]] == null && !this.MmlTokenAllow[match[1]]) { |
| 1505 |
TEX.Error(["UnknownAttrForElement", |
| 1506 |
"%1 is not a recognized attribute for %2", |
| 1507 |
match[1],type]); |
| 1508 |
} |
| 1509 |
var value = this.MmlFilterAttribute(match[1],match[2].replace(/^(['"])(.*)\1$/,"$2")); |
| 1510 |
if (value) { |
| 1511 |
if (value.toLowerCase() === "true") {value = true} |
| 1512 |
else if (value.toLowerCase() === "false") {value = false} |
| 1513 |
def[match[1]] = value; |
| 1514 |
def.attrNames.push(match[1]); |
| 1515 |
} |
| 1516 |
attr = attr.substr(match[0].length); |
| 1517 |
} |
| 1518 |
this.Push(this.mmlToken(MML[type](data).With(def))); |
| 1519 |
}, |
| 1520 |
MmlFilterAttribute: function (name,value) {return value}, |
| 1521 |
MmlTokenAllow: { |
| 1522 |
fontfamily:1, fontsize:1, fontweight:1, fontstyle:1, |
| 1523 |
color:1, background:1, |
| 1524 |
id:1, "class":1, href:1, style:1 |
| 1525 |
}, |
| 1526 |
|
| 1527 |
Strut: function (name) { |
| 1528 |
this.Push(MML.mpadded(MML.mrow()).With({height: "8.6pt", depth: "3pt", width: 0})); |
| 1529 |
}, |
| 1530 |
|
| 1531 |
Phantom: function (name,v,h) { |
| 1532 |
var mml = this.ParseArg(name); |
| 1533 |
if (v || h) { |
| 1534 |
mml = MML.mpadded(mml); |
| 1535 |
if (h) {mml.height = mml.depth = 0} |
| 1536 |
if (v) {mml.width = 0} |
| 1537 |
} |
| 1538 |
this.Push(MML.TeXAtom(MML.mphantom(mml))); |
| 1539 |
}, |
| 1540 |
|
| 1541 |
Smash: function (name) { |
| 1542 |
var bt = this.trimSpaces(this.GetBrackets(name,"")); |
| 1543 |
var smash = MML.mpadded(this.ParseArg(name)); |
| 1544 |
switch (bt) { |
| 1545 |
case "b": smash.depth = 0; break; |
| 1546 |
case "t": smash.height = 0; break; |
| 1547 |
default: smash.height = smash.depth = 0; |
| 1548 |
} |
| 1549 |
this.Push(MML.TeXAtom(smash)); |
| 1550 |
}, |
| 1551 |
|
| 1552 |
Lap: function (name) { |
| 1553 |
var mml = MML.mpadded(this.ParseArg(name)).With({width: 0}); |
| 1554 |
if (name === "\\llap") {mml.lspace = "-1width"} |
| 1555 |
this.Push(MML.TeXAtom(mml)); |
| 1556 |
}, |
| 1557 |
|
| 1558 |
RaiseLower: function (name) { |
| 1559 |
var h = this.GetDimen(name); |
| 1560 |
var item = STACKITEM.position().With({name: name, move: 'vertical'}); |
| 1561 |
if (h.charAt(0) === '-') {h = h.slice(1); name = {raise: "\\lower", lower: "\\raise"}[name.substr(1)]} |
| 1562 |
if (name === "\\lower") {item.dh = '-'+h; item.dd = '+'+h} else {item.dh = '+'+h; item.dd = '-'+h} |
| 1563 |
this.Push(item); |
| 1564 |
}, |
| 1565 |
|
| 1566 |
MoveLeftRight: function (name) { |
| 1567 |
var h = this.GetDimen(name); |
| 1568 |
var nh = (h.charAt(0) === '-' ? h.slice(1) : '-'+h); |
| 1569 |
if (name === "\\moveleft") {var tmp = h; h = nh; nh = tmp} |
| 1570 |
this.Push(STACKITEM.position().With({ |
| 1571 |
name: name, move: 'horizontal', |
| 1572 |
left: MML.mspace().With({width: h, mathsize: MML.SIZE.NORMAL}), |
| 1573 |
right: MML.mspace().With({width: nh, mathsize: MML.SIZE.NORMAL}) |
| 1574 |
})); |
| 1575 |
}, |
| 1576 |
|
| 1577 |
Hskip: function (name) { |
| 1578 |
this.Push(MML.mspace().With({width: this.GetDimen(name), mathsize: MML.SIZE.NORMAL})); |
| 1579 |
}, |
| 1580 |
|
| 1581 |
Rule: function (name,style) { |
| 1582 |
var w = this.GetDimen(name), |
| 1583 |
h = this.GetDimen(name), |
| 1584 |
d = this.GetDimen(name); |
| 1585 |
var def = {width:w, height:h, depth:d}; |
| 1586 |
if (style !== 'blank') { |
| 1587 |
def.mathbackground = (this.stack.env.color || "black"); |
| 1588 |
} |
| 1589 |
this.Push(MML.mspace().With(def)); |
| 1590 |
}, |
| 1591 |
rule: function (name) { |
| 1592 |
var v = this.GetBrackets(name), |
| 1593 |
w = this.GetDimen(name), |
| 1594 |
h = this.GetDimen(name); |
| 1595 |
var mml = MML.mspace().With({ |
| 1596 |
width: w, height:h, |
| 1597 |
mathbackground: (this.stack.env.color || "black") |
| 1598 |
}); |
| 1599 |
if (v) { |
| 1600 |
mml = MML.mpadded(mml).With({voffset: v}); |
| 1601 |
if (v.match(/^\-/)) { |
| 1602 |
mml.height = v; |
| 1603 |
mml.depth = '+' + v.substr(1); |
| 1604 |
} else { |
| 1605 |
mml.height = '+' + v; |
| 1606 |
} |
| 1607 |
} |
| 1608 |
this.Push(mml); |
| 1609 |
}, |
| 1610 |
|
| 1611 |
MakeBig: function (name,mclass,size) { |
| 1612 |
size *= TEXDEF.p_height; |
| 1613 |
size = String(size).replace(/(\.\d\d\d).+/,'$1')+"em"; |
| 1614 |
var delim = this.GetDelimiter(name,true); |
| 1615 |
this.Push(MML.mstyle(MML.TeXAtom(MML.mo(delim).With({ |
| 1616 |
minsize: size, maxsize: size, |
| 1617 |
fence: true, stretchy: true, symmetric: true |
| 1618 |
})).With({texClass: mclass})).With({scriptlevel: 0})); |
| 1619 |
}, |
| 1620 |
|
| 1621 |
BuildRel: function (name) { |
| 1622 |
var top = this.ParseUpTo(name,"\\over"); |
| 1623 |
var bot = this.ParseArg(name); |
| 1624 |
this.Push(MML.TeXAtom(MML.munderover(bot,null,top)).With({texClass: MML.TEXCLASS.REL})); |
| 1625 |
}, |
| 1626 |
|
| 1627 |
HBox: function (name,style) { |
| 1628 |
this.Push.apply(this,this.InternalMath(this.GetArgument(name),style)); |
| 1629 |
}, |
| 1630 |
|
| 1631 |
FBox: function (name) { |
| 1632 |
this.Push(MML.menclose.apply(MML,this.InternalMath(this.GetArgument(name))).With({notation:"box"})); |
| 1633 |
}, |
| 1634 |
|
| 1635 |
Not: function (name) { |
| 1636 |
this.Push(STACKITEM.not()); |
| 1637 |
}, |
| 1638 |
|
| 1639 |
Dots: function (name) { |
| 1640 |
this.Push(STACKITEM.dots().With({ |
| 1641 |
ldots: this.mmlToken(MML.mo(MML.entity("#x2026")).With({stretchy:false})), |
| 1642 |
cdots: this.mmlToken(MML.mo(MML.entity("#x22EF")).With({stretchy:false})) |
| 1643 |
})); |
| 1644 |
}, |
| 1645 |
|
| 1646 |
Require: function (name) { |
| 1647 |
var file = this.GetArgument(name) |
| 1648 |
.replace(/.*\//,"") // remove any leading path |
| 1649 |
.replace(/[^a-z0-9_.-]/ig,""); // remove illegal characters |
| 1650 |
this.Extension(null,file); |
| 1651 |
}, |
| 1652 |
|
| 1653 |
Extension: function (name,file,array) { |
| 1654 |
if (name && !typeof(name) === "string") {name = name.name} |
| 1655 |
file = TEX.extensionDir+"/"+file; |
| 1656 |
if (!file.match(/\.js$/)) {file += ".js"} |
| 1657 |
if (!AJAX.loaded[AJAX.fileURL(file)]) { |
| 1658 |
if (name != null) {delete TEXDEF[array || 'macros'][name.replace(/^\\/,"")]} |
| 1659 |
HUB.RestartAfter(AJAX.Require(file)); |
| 1660 |
} |
| 1661 |
}, |
| 1662 |
|
| 1663 |
Macro: function (name,macro,argcount,def) { |
| 1664 |
if (argcount) { |
| 1665 |
var args = []; |
| 1666 |
if (def != null) { |
| 1667 |
var optional = this.GetBrackets(name); |
| 1668 |
args.push(optional == null ? def : optional); |
| 1669 |
} |
| 1670 |
for (var i = args.length; i < argcount; i++) {args.push(this.GetArgument(name))} |
| 1671 |
macro = this.SubstituteArgs(args,macro); |
| 1672 |
} |
| 1673 |
this.string = this.AddArgs(macro,this.string.slice(this.i)); |
| 1674 |
this.i = 0; |
| 1675 |
if (++this.macroCount > TEX.config.MAXMACROS) { |
| 1676 |
TEX.Error(["MaxMacroSub1", |
| 1677 |
"MathJax maximum macro substitution count exceeded; " + |
| 1678 |
"is there a recursive macro call?"]); |
| 1679 |
} |
| 1680 |
}, |
| 1681 |
|
| 1682 |
Matrix: function (name,open,close,align,spacing,vspacing,style,cases,numbered) { |
| 1683 |
var c = this.GetNext(); |
| 1684 |
if (c === "") |
| 1685 |
{TEX.Error(["MissingArgFor","Missing argument for %1",name])} |
| 1686 |
if (c === "{") {this.i++} else {this.string = c+"}"+this.string.slice(this.i+1); this.i = 0} |
| 1687 |
var array = STACKITEM.array().With({ |
| 1688 |
requireClose: true, |
| 1689 |
arraydef: { |
| 1690 |
rowspacing: (vspacing||"4pt"), |
| 1691 |
columnspacing: (spacing||"1em") |
| 1692 |
} |
| 1693 |
}); |
| 1694 |
if (cases) {array.isCases = true} |
| 1695 |
if (numbered) {array.isNumbered = true; array.arraydef.side = numbered} |
| 1696 |
if (open || close) {array.open = open; array.close = close} |
| 1697 |
if (style === "D") {array.arraydef.displaystyle = true} |
| 1698 |
if (align != null) {array.arraydef.columnalign = align} |
| 1699 |
this.Push(array); |
| 1700 |
}, |
| 1701 |
|
| 1702 |
Entry: function (name) { |
| 1703 |
this.Push(STACKITEM.cell().With({isEntry: true, name: name})); |
| 1704 |
if (this.stack.Top().isCases) { |
| 1705 |
// |
| 1706 |
// Make second column be in \text{...} (unless it is already |
| 1707 |
// in a \text{...}, for backward compatibility). |
| 1708 |
// |
| 1709 |
var string = this.string; |
| 1710 |
var braces = 0, close = -1, i = this.i, m = string.length; |
| 1711 |
// |
| 1712 |
// Look through the string character by character... |
| 1713 |
// |
| 1714 |
while (i < m) { |
| 1715 |
var c = string.charAt(i); |
| 1716 |
if (c === "{") { |
| 1717 |
// |
| 1718 |
// Increase the nested brace count and go on |
| 1719 |
// |
| 1720 |
braces++; |
| 1721 |
i++; |
| 1722 |
} else if (c === "}") { |
| 1723 |
// |
| 1724 |
// If there are too many close braces, just end (we will get an |
| 1725 |
// error message later when the rest of the string is parsed) |
| 1726 |
// Otherwise |
| 1727 |
// decrease the nested brace count, |
| 1728 |
// if it is now zero and we haven't already marked the end of the |
| 1729 |
// first brace group, record the position (use to check for \text{} later) |
| 1730 |
// go on to the next character. |
| 1731 |
// |
| 1732 |
if (braces === 0) { |
| 1733 |
m = 0; |
| 1734 |
} else { |
| 1735 |
braces--; |
| 1736 |
if (braces === 0 && close < 0) { |
| 1737 |
close = i - this.i; |
| 1738 |
} |
| 1739 |
i++; |
| 1740 |
} |
| 1741 |
} else if (c === "&" && braces === 0) { |
| 1742 |
// |
| 1743 |
// Extra alignment tabs are not allowed in cases |
| 1744 |
// |
| 1745 |
TEX.Error(["ExtraAlignTab","Extra alignment tab in \\cases text"]); |
| 1746 |
} else if (c === "\\") { |
| 1747 |
// |
| 1748 |
// If the macro is \cr or \\, end the search, otherwise skip the macro |
| 1749 |
// (multi-letter names don't matter, as we will skip the rest of the |
| 1750 |
// characters in the main loop) |
| 1751 |
// |
| 1752 |
if (string.substr(i).match(/^((\\cr)[^a-zA-Z]|\\\\)/)) {m = 0} else {i += 2} |
| 1753 |
} else { |
| 1754 |
// |
| 1755 |
// Go on to the next character |
| 1756 |
// |
| 1757 |
i++; |
| 1758 |
} |
| 1759 |
} |
| 1760 |
// |
| 1761 |
// Check if the second column text is already in \text{}, |
| 1762 |
// If not, process the second column as text and continue parsing from there, |
| 1763 |
// (otherwise process the second column as normal, since it is in \text{} |
| 1764 |
// |
| 1765 |
var text = string.substr(this.i,i-this.i); |
| 1766 |
if (!text.match(/^\s*\\text[^a-zA-Z]/) || close !== text.replace(/\s+$/,'').length - 1) { |
| 1767 |
this.Push.apply(this,this.InternalMath(text,0)); |
| 1768 |
this.i = i; |
| 1769 |
} |
| 1770 |
} |
| 1771 |
}, |
| 1772 |
|
| 1773 |
Cr: function (name) { |
| 1774 |
this.Push(STACKITEM.cell().With({isCR: true, name: name})); |
| 1775 |
}, |
| 1776 |
|
| 1777 |
CrLaTeX: function (name, nobrackets) { |
| 1778 |
var n; |
| 1779 |
if (!nobrackets && this.string.charAt(this.i) === "[") { |
| 1780 |
n = this.GetBrackets(name,"").replace(/ /g,"").replace(/,/,"."); |
| 1781 |
if (n && !this.matchDimen(n)) { |
| 1782 |
TEX.Error(["BracketMustBeDimension", |
| 1783 |
"Bracket argument to %1 must be a dimension",name]); |
| 1784 |
} |
| 1785 |
} |
| 1786 |
this.Push(STACKITEM.cell().With({isCR: true, name: name, linebreak: true})); |
| 1787 |
var top = this.stack.Top(); |
| 1788 |
if (top.isa(STACKITEM.array)) { |
| 1789 |
if (n && top.arraydef.rowspacing) { |
| 1790 |
var rows = top.arraydef.rowspacing.split(/ /); |
| 1791 |
if (!top.rowspacing) {top.rowspacing = this.dimen2em(rows[0])} |
| 1792 |
while (rows.length < top.table.length) {rows.push(this.Em(top.rowspacing))} |
| 1793 |
rows[top.table.length-1] = this.Em(Math.max(0,top.rowspacing+this.dimen2em(n))); |
| 1794 |
top.arraydef.rowspacing = rows.join(' '); |
| 1795 |
} |
| 1796 |
} else { |
| 1797 |
if (n) {this.Push(MML.mspace().With({depth:n}))} |
| 1798 |
this.Push(MML.mspace().With({linebreak:MML.LINEBREAK.NEWLINE})); |
| 1799 |
} |
| 1800 |
}, |
| 1801 |
emPerInch: 7.2, |
| 1802 |
pxPerInch: 72, |
| 1803 |
matchDimen: function (dim) { |
| 1804 |
return dim.match(/^(-?(?:\.\d+|\d+(?:\.\d*)?))(px|pt|em|ex|mu|pc|in|mm|cm)$/); |
| 1805 |
}, |
| 1806 |
dimen2em: function (dim) { |
| 1807 |
var match = this.matchDimen(dim); |
| 1808 |
var m = parseFloat(match[1]||"1"), unit = match[2]; |
| 1809 |
if (unit === "em") {return m} |
| 1810 |
if (unit === "ex") {return m * .43} |
| 1811 |
if (unit === "pt") {return m / 10} // 10 pt to an em |
| 1812 |
if (unit === "pc") {return m * 1.2} // 12 pt to a pc |
| 1813 |
if (unit === "px") {return m * this.emPerInch / this.pxPerInch} |
| 1814 |
if (unit === "in") {return m * this.emPerInch} |
| 1815 |
if (unit === "cm") {return m * this.emPerInch / 2.54} // 2.54 cm to an inch |
| 1816 |
if (unit === "mm") {return m * this.emPerInch / 25.4} // 10 mm to a cm |
| 1817 |
if (unit === "mu") {return m / 18} |
| 1818 |
return 0; |
| 1819 |
}, |
| 1820 |
Em: function (m) { |
| 1821 |
if (Math.abs(m) < .0006) {return "0em"} |
| 1822 |
return m.toFixed(3).replace(/\.?0+$/,"") + "em"; |
| 1823 |
}, |
| 1824 |
|
| 1825 |
HLine: function (name,style) { |
| 1826 |
if (style == null) {style = "solid"} |
| 1827 |
var top = this.stack.Top(); |
| 1828 |
if (!top.isa(STACKITEM.array) || top.data.length) |
| 1829 |
{TEX.Error(["Misplaced","Misplaced %1",name])} |
| 1830 |
if (top.table.length == 0) { |
| 1831 |
top.frame.push("top"); |
| 1832 |
} else { |
| 1833 |
var lines = (top.arraydef.rowlines ? top.arraydef.rowlines.split(/ /) : []); |
| 1834 |
while (lines.length < top.table.length) {lines.push("none")} |
| 1835 |
lines[top.table.length-1] = style; |
| 1836 |
top.arraydef.rowlines = lines.join(' '); |
| 1837 |
} |
| 1838 |
}, |
| 1839 |
|
| 1840 |
HFill: function (name) { |
| 1841 |
var top = this.stack.Top(); |
| 1842 |
if (top.isa(STACKITEM.array)) top.hfill.push(top.data.length); |
| 1843 |
else TEX.Error(["UnsupportedHFill","Unsupported use of %1",name]); |
| 1844 |
}, |
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
/************************************************************************/ |
| 1849 |
/* |
| 1850 |
* LaTeX environments |
| 1851 |
*/ |
| 1852 |
|
| 1853 |
BeginEnd: function (name) { |
| 1854 |
var env = this.GetArgument(name), isEnd = false; |
| 1855 |
if (env.match(/^\\end\\/)) {isEnd = true; env = env.substr(5)} // special \end{} for \newenvironment environments |
| 1856 |
if (env.match(/\\/i)) {TEX.Error(["InvalidEnv","Invalid environment name '%1'",env])} |
| 1857 |
var cmd = this.envFindName(env); |
| 1858 |
if (!cmd) {TEX.Error(["UnknownEnv","Unknown environment '%1'",env])} |
| 1859 |
if (!isArray(cmd)) {cmd = [cmd]} |
| 1860 |
var end = (isArray(cmd[1]) ? cmd[1][0] : cmd[1]); |
| 1861 |
var mml = STACKITEM.begin().With({name: env, end: end, parse:this}); |
| 1862 |
if (name === "\\end") { |
| 1863 |
if (!isEnd && isArray(cmd[1]) && this[cmd[1][1]]) { |
| 1864 |
mml = this[cmd[1][1]].apply(this,[mml].concat(cmd.slice(2))); |
| 1865 |
} else { |
| 1866 |
mml = STACKITEM.end().With({name: env}); |
| 1867 |
} |
| 1868 |
} else { |
| 1869 |
if (++this.macroCount > TEX.config.MAXMACROS) { |
| 1870 |
TEX.Error(["MaxMacroSub2", |
| 1871 |
"MathJax maximum substitution count exceeded; " + |
| 1872 |
"is there a recursive latex environment?"]); |
| 1873 |
} |
| 1874 |
if (cmd[0] && this[cmd[0]]) {mml = this[cmd[0]].apply(this,[mml].concat(cmd.slice(2)))} |
| 1875 |
} |
| 1876 |
this.Push(mml); |
| 1877 |
}, |
| 1878 |
envFindName: function (name) { |
| 1879 |
return (TEXDEF.environment.hasOwnProperty(name) ? TEXDEF.environment[name] : null); |
| 1880 |
}, |
| 1881 |
|
| 1882 |
Equation: function (begin,row) {return row}, |
| 1883 |
|
| 1884 |
ExtensionEnv: function (begin,file) {this.Extension(begin.name,file,"environment")}, |
| 1885 |
|
| 1886 |
Array: function (begin,open,close,align,spacing,vspacing,style,raggedHeight) { |
| 1887 |
if (!align) {align = this.GetArgument("\\begin{"+begin.name+"}")} |
| 1888 |
var lines = ("c"+align).replace(/[^clr|:]/g,'').replace(/[^|:]([|:])+/g,'$1'); |
| 1889 |
align = align.replace(/[^clr]/g,'').split('').join(' '); |
| 1890 |
align = align.replace(/l/g,'left').replace(/r/g,'right').replace(/c/g,'center'); |
| 1891 |
var array = STACKITEM.array().With({ |
| 1892 |
arraydef: { |
| 1893 |
columnalign: align, |
| 1894 |
columnspacing: (spacing||"1em"), |
| 1895 |
rowspacing: (vspacing||"4pt") |
| 1896 |
} |
| 1897 |
}); |
| 1898 |
if (lines.match(/[|:]/)) { |
| 1899 |
if (lines.charAt(0).match(/[|:]/)) {array.frame.push("left"); array.frame.dashed = lines.charAt(0) === ":"} |
| 1900 |
if (lines.charAt(lines.length-1).match(/[|:]/)) {array.frame.push("right")} |
| 1901 |
lines = lines.substr(1,lines.length-2); |
| 1902 |
array.arraydef.columnlines = |
| 1903 |
lines.split('').join(' ').replace(/[^|: ]/g,'none').replace(/\|/g,'solid').replace(/:/g,'dashed'); |
| 1904 |
} |
| 1905 |
if (open) {array.open = this.convertDelimiter(open)} |
| 1906 |
if (close) {array.close = this.convertDelimiter(close)} |
| 1907 |
if (style === "D") {array.arraydef.displaystyle = true} |
| 1908 |
else if (style) {array.arraydef.displaystyle = false} |
| 1909 |
if (style === "S") {array.arraydef.scriptlevel = 1} // FIXME: should use mstyle? |
| 1910 |
if (raggedHeight) {array.arraydef.useHeight = false} |
| 1911 |
this.Push(begin); |
| 1912 |
return array; |
| 1913 |
}, |
| 1914 |
|
| 1915 |
AlignedArray: function (begin) { |
| 1916 |
var align = this.GetBrackets("\\begin{"+begin.name+"}"); |
| 1917 |
return this.setArrayAlign(this.Array.apply(this,arguments),align); |
| 1918 |
}, |
| 1919 |
setArrayAlign: function (array,align) { |
| 1920 |
align = this.trimSpaces(align||""); |
| 1921 |
if (align === "t") {array.arraydef.align = "baseline 1"} |
| 1922 |
else if (align === "b") {array.arraydef.align = "baseline -1"} |
| 1923 |
else if (align === "c") {array.arraydef.align = "center"} |
| 1924 |
else if (align) {array.arraydef.align = align} // FIXME: should be an error? |
| 1925 |
return array; |
| 1926 |
}, |
| 1927 |
|
| 1928 |
/************************************************************************/ |
| 1929 |
/* |
| 1930 |
* String handling routines |
| 1931 |
*/ |
| 1932 |
|
| 1933 |
/* |
| 1934 |
* Convert delimiter to character |
| 1935 |
*/ |
| 1936 |
convertDelimiter: function (c) { |
| 1937 |
if (c) {c = (TEXDEF.delimiter.hasOwnProperty(c) ? TEXDEF.delimiter[c] : null)} |
| 1938 |
if (c == null) {return null} |
| 1939 |
if (isArray(c)) {c = c[0]} |
| 1940 |
if (c.length === 4) {c = String.fromCharCode(parseInt(c,16))} |
| 1941 |
return c; |
| 1942 |
}, |
| 1943 |
|
| 1944 |
/* |
| 1945 |
* Trim spaces from a string |
| 1946 |
*/ |
| 1947 |
trimSpaces: function (text) { |
| 1948 |
if (typeof(text) != 'string') {return text} |
| 1949 |
var TEXT = text.replace(/^\s+|\s+$/g,''); |
| 1950 |
if (TEXT.match(/\\$/) && text.match(/ $/)) TEXT += " "; |
| 1951 |
return TEXT; |
| 1952 |
}, |
| 1953 |
|
| 1954 |
/* |
| 1955 |
* Check if the next character is a space |
| 1956 |
*/ |
| 1957 |
nextIsSpace: function () { |
| 1958 |
return this.string.charAt(this.i).match(/\s/); |
| 1959 |
}, |
| 1960 |
|
| 1961 |
/* |
| 1962 |
* Get the next non-space character |
| 1963 |
*/ |
| 1964 |
GetNext: function () { |
| 1965 |
while (this.nextIsSpace()) {this.i++} |
| 1966 |
return this.string.charAt(this.i); |
| 1967 |
}, |
| 1968 |
|
| 1969 |
/* |
| 1970 |
* Get and return a control-sequence name |
| 1971 |
*/ |
| 1972 |
GetCS: function () { |
| 1973 |
var CS = this.string.slice(this.i).match(/^([a-z]+|.) ?/i); |
| 1974 |
if (CS) {this.i += CS[1].length; return CS[1]} else {this.i++; return " "} |
| 1975 |
}, |
| 1976 |
|
| 1977 |
/* |
| 1978 |
* Get and return a TeX argument (either a single character or control sequence, |
| 1979 |
* or the contents of the next set of braces). |
| 1980 |
*/ |
| 1981 |
GetArgument: function (name,noneOK) { |
| 1982 |
switch (this.GetNext()) { |
| 1983 |
case "": |
| 1984 |
if (!noneOK) {TEX.Error(["MissingArgFor","Missing argument for %1",name])} |
| 1985 |
return null; |
| 1986 |
case '}': |
| 1987 |
if (!noneOK) { |
| 1988 |
TEX.Error(["ExtraCloseMissingOpen", |
| 1989 |
"Extra close brace or missing open brace"]); |
| 1990 |
} |
| 1991 |
return null; |
| 1992 |
case '\\': |
| 1993 |
this.i++; return "\\"+this.GetCS(); |
| 1994 |
case '{': |
| 1995 |
var j = ++this.i, parens = 1; |
| 1996 |
while (this.i < this.string.length) { |
| 1997 |
switch (this.string.charAt(this.i++)) { |
| 1998 |
case '\\': this.i++; break; |
| 1999 |
case '{': parens++; break; |
| 2000 |
case '}': |
| 2001 |
if (--parens == 0) {return this.string.slice(j,this.i-1)} |
| 2002 |
break; |
| 2003 |
} |
| 2004 |
} |
| 2005 |
TEX.Error(["MissingCloseBrace","Missing close brace"]); |
| 2006 |
break; |
| 2007 |
} |
| 2008 |
return this.string.charAt(this.i++); |
| 2009 |
}, |
| 2010 |
|
| 2011 |
/* |
| 2012 |
* Get an optional LaTeX argument in brackets |
| 2013 |
*/ |
| 2014 |
GetBrackets: function (name,def) { |
| 2015 |
if (this.GetNext() != '[') {return def}; |
| 2016 |
var j = ++this.i, parens = 0; |
| 2017 |
while (this.i < this.string.length) { |
| 2018 |
switch (this.string.charAt(this.i++)) { |
| 2019 |
case '{': parens++; break; |
| 2020 |
case '\\': this.i++; break; |
| 2021 |
case '}': |
| 2022 |
if (parens-- <= 0) { |
| 2023 |
TEX.Error(["ExtraCloseLooking", |
| 2024 |
"Extra close brace while looking for %1","']'"]); |
| 2025 |
} |
| 2026 |
break; |
| 2027 |
case ']': |
| 2028 |
if (parens == 0) {return this.string.slice(j,this.i-1)} |
| 2029 |
break; |
| 2030 |
} |
| 2031 |
} |
| 2032 |
TEX.Error(["MissingCloseBracket", |
| 2033 |
"Couldn't find closing ']' for argument to %1",name]); |
| 2034 |
}, |
| 2035 |
|
| 2036 |
/* |
| 2037 |
* Get the name of a delimiter (check it in the delimiter list). |
| 2038 |
*/ |
| 2039 |
GetDelimiter: function (name,braceOK) { |
| 2040 |
while (this.nextIsSpace()) {this.i++} |
| 2041 |
var c = this.string.charAt(this.i); this.i++; |
| 2042 |
if (this.i <= this.string.length) { |
| 2043 |
if (c == "\\") { |
| 2044 |
c += this.GetCS(name); |
| 2045 |
} else if (c === "{" && braceOK) { |
| 2046 |
this.i--; |
| 2047 |
c = this.GetArgument(name).replace(/^\s+/,'').replace(/\s+$/,''); |
| 2048 |
} |
| 2049 |
if (TEXDEF.delimiter.hasOwnProperty(c)) {return this.convertDelimiter(c)} |
| 2050 |
} |
| 2051 |
TEX.Error(["MissingOrUnrecognizedDelim", |
| 2052 |
"Missing or unrecognized delimiter for %1",name]); |
| 2053 |
}, |
| 2054 |
|
| 2055 |
/* |
| 2056 |
* Get a dimension (including its units). |
| 2057 |
*/ |
| 2058 |
GetDimen: function (name) { |
| 2059 |
var dimen; |
| 2060 |
if (this.nextIsSpace()) {this.i++} |
| 2061 |
if (this.string.charAt(this.i) == '{') { |
| 2062 |
dimen = this.GetArgument(name); |
| 2063 |
if (dimen.match(/^\s*([-+]?([.,]\d+|\d+([.,]\d*)?))\s*(pt|em|ex|mu|px|mm|cm|in|pc)\s*$/)) |
| 2064 |
{return dimen.replace(/ /g,"").replace(/,/,".")} |
| 2065 |
} else { |
| 2066 |
dimen = this.string.slice(this.i); |
| 2067 |
var match = dimen.match(/^\s*(([-+]?([.,]\d+|\d+([.,]\d*)?))\s*(pt|em|ex|mu|px|mm|cm|in|pc)) ?/); |
| 2068 |
if (match) { |
| 2069 |
this.i += match[0].length; |
| 2070 |
return match[1].replace(/ /g,"").replace(/,/,"."); |
| 2071 |
} |
| 2072 |
} |
| 2073 |
TEX.Error(["MissingDimOrUnits", |
| 2074 |
"Missing dimension or its units for %1",name]); |
| 2075 |
}, |
| 2076 |
|
| 2077 |
/* |
| 2078 |
* Get everything up to the given control sequence (token) |
| 2079 |
*/ |
| 2080 |
GetUpTo: function (name,token) { |
| 2081 |
while (this.nextIsSpace()) {this.i++} |
| 2082 |
var j = this.i, k, c, parens = 0; |
| 2083 |
while (this.i < this.string.length) { |
| 2084 |
k = this.i; c = this.string.charAt(this.i++); |
| 2085 |
switch (c) { |
| 2086 |
case '\\': c += this.GetCS(); break; |
| 2087 |
case '{': parens++; break; |
| 2088 |
case '}': |
| 2089 |
if (parens == 0) { |
| 2090 |
TEX.Error(["ExtraCloseLooking", |
| 2091 |
"Extra close brace while looking for %1",token]) |
| 2092 |
} |
| 2093 |
parens--; |
| 2094 |
break; |
| 2095 |
} |
| 2096 |
if (parens == 0 && c == token) {return this.string.slice(j,k)} |
| 2097 |
} |
| 2098 |
TEX.Error(["TokenNotFoundForCommand", |
| 2099 |
"Couldn't find %1 for %2",token,name]); |
| 2100 |
}, |
| 2101 |
|
| 2102 |
/* |
| 2103 |
* Parse various substrings |
| 2104 |
*/ |
| 2105 |
ParseArg: function (name) {return TEX.Parse(this.GetArgument(name),this.stack.env).mml()}, |
| 2106 |
ParseUpTo: function (name,token) {return TEX.Parse(this.GetUpTo(name,token),this.stack.env).mml()}, |
| 2107 |
|
| 2108 |
/* |
| 2109 |
* Break up a string into text and math blocks |
| 2110 |
*/ |
| 2111 |
InternalMath: function (text,level) { |
| 2112 |
var def = (this.stack.env.font ? {mathvariant: this.stack.env.font} : {}); |
| 2113 |
var mml = [], i = 0, k = 0, c, match = '', braces = 0; |
| 2114 |
if (text.match(/\\?[${}\\]|\\\(|\\(eq)?ref\s*\{/)) { |
| 2115 |
while (i < text.length) { |
| 2116 |
c = text.charAt(i++); |
| 2117 |
if (c === '$') { |
| 2118 |
if (match === '$' && braces === 0) { |
| 2119 |
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-1),{}).mml())); |
| 2120 |
match = ''; k = i; |
| 2121 |
} else if (match === '') { |
| 2122 |
if (k < i-1) mml.push(this.InternalText(text.slice(k,i-1),def)); |
| 2123 |
match = '$'; k = i; |
| 2124 |
} |
| 2125 |
} else if (c === '{' && match !== '') { |
| 2126 |
braces++; |
| 2127 |
} else if (c === '}') { |
| 2128 |
if (match === '}' && braces === 0) { |
| 2129 |
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i),{}).mml().With(def))); |
| 2130 |
match = ''; k = i; |
| 2131 |
} else if (match !== '') { |
| 2132 |
if (braces) braces--; |
| 2133 |
} |
| 2134 |
} else if (c === '\\') { |
| 2135 |
if (match === '' && text.substr(i).match(/^(eq)?ref\s*\{/)) { |
| 2136 |
var len = RegExp["$&"].length; |
| 2137 |
if (k < i-1) mml.push(this.InternalText(text.slice(k,i-1),def)); |
| 2138 |
match = '}'; k = i-1; i += len; |
| 2139 |
} else { |
| 2140 |
c = text.charAt(i++); |
| 2141 |
if (c === '(' && match === '') { |
| 2142 |
if (k < i-2) mml.push(this.InternalText(text.slice(k,i-2),def)); |
| 2143 |
match = ')'; k = i; |
| 2144 |
} else if (c === ')' && match === ')' && braces === 0) { |
| 2145 |
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-2),{}).mml())); |
| 2146 |
match = ''; k = i; |
| 2147 |
} else if (c.match(/[${}\\]/) && match === '') { |
| 2148 |
i--; text = text.substr(0,i-1) + text.substr(i); // remove \ from \$, \{, \}, or \\ |
| 2149 |
} |
| 2150 |
} |
| 2151 |
} |
| 2152 |
} |
| 2153 |
if (match !== '') TEX.Error(["MathNotTerminated","Math not terminated in text box"]); |
| 2154 |
} |
| 2155 |
if (k < text.length) mml.push(this.InternalText(text.slice(k),def)); |
| 2156 |
if (level != null) { |
| 2157 |
mml = [MML.mstyle.apply(MML,mml).With({displaystyle:false,scriptlevel:level})]; |
| 2158 |
} else if (mml.length > 1) { |
| 2159 |
mml = [MML.mrow.apply(MML,mml)]; |
| 2160 |
} |
| 2161 |
return mml; |
| 2162 |
}, |
| 2163 |
InternalText: function (text,def) { |
| 2164 |
text = text.replace(/^\s+/,NBSP).replace(/\s+$/,NBSP); |
| 2165 |
return MML.mtext(MML.chars(text)).With(def); |
| 2166 |
}, |
| 2167 |
|
| 2168 |
/* |
| 2169 |
* Routines to set the macro and environment definitions |
| 2170 |
* (overridden by begingroup to make localized versions) |
| 2171 |
*/ |
| 2172 |
setDef: function (name,value) {value.isUser = true; TEXDEF.macros[name] = value}, |
| 2173 |
setEnv: function (name,value) {value.isUser = true; TEXDEF.environment[name] = value}, |
| 2174 |
|
| 2175 |
/* |
| 2176 |
* Replace macro parameters with their values |
| 2177 |
*/ |
| 2178 |
SubstituteArgs: function (args,string) { |
| 2179 |
var text = ''; var newstring = ''; var c; var i = 0; |
| 2180 |
while (i < string.length) { |
| 2181 |
c = string.charAt(i++); |
| 2182 |
if (c === "\\") {text += c + string.charAt(i++)} |
| 2183 |
else if (c === '#') { |
| 2184 |
c = string.charAt(i++); |
| 2185 |
if (c === '#') {text += c} else { |
| 2186 |
if (!c.match(/[1-9]/) || c > args.length) { |
| 2187 |
TEX.Error(["IllegalMacroParam", |
| 2188 |
"Illegal macro parameter reference"]); |
| 2189 |
} |
| 2190 |
newstring = this.AddArgs(this.AddArgs(newstring,text),args[c-1]); |
| 2191 |
text = ''; |
| 2192 |
} |
| 2193 |
} else {text += c} |
| 2194 |
} |
| 2195 |
return this.AddArgs(newstring,text); |
| 2196 |
}, |
| 2197 |
|
| 2198 |
/* |
| 2199 |
* Make sure that macros are followed by a space if their names |
| 2200 |
* could accidentally be continued into the following text. |
| 2201 |
*/ |
| 2202 |
AddArgs: function (s1,s2) { |
| 2203 |
if (s2.match(/^[a-z]/i) && s1.match(/(^|[^\\])(\\\\)*\\[a-z]+$/i)) {s1 += ' '} |
| 2204 |
if (s1.length + s2.length > TEX.config.MAXBUFFER) { |
| 2205 |
TEX.Error(["MaxBufferSize", |
| 2206 |
"MathJax internal buffer size exceeded; is there a recursive macro call?"]); |
| 2207 |
} |
| 2208 |
return s1+s2; |
| 2209 |
} |
| 2210 |
|
| 2211 |
}); |
| 2212 |
|
| 2213 |
/************************************************************************/ |
| 2214 |
|
| 2215 |
TEX.Augment({ |
| 2216 |
Stack: STACK, Parse: PARSE, Definitions: TEXDEF, Startup: STARTUP, |
| 2217 |
|
| 2218 |
config: { |
| 2219 |
MAXMACROS: 10000, // maximum number of macro substitutions per equation |
| 2220 |
MAXBUFFER: 5*1024 // maximum size of TeX string to process |
| 2221 |
}, |
| 2222 |
|
| 2223 |
sourceMenuTitle: /*_(MathMenu)*/ ["TeXCommands","TeX Commands"], |
| 2224 |
annotationEncoding: "application/x-tex", |
| 2225 |
|
| 2226 |
prefilterHooks: MathJax.Callback.Hooks(true), // hooks to run before processing TeX |
| 2227 |
postfilterHooks: MathJax.Callback.Hooks(true), // hooks to run after processing TeX |
| 2228 |
|
| 2229 |
// |
| 2230 |
// Check if AMSmath extension must be loaded and push |
| 2231 |
// it on the extensions array, if needed |
| 2232 |
// |
| 2233 |
Config: function () { |
| 2234 |
this.SUPER(arguments).Config.apply(this,arguments); |
| 2235 |
if (this.config.equationNumbers.autoNumber !== "none") { |
| 2236 |
if (!this.config.extensions) {this.config.extensions = []} |
| 2237 |
this.config.extensions.push("AMSmath.js"); |
| 2238 |
} |
| 2239 |
}, |
| 2240 |
|
| 2241 |
// |
| 2242 |
// Convert TeX to ElementJax |
| 2243 |
// |
| 2244 |
Translate: function (script) { |
| 2245 |
var mml, isError = false, math = MathJax.HTML.getScript(script); |
| 2246 |
var display = (script.type.replace(/\n/g," ").match(/(;|\s|\n)mode\s*=\s*display(;|\s|\n|$)/) != null); |
| 2247 |
var data = {math:math, display:display, script:script}; |
| 2248 |
var callback = this.prefilterHooks.Execute(data); if (callback) return callback; |
| 2249 |
math = data.math; |
| 2250 |
try { |
| 2251 |
mml = TEX.Parse(math).mml(); |
| 2252 |
} catch(err) { |
| 2253 |
if (!err.texError) {throw err} |
| 2254 |
mml = this.formatError(err,math,display,script); |
| 2255 |
isError = true; |
| 2256 |
} |
| 2257 |
if (mml.isa(MML.mtable) && mml.displaystyle === "inherit") mml.displaystyle = display; // for tagged equations |
| 2258 |
if (mml.inferred) {mml = MML.apply(MathJax.ElementJax,mml.data)} else {mml = MML(mml)} |
| 2259 |
if (display) {mml.root.display = "block"} |
| 2260 |
if (isError) {mml.texError = true} |
| 2261 |
data.math = mml; |
| 2262 |
return this.postfilterHooks.Execute(data) || data.math; |
| 2263 |
}, |
| 2264 |
prefilterMath: function (math,displaystyle,script) { |
| 2265 |
return math; |
| 2266 |
}, |
| 2267 |
postfilterMath: function (math,displaystyle,script) { |
| 2268 |
this.combineRelations(math.root); |
| 2269 |
return math; |
| 2270 |
}, |
| 2271 |
formatError: function (err,math,display,script) { |
| 2272 |
var message = err.message.replace(/\n.*/,""); |
| 2273 |
HUB.signal.Post(["TeX Jax - parse error",message,math,display,script]); |
| 2274 |
return MML.Error(message); |
| 2275 |
}, |
| 2276 |
|
| 2277 |
// |
| 2278 |
// Produce an error and stop processing this equation |
| 2279 |
// |
| 2280 |
Error: function (message) { |
| 2281 |
// |
| 2282 |
// Translate message if it is ["id","message",args] |
| 2283 |
// |
| 2284 |
if (isArray(message)) {message = _.apply(_,message)} |
| 2285 |
throw HUB.Insert(Error(message),{texError: true}); |
| 2286 |
}, |
| 2287 |
|
| 2288 |
// |
| 2289 |
// Add a user-defined macro to the macro list |
| 2290 |
// |
| 2291 |
Macro: function (name,def,argn) { |
| 2292 |
TEXDEF.macros[name] = ['Macro'].concat([].slice.call(arguments,1)); |
| 2293 |
TEXDEF.macros[name].isUser = true; |
| 2294 |
}, |
| 2295 |
|
| 2296 |
/* |
| 2297 |
* Create an mrow that has stretchy delimiters at either end, as needed |
| 2298 |
*/ |
| 2299 |
fenced: function (open,mml,close) { |
| 2300 |
var mrow = MML.mrow().With({open:open, close:close, texClass:MML.TEXCLASS.INNER}); |
| 2301 |
mrow.Append( |
| 2302 |
MML.mo(open).With({fence:true, stretchy:true, symmetric:true, texClass:MML.TEXCLASS.OPEN}) |
| 2303 |
); |
| 2304 |
if (mml.type === "mrow" && mml.inferred) { |
| 2305 |
mrow.Append.apply(mrow, mml.data); |
| 2306 |
} else { |
| 2307 |
mrow.Append(mml); |
| 2308 |
} |
| 2309 |
mrow.Append( |
| 2310 |
MML.mo(close).With({fence:true, stretchy:true, symmetric:true, texClass:MML.TEXCLASS.CLOSE}) |
| 2311 |
); |
| 2312 |
return mrow; |
| 2313 |
}, |
| 2314 |
/* |
| 2315 |
* Create an mrow that has \mathchoice using \bigg and \big for the delimiters |
| 2316 |
*/ |
| 2317 |
fixedFence: function (open,mml,close) { |
| 2318 |
var mrow = MML.mrow().With({open:open, close:close, texClass:MML.TEXCLASS.ORD}); |
| 2319 |
if (open) {mrow.Append(this.mathPalette(open,"l"))} |
| 2320 |
if (mml.type === "mrow") {mrow.Append.apply(mrow,mml.data)} else {mrow.Append(mml)} |
| 2321 |
if (close) {mrow.Append(this.mathPalette(close,"r"))} |
| 2322 |
return mrow; |
| 2323 |
}, |
| 2324 |
mathPalette: function (fence,side) { |
| 2325 |
if (fence === '{' || fence === '}') {fence = "\\"+fence} |
| 2326 |
var D = '{\\bigg'+side+' '+fence+'}', T = '{\\big'+side+' '+fence+'}'; |
| 2327 |
return TEX.Parse('\\mathchoice'+D+T+T+T,{}).mml(); |
| 2328 |
}, |
| 2329 |
|
| 2330 |
// |
| 2331 |
// Combine adjacent <mo> elements that are relations |
| 2332 |
// (since MathML treats the spacing very differently) |
| 2333 |
// |
| 2334 |
combineRelations: function (mml) { |
| 2335 |
var i, m, m1, m2; |
| 2336 |
for (i = 0, m = mml.data.length; i < m; i++) { |
| 2337 |
if (mml.data[i]) { |
| 2338 |
if (mml.isa(MML.mrow)) { |
| 2339 |
while (i+1 < m && (m1 = mml.data[i]) && (m2 = mml.data[i+1]) && |
| 2340 |
m1.isa(MML.mo) && m2.isa(MML.mo) && |
| 2341 |
m1.Get("texClass") === MML.TEXCLASS.REL && |
| 2342 |
m2.Get("texClass") === MML.TEXCLASS.REL) { |
| 2343 |
if (m1.variantForm == m2.variantForm && |
| 2344 |
m1.Get("mathvariant") == m2.Get("mathvariant") && m1.style == m2.style && |
| 2345 |
m1["class"] == m2["class"] && !m1.id && !m2.id) { |
| 2346 |
m1.Append.apply(m1,m2.data); |
| 2347 |
mml.data.splice(i+1,1); m--; |
| 2348 |
} else { |
| 2349 |
m1.rspace = m2.lspace = "0pt"; i++; |
| 2350 |
} |
| 2351 |
} |
| 2352 |
} |
| 2353 |
if (!mml.data[i].isToken) {this.combineRelations(mml.data[i])} |
| 2354 |
} |
| 2355 |
} |
| 2356 |
} |
| 2357 |
}); |
| 2358 |
|
| 2359 |
// |
| 2360 |
// Add the default filters |
| 2361 |
// |
| 2362 |
TEX.prefilterHooks.Add(function (data) { |
| 2363 |
data.math = TEX.prefilterMath(data.math,data.display,data.script); |
| 2364 |
}); |
| 2365 |
TEX.postfilterHooks.Add(function (data) { |
| 2366 |
data.math = TEX.postfilterMath(data.math,data.display,data.script); |
| 2367 |
}); |
| 2368 |
|
| 2369 |
TEX.loadComplete("jax.js"); |
| 2370 |
|
| 2371 |
})(MathJax.InputJax.TeX,MathJax.Hub,MathJax.Ajax); |