mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-12 22:48:41 +00:00
\char character escaping and nicer MathML via \html@mathml (#1454)
* \html@mathml Fix #1452 * Add missing file * Implement \char (via internal \@char) * Remove excess <mstyle> wrapper on \mathbin etc. * Fix tests * Add Unicode support for \copyright and \textregistered Testing that this doesn't lead to an infinite loop thanks to \char` escaping. * Add tests * Use assertNodeType * Switch from regex to lookup table, and no parseInt
This commit is contained in:
@@ -1,5 +1,34 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`A MathML builder \\html@mathml makes clean symbols 1`] = `
|
||||
|
||||
<math>
|
||||
<semantics>
|
||||
<mrow>
|
||||
<mtext>
|
||||
©
|
||||
</mtext>
|
||||
<mi mathvariant="normal">
|
||||
≠
|
||||
</mi>
|
||||
<mi mathvariant="normal">
|
||||
∉
|
||||
</mi>
|
||||
<mi mathvariant="normal">
|
||||
≘
|
||||
</mi>
|
||||
<mtext>
|
||||
KaTeX
|
||||
</mtext>
|
||||
</mrow>
|
||||
<annotation encoding="application/x-tex">
|
||||
\\copyright\\neq\\notin≘\\KaTeX
|
||||
</annotation>
|
||||
</semantics>
|
||||
</math>
|
||||
|
||||
`;
|
||||
|
||||
exports[`A MathML builder \\text fonts become mathvariant 1`] = `
|
||||
|
||||
<math>
|
||||
@@ -382,34 +411,32 @@ exports[`A MathML builder should render boldsymbol with the correct mathvariants
|
||||
<math>
|
||||
<semantics>
|
||||
<mrow>
|
||||
<mstyle>
|
||||
<mrow>
|
||||
<mi mathvariant="bold-italic">
|
||||
A
|
||||
</mi>
|
||||
<mi mathvariant="bold-italic">
|
||||
x
|
||||
</mi>
|
||||
<mn mathvariant="bold-italic">
|
||||
2
|
||||
</mn>
|
||||
<mi mathvariant="bold-italic">
|
||||
k
|
||||
</mi>
|
||||
<mi mathvariant="bold-italic">
|
||||
ω
|
||||
</mi>
|
||||
<mi mathvariant="bold-italic">
|
||||
Ω
|
||||
</mi>
|
||||
<mi mathvariant="bold-italic">
|
||||
ı
|
||||
</mi>
|
||||
<mo mathvariant="bold-italic">
|
||||
+
|
||||
</mo>
|
||||
</mrow>
|
||||
</mstyle>
|
||||
<mrow>
|
||||
<mi mathvariant="bold-italic">
|
||||
A
|
||||
</mi>
|
||||
<mi mathvariant="bold-italic">
|
||||
x
|
||||
</mi>
|
||||
<mn mathvariant="bold-italic">
|
||||
2
|
||||
</mn>
|
||||
<mi mathvariant="bold-italic">
|
||||
k
|
||||
</mi>
|
||||
<mi mathvariant="bold-italic">
|
||||
ω
|
||||
</mi>
|
||||
<mi mathvariant="bold-italic">
|
||||
Ω
|
||||
</mi>
|
||||
<mi mathvariant="bold-italic">
|
||||
ı
|
||||
</mi>
|
||||
<mo mathvariant="bold-italic">
|
||||
+
|
||||
</mo>
|
||||
</mrow>
|
||||
</mrow>
|
||||
<annotation encoding="application/x-tex">
|
||||
\\boldsymbol{Ax2k\\omega\\Omega\\imath+}
|
||||
|
@@ -93,7 +93,10 @@ describe("A rel parser", function() {
|
||||
expect(parse).toBeTruthy();
|
||||
|
||||
for (let i = 0; i < parse.length; i++) {
|
||||
const group = parse[i];
|
||||
let group = parse[i];
|
||||
if (group.type === "htmlmathml") {
|
||||
group = group.value.html[0];
|
||||
}
|
||||
expect(group.type).toEqual("rel");
|
||||
}
|
||||
});
|
||||
@@ -1503,12 +1506,12 @@ describe("A font parser", function() {
|
||||
expect(nestedParse.value.font).toEqual("mathbb");
|
||||
expect(nestedParse.value.type).toEqual("font");
|
||||
|
||||
expect(nestedParse.value.body.value.length).toEqual(4);
|
||||
const bbBody = nestedParse.value.body.value;
|
||||
expect(bbBody.length).toEqual(3);
|
||||
expect(bbBody[0].type).toEqual("mathord");
|
||||
expect(bbBody[3].type).toEqual("font");
|
||||
expect(bbBody[3].value.font).toEqual("mathrm");
|
||||
expect(bbBody[3].value.type).toEqual("font");
|
||||
expect(bbBody[2].type).toEqual("font");
|
||||
expect(bbBody[2].value.font).toEqual("mathrm");
|
||||
expect(bbBody[2].value.type).toEqual("font");
|
||||
});
|
||||
|
||||
it("should work with \\textcolor", function() {
|
||||
@@ -2802,6 +2805,20 @@ describe("A macro expander", function() {
|
||||
{"\\mode": "\\TextOrMath{t}{m}"});
|
||||
});
|
||||
|
||||
it("\\char produces literal characters", () => {
|
||||
expect("\\char`a").toParseLike("\\char`\\a");
|
||||
expect("\\char`\\%").toParseLike("\\char37");
|
||||
expect("\\char`\\%").toParseLike("\\char'45");
|
||||
expect("\\char`\\%").toParseLike('\\char"25');
|
||||
expect("\\char").toNotParse();
|
||||
expect("\\char`").toNotParse();
|
||||
expect("\\char'").toNotParse();
|
||||
expect('\\char"').toNotParse();
|
||||
expect("\\char'a").toNotParse();
|
||||
expect('\\char"g').toNotParse();
|
||||
expect('\\char"g').toNotParse();
|
||||
});
|
||||
|
||||
// TODO(edemaine): This doesn't work yet. Parses like `\text text`,
|
||||
// which doesn't treat all four letters as an argument.
|
||||
//it("\\TextOrMath should work in a macro passed to \\text", function() {
|
||||
@@ -3070,7 +3087,9 @@ describe("Unicode", function() {
|
||||
});
|
||||
|
||||
it("should parse symbols", function() {
|
||||
expect("£¥ðℂℍℑℓℕ℘ℙℚℜℝℤℲℵℶℷℸ⅁∀∁∂∃∇∞∠∡∢♠♡♢♣♭♮♯✓°¬‼⋮\u00b7").toParse(strictSettings);
|
||||
expect("ð").toParse(); // warns about lacking character metrics
|
||||
expect("£¥ℂℍℑℓℕ℘ℙℚℜℝℤℲℵℶℷℸ⅁∀∁∂∃∇∞∠∡∢♠♡♢♣♭♮♯✓°¬‼⋮\u00B7\u00A9").toBuild(strictSettings);
|
||||
expect("\\text{£¥\u00A9\u00AE\uFE0F}").toBuild(strictSettings);
|
||||
});
|
||||
|
||||
it("should build Greek capital letters", function() {
|
||||
|
@@ -128,4 +128,9 @@ describe("A MathML builder", function() {
|
||||
"\\texttt{tt\\textit{italic\\textbf{bold italic}}\\textbf{bold}}}"))
|
||||
.toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('\\html@mathml makes clean symbols', () => {
|
||||
expect(getMathML("\\copyright\\neq\\notin\u2258\\KaTeX"))
|
||||
.toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user