|
100 | 100 | "min-height": 0, "max-height":"none",
|
101 | 101 | padding:0, border: 0, margin: 0
|
102 | 102 | },
|
| 103 | + ".MathJax_SVG_LineBox": { |
| 104 | + display: "table-cell!important", |
| 105 | + width: "10000em!important", |
| 106 | + "min-width":0, "max-width":"none", |
| 107 | + padding:0, border:0, margin:0 |
| 108 | + }, |
103 | 109 |
|
104 | 110 | "#MathJax_SVG_Tooltip": {
|
105 | 111 | position: "absolute", left: 0, top: 0,
|
|
173 | 179 | );
|
174 | 180 |
|
175 | 181 | // Used in preTranslate to get linebreak width
|
176 |
| - this.linebreakSpan = HTML.Element("span",null, |
177 |
| - [["hr",{style: {width:"auto", size:1, padding:0, border:0, margin:0}}]]); |
| 182 | + this.linebreakSpan = HTML.Element("span",{className:"MathJax_SVG_LineBox"}); |
178 | 183 |
|
179 | 184 | // Set up styles
|
180 | 185 | return AJAX.Styles(this.config.styles,["InitializeSVG",this]);
|
|
190 | 195 | document.body.appendChild(this.ExSpan);
|
191 | 196 | document.body.appendChild(this.linebreakSpan);
|
192 | 197 | this.defaultEx = this.ExSpan.firstChild.offsetHeight/60;
|
193 |
| - this.defaultWidth = this.linebreakSpan.firstChild.offsetWidth; |
| 198 | + this.defaultWidth = this.linebreakSpan.offsetWidth; |
194 | 199 | document.body.removeChild(this.linebreakSpan);
|
195 | 200 | document.body.removeChild(this.ExSpan);
|
196 | 201 | },
|
|
256 | 261 | test = script.previousSibling; div = test.previousSibling;
|
257 | 262 | jax = script.MathJax.elementJax; if (!jax) continue;
|
258 | 263 | ex = test.firstChild.offsetHeight/60;
|
259 |
| - cwidth = div.previousSibling.firstChild.offsetWidth / this.config.scale * 100; |
260 |
| - if (relwidth) {maxwidth = cwidth} |
| 264 | + cwidth = Math.max(0,(div.previousSibling.offsetWidth-2) / this.config.scale * 100); |
261 | 265 | if (ex === 0 || ex === "NaN") {
|
262 | 266 | // can't read width, so move to hidden div for processing
|
263 | 267 | // (this will cause a reflow for each math element that is hidden)
|
264 | 268 | this.hiddenDiv.appendChild(div);
|
265 | 269 | jax.SVG.isHidden = true;
|
266 | 270 | ex = this.defaultEx; cwidth = this.defaultWidth;
|
267 |
| - if (relwidth) {maxwidth = cwidth} |
268 | 271 | }
|
| 272 | + if (relwidth) {maxwidth = cwidth} |
269 | 273 | jax.SVG.ex = ex;
|
270 | 274 | jax.SVG.em = em = ex / SVG.TeX.x_height * 1000; // scale ex to x_height
|
271 | 275 | jax.SVG.cwidth = cwidth/em * 1000;
|
|
2089 | 2093 | var style = svg.element.style, px = SVG.TeX.x_height/SVG.ex;
|
2090 | 2094 | var H = (Math.ceil(svg.H/px)+1)*px+SVG.HFUZZ, // round to pixels and add padding
|
2091 | 2095 | D = (Math.ceil(svg.D/px)+1)*px+SVG.DFUZZ;
|
2092 |
| - svg.element.setAttribute("width",SVG.Ex(l+svg.w+r)); |
| 2096 | + var w = l + svg.w + r; |
| 2097 | + svg.element.setAttribute("width",SVG.Ex(w)); |
2093 | 2098 | svg.element.setAttribute("height",SVG.Ex(H+D));
|
2094 | 2099 | style.verticalAlign = SVG.Ex(-D);
|
2095 | 2100 | if (l) style.marginLeft = SVG.Ex(-l);
|
2096 | 2101 | if (r) style.marginRight = SVG.Ex(-r);
|
2097 | 2102 | svg.element.setAttribute("viewBox",SVG.Fixed(-l,1)+" "+SVG.Fixed(-H,1)+" "+
|
2098 |
| - SVG.Fixed(l+svg.w+r,1)+" "+SVG.Fixed(H+D,1)); |
| 2103 | + SVG.Fixed(w,1)+" "+SVG.Fixed(H+D,1)); |
2099 | 2104 | //
|
2100 | 2105 | // If there is extra height or depth, hide that
|
2101 | 2106 | //
|
|
2105 | 2110 | style.verticalAlign = SVG.Ex(-svg.d);
|
2106 | 2111 | }
|
2107 | 2112 | //
|
| 2113 | + // The approximate ex can cause full-width equations to be too wide, |
| 2114 | + // so if they are close to full width, make sure they aren't too big. |
| 2115 | + // |
| 2116 | + if (Math.abs(w-SVG.cwidth) < 10) |
| 2117 | + style.maxWidth = SVG.Fixed(SVG.cwidth*SVG.em/1000); |
| 2118 | + // |
2108 | 2119 | // Add it to the MathJax span
|
2109 | 2120 | //
|
2110 | 2121 | var alttext = this.Get("alttext");
|
|
2131 | 2142 | if (shift) {
|
2132 | 2143 | HUB.Insert(style,({
|
2133 | 2144 | left: {marginLeft: SVG.Ex(shift)},
|
2134 |
| - right: {marginRight: SVG.Ex(-shift), marginLeft: SVG.Ex(Math.max(0,shift-(l+svg.w+r)))}, |
| 2145 | + right: {marginRight: SVG.Ex(-shift), marginLeft: SVG.Ex(Math.max(0,shift-(w)))}, |
2135 | 2146 | center: {marginLeft: SVG.Ex(shift), marginRight: SVG.Ex(-shift)}
|
2136 | 2147 | })[values.indentalign]);
|
2137 | 2148 | }
|
|
0 commit comments