#!/bin/bash ## getfileversion ## ## This simple shell script prints the version and date of a LaTeX class or ## style file. ## ## Version 0.1, 2005-04-30 ## ## Copyright 2005 Harald Harders, h.harders@tu-bs.de ## ## This programme may be distributed and/or modified under the ## conditions of the LaTeX Project Public License, either version 1.2 ## of this license or (at your option) any later version. ## The latest version of this license is in ## http://www.latex-project.org/lppl.txt ## and version 1.2 or later is part of all distributions of LaTeX ## version 1999/12/01 or later. ## ## This programme consists of the files getfileversion, README, and ChangeLog. # help screen if [ -z "$1" ] then echo 'This programme prints the version and date of a LaTeX class or' >&2 echo 'style file.' >&2 echo '' >&2 echo 'Syntax:' >&2 echo 'getfileversion ' >&2 echo '' >&2 echo 'This programme handles style files (extension .sty) and' >&2 echo 'class files (extension .cls). If no extension is given,' >&2 echo '.sty is assumed.' >&2 exit 1 fi # make temporary directory TMPDIR=`mktemp -d /tmp/getfileversion.XXXXXX` || exit 1 cd $TMPDIR # extract basenames for extensions .cls and .sty FILE=$1 STYLE=${1%%.sty} CLASS=${1%%.cls} # handle .cls files and .sty files seperately if [ "$CLASS.cls" == "$FILE" ] then echo -n "Looking for class file »$CLASS.cls«: " # generate temporary LaTeX file ( cat << EOM \documentclass{$CLASS} \nofiles \makeatletter \def\GetFileInfo#1{% \def\filename{#1}% \def\@tempb##1 ##2 ##3\relax##4\relax{% \def\filedate{##1}% \def\fileversion{##2}% \def\fileinfo{##3}}% \edef\@tempa{\csname ver@#1\endcsname}% \expandafter\@tempb\@tempa\relax? ? \relax\relax} \makeatother \GetFileInfo{$CLASS.cls} \typeout{VERSION \fileversion, \filedate} \begin{document} \end{document} EOM ) > getfileversion.tex else echo -n "Looking for style file »$STYLE.sty«: " # generate temporary LaTeX file ( cat << EOM \documentclass{ltxdoc} \nofiles \usepackage{$STYLE} \GetFileInfo{$STYLE.sty} \typeout{VERSION \fileversion, \filedate} \begin{document} \end{document} EOM ) > getfileversion.tex fi # run temporary LaTeX file which writes »VERSION ...« into the logfile pdflatex -interaction=nonstopmode getfileversion.tex > /dev/null # extract the line containing »VERSION« and remove »VERSION « grep -e '^VERSION' getfileversion.log | sed 's/VERSION //' # delete temporary directory #rm -rf $TMPDIR #EOF