Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a large document that I have split into several separate documents. I have one main.tex file and several file_i.tex files which are included into main.tex using the \input-command. It also happens that this including is nested, i.e. that one of file_i.tex files included another file.

The log file main.log that is generated looks something like this:

blabla
(main.tex
blabla
blabla
(file_1.tex
blabla
)
(file_2.tex
blablabla
(file_2_1.tex)
)
blabla
)

I wonder if there exists some way/script that splits this file into e.g. part_main.log, part_file_1.log, part_file_2.log and part_file_2_1.log.

It doesn't seem to difficult to write an ad-hoc script to do this, but it also seems such a common problem, that I would expect some well-tested scripts to already be available.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

I don't know of an "official" script but I wrote a little perl script some time ago for a similar task. It is kind of a dirty hack and sparsely tested, but it might be useful for others as well. Improvements are welcome.

The script expects TeX's logfile as a parameter and generates separate .log files for each included module.

#!/usr/bin/perl

use File::Basename;

die("Syntax: splitlog <logfile>") unless ($#ARGV == 1);

@log = <ARGV>;
push(@files, $ARGV[0]);
foreach (@log) {
   chomp;
   while (length($_) > 0) {
      if (/^\(([^)]+)$/) {
         push(@files, $1);
         $_ = "";
         $fname = basename($1);
         open(LOG, ">$fname.log");
      }
      elsif (/^(\)+)\s*(.*)$/) {
         for ($i=0; $i < length($1); ++$i) {
            close(LOG);
            pop(@files);
         }
         if ($#files > 0) {
            $fname = basename($files[-1]);
            open(LOG, ">>$fname.log");
         }
         $_ = $2;
      }
      else {
         print LOG "$_\n";
         $_ = "";
      }
   }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.