Fix argument font sizing in \fbox and \raisebox, fix font sizing in \TeX, \LaTeX, \KaTeX (#1787)
* Remove forced \normalsize in \raisebox Fix #1786 (incorrect size of "E" in `\TeX`) by fixing `\raisebox` to keep the current font size. Previously, `\raisebox` was rendering its second argument as if it were in `\normalsize\textrm{...}`; now, the argument is just as if it were in `\textrm{...}`. * Fix screenshots * New "hbox" argument type to convert box-like arguments * Review comments * Fix \fbox to use hbox argument * Render A in \LaTeX and \KaTeX in \scriptstyle (not \scriptsize) * Add screenshot test * Revert .sizing { width: min-content} thanks to #2044
@@ -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;
|
||||
|
@@ -222,7 +222,7 @@ defineFunction({
|
||||
names: ["\\fbox"],
|
||||
props: {
|
||||
numArgs: 1,
|
||||
argTypes: ["text"],
|
||||
argTypes: ["hbox"],
|
||||
allowedInText: true,
|
||||
},
|
||||
handler({parser}, args) {
|
||||
|
@@ -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",
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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}
|
||||
|
@@ -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";
|
||||
|
@@ -618,9 +618,13 @@ exports[`A MathML builder should use <mpadded> for raisebox 1`] = `
|
||||
<semantics>
|
||||
<mrow>
|
||||
<mpadded voffset="0.25em">
|
||||
<mtext>
|
||||
b
|
||||
</mtext>
|
||||
<mstyle scriptlevel="0"
|
||||
displaystyle="false"
|
||||
>
|
||||
<mtext>
|
||||
b
|
||||
</mtext>
|
||||
</mstyle>
|
||||
</mpadded>
|
||||
</mrow>
|
||||
<annotation encoding="application/x-tex">
|
||||
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 9.4 KiB |
@@ -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)
|
||||
|