LaTeX macro expander
If you just want to see how LaTeX works, and what it does when macros are expanded, you can put \tracingmacros
or \tracingall
in your .tex file, and LaTeX will write the expansion process in the log file.
Solution for me was http://ctan.org/pkg/de-macro, it is included with TeX Live, then if you are using a Debian based linux distribution it is likely you already have it
what you have to do is:
- place your definitions in a file called something like
something-private.sty
, in the same directory your original fileyourfile.tex
is located - comment or remove your definitions in
yourfile.tex
- place a command
\usepackage{something-private}
inyourfile.tex
- open a shell, and go to the directory where
yourfile.tex
is located - in the shell execute
de-macro yourfile.tex
a yourfile-clean.tex
will be created with the desired macros expanded, if you need to change something in your definitions then remove the *-clean.tex
files and run de-macro
again.
I'm not aware of a package to do this, but I'd love to have one. The cleveref
package has an option along these lines:
When the poorman option is supplied, your document will be processed as normal. But in addition, a
sed
script will automatically be written, containing rules for replacing all the\cref
commands with the LaTeX code that they would produce, and using the standard\ref
command to produce the cross-references themselves.
In the package I imagine for LaTeX, you'd have a command such as \newmacro
that behaved along the same lines, which would behave like \newcommand
except the author would ensure that only "sane" expansions would occur. It could then write an auxiliary file that uses a Lua script to generate a copy of the document with all the macros replaced by their definitions.
So, er, anyone willing to write it?