-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite spacing commands and \mod as macros #1156
Conversation
Fix KaTeX#1130 by defining `\!`, `\negthinspace`, `\,`, `\thinspace`, `\:`, `\medspace`, `\;`, `\thickspace`, `\negmedspace`, `\negthickspace`, `\enspace`, `\enskip`, `\qquad`, `\quad` as macros. Fix KaTeX#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
Codecov Report
@@ Coverage Diff @@
## master #1156 +/- ##
==========================================
+ Coverage 81.56% 82.29% +0.72%
==========================================
Files 78 77 -1
Lines 4259 4242 -17
Branches 734 732 -2
==========================================
+ Hits 3474 3491 +17
+ Misses 670 649 -21
+ Partials 115 102 -13
Continue to review full report at Codecov.
|
src/mathMLTree.js
Outdated
*/ | ||
toMarkup(): string { | ||
if (this.character) { | ||
return this.character; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused about the correct markup here. Perhaps it should be `<mtext>${this.character}</mtext>
`, and then we need to remove this <mtext>
wrapper if it gets included in an <mo>
or other token element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to do this either. In the past I've look at what MathJax outputs, but <mspace width="thinmathspace" />
doesn't seem ideal. Is it bad if we include <mtext>
nodes inside <mo>
or other element types?
@@ -142,7 +141,7 @@ exports[`A MathML builder should output \\limsup_{x \\rightarrow \\infty} correc | |||
<msub> | |||
<mo> | |||
<mi mathvariant="normal"> | |||
lim sup | |||
lim&ThinSpace;sup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This extra escaping is a bug, caused by operatorname
's mathmlBuilder
creating a mathMLTree.TextNode
, which escapes its text. I'm not quite sure how to fix it, other than switching to the Unicode representations...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're definitely doing something wrong here. In toNode
we call document.createTextNode
which expects to be passed an escaped string, yet we're passing this.text
. I feel like we should maybe be doing the escaping within the constructor and then we could add an escape
as an optional second parameter with the default being true
.
@edemaine looks like some of the screenshots changed. Could you add updated screenshots when you have some time? |
@kevinbarabash Done. This has revealed more bugs, which I'll take a look at later. |
@edemaine what kind of bugs did this reveal? |
@kevinbarabash I meant bugs in this PR. I just merged with the many changes on master, and will take another look at this. CircleCI's screenshot diffs will help too! Here are the diffs, for the record: Specifically, |
I finally took a look at these. It turns out that the big changes are actually bug fixes!
|
@edemaine there are some |
@kevinbarabash Oops, fixed! |
The |
@kevinbarabash Thanks for spotting those -- not sure how I missed Mod in particular. c6f3a7a recompiles the The problem with the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for also improving the MathML output to include all of those specific spacing characters.
@@ -24,7 +24,6 @@ import "./functions/lap"; | |||
import "./functions/math"; | |||
import "./functions/mathchoice"; | |||
import "./functions/mclass"; | |||
import "./functions/mod"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
if (width >= 0.05555 && width <= 0.05556) { | ||
this.character = " "; // \u200a | ||
} else if (width >= 0.1666 && width <= 0.1667) { | ||
this.character = " "; // \u2009 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
// See https://www.w3.org/TR/2000/WD-MathML2-20000328/chapter6.html | ||
// for a table of space-like characters. We consistently use the | ||
// &LongNames; because Unicode does not have single characters for | ||
//    (\u2005\u200a) and all negative spaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't don't understand this comment. I don't see $LongNames;
anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant   
is an example of a long name between a &
and ;
, as opposed to the Unicode equivalent. See the table in Section 6.1.4. I could change to &CharacterNames;
or just "character names" if that would be clearer.
@kevinbarabash Thanks for the review! |
Fix #1130 by defining
\!
,\negthinspace
,\,
,\thinspace
,\:
,\medspace
,\;
,\thickspace
,\negmedspace
,\negthickspace
,\enspace
,\enskip
,\qquad
,\quad
as macros. Some of these are new. Also, we now use the AMS definitions of spaces, which are slightly different (e.g., using 1mu = 1/18em instead of .05555em, and working in text mode instead of just math mode).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