mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 19:28:39 +00:00
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.
This commit is contained in:
@@ -23,4 +23,5 @@ export type ArgType = "color" | "size" | "url" | "original" | Mode;
|
||||
// LaTeX display style.
|
||||
export type StyleStr = "text" | "display";
|
||||
|
||||
export type BreakToken = "]" | "}" | "$";
|
||||
// Allowable token text for "break" arguments in parser
|
||||
export type BreakToken = "]" | "}" | "$" | "\\)";
|
||||
|
Reference in New Issue
Block a user