* 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
* Use current font for accents
Fix#353 using `buildCommon.makeSymbol` to automatically determine font
for the accent symbol.
* Fix screenshots
* Fix flow error
* Fix file permissions
* Unicode characters in math render in text mode
Improve #2031 by rendering all supported Unicode text characters (via
supportedCodepoints) in text mode, mimicking wrapping them in `\text`,
thereby using metrics of letter M as usual.
* Add tests
* Improve documentation
* Implement review comments
* 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)
* Remove forced \normalsize in \raisebox
Fix#1786 (incorrect size of "E" in `\TeX`) by fixing `\raisebox` to
keep the current font size. Previously, `\raisebox` was rendering its
second argument as if it were in `\normalsize\textrm{...}`; now,
the argument is just as if it were in `\textrm{...}`.
* Fix screenshots
* New "hbox" argument type to convert box-like arguments
* Review comments
* Fix \fbox to use hbox argument
* Render A in \LaTeX and \KaTeX in \scriptstyle (not \scriptsize)
* Add screenshot test
* Revert .sizing { width: min-content} thanks to #2044
* Fix font choice in operators like \log (e.g. \boldsymbol{\log})
Fix#1971 by correctly passing arguments into the font choice for
the HTML handler for operators like \log.
* Extend BoldSymbol screenshot test
* Require options argument in mathsym to avoid this type of bug in the future
* Update screenshot
Fix#1788 by removing `display:inline-block` rule from `.sizing`.
I don't see why a sizing change cares about the display mode, and it
fixes the interaction between `makeVList` and sizing commands.
It should also allow me to remove a `.sizing { width:min-content }` rule
that I had to add in #1787.
* 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
* Improve MathML for classes
* Fix lint errors
* Fix another lint error
* Simplify MathML resulting from single character box
* Fix lint errors
* make some of the arrays in our html/mathml helper functions readonly
* \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
* Test for duplicate symbols/macros
We've had a few cases where we accidentally include the same symbol or macro
definition in both macros.js and symbols.js. This new test automatically
detects these scenarios during Jest testing.
* Fix lint errors
* 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
Update `test/screenshotter/test.tex`'s definition of `\KaTeX` macro to match
the metrics of `src/macros.js`'s definition of `\KaTeX`, and thereby fix#1703.
I just changed the `\kern` metrics to match the update from #974, and left
the font selection code to match LaTeX's definition of `\LaTeX`.
* 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
* 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
* 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
* Add support for `\lparen` and `\rparen` delimiters.
* Add missing math delimiter. Fix alphabetic order.
* Add test.
* Add spaces between parenthesis and square brackets.
* Move unsupported command (undefined control sequence) error to parseSymbol
* Change parseGivenFunction and parseFunction to parse only function
* Move \begin handling to environment.js
* Remove ParsedFunc/Arg, move logics into parseGroup
* Fix flow error
* Remove parseFunction, rename parseGivenFunction to parseFunction
* Minor fixes
* Remove previously resolved TODO
* Minor fixes
* Update flow typing