Commit Graph

642 Commits

Author SHA1 Message Date
Ashish Myles
d8060ca9b4 Port functions.js to @flow. (#867)
* Make types in defineFunction stricter and prep for porting functions.js to flow.

* Add more explicit types to functions/delimsizing.js.

* Port functions.js to @flow.
2017-09-10 21:25:36 -04:00
Ashish Myles
ceefd4934f Remove the positions array computed by Parser's parseArguments(). (#864)
This array is computed incorrectly (it's always an array of undefineds)
and it's not used anywhere.
2017-09-09 22:22:46 -04:00
Ashish Myles
1c344ed6ee Port environments.js to @flow. (#862)
* Port environment.js to @flow.

* Updated per comments.
2017-09-09 20:31:32 -04:00
Ashish Myles
b4a00824d3 @flow: Correct argType to Array in defineFunction. (#860) 2017-09-09 18:09:02 -04:00
Ashish Myles
9e330194b8 Port symbol.js to @flow. (#858)
* Port symbol.js to @flow.

* Add a `Mode` @flow type and use it in `ParseNode`.
2017-09-09 17:54:47 -04:00
Xuming Zeng
0f9fb0a1ce To @flow: fontMetrics, fontMetricsData, Options, Settings, Style (#848)
*     To @flow: fontMetrics, fontMetricsData, Options, Settings, Style

* Don't overuse $Shape, improve type checking for fontMetrics*, make maxSize required in OptionsData and update callers.

* Remove eslintrc globals change, since eslint-plugin-flowtype makes it redundant.

* Remove extra ?s in Options and Settings

* Undo removal of width in fontMetrics and switch to `T | void` for nullable types in Options

* fix typing of FontMetrics
2017-09-09 17:21:52 -04:00
Ron Kok
ccf09786cc Improve SVG Performance (#841)
* Improve SVG Performance

This PR introduces three new classes:  `svgNode`, `pathNode`, and `lineNode`. SVG data is then loaded into the domTree exclusively via instances of these classes.

`innerHTML` is banished.

* Fix lint errors

* Fix \cancel typo

* Fix sqrt height

* Adjust min-lenght

Adjust some of the extensible arrows to get a min-length that matches glyph length of the long arrows in KaTeX Main font range from Unicode 27F5  to 27FC.

The accent arrows still get min-lengths that match the arrows in the Unicode 2100 range.

* regenerate screenshots after optimizing SVG code

* update DisplayStyle screenshot for Chrome

* update OverUnderset and Smash screenshots for Chrome as well

* Remove escapes from template strings

* Pick up review comments

* Fix lint errors

* Add comments
2017-09-08 23:27:47 -04:00
Ashish Myles
3818105868 Port unit.js to @flow. (#855)
* Port unit.js to @flow.

* Removed unnecesary types.
2017-09-07 10:00:46 -04:00
Ashish Myles
d46ca811c1 Add @flow to unicodeRegexes and change to ES6 exports. 2017-09-07 09:41:13 -04:00
Erik Demaine
588f5a1ee6 eslint-plugin-flowtype & upgrade to eslint@4 (#849)
* Add eslint-plugin-flowtype. Fix #844

Using the recommended settings for plugin.
This involved adding some spaces to some existing union types.

* Upgrade to eslint@4, fix spotted bugs

Switched to indent-legacy to allow e.g. comments to have extra indents.
2017-09-06 22:06:26 -04:00
Ashish Myles
cb7f166a7e To @flow: MacroExpander. (#845)
* To @flow: MacroExpander.

* Explicitly pass context into defineMacro called with a function.

Instead of binding `this` when `defineMacro` is invoked
with a function, we now pass an explicit context as a
parameter to the function. This is a bit more obvious
and is currently more type-safe due to a bug in `@flow`:
https://github.com/facebook/flow/issues/4809

* Per feedback, rename some types, fields, and variables.
2017-09-06 21:39:50 -04:00
Aria Buckles
feef4107df Fix match-at flow errors (#847)
Upgrade match-at and flow versions to resolve the match-at flow
errors, allowing us to remove match-at from the .flowconfig ignore

Test plan:

run `jest` and get the following output:

    PASS  test/unicode-spec.js
    PASS  test/errors-spec.js
    PASS  test/mathml-spec.js
    PASS  test/katex-spec.js (5.104s)

run `flow` and get:

    No errors!
2017-09-05 22:37:17 -04:00
Erik Demaine
e71c7d4b81 copy-tex contrib module (#813)
* copy-tex contrib module

* Factor out replacement code

* Fix lint

* Support for more browsers, in particular Firefox

* Use for loop instead of Array.forEach
* Use replaceChild if replaceWith is unavailable
* Browserify to remove let etc.

* Fix HTML handling, in particular for Edge

* Convert DocumentFragment to HTML directly (via children' outerHTML)
* Set HTML content *before* text content; Edge takes the last only

* Handle .katex-html and .katex-mathml separately

* Implement option 2: CSS user-select: all

Also fix auto-render.js build location

* Revise documentation according to @kevinbarabash's comments

* Split copy-tex.js into it + katex2tex.js

This supports re-use of code in a custom copy handler.

* Document custom copy handler

* Add missing file
2017-09-04 21:17:46 -04:00
Erik Demaine
ca224eda81 Support for \raisebox (#685)
* Rough support for \raisebox

* Fix bounding box thanks to @kevinbarash and @ronkok

* Use calculateSize to support all currently supported units (ex, em, mu).
* Shift height and depth in all cases.

* Add screenshot test

* Rename transform -> raisebox

* Switch to normalsize in raisebox

* Attempt at using makeVList

* Significant rewrite, now working well

* rename textFunctionStyles to textFunctionFonts
2017-09-04 20:49:10 -04:00
Erik Demaine
6857689946 Advanced macro support and magic \dots (#794)
* Advanced macro support and magic \dots

* Fix \relax behavior

* Use \DOTSB in \iff, \implies, \impliedby

* Add multiple expansion test

* Implement some of @kevinbarash's comments

* More @kevinbarabash comments

* Token moved from merge

* Add type to defineMacro

* @flow
2017-09-04 20:27:04 -04:00
Ashish Myles
0c2dd845f3 Update Parser comments to match implementation. (#837) 2017-09-04 15:48:56 -04:00
Ashish Myles
13f3eac741 To @flow: Token, Lexer, ParseError, and ParseNode. (#839)
* To @flow: Token, Lexer, ParseError, and ParseNode.

* PR fixes 1.
2017-09-04 15:27:58 -04:00
Kevin Barabash
12399da73d make 'names' accept only an array of strings, add warning comments about where new functions should be added 2017-09-02 15:11:44 -04:00
Kevin Barabash
6db61cb219 run flow as part of 'npm test' so it runs on travis-ci 2017-09-02 15:11:44 -04:00
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