Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org [SOLVED] Merging files together based on latex syntax.
 Linux - Software This forum is for Software issues. Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

 03-04-2010, 07:35 AM #1 batonac LQ Newbie   Registered: Feb 2010 Posts: 5 Rep: 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.
 03-05-2010, 07:46 AM #2 amani Senior Member   Registered: Jul 2006 Location: Kolkata, India Distribution: Debian 64-bit GNU/Linux, Kubuntu64, Fedora QA, Slackware, Posts: 2,762 Rep: Post your problem in the texlive mailing list.
03-05-2010, 08:15 AM   #3
batonac
LQ Newbie

Registered: Feb 2010
Posts: 5

Original Poster
Rep:

Quote:
 Originally Posted by amani 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```

 Tags bash, latex, merge, syntax