3

for some improvement of reledmac/reledpar (https://github.com/maieul/ledmac/issues/668), I need to gobble any argument of a macro before using it in a \edef. But I get an error.

See this MWE

\documentclass{book}

\usepackage{imakeidx}
\makeindex[name=toto,title=toto]
\makeindex
\begin{document}


s\renewcommand{\index}[1]{}
\edef\titi{\index{sncf}a}%That works

s\renewcommand{\index}[2][]{}
\edef\titi{\index[a]{sncf}a}%That does not work


\end{document}
  • When a command is defined to have an optional argument, it doesn't survive \edef. With xparse you may be able to go with \RenewExpandableDocumentCommand{\index}{om}{}. – egreg Aug 4 '17 at 11:20
3

Macros with optional arguments don't survive \edef, unless they are defined with xparse’s \NewExpandableDocumentCommand (with some limitations).

\documentclass{book}
\usepackage{xparse}
\usepackage{imakeidx}
\makeindex[name=toto,title=toto]
\makeindex
\begin{document}


s\renewcommand{\index}[1]{}
\edef\titi{\index{sncf}a}%That works
\titi

s\RenewExpandableDocumentCommand{\index}{om}{}
\edef\titi{\index[a]{sncf}a}%This works, too
\titi

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.