Commit Graph

823 Commits

Author SHA1 Message Date
Kevin Barabash
d8116bdc64 update defineFunction to accept a single arg, introduce flow to do some typechecking 2017-09-02 15:11:44 -04:00
Kevin Barabash
a99c7c9e0f extract delimsizing functions into their own file 2017-09-02 15:11:44 -04:00
Kevin Barabash
8bdc5e3e6a group all \phantom related code together 2017-09-02 15:11:44 -04:00
Ron Kok
092aa0c767 Add \smash, laps, spaces, and phantoms (#833)
* Add \smash, laps, spaces, and phantoms

1. Support `\smash`, including the optional argument from AMS.

2. Change `\llap` and `\rlap` so that they render in text style. Repeat: This *changes* KaTeX behavior.

3. Add `\mathllap` and `\mathrlap`. These will act as they do  in `mathtools` and as in previous KaTeX versions of `\llap` and `\rlap`.

4. Add `\mathclap` and `\clap`.

5. Add `\hphantom` and \vphantom`.

6. Add `\thinspace`, `\medspace`, `\thickspace`

7. Add `\hspace`.

This work will resolve issue #270 and parts of #50 and #164.

A. Perlis has written a [concise description](https://www.math.lsu.edu/~aperlis/publications/mathclap/perlis_mathclap_24Jun2003.pdf) of items 1 thru 5. Except for `\smash`'s optional argument. It's described in the [AMS User's Guide](http://texdoc.net/texmf-dist/doc/latex/amsmath/amsldoc.pdf).

Item 6 also comes from the AMS User's Guide.

* Fix test spec

* Exploit makeVList for smash

* update smash and phantom screenshots for chrome

* Pick up review comments

* Change test from \llap to \mathlap

\llap is fundamentally a text-mode function. We should not expect it to work correctly when given math-mode arguments. So test \mathllap instead.

* Correct \llap macro

A correction. The previous macro returned an error if given an argument with math-mode content, such as x^2.

The corrected macro will not return an error. It will instead return well rendered math, but letters are in `\mathrm` font.

* update \llap, \rlap, \clap macros to use \textrm

* update Lap screenshots
2017-09-02 14:04:30 -04:00
Xuming Zeng
211c86d39b Add a maxSize option to limit user-specified sizes (#803)
* Fix color support for stretchy, strikethrough, and fbox
Summary:
Stuff like `\red{\overbrace{AB}}` works now in addition to `\color{red}{\overbrace{AB}}`. Strikethrough now respects color. The Firefox in the screenshotter doesn't seem to support `background-image` + `mask`, but I manually tested that the latest Firefox does.

Test plan:
Ran `make`, then tested in latest Chrome and Firefox to ensure color support was working, then ran `make screenshots`.

* Add a maxSize option to limit user-specified sizes (#109)

* Simplify maxSize logic and add unit test
* Clamp negative maxSize to zero
* Use a default maxSize of infinity to remove branching in calculateSize
2017-08-31 06:39:28 -04:00
Sophie Alpert
b27d7011d1 Fix exponential behavior in accent production (#834)
src/functions.js was returning two properties referring to the base; since buildHTML runs `JSON.parse(JSON.stringify(tree))` to get an immutable copy, that meant we'd traverse and serialize and parse an exponentially-sized tree.

Test Plan: `\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{A}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}` renders instantly; previously, it reliably timed out with even half that depth.
2017-08-30 07:11:33 -04:00
Schmulik Raskin
d36ca4a2fa Add contrib to NPM files 2017-08-30 05:55:19 +09:00
Ashish Myles
be60165bb1 Require \[text]color HTML colors to be well-formed. (#827)
Previously, the parser accepted all letters of the
alphabet for hex digits in HTML colors, and allowed any
number of digits. Now, only well-formed HTML hex colors
are allowed.
2017-08-28 23:39:19 -04:00
William J. Bowman
2fbb2b0128 Added MathJax compatibility script (#680)
* Added MathJax compatibility script

* Removed make integrity, which release.sh handles

* Renamed scripts

* Use katex.render (and options) instead of manually string munging

* Rewrote code based on feedback

* Renamed file correctly

* Extended README with an example of usage

* Removed CDN paths in place of an abstract path

* Revert "Removed CDN paths in place of an abstract path"

This reverts commit 857f8de2e449d9ac5a3d8eab5104dac561c533c4.

* Replace versions with `...`, with note to avoid confusing users

* Revert some `...` replacements to files that do exist.
2017-08-27 18:17:42 -04:00
Kevin Barabash
96c1fe7ad8 Bump master to v0.8.4-pre 2017-08-27 18:01:07 -04:00
Kevin Barabash
796551021b switch pre-commit hook to use pre-commit npm package (#823) 2017-08-27 17:53:41 -04:00
Ron Kok
ba069db196 Reduce SVG (#819)
* Reduce SVG

1. Edit to reduce redundancy in SVG code. Save 5 KB in size of stretchy.js

2. Bug fix: Use correct path geometry for `\xleftharpoondown`.

* remove unnecessary fill='currentcolor'
2017-08-25 22:10:28 -04:00
Emily Eisenberg
dd99b0064c Merge pull request #821 from hblumberg/master
Fix link in CONTRIBUTING.md.
2017-08-26 03:04:18 +08:00
Hannah Blumberg
a787bcb257 Fix link in CONTRIBUTING.md.
This fixes `[preview page] (http://utensil-site.github.io/available-in-katex/)` (and instead makes `preview page` a link).
2017-08-25 11:43:12 -07:00
Kevin Barabash
c6647e3303 Added support for \not (#140)
* Added support for \not

* fix grammar in comment
2017-08-23 13:24:17 -04:00
Erik Demaine
201193233e Support for \' \` \^ \~ \= \u \. \" \r \H \v text-mode accents (#802)
* Support for \' \` \^ \~ \= \u \. \" \r \H \v text-mode accents

* bug fix

* Possible Safari fix

* Forbid text accents in math mode

* Switch to noncombining characters for most accents. Revert Safari change.

* Add tests

* Found non-combining diaresis accent too
2017-08-23 03:18:33 -04:00
Ron Kok
e88256b397 Improve \sqrt (#810)
* Improve \sqrt

Make \sqrt out of inline SVGs to ensure a perfect match at the junction between surd and viniculum.

* Tweak for kern clarity

* Fix lint error

* regenerate screenshot tests with sqrts

* Correct advance

Edit the SVG paths so that they have the correct left bearing and advance width values.

This will correct the spacing on the left side of each surd and it will also improve the placment of a root indice.

* Revise scriptstyle surds

In the `main` size, delimiters *do* scale with scriptstyle and scriptscriptstyle.

* update screenshot images containing sqrts
2017-08-22 21:39:15 -04:00
Erik Demaine
dd0c14ac01 Support CJK full-width punctuation + Unicode dots (#814) 2017-08-21 22:05:13 -04:00
Erik Demaine
6d2cf79f53 Pre-commit hook to call make lint (#815) 2017-08-21 21:55:49 -04:00
Martin von Gagern
a9708a25f2 Modernize font creation (#624)
* Modernize font creation

* Automate the build process, instead of writing a complicated manual
* Update sources used by the docker image away from google code
* Exclude MathJax-dev checkout from docker image, to allow image reuse
* Try to keep the individual image layers small by combining RUN commands
  and removing temporary files used only during each individual step

* Allow creating fonts from local directory

Also use hash of Dockerfile to compute image tag, in order to ensure
creation of a new image if the Dockerfile changes.

* make glob syntax work on MacOS
2017-08-20 01:45:34 -04:00
Ron Kok
a4b1bf01be Use inline SVG for stretchy elements (#807)
* Use inline SVG for stretchy elements

Replace all background-images with inline SVG code.

Pros:

* `\color` works in all browsers, even IE/Edge
* Better printing
* Much simpler CSS
    * No links to background-images
    * No `mask`
    * No browser-detection
* No external SVG files
* Faster first rendering

Cons

* No image caching
* Heavier HTML load
* Larger JavaScript file
* `\cancel` line is in `px` units, not `em` units

* Remove static/images from make file

* Change \cancel from px to em

* regenerate screenshots for functions using inline svg
2017-08-19 21:51:16 -04:00
Christian Abdelmassih
81037e5d10 Add latin-1 letters as math symbols (#796)
Additional work is required to render them using Computer Modern, currently we use the fallback font which is Times New Roman.
2017-08-19 13:29:35 -04:00
Kevin Barabash
2cd961dbe0 Bump master to v0.8.3-pre 2017-08-17 01:13:27 -04:00
Hallvord R. M. Steen
a7351ffc81 Detect attachEvent() support correctly, fixes #771 (#772) 2017-08-15 22:40:03 -04:00
Xuming Zeng
d01c73c312 Fix color support for stretchy, strikethrough, and fbox (#792)
Summary:
Stuff like `\red{\overbrace{AB}}` works now in addition to `\color{red}{\overbrace{AB}}`. Strikethrough now respects color. The Firefox in the screenshotter doesn't seem to support `background-image` + `mask`, but I manually tested that the latest Firefox does.

Test plan:
Ran `make`, then tested in latest Chrome and Firefox to ensure color support was working, then ran `make screenshots`.
2017-08-15 22:25:31 -04:00
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