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