lib/Tools/latex
author berghofe
Mon, 30 Sep 2002 16:36:57 +0200
changeset 13605 528f7489a403
parent 12846 0fce95478e19
child 14344 0f0a2148a099
permissions -rwxr-xr-x
Added syntax for "asm_lr" simplifier option.

#!/usr/bin/env bash
#
# $Id$
# Author: Markus Wenzel, TU Muenchen
# License: GPL (GNU GENERAL PUBLIC LICENSE)
#
# DESCRIPTION: run LaTeX (and related tools)


PRG="$(basename "$0")"

function usage()
{
  echo
  echo "Usage: $PRG [OPTIONS] [FILE]"
  echo
  echo "  Options are:"
  echo "    -o FORMAT    specify output format: dvi (default), dvi.gz, ps, ps.gz,"
  echo "                 pdf, bbl, png, sty"
  echo
  echo "  Run LaTeX (and related tools) on FILE (default root.tex),"
  echo "  producing the specified output format."
  echo
  exit 1
}

function fail()
{
  echo "$1" >&2
  exit 2
}


## process command line

# options

OUTFORMAT=dvi

while getopts "o:" OPT
do
  case "$OPT" in
    o)
      OUTFORMAT="$OPTARG"
      ;;
    \?)
      usage
      ;;
  esac
done

shift $(($OPTIND - 1))


# args

FILE="root.tex"
[ "$#" -ge 1 ] && { FILE="$1"; shift; }

[ "$#" -ne 0 ] && usage


## main

# root file

DIR=$(dirname "$FILE")
FILEBASE=$(basename "$FILE" .tex)
[ "$DIR" = . ] || FILEBASE="$DIR/$FILEBASE"

function check_root () { [ -f "$FILEBASE.tex" ] || fail "Bad file '$FILE'"; }


# operations

function run_latex () { $ISABELLE_LATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
function run_pdflatex () { $ISABELLE_PDFLATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
function run_bibtex () { $ISABELLE_BIBTEX </dev/null "$FILEBASE"; }
function run_dvips () { $ISABELLE_DVIPS -q -o "$FILEBASE.ps" "$FILEBASE.dvi"; }
function run_thumbpdf () { [ -n "$ISABELLE_THUMBPDF" ] && $ISABELLE_THUMBPDF "$FILEBASE"; }
function copy_styles () { cp -f "$ISABELLE_HOME/lib/texinputs"/*.sty "$DIR"; }

case "$OUTFORMAT" in
  dvi)
    check_root && \
    run_latex
    RC="$?"
    ;;
  dvi.gz)
    check_root && \
    run_latex && \
    gzip -f "$FILEBASE.dvi"
    RC="$?"
    ;;
  ps)
    check_root && \
    run_latex && \
    run_dvips &&
    RC="$?"
    ;;
  ps.gz)
    check_root && \
    run_latex && \
    run_dvips &&
    gzip -f "$FILEBASE.ps"
    RC="$?"
    ;;
  pdf)
    check_root && \
    run_pdflatex
    RC="$?"
    ;;
  bbl)
    check_root && \
    run_bibtex
    RC="$?"
    ;;
  png)
    check_root && \
    run_thumbpdf
    RC="$?"
    ;;
  sty)
    copy_styles
    RC="$?"
    ;;
  *)
    fail "Bad output format '$OUTFORMAT'"
    ;;
esac

exit "$RC"