diff --git a/src/Parser.js b/src/Parser.js index 82d0777..0cf911c 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -394,6 +394,17 @@ const styleFuncs = [ "\\displaystyle", "\\textstyle", "\\scriptstyle", "\\scriptscriptstyle", ]; +// Old font functions +const oldFontFuncs = { + "\\rm": "mathrm", + "\\sf": "mathsf", + "\\tt": "mathtt", + "\\bf": "mathbf", + "\\it": "mathit", + //"\\sl": "textsl", + //"\\sc": "textsc", +}; + /** * Parses an implicit group, which is a group that starts at the end of a * specified, and ends right before a higher explicit group ends, or at EOL. It @@ -462,7 +473,8 @@ Parser.prototype.parseImplicitGroup = function() { result.position = end.position; return result; } else if (utils.contains(sizeFuncs, func)) { - // If we see a sizing function, parse out the implict body + // If we see a sizing function, parse out the implicit body + this.consumeSpaces(); const body = this.parseExpression(false); return new ParseNode("sizing", { // Figure out what size to use based on the list of functions above @@ -470,7 +482,8 @@ Parser.prototype.parseImplicitGroup = function() { value: body, }, this.mode); } else if (utils.contains(styleFuncs, func)) { - // If we see a styling function, parse out the implict body + // If we see a styling function, parse out the implicit body + this.consumeSpaces(); const body = this.parseExpression(true); return new ParseNode("styling", { // Figure out what style to use by pulling out the style from @@ -478,6 +491,22 @@ Parser.prototype.parseImplicitGroup = function() { style: func.slice(1, func.length - 5), value: body, }, this.mode); + } else if (func in oldFontFuncs) { + const style = oldFontFuncs[func]; + // If we see an old font function, parse out the implicit body + this.consumeSpaces(); + const body = this.parseExpression(true); + if (style.slice(0, 4) === 'text') { + return new ParseNode("text", { + style: style, + body: new ParseNode("ordgroup", body, this.mode), + }, this.mode); + } else { + return new ParseNode("font", { + font: style, + body: new ParseNode("ordgroup", body, this.mode), + }, this.mode); + } } else { // Defer to parseFunction if it's not a function we handle return this.parseFunction(start); @@ -629,9 +658,7 @@ Parser.prototype.parseGroupOfType = function(innerMode, optional) { if (innerMode === "text") { // text mode is special because it should ignore the whitespace before // it - while (this.nextToken.text === " ") { - this.consume(); - } + this.consumeSpaces(); } // By the time we get here, innerMode is one of "text" or "math". // We switch the mode of the parser, recurse, then restore the old mode. @@ -640,6 +667,12 @@ Parser.prototype.parseGroupOfType = function(innerMode, optional) { return res; }; +Parser.prototype.consumeSpaces = function() { + while (this.nextToken.text === " ") { + this.consume(); + } +}; + /** * Parses a group, essentially returning the string formed by the * brace-enclosed tokens plus some position information. diff --git a/src/functions.js b/src/functions.js index 0f52e94..1cec871 100644 --- a/src/functions.js +++ b/src/functions.js @@ -591,6 +591,11 @@ defineFunction([ "\\scriptscriptstyle", ], 0, null); +// Old font changing functions +defineFunction([ + "\\rm", "\\sf", "\\tt", "\\bf", "\\it", //"\\sl", "\\sc", +], 0, null); + defineFunction([ // styles "\\mathrm", "\\mathit", "\\mathbf", diff --git a/test/screenshotter/images/OldFont-chrome.png b/test/screenshotter/images/OldFont-chrome.png new file mode 100644 index 0000000..9827a8f Binary files /dev/null and b/test/screenshotter/images/OldFont-chrome.png differ diff --git a/test/screenshotter/images/OldFont-firefox.png b/test/screenshotter/images/OldFont-firefox.png new file mode 100644 index 0000000..97c7829 Binary files /dev/null and b/test/screenshotter/images/OldFont-firefox.png differ diff --git a/test/screenshotter/ss_data.yaml b/test/screenshotter/ss_data.yaml index 8838e48..db41584 100644 --- a/test/screenshotter/ss_data.yaml +++ b/test/screenshotter/ss_data.yaml @@ -118,6 +118,12 @@ NestedFractions: | \dfrac{\frac{a}{b}}{\frac{c}{d}}\dfrac{\dfrac{a}{b}} {\dfrac{c}{d}}\frac{\frac{a}{b}}{\frac{c}{d}} NullDelimiterInteraction: a \bigl. + 2 \quad \left. + a \right) +OldFont: | + \begin{matrix} + \rm rm & it & \it it & \bf bf & \sf sf & \tt tt \\ + \text{\rm rm} & \text{rm} & \text{\it it} & \text{\bf bf} & \text{\sf sf} & \text{\tt tt} \\ + i\rm r\it i & \text{r\it i\rm r} + \end{matrix} OpLimits: | {\sin_2^2 \lim_2^2 \int_2^2 \sum_2^2} {\displaystyle \lim_2^2 \int_2^2 \intop_2^2 \sum_2^2}