LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Merging files together based on latex syntax. (https://www.linuxquestions.org/questions/linux-software-2/merging-files-together-based-on-latex-syntax-793143/)

batonac 03-04-2010 07:35 AM

Merging files together based on latex syntax.
 
I have a latex code file which links itself to many other latex files. The syntax is as follows:

\input{*path of file to be inputed*}

The path is relative to the current working directory, so if my file is stored in /home/kevin/mybook.tex and I want to include a file in /home/kevin/latexstuff/copyleft.tex I simply write:

\input{latexstuff/copyleft.tex}

The latex compiler includes these files just as if they had been copied and pasted into the main latex file at the point specified. My problem is that I have a document which depends on quite a bit of these \input commands, but I am trying to use a latex preprocessor (ratexdb, adds database fields to your latex documents) which does not support \input commands, leaving my file only half processed.

So I was wondering: is there any easy way to parse through my main file, detect only the \input commands, interpret the syntax and include the files specified (where specified), and produce a second, populated file, which can then be processed by ratexdb?

I've seen amazing things done with makefiles, bash scripts, grep, cat, perl, etc., but I'm not quite sure how to use these tools to solve my problem.

amani 03-05-2010 07:46 AM

Post your problem in the texlive mailing list.

batonac 03-05-2010 08:15 AM

Quote:

Originally Posted by amani (Post 3886894)
Post your problem in the texlive mailing list.

I actually was able to work out a solution with another Latex user. He helped me write the following script which solves my problem completely:

Code:

#! /bin/sh

awk '!/input\{/ {print}
/input\{/ {
sub (/input\{/,"")
sub (/\}.*/,"")
cmd= "cat ./"$1""
system(cmd)
}' inputfile.tex > mergedfile.tex



All times are GMT -5. The time now is 11:08 PM.