General ⇒ LaTeX preprocessor (combining input files)
LaTeX preprocessor (combining input files)
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
LaTeX preprocessor (combining input files)
Code: Select all
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
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