Commit Graph

514 Commits

Author SHA1 Message Date
Eddie Kohler
dc79b91dbf Mark delimiters with the proper class (mopen or mclose).
This fixes some atom spacing issues. Update the BinCancellation
screenshotter test.
2016-12-05 15:48:04 -05:00
Eddie Kohler
1a99e7a2e9 The \llap and \rlap commands always generate "mord" atoms.
This is how TeX does it.
2016-12-05 15:48:04 -05:00
Eddie Kohler
c951df4269 Fix #4.
Post-process the list of atoms after they are created, changing
binary operators to ordinary atoms according to the TeXbook's
rules. This makes the `prev` argument redundant, so drop it.

This commit assumes that the math class (mop/mbin/mrel/etc.) comes
first in the `classes` list, if present. Add a TODO to change the
signature of `makeSpan/makeSymbol` to enforce this invariant.
2016-12-05 15:47:06 -05:00
Eddie Kohler
9d3cdf694c Fix spacing between groups to match TeX spacing (#567)
* Internal: Pass full `options` objects to makeSpan/makeSymbol.

Not just the current color. This will facilitate applying options
to built nodes in a standardized way, rather than changing all
callsites.

* Add style switching test: text and scriptstyle in the same group.

* Apply style-specific spacing using different CSS coding.

Specifically, infer style from a class on the *current* element,
rather than the parent element. Use "mtight" class to denote elements
with tight spacing (scriptstyle or scriptscriptstyle). Apply that
class automatically based on options.

* Fix #533, #534, #541.

- #534: Implement getTypeOfGroup for font groups.
- #533, #541: Improve the ways spaces are applied to lists. Since
  CSS adjacency implements mathematical spacing, it's incorrect to
  introduce "convenience spans" for spaces and display changes into
  the generated HTML -- those spans break adjacency. Apply display
  changes directly, and shift space spans into adjacent atoms.

Requires updates to two screenshotter tests, LimitControls and
SupSubLeftAlignReset. The new results for these tests are closer
to TeX output than the old results.

Also requires updates to Jasmine tests, since those assumed output
structures that have changed.

* Fix #136: Size commands generate fragments, not spans.

This is so the size commands don't hide the types of their enclosed
atoms. Addresses #136.

This slightly changes the vertical position of the Sizing test. Not
sure the vertical position matters, so change the test.
2016-11-28 12:55:54 -05:00
Martin von Gagern
be96695586 Improved Docker for Mac support (#568)
* Exit cleanly after invalid screenshot test name

This avoids waiting forever.

* Auto-detect host IP in Docker for Mac environment

This checks all available network addresses to find one which the Selenium
container can connect to.  That way we don't have to analyze network
settings or similar to figure out the main public IP address of the machine.

* Make server less sensitive to current working directory

That way it becomes possible to run screenshotter.js from within the
Screenshotter directory, and still server all files as intended.
2016-11-27 18:57:53 -05:00
Martin von Gagern
94dad8029d Check out test fonts in screenshotter.sh (#570)
This ensures that running screenshots as indicated by the screenshotter
readme will correctly render the Unicode examples, even if not run on
Travis.  It also fixes the commit ID of the unicode fonts.

One alternative would have been using a git submodule.  But as many tools
will initialize submodules automatically, that would mean big downloads for
anyone using such a tool to clone KaTeX.

Another alternative would be tweaking the server to fetch the files on
demand if the local copy is unavailable.  But that would cause additional
network overhead, so grabbing the files just once should be simpler.
2016-11-23 09:38:47 -05:00
Eddie Kohler
7b5580b1fa Screenshotter: Obey --katex/selenium-ip options under --container. (#566)
Some Docker configs, such as Docker for Mac, need explicit --katex-ip
and --selenium-ip options. Obey those options.
2016-11-22 11:23:32 +01:00
Kevin Barabash
22957d40f6 Use style specific FONTDIM metrics (#545)
Summary:
FONTDIM metrics include metrics like sup2, sup3, etc. which are used for
position sub/super-scripts, fractions, delimiters, etc.  TeX uses three
different font styles: textfont2 (DISPLAY & TEXT), scriptfont2 (SCRIPT), and
scriptscriptfont2 (SCRIPTSCRIPT) and has different sets of metrics for each.
This diff adds style specific metrics for better TeX compliance.

Notable squashed commits:
- Recreated screenshots (martin)
- fix getEmPerEx to use getXHeight
- regularize how we access options.style, remove unnecessary newlines
- use var style = options.style in more places in buildHTML
2016-11-04 07:45:08 +01:00
Matthew Rothenberg
ace67541a0 Create CODE_OF_CONDUCT.md (#553) 2016-11-02 22:02:47 -04:00
Martin von Gagern
0ebbc25672 Add build artifacts to .gitignore and allow installing dependencies without building KaTeX
* Let git ignore .npm-install.stamp and dist

The former is created for most makefile targets after dependencies have been
retrieved.  The latter is created by typical operations like “make” without
arguments or “npm install”.  Having these around is to be expected.

Adding this to .gitignore should NOT affect npm packaging, since that is
based on a whitelist in package.json which does mention dist.

* Allow installing dependencies without actually building KaTeX

We have been using “npm install” to install dependencies, but since that
also does build KaTeX itself, it may fail if e.g. there are any style guide
violations.  Now we only fetch dependencies but do not build KaTeX itself.

The make conditionals used here are not part of POSIX make but a GNU
extension.  But we already use functionality not mandated by POSIX (namely
many of the functions like “wildcard”), so this should not make portability
any worse than it already is.
2016-11-02 21:24:59 -04:00
Emily Eisenberg
fef5b88057 Merge pull request #548 from deckar01/547-unminified-assets
Keep unminified katex.js and katex.css build files
2016-11-01 12:08:29 -07:00
Martin von Gagern
d5025c61e8 Fix texcmp issues related to bit depth and kerning (#549)
* Ensure bit depth 8
* Print affected file if PNG failed to read (e.g. due to wrong bit depth)
* Disable running Kern test case through TeX as doing so fails
2016-10-22 19:37:18 -04:00
Jared Deckard
4fb9445a92 Keep unminified katex.js and katex.css build files 2016-10-10 18:28:34 -05:00
Martin von Gagern
d50745d5a9 Make screenshotter work with docker-machine (#494)
Since boot2docker has been superseded by docker-machine, we need this to
support developers on OS X.  The changes to the bash script ensure that we
clean up our containers even if taking screenshots gets hung and requires a
keyboard interrupt, as happens if the IP addresses were guessed incorrectly.
2016-10-07 23:15:54 -04:00
Janis Lesinskis
f1be1a3462 Invalid input error message (#540)
* Added check for type of expressions passed to parseTree function
* Added tests for bad input raising exception
* Added test for supported types NOT throwing exception
* Added test case for parser taking String objects
2016-09-23 14:45:33 +02:00
Mathijs Henquet
a16ae7a5eb Ignore `font' groups when determining base elements, fixes #390 (#469)
* Ignore `font' groups when determining base elements, fixes #390

* fix ===

* Added testcase
2016-09-17 17:22:01 -07:00
Viktor Qvarfordt
e4d2d933af Provide link to auto-render.min.js in usage example (#522) 2016-09-17 15:23:26 -07:00
Martin von Gagern
e6de31d2d6 Call “npm install” automatically if package.json changed (#505)
This adds a stamp file which is used to detect whether the `package.json`
file got updated since the last `npm install`.  If so, `npm install` is run
again to update all modules to the version described in `package.json`.
This happens as a dependency of only those modules which actually need some
npm-installed module.

Setting the corresponding make variable to the empty string disables the
feature, which is used by the `make` invocation in the `prepublish` script
inside `package.json` to avoid infinite loops.  It can also be used by
developers working in an environment with reduced connectivity, as long as
they know what they are doing.
2016-08-23 18:05:50 -07:00
Kevin Barabash
ec62ec39d8 Add support for Latin-1, Cyrillic, and CJK characters inside \text{} (#508)
Summary:
This diff provides support for Latin-1, Cyrillic, and CJK characters
inside \text{} groups.  For Latin-1 and Cyrillic characters we use
glyph metrics from a glyph from Basic Latin that has roughly the same
bounding box.  We use the metrics for a capital 'M' to approximate the
full-width CJK characters.  Half-width characters are not supported yet.

Test Plan:
- make test
- make screenshots

Reviewers: emily
2016-08-01 17:51:40 -07:00
Martin von Gagern
92bbbffbc8 Add --wait option to screenshotter (#510)
Sometimes a page might not be ready when the screenshot is taken, due to
fonts still being loaded or some such.  In --verify mode this is taken care
of by repeated attempts.  But when creating a screenshot for the first time,
it might be desirable to wait a given number of seconds for things to settle
down.  So this commit introduces a --wait option to the screenshotter.
2016-07-29 12:26:30 -07:00
Charles Marsh
725524a214 Specify TrueType font format as 'truetype' rather than 'ttf'
Summary:
I've been experimenting with delivering a TrueType-only KaTeX build for our mobile apps. I couldn't
get anything to render properly until I flipped the `format` specifier from `ttf` to `truetype`.
Though I can't find a definitive source on this, all the examples I've seen online use `truetype`
over `ttf`, and flipping from `ttf` to `truetype` fixed my own issues.

It's unlikely that this has been much of a problem in practice, since so many browsers now support
WOFF (I'm considering a TrueType-only build since it's the least common denominator across Android
4.3+ and mobile Safari).

Test Plan:
- To force TrueType rendering, comment out the `.use-eot`, `.use-woff2`, and `.use-woff` lines in `fonts.less`.
- Run `make serve`.
- Open up the demo page.
    - Verify that the demo text is rendered as before (only the parens are noticeably different in the demo?).

Reviewers: kevinb, emily

Reviewed By: emily

Subscribers: benkomalo

Differential Revision: https://phabricator.khanacademy.org/D29274
2016-07-25 10:28:34 -07:00
Martin von Gagern
4a9c2acbf7 Add some more symbols (#502)
This adds support for the following input sequences:

    -- --- ` ' `` '' \degree \pounds \maltese

resulting in – — ‘ ’ “ ” ° £ ✠ symbols already present in our fonts.

As part of this modification, the recognition of multiple dashes was moved
from the lexer to the parser.
This is neccessary since in math mode a sequence of hyphens is just a
sequence of minus signs.  Just like a pair of apostrophes in math mode is a
double prime not a right double quotation mark.
To make this easier, parseGroup and parseOptionalGroup have been merged.
2016-07-24 19:56:31 -07:00
Martin von Gagern
befe1c1af7 Upgrade less to version 2 (#503)
This fixes a problem where the graceful-js dependency of the old less
version is incompatible with node 7, and will cause warnings on node 6.
The resulting katex.min.css is exactly the same as with the previous
version, so the major version upgrade does not seem to affect the outcome.

The less.Parser has been deprecated, and less.render is the supported
approach now, so we have to switch the development server to that.
2016-07-12 12:23:28 -07:00
Martin von Gagern
8c55aed39a Allow macro definitions in settings (#493)
* Introduce MacroExpander

The job of the MacroExpander is turning a stream of possibly expandable
tokens, as obtained from the Lexer, into a stream of non-expandable tokens
(in KaTeX, even though they may well be expandable in TeX) which can be
processed by the Parser.  The challenge here is that we don't have
mode-specific lexer implementations any more, so we need to do everything on
the token level, including reassembly of sizes and colors.

* Make macros available in development server

Now one can specify macro definitions like \foo=bar as part of the query
string and use these macros in the formula being typeset.

* Add tests for macro expansions

* Handle end of input in special groups

This avoids an infinite loop if input ends prematurely.

* Simplify parseSpecialGroup

The parseSpecialGroup methos now returns a single token spanning the whole
special group, and leaves matching that string against a suitable regular
expression to whoever is calling the method.  Suggested by @cbreeden.

* Incorporate review suggestions

Add improvements suggested by Kevin Barabash during review.

* Input range sanity checks

Ensure that both tokens of a token range come from the same lexer,
and that the range has a non-negative length.

* Improved wording of two comments
2016-07-08 12:24:31 -07:00
Shadaj Laddad
b49eee4de7 Updated Khan Academy colors to new colors
Summary: The KaTex renderer used to use old Khan Academy colors when displaying colored text. The configuration is now updated to have the new colors.

Test Plan:
- verified that colored text now uses the new colors in a browser
- running commands such as `\blueA{blueA}` will style the text in the blueA color from the configuration

Reviewers: emily, kevinb

Reviewed By: kevinb

Differential Revision: https://phabricator.khanacademy.org/D27963
2016-06-07 17:24:47 -07:00
Emily Eisenberg
26f06754e7 Merge pull request #490 from cbreeden/Fix#488-supsub-alignment
Fix #488 Subsup alignments
2016-06-01 15:10:50 -07:00
Christopher Breeden
3668bb084e add msupsub tag to scripts, fix #488 2016-06-01 16:57:56 -05:00
Andrey Mikhaylov (lolmaus)
b120b1c3d8 Fixed indentation in auto-render readme (#481) 2016-05-26 10:10:54 -07:00
Johannes Schmitz
1cf10c4cd6 Update CDN links to latest version (#478) 2016-05-23 11:42:27 -07:00
Kevin Barabash
9884ac3e8d Merge pull request #423 from Khan/kern
Add support for \kern
2016-04-19 21:22:24 -07:00
Emily Eisenberg
991f4eb096 Ignore release.sh in bower.json
Summary: We didn't have a rule for ignoring .sh files in the bower.json,
so it got included in the 0.6.0 release. Oops! This adds it to the
ignore file.

Test Plan:
 - ???

Auditors: kevinb
2016-04-15 18:48:24 -07:00
Emily Eisenberg
b62e1cf314 Make the release script correctly link to the new release page.
Test Plan:
 - Cross fingers!

Auditors: kevinb
2016-04-15 18:30:31 -07:00
Kevin Barabash
5991a6078b Bump master to v0.7.0-pre 2016-04-15 18:18:36 -07:00
Kevin Barabash
aa36c459ae don't do any linting/checking of the release commits
Summary:
We prevent any precommit checks so that we don't have to include
a "Test Plan" etc. in the release commit message.

Test Plan:
- ./release.sh 0.6.0 0.7.0

Auditors: emily
2016-04-15 18:14:13 -07:00
Kevin Barabash
0f7a1a06e9 Blacklist dist/** so that ka-lint doesn't barf on those files
Test Plan:
- ./release.sh 0.6.0 0.7.0

Auditors: emily
2016-04-15 18:11:31 -07:00
Kevin Barabash
36164b98ea Make it compatible with Mac
Test Plan:
- ./release 0.6.0 0.7.0

Auditors: emily
2016-04-15 18:09:14 -07:00
Kevin Barabash
363a6ba311 Merge pull request #461 from Khan/add-release
Add a release script.
2016-04-15 17:33:35 -07:00
Emily Eisenberg
224efafda8 Add a release script.
Summary: Make the release script that's been floating around in my gists
for a while into a real script.

Test Plan:
 - Comment out all the scary bits (the two pushes, and `npm
   publish`), and run:
 - `./release.sh 0.6.0`
 - Checkout the `v0.6.0` tag, see that it successfully modified
   package.json and bower.json to version 0.6.0, and built and committed
   the rest of the files.
 - `git tag -d v0.6.0`
 - `./release.sh 0.6.0 0.7.0`
 - Checkout master, see that it successfully made a commit bumping
   package.json and bower.json to 0.7.0-pre.

Reviewers: @kevinbarabash
2016-04-15 12:19:16 -07:00
Emily Eisenberg
ccd8f40028 Make make lint not automatically fix lint
Summary: Looks like there was lint, but `make lint` wasn't failing on it
because it would just automatically fix it! This removes the `--fix`
from `eslint` and fixes the lint.

Test Plan:
 - `make lint`

Auditors: kevinb
2016-04-15 12:08:14 -07:00
Ben Alpert
965b8a6164 Add \underline support (#456)
![image](https://cloud.githubusercontent.com/assets/6820/14412284/e63218b6-ff13-11e5-912c-fc6e30928b93.png)

Fixes #209.
2016-04-10 20:32:24 -07:00
Kevin Barabash
a33fa4fd64 Merge pull request #448 from Khan/fix-centered-subsuperscripts
Fix sub- and super-scripts not being centered inside of display math
2016-03-07 00:07:25 -08:00
Emily Eisenberg
229ce562ff Fix sub- and super-scripts not being centered inside of display math
It looks like the `text-align: center` is affecting the text in sub and
superscripts. Fixes #447

Test Plan:
 - Visit [this
   example](http://localhost:7936/?text=x%5El_%7Bi%5E%7Bl%2B1%7D%2Bi%2C%20j%5E%7Bl%2B1%7D%2Bj%2C%20d%7D)
 - Edit the HTML to add `<span class="katex-display">...</span>` around the
   `<span class="katex">` node.
 - See that the sub and superscripts are left-aligned, not centered

(It looks like we don't have a way to test this in the screenshotter for now)

@kevinb
2016-03-05 09:37:39 -08:00
Ben Alpert
d2079a6c9c Merge pull request #444 from mathiasbynens/https
README: Use HTTPS where possible
2016-03-02 11:35:47 -08:00
Mathias Bynens
d5359ef5bb README: Use HTTPS where possible
There’s no reason not to always use HTTPS. See https://github.com/konklone/cdns-to-https#background for more info.
2016-03-01 15:44:45 +01:00
Ben Alpert
83dea37b51 Merge pull request #436 from tirsen/master
Bundle css and fonts in npm package.
2016-02-19 11:23:35 -08:00
Jon Tirsen
a5207fef94 Bundle css and fonts in npm package. 2016-02-18 09:21:28 +01:00
Kevin Barabash
3083efba66 Add support for \kern
Summary:
This only supports em and ex units and doesn't handle vertical layouts.
Negative kerning works.

Test Plan:
- make test
- make screenshots (verify that d is slightly overlapping c in the screenshots)

Reviewers: emily
2015-12-30 18:14:29 -08:00
Kevin Barabash
c79fb58936 Revert previous change to make \centerdot like \cdot
Summary:
Alpert alerted me to the fact that \centerdot and \cdot are
not the same despite what MathJax thinks.

Test Plan:
- make serve
- load http://localhost:7936/
- see the `a \centerdot b` produces a small, bottom-aligned square

Auditors: alpert emily
2015-12-29 10:21:44 -08:00
Kevin Barabash
157bfb0cf5 \centerdot should produce the same glyph as \cdot
Summary:
Update the symbol definition for \centerdot so that it does
the same thing as \cdot.
Fixes https://github.com/Khan/KaTeX/issues/421.

Test Plan:
- make serve
- open http://localhost:7936/
- verify that `a \centerdot b` looks the same as `a \cdot b`

Auditors: emily
2015-12-29 10:00:17 -08:00
Kevin Barabash
9ad50178f1 Merge pull request #405 from Khan/eslint
Migrate to eslint
2015-12-04 17:42:06 -08:00