Add length and rawError as public parameters of ParseError to allow for richer error UIs in editors. This information was already there, but only encoded into the errors message. This change is purely additional, the existing parameters have not changed.
* fix: Support `\let` via `macros` option
Issue #3737 turned out to be how we handled the return value of `expandOnce`.
We assumed that, if the return value isn't an `Array`, it's an
`instanceof Token`. This isn't necessary true with a user's `macros`
object, and given that we don't currently export `Token`, it's pretty
difficult to bypass.
Given that we never actually use the array return values from
`expandOnce`, I changed the return value for `expandOnce` to either a
`number` (to indicate the number of expanded tokens, so you could still
look up the tokens in the stack if you wanted to) or `false`
(to indicate no expansion happened). We can't use `0` for the latter
because an actual expansion might result in zero tokens.
The resulting code is arguably cleaner.
I also documented that `macros` can have object expansions, and
specified how to simulate `\let`.
Fixes#3737
* Revise macros documentation according to comments
* `\bar` examples weren't rendering correctly because of `\gdef\bar`
example when illustrating `\gdef` and `\xdef`.
* Improve `\bar` name to `\sqr` when defining squaring
(not necessary for fix, but improved naming).
* Fix `\def` scoping test that originally seemed related.
Fixes#3803
Fix `src/functions/cr.js`'s definition of `\\` to manually look for an
optional argument via `future()` instead of `numOptionalArgs`, so that
it does *not* skip over spaces. This matches the existing behavior of
`\\` in `src/environments/array.js` and AMSMath's behavior of `\math@cr`
via `\new@ifnextchar`.
Fixes#3745
Co-authored-by: Ron Kok <ronkok@comcast.net>
* feat: Support \Braket, \set, and \Set
* Update screenshots.
* Rewrite to redefine | via macros
* Update screenshot after merge
* Rename \bra@ket@one -> \bra@set
* Fix spacing in \set and \Set to match braket.sty
* Add || and \| support
* Update tests
* Update screenshots
Co-authored-by: Ron Kok <ronkok@comcast.net>
* feat: Support Unicode (sub|super)script characters
* Acquire tokens via repeated fetch()
* Match more Unicode (sub|super)script characters
* Update docs with new characters
* Add Greek characters to RegEx
* Pick up review comments
Co-authored-by: Erik Demaine <edemaine@mit.edu>
* Apply operator spacing to Unicode ∙ ∘ ∖
* Appease Semantic Versioning.
* Fix website build issue
* Tweak docs to space final bin correctly
Co-authored-by: Erik Demaine <edemaine@mit.edu>
* feat: \nonumber and \notag support
Support `\nonumber` (and equivalent `\notag`) using a global macro
`\@eqnsw` to track whether one occurs in each row, similar to how
amsmath uses global `\@eqnswtrue`/`\@eqnswfalse`.
Fix#2950
* Remove duplicate mention of align*
* Working version of \tag within {align}
* Simpler subparse mechanism
* Fix flow errors, clarifying set-to-undefined
* Document that \tag works in rows
* Add screenshot tests
* Add Jest tests
* Add Safari screenshot
* Commit message about fixing \tag
Fixes#2379
* Apply suggestions from code review
Co-authored-by: ylemkimon <y@ylem.kim>
* Revise and move getAutoTag
* Fix handling of split
* Remove unnecessary feedTokens
Co-authored-by: ylemkimon <y@ylem.kim>
Co-authored-by: ylemkimon <y@ylem.kim>
* feat: implement \relax as no-op function
BREAKING CHANGE: `\relax` is now implemented as a function. It'll stop
expansions and parsing, so the behavior around `\relax` may change.
For example, `\kern2\relax em` will no longer work.
* Round distances to 4 places
* Revert numbers in mathMLTree.js
* Update Jest test
* fix: round dimension to 4 places via makeEm
* test: update screenshots
* docs: add link to this PR
Co-authored-by: ylemkimon <y@ylem.kim>
Close all groups after parse, in particular in case of parse error,
completing `Namespace`'s simulation of local definitions.
Fixes#3122
Co-authored-by: ylemkimon <y@ylem.kim>
* fix: \char support for >16-bit Unicode characters
`String.fromCharCode` only supports Unicode characters up to 16-bit.
`String.fromCodePoint` from ECMAScript 2015 supports all Unicode code points.
Unfortunately, IE doesn't support the latter, so use former as fallback.
Fixes#3004
Co-authored-by: ylemkimon <y@ylem.kim>
* feat: text-mode cedilla accent via \c
Add text-mode accent function `\c` and corresponding Unicode support.
Part of #638
Co-authored-by: Kevin Barabash <kevinb@khanacademy.org>
* Update screenshots
Co-authored-by: Kevin Barabash <kevinb@khanacademy.org>
* chore(deps): update selenium/standalone-firefox docker tag to v20210422 [skip netlify]
* test(screenshotter): update screenshots
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Young Min Kin <mail@ylem.kim>
Previously, the matrix family of environments assumed that the number of
columns was given by the number of columns in the first row. This
didn't work when there were zero rows, and it didn't handle the case
where future rows have more columns than the first (which is visible
when using an alignment other than `c`, such as `\begin{matrix*}[r]`).
Fixes#3017
Co-authored-by: ylemkimon <y@ylem.kim>
* feat: Allow text-mode accents in math mode, except in strict mode
LaTeX only issues a warning when using e.g. `\r` in math mode.
KaTeX will now do the same with the default `strict` setting of `warn`.
Fixes#2983
* Fix accent mode
Co-authored-by: ylemkimon <y@ylem.kim>
* fix#2990
fix make stretchycode to textNode bug.
* fix: fix stretchy.js@mathMLnode line too long
* chore(screenshotter): update stretchy snapshots
* fix: remove dup '\' in cdrightarrow cdleftarrow and cdlongequal
* test: add stretchy MathML builder test case
Co-authored-by: nferzhuang <nferzhuang@tencent.com>
Co-authored-by: Ron Kok <ronkok@comcast.net>
* fix: Correctly parse \ followed by whitespace
LaTeX parses `\` followed by whitespace including up to one newline
as equivalent to `\ `. (With multiple newlines, you get paragraph
breaks.)
Fix#2860.
* Improve comments
* Avoid second RegExp match in control words
* Document capturing groups
Co-authored-by: Ron Kok <ronkok@comcast.net>
Support single characters having a catcode of 13 (active) or 12 (other),
and expand a macro defined for the character only if it's active.
This enables defining `~` as a macro, but avoiding expansion in URLs.
Fix#2924
Co-authored-by: ylemkimon <y@ylem.kim>
* Combine characters together in all expressions
Call `tryCombineChars` in `buildExpression`
* update screenshots, exclude 'coverage' from lint
* update MathML snapshots
* don't combine two 'mbin's or two 'mord's
* update screenshots
* update screenshots
Co-authored-by: ylemkimon <y@ylem.kim>
Co-authored-by: Kevin Barabash <kevinb@khanacademy.org>
* Support {CD}
* Edit screenshotter test to fit on one page
* Update screenshots
* Remove bogus Safari screenshot
* Edit documentation to avoid tag conflicts and explain delimiters
* Add type annotations
* Add bogus safari screenshot
* Update with real Safari screenshot
* Set label vertical alignment
* Revise call to parseExpression() per PR 2085 changes to macro parsing
* Update Firefox screenshot
* Pick up review comments
* Add unit tests and snapshot.
* Tighten up label collection.
* Better loop index
* remove extra space
* Picked up comments. Added a parse check. Added a test.
Co-authored-by: ylemkimon <y@ylem.kim>
Co-authored-by: Kevin Barabash <kevinb@khanacademy.org>
Co-authored-by: Kevin Barabash <kevinb7@gmail.com>