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}
1
  • 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
    Commented Aug 4, 2017 at 11:20

1 Answer 1

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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .