Rewrite spacing commands as macros (#1156)

* Rewrite spacing commands as macros

Fix #1130 by defining `\!`, `\negthinspace`, `\,`, `\thinspace`, `\:`,
`\medspace`, `\;`, `\thickspace`, `\negmedspace`, `\negthickspace`,
`\enspace`, `\enskip`, `\qquad`, `\quad` as macros.

Fix #1036 by defining a new `SpaceNode` in mathMLTree that recognizes
all special space amounts from
https://www.w3.org/TR/2000/WD-MathML2-20000328/chapter6.html

* Fix <mspace> rendering and add a test to catch it

* Update screenshots

* Wrap special space characters in <mtext>

* Update screenshots

* Fix MathML escaping behavior

* Fix flow typos

* Fix Unicode-chrome

* Reimplement mod operators in terms of macros

* Rerun ModScript

* Remove excess table entries (now already macros)

* Fix bmod
This commit is contained in:
Erik Demaine
2018-05-29 08:43:52 -04:00
committed by Kevin Barabash
parent 978148ec6e
commit 417383e002
21 changed files with 269 additions and 281 deletions

View File

@@ -57,6 +57,24 @@ exports[`A MathML builder accents turn into <mover accent="true"> in MathML 1`]
`;
exports[`A MathML builder normal spaces render normally 1`] = `
<math>
<semantics>
<mrow>
<mspace width="1em">
</mspace>
<mspace width="0.431em">
</mspace>
</mrow>
<annotation encoding="application/x-tex">
\\kern1em\\kern1ex
</annotation>
</semantics>
</math>
`;
exports[`A MathML builder should concatenate digits into single <mn> 1`] = `
<math>
@@ -125,8 +143,9 @@ exports[`A MathML builder should generate the right types of nodes 1`] = `
<mn>
1
</mn>
<mspace width="0.277778em">
</mspace>
<mtext>
&ThickSpace;
</mtext>
<mtext>
a
</mtext>
@@ -169,7 +188,7 @@ exports[`A MathML builder should output \\limsup_{x \\rightarrow \\infty} correc
<msub>
<mo>
<mi mathvariant="normal">
limsup
lim&ThinSpace;sup
</mi>
<mo>
@@ -204,7 +223,7 @@ exports[`A MathML builder should output \\limsup_{x \\rightarrow \\infty} in dis
<munder>
<mo>
<mi mathvariant="normal">
limsup
lim&ThinSpace;sup
</mi>
<mo>
@@ -519,6 +538,74 @@ exports[`A MathML builder should use <munderover> for large operators 1`] = `
`;
exports[`A MathML builder special spaces render specially 1`] = `
<math>
<semantics>
<mrow>
<mtext>
&ThinSpace;
</mtext>
<mtext>
&ThinSpace;
</mtext>
<mtext>
&MediumSpace;
</mtext>
<mtext>
&MediumSpace;
</mtext>
<mtext>
&ThickSpace;
</mtext>
<mtext>
&ThickSpace;
</mtext>
<mtext>
&NegativeThinSpace;
</mtext>
<mtext>
&NegativeThinSpace;
</mtext>
<mtext>
&NegativeMediumSpace;
</mtext>
<mtext>
&NegativeThickSpace;
</mtext>
<mtext>
&VeryThinSpace;
</mtext>
<mtext>
&ThinSpace;
</mtext>
<mtext>
&MediumSpace;
</mtext>
<mtext>
&ThickSpace;
</mtext>
<mtext>
&NegativeVeryThinSpace;
</mtext>
<mtext>
&NegativeThinSpace;
</mtext>
<mtext>
&NegativeMediumSpace;
</mtext>
<mtext>
&NegativeThickSpace;
</mtext>
</mrow>
<annotation encoding="application/x-tex">
\\,\\thinspace\\:\\medspace\\;\\thickspace\\!\\negthinspace\\negmedspace\\negthickspace\\mkern1mu\\mkern3mu\\mkern4mu\\mkern5mu\\mkern-1mu\\mkern-3mu\\mkern-4mu\\mkern-5mu
</annotation>
</semantics>
</math>
`;
exports[`A MathML builder tags use <mlabeledtr> 1`] = `
<math>

View File

@@ -107,4 +107,15 @@ describe("A MathML builder", function() {
expect(getMathML("\\tag{hi} x+y^2", {displayMode: true}))
.toMatchSnapshot();
});
it('normal spaces render normally', function() {
expect(getMathML("\\kern1em\\kern1ex")).toMatchSnapshot();
});
it('special spaces render specially', function() {
expect(getMathML(
"\\,\\thinspace\\:\\medspace\\;\\thickspace" +
"\\!\\negthinspace\\negmedspace\\negthickspace" +
"\\mkern1mu\\mkern3mu\\mkern4mu\\mkern5mu" +
"\\mkern-1mu\\mkern-3mu\\mkern-4mu\\mkern-5mu")).toMatchSnapshot();
});
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB