# Expand all \newcommand without doing anything else in LaTeX? [duplicate]

Can I expand all \newcommands without doing anything else in LaTeX?

Edited: My true goal is standardizing math papers in plain text so that theorems and definitions can be accurately and easily extracted without losing mathematical symbols.

## marked as duplicate by Werner macros StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Nov 19 '18 at 21:43

• No (maybe there exists an external program to preprocess your LaTeX file) – Henri Menke Nov 19 '18 at 21:02
• @HenriMenke Yeah I think I will just write one. It shouldn't be hard. It's pretty much just putting all new commands into a python dictionary and recursively substituting them to the point that they are all gone. – Ying Zhou Nov 19 '18 at 21:04

There are several existing programs that do this in limited contexts for example

https://ctan.org/tex-archive/support/de-macro

However it is in general not possible to expand all macros without a full tex execution.

Consider

\newcommand\foo{\ifx\zzz\undefined no\else yes\fi}


which expands to no or yes depending on the state of TeX at that time or

\newcommand\foo{\sbox0{hello}\ifdim\wd0>2cm yes\else no\fi}


which expands to no or yes depending on the width of some text set in the current font.

In simple cases the document will behave the same way if you expand the macros but for example if you expand \zzz (and remove its definition) then the expansion of \foo will change.

If however you are restricting to expanding out simple shortcut macros used for authoring convenience, which contain no conditional or recursive calls then simple string replacement in any text processing tool will probably do the right thing, on a good day.

• @UlrichDiez I managed to avoid including a copy of xii.tex` in this answer, don't tempt me:-) – David Carlisle Nov 20 '18 at 10:45
• I like your xii.tex. It reminds me of Michael Downes' Around the Bend questions 10 and 11 (Obfuscated TeX code / Decoding obfuscated TeX code). – Ulrich Diez Nov 20 '18 at 11:00