hekeus@51: #!/bin/bash hekeus@51: hekeus@51: # ---------------------------------------------------------------------- hekeus@51: # This shell script produces the latex source-package of a paper hekeus@51: # as required by AAAI, in preparation for printed proceedings. hekeus@51: # Copyright (C) 2009 Christian Fritz "fritz at cs dot toronto dot hekeus@51: # edu" hekeus@51: # ---------------------------------------------------------------------- hekeus@51: # This program is free software: you can redistribute it and/or hekeus@51: # modify it under the terms of the GNU General Public License as hekeus@51: # published by the Free Software Foundation, either version 3 of hekeus@51: # the License, or (at your option) any later version. hekeus@51: # hekeus@51: # This program is distributed in the hope that it will be useful, hekeus@51: # but WITHOUT ANY WARRANTY; without even the implied warranty of hekeus@51: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the hekeus@51: # GNU General Public License for more details. hekeus@51: # hekeus@51: # You should have received a copy of the GNU General Public hekeus@51: # License along with this program. If not, see hekeus@51: # . hekeus@51: # ---------------------------------------------------------------------- hekeus@51: hekeus@51: # function for recursive processing of style files hekeus@51: recurseStyles() { hekeus@51: echo "..recursively processing required packages of $1" hekeus@51: PACKAGES=`grep RequirePackage $1 | sed 's/RequirePackage\[[^]]*\]/RequirePackage/g' | sed 's/.*RequirePackage{\([^}]*\)}.*/\1/' | sed -e 's/, */\n/g'` hekeus@51: for name in $PACKAGES; do hekeus@51: if [ ! -e sources/$name.sty ]; then hekeus@51: echo "..locating and copying: $name" hekeus@51: FILE=`locate /$name.sty | head -n 1` hekeus@51: if [ -e $FILE ]; then hekeus@51: cp $FILE sources hekeus@51: else hekeus@51: echo "..cannot locate $name.sty" hekeus@51: fi hekeus@51: if [ -e sources/$name.sty ]; then hekeus@51: recurseStyles sources/$name.sty hekeus@51: fi hekeus@51: fi hekeus@51: done hekeus@51: } hekeus@51: hekeus@51: # ------------------------------- hekeus@51: hekeus@51: # give a tex file as parameter hekeus@51: if (( $# < 1 )); then hekeus@51: echo "Error: Please give a tex-file as parameter, e.g., ./aaai_script.sh main.tex"; hekeus@51: exit; hekeus@51: fi; hekeus@51: hekeus@51: mkdir sources hekeus@51: hekeus@51: echo "locating and copying all used packages" hekeus@51: PACKAGES=`grep ^.usepackage $1 | sed -e 's/.*usepackage{\(.*.\)}.*/\1/' | sed -e 's/, /\n/g'` hekeus@51: for name in $PACKAGES; do hekeus@51: echo "locating and copying: $name" hekeus@51: if [ -e $name.sty ]; then hekeus@51: cp $name.sty sources hekeus@51: else hekeus@51: FILE=`locate /$name.sty | head -n 1` hekeus@51: if [ -e $FILE ]; then hekeus@51: cp $FILE sources hekeus@51: else hekeus@51: echo "cannot locate $name.sty" hekeus@51: fi hekeus@51: fi hekeus@51: if [ -e sources/$name.sty ]; then hekeus@51: recurseStyles sources/$name.sty hekeus@51: fi hekeus@51: done hekeus@51: hekeus@51: hekeus@51: echo "inlining all included files" hekeus@51: cp $1 __tmp1 hekeus@51: while ( grep ^.input __tmp1 ); do hekeus@51: # INPUTS=`grep ^.input __tmp1 | sed 's/.*input *{*\([^.}]*\).*/\1/'` hekeus@51: # cat __tmp1 | sed '/^%.*$/d' > __tmp2 hekeus@51: # for name in $INPUTS; do hekeus@51: # echo "inlining $name" hekeus@51: # awk -v filename=$name '{ if ($0 ~ ".input.*"filename) { system("cat "filename".tex | sed '/^%.*\$/d'"); } else { print $0; } }' < __tmp2 > __tmp1 hekeus@51: # done hekeus@51: awk '{ if ( $0 ~ /\\input( |{)/ ) { sub(/\\input( |{)/,""); sub(/}/, ""); sub(/\.tex/, ""); system("cat "$0".tex | sed '/^%.*\$/d'") } else { print $0; } }' __tmp1 > __tmp2 hekeus@51: cp __tmp2 __tmp1 hekeus@51: done hekeus@51: hekeus@51: echo "inlining bibitems" hekeus@51: BIBFILE=`echo $1 | sed 's/.tex/.bbl/'` hekeus@51: awk -v filename=$BIBFILE '{ if ($0 ~ ".bibliography{") { system("cat "filename); } else { print $0; } }' < __tmp1 > __tmp2 hekeus@51: cp __tmp2 sources/full.tex hekeus@51: hekeus@51: hekeus@51: echo "getting figures" hekeus@51: FIGURES=`grep includegraphics __tmp2 | grep -v ^% | sed 's/.*{\([^}]*\)}*/\1/'` hekeus@51: for name in $FIGURES; do hekeus@51: echo "getting figure $name" hekeus@51: mkdir -p sources/`echo "$name" | sed 's/\(.*\)\/.*/\1/'` hekeus@51: cp $name.*ps sources/`echo "$name" | sed 's/\(.*\)\/.*/\1/'` hekeus@51: done hekeus@51: hekeus@51: # ------------------------------- hekeus@51: hekeus@51: cd sources hekeus@51: echo "latexing source" hekeus@51: latex full.tex hekeus@51: echo "latexing source once more" hekeus@51: latex full.tex hekeus@51: hekeus@51: echo "creating the PDF using" hekeus@51: dvips -Ppdf -G0 -tletter full -o full.ps hekeus@51: ps2pdf -sPAPERSIZE=letter -dMaxSubsetPct=100 -dCompatibilityLevel=1.2 -dSubsetFonts=false -dEmbedAllFonts=true full.ps hekeus@51: cd .. hekeus@51: hekeus@51: echo "DONE"