Are there a preprocessor for TeX, like for C/C++?

Are there a way to apply a macro to .tex file in order to generate new file? For example, I have macro:

\renewcommand{asd}{some phrase here}

I have a .tex file:

bla-bla \asd bla-bla

I would like to get a new .tex file where all macros are replaced, and it will have this contents:

bla-bla some phrase here bla-bla
  • For a simple case, just use search and replace in your editor, or use sed. The only thing that can deal with every possibility is TeX itself. – Ian Thompson Sep 2 '14 at 9:58
  • Sorry, I can't, I've got a lot of files with complex macros... :( – Dennis Yurichev Sep 2 '14 at 10:01
  • 5
    This seems very similar to LaTeX macro expander – egreg Sep 2 '14 at 10:18
  • i write the uk faq code in latex, and generate html on-line for whatever answer: just what you need. however, the latex i write is highly stylised, and is full of annotations saying "don't let this line get too long" and the like. there's some slick stuff in there, but i wouldn't want to be writing that sort of code for anything for which there was a timescale. in my opinion, my situation (developed and improved since 1994) is analagous to yours. you can make a transcript only if you wrote your latex with transcription in mind. – wasteofspace Sep 2 '14 at 16:27

This answer is based on a similar SO question.

You can actually use the C preprocessor if you like:

$ cat <<EOF | cpp -P | pdflatex
#define NAME Sean Allred

Hello, NAME.

All of the features of the C preprocessor are available for use :-)

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.