I have a bunch of latex files witch use the \input{filename.tex}
macro (it works like an #include
from C), and I want to resolve them so I can output all of them to a single .tex file (the file must be pasted at the place of the \input{}
macro, it is safe to assume that each file is referenced only once).
Example:
tesis.tex:
My thesis.
\input{chapter1.tex}
More things
\input{chapter2.tex}
chapter1.tex:
Chapter 1 content.
chapter2.tex:
Chapter 2 content.
\include{section2-2.tex}
section2-2.tex:
Section 1.
The desired result should be:
My thesis.
Chapter 1 content.
More things
Chapter 2 content.
Section 1.
If there was only a \input{foo.tex}
level I would be able to solve this with this AWK program:
/\\input\{.*\}/{
sub(/^[^{]*{/,"",$0)
sub(/}[^}]*$/,"",$0)
system("cat " $0)
next
}
{
print $0
}
Is there any way to read files recursively in AWK?
(I am open to do it with any other language, but the posixest the better)
Thanks!