lib/Tools/latex
author haftmann
Wed, 01 Jun 2005 14:16:45 +0200
changeset 16171 3c939bb52420
parent 16170 75cb95f4825f
child 16874 3057990d20e0
permissions -rwxr-xr-x
remove CVS id from *.sty latex styles
     1 #!/usr/bin/env bash
     2 #
     3 # $Id$
     4 # Author: Markus Wenzel, TU Muenchen
     5 #
     6 # DESCRIPTION: run LaTeX (and related tools)
     7 
     8 
     9 PRG="$(basename "$0")"
    10 
    11 function usage()
    12 {
    13   echo
    14   echo "Usage: $PRG [OPTIONS] [FILE]"
    15   echo
    16   echo "  Options are:"
    17   echo "    -o FORMAT    specify output format: dvi (default), dvi.gz, ps, ps.gz,"
    18   echo "                 pdf, bbl, png, sty, syms"
    19   echo
    20   echo "  Run LaTeX (and related tools) on FILE (default root.tex),"
    21   echo "  producing the specified output format."
    22   echo
    23   exit 1
    24 }
    25 
    26 function fail()
    27 {
    28   echo "$1" >&2
    29   exit 2
    30 }
    31 
    32 
    33 ## process command line
    34 
    35 # options
    36 
    37 OUTFORMAT=dvi
    38 
    39 while getopts "o:" OPT
    40 do
    41   case "$OPT" in
    42     o)
    43       OUTFORMAT="$OPTARG"
    44       ;;
    45     \?)
    46       usage
    47       ;;
    48   esac
    49 done
    50 
    51 shift $(($OPTIND - 1))
    52 
    53 
    54 # args
    55 
    56 FILE="root.tex"
    57 [ "$#" -ge 1 ] && { FILE="$1"; shift; }
    58 
    59 [ "$#" -ne 0 ] && usage
    60 
    61 
    62 ## main
    63 
    64 # root file
    65 
    66 DIR=$(dirname "$FILE")
    67 FILEBASE=$(basename "$FILE" .tex)
    68 [ "$DIR" = . ] || FILEBASE="$DIR/$FILEBASE"
    69 
    70 function check_root () { [ -f "$FILEBASE.tex" ] || fail "Bad file '$FILE'"; }
    71 
    72 
    73 # operations
    74 
    75 #set by configure
    76 AUTO_PERL=perl
    77 
    78 function run_latex () { $ISABELLE_LATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
    79 function run_pdflatex () { $ISABELLE_PDFLATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
    80 function run_bibtex () { $ISABELLE_BIBTEX </dev/null "$FILEBASE"; }
    81 function run_makeindex () { $ISABELLE_MAKEINDEX </dev/null "$FILEBASE"; }
    82 function run_dvips () { $ISABELLE_DVIPS -q -o "$FILEBASE.ps" "$FILEBASE.dvi"; }
    83 function run_thumbpdf () { [ -n "$ISABELLE_THUMBPDF" ] && $ISABELLE_THUMBPDF "$FILEBASE"; }
    84 function copy_styles ()
    85 {
    86   for STYLEFILE in "$ISABELLE_HOME/lib/texinputs"/*.sty
    87   do
    88     TARGET="$DIR"/$(basename $STYLEFILE)
    89     rm -f $TARGET
    90     "$AUTO_PERL" -n -e 's/\$[I]d:?(?:\s)*([^\$]*)\$//g; print;' "$STYLEFILE" > "$TARGET"
    91     #~ "$AUTO_PERL" -n -e 's/\$[I]d:?(?:\s)*([^\$]*)\$/originating from CVS: $1/g; print;' $STYLEFILE > $TARGET
    92     # the [I] is there to prevent CVS from expanding $Id...$ itself ;-)
    93   done
    94 }
    95 
    96 function extract_syms ()
    97 {
    98   "$AUTO_PERL" -n \
    99     -e '(!m,%requires, || m,%requires latin1, || m,%requires amssymb, || m,%requires textcomp,) && m,\\newcommand\{\\isasym(\w+)\}, && print "$1\n";' \
   100     "$ISABELLE_HOME/lib/texinputs/isabellesym.sty" > "$DIR/syms.lst"
   101   "$AUTO_PERL" -n \
   102     -e 'm,\\newcommand\{\\isactrl(\w+)\}, && print "$1\n";' \
   103     "$ISABELLE_HOME/lib/texinputs/isabelle.sty" > "$DIR/ctrls.lst"
   104 }
   105 
   106 case "$OUTFORMAT" in
   107   dvi)
   108     check_root && \
   109     run_latex
   110     RC="$?"
   111     ;;
   112   dvi.gz)
   113     check_root && \
   114     run_latex && \
   115     gzip -f "$FILEBASE.dvi"
   116     RC="$?"
   117     ;;
   118   ps)
   119     check_root && \
   120     run_latex && \
   121     run_dvips &&
   122     RC="$?"
   123     ;;
   124   ps.gz)
   125     check_root && \
   126     run_latex && \
   127     run_dvips &&
   128     gzip -f "$FILEBASE.ps"
   129     RC="$?"
   130     ;;
   131   pdf)
   132     check_root && \
   133     run_pdflatex
   134     RC="$?"
   135     ;;
   136   bbl)
   137     check_root && \
   138     run_bibtex
   139     RC="$?"
   140     ;;
   141   idx)
   142     check_root && \
   143     run_makeindex
   144     RC="$?"
   145     ;;
   146   png)
   147     check_root && \
   148     run_thumbpdf
   149     RC="$?"
   150     ;;
   151   sty)
   152     copy_styles
   153     RC="$?"
   154     ;;
   155   syms)
   156     extract_syms
   157     RC="$?"
   158     ;;
   159   *)
   160     fail "Bad output format '$OUTFORMAT'"
   161     ;;
   162 esac
   163 
   164 exit "$RC"