Commit Graph

598 Commits

Author SHA1 Message Date
Kevin Barabash
e192be2177 Update package.json to point 'main' at dist/katex.js (#791)
Summary:
Now that we're using ES6 import statements in our source code
it makes it difficult for people to consume the katex package
as a node module unless they're using node.js version 8.x.

This diff points the node entry to dist/katex.js which
is the compiled version of katex.js.

Test Plan:
- publish
- create a new project node project and add the new npm katex package as a deep
- require katex in a test file and run it using node.js version 6.x
2017-08-15 00:15:34 +09:00
Kevin Barabash
fafaf85f96 Fix MathML output for ' and large operators with limits (#788)
Summary: (@kevinbarabash)
This diff extracts MathML builder tests out into a separate file and
updates them to use jest snapshot testing.  It updates the output of
prime ' from using identifier nodes <mi> to operator nodes <mo>.  It
also updates large operators with limits to use munderover instead
of msupsub. I added an option to remove unnecessary mrows to buildGroup.
Right now it's only used for by groupTypes.supsub. I'll see if it can be used
elsewhere (everywhere?) in a follow up PR.

Test Plan:
- make test w/o errors
- verify mathml snapshots contain the desired markup
2017-08-14 22:27:48 +09:00
Kevin Barabash
e00738d16f Accept all existing Greek letters using unicode characters in math mode (#410)
Test Plan:
- make test
- run screenshot tests on travis-ci
2017-08-14 00:31:43 -04:00
Kevin Barabash
ef66f30912 Bump master to v0.8.2-pre 2017-08-11 22:14:52 -04:00
Ben Alpert
3e9d66c067 Fix Makefile to include images in build files (#784)
Test Plan:
Ran `make` then `find build/katex`. New entries:

```
build/katex/images
build/katex/images/bcancel.svg
build/katex/images/cancel.svg
build/katex/images/doubleleftarrow.svg
build/katex/images/doubleleftrightarrow.svg
build/katex/images/doublerightarrow.svg
build/katex/images/hookleftarrow.svg
build/katex/images/hookrightarrow.svg
build/katex/images/Image-Licensing-and-Technical-Notes.txt
build/katex/images/leftarrow.svg
build/katex/images/leftdoublearrow.svg
build/katex/images/leftharpoon.svg
build/katex/images/leftharpoondown.svg
build/katex/images/leftrightarrow.svg
build/katex/images/leftrightharpoons.svg
build/katex/images/linesegment.svg
build/katex/images/longequal.svg
build/katex/images/mapsto.svg
build/katex/images/overbrace.svg
build/katex/images/overgroup.svg
build/katex/images/rightarrow.svg
build/katex/images/rightharpoon.svg
build/katex/images/rightharpoondown.svg
build/katex/images/rightleftharpoons.svg
build/katex/images/tilde1.svg
build/katex/images/tilde2.svg
build/katex/images/tilde3.svg
build/katex/images/tilde4.svg
build/katex/images/tofrom.svg
build/katex/images/twoheadleftarrow.svg
build/katex/images/twoheadrightarrow.svg
build/katex/images/underbrace.svg
build/katex/images/undergroup.svg
build/katex/images/widehat1.svg
build/katex/images/widehat2.svg
build/katex/images/widehat3.svg
build/katex/images/widehat4.svg
build/katex/images/xcancel.svg
```

Verified `unzip -l build/katex.zip` shows them too. Added this file to `build/katex/test.html` and it renders without error and I see the SVG included via devtools:

```
<!DOCTYPE html>
<link rel="stylesheet" href="katex.css">
<script src="katex.js"></script>
<div id="container"></div>
<script>
katex.render("\\overbrace{xyyyyyyyyyyyyyyyyyyyyyyyyyz}", container);
</script>
```
2017-08-11 22:11:02 -04:00
Kevin Barabash
107d5284b5 Bump master to v0.9.0-pre 2017-08-11 20:00:34 -04:00
Kevin Barabash
d16d5dfd3f Replace --exit-status with --exit-code
Summary:
My version of git and the online docs for git-diff show --exit-code as
the option to return the status code, not --exit-status.  This commit
updates release.sh to use --exit-code in place of --exit-status.

Test Plan:
- ./release.sh 0.8.0 0.9.0

Auditors: emily
2017-08-11 19:23:24 -04:00
Erik Demaine
a0bedcce8e Support absolute TeX units (#732)
* Support absolute TeX units

* Implement @kohler's comments

* Rewrite unit documentation according to @kohler's comments
2017-08-11 18:30:06 -04:00
Eddie Kohler
dcdca732a3 Improve rule coding, including for \sqrt. (#776)
* Improve rule coding.

* Rule widths (overline, underline, fraction, sqrt) actually scale
  with the current font size in AMS-TeX. Implement that. (Sqrt is
  a special case: the rule width depends on the font size *of the
  surd*.)
* Change the CSS coding for rules. The old, complex coding prevented
  variable-width lines and may have contributed to issues like #696.
  Its purpose, according to 0a3a2271f4,
  was IE8 support; but KaTeX no longer supports IE8.

* The 0.5px offset makes larger sizes better, smaller sizes worse.

Smaller sizes seem more important.

* Cleanup (intended to be squashed).
2017-08-06 15:11:23 -04:00
Eddie Kohler
766487bfe3 Solve Safari rendering issues with font-size overrides. (#780)
Some delicate surgery is required on the `vlist-s` table-cell CSS.
Problem with #768 reported by @ronkok; issue #779. Fixes:

* `font-size: 1px` (rather than `font-size: 0.05em`) solves render
  issues with user overrides of the `.katex` `font-size`.
* Also fix a width issue.
2017-08-01 23:37:52 -04:00
Kevin Barabash
1e148746f8 Revert "Make KaTeX work in Quirks mode (#608)" (#777)
This reverts commit d93a958379.
2017-07-30 23:28:58 -04:00
Emily Eisenberg
d93a958379 Make KaTeX work in Quirks mode (#608)
* Make KaTeX work in Quirks mode

Summary: In issue #601, it was noticed that the KaTeX bug with the fraction
bars overlapping the text was occuring with an XHTML doctype. This indicated
that the bug we were seeing was caused by both quirks mode and limited-quirks
mode (which is a version of quirks mode with fewer quirks and is enabled for
various doctypes including some XHTML ones).

Based on the [quirks spec](https://quirks.spec.whatwg.org/), it appears that
there are only two quirks in limited-quirks mode, both having to do with a
line-height calculation. @gagern figured out that if we added some zero-width
spaces in our elements, we would stop triggering the quirk, which would make
our fractions render correctly in limited-quirks mode.

I implemented that change, and ran the screenshotter in limited-quirks mode.
There were several other places that suffered from the same quirk, but were
also easily fixed via adding zero-width spaces. I then ran the screenshotter in
quirks mode, and discovered that (once an appropriate meta charset was added),
everything looked correct still.

So, this diff fixes all of the places that the limited-quirks mode quirks
affect our rendering, and removes the warning about rendering in quirks mode.

I also added support to our screenshotter to render things in both no-quirks
and quirks mode, to ensure that things don't break in the future. I copied the
non-quirks images to the quirks images, and ran the screenshotter with
`--verify` to make sure that they look the same.

I have some thoughts that I'd like to hear opinions about:
 - I'm not super happy with how the screenshot tests work. Ideally we'd test
   both quirks mode and non-quirks mode against the same images, since we'd
   like them to be the same. I'm not sure how to make that work well, though,
   since then people wouldn't be able to tell if it's a quirks-mode problem or
   not.
 - I removed the doctype in the testing page file, so all testing would now be
   done in quirks-mode. Not sure if we really want that.
 - I need to test this in IE, but it looks like the trailing commas change we
   made with eslinting is causing problems (cause IE doesn't like trailing
   commas).

Test Plan:
 - `./dockers/Screenshotter/screenshotter.sh --verify`

* Compare quirks mode against same screenshot files

Now the screenshotter itself can run more than one mode.  It does serve the
HTML file from its own JavaScript code now, so that it can include different
doctype headers without needing distinct files for each.  There is a
provision to mark specific tests as quirky in case they produce different
results depending on the mode.

* Some cleaning up and comments

* Restore access to the babelified version of the HTML page for screenshots

* Reference unicode fonts using absolute path names

This avoids issues caused by the fact that the dynamically generated
ss-render.html is mounted to a different location than the test.html from
which it is derived.

* do chrome screenshots first

* remove commented out code, simplify hadle_search_string call
2017-07-30 22:41:37 -04:00
Jörn Lenoch
2eb32a8775 Add configurable error callback (#658)
Replace console.error with a configurable option. This mimcs the current
default behaviour to guaranteee compatibility with previous versions.
Update errorCallback to the README.md
2017-07-30 11:27:29 -04:00
Eddie Kohler
2da06d541e Shrinkwrap vlists in table-like CSS. (#768)
TeX and CSS treat line heights in fundamentally different ways. In
TeX, every character is treated as a box of its precise height and
depth; the line height (\baselineskip) applies after characters have
been assembled into lines. In CSS, in contrast, every character
creates a "line box" corresponding to the accompanying font. When
characters of different fonts and sizes are placed into the same
span, the resulting line box contains the line boxes of all children.

This is unfortunate because, for example, we want `\frac{1}{2}` to
behave in vertical spacing contexts like it is exactly as tall and
deep as the visible fraction (which is the TeX behavior). Given CSS
constraints, though, in most contexts the fraction has extra vertical
space: the line boxes for the numerator and denominator create
padding. For small boxes, this isn't so bad. To really see the
problem put a tall rule in the denominator of a fraction, or check
out the VerticalSpacing screenshotter test, which has way more space
than it should.

Solving this problem in CSS is difficult. There is no easy way to get
rid of the extra line boxes.

But there is *a* way, namely tables. A table-cell with vertical-align
top, bottom, or middle is ignored for the purposes of line height
calculation.

So in this commit, makeVList puts its contents into a
vertical-align:bottom table-cell (to clear unwanted line boxes), with
an extra row used to represent depth.

Many Chrome screenshotter tests change. This is because Chrome rounds
table dimensions to integral numbers of pixels, while it uses
sub-pixel positioning for non-table displayed tabs. That makes many
vlists a fraction of a pixel wider than they used to be.
2017-07-30 11:13:55 -04:00
Eddie Kohler
32c7fc47d1 Ensure screenshotter runs *all* tests. (#769)
Previously, we added a `oneDone` promise *every time a test attempt
failed*. This decremented the count of remaining tests once per
failed attempt. As a result, Chrome tests didn't run to the end.
2017-07-29 21:27:26 -04:00
Kevin Barabash
8c53698b35 Update {b,x}cancel to have a 0.5px transition in gradient so that the lines are antialiased (#761) 2017-07-22 15:42:43 -07:00
Eddie Kohler
e7658ccd76 Test site supports before= and after= search parameters.
They add text before/after the math. Example use: testing baseline alignment.
2017-07-21 13:45:49 -04:00
Eddie Kohler
050905f804 Supply marginLeft/marginRight as inputs to makeVList.
Current code, which modifies the returned elements from makeVList,
is fragile: if makeVList internals changed, the callers would have
to change too.
2017-07-21 13:06:13 -04:00
Erik Demaine
440ba6dd1f Use \displaystyle within \over/\underbrace (#765) 2017-07-15 18:41:00 -04:00
Kevin Barabash
5b6c222cd6 rename parseData.js to ParseNode.js and export ParseNode as the default 2017-07-15 16:26:30 -04:00
Kevin Barabash
361c500a7f Switch from jasmine to jest (#747)
Summary:
The reasons for switching to jest:
- easy snapshot testing so that we can easily verify the structure of the parse tree and MathML tree
- easy compilation of ES6 features for tests as we continue to expand our use of ES6

Test Plan:
- npm test
2017-07-11 14:16:26 -04:00
Eddie Kohler
4480f2c987 Correct computation of TeX sizes. (#755)
* Em and mu sizes are relative to current font's quad metric,
  which might not be "1em" in CSS terms.
* We don't need the `emPerEx` metric, because we want to convert
  TeX `ex` to CSS `em`, not TeX `ex` to TeX `em`. The `xHeight`
  metric does that already: it is relative to font size.
* Mu sizes scale with the style, em and ex do not (empirically
  checked; agrees with rule 2 of TeXbook Appendix G).
  This corrects a bug in b866cd5224 (in which em scaled),
  and a bug in previous versions (in which mu did not scale).
* Correct rule sizes. Previous comment---"the sizes of rules are
  absolute"---was misleading. Rule sizes are NOT absolute---in
  \large size, a rule denominated in 'em' is larger. But the 'em'
  unit is not sensitive to styles. So now a 1em rule will be the
  same size in super/subscript, as it should be, but an 18mu rule
  will change size in super/subscript, as it should.

Note a TODO.
2017-07-09 17:23:00 -04:00
Eddie Kohler
782484eb75 Set maxFontSize on rules. (#744)
This is needed in vlists, as in #646, to make fontsize-ensurer
nodes big enough.
2017-07-08 20:22:29 -04:00
Eddie Kohler
f43b00b50f Screenshotter: Add --diff and --attempts options. (#736)
--diff produces a texcmp-like diff in test/screenshotter/diff.
2017-07-06 08:49:34 -04:00
Eddie Kohler
1704d3b003 Speed up screenshot by avoid a full page + asset load for each test
The slowest part of screenshotter tests is the page load, probably
because so many assets must be loaded over the slow docker
connection. On my laptop this takes ~4s per test. The new default
avoids this cost by rendering new TeX on the existing
page. For second and subsequent tests, use `executeAsyncScript`
to call KaTeX, rather than performing a full page + asset load.
(If too many errors happen in `--verify` mode, we fall back to
full loads.)  The `--reload` flag will enable the previous behavior.

On my laptop, a full verify (chrome + FF) used to take 12m20s+.
It now takes 2m23s, a speed up of 6x.
2017-07-04 00:13:57 -04:00
Hossein Saniei
a019f36f8a Upgrade the source to use ES6 syntax including classes, import and static properties (#679)
* Add babel transform-class-properties to have static class properties

* Upgrade Lexer and Parser files to use ES6 classes

* Update eslint max line length to 90 character (more indent because of using ES6 classes)

* Upgrade eslint and jasmin to support ES stage-2 features

* Use static properties to place constants near their functions

* Migrate all remaining sources to ES6 syntax

* Increase eslint max line length to 84

* Remove non-babelified endpoint in dev server.js

* Clean up server.js functions after removing browserified

* Make screenshotter not to use babel endpoint as we babelify everything now
2017-07-03 08:09:21 -04:00
Erik Demaine
0edd3d1bbb Implement \coloneqq, \colonequals, etc. based on mathtools and colonequals (#727)
Fix #657 (modulo #725)
2017-06-30 14:52:37 -04:00
Eddie Kohler
f23bf3fe63 Associate font metrics with Options, not Style. (#743)
* Associate font metrics with Options, not Style.

Font metrics are associated with a given font and size combination.
Before KaTeX understood sizing commands, sizes were associated with
a Style. That's not true now. So instead of `style.metrics`, use
`options.fontMetrics()`, since `options` knows the font and the
size.

This is a cleanup commit with no visible effects on most tests (there
could be some small effect on size + style combinations). It will
make other changes possible later.
2017-06-30 13:50:28 -04:00
Erik Demaine
ebaa3feab3 Mention texcmp (#753) 2017-06-30 13:42:39 -04:00
Eddie Kohler
87b9123200 Correct handling of unbraced kerns followed by spaces. (#751)
Did not realize that `Parser.nextToken.text` can contain spaces
(it can). Handle that.
2017-06-30 13:40:41 -04:00
Eddie Kohler
aa1722c8b6 Vertically center single-character \mathop. (#745)
* Vertically center single-character \mathop.

Fix #726.

* Add screenshotter test
2017-06-30 08:49:00 -07:00
Eddie Kohler
b866cd5224 Fix interaction between styles and sizes. (#719)
* Fix interaction between styles and sizes by implementing styles as sizes.

Rather than having both `textstyle` CSS classes and `size5` CSS classes
affect the font size (and step on each other), implement sizes more the
way TeX does: a command like `\displaystyle` changes the current size.

This is actually a simplification, since now only `size` affects the size.
Simplifies CSS and computation. Many screenshotter tests change; they
change to be more like TeX. For instance, `\sqrt` fixes some
discrepancies in size treatment.

Also:

Remove the `Options.withX()` methods in favor of `.havingX()`, which
might return the same `options`.

Remove `Style.cls()` and `Style.reset()`.

Remove `Options.reset()`. You should never modify an `Options`; they
should change only by the `havingX()` methods.

* Implement TeX sizing for scriptsize/scriptscriptsize.

At every size level. Also make the sizes match TeX to the last decimal.

* Review comments.
2017-06-27 20:55:14 -04:00
Ron Kok
4f57d53f6e Show correct browser support (#737)
* Show correct browser support

KaTeX runs in IE 9 but not in IE 8. This PR edits the README and
Contributing files to reflect that fact.

Resolves issue #377.

* Show correct browser support

KaTeX runs in IE 9 but not in IE 8. This PR edits the README and
Contributing files to reflect that fact and adds Edge to browser list.

Resolves issue #377.
2017-06-25 17:50:31 -04:00
Erik Demaine
a36709d239 Add documentation for how to run auto-render example (#740) 2017-06-25 17:47:46 -04:00
Kevin Barabash
29fc2d56d4 Remove duplicate comment 2017-06-16 00:00:43 -04:00
Ron Kok
eff7653c51 Support stretchy wide elements. (#670) 2017-06-15 23:47:51 -04:00
Erik Demaine
eaa7f3a17d Fix high contrast mode better, thanks to @GeeLaw (#733) 2017-06-15 19:01:58 -04:00
Alex Pearce
60b1969a01 Support all render options in auto-render.
Closes #690.
2017-06-14 10:50:14 -04:00
Erik Demaine
25dde7f841 Implicit \color, explicitly grouped \textcolor (#619) 2017-06-12 23:11:27 -04:00
Martin von Gagern
ad0abbd4e9 Update texcmp to ubuntu 17.04 and avoid mounted host directory (#722)
* Update texcmp to ubuntu 17.04 and avoid mounted host directory

Switch to linux 17.04 in order to have a version of nodejs which understands
ES6 syntax, for the sake of a consistent codebase.
Avoid mounting the host directory, but use “docker cp” instead to transfer
files between host and container.  This should avoid ownership and
permission issues.
Support macros with positional arguments.
Fix one overline example which caused LaTeX failure due to missing braces.

* Extract texcmp results as current user

This allows running the texcmp.sh script using sudo on afs.

* Change texcmp conversion to gray

As per #708, this should increase compatibility with older versions of
imagemagick, and might also do a better job of preserving the original sRGB
color space.

* Abandon tar and use plain docker cp instead

Thanks to Erik Demaine for suggesting this.

* Move npm install into creation of texcmp docker image
2017-06-11 16:02:06 -04:00
Erik Demaine
06d6c96894 Add \jot lineskip to aligned environment, switch contents to displaystyle, and add gathered (#725) 2017-06-10 17:10:29 -04:00
Kevin Barabash
95af9379da Merge pull request #724 from edemaine/highcontrast
Support Windows high-contrast mode. Fix #716
2017-06-10 16:07:00 -04:00
Erik Demaine
7fdb1eed81 Implement $...$ within \text via styling node (#637) 2017-06-10 16:03:22 -04:00
Erik Demaine
a564c0aeef Support Windows high-contrast mode. Fix #716 2017-06-10 12:58:55 -04:00
Kevin Barabash
9913242245 Merge pull request #718 from kohler/fix-711
Fix #711 issue with multiple superscripts.
2017-06-06 20:38:10 -04:00
Eddie Kohler
3af23fd8a4 Fix #711 issue with multiple superscripts.
The previous code incorrectly implemented TeXbook rules. First off,
the font metrics at issue should be those for the superscript/
subscript style, not the main style. Secondly, the metrics should be
scaled by the font size.

This changes some screenshotter tests (and they look more like TeX
now).
2017-06-05 23:52:16 -04:00
Kevin Barabash
9f3f445360 Merge pull request #684 from edemaine/anglebracket
Support <, >, | and many \text... commands in text mode
2017-05-16 20:19:38 -04:00
Kevin Barabash
78be8d4a29 Merge pull request #697 from edemaine/implies
Add \iff, \implies, \impliedby support
2017-05-16 20:02:39 -04:00
Erik Demaine
1428136e52 Support <, >, |, and long-form symbols. Fix #662
Add long-form aliases for various text symbols

* \textgreater is an alias for > in text mode
* \textless is an alias for < in text mode
* \textbar is an alias for | in text mode
* \textdollar is an alias for \$ in text mode
* \textunderscore is an alias for \_ in text mode
* \textbraceleft is an alias for \{ in text mode
* \textbraceright is an alias for \} in text mode
* \textless is an alias for < in text mode
* \textgreater is an alias for > in text mode
* \textbar is an alias for | in text mode
* \textbardbl is an alias for \| in text mode
* \textendash is an alias for -- in text mode
* \textemdash is an alias for --- in text mode
* \textquoteleft is an alias for ` in text mode
* \textquoteright is an alias for ' in text mode
* \textquotedblleft is an alias for `` in text mode
* \textquotedblright is an alias for '' in text mode
* \textdagger is an alias for \dag in text mode
* \textdaggerdbl is an alias for \ddag in text mode
* \textsterling is an alias for \pounds in text mode
* \dag, \ddag work in text mode
* \circledR, \checkmark, \pounds work in text mode too
* Extend Symbols1 test to test \pounds and \textdollar in \text
* Add note about \pounds in text vs. math mode
2017-05-16 18:03:47 -04:00
Erik Demaine
46f34181e3 Add \iff, \implies, \impliedby support. Fix #190.
* Based on @ronkok's code, but without \mathrel as it's absent
  from amstex.sty.
* Add toBuild tests to ensure these operators expand.
2017-05-16 17:50:06 -04:00