# Get fully expanded tex file [duplicate]

I'm using TexLive 2016. Is there a way I can get the expanded Latex BEFORE it is converted to PDF? Quick example in case I'm asking the wrong question! i.e.

main.tex:

\documentclass[12pt]{article}
\begin{document}
\section{Some Notes}
\input{"testinput.tex"}
\subsection*{Mood}
Some sub section
\end{document}


testinput.tex:

\section{Include Stuff}
Did this get included?


Should give:

\documentclass[12pt]{article}
\begin{document}
\section{Some Notes}
\section{Include Stuff}
Did this get included?
\subsection*{Mood}
Some sub section
\end{document}


We have some fairly complex nested files so I'm hoping there's a solution to that. I imagine that Latex MUST "assemble" the document before it can be processed?

Thanks!

• I am sorry your imagination does match reality. TeX never generates an expanded document (and in general there is no such expansion possible) – David Carlisle Aug 8 '17 at 10:02
• Hope this was not possible in TeX itself, it may get done by using external tools like Perl, Python, etc... – MadyYuvi Aug 8 '17 at 10:06
• Thanks David - would you have any suggestions on workarounds? When you say it's "not possible" is that as big a "no" as it sounds? :-) i.e. is it not conceptually feasible to view a nested Latex document with the inclusions "inline". Fully prepared to accept this if so but it does seem a bit strange! Amongst other things, I'd like to run a "Flesch readability score" over a Latex doc, which would seem to require having all readable text in one place. Is that simply not an option? – Bill Jones Aug 8 '17 at 10:09
• Thanks Henri! There's are two VERY useful comments on that answer that led to a python library and also the fact that "latexpand" is included in TexLive and does exactly what I need! – Bill Jones Aug 8 '17 at 10:51