mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 11:48:41 +00:00
Implement $...$ within \text via styling node (#637)
This commit is contained in:
committed by
Kevin Barabash
parent
9913242245
commit
7fdb1eed81
@@ -732,6 +732,7 @@ describe("A text parser", function() {
|
||||
const badTextExpression = "\\text{a b%}";
|
||||
const badFunctionExpression = "\\text{\\sqrt{x}}";
|
||||
const mathTokenAfterText = "\\text{sin}^2";
|
||||
const textWithEmbeddedMath = "\\text{graph: $y = mx + b$}";
|
||||
|
||||
it("should not fail", function() {
|
||||
expect(textExpression).toParse();
|
||||
@@ -789,6 +790,10 @@ describe("A text parser", function() {
|
||||
parse.value.body.map(function(n) { return n.value; }).join("")
|
||||
).toBe("moo");
|
||||
});
|
||||
|
||||
it("should parse math within text group", function() {
|
||||
expect(textWithEmbeddedMath).toParse();
|
||||
});
|
||||
});
|
||||
|
||||
describe("A color parser", function() {
|
||||
@@ -1539,7 +1544,7 @@ describe("A MathML font tree-builder", function() {
|
||||
const markup = buildMathML(tree, tex, defaultOptions).toMarkup();
|
||||
expect(markup).toContain("<mi mathvariant=\"double-struck\">A</mi>");
|
||||
expect(markup).toContain("<mi>x</mi>");
|
||||
expect(markup).toContain("<mn mathvariant=\"normal\">2</mn>");
|
||||
expect(markup).toContain("<mn>2</mn>");
|
||||
expect(markup).toContain("<mi>\u03c9</mi>"); // \omega
|
||||
expect(markup).toContain("<mi mathvariant=\"normal\">\u03A9</mi>"); // \Omega
|
||||
expect(markup).toContain("<mi>\u0131</mi>"); // \imath
|
||||
@@ -1552,7 +1557,7 @@ describe("A MathML font tree-builder", function() {
|
||||
const markup = buildMathML(tree, tex, defaultOptions).toMarkup();
|
||||
expect(markup).toContain("<mi mathvariant=\"normal\">A</mi>");
|
||||
expect(markup).toContain("<mi mathvariant=\"normal\">x</mi>");
|
||||
expect(markup).toContain("<mn mathvariant=\"normal\">2</mn>");
|
||||
expect(markup).toContain("<mn>2</mn>");
|
||||
expect(markup).toContain("<mi>\u03c9</mi>"); // \omega
|
||||
expect(markup).toContain("<mi mathvariant=\"normal\">\u03A9</mi>"); // \Omega
|
||||
expect(markup).toContain("<mi>\u0131</mi>"); // \imath
|
||||
@@ -1563,12 +1568,12 @@ describe("A MathML font tree-builder", function() {
|
||||
const tex = "\\mathit{" + contents + "}";
|
||||
const tree = getParsed(tex);
|
||||
const markup = buildMathML(tree, tex, defaultOptions).toMarkup();
|
||||
expect(markup).toContain("<mi mathvariant=\"italic\">A</mi>");
|
||||
expect(markup).toContain("<mi mathvariant=\"italic\">x</mi>");
|
||||
expect(markup).toContain("<mi>A</mi>");
|
||||
expect(markup).toContain("<mi>x</mi>");
|
||||
expect(markup).toContain("<mn mathvariant=\"italic\">2</mn>");
|
||||
expect(markup).toContain("<mi mathvariant=\"italic\">\u03c9</mi>"); // \omega
|
||||
expect(markup).toContain("<mi mathvariant=\"italic\">\u03A9</mi>"); // \Omega
|
||||
expect(markup).toContain("<mi mathvariant=\"italic\">\u0131</mi>"); // \imath
|
||||
expect(markup).toContain("<mi>\u03c9</mi>"); // \omega
|
||||
expect(markup).toContain("<mi>\u03A9</mi>"); // \Omega
|
||||
expect(markup).toContain("<mi>\u0131</mi>"); // \imath
|
||||
expect(markup).toContain("<mo>+</mo>");
|
||||
});
|
||||
|
||||
@@ -1623,7 +1628,7 @@ describe("A MathML font tree-builder", function() {
|
||||
// MathJax marks everything below as "script" except \omega
|
||||
// We don't have these glyphs in "script" and neither does MathJax
|
||||
expect(markup).toContain("<mi>x</mi>");
|
||||
expect(markup).toContain("<mn mathvariant=\"normal\">2</mn>");
|
||||
expect(markup).toContain("<mn>2</mn>");
|
||||
expect(markup).toContain("<mi>\u03c9</mi>"); // \omega
|
||||
expect(markup).toContain("<mi mathvariant=\"normal\">\u03A9</mi>"); // \Omega
|
||||
expect(markup).toContain("<mi>\u0131</mi>"); // \imath
|
||||
@@ -1661,6 +1666,22 @@ describe("A MathML font tree-builder", function() {
|
||||
"</mstyle>";
|
||||
expect(markup).toContain(node);
|
||||
});
|
||||
|
||||
it("should render text as <mtext>", function() {
|
||||
const tex = "\\text{for }";
|
||||
const tree = getParsed(tex);
|
||||
const markup = buildMathML(tree, tex, defaultOptions).toMarkup();
|
||||
expect(markup).toContain("<mtext>for\u00a0</mtext>");
|
||||
});
|
||||
|
||||
it("should render math within text as side-by-side children", function() {
|
||||
const tex = "\\text{graph: $y = mx + b$}";
|
||||
const tree = getParsed(tex);
|
||||
const markup = buildMathML(tree, tex, defaultOptions).toMarkup();
|
||||
expect(markup).toContain("<mrow><mtext>graph:\u00a0</mtext>");
|
||||
expect(markup).toContain(
|
||||
"<mi>y</mi><mo>=</mo><mi>m</mi><mi>x</mi><mo>+</mo><mi>b</mi>");
|
||||
});
|
||||
});
|
||||
|
||||
describe("A bin builder", function() {
|
||||
|
BIN
test/screenshotter/images/TextWithMath-chrome.png
Normal file
BIN
test/screenshotter/images/TextWithMath-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.8 KiB |
BIN
test/screenshotter/images/TextWithMath-firefox.png
Normal file
BIN
test/screenshotter/images/TextWithMath-firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.5 KiB |
@@ -170,6 +170,7 @@ Symbols1: |
|
||||
\maltese\degree\pounds\$
|
||||
\text{\maltese\degree\pounds\textdollar}
|
||||
Text: \frac{a}{b}\text{c~ {ab} \ e}+fg
|
||||
TextWithMath: \text{for $a < b$ and $ c < d $}.
|
||||
Unicode: \begin{matrix}\text{ÀàÇçÉéÏïÖöÛû} \\ \text{БГДЖЗЙЛФЦШЫЮЯ} \\ \text{여보세요} \\ \text{私はバナナです} \end{matrix}
|
||||
UnsupportedCmds:
|
||||
tex: \err\,\frac\fracerr3\,2^\superr_\suberr\,\sqrt\sqrterr
|
||||
|
Reference in New Issue
Block a user