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'm tired of manually creating the tarfiles I need for uploading articles to the arxiv. The process involves creating a tarfile of all the (non-standard) source files. So naturally it needs the .tex file(s), the .pdf files, the .bbl file and perhaps an .idx if you have an index (perhaps something else?). I usually keep my figures in a subdirectory under the one where the .tex file lives, so the tar file would have to keep that directory structure. What I usually do is compile with \listfiles then manually grab the list of files from the output, stick them in <filelist> together with the name of the main .tex file and then run tar c -T<filelist> -f<output.tar>. Not a huge operation, but it would be nice to automate since I usually forget the required switches by the time I need to upload another article to the arxiv....

I looked online and found unlog.sh on the arxiv itself, but it specifically states that it is not designed for the output of pdflatex. When I tried to modify it for the output of the pdflatex, indeed I didn't manage, but this might be due to my lacking perl skills, and not for any good reason.

Does anyone know of a nice script for creating the required tarfiles for the arxiv, or is interested in modifying unlog.sh so that it works properly on pdflatex log files?

share|improve this question
    
can you give details of what exactly these tar files are supposed to contain? what is the script supposed to do with the output of pdflatex? –  Juan A. Navarro Aug 11 '10 at 11:53
    
Added details in question. –  Yossi Farjoun Aug 11 '10 at 12:06
    
What's the problem with running unlog on the logfile of a pdflatex run? Do you get stuff that you don't expect, or stuff missing that you do? I wouldn't recommend it since it slurps in everything including all the standard packages that aren't needed in the tar file. –  Andrew Stacey Aug 11 '10 at 12:20
    
Both problems you states, it include the kitchen sink (like article.cls) and it misses my pdf file (even if I add pdf to the script in the obvious place) –  Yossi Farjoun Aug 11 '10 at 13:39
    
I get the same behaviour with latex as pdflatex: it slurps in too much and misses the graphics figures. –  Andrew Stacey Aug 11 '10 at 14:43
show 3 more comments

1 Answer

up vote 2 down vote accepted

With some basic testing, the following works for me. Copy it to a file, say unlog.pl, and save it somewhere on your path. Either make it executable or invoke it via perl unlog.pl logfile tarfile.

It goes through the logfile looking for suitable files (much as the original script did). I modified the search pattern to pick up included graphics (these seemed to be signalled by angular brackets in the logfile) and added .pdf to the extensions (others can easily be added).

It builds the tar file out of those files that are below the user's home directory on the supposition that those are the unusual ones. Those that are below the current directory are added with directories (relative to the current directory), those that aren't are stripped of leading directories.

The logic there being that if it's below the current directory it's probably special to this file and is probably included via \includegraphics{relative/path/to/file} so the relative path is important. If it's not below the current directory then it's probably included via something like \usepackage{style} so putting it in without any directory should work.

#!/usr/bin/perl

use strict;
use Cwd qw/abs_path getcwd/;
use Archive::Tar;

die "unlog logfile output-file" unless $#ARGV == 1;

my ($logfile,$tarfile) = @ARGV;

if (!($logfile =~ /\.log$/)) {
    $logfile .= ".log";
}

open(LOGFILE,"$logfile") or
    die "cannot read $logfile";

my $tar = Archive::Tar->new();

my $cwd = getcwd();
my %tarfiles;

while (<LOGFILE>) {
    while (/[\(|<](\S*\.(bbl|tex|sty|cls|e?ps|tib|ttz|ttx|pdf))\b/g) {
    print "found $1: ";
    # Convert relative directories to absolute in the tar args:
    my $x=abs_path($1);
    if (exists($tarfiles{$x})){
        print "already in, skipping\n";
        next;
    } 
    $tarfiles{$x} = 1;
    if ($x =~ m/^$ENV{HOME}/) {
        # Only add files that are within our home directory
        if ($x =~ s#^$cwd/##) {
        # Subdirectories of _this_ one get preserved
        print "adding to tar, preserving directory\n";
        $tar->add_files($x);
        } else {
        # Probably within our own texmf tree, so add it to the list
        # but strip off any leading directories
        my ($dir,$name) = ($x =~ m/(.*\/)?([^\/]*)/);
        print "adding to tar, no leading directory\n";
        chdir($dir);
        $tar->add_files($name);
        chdir($cwd);
        }
    } else {
        # Otherwise, do nothing as it's probably in the global texmf tree
        print "omitting\n";
    }
    }
}

$tar->write($tarfile);
share|improve this answer
    
Just what the doctor ordered. It works for me, for my simple example. (And now I also have a nice exercise of understanding a perl script..) Thank-you! –  Yossi Farjoun Aug 12 '10 at 8:23
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.