Commit Graph

882 Commits

Author SHA1 Message Date
Erik Demaine
acccce801d \def support (and \gdef and \global\def) (#1348)
* Nested environments of macro definitions

* Rename environment -> namespace

* \def support

* Clean up \df@tag at beginning

* \global\def support

* Fix \global via new setMacro helper

* Fix caching behavior and build array on top of it

Also avoid double lookup of macros

* Add tests

* Add argument tests

* Remove global pointer

* Note about macros object being modified

* add __defineMacro

* Add \global\def test

* More \global tests

* Constant-time lookup

Rewrite to use an "undo" stack similar to TeX, so get and set are
constant-time operations.  get() still has to check two objects: one with all
current settings, and then the built-ins.  Local set() sets the current value
and (when appropriate) adds an undo operation to the undo stack.  Global set()
still takes time linear in the number of groups, possibly changing the undo
operation at every level.

`Namespace` now refers to a space of things like macros or lengths.

* Add \def to-dos

* Put optional arguments in their own group

* Rename `pushNamespace` -> `beginGroup`

* Wrap each expression in a group namespace

* Add comments
2018-05-28 21:58:57 +02:00
Kevin Barabash
3ec752f5f1 Make ParseNodeTypes more regular (#1373)
Make ParseNodeTypes more regular: make 'size' and 'url' node values be objects.
2018-05-28 12:55:59 -04:00
greenkeeper[bot]
659b4e30c8 Update dependencies to enable Greenkeeper 🌴 (#1368)
* chore: add Greenkeeper config file

* chore(package): update dependencies

* chore(package): update dependencies

* docs(readme): add Greenkeeper badge

* Exclude "dockers/texcmp/package.json",

* Revert "dockers/texcmp/package.json"

Reverts ddc6aa9e05d9e3a7e1e960c7c62f15b8dbff70a9
2018-05-28 05:37:36 +02:00
ylemkimon
25e07a7df6 Upgrade to webpack 4 (#1337) 2018-05-28 05:20:33 +02:00
Ron Kok
5a9e4c1708 Fix wide character spacing (#1371)
* Fix wide character spacing

Fixes issue #1360

* Add test

* Use concat
2018-05-28 05:11:59 +02:00
Ron Kok
2974639877 Fix coloneq etc (#1372)
Fix issue #1333.

`\coloneq` and several similar functions are written as macros. When expanded, these result in atoms like ":" and "=" placed adjacent to each other at the top level. So they exposed to a split by an automatic line break.

This PR wraps each of these macros in an `\mathrel{ }`. This prevents the line break.
2018-05-28 11:28:02 +09:00
Ron Kok
d41b0b010a Fix nested \tfrac (#1370)
Fixes issue #1352.
2018-05-28 10:59:23 +09:00
Ashish Myles
e3fb2f95ae Update flow version and address type errors. (#1369) 2018-05-27 16:19:10 -04:00
Ashish Myles
9cde0336d3 Correct (type-wise) raisebox's usage of sizing's buildHtml. (#1361)
* Correct (type-wise) raisebox's usage of sizing's buildHtml.

* Move HTML and MathML groupTypes into defineFunction.

Currently, functions defined in functions/* import all exports from buildHtml
and buildMathML, but they should never use `groupTypes` directly as it loses
type-safety. They should instead use more type-safe `htmlBuilder`s and
`mathmlBuilder`s exported directly from other definitions `functions/*` to allow
flow to catch errors.

* Rename groupTypes to groupBuilders.
2018-05-27 16:24:30 +09:00
Erik Demaine
d9fe716d0e Update contrib READMEs to jsdelivr v0.10.0-alpha (#1362)
This is particularly important as update-sri.js only updates jsdelivr links.

I was able to get update-sri.js to do the heavy lifting (computing checksums)
after updating the links in general, and downloading v0.10.0-alpha from CDN.
2018-05-26 21:54:43 +02:00
Ashish Myles
9e2d5b1256 Move "supsub" handers into functions/supsub.js and add flow types. (#1359)
* Move "supsub" handlers to functions/subsub.js.

* Add flow types to functions/supsub.js.

* Simplify getBaseElem's output type based on all existing uses.

Before supsub was ported to flow, it had an instance where it could pass a
nullable to isCharacterBox which would pass it into getBaseElem and receive a
false. The refactor and strict typing of supsub now ensures that only a
non-nullable value is passed in to isCharacterBox and getBaseElem.

* Remove warnings at the top of buildMathML and buildHTML.

* Fix silly mistake.
2018-05-27 02:40:37 +09:00
Ashish Myles
1e629a0310 Export htmlBuilder from accent, horizBrace, and op for supsub. (#1349)
* Export htmlBuilder from accent, horizBrace, and op for supsub.

* Addressed review comments.
2018-05-25 12:28:58 +09:00
Ron Kok
a5e6b92ff1 Fix lap vertical alignment. (#1162)
* Fix lap vertical alignment.

Fixes issue #1153.

* Fix horizontal alignment

Wrap the entire lap pair with a mord.

* Support Unicode \ll and \lll

Fixes issue #1271

* Update screenshots

* Update screenshots

* generated updated screenshots for Lap

* Change double strut to single strut

* Delete screenshotter test

* Add (commented out) test

* Fix mis-spelled word
2018-05-25 03:27:15 +02:00
ylemkimon
ef666c18da Update dependencies: less(-loader), uglifyjs-webpack-plugin, request (#1343) 2018-05-23 16:13:06 +02:00
ylemkimon
41ac2456f0 Add missing v prefix to the size badge URL (#1342)
* Add missing `v` prefix to the size badge URL

* Add missing `v` prefix to badge URL update script
2018-05-23 09:05:32 -04:00
Ashish Myles
4c3439192f Move "ordgroup" and "tag" builders into functions/*. (#1339)
* Move "ordgroup" builders to functions/ordgroup.js.
* Move "tag" MathML builder to functions/tag.js.
2018-05-22 22:18:39 -04:00
Erik Demaine
485c509879 Cleanup MathML <mrow>, <mtext>, <mn> (#1338)
* Avoid unnecessary <mrow> wrapping

buildMathML gains two helpers:
* `makeRow` helper wraps an array of nodes in `<mrow>`,
  unless the array has length 1, in which case no wrapping is necessary.
* `buildExpressionRow` for common case of `makeRow(buildExpression(...))`

* Combine adjacent <mtext>s in all cases

No more need for `makeTextRow` helper or anything fancy in text MathML handler.

* Concatenate <mn>s and decimal point into single <mn>

Fix #203

* Fix snapshots
2018-05-21 22:56:34 -04:00
Ashish Myles
ef9cd5c172 Spacing (#1335)
* Move "spacing" builders to functions/symbolsSpacing.js.

* Add flow types to functions/symbolsSpacing.js.

* Address reviewer comments.
2018-05-21 16:22:23 +02:00
ylemkimon
74e84e72d2 Add regenerate option to the screenshotter (#1220)
* Add regenerate option to the screenshotter

Save new screenshot when match fails

* Ignore Chrome debug log file

* CircleCI: Generate only failed screenshots

* CircleCI Test

* Revert "CircleCI Test"

This reverts commit 5d3afb2602f32470eeba7767748faba177ba933e.

* Rename `regenerate` to `new`

* Add ` /test/screenshotter/new/` to .gitignore
2018-05-21 08:06:50 -04:00
Ashish Myles
34cf5c2f81 Move HTML and MathML builders for symbol groups into src/functions/{symbolsOp,symbolsOrd}.js. (#1334)
* Move HTML and MathML builders for symbol groups into src/functions/{symbolsOp,symbolsOrd}.js.
2018-05-20 22:07:35 -04:00
Ashish Myles
ff8ca60584 Horiz brace (#1332)
* Move "horizBrace" to functions/horizBrace.js.

* Add flow types to functions/horizBrace.js.

* Remove blank lines and warning comment in functions.js.

* Remove import comments and alphabetize functions/ imports in functions.js.
2018-05-20 23:33:20 +02:00
Ashish Myles
28dfa91fb5 Move "xArrow" into functions/arrow.js and add flow types. (#1327)
* Move "xArrow" into functions/arrow.js.

* Add flow types to functions/arrow.js.

* Address review comments.
2018-05-20 04:41:39 +02:00
Ashish Myles
35d6181a95 Move "raisebox" into functions/raisebox.js. (#1331) 2018-05-20 03:53:51 +02:00
Ashish Myles
ea7003ff6e Move environment delimiter handling to functions/environment.js. (#1329) 2018-05-20 03:44:36 +02:00
Ashish Myles
fabae7c658 Move infix operator handling into functions/genfrac.js. (#1328) 2018-05-20 03:36:20 +02:00
Kevin Barabash
5aad11eff3 Bump master to v0.11.0-pre 2018-05-19 20:49:11 -04:00
Erik Demaine
a0ddad338e Support \tag, \tag*, and \gdef (#1309)
* Tag sketch

* Drop objectAssign; already using Object.assign elsewhere

* Basic \gdef support

* Bug fix

* Finish \tag

* MathML numbers equations with <mlabeledtr>

* Fix flow bugs

* \gdef tests

* Add basic \tag tests

* Screenshot test for \tag

* \tag* test

* Add missing file

* Bug fix screenshot

* Major refactor

* Represent tag at top level of parse tree, requiring less hackery
  * No more \@tag function; it was essentially just doing \text
* Wrap tag in group so e.g. ( and ) are formatted the same
* Add `feed` method to MacroExpander for multiple inputs (for tag)
* Bug fixes in buildHTML, makeTextRow, _getBuilt (for display mode)
* Remove excess <mrow> wrapper when unnecessary

* Update screenshot from tag being wrapped in group

* Add maxExpand limit
2018-05-19 22:19:21 +02:00
Ashish Myles
99b2afa935 Specify flow output types for htmlBuilder and mathmlBuilder. (#1324)
* Specify flow output types for htmlBuilder and mathmlBuilder.

* Add TODOs to refactor to improve the return type of mathmlBuilder.
2018-05-19 02:27:52 +02:00
Ashish Myles
f49a524da7 Move "mclass" node logic to functions/mclass. (#1325)
* Move "mclass" node logic to functions/mclass.
2018-05-18 12:44:28 -04:00
Ashish Myles
73e0c13d10 Move the rest of the ops from functions.js to functions/ops.js. (#1323) 2018-05-18 09:59:03 -04:00
Erik Demaine
7b22eeb64a Move test helpers into common modules (#1318)
* Move test helpers into common modules

* helpers.js gets all the helper functions
* setup.js gets the common Jest setup (serializer, expect extensions)

* Exclude test from coverage testing

* @ylemkimon's comments: parsing -> building, settings || defaultSettings

* Default argument for settings

* Fix lint errors

* @ylemklemon's comment: use buildAndSetResult

* Use template literals
2018-05-18 09:45:19 -04:00
Adam Kulidjian
4a3d6a526f changelog for KaTeX - complete w/ links (#1322) 2018-05-18 04:39:58 +02:00
Erik Demaine
369b5a8276 Allow all Unicode symbols in nonstrict mode (#1217)
Change symbol parsing to allow all Unicode symbols when the appropriate strict setting allows it.  By default, this allows all symbols, but the user will get (probably two) warnings about them.
2018-05-17 11:33:01 -04:00
Ashish Myles
431434258d Make htmlBuilder and mathmlBuilder params type-safe. (#1312)
* Make htmlBuilder and mathmlBuilder params type-safe.

Also correct and refine some of the ParseNode types.
2018-05-17 10:38:48 -04:00
Ryan Randall
7eed150c48 Documenting String.raw (#1198)
* Documenting String.raw

* Typo

* Rewrite String.raw doc
2018-05-17 22:27:56 +09:00
Erik Demaine
1ed99d9ff3 Strict setting controls \newline display-mode behavior; fix MacroExpander space handling (#1314)
* Strict setting controls \newline display-mode behavior

* Bug-fix space handling in macros

Whitespace after a \controlWord is now handled within the lexer, not by the
MacroExpander.  This way, \\ expanding to \newline doesn't accidentally
cause spaces to get consumed.

* Rename nonstrict -> reportNonstrict; strictBehavior -> useStrictBehavior

* Second category of errorCodes
2018-05-16 09:37:41 -04:00
Erik Demaine
7ab4f76e16 Implement strict mode (replacing unicodeTextInMathMode) (#1278)
* Implement strict mode (replacing unicodeTextInMathMode)

Add new "strict" setting (default value false) that can take a boolean
(whether to throw an error or silently ignore), string ("ignore",
"warn", or "error"), or a function possibly returning such a value.
This enables a variety of ways of handling or ignoring transgressions
from "true" LaTeX behavior, making KaTeX easier to use while still
providing the ability for strict LaTeX adherance.

Resolve #1226, implementing that spec, for two existing
transgressions from regular LaTeX:

* src/functions/kern.js had some errors and warnings about use of
  (units in) math vs. text mode commands.
* The former setting unicodeTextInMathMode (not in any released version)
  needed to be set to true to enable Unicode text symbols in math mode.

Now these are controlled by the strict setting.  By default, KaTeX is now
very permissive, but if desired, the user can request warnings or errors.

* Rewrite strict description

* Add tests for strict functions

* Stricter type for strict

* Switch default strict setting to "warn"

* Fix new flow error

* Fix another flow bug
2018-05-13 14:27:30 -04:00
Erik Demaine
4801ab875a Support for top-level \newline and \\ in inline math (#1298)
* Support for top-level \newline and \\ in inline math

This was a little tricky because `\\` was defined as an endOfExpression.
Instead made `\\` a termination specific to an array environment.
Outside an array environment, buildHTML handles the `cr` object,
resulting in a `.newline` class.  Currently this turns into a
`display: block` (with appropriate vertical spacing) only in inline math,
matching LaTeX.

* Simplify code

* Fix Jest errors

* NewLine screenshot test

* Bug fix: \\ only works at top level of inline

* Add \newline and \cr to test

* Switch test to pmatrix

* Add vertical space test

* Add \\ vs. \newline tests

* Fix flow errors

* Add \cr test

* Add documentation for \\ at top level

* Comment out newRow

* Fix commenting out
2018-05-13 09:58:24 -04:00
Erik Demaine
bb1dc0c431 throwOnError documentation bug fix (#1308)
3613885da1 (r28950405)
2018-05-12 22:31:21 -04:00
Ron Kok
74422e1462 Support \hline (#1306)
* Support \hline

Support `\hline`.

* Fix CSS

* Fix lint errors

* Add double \hline. Code Cleanup

* Reduce width of screenshot test

* Add screenshots

* Use consumeSpaces, read multiple \hlines

* Code cleanup

* Update screenshots
2018-05-12 13:51:14 -04:00
Erik Demaine
929b9bf5e7 One strut instead of two (#1307)
* One strut instead of two

As suggested in https://github.com/Khan/KaTeX/pull/1287#discussion_r187485780
the two struts were redundant; the formerly "bottom" strut suffices to
implement both height and depth constraints.

* Update screenshots
2018-05-11 16:21:52 -04:00
Erik Demaine
9bb48b83f1 Cleanup domTree.js to re-use code (#1305)
* Refactor span and anchor into common HtmlDomContainer superclass,
  without changing internal data structure (e.g. not storing tagName).
* Makes it easy to add more similar tags
* Number of lines falls from 676 to 587
2018-05-11 19:31:21 +09:00
Erik Demaine
523df299e5 Line breaks for inline formulas (#1287)
* Line breaks for inline formulas

* Basic support for \allowbreak and \nobreak

* Fix spacing around \nobreak, and add documentation

* Backwards-compatibility _getBuilt to fix tests

* Put operator spacing on same line as operator

* One approach to ~

* Simplify \allowbreak/\nobreak, make ~/\nobreakspace prevent line breaks

* Adapt to #1295

* Prevent wrapping within a .base

* Implement \hspace* properly

* Fix flow error

* Update comment for regularSpace

* Update screenshots

* Move `width: min-content` from .katex into .base

* Fix screenshot

* Add min-width rule to .vlist-s

* Factor out hasClass method

* Cleanup nobreak test

* Pull out buildHTMLUnbreakable

* Fix \hspace* test (no longer the same as \hspace)

* Fix \nobreak handling

* Add screenshot test
2018-05-11 01:44:26 +02:00
Ron Kok
34e6458245 Fix underbrace (#1304)
* Fix \underbrace

Fix the vertical alignment so that it correctly takes into account the descender of the lower element.

Fixes issue 1303.

* Update screenshots
2018-05-10 12:50:59 -04:00
Ron Kok
c2ae9e0da6 Revert frac-lines to borders (#1249)
* Revert frac-lines to borders

This PR reverts the rendering of frac-lines from SVG paths back to span borders. This solves the thick grey bar reported by @mbourne in issue #1173.

The result is a frac-line similar to KaTeX v0.9.0-alpha1. The frac-lines are span borders and the CSS contains a `min-width: 1px;` rule to keep those borders visible.

There is one difference between this PR and v0.9.0-alpha1. The earlier work contained a second CSS rule:
```
@media screen and (-webkit-min-device-pixel-ratio: 2), screen and (min-resolution: 192dpi) {
      .katex.mfra.fracline {
            min-height:0.5px;
        }
    }

That second CSS rule did not help much. Instead, it caused some lines to disappear. In the thread to issue 1173, people tested the rendering from the proposed approach and reported that frac-lines disappeared only at sized that were already too small to read.

* Fix lint errors

* Remove superfluous SVG paths.

* Remove superfluous CSS

* Removed `rulespan` from `stretchy.js`

* Support Unicode \ll and \lll

Fixes issue #1271

* Fix indent

* update screenshots for fracLineBorder

* Update Arrays-chrome screenshot for fracLineBorder
2018-05-10 16:05:24 +09:00
Ron Kok
7b7b532fb6 Adjust \underset alignment and spacing (#1290)
* Support Unicode \ll and \lll

Fixes issue #1271

* Adjust \underset alignment and spacing

Fixes issue #1288.

1.  Fixes vertical alignment by keeping the base element on the baseline.
2. Assigns horizontal spacing to \underset in a manner that aligns with LaTeX `\binrel`

* Fix flow error

* Add comment

* Allow for shift of mathops

* Update screenshots

* Test for nested ordgroups

* Set \stackrel spacing class to mrel

* Fix lint error

* Better determination of atom type

* Add comment.

* Add `suppressBaseShift` to ParseNodeTypes
2018-05-10 13:13:37 +09:00
Ashish Myles
5a4aedd882 Make ParseNode value payload and defineFunction handler functions type-safe (#1276)
* Make ParseNode `value` payload type-safe.

* Make defineFunction handlers aware of ParseNode data types.

* Add `type` to all function definitions to help determine handler return type.

* Added unit test for case caught only in screenshot test and fixed issue.

* Rename some symbol `Group`s to avoid conflicts with `ParseNode` groups.

Symbol `Group`s are also used as `ParseNode` types. However, `ParseNode`s of
these types always contain a raw text token as opposed to any structured
content. These `ParseNode`s are passed as arguments into function handlers to
create more semantical `ParseNode`s with more structure.

Before this change, "accent" and "op" were both symbol `Group`s and `ParseNode`
types. With this change, these two types (the raw accent token `ParseNode`, and
the structured semantical `ParseNode` are separated for better type-safety on
the `ParseNode` payload).

* stretchy: Remove FlowFixMe for a forced typecast that's no longer needed.
2018-05-09 20:13:31 -04:00
Erik Demaine
3613885da1 Document new error handling behavior (renderOnError) (#1302)
PR #1169 forgot to document itself.  This fixes the README accordingly.
2018-05-09 23:11:33 +09:00
Erik Demaine
2ee5c684ee Update texcmp (#1297)
* Update texcmp

I found that the existing docker rules for texcmp did not make a working
installation of LaTeX; in particular, it was missing a lot of the recently
added packages.  I updated to Ubuntu 17.10 and tweaked the package listings
until things compiled again.  Now I can run texcmp again.

* texlive-font-utils not necessary
2018-05-09 09:34:47 -04:00
Ron Kok
42f305304b Fix extensible arrow sup vertical alignment (#1256)
* Fix extensible arrow sup vertical alignment

Fixes issue #1254

* Fix lint error

* Allow small depth
2018-05-09 22:27:30 +09:00