siefkenj / unified-latex

Utilities for parsing and manipulating LaTeX ASTs with the Unified.js framework
MIT License
85 stars 20 forks source link

Default Arguments #83

Closed siefkenj closed 6 months ago

siefkenj commented 6 months ago

This PR adds some of the functionality from #62 but with a slightly different approach.

Default arguments are now stored on argument nodes if an argument is not provided. a defaultArg is always a string.

Since a default argument may contain LaTeX code, it will need to be parsed again before inserting into an expanded macro. For example \NewDocumentCommand{\xxx}{E{^}{{\color{red}x}}}{#1} would store the string "\color{red}x as the default argument. A call to parse would be needed in expandMacros

siefkenj commented 6 months ago

@theseanl I have incorporated some functionality from #62 . Let me know if you want to rework the macro expansion in #82 to be based off of this work.

theseanl commented 6 months ago

In #62, where default argument support is already completely implemented, adding default arguments to AST as done in this PR is not even needed. expandMacros have all the information needed to expand default arguments, so what this PR does (adding default arguments to renderInfo) is useless. You would be better off working on improving #62. I am open to more reviews.

siefkenj commented 6 months ago

I see you kept the default arg information just for expansion :-).

I like the argspec grammar in this PR better. I will reimplement the macro expansion on top of this PR. The other parts of #62 are the improvements to gobbleSingleArgument. We can revisit those after expansion is done.