lib/Tools/latex
author haftmann
Wed Jun 01 08:58:25 2005 +0200 (2005-06-01)
changeset 16163 a9f460f16fd6
parent 16162 ffe21872a2a0
child 16170 75cb95f4825f
permissions -rwxr-xr-x
improved *.sty handling
     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)*([^\$]*)\$/originating from CVS: $1/g; print;' $STYLEFILE > $TARGET
    91     # the [I] is there to prevent CVS from expanding $Id...$ itself ;-)
    92   done
    93 }
    94 
    95 function extract_syms ()
    96 {
    97   "$AUTO_PERL" -n \
    98     -e '(!m,%requires, || m,%requires latin1, || m,%requires amssymb, || m,%requires textcomp,) && m,\\newcommand\{\\isasym(\w+)\}, && print "$1\n";' \
    99     "$ISABELLE_HOME/lib/texinputs/isabellesym.sty" > "$DIR/syms.lst"
   100   "$AUTO_PERL" -n \
   101     -e 'm,\\newcommand\{\\isactrl(\w+)\}, && print "$1\n";' \
   102     "$ISABELLE_HOME/lib/texinputs/isabelle.sty" > "$DIR/ctrls.lst"
   103 }
   104 
   105 case "$OUTFORMAT" in
   106   dvi)
   107     check_root && \
   108     run_latex
   109     RC="$?"
   110     ;;
   111   dvi.gz)
   112     check_root && \
   113     run_latex && \
   114     gzip -f "$FILEBASE.dvi"
   115     RC="$?"
   116     ;;
   117   ps)
   118     check_root && \
   119     run_latex && \
   120     run_dvips &&
   121     RC="$?"
   122     ;;
   123   ps.gz)
   124     check_root && \
   125     run_latex && \
   126     run_dvips &&
   127     gzip -f "$FILEBASE.ps"
   128     RC="$?"
   129     ;;
   130   pdf)
   131     check_root && \
   132     run_pdflatex
   133     RC="$?"
   134     ;;
   135   bbl)
   136     check_root && \
   137     run_bibtex
   138     RC="$?"
   139     ;;
   140   idx)
   141     check_root && \
   142     run_makeindex
   143     RC="$?"
   144     ;;
   145   png)
   146     check_root && \
   147     run_thumbpdf
   148     RC="$?"
   149     ;;
   150   sty)
   151     copy_styles
   152     RC="$?"
   153     ;;
   154   syms)
   155     extract_syms
   156     RC="$?"
   157     ;;
   158   *)
   159     fail "Bad output format '$OUTFORMAT'"
   160     ;;
   161 esac
   162 
   163 exit "$RC"