Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro default argument support #24

Open
theseanl opened this issue Dec 28, 2022 · 1 comment · May be fixed by #62
Open

Macro default argument support #24

theseanl opened this issue Dec 28, 2022 · 1 comment · May be fixed by #62

Comments

@theseanl
Copy link
Contributor

theseanl commented Dec 28, 2022

I'm trying to write some custom plugins for transforming latex, and so far, I really liked your work, especially in how you provide every required toolsets via modular package structure.
While experimenting with it, I noticed that currently there's no support for macros with default arguments.

% input.tex
\documentclass{article}
% \newcommand\foo[2][bar]{#1,#2}
\begin{document}
    \foo[bar]{baz}
    \foo{baz}
\end{document}
unified-latex input.tex -e "\\newcommand\\foo[2][bar]{#1,#2}"

Then the result will be

\documentclass{article}

%\newcommand\foo[2][bar]{#1,#2}

\begin{document}
        bar,baz

        ,baz
\end{document}

where the expected output would have two identical lines of bar,baz.

In unified-latex-util-macros, an xpase-style signature is computed, but it produces o irrespective of the presence of a default argument. I've also noticed that manually passing O{bar} m via \NewDocumentCommand still produces unexpected results, so there should be another issue regarding macro expanders.

It'd be nice if this support can be added. I'm wondering to know if there's any blocker for implementing it, I'm interested in sending a PR.

@siefkenj
Copy link
Owner

That would be a welcome PR :-).

It looks like, after you figure out how to grab the default arg when parsing the macro string, a little modification to

export function createMacroExpander(

should be most of what is needed.

Please include some tests with your PR :-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants