CTAN Comprehensive TeX Archive Network

Directory macros/generic/multiexpand


Variations on the \expandafter primitive

The package defines \multiexpand, \multiexpandafter, \MultiExpand and \MultiExpandAfter, replacing large chains of \expandafter. These four commands take as an argument the number of expansion to be done. If e is available, this number is evaluated using \numexpr.

Say we want to expand \C five times before \A and \B in \A\B\C. The traditional approach would be to insert 31 \expandafter before \A and the same number before \B. With this package one can use any of


In one step of expansion (triggered by the \expandafter's), \romannumeral\multiexpand{5} expands the following token 5 times, whereas \romannumeral\multiexpandafter{5} expands the token after that 5 times. The macros \MultiExpandAfter and \MultiExpand take two steps of expansion, but do not require \romannumeral. Another example is that in two steps of expansion,


expands \d 10 times, then \c 7 times (9-2), then \b once (3-2).

The package can be built from the file multiexpand.dtx' by running pdflatex multiexpand.dtx pdflatex multiexpand.dtx

Download the contents of this package in one zip archive (372.1k).

multiexpand – Variations on the primitive command \expandafter

The package provides two user commands; one that performs multiple expansions, and one that does multiple \expandafter operations, in a single macro call.

The author suggests that the same effect could be provided by use of the command variant mechanisms of 3 (see, for example, the interface documentation of the experimental 3 kernel).

Bug trackerhttps://github.com/blefloch/latex-multiexpand/issues
Version1.5 2017-11-29
LicensesThe Project Public License 1.3c
Copyright2011–2017 Bruno Le Floch
MaintainerBruno Le Floch
Contained inTeX Live as multiexpand
MiKTeX as multiexpand
TopicsMacro support
Guest Book Sitemap Contact Contact Author