Commit Graph

108 Commits

Author SHA1 Message Date
Kevin Barabash
14a58adb90 Migrate to eslint
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
2015-12-01 10:02:08 -08:00
Kevin Barabash
7cdb08bf7e Merge pull request #388 from gagern/updateSelenium
Update Selenium Docker images from 2.46.0 to 2.48.2
2015-11-30 21:19:29 -08:00
Martin von Gagern
8201501d77 Introduce an aligned environment
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.
2015-11-23 20:22:06 +01:00
Martin von Gagern
e7195601e1 Added unit tests for error messages
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.
2015-11-21 15:38:26 +01:00
Martin von Gagern
cc17f36edc Drop local copy of jasmine, multiple spec files in browser tests
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.
2015-11-12 18:34:31 +01:00
Martin von Gagern
4792dec8e5 Update Selenium Docker images from 2.46.0 to 2.48.2 2015-11-12 17:08:16 +01:00
Martin von Gagern
92034c17f9 Switch from jasmine-node to jasmine itself
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.
2015-11-10 12:38:49 +01:00
Kevin Barabash
9aab9c1efe Merge pull request #361 from crepererum/feature/gt_lt
Add \gt and \lt
2015-10-05 16:32:49 +00:00
Marco Neumann
95e568ed6b Add \gt and \lt 2015-10-05 08:34:03 +02:00
Martin von Gagern
d423bec089 Rewrote lexer, avoiding some mode-specific distinctions
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.
2015-10-02 20:06:03 +02:00
Kevin Barabash
b98670b8ed Set the greedines of font functions to 2 so that e^\mathbf{x} will parse
Test Plan: make test

Reviewers: emily
2015-09-25 14:17:23 -07:00
Emily Eisenberg
252f6320ef Remove 3px border around rules.
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.
2015-09-22 10:21:33 -07:00
Martin von Gagern
71881e3d36 Make texcmp work again, including KaTeX logo
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.
2015-09-10 16:05:23 +02:00
Emily Eisenberg
d6cec8a861 Rename breakOnUnsupportedCmds to throwOnError.
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.
2015-09-01 16:51:03 -07:00
Kevin Barabash
c428abca1e Merge pull request #292 from kevinb7/fonts-p3_mathml
Adds MathML support for math font commands.
2015-09-01 09:00:16 -06:00
Kevin Barabash
64e63d7546 Adds MathML support for math font commands.
This is part 3 or 3.  The first two pull requests added font metrics, HTML rendering, and screenshot tests.
2015-08-30 17:24:04 -06:00
Martin von Gagern
9c2a391ff6 (Re-)Create some more screenshots in a reproducible way
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.
2015-08-30 23:09:42 +02:00
Martin von Gagern
2e002ff37a Use jspngopt and pako to create reproducible PNG files for Chrome as well
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.
2015-08-30 02:12:55 +02:00
Kevin Barabash
72027a1a56 Merge pull request #330 from xymostech/add-vert-separator
Add | column separators to arrays.
2015-08-28 10:29:26 -06:00
Emily Eisenberg
3a8adbf595 Add | column separators to arrays.
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`
2015-08-28 08:50:42 -07:00
Kevin Barabash
fd2d58fd80 Adds math commands, HTML rendering, and screenshotter tests.
This is part 2 of 3.  Part 1 added new fonts metrics.  Part 2 will add MathML support and unit tests.
2015-08-19 22:04:34 -06:00
Martin von Gagern
1846929110 Add tool to check symbol group types against LaTeX
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.
2015-08-19 22:56:41 +02:00
Martin von Gagern
758f4a73d9 Merge remote-tracking branch 'origin/master' into ssYaml 2015-08-06 10:18:04 +02:00
Martin von Gagern
62a8b2d4e7 Whitelist keys to include in ss_data query strings 2015-08-03 22:45:22 +02:00
Kevin Barabash
b2d2df9bef Merge pull request #317 from JeffEverett/unsupported_commands
Added support for visual depiction of unsupported commands
2015-07-29 10:55:04 -07:00
Jeff Everett
9b0f42ea50 Fixed limit controls in textstyle 2015-07-28 15:22:30 -06:00
Jeff Everett
e1c221273c Added support for visual depiction of unsupported commands 2015-07-28 00:50:08 -06:00
Jeff Everett
5d83bb8cc0 Added support for \limits and \nolimits controls 2015-07-24 19:33:09 -06:00
Emily Eisenberg
ce99abd1f2 Update Dockerfile for ttfautohint, update metrics
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
2015-07-16 12:01:26 -07:00
Martin von Gagern
fb403fa9eb Switch Screenshotter data from JSON to YAML
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.
2015-07-16 08:57:17 +02:00
Martin von Gagern
b7e1581869 Update chrome screenshots
I forgot to re-create these after rebasing.
2015-07-15 15:40:31 +02:00
Martin von Gagern
6f65f685f3 Add screenshots taken from Chrome 2015-07-14 18:09:58 +02:00
Martin von Gagern
5d155c75db Switch from own docker image to standard selenium images
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.
2015-07-14 18:09:58 +02:00
Martin von Gagern
6362e0f8f2 Test case demonstrating the desired spacing around an array 2015-07-10 17:37:53 +02:00
Martin von Gagern
7dc8b68092 Improve horizontal spacing of fractions
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.
2015-07-07 10:03:34 +02:00
Martin von Gagern
c562813afa Take snapshots of formulas rendered by LaTeX and compute visual diffs
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.
2015-07-06 15:54:14 +02:00
Martin von Gagern
758bdba31e Implement cases environment
See issue #278.  Although the official definition makes use of @{…}
notation, we use custom spacing instead, since that seems easier for now.
2015-07-01 08:05:08 +02:00
Martin von Gagern
2f7a54877a Implement environments, for arrays and matrices in particular
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.
2015-06-18 22:24:40 +02:00
hathix
9869d59cad Added new exercise colors as macros
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
2015-05-26 19:07:51 -07:00
John Resig
b9eb8c74e0 Expose a new .__parse() method for generating a parse tree from a math expression. 2015-05-04 15:59:18 -04:00
Emily Eisenberg
af8c1307f7 Add better lint checking.
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
2015-04-22 18:55:20 -07:00
Emily Eisenberg
c48de165e8 Add optional arguments to \sqrt
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
2015-04-22 15:26:10 -07:00
Emily Eisenberg
99a81aca50 Fix the greediness of the \color function
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
2015-04-01 15:29:04 -07:00
Kevin Barabash
39f5bcb042 Add support for \phantom
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
2015-03-13 16:24:04 -06:00
Emily Eisenberg
51d751f96d Make text operators <mi>s
Summary: According to the MathML spec [about
identifiers](http://www.w3.org/TR/MathML3/chapter3.html#id.3.2.3.3),
text function names should be <mi>s. This fixes that.

Fixes #202

Test plan:
 - `make test`

Auditors: alpert
2015-03-13 08:11:21 -07:00
Emily Eisenberg
2f552af02d Make our own screenshotting script instead of using huxley
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
2015-03-12 16:40:15 -07:00
Emily Eisenberg
aaeab1200c Add MathML rendering to improve accessibility
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 #38

Closes #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
2015-03-01 18:33:20 -08:00
Emily Eisenberg
fd18f6979e Add an optional settings argument to render calls
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
2015-02-19 15:26:57 -08:00
Ben Alpert
2cbee18010 Add \choose support
Test Plan: Looked at `1 + 2\choose {3 \over 4}`, npm tested.

Reviewers: emily

Reviewed By: emily

Differential Revision: http://phabricator.khanacademy.org/D13903
2014-10-15 16:05:58 -07:00
Ben Alpert
006a0a761c Add support for \{,d,t}binom
Test Plan: `\binom xy^{\binom xy^{\binom xy}}` looks like something. `\dbinom` and `\tbinom` also seem to work.

Reviewers: emily

Reviewed By: emily

Subscribers: jessie

Differential Revision: http://phabricator.khanacademy.org/D13315
2014-10-14 17:01:19 -07:00