TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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


use File::Basename;

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

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

Your Answer


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.