This commit introduces environments, and implements the parser
infrastructure to handle them, even including arguments after the
“\begin{name}” construct. It also offers a way to turn array-like data
structures, i.e. delimited by “&” and “\\”, into nested arrays of groups.
Environments are essentially functions which call back to the parser to
parse their body. It is their responsibility to stop at the next “\end”,
while the parser takes care of verifing that the names match between
“\begin” and “\end”. The environment has to return a ParseResult, to
provide the position that goes with the resulting node.
One application of this is the “array” environment. So far, it supports
column alignment, but no column separators, and no multi-column shorthands
using “*{…}”. Building on the same infrastructure, there are “matrix”,
“pmatrix”, “bmatrix”, “vmatrix” and “Vmatrix” environments. Internally
these are just “\left..\right” wrapped around an array with no margins at
its ends. Spacing for arrays and matrices was derived from the LaTeX
sources, and comments indicate the appropriate references.
Now we have hard-wired breaks in parseExpression, to always break on “}”,
“\end”, “\right”, “&”, “\\” and “\cr”. This means that these symbols are
never PART of an expression, at least not without some nesting. They may
follow AFTER an expression, and the caller of parseExpression should be
expecting them. The implicit groups for sizing or styling don't care what
ended the expression, which is all right for them. We still have support
for breakOnToken, but now it is only used for “]” since that MAY be used to
terminate an optional argument, but otherwise it's an ordinary symbol.
Summary:
Use the TeX definitions of `\root` to get the optional `\sqrt`
argument in the right place. Also add the MathML version.
Fixes#48
Test Plan:
- `make test`
- See that the images look good
Reviewers: kevinb, alpert
Reviewed By: alpert
Differential Revision: https://phabricator.khanacademy.org/D17236
Summary:
Using \phantom with non-phantom math in Perseus doesn't render to be the
same size because \phantom uses MathJax and the non-phantom math uses KaTeX.
Implementing \phantom in KaTeX should solve this alignment issue.
Test Plan:
[x] write (and run) unit tests
[x] create (and run) screenshotter tests
Reviewers: emily
Reviewed By: emily
Differential Revision: https://phabricator.khanacademy.org/D16720
Summary:
This adds support for rendering KaTeX to both HTML and MathML
with the intent of improving accessibility. To accomplish this, both
MathML and HTML are rendered, but with the MathML visually hidden and
the HTML spans aria-hidden. Hopefully, this should produce much better
accessibility for KaTeX.
Should fix/improve #38Closes#189
Test Plan:
- Ensure all the tests, and the new tests, still pass.
- Ensure that for each of the group types in `buildHTML.js`, there is a
corresponding one in `buildMathML.js`.
- Ensure that the huxley screenshots didn't change (except for
BinomTest, which changed because I fixed a bug in `buildHTML` where
`genfrac` didn't have a `groupToType` mapping).
- Run ChromeVox on the test page, render some math. (for example,
`\sqrt{x^2}`)
- Ensure that a mathy-sounding expression is read. (I hear "group
square root of x squared math").
- Ensure that nothing else is read (like no "x" or "2").
- Ensure that MathML markup is generated correctly and is interpreted
by the browser correctly by running
`document.getElementById("math").innerHTML =
katex.renderToString("\\sqrt{x^2}");` and seeing that the same speech
is read.
Reviewers: john, alpert
Reviewed By: john, alpert
Subscribers: alpert, john
Differential Revision: https://phabricator.khanacademy.org/D16373