From bcceb085909ba22f35d18ccfd919cb508617751d Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sun, 9 Feb 2014 13:45:58 -0500 Subject: [PATCH] Add \texttt and \textsf macros, and make them work with mtextFontInherit. Resolves issue #459. --- unpacked/jax/input/TeX/jax.js | 2 ++ unpacked/jax/output/HTML-CSS/config.js | 14 ++++++++++++++ unpacked/jax/output/HTML-CSS/jax.js | 8 ++++++-- unpacked/jax/output/SVG/config.js | 13 +++++++++++++ unpacked/jax/output/SVG/jax.js | 3 +++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/unpacked/jax/input/TeX/jax.js b/unpacked/jax/input/TeX/jax.js index 19bf4e4e7..f0b85ae77 100644 --- a/unpacked/jax/input/TeX/jax.js +++ b/unpacked/jax/input/TeX/jax.js @@ -935,6 +935,8 @@ textrm: ['Macro','\\mathord{\\rm\\text{#1}}',1], textit: ['Macro','\\mathord{\\it{\\text{#1}}}',1], textbf: ['Macro','\\mathord{\\bf{\\text{#1}}}',1], + textsf: ['Macro','\\mathord{\\sf{\\text{#1}}}',1], + texttt: ['Macro','\\mathord{\\tt{\\text{#1}}}',1], pmb: ['Macro','\\rlap{#1}\\kern1px{#1}',1], TeX: ['Macro','T\\kern-.14em\\lower.5ex{E}\\kern-.115em X'], LaTeX: ['Macro','L\\kern-.325em\\raise.21em{\\scriptstyle{A}}\\kern-.17em\\TeX'], diff --git a/unpacked/jax/output/HTML-CSS/config.js b/unpacked/jax/output/HTML-CSS/config.js index fbea8a75c..3d99245f1 100644 --- a/unpacked/jax/output/HTML-CSS/config.js +++ b/unpacked/jax/output/HTML-CSS/config.js @@ -75,6 +75,20 @@ MathJax.OutputJax["HTML-CSS"] = MathJax.OutputJax({ "font-size": "90%" }, + // + // For mtextFontInherit version of \texttt{} + // + ".MathJax .MJX-monospace": { + "font-family": "monospace" + }, + + // + // For mtextFontInherit version of \textsf{} + // + ".MathJax .MJX-sans-serif": { + "font-family": "sans-serif" + }, + "#MathJax_Tooltip": { "background-color": "InfoBackground", color: "InfoText", border: "1px solid black", diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index 0f2a7e3c1..3b1a9b085 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -2170,8 +2170,12 @@ span = this.HTMLhandleSize(this.HTMLcreateSpan(span)); var variant = this.HTMLgetVariant(); // Avoid setting the font style for error text or if mtextFontInherit is set - if (HTMLCSS.config.mtextFontInherit || this.Parent().type === "merror") - {variant = {bold:variant.bold, italic:variant.italic, fontInherit: true}} + if (HTMLCSS.config.mtextFontInherit || this.Parent().type === "merror") { + var vname = this.Get("mathvariant"); + if (vname === "monospace") {span.className += " MJX-monospace"} + else if (vname.match(/sans-serif/)) {span.className += " MJX-sans-serif"} + variant = {bold:variant.bold, italic:variant.italic, fontInherit: true}; + } for (var i = 0, m = this.data.length; i < m; i++) {if (this.data[i]) {this.data[i].toHTML(span,variant)}} if (!span.bbox) {span.bbox = this.HTMLzeroBBox()} diff --git a/unpacked/jax/output/SVG/config.js b/unpacked/jax/output/SVG/config.js index 7e975fefd..634c766ba 100644 --- a/unpacked/jax/output/SVG/config.js +++ b/unpacked/jax/output/SVG/config.js @@ -64,6 +64,19 @@ MathJax.OutputJax.SVG = MathJax.OutputJax({ margin: "1em 0em" }, + // + // For mtextFontInherit version of \texttt{} + // + ".MathJax_SVG .MJX-monospace": { + "font-family": "monospace" + }, + + // + // For mtextFontInherit version of \textsf{} + // + ".MathJax_SVG .MJX-sans-serif": { + "font-family": "sans-serif" + }, "#MathJax_SVG_Tooltip": { "background-color": "InfoBackground", color: "InfoText", border: "1px solid black", diff --git a/unpacked/jax/output/SVG/jax.js b/unpacked/jax/output/SVG/jax.js index 8c2a72a7c..464124ce5 100644 --- a/unpacked/jax/output/SVG/jax.js +++ b/unpacked/jax/output/SVG/jax.js @@ -1483,6 +1483,9 @@ var variant = this.SVGgetVariant(), def = {direction:this.Get("dir")}; if (variant.bold) {def["font-weight"] = "bold"} if (variant.italic) {def["font-style"] = "italic"} + variant = this.Get("mathvariant"); + if (variant === "monospace") {def["class"] = "MJX-monospace"} + else if (variant.match(/sans-serif/)) {def["class"] = " MJX-sans-serif"} svg.Add(BBOX.TEXT(scale,this.data.join(""),def)); svg.Clean(); this.SVGhandleColor(svg); this.SVGsaveData(svg);