Readonly
atOptional
Readonly
computeThe index of the current token
Readonly
optionsReadonly
peekReturn the next token, without advancing the index
Boundaries are used to detect the end of an expression.
They are used for unusual syntactic constructs, for example
\int \sin x dx
where the dx
is not an argument to the \sin
function, but a boundary of the integral.
They are also useful when handling syntax errors and recovery.
For example, \begin{bmatrix} 1 & 2 { \end{bmatrix}
has an
extraneous {
, but the parser will attempt to recover and continue
parsing when it encounters the \end{bmatrix}
boundary.
Return true if the terminator condition is met or if the last token has been reached.
Return an error expression with the specified code and arguments
Parse an argument list, for example: (12, x+1)
or \left(x\right)
()
, or just a primary
(i.e. we interpret \cos x + 1
as \cos(x) + 1
)Return an array of expressions, one for each argument, or null
if no
argument was found.
Optional
kind: "implicit" | "enclosure"Optional
until: TerminatorParse an expression:
<expression> ::=
| <primary> ( <infix-op> <expression> )?
| <prefix-op> <expression>
<primary> :=
(<number> | <symbol> | <function-call> | <matchfix-expr>)
(<subsup> | <postfix-operator>)*
<matchfix-expr> :=
<matchfix-op-open> <expression> <matchfix-op-close>
<function-call> ::=
| <function><matchfix-op-group-open><expression>[',' <expression>]<matchfix-op-group-close>
This is the top-level parsing entry point.
Stop when an operator of precedence less than until.minPrec
or the sequence of tokens until.tokens
is encountered
until
is { minPrec:0 }
by default.
Optional
until: Partial<Terminator>Parse an expression in aLaTeX group enclosed in curly brackets {}
.
These are often used as arguments to LaTeX commands, for example
\frac{1}{2}
.
Return null
if none was found
Return ['Sequence']
if an empty group {}
was found
Parse an expression enclosed in a LaTeX optional group enclosed in square brackets []
.
Return null
if none was found.
Parse a postfix operator, such as '
or !
.
Prefix, infix and matchfix operators are handled by parseExpression()
Optional
until: Partial<Terminator>Some LaTeX commands have arguments that are not interpreted as
expressions, but as strings. For example, \begin{array}{ccc}
(both
array
and ccc
are strings), \color{red}
or \operatorname{lim sup}
.
If the next token is the start of a group ({
), return the content
of the group as a string. This may include white space, and it may need
to be trimmed at the start and end of the string.
LaTeX commands are typically not allowed inside a string group (for example,
\alpha
would result in an error), but we do not enforce this.
If optional
is true, this should be an optional group in square brackets
otherwise it is a regular group in braces.
Optional
optional: booleanA symbol can be:
x
\pi
\operatorname{speed}
Optional
until: Partial<Terminator>Parse an expression in a tabular format, where rows are separated by \\
and columns by &
.
Return rows of sparse columns: empty rows are indicated with Nothing
,
and empty cells are also indicated with Nothing
.
Some LaTeX commands (but not all) can accept arguments as single
tokens (i.e. without braces), for example ^2
, \sqrt3
or \frac12
This argument will usually be a single token, but can be a sequence of
tokens (e.g. \sqrt\frac12
or \sqrt\operatorname{speed}
).
The following tokens are excluded from consideration in order to fail
early when encountering a likely syntax error, for example x^(2)
instead of x^{2}
. With (
in the list of excluded tokens, the
match will fail and the error can be recovered.
The excluded tokens include !"#$%&(),/;:?@[]
|~", \left
, \bigl
, etc...
True if the last token has been reached. Consider also
atTerminator()
.