Commit Graph

206 Commits

Author SHA1 Message Date
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
Karl Traunmüller
8fcfe97e11 Fix test that was checking numerator instead of denominator (#2160)
* Test was checking numerator instead of denominator

* fixed a typo
2019-11-30 09:33:20 -05:00
Ron Kok
d1cee3cf3d Support {rcases} and {drcases} (#2149)
* Support {rcases} and {drcases}

* Fix lint error

* Update screenshots
2019-11-10 18:36:02 +09:00
Erik Demaine
0cdb28b256 \@ifnextchar consumes spaces (#2118)
* \@ifnextchar consumes spaces

Fix #2117 by fixing our implementation of \@ifnextchar to match LaTeX's:
consuming spaces before checking the next character.  See #2117 for details.

* Update MacroContextInterface
2019-10-13 00:33:30 +09:00
Erik Demaine
1eda0e86a0 Add support for \cal (#2116)
Fix #2115 by adding \cal to list of old-style font commands.
(Surprisingly tiny change!)
Add tests for all old-style font commands.
2019-10-10 20:46:10 -04:00
Ciro Santilli,Opinions and content are my own, not my employer's,2018新疆改造中心,1989六四事件,1999法轮功 ,2019 996.ICU, 2018包子露宪,2015 710律师劫,2015巴拿马文件 邓家贵,2017低端人口,2008西藏骚乱scriptalert(1)/script
36595343b7 Create globalGroup option to place definitions in global scope (#2091)
If true, this allows \newcommand definitions to persist across calls to
renderToString.

Fix https://github.com/KaTeX/KaTeX/issues/2070
2019-09-22 15:03:44 -04:00
Erik Demaine
2a3013d72a Fix parse timing by separating consume() into fetch() and consume() (#2054)
* Fix parse timing by separating consume() into fetch() and consume()

Fix #1989, and generally cleanup parse timing (many fewer hoops to jump
through) by defining two methods on parser:

1. `consume()` marks the current token (`nextToken`) as "done", but
   doesn't yet fetch the next token (setting `nextToken` to `null`).
2. `fetch()` fetches the next token if we don't already have one
   (e.g., if last token was `consume()`d).

Before this change, `consume()` did both actions.  By separating them,
and allowing the parser to live in a state for a while where `nextToken`
is `null`, it is far easier to change settings (in particular, math/text
mode and catcodes) before reading the next token, in a way that depends
on what we're parsing.  For example, if an argument should be treated in
text mode, we can just set the mode in the argument parser, instead of
when the previous token was consumed.  Similarly, if an argument should
be treated as a URL, we can just set the catcode of `%` in the URL
argument parser, and reset it after.  We no longer have to take care to
reset things before calling `consume()`.

This change mostly involves changing `this.nextToken` to `this.fetch()`.
In a perfect world, we could use slightly fewer calls to `this.fetch()`,
but Flow doesn't realize that `this.nextToken` will be non-null after a
call to `this.fetch()`, so we need to use a few more calls to
`this.nextToken()` or a few more local `nextToken` variables.

* Remove now-unnecessary consumeMath

* Update Parser.js
2019-08-21 16:14:42 +09: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
Ron Kok
2dc8f8121a Support \operatorname* (#1899)
* Support \operatorname*

* Fix lint errors

* Fix YAML

* Update screenshots

* Break out a function to avoid code duplication

* Fix lint errors

* Restore wrapper span

* Update docs

* Reinstall color macros lost in merge

* Update screenshots

* Add type annotations, Move to utils file, add \limits to screenshots

* Fix lint errors

* Rearrange screen shot to fit onto page

* Update screenshots

* tweak location of utils.js and assembleSupSup.js
2019-07-17 21:38:44 -04: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
fc79f79c78 Support Unicode \digamma (#2010)
* Support Unicode \digamma

* Update screenshotter images
2019-07-05 20:01:51 -04:00
Erik Demaine
19d9d83ad3 \color affects following \right, put array cells in their own groups (#1845)
* \color affects following \right

Fix #1844 by giving `leftright` nodes a `rightColor` attribute for how
to color the right bracket.  Now `\color` sets the macro
`\current@color` in the current environment (in particular, resetting
after `\right`), just like `color.sty` does in LaTeX.  This is used to
specially pass the current color into any following `\right` and then
into the `leftright` parse node.

* Add test

* Put each array cell in its own group/namespace

* Improve cell group isolation, add test and TODO

* Improve comments
2019-07-05 00:27:55 -04:00
elbaro
88d9a8a4df Add \plim (#1952)
* Add \plim

* tweak position of argmin and plim in support table
2019-06-01 20:20:26 -04:00
Ron Kok
3b60aee16c Support {smallmatrix}, {subarray}, and \substack (#1969)
* Support {smallmatrix}, {subarray}, and \substack

* Fix lint errors

* Update docs. Screenshots step 1.

* Screenshots step 2

* Screenshots step 3

* Pick up review comments

* Fixed arraycolsep for {smallmatrix}

* Fixed lint error

* Updated screenshots
2019-05-20 23:34:49 -04:00
Ron Kok
6b0f06df21 Improve MathML fonts (#1965) 2019-05-19 19:24:34 -04:00
Ben Dyer
4f2da04e5d Add test for double square brackets to katex-spec (#1956) 2019-05-12 23:25:25 -04:00
Kevin Barabash
5806b240b3 disable \includegraphics until trust settings is merged (#1951)
* disable \includegraphics until trust settings is merged

* disable one more test
2019-04-28 17:52:27 -04:00
Tesla_Ice_Zhang
6bb312f687 Support double-square curly braces (#1953)
* Support double-square curly braces

Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>

* Rename `llbrace` to `lBrace`

* Address comments: add mathml

* Fix code style

* Fix doc

* Add to docs/support_table
2019-04-25 07:23:00 -07:00
ylemkimon
7d7c55c4c7 Approximate font metrics only when metrics don't exist (#1898)
Fix non-existent metrics error for \eth
2019-04-06 18:24:32 -04:00
Erik Demaine
070883532a Support \textup and \textmd (#1921)
* Support \textup and \textmd

This PR adds support for `\textup` and `\textmd`, which are the inverses of
`\textit` and `\textbf`.  Unlike bare `\text`, they result in `textup` and
`textmd` classes being applied, but those have no CSS rules, so they act the
same as bare `\text`.

Fixes #1909.

* Add documentation

* Add unsupported font commands
2019-04-06 02:51:11 +09:00
Ron Kok
21f7fe85d5 Improve MathML for characters in Unicode private use area (#1908)
* Add macros for private area characters

* Add \nsupseteqq and \nsubseteqq
2019-03-28 09:37:54 -07:00
Erik Demaine
7f778d1543 leqno and fleqn support (#1814)
* leqno support

* Add fleqn support

* Add tests

* Lint fix

* Add leqno and fleqn to website demo
2019-01-29 18:40:17 +09:00
René Filip
9ddc24c9f1 add \argmax and \argmin (#1820)
* add \argmax and \argmin

* add reference to argmin and argmax
2019-01-12 18:36:36 -05:00
Ron Kok
e85cb97cca Fix \genfrac w/empty delimiter arguments (#1816) 2019-01-02 02:13:54 +09:00
Ron Kok
f5234a2f01 Fix \hphantom width (#1809)
* Fix \hphantom width

* Spin up phony screenshot test

* Make better choice of smash screenshot test

* Real screenshotter test

* Add strict mode

* Fix lint error

* useStrictBehavior

* Revert to previous strict setting

* useStrictBehavior "phantomSpacing"

* Fix tests via nonstrictSettings

* Fix documentation

* Remove bin|rel
2019-01-02 01:49:23 +09: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
Ron Kok
d604965c62 Allow \includegraphics to omit the optional argument (#1807)
* Allow \includegraphics to omit the optional argument

* Fix lint error
2018-12-23 18:52:30 -05:00
ylemkimon
3dfd17d9b4 Add catcode to Lexer, move comment parsing back to Lexer (#1789)
* Remove redundant consumeSpaces()

- Spaces after command sequence are ignored in Lexer
- parseExpression consumes spaces in the math mode

* Add catcode to Lexer, move comment parsing back to Lexer

- Fix parsing a comment before a sup/subscript argument
- Fix parsing a comment before an expression
- Fix parsing a comment before or between \hline
- Fix parsing a comment in the macro definition
- Fix parsing a comment including a command sequence

* Update Lexer.js

* Update Parser.js

* catcode -> catcodes
2018-11-24 18:42:14 -05:00
Ron Kok
f713f324bd Support \includegraphics (#1620)
* Support \includegraphics

* Update screenshots

* Fix lint errors

* Fix more lint errors

* Fix lint errors take 3

* Add documentation, error messages

* Improve CSS

* Update domTree to coordinate with PR #1633

* Update screenshots

* fix flow errors

* Use same RegEx as href

* Fix lint error

* Accept raw ArgType

* Fix lint error

* fix flow error

* Add test
2018-11-01 18:43:41 -04: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
Ron Kok
5f3ab13d02 Support blackboard bold in text mode (#1757) 2018-10-29 00:24:44 -04:00
ylemkimon
4dd0e2cdca Add \> (#1752)
* Add \>

* Update snapshot
2018-10-24 22:04:00 -04:00
Ron Kok
0b7b4db7fc Support Unicode double square brackets (#1750) 2018-10-24 15:57:36 +09:00
AlbertHilb
89bb371152 Add support for \lparen and \rparen delimiters. (#1741)
* Add support for `\lparen` and `\rparen` delimiters.

* Add missing math delimiter. Fix alphabetic order.

* Add test.

* Add spaces between parenthesis and square brackets.
2018-10-15 21:05:10 -04:00
ylemkimon
a51dc4b072 Wrap document fragment where classes, attributes, or styles are applied (#1707)
* Wrap document fragment group where classes or styles are applied

* Wrap non-math node where attributes are applied in \href
2018-10-12 22:26:13 -04:00
ylemkimon
3907545e2c Add raw string group, move comment parsing to Parser, change URL group parser (#1711)
* Add raw string group

* Move comment parsing to Parser

* Use raw string group in URL group parser

* Update types.js

* Add multi-level nested url test
2018-10-12 21:21:57 -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
Ron Kok
9b7e10e4f7 Allow 6-digit color spec w/o # (#1690)
* Allow 6-digit color spec w/o #

* Improve RegEx pattern

* Pick up comment

* fix lint
2018-09-01 13:27:17 -04: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
Erik Demaine
00a23b682f Test that \neq is in a group (#1574) 2018-08-09 12:37:51 +09:00
Ron Kok
98dd7fc912 Fix \Large roots (#1485)
* Fix roots

* Update screenshots

* Added a test in a craven gambit to get a green check mark

* Adjust small radicals

* Fix lint error

* Update screenshots
2018-08-08 08:46:04 +09:00
Ron Kok
50c0240349 Support mediawiki (#1558)
* Support mediawiki

* Fix lint error

* Fix link to deprecated syntax

* Change In master to display of functions
2018-08-08 07:49:38 +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
Ron Kok
b2d38104cd Fix \fbox (#1550)
* Fix \fbox

* Fix lint errors

* Change negative space test from \fbox to \boxed
2018-08-04 20:32:06 -07:00
Ashish Myles
fd6690b988 Flatten ParseNodes: "supsub" and related ("accent", "accentUnder", "horizBrace", "xarrow", "op"). (#1542) 2018-08-03 14:06:02 +09:00
Ashish Myles
7e97a382ec Introduce "atom" parse node to coalesce various symbol nodes. (#1541) 2018-08-02 20:46:40 +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