Commit Graph

30 Commits

Author SHA1 Message Date
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
ylemkimon
d1c0468ef8 Reorganize some glyphs, simplify font selection, break \mathcal{123} (#2156)
* Reorganize some glyphs

* Remove mathdefault

Numerals are textord and it was never reachable.

* Use PUA for \imath and \jmath

* Update katex-fonts

* Update tests

* Update src/buildCommon.js

* Update screenshots

* Add comment regarding usage of PUA in \imath and \jmath

* Update fonts

Co-authored-by: Erik Demaine <edemaine@mit.edu>
2020-07-11 14:54:28 -04:00
Erik Demaine
1512de5b35 Reset to leftmost spacing mode after newline (#1841)
* Reset to leftmost spacing mode after newline

Newlines have class "mspace newline" but shouldn't be fully ignored:
they should reset the spacing mode back to "leftmost" so as to not
accidentally create trailing spaces at end of lines.  Fix #1828.

* Update snapshots

* Add root detection, and treat newline specially only then

Co-authored-by: ylemkimon <mail@ylem.kim>
2020-07-11 12:36:51 -04:00
ylemkimon
9917d1ce84 Add support for \expandafter, \noexpand, \edef, \let, and \long (#2122)
* Add support for \expandafter

* Add support for \noexpand

* Add support for \edef

* Update comments

* Allow \long before macro definition

* Update documentation

* Update comments

* Fix defPrefix

* Add support for \let

* Update documentation

* Print error token

* Update documentation

* Check whether command is expandable

* Add tests

* Fix token order

* Make noexpand a Token property

* Throw error if control sequence is undefined when expanding

* Rename expandableOnly to expandOnly

* Make unexpandable macro property

* Move \expandafter to macros.js

* Add TODO

* Fix merge conflict

* Update a test case

* Remove unused functions in MacroContextInterface

* Update comments

* Refactor code

* Move \noexpand to macros

* Update MacroExpander.js

* Add a test case

* Separate control sequence check to a function

* Add support for \futurelet

* Separate RHS getter to a function

* Update documentation

* Move expandOnly logic to expandOnce

* Refactor code and update comments

Co-authored-by: Kevin Barabash <kevinb@khanacademy.org>
2020-03-11 12:14:34 +09:00
ylemkimon
e5333ad04d Add HTML extension (#2082)
* Add html extension

* Fix flow error

* Update documentation

* Add tests

* Call buildA11yStrings for "html" node

* Throw ParseError when parsing \htmlData fails

* Improve documentation

* Add a screenshotter test

* Add dummy screenshot

* Update screenshots
2019-12-01 17:49:28 -05:00
Erik Demaine
285c9fe0b6 Re includegraphics (#2053)
* Re-enable \includegraphics now that we have trust setting

This reverts commit 5806b240b3.

* Include Khan Academy test logo in repo and use in test (fix #1892)

* Update screenshots

* Update documentation

* Add tests, cleanup existing tests

* Update snapshots

* Enable trust testing (trust=true by default)
2019-07-22 00:15:29 +09:00
Erik Demaine
3800dc49c1 [breaking] trust setting to indicate whether input text is trusted (#1794)
* trust option to indicate whether input text is trusted

* Revamp into trust contexts beyond just command

* Document new trust function style

* Fix screenshot testing

* Use trust setting in \url and \href

* Check `isTrusted` in `\url` and `\href` (so now disabled by default)
* Automatically compute `protocol` from `url` in `isTrusted`, so it
  doesn't need to be passed into every context.

* Document untrusted features in support list/table

* Existing tests trust by default

* remove allowedProtocols and fix flow errors

* remove 'allowedProtocols' from documentation

* add a comment about a flow error, rename urlToProtocol to protocolFromUrl

* add tests test that use function version of trust option

* default trust to false in MathML tests

* fix test title, remove 'trust: false' from test settings since it's the default
2019-07-08 21:57:23 -04:00
Ron Kok
9822414733 Render MathML directly (#1966)
* Render MathML

* Fix lint error

* Change from main api to rendering options
2019-05-13 19:31:04 -04:00
Erik Demaine
8346294bf3 Fix \\ and \newline after operator (#1796)
* Fix \\ and \newline after operator

Fix #1790.  `\\` and `\newline` render as a span with classes
`mspace` and `newline`.  We need to check for `newline` when bringing
spaces into the same `base` group.

* Add tests and comment
2018-12-26 18:17:30 -05:00
ylemkimon
a3215b284e Refactor buildExpression to depth-first traverse groups (nodes), fix spacings and \begingroup...\endgroup (#1706)
* Refactor `buildExpression` to depth-first traverse groups (nodes)

* Fix \begingroup...\endgroup

* Rename traverseNodes to traverseNonSpaceNodes, update comments and tests

* Update Parser.js

* Update katex-spec.js.snap
2018-10-29 00:31:00 -04:00
ylemkimon
ba8e224b8d Fix \mathit font and italic correction and add \mathnormal (#1700)
* Fix \mathit font (Math-Italic -> Main-Italic) and italic correction

* Rename mathit to mathdefault and mainit to mathit

* Add \mathnormal
2018-10-10 17:18:07 +09:00
Ashish Myles
fcc5c4420a Rename .value to .body in "ordgroup". (#1609) 2018-08-13 23:17:23 +09:00
Ashish Myles
8492a7532b Rename .value to .text or .color where applicable. (#1606)
* Update comment for defineFunction handler.

* Rename .value to .text in all token-style ParseNodes.

* Rename symbolNode's .value to .text.

* Rename color-token's .value to .color.
2018-08-13 20:58:46 +09:00
Ashish Myles
f3a9bd4b3d Flatten "styling", "text", and "array" ParseNodes. (#1559)
* Flatten "styling" ParseNode.

* Flatten "text" ParseNode.

* Flatten "array" ParseNode.
2018-08-07 14:26:40 +09:00
Ashish Myles
5b6ffd7b9d Flatten a bunch of non-pervasive ParseNode types (part 2) (#1552)
* Flatten "operatorname" ParseNode.

* Flatten "overline" ParseNode.

* Flatten "raisebox" ParseNode.

* Flatten "rule" ParseNode.

* Flatten "sizing" ParseNode.

* Flatten "smash" ParseNode.

* Flatten "sqrt" ParseNode.

* Flatten "underline" ParseNode.

* Flatten "enclose" ParseNode.

* Flatten "environment" ParseNode.

* Flatten "genfrac" ParseNode.

* Flatten "htmlmathml" ParseNode.

* Flatten "infix" ParseNode.

* Flatten "kern" ParseNode.

* Flatten "lap" ParseNode.

* Flatten "color" ParseNode.
2018-08-06 14:59:44 +09:00
Ashish Myles
1506dc1d88 Flatten a bunch of non-pervasive ParseNode types (part 1) (#1551)
* Flatten "url" ParseNode.

* Flatten "href" ParseNode.

* Flatten "verb" ParseNode.

* Flatten "tag" ParseNode.

* Flatten "cr" ParseNode.

* Flatten "delimsizing" ParseNode.

* Flatten "middle" ParseNode.

* Flatten "leftright" ParseNode.

* Flatten "leftright-right" ParseNode.

* Flatten "mathchoice" ParseNode.

* Remove unused ParseNode type "mod".

* Flatten "mclass" ParseNode.

* Flatten "font" ParseNode.

* Flatten "phantom" ParseNode.

* Flatten "hphantom" ParseNode.

* Flatten "vphantom" ParseNode.
2018-08-06 11:49:43 +09:00
Ashish Myles
fd6690b988 Flatten ParseNodes: "supsub" and related ("accent", "accentUnder", "horizBrace", "xarrow", "op"). (#1542) 2018-08-03 14:06:02 +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
4a2903148e Automatic mrel/mbin spacing for \boldsymbol (#1388)
* Automatic mrel/mbin spacing for \boldsymbol

Fix #1154

* Add test

* Add missing mode

* Separate out \boldsymbol support to correct flow types

* Fix ternaries thanks to @ronkok's comment

* Revert package-lock.json

* Add screenshot test
2018-06-11 08:19:50 -04:00
Hossein Saniei
8b1e1b4886 [plugin system] Add a utility function (setFontMetrics) to extend builtin fontMetrics (#1269)
* Add and expose addFontMetrics function

* fix typo

* recreate package.json-lock

* Add setFontMetrics function to change the defualt metricMap - change getFontMetrics to getGlobalMetrics

* use new setFontMetrics on main KaTeX object

* fix package-lock.json error by rebuilding it

* Add appropriate tests

* update the snapshot
2018-06-09 20:42:35 -04:00
Ron Kok
93904c51ab Support \hdashline (#1407)
* Support \hdashline

Support `\hdashline` from package `arydshln`. This PR acts as a complement to PR #1395.

Similarly to #1395, the dashed line is rendered as `border-bottom-style: dashed;`. That does not exactly match the `dashsegment` and `dashgap` lengths in `arydshln`, but it does render black lines with sharp edges.

* Fixed top line position

* Add screenshots

* Fix lint error

* Fix another lint error

* Deleted HLine screenshots

* Pick up comments
2018-06-07 03:30:29 +02:00
Erik Demaine
fcb32f058b Support \arraystretch as a macro definition (#1381)
* Support \arraystretch as a macro definition

Also add `expandMacro` and `expandMacroAsText` helpers to `MacroExpander`.

* Remove excess defaulting

* Add test
2018-06-03 18:19:23 -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
Erik Demaine
49e673a59c Stop throwing ParseError when throwOnError is false (#1169)
* Stop throwing ParseError when throwOnError is false

`render`, `renderToString`, etc. now catch ParseError and render it to the
raw LaTeX (with proper escaping) and a hover title with the error.

Along the way:
* Use new `katex.__renderToDomTree` in katex-spec's `_getBuilt`.
  (This was necessary to get the new error handling in `_getBuilt`.)
* Fix jest results which must always be functions, not strings.

* fix lint

* Fix flow error

Leave error type unspecified, as we check it with instanceof.

* Update katex-spec.js
2018-05-09 22:18:50 +09:00
Ryan Randall
7de91f73eb Nested Math in Non-Default Text Fix (#1111)
* Fixing nested math in non-default text. Added appropriate screenshot tests.

* Adding appropriate logic for buildMathML and resolving tests.

* Addressing Kevin's comment. Adding tests.

* Adding appropriate screenshots.

* Removing unnecessary data, adding consistent naming convention.

* Cleanup

* Handling possible edge cases.

* Updating per PR comments
2018-02-19 17:37:08 -05:00
Kevin Barabash
4bec90be0c extract font functions and implicit color function (#1119)
* extract font functions and implicit color function

* remove oldFontFuncs from Parser.js

* allow old font commands in text mode
2018-01-31 10:03:30 -05:00
Kevin Barabash
f80d0afee8 extract sizing and styling implicit functions (#1116)
* extract sizing and styling implicit functions

* add BreakToken type
2018-01-30 07:13:01 -05:00
Kevin Barabash
71e0b35b27 allow sizing commands inside optional groups (#885)
* allow sizing commands inside optional groups

* allow color, old font, and style commands inside optional groups
2017-10-03 11:30:59 -06:00