feat(macro): improve argument parsing (#2085)

* Improve macro argument parsing

* Make \above a primitive command

* Fix screenshotter data

* Normalize argument where necessary

* Improve argument location info

* Update comments

* Minor refactor

* Modularize group parsers

* Allow braced and blank size argument

for non-strict mode and \genfrac, respectively.

* Minor refactor & update comments

* Remove raw option in parseStringGroup

* Update tests

* Fix { delimited parameter

* Update tests

* Update tests

* Normalize argument in \genfrac

* Update tests

* Consume space before scanning an optional argument

* Fix \\, \newline, and \cr behavior

* Fix flow error

* Update comments

* Remove unnecessary mode switching

Parser mode affects neither fetch nor consume.

* Allow single (active) character macro

* Add function property `primitive`

* Set \mathchoice and \*style primitive

* Separate size-related improvements out to #2139

* Fix flow error

* Update screenshots

* Update demo example

* Add a migration guide

* Fix capitalization

* Make a primitive function unexpandable

* Update screenshots

* Update screenshots

* Revert "Document \def doesn't support delimiters (#2288) (#2289)"

This reverts commit f96fba6f7f.

* Update comments, errors, and tests

* Update screenshots
This commit is contained in:
ylemkimon
2020-09-06 12:56:13 +09:00
committed by GitHub
parent 8578d74f82
commit dc5f97aaa2
35 changed files with 432 additions and 348 deletions

View File

@@ -83,6 +83,9 @@ export type FunctionPropSpec = {
// Must be true if the function is an infix operator.
infix?: boolean,
// Whether or not the function is a TeX primitive.
primitive?: boolean,
};
type FunctionDefSpec<NODETYPE: NodeType> = {|
@@ -128,6 +131,7 @@ export type FunctionSpec<NODETYPE: NodeType> = {|
allowedInMath: boolean,
numOptionalArgs: number,
infix: boolean,
primitive: boolean,
// FLOW TYPE NOTES: Doing either one of the following two
//
@@ -186,6 +190,7 @@ export default function defineFunction<NODETYPE: NodeType>({
: props.allowedInMath,
numOptionalArgs: props.numOptionalArgs || 0,
infix: !!props.infix,
primitive: !!props.primitive,
handler: handler,
};
for (let i = 0; i < names.length; ++i) {
@@ -223,6 +228,10 @@ export function defineFunctionBuilders<NODETYPE: NodeType>({
});
}
export const normalizeArgument = function(arg: AnyParseNode): AnyParseNode {
return arg.type === "ordgroup" && arg.body.length === 1 ? arg.body[0] : arg;
};
// Since the corresponding buildHTML/buildMathML function expects a
// list of elements, we normalize for different kinds of arguments
export const ordargument = function(arg: AnyParseNode): AnyParseNode[] {