diff --git a/src/Parser.js b/src/Parser.js index 1dcb7f62..a8efaac9 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -534,6 +534,22 @@ export default class Parser { case "math": case "text": return this.parseGroup(name, optional, greediness, undefined, type); + case "hbox": { + // hbox argument type wraps the argument in the equivalent of + // \hbox, which is like \text but switching to \textstyle size. + const group = this.parseGroup( + name, optional, greediness, undefined, "text"); + if (!group) { + return group; + } + const styledGroup = { + type: "styling", + mode: group.mode, + body: [group], + style: "text", // simulate \textstyle + }; + return styledGroup; + } case "raw": { if (optional && this.nextToken.text === "{") { return null; diff --git a/src/functions/enclose.js b/src/functions/enclose.js index 364e05a6..c1befd7a 100644 --- a/src/functions/enclose.js +++ b/src/functions/enclose.js @@ -222,7 +222,7 @@ defineFunction({ names: ["\\fbox"], props: { numArgs: 1, - argTypes: ["text"], + argTypes: ["hbox"], allowedInText: true, }, handler({parser}, args) { diff --git a/src/functions/raisebox.js b/src/functions/raisebox.js index 61bfdb04..40bff067 100644 --- a/src/functions/raisebox.js +++ b/src/functions/raisebox.js @@ -1,12 +1,12 @@ // @flow -import defineFunction, {ordargument} from "../defineFunction"; +import defineFunction from "../defineFunction"; import buildCommon from "../buildCommon"; import mathMLTree from "../mathMLTree"; import {assertNodeType} from "../parseNode"; import {calculateSize} from "../units"; +import * as html from "../buildHTML"; import * as mml from "../buildMathML"; -import * as sizing from "./sizing"; // Box manipulation defineFunction({ @@ -14,7 +14,7 @@ defineFunction({ names: ["\\raisebox"], props: { numArgs: 2, - argTypes: ["size", "text"], + argTypes: ["size", "hbox"], allowedInText: true, }, handler({parser}, args) { @@ -28,19 +28,7 @@ defineFunction({ }; }, htmlBuilder(group, options) { - const text = { - type: "text", - mode: group.mode, - body: ordargument(group.body), - font: "mathrm", // simulate \textrm - }; - const sizedText = { - type: "sizing", - mode: group.mode, - body: [text], - size: 6, // simulate \normalsize - }; - const body = sizing.htmlBuilder(sizedText, options); + const body = html.buildGroup(group.body, options); const dy = calculateSize(group.dy, options); return buildCommon.makeVList({ positionType: "shift", diff --git a/src/functions/styling.js b/src/functions/styling.js index f443a454..6d994264 100644 --- a/src/functions/styling.js +++ b/src/functions/styling.js @@ -48,15 +48,6 @@ defineFunction({ }, mathmlBuilder(group, options) { // Figure out what style we're changing to. - // TODO(kevinb): dedupe this with buildHTML.js - // This will be easier of handling of styling nodes is in the same file. - const styleMap = { - "display": Style.DISPLAY, - "text": Style.TEXT, - "script": Style.SCRIPT, - "scriptscript": Style.SCRIPTSCRIPT, - }; - const newStyle = styleMap[group.style]; const newOptions = options.havingStyle(newStyle); diff --git a/src/macros.js b/src/macros.js index f04bd0db..9af10ec5 100644 --- a/src/macros.js +++ b/src/macros.js @@ -695,17 +695,17 @@ defineMacro("\\TeX", "\\textrm{\\html@mathml{" + // \TeX} // This code aligns the top of the A with the T (from the perspective of TeX's // boxes, though visually the A appears to extend above slightly). -// We compute the corresponding \raisebox when A is rendered at \scriptsize, -// which is size3, which has a scale factor of 0.7 (see Options.js). +// We compute the corresponding \raisebox when A is rendered in \normalsize +// \scriptstyle, which has a scale factor of 0.7 (see Options.js). const latexRaiseA = fontMetricsData['Main-Regular']["T".charCodeAt(0)][1] - 0.7 * fontMetricsData['Main-Regular']["A".charCodeAt(0)][1] + "em"; defineMacro("\\LaTeX", "\\textrm{\\html@mathml{" + - `L\\kern-.36em\\raisebox{${latexRaiseA}}{\\scriptsize A}` + + `L\\kern-.36em\\raisebox{${latexRaiseA}}{\\scriptstyle A}` + "\\kern-.15em\\TeX}{LaTeX}}"); // New KaTeX logo based on tweaking LaTeX logo defineMacro("\\KaTeX", "\\textrm{\\html@mathml{" + - `K\\kern-.17em\\raisebox{${latexRaiseA}}{\\scriptsize A}` + + `K\\kern-.17em\\raisebox{${latexRaiseA}}{\\scriptstyle A}` + "\\kern-.15em\\TeX}{KaTeX}}"); // \DeclareRobustCommand\hspace{\@ifstar\@hspacer\@hspace} diff --git a/src/types.js b/src/types.js index eba9ef73..e80e55ac 100644 --- a/src/types.js +++ b/src/types.js @@ -20,7 +20,8 @@ export type Mode = "math" | "text"; // first argument is special and the second // argument is parsed normally) // - Mode: Node group parsed in given mode. -export type ArgType = "color" | "size" | "url" | "raw" | "original" | Mode; +export type ArgType = "color" | "size" | "url" | "raw" | "original" | "hbox" | + Mode; // LaTeX display style. export type StyleStr = "text" | "display" | "script" | "scriptscript"; diff --git a/test/__snapshots__/mathml-spec.js.snap b/test/__snapshots__/mathml-spec.js.snap index 8fa7146a..535de1f0 100644 --- a/test/__snapshots__/mathml-spec.js.snap +++ b/test/__snapshots__/mathml-spec.js.snap @@ -618,9 +618,13 @@ exports[`A MathML builder should use for raisebox 1`] = ` - - b - + + + b + + diff --git a/test/screenshotter/images/KaTeX-chrome.png b/test/screenshotter/images/KaTeX-chrome.png index ee89422f..241253b6 100644 Binary files a/test/screenshotter/images/KaTeX-chrome.png and b/test/screenshotter/images/KaTeX-chrome.png differ diff --git a/test/screenshotter/images/KaTeX-firefox.png b/test/screenshotter/images/KaTeX-firefox.png index 4495cf2a..211d1a02 100644 Binary files a/test/screenshotter/images/KaTeX-firefox.png and b/test/screenshotter/images/KaTeX-firefox.png differ diff --git a/test/screenshotter/images/LaTeX-chrome.png b/test/screenshotter/images/LaTeX-chrome.png index ca5de59c..5139db80 100644 Binary files a/test/screenshotter/images/LaTeX-chrome.png and b/test/screenshotter/images/LaTeX-chrome.png differ diff --git a/test/screenshotter/images/LaTeX-firefox.png b/test/screenshotter/images/LaTeX-firefox.png index 9892e70d..3194ccd5 100644 Binary files a/test/screenshotter/images/LaTeX-firefox.png and b/test/screenshotter/images/LaTeX-firefox.png differ diff --git a/test/screenshotter/ss_data.yaml b/test/screenshotter/ss_data.yaml index 80c9f44a..ce5764f8 100644 --- a/test/screenshotter/ss_data.yaml +++ b/test/screenshotter/ss_data.yaml @@ -160,7 +160,7 @@ Integrands: | \iint + \oiint + \iiint + \oiiint \end{array} KaTeX: - tex: \KaTeX + tex: \KaTeX, \large \KaTeX nolatex: \KaTeX not supported by LaTeX Kern: tex: \frac{a\kern{1em}b}{c}a\kern{1em}b\kern{1ex}c\kern{-0.25em}d @@ -173,7 +173,7 @@ Kern: # \mathrlap{\overbrace{\phantom{a_0+a_1+a_2}}^m}a_0+a_1+a_2 # \end{array} LargeRuleNumerator: \frac{\textcolor{blue}{\rule{1em}{2em}}}{x} -LaTeX: \text{\LaTeX}, \text{\TeX} +LaTeX: \text{\LaTeX}, \text{\TeX}, \large \text{\LaTeX}, \text{\TeX} LeftRight: \left( x^2 \right) \left\{ x^{x^{x^{x^x}}} \right. LeftRightListStyling: a+\left(x+y\right)-x LeftRightMiddle: \left( x^2 \middle/ \right) \left\{ x^{x^{x^{x^x}}} \middle/ y \right.\left(x\middle|y\,\middle|\,z\right)