summaryrefslogtreecommitdiff
path: root/support/latexfileversion/latexfileversion
blob: bae05f520aa68f2a290c706d4c62e68932bec25d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bash
## latexfileversion
##
## This simple shell script prints the version and date of a LaTeX class or
## style file.
##
## Version 0.3, 2011-12-31, Add support for arbitrary tex input file types
##                          Rename from getfileversion to latexfileversion
## Version 0.2, 2011-12-30, Avoid special characters as guillemots
## Version 0.1, 2005-04-30, Initial version
##
## Copyright 2005, 2011  Harald Harders, harald.harders@gmx.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
## latexfileversion, README, and ChangeLog.
VERSION=0.3

# help screen
if [ -z "$1" ]
then
    echo 'latexfileversion v'$VERSION >&2 
    echo '' >&2
    echo 'This programme prints the version and date of a LaTeX class or' >&2
    echo 'style file.' >&2
    echo '' >&2
    echo 'Syntax:' >&2
    echo 'latexfileversion <file>' >&2
    echo '' >&2
    echo 'This programme handles style files (extension .sty),' >&2
    echo 'class files (extension .cls), and other tex input files.' >&2
    echo 'The file extension must be given.' >&2
    exit 1
fi

# make temporary directory
TMPDIR=`mktemp -d /tmp/latexfileversion.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
) > latexfileversion.tex
else
    if [ "$STYLE.sty" == "$FILE" ]
    then
	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
) > latexfileversion.tex
    else
	echo -n "Looking for file '$FILE': "
        # generate temporary LaTeX file
(
cat << EOM
\documentclass{ltxdoc}
\nofiles
\input{$FILE}
\GetFileInfo{$FILE}
\typeout{VERSION \fileversion, \filedate}
\begin{document}
\end{document}
EOM
) > latexfileversion.tex
    fi
fi

# run temporary LaTeX file which writes »VERSION ...« into the logfile
pdflatex -interaction=nonstopmode latexfileversion.tex > /dev/null
# extract the line containing »VERSION« and remove »VERSION «
grep -e '^VERSION' latexfileversion.log | sed 's/VERSION //' 

# delete temporary directory
rm -rf $TMPDIR

#EOF