Commit Graph

10 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
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
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
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
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
Ashish Myles
c47655cc0e Correct @flow types. Refactor some Parser code for stricter typing. (#896)
* Correct @flow types in defineFunction and types.

* Parser: Split parseFunction into two for stricter typing.
2017-09-20 23:33:49 -04:00
Ashish Myles
d8060ca9b4 Port functions.js to @flow. (#867)
* Make types in defineFunction stricter and prep for porting functions.js to flow.

* Add more explicit types to functions/delimsizing.js.

* Port functions.js to @flow.
2017-09-10 21:25:36 -04:00
Ashish Myles
1c344ed6ee Port environments.js to @flow. (#862)
* Port environment.js to @flow.

* Updated per comments.
2017-09-09 20:31:32 -04:00
Ashish Myles
b4a00824d3 @flow: Correct argType to Array in defineFunction. (#860) 2017-09-09 18:09:02 -04:00
Ashish Myles
9e330194b8 Port symbol.js to @flow. (#858)
* Port symbol.js to @flow.

* Add a `Mode` @flow type and use it in `ParseNode`.
2017-09-09 17:54:47 -04:00