General ⇒ LaTeX preprocessor (combining input files)
LaTeX preprocessor (combining input files)
Does anyone know of a way to process only the \input command of a LaTeX file so that a multi-file document is joined into one (big) LaTeX file? I need to do this in order to use a database preprocessor (ratexdb) which doesn't support the \input command.
-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
LaTeX preprocessor (combining input files)
If you have GNU-AWK on your system, the following command will do what you desire, provided all \input commands are on a line by themselves:
You could write a more sophisticated AWK script that similarly processes files without the restriction of having the \input lines as the only thing on the line. This quick-and-dirty version is what I came up with in two minutes.
Code: Select all
Code, edit and compile here:
awk '!/input\{/ {print}/input\{/ {sub (/input\{/,"")sub (/\}.*/,"")cmd= "cat "$1".tex"system(cmd)}' input-unmerged.tex > input-merged.tex
LaTeX preprocessor (combining input files)
Wow thanks man! You saved me! This code is absolutely awesome! It will have to be slightly modified from project to project, but that's a small price to pay for this functionality.kaiserkarl13 wrote:If you have GNU-AWK on your system, the following command will do what you desire, provided all \input commands are on a line by themselves:
Code: Select all
Code, edit and compile here:awk '!/input\{/ {print}/input\{/ {sub (/input\{/,"")sub (/\}.*/,"")cmd= "cat "$1".tex"system(cmd)}' input-unmerged.tex > input-merged.tex
The code I ended up using looks like this:
Note noobs (Like I once was):#! /bin/sh
awk '!/input\{/ {print}
/input\{/ {
sub (/input\{/,"")
sub (/\}.*/,"")
cmd= "cat ./"$1""
system(cmd)
}' ShrockFab\ Catalog.tex > Shrockfab\ Catalog-merged.tex
I just put it in a text file, saved is as "preprocessor", made the file executable (chmod +x preprocessor), and then run it in the same directory as my latex files. The script will probably only work on Linux/unix unless you have cygwin installed on Windows. To make it work for your project, simply replace "ShrockFab\ Catalog" with your own file name. ("My\ File" if it contains a space, otherwise "MyFile")
To run it, simply go to the working directory in the linux terminal and type:
Code: Select all
./preprocessor