I'm currently working on an experiment that involves re-typesetting a digitized physical book from OCRed images. For various reasons involving the workflow, the resulting project architecture is a "backbone" LaTeX document containing a series of \input{page0000.tex}
lines, one for each page image of the original book.
It seems like it should be trivial, but I must not have stumbled on the correct keywords: I'd like to be able to generate a single, monolithic LaTeX file, where the \input{}
code has been replaced by the file contents—but not replacing the \include
d files. In other words: something to stitch together the pages into a single run-on LaTeX file.
I could do it rather simply in Ruby, but I just have to think there's a pure TeX (cli?) solution.
Best Answer
I'd use
cat
. But since you asked for a TeX implementation, here you go.You need to use e-TeX (pdfTeX would work) to run this. It will ask you for the name of the master file and for the name of the output file:
Here, I entered
base
andoutput
to the queries and it readbase.tex
and producedoutput.tex
.It isn't perfect. Spaces after
\input{foo}
are lost, but you can replace\input{foo} bar
with\input{foo}{} bar
to keep them. Also, it assumes that%
is always a comment, at least on\input
lines.Here's my one test example.
a.tex
throughe.tex
consist of a single letter, A through E, respectively. Here's the output.Note that
\input
replacement is not recursive, although it probably could be, at least up to depth 14 (which would hit the maximum number of TeX input streams—unless e-TeX supports more).Finally, this is totally ridiculous. Don't use it. Use something meant for dealing with files instead.