Skip to content

Commit c05ab62

Browse files
committed
Add config option for matching font heights in NativeMML and HTML-CSS output (can't do it for SVG, since we aren't using native fonts)
1 parent bbf543a commit c05ab62

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

unpacked/jax/output/HTML-CSS/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ MathJax.OutputJax["HTML-CSS"] = MathJax.OutputJax({
3535
webfontDir: MathJax.OutputJax.fontDir + "/HTML-CSS", // font name added later
3636

3737
config: {
38+
matchFontHeight: true, // try to match math font height to surrounding font?
3839
scale: 100, minScaleAdjust: 50, // global math scaling factor, and minimum adjusted scale factor
3940
availableFonts: ["STIX","TeX"], // list of local fonts to check for
4041
preferredFont: "TeX", // preferred local font (TeX or STIX)

unpacked/jax/output/HTML-CSS/jax.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@
534534
ex = this.defaultEx; em = this.defaultEm;
535535
if (relwidth) {maxwidth = this.defaultWidth}
536536
}
537-
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,(ex/this.TeX.x_height)/em) * this.config.scale);
537+
scale = (this.config.matchFontHeight ? ex/this.TeX.x_height/em : 1);
538+
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale)*this.config.scale);
538539
jax.HTMLCSS.scale = scale/100; jax.HTMLCSS.fontSize = scale+"%";
539540
jax.HTMLCSS.em = jax.HTMLCSS.outerEm = em; this.em = em * scale/100; jax.HTMLCSS.ex = ex;
540541
jax.HTMLCSS.lineWidth = (linebreak ? this.length2em(width,1,maxwidth/this.em) : 1000000);
@@ -584,7 +585,7 @@
584585
this.em = MML.mbase.prototype.em = jax.HTMLCSS.em * jax.HTMLCSS.scale;
585586
this.outerEm = jax.HTMLCSS.em; this.scale = jax.HTMLCSS.scale;
586587
this.linebreakWidth = jax.HTMLCSS.lineWidth;
587-
span.style.fontSize = jax.HTMLCSS.fontSize;
588+
if (this.scale !== 1) {span.style.fontSize = jax.HTMLCSS.fontSize}
588589
//
589590
// Typeset the math
590591
//

unpacked/jax/output/NativeMML/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ MathJax.OutputJax.NativeMML = MathJax.OutputJax({
3232
extensionDir: MathJax.OutputJax.extensionDir + "/NativeMML",
3333

3434
config: {
35+
matchFontHeight: true, // try to match math font height to surrounding font?
3536
scale: 100, // scaling factor for all math
3637
minScaleAdjust: 50, // minimum scaling to adjust to surrounding text
3738
// (since the code for that is a bit delicate)

unpacked/jax/output/NativeMML/jax.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,12 @@
257257
ex = test.firstChild.offsetWidth/60;
258258
mex = test.lastChild.offsetWidth/60;
259259
if (ex === 0 || ex === "NaN") {ex = this.defaultEx; mex = this.defaultMEx}
260-
scale = (mex > 1 ? ex/mex : 1) * this.config.scale;
261-
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale));
262-
jax.NativeMML.ex = ex; jax.NativeMML.scale = scale/100;
260+
scale = (this.config.matchFontHeight && mex > 1 ? ex/mex : 1);
261+
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale) * this.config.scale);
262+
jax.NativeMML.ex = ex;
263263
} else {scale = 100}
264264
jax.NativeMML.fontSize = scale+"%";
265+
jax.NativeMML.scale = scale/100;
265266
}
266267
//
267268
// Remove the test spans used for determining scales
@@ -286,9 +287,9 @@
286287
var jax = script.MathJax.elementJax, math = jax.root;
287288
var span = document.getElementById(jax.inputID+"-Frame"),
288289
container = span.firstChild, mspan = container.firstChild;
289-
span.style.fontSize = jax.NativeMML.fontSize;
290290
this.ex = jax.NativeMML.ex || this.defaultEx;
291291
this.scale = jax.NativeMML.scale || 1;
292+
if (this.scale !== 1) {span.style.fontSize = jax.NativeMML.fontSize}
292293
//
293294
// Convert to MathML (if restarted, remove any partial math)
294295
//

0 commit comments

Comments
 (0)