Commit Graph

123 Commits

Author SHA1 Message Date
Erik Demaine
4801ab875a Support for top-level \newline and \\ in inline math (#1298)
* Support for top-level \newline and \\ in inline math

This was a little tricky because `\\` was defined as an endOfExpression.
Instead made `\\` a termination specific to an array environment.
Outside an array environment, buildHTML handles the `cr` object,
resulting in a `.newline` class.  Currently this turns into a
`display: block` (with appropriate vertical spacing) only in inline math,
matching LaTeX.

* Simplify code

* Fix Jest errors

* NewLine screenshot test

* Bug fix: \\ only works at top level of inline

* Add \newline and \cr to test

* Switch test to pmatrix

* Add vertical space test

* Add \\ vs. \newline tests

* Fix flow errors

* Add \cr test

* Add documentation for \\ at top level

* Comment out newRow

* Fix commenting out
2018-05-13 09:58:24 -04:00
Ron Kok
74422e1462 Support \hline (#1306)
* Support \hline

Support `\hline`.

* Fix CSS

* Fix lint errors

* Add double \hline. Code Cleanup

* Reduce width of screenshot test

* Add screenshots

* Use consumeSpaces, read multiple \hlines

* Code cleanup

* Update screenshots
2018-05-12 13:51:14 -04:00
Erik Demaine
523df299e5 Line breaks for inline formulas (#1287)
* Line breaks for inline formulas

* Basic support for \allowbreak and \nobreak

* Fix spacing around \nobreak, and add documentation

* Backwards-compatibility _getBuilt to fix tests

* Put operator spacing on same line as operator

* One approach to ~

* Simplify \allowbreak/\nobreak, make ~/\nobreakspace prevent line breaks

* Adapt to #1295

* Prevent wrapping within a .base

* Implement \hspace* properly

* Fix flow error

* Update comment for regularSpace

* Update screenshots

* Move `width: min-content` from .katex into .base

* Fix screenshot

* Add min-width rule to .vlist-s

* Factor out hasClass method

* Cleanup nobreak test

* Pull out buildHTMLUnbreakable

* Fix \hspace* test (no longer the same as \hspace)

* Fix \nobreak handling

* Add screenshot test
2018-05-11 01:44:26 +02:00
Ashish Myles
5a4aedd882 Make ParseNode value payload and defineFunction handler functions type-safe (#1276)
* Make ParseNode `value` payload type-safe.

* Make defineFunction handlers aware of ParseNode data types.

* Add `type` to all function definitions to help determine handler return type.

* Added unit test for case caught only in screenshot test and fixed issue.

* Rename some symbol `Group`s to avoid conflicts with `ParseNode` groups.

Symbol `Group`s are also used as `ParseNode` types. However, `ParseNode`s of
these types always contain a raw text token as opposed to any structured
content. These `ParseNode`s are passed as arguments into function handlers to
create more semantical `ParseNode`s with more structure.

Before this change, "accent" and "op" were both symbol `Group`s and `ParseNode`
types. With this change, these two types (the raw accent token `ParseNode`, and
the structured semantical `ParseNode` are separated for better type-safety on
the `ParseNode` payload).

* stretchy: Remove FlowFixMe for a forced typecast that's no longer needed.
2018-05-09 20:13:31 -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
Ron Kok
f01f504cfe Support some Unicode Mathematical Alphanumeric Symbols (#1232)
* Support some  Unicode Mathematical Alphanumeric Symbols

This PR adds support for some of the characters in Unicode range U+1D400 to U+1D7FF, [Mathematical Alphanumeric Symbols](https://www.unicode.org/charts/PDF/U1D400.pdf).  Specifically, it adds support for:
* A-Z a-z bold
* A-Z a-z bold italic
* A-Z a-z Fractur
* A-Z a-z sans-serif
* A-Z double struck
•	A-Z script

Addresses issue #1215 and parts of #260.

* Fix lint error

* Fix MathML, and pick up review comments

* Fix lint error

* Add text mode. Remove sans-serif.

* Fix lint error

* Fixed \mathrm, added screenshotter test

* Change screenshotter test to an array

* Add screenshots

* Picked up review comments. Add characters
2018-05-07 20:06:16 -04:00
Ron Kok
f25e08d618 Support Unicode ≘≙≚≛≝≞≟ (#1274)
* Support Unicode stackrel

Supports Unicode characters ≘ ≙ ≚ ≛ ≝ ≞ ≟

* Fix lint error

* Delete unnecessary braces
2018-05-03 16:58:04 -04:00
Ron Kok
7fec5ae5dc Fix \underset (#1277)
* Fix \underset

This PR modifies `\underset` and `\overset` to align with LaTeX behavior when a superscript is applied after the `\underset`.  Fixes issue #1275.

I also changed the spacing from KaTeX `mop` to KaTeX `rmel`. The result seems to be a closer visual match to LaTeX.

* Update screenshots
2018-05-03 16:50:18 -04:00
Ron Kok
5535d720dc Greek caps (#1283)
* Support Greek capital letters

Supports Greek letters ΑΒΕΖΗΙΚΜΝΟΡΤΧ.

Resolves issue #1282.
2018-05-02 14:29:57 -04:00
Ron Kok
b4b57cbc2b Support Unicode \ll and \lll (#1273)
* Support Unicode \ll and \lll

Fixes #1272. Consistent with `unicode-math`

* Rearranged test strings
2018-04-24 21:01:05 -04:00
ylemkimon
1c5a7ed232 Fix anchor.toMarkup (#1246)
* Fix anchor.toMarkup

* Add space between `a`(tag name) and `href`(attribute name)
* Remove `this.href` appended to `markup` in the template literal

* Add regression test on #1245
2018-03-31 08:44:27 -04:00
Erik Demaine
4f29c5a942 Support \( and fix instant mode switching for $, \(, \text (#1213)
* Fix #1212 by supporting `\(...\)` in addition to `$...$` inline math nested inside `\text`. This turned out to be harder than one would think because of the way `$` was being handled specially, while `\(` needed to be handled as a function, which immediately consumed the `\(` token, which meant that the first following token got consumed in text mode instead of math mode (unlike `$` where we could switch the mode before consumption).
* Added new `consumeMode` setting for functions which tells the parser to switch modes just for the consumption of the command token.
* Now that we're working with functions, move all the `$` handling code into `functions/math.js`.  Somewhat bizarrely, we can define `$` as a function (nearly identical to `\(`) and it all works (just like we can have single-character macros).  This move removed a lot of messy stuff from `Parser.js`: `ParsedDollar`, `ParsedFuncOrArgOrDollar`, `newDollar`, `assertFuncOrArg`, and at least three explicit checks for `if (... === "$")`.
* Moved the `consume()` for the command token from `parseSymbol` to `parseGivenFunction`.  This ended up not being strictly necessary, but seems conceptually cleaner.
* Partially address #1027 by setting `consumeMode: "text"` for `\text` commands.  As a result, `\text` now instantly switches the mode to `"text"`, so even an unbraced macro argument will properly detect text mode.  I added a test for this, which is a slightly weaker form of #1027.
2018-03-14 10:54:36 -04:00
Ron Kok
65b47430b5 Support Unicode delimiters (#1207)
* Support Unicode delimiters

This PR adds support for the Unicode versions of \lfloor, \rfloor, \lceil, \rceil, \lgroup, \rgroup, \lmoustache, \rmoustache, \ulcorner, \urcorner, \llcorner, and \lrcorner.

All the mappings agree with `unicode math`

* Change tests from Parse to Build
2018-03-13 09:21:19 -03:00
Erik Demaine
0d3cf000d2 Add \yen support to text mode (#1208)
Fix #1204 by adding `\yen` support to text mode.

More generally, I checked all the text+mode symbols supported by
[amsfonts](http://mirrors.ctan.org/fonts/amsfonts/doc/amsfonts.pdf)
(see Section 6), and found that `\yen` is the only one lacking text-mode
support.
2018-03-13 02:22:04 +01:00
Ron Kok
b148d5da71 Support Unicode ° (#1203)
Oddly, `unicode-math-table.txt` does not contain an entry for U+00B0. But `\degree` is surely the correct mapping.
2018-03-10 13:19:13 -05:00
Erik Demaine
abfb641d7a Fix \nobreakspace, refactor "regular space" checking (#1200)
* Fix \nobreakspace, refactor "regular space" checking

Fix #1199 by adding \nobreakspace to the list of commands/symbols that
behave like a regular space character.  Refactor to put that list in one
place, and use an object so it checks instantly instead of sequentially.

* Copy test from #1201
2018-03-10 00:14:42 +01:00
Erik Demaine
aed1c1e564 unicodeTextInMathMode setting (#1117)
* unicodeTextInMathMode setting

* When `unicodeTextInMathMode` is `true`, accented letters from
  `unicodeSymbols.js`, and CJK and other supported languages,
  get added support in math mode (as requested in #895).
* When `unicodeTextInMathMode` is `false, all of these stop working in
  math mode, and are only supported in text mode (matching XeTeX behavior).
  Note that this is a backwards incompatibility with some 0.9.0 alpha/betas.

* Fix handling of Unicode characters ð, Å, å

* Fix double handling of ð (math maps to \eth, not special Unicode character)
* Remove Åå special math handling, thanks to #1125

* Forbid extraLatin when unicodeTextInMathMode is false
2018-02-19 21:25:20 -05: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
Erik Demaine
b341034d2b Add tests for __* internal interface (#1170)
Inspired by codecov
2018-02-19 10:39:16 -05:00
Ron Kok
d80be86015 Support Unicode colon equals (#1151)
* Support Unicode colon equals

This PR adds support for three Unicode characters: `≔` `≕` `⩴`

* Fix error in \Coloneqq
2018-02-09 07:58:23 -05:00
Ron Kok
73d80f595c Add \nobreakspace (#1145) 2018-02-05 21:17:36 -05:00
Ron Kok
ea3b6abe32 Enable spacing functions in text mode (#1139)
* Enable spacing functions in text mode

Spacing functions such as `\;` or `\quad` should be accepted in either math mode or text mode

* Add tests

* Fix tests

* Fix lint error
2018-02-04 13:58:04 -05:00
Kevin Barabash
603f12df8d add support for unicode angle brackets, single vertical bar, double vertical bar (#1123)
* add support for unicode angle brackets

* add tests, remove vertical bar changes

* fix 'message not a function' errors
2018-01-31 20:03:16 -05:00
Kevin Barabash
63f541b6e6 Use JS for spacing between atoms instead of CSS (#1070)
* Use JS for spacing between atoms instead of CSS

Summary:
This is the first step towards creating an intermediate representation
that can be used to generate HTML, SVG, and Canvas commands for rendering.
By generating spans that contain the width of the spaces instead of
relying on CSS sibling rules we'll be able to one day replaces the spans
with intermeidate 'Glue' nodes (in a later PR).

An added benefit of this approach is that is enables us to programmatically
change the values for thinspace, mediumspace, and thickspace which will
allow us to implement the \setlength command.

Test Plan:
- npm test
- dockers/Screenshotter/screenshotter.sh --verify

* fixed failures in BinCancellation, BoldSymbol, and OperatorName

* update screenshots

* don't use current size when determining size of spaces, update more screenshots

* fix spacing in SizingBaseline and StyleSwitching

* actually do the right thing for sizing groups

* fix \not for Chrome and Firefox

* do TODOs

* address feedback from the code review

* fix issue in delimsizing.js

* add TODO to think about a better solution in href.js

* fix typos, simplify href, be honest about paddingLeft for \not
2018-01-24 23:03:36 -05:00
Erik Demaine
a32f82a8ea Add support for \aa, \AA, \lq, \rq, \lbrack, \rbrack (#1069)
* Add support for \aa, \AA, \lq, \rq, \lbrack, \rbrack

The lack of \aa and \AA was reported in #1066.  Added these
via simple macros, with supporting tests.  Also add \lq, \rq,
\lbrack, \rbrack as aliases for "`", "'", "[", "]" which were
in the same area of latex.ltx.

* removed duplicate comment
2018-01-16 12:07:50 -05:00
Erik Demaine
484d44ee70 Unicode accents (#992)
* Unicode accents

* Lexer now looks for combining dicritical marks and adds them to the same character
* Parser's `parseSymbol` now recognizes both combined and uncombined forms of Unicode accents, and builds accent objects just like the accent functions
* Added CJK support to math mode (not just text mode)

* Add invalid combining character test

* Add MathML test

* Add weak support for other Latin-1 characters

This maintains backwards compatibility, but it uses the wrong font.
There's a TODO to fix this later.

Also refactor symbol code to use for..of

* Update Unicode screenshot

* Remove dot from accented i and j (in math mode)

Also add dotless Unicode characters to support some accented i's and j's

* Fix \imath, \jmath, \pounds, and more tests

* Switch from for..of to .split().forEach()

Save around 800 bytes in minified code

* Fix split

* normalize() detection

* Convert back to vanilla for loops

* Fix merge

* Move normalize dependency to unicodeMake.js

* Make unicodeSymbols into a lookup table instead of macros

This is important for multi-accented characters.

* Add comments about when to run

* Move symbols definition into unicodeMake/Symbols.js

* Remove CJK support in text mode

* Add missing semicolon

* Refactor unicodeAccents to its own file

* Dotless i/j support in text mode

* Remove excess character mappings

* Fix Åå in math mode (still via Times)

* Update to support #1030

* Add accented Greek letter support (for supported Greek symbols)

* Update screenshot

* remove Æ, æ, Ø, ø, and ß from math mode test
2017-12-28 23:32:45 -07:00
Kevin Barabash
7229f02d8f Implement correct macros for liminf and limsup, fixes #111 (#887)
* Implement correct macros for liminf and limsup, fixes #111

* fix nits
2017-12-26 17:11:10 -07:00
Kevin Barabash
522b238e20 add \ae, \AE, \oe, \OE, \o, \O, \ss with unicode support for those characters in text mode (#1030) 2017-12-22 12:42:43 -07:00
Kevin Barabash
2b2cf73f2e add \i and \j for text mode (#1029) 2017-12-22 13:57:31 -05:00
Erik Demaine
c30edaaf5b Implement \TextOrMath, \@secondoftwo (#1024)
* Implement \TextOrMath, \@secondoftwo

* Parser now tells MacroExpander about mode switching.  (This seems preferable
  to a circular reference between Parser and MacroExpander.)
* Implement \TextOrMath
* Improve when we switch modes so that this actually works,
  in all cases except single-symbol arguments.
* Add \@secondoftwo to match \@firstoftwo.
* Add comments documenting all the conditional macros

* Define type for switchMode

* Fix mode detection for ligatures

* Switch mode before the call to parseSymbol() in parseGroup

This fixes the Colorbox screenshot test.
2017-12-21 21:43:27 -07:00
Ryan Randall
50765a0ccd Stacking text commands (#1009)
* Adding support for SansSerif-Bold

* Updating to include SansSerif Italic.

* WIP

* Working text stacking

* More robust screenshot.

* Don't want to break users :)

* Updating per PR comments.

* Fixing Unicode and updating snapshots.

* Adding suggested tests.

* Opting to use old method for unit testing.

* Adding TODO
2017-12-13 09:10:23 -05:00
Ron Kok
46176c1d69 Support Unicode middle dot (#1015)
* Support Unicode middle dot

This PR adds support for Unicode characters U+00B7 MIDDLE DOT and U+22C5 DOT OPERATOR.

* Use escapes for tests. Edit macro comment.
2017-12-10 16:16:45 -05:00
Erik Demaine
7036eb85cd \kern fixes, \hskip support, \TeX, \LaTeX, \KaTeX (#974)
* Refactor \kern, proper \mkern support, add \hskip

* Move \kern, \mkern into functions directory
* Add \hskip, \mskip support (but without supporting plus/minus)
* Properly separate \kern, \hskip from \mkern, \mskip.
  (The former work in both modes, and don't support mu units.
  The latter work only in math mode and only support mu units.)

* Render \kern etc. using MathML <mspace>

* Implement \TeX macro

* Implement \LaTeX

* New KaTeX logo \katex

* Rename hskip.js -> kern.js

* Tweak katex \kern to 0.16em

* \katex kern -.17em

* Compute A raise height in \LaTeX and \katex

* Switch mu unit errors to warnings

* LaTeX screenshot test

* Replace \KaTeX with macro definition

* Update screenshots with \KaTeX in them

* Fix font selection for \*TeX macros
2017-11-27 14:40:38 -05:00
Ron Kok
0bde52f04f Support Unicode \mid (#993)
Map ∣, U+2223, to `\mid`
2017-11-26 18:32:01 -05:00
Ron Kok
dc0c3970c2 Support Unicode ∴ and ∵ (#991)
* Support Unicode ∴ and ∵

* Add comments
2017-11-25 20:00:58 -05:00
Erik Demaine
e93668c666 \hspace*, \@ifstar, \@ifnextchar, \@firstoftwo (#975)
* \hspace*, \@ifstar, \@ifnextchar, \@firstoftwo

* Support both \hspace and \hspace* (still aliasing to \kern)
  using new \@ifstar
* \@ifstar is a macro using new \@ifnextchar and \@firstoftwo
  (same definition as LaTeX)
* \@firstoftwo and \@ifnextchar use available MacroParser features
  to act as they do in LaTeX.
* Also new method pushTokens (which I almost used but didn't end up),
  and moved pushToken next to it and popToken.

* Fix flow errors; generalize MacroDefinition

* Add tests for macros
2017-11-24 14:48:04 -05:00
Ron Kok
a02859033a Support Unicode Symbols (#950)
* Support Unicode Symbols

This is the third in a series of PRs to give KaTeX the ability to recognize Unicode character input. This one supports some but not all letter-like symbols and some other symbols. All the characters in this PR will produce `textord` atoms in `math` mode.

The list is not comprehensive. It’s a bit eclectic. Some of these characters are important. Others were just easy to include. A few important characters are omitted because it wasn’t clear to me which is the best way to implement them. I’ll address those characters in future PRs.

* Add comments. Remove RegEx.

* Fix omitted parens
2017-11-24 14:19:22 -05:00
Erik Demaine
ecad4de4ce Single-character macros like active characters (#973)
* Single-character macros like active characters

* Rewrite README according to @kevinbarabash's comment
2017-11-24 13:40:23 -05:00
Hiromi Ishii
fd82c4fad0 Implemented `\href' command (#923)
* Implements `\href' command.

* Added `functions/href.js`.
* Added `domTree.anchor` and `buildCommon.makeAnchor` functions.
* Make `buildHTML.getTypeOfDomTree` exported.

* Reflects the code reviews

* Create new argType "url" to treat link string in math appropriately
* Stop using too shorten variable names
* Start using template strings

* Adopts template literal

* Elaborates on glueing

* If-clause restructuring

* Solved confusing explanation

* Allow balanced braces in url

* Adds unit-test for \href

* Adds snapshot tests
2017-11-23 23:23:35 -05:00
Ron Kok
69aff05024 Support Unicode Big Operators (#961)
* Support Unicode Big Operators

This is the sixth in a series of PRs to give KaTeX the ability to recognize Unicode character input.

This is the final PR in this series that will submit characters in bulk. After this, there come some characters whose alias or atom type was not obvious. I'll turn in PRs for them, too, but only after they are vetted.

* Move constants outside of main functions

* Replace ∫ with \u222b

* Add backslash
2017-11-22 20:48:33 -05:00
Ron Kok
1f8a4f0490 Support Unicode Arrows (#947)
* Support Unicode Arrows

This is the second in a series of PRs to give KaTeX the ability to recognize Unicode character input.

All the characters in this PR will produce `rel` atoms.
2017-11-22 10:11:29 -05:00
Ron Kok
6325685a9f Support Unicode Negated Relations (#952)
* Support Unicode Negated Relations

This is the fifth in a series of PRs to give KaTeX the ability to recognize Unicode character input.

All the characters in this PR will produce `rel` atoms.

* Add parse tests

* Fix AMS functions

Fix a brain cramp.

* Add internal aliases to code comments
2017-11-22 08:37:53 -05:00
Hiromi Ishii
6f1661f7da Implements \mathchoice command (#969)
This PR implements `\mathchoice` function.
I once created PR on the wrong branch. Sorry for the mess.

This is particularly useful when one defines custom macro for "big operators".
For example:

```latex
\newcommand{\infdisj}{%
  \mathop{%
    \mathchoice{% display
      \bigvee\hspace{-2ex}\bigvee%
    }{          % inline
      \bigvee\hspace{-1.75ex}\bigvee%
    }{          % script
      \bigvee\hspace{-1.4ex}\bigvee%
    }{          % scriptscript
      \bigvee\hspace{-1ex}\bigvee%
}}}
```
2017-11-22 07:34:05 -05:00
Ron Kok
2d32263998 Support Unicode Binary Operators (#951)
This is the fourth in a series of PRs to give KaTeX the ability to recognize Unicode character input.

All the characters in this PR will produce `bin` atoms.
2017-11-21 12:20:56 -05:00
Ron Kok
839f872faa Fix linefeed test (#964)
I must have been asleep when I wrote the tests for PR#949.
2017-11-12 20:34:22 -05:00
Ron Kok
3e344535ff Fix #946 (#949)
* Fix #946

Issue #946 identified a case in which `array.js` ate the final row of a well-written `aligned` environment.

This PR modifies code from PR #479 to fix this problem and to also continue to eat a trailing `\\` submitted to any environment.

* Fix bug and add tests

* Add final newline to test.

Doh!
2017-11-11 19:12:13 -05:00
Ron Kok
bd4e1464a0 Support Unicode relations (#933)
* Support Unicode relations

This is the first in a series of PRs to give KaTeX the ability to recognize Unicode character input. The code in this PR follows the style of PR #410.
All the characters in this PR will produce rel atoms. I’ll submit PRs for other atom types later.

* Fix lint error.

* Correct mapping errors

This commit fixes a brain cramp of mine.
2017-10-17 09:06:41 -04:00
Erik Demaine
3280652bd6 Fix space handling (#912)
Fixes several issues with space handling: (fix #910)
1. "Control symbols" (as they're called in the TeXbook), such as `\\`, should
   not have spaces eaten after them (only "control words" such as `\foo`).
2. In math mode, spaces should be consumed at the parser level, not the
   gullet level.  This enables `\\ [x]` to parse differently from `\\[x]`
3. Eat spaces between arguments, so `\frac x y` still works.
   (This used to work only because math mode ate all spaces.
    The analog in text mode wouldn't have worked.)

Also eat spaces in initial arguments in math mode, and before ^ and _ in atoms.
2017-10-10 10:09:37 -04: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
Kevin Barabash
eaef0127c5 Add support for comments, fixes #20 (#884) 2017-09-25 21:50:27 -06:00