mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-11 22:18:41 +00:00
Add support for \expandafter, \noexpand, \edef, \let, and \long (#2122)
* Add support for \expandafter * Add support for \noexpand * Add support for \edef * Update comments * Allow \long before macro definition * Update documentation * Update comments * Fix defPrefix * Add support for \let * Update documentation * Print error token * Update documentation * Check whether command is expandable * Add tests * Fix token order * Make noexpand a Token property * Throw error if control sequence is undefined when expanding * Rename expandableOnly to expandOnly * Make unexpandable macro property * Move \expandafter to macros.js * Add TODO * Fix merge conflict * Update a test case * Remove unused functions in MacroContextInterface * Update comments * Refactor code * Move \noexpand to macros * Update MacroExpander.js * Add a test case * Separate control sequence check to a function * Add support for \futurelet * Separate RHS getter to a function * Update documentation * Move expandOnly logic to expandOnce * Refactor code and update comments Co-authored-by: Kevin Barabash <kevinb@khanacademy.org>
This commit is contained in:
@@ -297,6 +297,10 @@ Direct Input: $∀ ∴ ∁ ∵ ∃ ∣ ∈ ∉ ∋ ⊂ ⊃ ∧ ∨ ↦ → ←
|
||||
|:-------------------------------------|:------
|
||||
|$\def\foo{x^2} \foo + \foo$ | `\def\foo{x^2} \foo + \foo`
|
||||
|$\gdef\bar#1{#1^2} \bar{y} + \bar{y}$ | `\gdef\bar#1{#1^2} \bar{y} + \bar{y}`
|
||||
| | `\edef\macroname#1#2…{definition to be expanded}`
|
||||
| | `\xdef\macroname#1#2…{definition to be expanded}`
|
||||
| | `\let\foo=\bar`
|
||||
| | `\futurelet\foo\bar x`
|
||||
| | `\global\def\macroname#1#2…{definition}`
|
||||
| | `\newcommand\macroname[numargs]{definition}`
|
||||
| | `\renewcommand\macroname[numargs]{definition}`
|
||||
@@ -306,11 +310,13 @@ Macros can also be defined in the KaTeX [rendering options](options.md).
|
||||
|
||||
Macros accept up to nine arguments: #1, #2, etc.
|
||||
|
||||
`\gdef` and `\global\def` macros will persist between math expressions.
|
||||
`\gdef`, `\xdef`, `\global\def`, `\global\edef`, `\global\let`, and `\global\futurelet` will persist between math expressions.
|
||||
|
||||
KaTeX has no `\par`, so all macros are long by default and `\long` will be ignored.
|
||||
|
||||
Available functions include:
|
||||
|
||||
`\char` `\mathchoice` `\TextOrMath` `\@ifstar` `\@ifnextchar` `\@firstoftwo` `\@secondoftwo` `\relax`
|
||||
`\char` `\mathchoice` `\TextOrMath` `\@ifstar` `\@ifnextchar` `\@firstoftwo` `\@secondoftwo` `\relax` `\expandafter` `\noexpand`
|
||||
|
||||
@ is a valid character for commands, as if `\makeatletter` were in effect.
|
||||
|
||||
|
Reference in New Issue
Block a user