Commit Graph

9 Commits

Author SHA1 Message Date
Erik Demaine
0e9acce9be feat: Allow text-mode accents in math mode, except in strict mode (#3009)
* 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>
2021-05-14 21:08:39 +00:00
ylemkimon
8a24907518 build(deps): update dependencies (#2301)
* Bump flow version

* Bump jest version

* Bump eslint version

* Bump rollup version

* Bump webpack version

* Bump misc dependencies and update lockfile

* Update lockfile

* Bump commander version

* Bump misc dependencies

* Bump istanbul version

* Bump docusaurus version

* Update lockfile

* Explicitly declare dependencies

* Bump caniuse-lite version

* Update lockfile

* Bump commander version

* Bump webpack and css-loader version

* Bump flow version
2020-07-25 11:38:29 -07:00
Erik Demaine
647c661db0 Remove double encoding in MathML via Unicode MathML spaces (#1813)
* Remove double encoding in MathML via Unicode MathML spaces

We used to have a complex mechanic for escaping strings, marking them as
`needsEscape = false`, and then not escaping those strings (for
combining strings in `\operatorname`).  But this doesn't really work
with `render`ing directly to a node, as `document.createTextNode` can't
be stopped from escaping.

I've thus removed this mechanic, which required the following changes:

* Switch MathML "smart space" encoding to use Unicode instead of
  `&LongNames;` (which weren't working with `render` for the same reason).
* Hack our HTML/MathML serializer to not use `String.trim`, which wrecks
  havoc with emitted Unicode spaces.

Now `toText()` doesn't escape, so strings concatenate in unescaped form,
and `toHTML()` only does the necessary escaping.  Thus fix #1782.

* Fix src/utils.js

Co-Authored-By: edemaine <edemaine@mit.edu>

* Fix src/mathMLTree.js documentation

Co-Authored-By: edemaine <edemaine@mit.edu>

* Remove trim hack thanks to diffable-html@4.0.0

* Switch back to jest-serializer-html

* Update mathMLTree.js
2019-01-02 01:55:44 +09:00
Erik Demaine
2202aa774f Comments without terminating newlines, \href fixes, \url support (#1529)
* Comments without terminating newlines in nonstrict mode

Fix #1506 by allowing single-line comments (`%` without terminating newline)
in nonstrict mode.  `Lexer` and `MacroExpander` now store the `Settings`
object, so the `Lexer` can complain about missing newline according to the
`strict` setting.  I filtered this out from the snapshot tests with a slightly
different `replacer`.

* Reimplement \href like \verb, add \url

Major restructuring to lex URL arguments differently, e.g. to support
`\href%{hello}` and `\href{http://foo.com/#test%}{hello}`.  The new URL
parsing code is simpler, but involves a special case in `parseSymbol`
like `\verb`.

Also add support for `\url` while we're here.

* Cleanup

* Fix flow errors and improve error messages

* Add \url to documentation

* Improve doc formatting
2018-07-31 14:13:30 -04:00
ylemkimon
71035c7111 Refactor test helpers (#1336)
* Refactor test helpers

* Combine common codes from `parse` and `build`, and dispatch using
`Mode`
* Remove `toNotBuild` and `toNotParse` and use `expect.not`
* Remove `Warning` and instead mock `console.warn`
* Add `expect.toHavePassed` and check whether parse/build succeeded
lazily
* Improve failed test `message`:
  - Use color
  - Print stack traces(excluding internals)
  - Print diff
  - Follow jest matcher output style

* Update helpers.js

* Remove toBeTruthy checks

getParsed throws an error if parsing fails.

* Used tagged literals

* Use .toHaveLength

* Use tagged literals

* Use to{Build,Parse}Like where possible

* Remove compareParseTree

* Use snapshot where possible

* Join into one line where <88 chars

* Revert console.warn() to throw an error

Merge `expectToWarn` to `expectKaTeX`, like
`expect.toFailWithParseError`

* Remove call to console.warn from stack traces

* Fix merge errors

* Remove `getTree`

* Move `_getBuilt` into `getBuilt`
* Move default settings and tagging literal support in to `getParsed` 
and `getBuilt`
* Remove stack traces clean-up
* Remove `toHavePassed` matcher

* Extract `expected` string construction into `printExpectedResult`
2018-07-21 19:06:07 -07:00
ylemkimon
518379aed5 lexer: Remove match-at dependency, use RegExp (#1447)
* lexer: Remove `match-at` dependency, use RegExp

* chore(package): update flow-bin to version 0.75.0

* Fix flow error

* Remove unused flow libs

* Minor fix

* Throw an error when `RegExp.exec` jumps
2018-06-28 03:13:27 +09:00
Erik Demaine
65569249be \newcommand, \renewcommand, \providecommand (#1382)
* \newcommand, \renewcommand, \providecommand

* Tests

* Add comment

* Add symbols to the set of already defined things

* Add implicitCommands, catch \hline outside array

* Add \relax

* Move isDefined to be a method of MacroExpander

* Namespace.has

* Reword error messages

* Add \hdashline given #1407
2018-06-07 13:39:39 +02: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
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