[texhax] pack'n'go latex files

Steve Schwartz s.schwartz at imperial.ac.uk
Tue Dec 2 02:10:06 CET 2008

(I sent this to the beamer list, but someone here may have had similar
needs and/or be interested in using or improving my hack solution)


I have some requests for copies of my presentations over the years, and
some people would obviously prefer ppt files so they can edit them, copy
the graphics in full resolution, etc. Of course, I can't give them that,
so I offer my latex source.

This isn't always easy, as I leave the graphics files in sensible
locations (for me) and just set the GraphicsPath to find them all. With
a big presentation this can be lots of files scattered all over my
hard-drive, and I often thought about trying to automate the process.

Today, after another request, I had a go at this by writing a script
that searches through the log file, finds all the graphics (they are
called out with a very specific form: <use /home/me/images/file.png>),
generates a shell script that then copies these all, together with the
latex source, to a target directory, and finally tar's it up. I append
the script in case anyone finds it useful.

But it is a quick hack and far from perfect, so I'm wondering if someone
has done a better job, or has the interest in improving mine. Here are
some of the deficiencies:

1 It doesn't find the graphics files that are in folders specified by my
TEXINPUTS environment (nor I presume in tex's default paths) as these
don't have a full path hierarchy in the log, i.e., they look like: <use

2  As written it only packs the top level latex document (that matches
the stem of the logfile name), so any included or inputted files don't
end up in my archive (I haven't tried to solve this, so maybe it's easy
to likewise spot them)

3  It also doesn't add any custom .sty files, though distinguishing
these from the plethora of packages loaded by beamer and available in
the standard distribution is probably a nightmare.

4  It's probably very inelegant - I'm not really a script writer, more
of a hacker, in particular:

5  It will fail if the graphics file extends over three lines :-). I hit
this one because the log file wraps lines with a newline character after
79 characters.

6  To be more universal, it would be better to be written in a portable
scripting language, e.g., perl, rather than as a C-script

This is not at all pressing, but any thoughts, improvements, or
alternatives would satisfy some curiosity. I'll send this also to the
texhax mailing list, but I think it is probably more likely to be of
interest to the beamer community.


============================ cut here =============================

# Script to pack up a latex doc and graphics.
# Packs: graphics, latex source and, if found, final pdf
# Limitations (would be possible to enhance):
#    Doesn't find graphics that are stored in standard latex path,
#     i.e., that don't have <use /...> with full path in .log file
#    Only picks up parent tex file, no included/input files
# history
#  SJS Dec 2008

if ($#argv < 2) then
   echo "Usage: packtex.sh <file_stem> <target directory>"

if (-d $2) then
   echo $2 "already exists - exiting"

# put temporary files in /tmp to be sure user can execute
# (in my system, I keep .tex files on a fat32 partition, which
# is not executable

if (-e /tmp/packtex_cp.sh) then
   rm -f /tmp/packtex_cp.sh

mkdir $2

# sed script below:
# Finds lines with <use...
# Appends the next line (N) in case file names extend to two lines
# Replaces <use by cp -u to set up copy command
# Replaces closing > by $1 and new line
# grep's only these lines and puts them in file in /tmp

sed  -e '/<use /N;s/\n//;s/<use /\ncp -u /g;s/>/ $1\n/g' $1.log | grep
"cp -u" > /tmp/packtex_cp.sh

# now make that file executable and execute it. Pass target directory as
chmod u+x /tmp/packtex_cp.sh
/bin/csh /tmp/packtex_cp.sh $2

# clean up
rm /tmp/packtex_cp.sh

# copy latex source and final pdf
cp $1.tex $2
if (-e $1.pdf) then
   cp $1.pdf $2

# bundle
tar -cvzf $1.tgz $2

=================================== cut here ==========================
Professor Steven J Schwartz      Phone: +44-(0)20-7594-7660
Space and Atmospheric Physics    Fax:   +44-(0)20-7594-7772
The Blackett Laboratory          E-mail: s.schwartz at imperial.ac.uk
Imperial College London          Office: Huxley 6M70 
London SW7 2AZ, U.K.             Web: http://www.sp.ph.ic.ac.uk/~sjs

More information about the texhax mailing list