| 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/output/CommonHTML/autoload/mtable.js |
| 7 |
* |
| 8 |
* Implements the CommonHTML output for <mtable> elements. |
| 9 |
* |
| 10 |
* --------------------------------------------------------------------- |
| 11 |
* |
| 12 |
* Copyright (c) 2015-2020 The MathJax Consortium |
| 13 |
* |
| 14 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 15 |
* you may not use this file except in compliance with the License. |
| 16 |
* You may obtain a copy of the License at |
| 17 |
* |
| 18 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 19 |
* |
| 20 |
* Unless required by applicable law or agreed to in writing, software |
| 21 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 22 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 |
* See the License for the specific language governing permissions and |
| 24 |
* limitations under the License. |
| 25 |
*/ |
| 26 |
|
| 27 |
MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () { |
| 28 |
var VERSION = "2.7.9"; |
| 29 |
var MML = MathJax.ElementJax.mml, |
| 30 |
CONFIG = MathJax.Hub.config, |
| 31 |
CHTML = MathJax.OutputJax.CommonHTML, |
| 32 |
SPLIT = MathJax.Hub.SplitList; |
| 33 |
|
| 34 |
var LABEL = -1, |
| 35 |
BIGDIMEN = 1000000; |
| 36 |
|
| 37 |
MML.mtable.Augment({ |
| 38 |
toCommonHTML: function (node) { |
| 39 |
// |
| 40 |
// Create the table nodes and put them in a table |
| 41 |
// (so that its bottom is on the baseline, rather than aligned on the top row) |
| 42 |
// |
| 43 |
var state = {rows:[], labels:[], labeled: false}; |
| 44 |
node = this.CHTMLdefaultNode(node,{noBBox:true, childOptions:state}); |
| 45 |
var table = CHTML.Element("mjx-table"); |
| 46 |
while (node.firstChild) table.appendChild(node.firstChild); |
| 47 |
node.appendChild(table); |
| 48 |
// |
| 49 |
// Get the table attributes |
| 50 |
// |
| 51 |
var values = this.getValues("columnalign","rowalign","columnspacing","rowspacing", |
| 52 |
"columnwidth","equalcolumns","equalrows", |
| 53 |
"columnlines","rowlines","frame","framespacing", |
| 54 |
"align","width","side","minlabelspacing","useHeight"); |
| 55 |
var t = CHTML.TEX.min_rule_thickness/CHTML.em; |
| 56 |
state.t = CHTML.Px(t*this.CHTML.scale,1); |
| 57 |
// |
| 58 |
// Create the table |
| 59 |
// |
| 60 |
this.CHTMLgetBoxSizes(values,state); |
| 61 |
this.CHTMLgetAttributes(values,state); |
| 62 |
this.CHTMLadjustCells(values,state); |
| 63 |
if (values.frame) table.style.border = state.t+" "+values.frame; |
| 64 |
this.CHTMLalignV(values,state,node); |
| 65 |
this.CHTMLcolumnWidths(values,state,node); |
| 66 |
this.CHTMLstretchCells(values,state); |
| 67 |
if (state.labeled) this.CHTMLaddLabels(values,state,node,table); |
| 68 |
// |
| 69 |
// Set the bounding box (ignores overlapping outside of the table) |
| 70 |
// |
| 71 |
var BBOX = this.CHTML; |
| 72 |
BBOX.w = BBOX.r = state.R; |
| 73 |
BBOX.h = BBOX.t = state.T-state.B; |
| 74 |
BBOX.d = BBOX.b = state.B; |
| 75 |
if (!values.frame && !BBOX.pwidth) { |
| 76 |
node.style.padding = "0 "+CHTML.Em(1/6); |
| 77 |
BBOX.L = BBOX.R = 1/6; |
| 78 |
} |
| 79 |
// |
| 80 |
// Add any needed space and color |
| 81 |
// |
| 82 |
this.CHTMLhandleSpace(node); |
| 83 |
this.CHTMLhandleBBox(node); |
| 84 |
this.CHTMLhandleColor(node); |
| 85 |
// |
| 86 |
// Return the completed node |
| 87 |
// |
| 88 |
return node; |
| 89 |
}, |
| 90 |
// |
| 91 |
// Get the natural height, depth, and widths of the rows and columns |
| 92 |
// |
| 93 |
CHTMLgetBoxSizes: function (values,state) { |
| 94 |
var LH = CHTML.FONTDATA.lineH * values.useHeight, |
| 95 |
LD = CHTML.FONTDATA.lineD * values.useHeight; |
| 96 |
var H = [], D = [], W = [], J = -1, i, m; |
| 97 |
for (i = 0, m = this.data.length; i < m; i++) { |
| 98 |
var row = this.data[i], s = (row.type === "mtr" ? 0 : LABEL); |
| 99 |
H[i] = LH; D[i] = LD; |
| 100 |
for (var j = s, M = row.data.length + s; j < M; j++) { |
| 101 |
if (W[j] == null) {W[j] = -BIGDIMEN; if (j > J) J = j} |
| 102 |
var cbox = row.data[j-s].CHTML; |
| 103 |
if (cbox.h > H[i]) H[i] = cbox.h; |
| 104 |
if (cbox.d > D[i]) D[i] = cbox.d; |
| 105 |
if (cbox.w > W[j]) W[j] = cbox.w; |
| 106 |
} |
| 107 |
} |
| 108 |
if (values.equalrows) { |
| 109 |
state.HD = true; |
| 110 |
var HH = Math.max.apply(Math,H); |
| 111 |
var DD = Math.max.apply(Math,D); |
| 112 |
for (i = 0, m = H.length; i < m; i++) {H[i] = HH; D[i] = DD} |
| 113 |
} |
| 114 |
state.H = H; state.D = D; state.W = W, state.J = J; |
| 115 |
}, |
| 116 |
// |
| 117 |
// Pad the spacing and alignment attributes to match the size of the table |
| 118 |
// |
| 119 |
CHTMLgetAttributes: function (values,state) { |
| 120 |
var CSPACE = SPLIT(values.columnspacing), |
| 121 |
RSPACE = SPLIT(values.rowspacing), |
| 122 |
CALIGN = SPLIT(values.columnalign), |
| 123 |
RALIGN = SPLIT(values.rowalign), |
| 124 |
CLINES = SPLIT(values.columnlines), |
| 125 |
RLINES = SPLIT(values.rowlines), |
| 126 |
CWIDTH = SPLIT(values.columnwidth), |
| 127 |
RCALIGN = [], i, m, J = state.J, M = state.rows.length-1; |
| 128 |
for (i = 0, m = CSPACE.length; i < m; i++) CSPACE[i] = this.CHTMLlength2em(CSPACE[i]); |
| 129 |
for (i = 0, m = RSPACE.length; i < m; i++) RSPACE[i] = this.CHTMLlength2em(RSPACE[i]); |
| 130 |
while (CSPACE.length < J) CSPACE.push(CSPACE[CSPACE.length-1]); |
| 131 |
while (CALIGN.length <= J) CALIGN.push(CALIGN[CALIGN.length-1]); |
| 132 |
while (CLINES.length < J) CLINES.push(CLINES[CLINES.length-1]); |
| 133 |
while (CWIDTH.length <= J) CWIDTH.push(CWIDTH[CWIDTH.length-1]); |
| 134 |
while (RSPACE.length < M) RSPACE.push(RSPACE[RSPACE.length-1]); |
| 135 |
while (RALIGN.length <= M) RALIGN.push(RALIGN[RALIGN.length-1]); |
| 136 |
while (RLINES.length < M) RLINES.push(RLINES[RLINES.length-1]); |
| 137 |
CALIGN[LABEL] = (values.side.substr(0,1) === "l" ? "left" : "right"); |
| 138 |
// |
| 139 |
// Override aligment data based on row-specific attributes |
| 140 |
// |
| 141 |
for (i = 0; i <= M; i++) { |
| 142 |
var row = this.data[i]; RCALIGN[i] = []; |
| 143 |
if (row.rowalign) RALIGN[i] = row.rowalign; |
| 144 |
if (row.columnalign) { |
| 145 |
RCALIGN[i] = SPLIT(row.columnalign); |
| 146 |
while (RCALIGN[i].length <= J) RCALIGN[i].push(RCALIGN[i][RCALIGN[i].length-1]); |
| 147 |
} |
| 148 |
} |
| 149 |
// |
| 150 |
// Handle framespacing |
| 151 |
// |
| 152 |
var FSPACE = SPLIT(values.framespacing); |
| 153 |
if (FSPACE.length != 2) FSPACE = SPLIT(this.defaults.framespacing); |
| 154 |
FSPACE[0] = Math.max(0,this.CHTMLlength2em(FSPACE[0])); |
| 155 |
FSPACE[1] = Math.max(0,this.CHTMLlength2em(FSPACE[1])); |
| 156 |
if (values.columnlines.replace(/none/g,"").replace(/ /g,"") !== "" || |
| 157 |
values.rowlines.replace(/none/g,"").replace(/ /g,"") !== "") values.fspace = true; |
| 158 |
// |
| 159 |
// Pad arrays so that final column can be treated as all the others |
| 160 |
// |
| 161 |
if (values.frame === MML.LINES.NONE) delete values.frame; else values.fspace = true; |
| 162 |
if (values.frame) { |
| 163 |
FSPACE[0] = Math.max(0,FSPACE[0]); |
| 164 |
FSPACE[1] = Math.max(0,FSPACE[1]); |
| 165 |
} |
| 166 |
if (values.fspace) { |
| 167 |
CSPACE[J] = FSPACE[0]; RSPACE[M] = FSPACE[1]; |
| 168 |
} else { |
| 169 |
CSPACE[J] = RSPACE[M] = 0; |
| 170 |
} |
| 171 |
CLINES[J] = RLINES[M] = MML.LINES.NONE; |
| 172 |
// |
| 173 |
// Save everything in the state |
| 174 |
// |
| 175 |
state.CSPACE = CSPACE; state.RSPACE = RSPACE; |
| 176 |
state.CALIGN = CALIGN; state.RALIGN = RALIGN; |
| 177 |
state.CLINES = CLINES; state.RLINES = RLINES; |
| 178 |
state.CWIDTH = CWIDTH; state.RCALIGN = RCALIGN; |
| 179 |
state.FSPACE = FSPACE; |
| 180 |
}, |
| 181 |
// |
| 182 |
// Add styles to cells to handle borders, spacing, alignment, etc. |
| 183 |
// |
| 184 |
CHTMLadjustCells: function(values,state) { |
| 185 |
var ROWS = state.rows, |
| 186 |
CSPACE = state.CSPACE, CLINES = state.CLINES, |
| 187 |
RSPACE = state.RSPACE, RLINES = state.RLINES, |
| 188 |
CALIGN = state.CALIGN, RALIGN = state.RALIGN, |
| 189 |
RCALIGN = state.RCALIGN; |
| 190 |
CSPACE[state.J] *= 2; RSPACE[ROWS.length-1] *= 2; // since halved below |
| 191 |
var T = "0", B, R, L, border, cbox, align, lastB = 0; |
| 192 |
if (values.fspace) { |
| 193 |
lastB = state.FSPACE[1]; |
| 194 |
T = CHTML.Em(state.FSPACE[1]); |
| 195 |
} |
| 196 |
state.RHD = []; state.RH = []; |
| 197 |
for (var i = 0, m = ROWS.length; i < m; i++) { |
| 198 |
var row = ROWS[i], rdata = this.data[i]; |
| 199 |
// |
| 200 |
// Space and borders between rows |
| 201 |
// |
| 202 |
B = RSPACE[i]/2; border = null; L = "0"; |
| 203 |
if (RLINES[i] !== MML.LINES.NONE && RLINES[i] !== "") border = state.t+" "+RLINES[i]; |
| 204 |
if (border || (CLINES[j] !== MML.LINES.NONE && CLINES[j] !== "")) { |
| 205 |
while (row.length <= state.J) { |
| 206 |
row.push(CHTML.addElement(row.node,"mjx-mtd",null,[['span']])); |
| 207 |
} |
| 208 |
} |
| 209 |
state.RH[i] = lastB + state.H[i]; // distance to baseline in row |
| 210 |
lastB = Math.max(0,B); |
| 211 |
state.RHD[i] = state.RH[i] + lastB + state.D[i]; // total height of row |
| 212 |
B = CHTML.Em(lastB); |
| 213 |
// |
| 214 |
// Frame space for initial cell |
| 215 |
// |
| 216 |
if (values.fspace) L = CHTML.Em(state.FSPACE[0]); |
| 217 |
// |
| 218 |
// The cells in the row |
| 219 |
// |
| 220 |
for (var j = 0, M = row.length; j < M; j++) { |
| 221 |
var s = (rdata.type === "mtr" ? 0 : LABEL); |
| 222 |
var mtd = rdata.data[j-s] || {CHTML: CHTML.BBOX.zero()}; |
| 223 |
var cell = row[j].style; cbox = mtd.CHTML; |
| 224 |
// |
| 225 |
// Space and borders between columns |
| 226 |
// |
| 227 |
R = CSPACE[j]/2; |
| 228 |
if (CLINES[j] !== MML.LINES.NONE) { |
| 229 |
cell.borderRight = state.t+" "+CLINES[j]; |
| 230 |
R -= 1/CHTML.em/2; |
| 231 |
} |
| 232 |
R = CHTML.Em(Math.max(0,R)); |
| 233 |
cell.padding = T+" "+R+" 0px "+L; |
| 234 |
if (border) cell.borderBottom = border; |
| 235 |
L = R; |
| 236 |
// |
| 237 |
// Handle vertical alignment |
| 238 |
// |
| 239 |
align = (mtd.rowalign||(this.data[i]||{}).rowalign||RALIGN[i]); |
| 240 |
var H = Math.max(1,cbox.h), D = Math.max(.2,cbox.d), |
| 241 |
HD = (state.H[i]+state.D[i]) - (H+D), |
| 242 |
child = row[j].firstChild.style; |
| 243 |
if (align === MML.ALIGN.TOP) { |
| 244 |
if (HD) child.marginBottom = CHTML.Em(HD); |
| 245 |
cell.verticalAlign = "top"; |
| 246 |
} else if (align === MML.ALIGN.BOTTOM) { |
| 247 |
cell.verticalAlign = "bottom"; |
| 248 |
if (HD) child.marginTop = CHTML.Em(HD); |
| 249 |
} else if (align === MML.ALIGN.CENTER) { |
| 250 |
if (HD) child.marginTop = child.marginBottom = CHTML.Em(HD/2); |
| 251 |
cell.verticalAlign = "middle"; |
| 252 |
} else { |
| 253 |
if (H !== state.H[i]) child.marginTop = CHTML.Em(state.H[i]-H); |
| 254 |
} |
| 255 |
// |
| 256 |
// Handle horizontal alignment |
| 257 |
// |
| 258 |
align = (mtd.columnalign||RCALIGN[i][j]||CALIGN[j]); |
| 259 |
if (align !== MML.ALIGN.CENTER) cell.textAlign = align; |
| 260 |
} |
| 261 |
row.node.style.height = CHTML.Em(state.RHD[i]); |
| 262 |
T = B; |
| 263 |
} |
| 264 |
CSPACE[state.J] /= 2; RSPACE[ROWS.length-1] /= 2; // back to normal |
| 265 |
}, |
| 266 |
// |
| 267 |
// Align the table vertically according to the align attribute |
| 268 |
// |
| 269 |
CHTMLalignV: function (values,state,node) { |
| 270 |
var n, M = state.rows.length, H = state.H, D = state.D, RSPACE = state.RSPACE; |
| 271 |
// |
| 272 |
// Get alignment type and row number |
| 273 |
// |
| 274 |
if (typeof(values.align) !== "string") values.align = String(values.align); |
| 275 |
if (values.align.match(/(top|bottom|center|baseline|axis)( +(-?\d+))?/)) { |
| 276 |
n = parseInt(RegExp.$3||"0"); |
| 277 |
values.align = RegExp.$1 |
| 278 |
if (n < 0) n += state.rows.length + 1; |
| 279 |
if (n > M || n <= 0) n = null; |
| 280 |
} else { |
| 281 |
values.align = this.defaults.align; |
| 282 |
} |
| 283 |
// |
| 284 |
// Get table height and baseline offset |
| 285 |
// |
| 286 |
var T = 0, B = 0, a = CHTML.TEX.axis_height; |
| 287 |
if (values.fspace) T += state.FSPACE[1]; |
| 288 |
if (values.frame) {T += 2/CHTML.em; B += 1/CHTML.em} |
| 289 |
for (var i = 0; i < M; i++) { |
| 290 |
var h = H[i], d = D[i]; |
| 291 |
T += h + d + RSPACE[i]; |
| 292 |
if (n) { |
| 293 |
if (i === n-1) { |
| 294 |
B += ({top:h+d, bottom:0, center:(h+d)/2, |
| 295 |
baseline:d, axis:a+d})[values.align] + RSPACE[i]; |
| 296 |
} |
| 297 |
if (i >= n) B += h + d + RSPACE[i]; |
| 298 |
} |
| 299 |
} |
| 300 |
if (!n) B = ({top:T, bottom:0, center:T/2, baseline:T/2, axis:T/2-a})[values.align]; |
| 301 |
// |
| 302 |
// Place the node and save the values |
| 303 |
// |
| 304 |
if (B) node.style.verticalAlign = CHTML.Em(-B); |
| 305 |
state.T = T; state.B = B; |
| 306 |
}, |
| 307 |
// |
| 308 |
// Determine column widths and set the styles for the columns |
| 309 |
// |
| 310 |
CHTMLcolumnWidths: function (values,state,node) { |
| 311 |
var CWIDTH = state.CWIDTH, CSPACE = state.CSPACE, J = state.J, j; |
| 312 |
var WW = 0, setWidths = false, relWidth = values.width.match(/%$/); |
| 313 |
var i, m, w; |
| 314 |
// |
| 315 |
// Handle equal columns by adjusting the CWIDTH array |
| 316 |
// |
| 317 |
if (values.width !== "auto" && !relWidth) { |
| 318 |
WW = Math.max(0,this.CHTMLlength2em(values.width,state.R)); |
| 319 |
setWidths = true; |
| 320 |
} |
| 321 |
if (values.equalcolumns) { |
| 322 |
if (relWidth) { |
| 323 |
// |
| 324 |
// Use percent of total (not perfect, but best we can do) |
| 325 |
// |
| 326 |
var p = CHTML.Percent(1/(J+1)); |
| 327 |
for (j = 0; j <= J; j++) CWIDTH[j] = p; |
| 328 |
} else { |
| 329 |
// |
| 330 |
// For width = auto, make all widths equal the widest, |
| 331 |
// otherwise, for specific width, remove intercolumn space |
| 332 |
// and divide by number of columns to get widest space. |
| 333 |
// |
| 334 |
w = Math.max.apply(Math,state.W); |
| 335 |
if (values.width !== "auto") { |
| 336 |
var S = (values.fspace ? state.FSPACE[0] + (values.frame ? 2/CHTML.em : 0) : 0); |
| 337 |
for (j = 0; j <= J; j++) S += CSPACE[j]; |
| 338 |
w = Math.max((WW-S)/(J+1),w); |
| 339 |
} |
| 340 |
w = CHTML.Em(w); |
| 341 |
for (j = 0; j <= J; j++) CWIDTH[j] = w; |
| 342 |
} |
| 343 |
setWidths = true; |
| 344 |
} |
| 345 |
// |
| 346 |
// Compute natural table width |
| 347 |
// |
| 348 |
var TW = 0; if (values.fspace) TW = state.FSPACE[0]; |
| 349 |
var auto = [], fit = [], percent = [], W = []; |
| 350 |
var row = state.rows[0]; |
| 351 |
for (j = 0; j <= J; j++) { |
| 352 |
W[j] = state.W[j]; |
| 353 |
if (CWIDTH[j] === "auto") auto.push(j) |
| 354 |
else if (CWIDTH[j] === "fit") fit.push(j) |
| 355 |
else if (CWIDTH[j].match(/%$/)) percent.push(j) |
| 356 |
else W[j] = this.CHTMLlength2em(CWIDTH[j],W[j]); |
| 357 |
TW += W[j] + CSPACE[j]; |
| 358 |
if (row[j]) row[j].style.width = CHTML.Em(W[j]); |
| 359 |
} |
| 360 |
if (values.frame) TW += 2/CHTML.em; |
| 361 |
var hasFit = (fit.length > 0); |
| 362 |
// |
| 363 |
// Adjust widths of columns |
| 364 |
// |
| 365 |
if (setWidths || (relWidth && hasFit)) { |
| 366 |
if (relWidth) { |
| 367 |
// |
| 368 |
// Attach appropriate widths to the columns |
| 369 |
// |
| 370 |
for (j = 0; j <= J; j++) { |
| 371 |
cell = row[j].style; |
| 372 |
if (CWIDTH[j] === "auto" && !hasFit) cell.width = ""; |
| 373 |
else if (CWIDTH[j] === "fit") cell.width = ""; |
| 374 |
else if (CWIDTH[j].match(/%$/)) cell.width = CWIDTH[j]; |
| 375 |
else cell.minWidth = cell.maxWidth = cell.width; |
| 376 |
} |
| 377 |
} else { |
| 378 |
// |
| 379 |
// Compute percentage widths |
| 380 |
// |
| 381 |
if (WW > TW) { |
| 382 |
var extra = 0; |
| 383 |
for (i = 0, m = percent.length; i < m; i++) { |
| 384 |
j = percent[i]; |
| 385 |
w = Math.max(W[j],this.CHTMLlength2em(CWIDTH[j],WW)); |
| 386 |
extra += w-W[j]; W[j] = w; |
| 387 |
row[j].style.width = CHTML.Em(w); |
| 388 |
} |
| 389 |
TW += extra; |
| 390 |
} |
| 391 |
// |
| 392 |
// Compute "fit" widths |
| 393 |
// |
| 394 |
if (!hasFit) fit = auto; |
| 395 |
if (WW > TW && fit.length) { |
| 396 |
var dw = (WW - TW) / fit.length; |
| 397 |
for (i = 0, m = fit.length; i < m; i++) { |
| 398 |
j = fit[i]; W[j] += dw; |
| 399 |
row[j].style.width = CHTML.Em(W[j]); |
| 400 |
} |
| 401 |
TW = WW; |
| 402 |
} |
| 403 |
} |
| 404 |
} |
| 405 |
W[LABEL] = state.W[LABEL]; |
| 406 |
state.W = W; |
| 407 |
state.R = TW; |
| 408 |
// |
| 409 |
// Set variable width on DOM nodes |
| 410 |
// |
| 411 |
if (relWidth) { |
| 412 |
node.style.width = this.CHTML.pwidth = "100%"; |
| 413 |
this.CHTML.mwidth = CHTML.Em(TW); |
| 414 |
node.firstChild.style.width = values.width; |
| 415 |
node.firstChild.style.margin = "auto"; |
| 416 |
} |
| 417 |
}, |
| 418 |
// |
| 419 |
// Stretch any cells that can be stretched |
| 420 |
// |
| 421 |
CHTMLstretchCells: function (values,state) { |
| 422 |
var ROWS = state.rows, H = state.H, D = state.D, W = state.W, |
| 423 |
J = state.J, M = ROWS.length-1; |
| 424 |
for (var i = 0; i <= M; i++) { |
| 425 |
var row = ROWS[i], rdata = this.data[i]; |
| 426 |
var h = H[i], d = D[i]; |
| 427 |
for (var j = 0; j <= J; j++) { |
| 428 |
var cell = row[j], cdata = rdata.data[j]; |
| 429 |
if (!cdata) continue; |
| 430 |
if (cdata.CHTML.stretch === "V") cdata.CHTMLstretchV(h,d); |
| 431 |
else if (cdata.CHTML.stretch === "H") cdata.CHTMLstretchH(cell,W[j]); |
| 432 |
} |
| 433 |
} |
| 434 |
}, |
| 435 |
// |
| 436 |
// Add labels to a table |
| 437 |
// |
| 438 |
CHTMLaddLabels: function (values,state,node,table) { |
| 439 |
// |
| 440 |
// Get indentation and alignment |
| 441 |
// |
| 442 |
var indent = this.getValues("indentalignfirst","indentshiftfirst","indentalign","indentshift"); |
| 443 |
if (indent.indentalignfirst !== MML.INDENTALIGN.INDENTALIGN) indent.indentalign = indent.indentalignfirst; |
| 444 |
if (indent.indentalign === MML.INDENTALIGN.AUTO) indent.indentalign = CONFIG.displayAlign; |
| 445 |
if (indent.indentshiftfirst !== MML.INDENTSHIFT.INDENTSHIFT) indent.indentshift = indent.indentshiftfirst; |
| 446 |
if (indent.indentshift === "auto") indent.indentshift = "0"; |
| 447 |
var shift = this.CHTMLlength2em(indent.indentshift,CHTML.cwidth); |
| 448 |
var labelspace = this.CHTMLlength2em(values.minlabelspacing,.8); |
| 449 |
var labelW = labelspace + state.W[LABEL], labelshift = 0, tw = state.R; |
| 450 |
var dIndent = this.CHTMLlength2em(CONFIG.displayIndent,CHTML.cwidth); |
| 451 |
var s = (state.CALIGN[LABEL] === MML.INDENTALIGN.RIGHT ? -1 : 1); |
| 452 |
if (indent.indentalign === MML.INDENTALIGN.CENTER) { |
| 453 |
tw += 2 * (labelW - s*(shift + dIndent)); |
| 454 |
shift += dIndent; |
| 455 |
} else if (state.CALIGN[LABEL] === indent.indentalign) { |
| 456 |
if (dIndent < 0) {labelshift = s*dIndent; dIndent = 0} |
| 457 |
shift += s*dIndent; if (labelW > s*shift) shift = s*labelW; shift += labelshift; |
| 458 |
shift *= s; tw += shift; |
| 459 |
} else { |
| 460 |
tw += labelW - s*shift + dIndent; |
| 461 |
shift -= s*dIndent; shift *= -s; |
| 462 |
} |
| 463 |
// |
| 464 |
// Create boxes for table and labels |
| 465 |
// |
| 466 |
var box = CHTML.addElement(node,"mjx-box",{ |
| 467 |
style:{width:"100%","text-align":indent.indentalign} |
| 468 |
}); box.appendChild(table); |
| 469 |
var labels = CHTML.Element("mjx-itable"); |
| 470 |
table.style.display = "inline-table"; if (!table.style.width) table.style.width = "auto"; |
| 471 |
labels.style.verticalAlign = "top"; |
| 472 |
table.style.verticalAlign = CHTML.Em(state.T-state.B-state.H[0]); |
| 473 |
node.style.verticalAlign = ""; |
| 474 |
if (shift) { |
| 475 |
if (indent.indentalign === MML.INDENTALIGN.CENTER) { |
| 476 |
table.style.marginLeft = CHTML.Em(shift); |
| 477 |
table.style.marginRight = CHTML.Em(-shift); |
| 478 |
} else { |
| 479 |
var margin = "margin" + (indent.indentalign === MML.INDENTALIGN.RIGHT ? "Right" : "Left"); |
| 480 |
table.style[margin] = CHTML.Em(shift); |
| 481 |
} |
| 482 |
} |
| 483 |
// |
| 484 |
// Add labels on correct side |
| 485 |
// |
| 486 |
if (state.CALIGN[LABEL] === "left") { |
| 487 |
node.insertBefore(labels,box); |
| 488 |
labels.style.marginRight = CHTML.Em(-state.W[LABEL]-labelshift); |
| 489 |
if (labelshift) labels.style.marginLeft = CHTML.Em(labelshift); |
| 490 |
} else { |
| 491 |
node.appendChild(labels); |
| 492 |
labels.style.marginLeft = CHTML.Em(-state.W[LABEL]+labelshift); |
| 493 |
} |
| 494 |
// |
| 495 |
// Vertically align the labels with their rows |
| 496 |
// |
| 497 |
var LABELS = state.labels, T = 0; |
| 498 |
if (values.fspace) T = state.FSPACE[0] + (values.frame ? 1/CHTML.em : 0); |
| 499 |
for (var i = 0, m = LABELS.length; i < m; i++) { |
| 500 |
if (LABELS[i] && this.data[i].data[0]) { |
| 501 |
labels.appendChild(LABELS[i]); |
| 502 |
var lbox = this.data[i].data[0].CHTML; |
| 503 |
T = state.RH[i] - Math.max(1,lbox.h); |
| 504 |
if (T) LABELS[i].firstChild.firstChild.style.marginTop = CHTML.Em(T); |
| 505 |
LABELS[i].style.height = CHTML.Em(state.RHD[i]); |
| 506 |
} else { |
| 507 |
CHTML.addElement(labels,"mjx-label",{style:{height:CHTML.Em(state.RHD[i])}}); |
| 508 |
} |
| 509 |
} |
| 510 |
// |
| 511 |
// Propagate full-width equations, and reserve room for equation plus label |
| 512 |
// |
| 513 |
node.style.width = this.CHTML.pwidth = "100%"; |
| 514 |
node.style.minWidth = this.CHTML.mwidth = CHTML.Em(Math.max(0,tw)); |
| 515 |
} |
| 516 |
}); |
| 517 |
|
| 518 |
MML.mtr.Augment({ |
| 519 |
toCommonHTML: function (node,options) { |
| 520 |
// |
| 521 |
// Create the row node |
| 522 |
// |
| 523 |
node = this.CHTMLcreateNode(node); |
| 524 |
this.CHTMLhandleStyle(node); |
| 525 |
this.CHTMLhandleScale(node); |
| 526 |
// |
| 527 |
// Add a new row with no label |
| 528 |
// |
| 529 |
if (!options) options = {rows:[],labels:[]}; |
| 530 |
var row = []; options.rows.push(row); row.node = node; |
| 531 |
options.labels.push(null); |
| 532 |
// |
| 533 |
// Add the cells to the row |
| 534 |
// |
| 535 |
for (var i = 0, m = this.data.length; i < m; i++) |
| 536 |
row.push(this.CHTMLaddChild(node,i,options)); |
| 537 |
// |
| 538 |
this.CHTMLhandleColor(node); |
| 539 |
return node; |
| 540 |
} |
| 541 |
}); |
| 542 |
MML.mlabeledtr.Augment({ |
| 543 |
toCommonHTML: function (node,options) { |
| 544 |
// |
| 545 |
// Create the row node |
| 546 |
// |
| 547 |
node = this.CHTMLcreateNode(node); |
| 548 |
this.CHTMLhandleStyle(node); |
| 549 |
this.CHTMLhandleScale(node); |
| 550 |
// |
| 551 |
// Add a new row, and get the label |
| 552 |
// |
| 553 |
if (!options) options = {rows:[],labels:[]}; |
| 554 |
var row = []; options.rows.push(row); row.node = node; |
| 555 |
var label = CHTML.Element("mjx-label"); options.labels.push(label); |
| 556 |
this.CHTMLaddChild(label,0,options); |
| 557 |
if (this.data[0]) options.labeled = true; |
| 558 |
// |
| 559 |
// Add the cells to the row |
| 560 |
// |
| 561 |
for (var i = 1, m = this.data.length; i < m; i++) |
| 562 |
row.push(this.CHTMLaddChild(node,i,options)); |
| 563 |
// |
| 564 |
this.CHTMLhandleColor(node); |
| 565 |
return node; |
| 566 |
} |
| 567 |
}); |
| 568 |
MML.mtd.Augment({ |
| 569 |
toCommonHTML: function (node,options) { |
| 570 |
node = this.CHTMLdefaultNode(node,options); |
| 571 |
CHTML.addElement(node.firstChild,"mjx-strut"); // forces height to 1em (we adjust later) |
| 572 |
// |
| 573 |
// Determine if this is stretchy or not |
| 574 |
// |
| 575 |
if (this.isEmbellished()) { |
| 576 |
var mo = this.CoreMO(), BBOX = this.CHTML; |
| 577 |
if (mo.CHTMLcanStretch("Vertical")) BBOX.stretch = "V"; |
| 578 |
else if (mo.CHTMLcanStretch("Horizontal")) BBOX.stretch = "H"; |
| 579 |
if (BBOX.stretch) { |
| 580 |
var min = mo.Get("minsize",true); |
| 581 |
if (min) { |
| 582 |
if (BBOX.stretch === "V") { |
| 583 |
var HD = BBOX.h + BBOX.d; |
| 584 |
if (HD) { |
| 585 |
var r = this.CHTMLlength2em(min,HD)/HD; |
| 586 |
if (r > 1) {BBOX.h *= r; BBOX.d *= r} |
| 587 |
} |
| 588 |
} else { |
| 589 |
BBOX.w = Math.max(BBOX.w,this.CHTMLlength2em(min,BBOX.w)); |
| 590 |
} |
| 591 |
} |
| 592 |
} |
| 593 |
} |
| 594 |
return node; |
| 595 |
} |
| 596 |
}); |
| 597 |
|
| 598 |
|
| 599 |
MathJax.Hub.Startup.signal.Post("CommonHTML mtable Ready"); |
| 600 |
MathJax.Ajax.loadComplete(CHTML.autoloadDir+"/mtable.js"); |
| 601 |
}); |
| 602 |
|