GeneralLaTeX preprocessor (combining input files)

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
batonac
Posts: 12
Joined: Fri Feb 26, 2010 5:41 pm

LaTeX preprocessor (combining input files)

Post by batonac »

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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

LaTeX preprocessor (combining input files)

Post by kaiserkarl13 »

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
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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.
batonac
Posts: 12
Joined: Fri Feb 26, 2010 5:41 pm

LaTeX preprocessor (combining input files)

Post by batonac »

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
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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.

The code I ended up using looks like this:
#! /bin/sh

awk '!/input\{/ {print}
/input\{/ {
sub (/input\{/,"")
sub (/\}.*/,"")
cmd= "cat ./"$1""
system(cmd)
}' ShrockFab\ Catalog.tex > Shrockfab\ Catalog-merged.tex
Note noobs (Like I once was):
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
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Post Reply