# Preprocess a .tex file and save it as a new file

I have several `.tex` files that I would like to share with other people. I've included in them (with the command `\input`) several files with macros that I've written myself. However, I would like to send only a self-contained `.tex` file.

What I need to do is generating another `.tex` file where the `\input` command is replaced with the content of the file, pretty much like you would do by calling just the preprocessor in C.

I guess this could be done (relatively) easily with a bit of scripting, but I would like to know if there were a builtin option in a LaTeX compiler.

• no (there are existing answers on site about this) latex never holds the source in memory or constructs the combined file. – David Carlisle Mar 9 '19 at 10:40
• @DavidCarlisle so you're saying that I have to do it by myself? – Mauro F. Mar 9 '19 at 10:41
• I'm saying latex won't do it, but there are lots of tools that do (or claim to do) this for you. (it is trivial to write a few lines of perl to do this on any normal document, writing a general tool that gets it right on any document and copes with the string `\input` in verbatim or comments etc is trickier but usually not needed) – David Carlisle Mar 9 '19 at 10:44