hekeus@51
|
1 #!/bin/bash
|
hekeus@51
|
2
|
hekeus@51
|
3 # ----------------------------------------------------------------------
|
hekeus@51
|
4 # This shell script produces the latex source-package of a paper
|
hekeus@51
|
5 # as required by AAAI, in preparation for printed proceedings.
|
hekeus@51
|
6 # Copyright (C) 2009 Christian Fritz "fritz at cs dot toronto dot
|
hekeus@51
|
7 # edu"
|
hekeus@51
|
8 # ----------------------------------------------------------------------
|
hekeus@51
|
9 # This program is free software: you can redistribute it and/or
|
hekeus@51
|
10 # modify it under the terms of the GNU General Public License as
|
hekeus@51
|
11 # published by the Free Software Foundation, either version 3 of
|
hekeus@51
|
12 # the License, or (at your option) any later version.
|
hekeus@51
|
13 #
|
hekeus@51
|
14 # This program is distributed in the hope that it will be useful,
|
hekeus@51
|
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
hekeus@51
|
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
hekeus@51
|
17 # GNU General Public License for more details.
|
hekeus@51
|
18 #
|
hekeus@51
|
19 # You should have received a copy of the GNU General Public
|
hekeus@51
|
20 # License along with this program. If not, see
|
hekeus@51
|
21 # <http://www.gnu.org/licenses/>.
|
hekeus@51
|
22 # ----------------------------------------------------------------------
|
hekeus@51
|
23
|
hekeus@51
|
24 # function for recursive processing of style files
|
hekeus@51
|
25 recurseStyles() {
|
hekeus@51
|
26 echo "..recursively processing required packages of $1"
|
hekeus@51
|
27 PACKAGES=`grep RequirePackage $1 | sed 's/RequirePackage\[[^]]*\]/RequirePackage/g' | sed 's/.*RequirePackage{\([^}]*\)}.*/\1/' | sed -e 's/, */\n/g'`
|
hekeus@51
|
28 for name in $PACKAGES; do
|
hekeus@51
|
29 if [ ! -e sources/$name.sty ]; then
|
hekeus@51
|
30 echo "..locating and copying: $name"
|
hekeus@51
|
31 FILE=`locate /$name.sty | head -n 1`
|
hekeus@51
|
32 if [ -e $FILE ]; then
|
hekeus@51
|
33 cp $FILE sources
|
hekeus@51
|
34 else
|
hekeus@51
|
35 echo "..cannot locate $name.sty"
|
hekeus@51
|
36 fi
|
hekeus@51
|
37 if [ -e sources/$name.sty ]; then
|
hekeus@51
|
38 recurseStyles sources/$name.sty
|
hekeus@51
|
39 fi
|
hekeus@51
|
40 fi
|
hekeus@51
|
41 done
|
hekeus@51
|
42 }
|
hekeus@51
|
43
|
hekeus@51
|
44 # -------------------------------
|
hekeus@51
|
45
|
hekeus@51
|
46 # give a tex file as parameter
|
hekeus@51
|
47 if (( $# < 1 )); then
|
hekeus@51
|
48 echo "Error: Please give a tex-file as parameter, e.g., ./aaai_script.sh main.tex";
|
hekeus@51
|
49 exit;
|
hekeus@51
|
50 fi;
|
hekeus@51
|
51
|
hekeus@51
|
52 mkdir sources
|
hekeus@51
|
53
|
hekeus@51
|
54 echo "locating and copying all used packages"
|
hekeus@51
|
55 PACKAGES=`grep ^.usepackage $1 | sed -e 's/.*usepackage{\(.*.\)}.*/\1/' | sed -e 's/, /\n/g'`
|
hekeus@51
|
56 for name in $PACKAGES; do
|
hekeus@51
|
57 echo "locating and copying: $name"
|
hekeus@51
|
58 if [ -e $name.sty ]; then
|
hekeus@51
|
59 cp $name.sty sources
|
hekeus@51
|
60 else
|
hekeus@51
|
61 FILE=`locate /$name.sty | head -n 1`
|
hekeus@51
|
62 if [ -e $FILE ]; then
|
hekeus@51
|
63 cp $FILE sources
|
hekeus@51
|
64 else
|
hekeus@51
|
65 echo "cannot locate $name.sty"
|
hekeus@51
|
66 fi
|
hekeus@51
|
67 fi
|
hekeus@51
|
68 if [ -e sources/$name.sty ]; then
|
hekeus@51
|
69 recurseStyles sources/$name.sty
|
hekeus@51
|
70 fi
|
hekeus@51
|
71 done
|
hekeus@51
|
72
|
hekeus@51
|
73
|
hekeus@51
|
74 echo "inlining all included files"
|
hekeus@51
|
75 cp $1 __tmp1
|
hekeus@51
|
76 while ( grep ^.input __tmp1 ); do
|
hekeus@51
|
77 # INPUTS=`grep ^.input __tmp1 | sed 's/.*input *{*\([^.}]*\).*/\1/'`
|
hekeus@51
|
78 # cat __tmp1 | sed '/^%.*$/d' > __tmp2
|
hekeus@51
|
79 # for name in $INPUTS; do
|
hekeus@51
|
80 # echo "inlining $name"
|
hekeus@51
|
81 # awk -v filename=$name '{ if ($0 ~ ".input.*"filename) { system("cat "filename".tex | sed '/^%.*\$/d'"); } else { print $0; } }' < __tmp2 > __tmp1
|
hekeus@51
|
82 # done
|
hekeus@51
|
83 awk '{ if ( $0 ~ /\\input( |{)/ ) { sub(/\\input( |{)/,""); sub(/}/, ""); sub(/\.tex/, ""); system("cat "$0".tex | sed '/^%.*\$/d'") } else { print $0; } }' __tmp1 > __tmp2
|
hekeus@51
|
84 cp __tmp2 __tmp1
|
hekeus@51
|
85 done
|
hekeus@51
|
86
|
hekeus@51
|
87 echo "inlining bibitems"
|
hekeus@51
|
88 BIBFILE=`echo $1 | sed 's/.tex/.bbl/'`
|
hekeus@51
|
89 awk -v filename=$BIBFILE '{ if ($0 ~ ".bibliography{") { system("cat "filename); } else { print $0; } }' < __tmp1 > __tmp2
|
hekeus@51
|
90 cp __tmp2 sources/full.tex
|
hekeus@51
|
91
|
hekeus@51
|
92
|
hekeus@51
|
93 echo "getting figures"
|
hekeus@51
|
94 FIGURES=`grep includegraphics __tmp2 | grep -v ^% | sed 's/.*{\([^}]*\)}*/\1/'`
|
hekeus@51
|
95 for name in $FIGURES; do
|
hekeus@51
|
96 echo "getting figure $name"
|
hekeus@51
|
97 mkdir -p sources/`echo "$name" | sed 's/\(.*\)\/.*/\1/'`
|
hekeus@51
|
98 cp $name.*ps sources/`echo "$name" | sed 's/\(.*\)\/.*/\1/'`
|
hekeus@51
|
99 done
|
hekeus@51
|
100
|
hekeus@51
|
101 # -------------------------------
|
hekeus@51
|
102
|
hekeus@51
|
103 cd sources
|
hekeus@51
|
104 echo "latexing source"
|
hekeus@51
|
105 latex full.tex
|
hekeus@51
|
106 echo "latexing source once more"
|
hekeus@51
|
107 latex full.tex
|
hekeus@51
|
108
|
hekeus@51
|
109 echo "creating the PDF using"
|
hekeus@51
|
110 dvips -Ppdf -G0 -tletter full -o full.ps
|
hekeus@51
|
111 ps2pdf -sPAPERSIZE=letter -dMaxSubsetPct=100 -dCompatibilityLevel=1.2 -dSubsetFonts=false -dEmbedAllFonts=true full.ps
|
hekeus@51
|
112 cd ..
|
hekeus@51
|
113
|
hekeus@51
|
114 echo "DONE"
|