Summary
We'd like contributors to use the same linter and lint rules that we use
internally. This diff swaps out eslint for jshint and fixes all lint failures
except for the max-len failures in the test suites.
Test Plan:
- ka-lint src
- make lint
- make test
Reviewers: emily
This is almost like the align* environment, but it starts out in math mode,
so we don't have to worry about the fact that we have no real surrounding
text mode in KaTeX. This is the first step towards align* and align.
This is an attempt to actually exercise all the code paths which can lead to
a ParserError exception (from malformed user input, without tinkering with
any KaTeX internals or exploiting a KaTeX bug). It documents the current
state of affairs, without changing any error messages. Comments indicate
future work, particularly with respect to the position often associated with
these error messages.
Instead of having our own copy of jasmine in the repository, we use
jasmine-core as an npm dependency and load it from there. That reduces the
size of the repository and helps keeping up to date. We're not using the
transitive dependency on jasmine-core via jasmine, since the jasmine package
might change its dependency any day (although unlikely).
The katex-spec.js shipped from the server now includes all
`test/*[Ss]pec.js` (as matched via glob) so that additional spec files can
be created and will automatically get included in the browser-side test
suite. The contrib specs are not included at this point.
Visit http://0.0.0.0:7936/test/test.html while running server.js to see this
in action and verify the lack of failures.
Jasmine supports node these days, so there is no longer a need to use a
separate (and unmaintained) package to provide such bindings.
Making the switch exposed several misuses of the `toMatch` assertion in the
existing specification. Most of them were converted to `toEqual`, since
`toMatch` is only for matching against regular expressions.
There are two main motivations for this commit. One is unicode input, which
requires unicode characters to get past the lexer. See discussion in #261.
The second is in preparation for #266, where we'd deal with one token of
look-ahead but might be lexing that token in an unknown mode in some cases.
The unit test shipped with this commit addresses the latter concern, since
it checks that a math-mode-only token may immediately follow some text mode
content group.
In this new implementation, all the various things that could get matched
have been collected into a single regular expression. The hope is that
this will be beneficial for performance and keep the code simpler.
The code was written with Unicode input in mind, including non-BMP codepoints.
The role of the lexer as a gate keeper, keeping out invalid TeX syntax, has
been abandoned. That role is still fulfilled by the symbols and functions
tables, though, since any input which is neither a symbol nor a command is
still considered invalid input, even though it lexes successfully.
Summary: For some reason, adding `border-style: solid` also adds a 3px
border around elements, which means that all of the rules that we
created are 3px too large. This sets the default size to 0 for all the
edges, which makes them correct.
Test plan:
- See that `a\rule{0em}{0em}b` produces no visible rule.
- See the new screenshots look reasonable.
Since all the math font test cases use the KaTeX logo, we need that.
I started with the definition of the logo from katex.less, but tweaked that
until it gave a good visual match, in particular a very similar logo width,
no matter the actual numbers.
With that logo, most tests can be compiled again, with the exception of the
one containing illegal functions to test visual error reporting.
That one needs to be explicitely disabled.
Also, the MathBb-chrome test changed, to what I believe is the correct
result? Not sure why it looked wrong before.
Test plan:
- `make test`
- take screenshots, see nothing changed.
When rebasing for 2e002ff37a I forgot to
re-create the screenshots based on the new parent. As a consequence, the
font testing images from fd2d58fd80 were not
updated for Firefox and not even included for Chrome.
We still have the strange issue that Lap can result in one of two possible
screenshots, and while the previous commit recreated one of them, this one
here recreates the other.
The combination of jspngopt and pako should eliminate possible causes for
different PNG encodings, although the core reason for #325 remains unknown.
Pako has poorer compression rates than native libz, but optimization can
counter that effect, and actually reduce the size of the screenshots.
The screenshots for LimitControls and UnsupportedCmds on Firefox used to
exhibit subpixel rendering before, for reasons unknown. The regenerated
versions don't exhibit this. See #324 for a discussion.
This adds the ability to add `|` to a column description and have
vertical separators be added. I added types to the column descriptions
and added some logic to handle the separators when building the vertical
lists of the array.
Test plan:
- See the Arrays screenshot looks good.
- `make test`
At the moment, the tool isn't suitable for automatic regression tests yet,
since some symbols will require human verification. That might change in
the future though, with a list of manually verified symbols which can be
skipped in automatic verification. For this reason the file got placed into
the test directory.
Summary:
Update the MathJaxFonts `Dockerfile` to enable the use of
`ttfautohint` which hints our fonts better. Also, fix the location that
batik is downloaded from, update some formatting in the `Dockerfile`,
and update the fonts and metrics.
Test Plan:
- Compare a rendered `= - A z 4 \Longrightarrow \Sigma \Biggl(` in
Chrome on Windows at font sizes 10px to 20px before and after this
change.
- See that characters look about the same, or better.
- See that the screenshot tests didn't change in firefox (maybe firefox
runs the same autohinting algorithm that we do?), and don't visually
change in chrome
Reviewers: kevinb, alpert
Reviewed By: kevinb, alpert
Differential Revision: https://phabricator.khanacademy.org/D18977
Escaping TeX in JSON as query strings is a pain: you have to double all the
\\, you have to escape the & and the #, you can't easily include line breaks
for readability, and so on. YAML solves most of these problems for most of
the situations. Now each test case can be structured, while simple test
cases only consist of a line of verbatim TeX code, with no escaping.
The most troublesome items remaining are lines starting in { since in YAML
these would denote inline mapping types. We use block notation for these.
Since the Selenium images are available for download, and downloading them
is usually faster than building them from scratch, this makes taking
screenshots easier. Furthermore, since the Selenium image is not specific
to KaTeX, it could as well be used for other purposes, thus saving space
since a single image can be used in multiple projects.
This change also deals with the non-determinism in the Lap screenshot:
We detect the one known (and accepted) alternate rendering and change the
output file name to Lap_alt in this case. So either Lap or Lap_alt gets
saved to, and if the image is different from both, then one of these files
will show a modification. On the other hand, if it is equal to either of
these, then the matching one will get overwritten, showing no change.
A fraction is surrounded by a box of width \nulldelimiterspace on either side.
That size is 1.2pt and does not scale with the style or font size.
Furthermore, a \frac creates a brace-enclosed group which results in a
\mathord, not a \mathinner.
The same test cases we use for our screenshots from Firefox are now also
being rendered by pdflatex, so the resulting images can be used as reference
for how things are supposed to look (if we concentrate on compatibility with
LaTeX). To make comparisons even easier, the differences between LaTeX and
Firefox snapshots are rendered in a visual way, using different colors.
Discussed in pull request #268.
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:
On https://app.asana.com/0/34646644303310/33935538887378, @eater requested we add some new colors to KaTeX, which lives in the spin-off Khan/KaTeX open source project. (See screenshot for colors.) I added these colors to KaTeX so math typesetting tools in exercises have access to them.
I used "blueA", "blueB", etc. because dashes and numbers aren't supported in KaTeX/LaTeX functions.
The actual mapping of color name => hex value is in "Options", and the listing of colors available for typesetting is in "functions".
See also https://phabricator.khanacademy.org/D18158 for the related additions to utils/math.js and KAthJax.
Test Plan:
- Set up the KaTeX dev environment (instructions taken from https://github.com/Khan/KaTeX/blob/master/CONTRIBUTING.md):
```
cd KaTeX
make setup
make serve
```
- Now that the server is up and running, visit http://localhost:7936/ to try live typesetting. Enter the following LaTeX code to try the new colors:
```
\blueE{e=mc^2}
```
- Try other new colors including \redD, \mintC, \grayH, \kaBlue, etc.
- Old colors like \orange should still work.
- Run the Jasmine test suite at http://localhost:7936/test/test.html.
Reviewers: emily
Reviewed By: emily
Subscribers: nataliefitzgerald, eater, cameron, david
Differential Revision: https://phabricator.khanacademy.org/D18152
Summary:
Make the lint checker check more files. Also, make arc run the
linter.
Test Plan:
- `arc lint`
- `make lint`
Reviewers: kevinb, alpert
Reviewed By: alpert
Differential Revision: https://phabricator.khanacademy.org/D17509
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:
The greediness of the `\color` function wasn't set correctly,
leading to expressions like `\color{red}\text{a}` parsing correctly,
when they shouldn't. (This is based on how MathJax parses, since TeX
doesn't have a `\color` function, so MathJax is the standard).
Test Plan:
- Make test
- See that `\color{red}\text{a}` doesn't parse (like MathJax)
- See that `\color{red}{\text{a}}` does parse (like MathJax)
- See that `\color{red}\frac12` doesn't parse (like MathJax)
- See that `\color{red}{\frac12}` does parse (like MathJax)
- See that `\red\text{a}` doesn't parse (like MathJax)
- See that `\red{\text{a}}` does parse (like MathJax)
- See that `\red\frac12` doesn't parse (like MathJax)
- See that `\red{\frac12}` does parse (like MathJax)
Reviewers: alpert
Reviewed By: alpert
Differential Revision: https://phabricator.khanacademy.org/D17130
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:
Create our own screenshotting script which takes screenshots. This
improves over huxley for a couple reasons:
- It makes the screenshots the correct size (for some reason, huxley struggles
with this).
- Its configuration matches more with what we want (we don't need multiple
screenshots or interaction, we just want a single static shot)
- It runs faster
I also changed the docs to reflect this change.
Test Plan:
- Make sure all of the tests that were in the Huxleyfile are now in ss_data.json
- Run the screenshotter docker
- Make sure all of the images look reasonable and don't change (except
sometimes the Lap test, which has some strange pixel-positioning
differences...)
Reviewers: kevinb
Reviewed By: kevinb
Differential Revision: https://phabricator.khanacademy.org/D16731
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
Summary:
Add the ability to pass in options to the render calls which contain information about the parse. This information is passed around to the parser and builder, which parse and render differently depending on the options. Currently, this includes an option to render the math in display mode (i.e. centered, block level, and in displaystyle).
Also added some changes to make it easier to add new data to functions (now that new data doesn't need to be copied into the ParseFuncOrArg data structure, it is looked up when it is needed) and has more sane support for the `'original'` argType (as suggested by pull request #93).
Test Plan:
- Make sure tests and lint pass
- Make sure huxley screenshots didn't change, and new screenshot looks correct
Reviewers: alpert
Reviewed By: alpert
Differential Revision: https://phabricator.khanacademy.org/D13810