lib/Tools/document
author wenzelm
Fri Oct 26 18:16:31 2001 +0200 (2001-10-26 ago)
changeset 11948 9c812b21b2e8
parent 11844 eb072fd9a45a
child 12688 4ad13c2f7196
permissions -rwxr-xr-x
need at least 3 latex runs to get toc right!
wenzelm@10555
     1
#!/usr/bin/env bash
wenzelm@7793
     2
#
wenzelm@7793
     3
# $Id$
wenzelm@9788
     4
# Author: Markus Wenzel, TU Muenchen
wenzelm@9788
     5
# License: GPL (GNU GENERAL PUBLIC LICENSE)
wenzelm@7793
     6
#
wenzelm@7793
     7
# DESCRIPTION: prepare theory session document
wenzelm@7793
     8
wenzelm@7793
     9
wenzelm@10511
    10
PRG="$(basename "$0")"
wenzelm@7793
    11
wenzelm@7793
    12
function usage()
wenzelm@7793
    13
{
wenzelm@7793
    14
  echo
wenzelm@7793
    15
  echo "Usage: $PRG [OPTIONS] [DIR]"
wenzelm@7793
    16
  echo
wenzelm@7793
    17
  echo "  Options are:"
wenzelm@8654
    18
  echo "    -c           cleanup -- be aggressive in removing old stuff"
wenzelm@7866
    19
  echo "    -o FORMAT    specify output format: dvi (default), dvi.gz, ps,"
wenzelm@7866
    20
  echo "                 ps.gz, pdf"
wenzelm@7793
    21
  echo
wenzelm@8211
    22
  echo "  Prepare the theory session document in DIR (default 'document')"
wenzelm@7857
    23
  echo "  producing the specified output format."
wenzelm@7793
    24
  echo
wenzelm@7793
    25
  exit 1
wenzelm@7793
    26
}
wenzelm@7793
    27
wenzelm@7793
    28
function fail()
wenzelm@7793
    29
{
wenzelm@7793
    30
  echo "$1" >&2
wenzelm@7793
    31
  exit 2
wenzelm@7793
    32
}
wenzelm@7793
    33
wenzelm@7793
    34
wenzelm@7793
    35
## process command line
wenzelm@7793
    36
wenzelm@7793
    37
# options
wenzelm@7793
    38
wenzelm@8211
    39
CLEAN=""
wenzelm@7793
    40
OUTFORMAT=dvi
wenzelm@7793
    41
wenzelm@11844
    42
while getopts "co:" OPT
wenzelm@7793
    43
do
wenzelm@7793
    44
  case "$OPT" in
wenzelm@8211
    45
    c)
wenzelm@8211
    46
      CLEAN=true
wenzelm@8211
    47
      ;;
wenzelm@7793
    48
    o)
wenzelm@7793
    49
      OUTFORMAT="$OPTARG"
wenzelm@7793
    50
      ;;
wenzelm@7793
    51
    \?)
wenzelm@7793
    52
      usage
wenzelm@7793
    53
      ;;
wenzelm@7793
    54
  esac
wenzelm@7793
    55
done
wenzelm@7793
    56
wenzelm@7793
    57
shift $(($OPTIND - 1))
wenzelm@7793
    58
wenzelm@7793
    59
wenzelm@7793
    60
# args
wenzelm@7793
    61
wenzelm@8211
    62
DIR="document"
wenzelm@9788
    63
[ "$#" -ge 1 ] && { DIR="$1"; shift; }
wenzelm@7793
    64
wenzelm@9788
    65
[ "$#" -ne 0 ] && usage
wenzelm@7793
    66
wenzelm@7793
    67
wenzelm@7793
    68
## main
wenzelm@7793
    69
wenzelm@7814
    70
# check format
wenzelm@7814
    71
wenzelm@7814
    72
case "$OUTFORMAT" in
wenzelm@7814
    73
  dvi | dvi.gz | ps | ps.gz | pdf)
wenzelm@7814
    74
    ;;
wenzelm@7814
    75
  *)
wenzelm@7814
    76
    fail "Bad output format '$OUTFORMAT'"
wenzelm@7814
    77
    ;;
wenzelm@7814
    78
esac
wenzelm@7814
    79
wenzelm@7814
    80
wenzelm@7814
    81
# prepare document
wenzelm@7793
    82
wenzelm@7814
    83
function pre_latex ()
wenzelm@7814
    84
{
wenzelm@7814
    85
  local FMT="$1"
wenzelm@8654
    86
  [ -n "$CLEAN" ] && rm -f *.aux *.out
wenzelm@11948
    87
  "$ISATOOL" latex -o "$FMT" && \
wenzelm@11948
    88
  { [ ! -f root.bib ] || "$ISATOOL" latex -o bbl; } && \
wenzelm@11948
    89
  "$ISATOOL" latex -o "$FMT"
wenzelm@7814
    90
}
wenzelm@7814
    91
wenzelm@8211
    92
(
wenzelm@8211
    93
  cd "$DIR" || fail "Bad directory '$DIR'"
wenzelm@8211
    94
wenzelm@8654
    95
  [ -n "$CLEAN" ] && rm -f "../document.$OUTFORMAT"
wenzelm@8654
    96
wenzelm@8211
    97
  if [ -f IsaMakefile ]; then
wenzelm@9788
    98
    "$ISATOOL" make "$OUTFORMAT"
wenzelm@9788
    99
    RC="$?"
wenzelm@8211
   100
  elif [ "$OUTFORMAT" = pdf ]; then
wenzelm@8211
   101
    pre_latex pdf && \
wenzelm@9788
   102
    "$ISATOOL" latex -o pdf && \
wenzelm@8211
   103
    { if [ -n "$ISABELLE_THUMBPDF" ]; then
wenzelm@9788
   104
        "$ISATOOL" latex -o png && \
wenzelm@9788
   105
        "$ISATOOL" latex -o pdf
wenzelm@8211
   106
      fi; }
wenzelm@9788
   107
    RC="$?"
wenzelm@8211
   108
  else
wenzelm@8211
   109
    pre_latex dvi && \
wenzelm@9788
   110
    "$ISATOOL" latex -o "$OUTFORMAT"
wenzelm@9788
   111
    RC="$?"
wenzelm@8211
   112
  fi
wenzelm@8211
   113
wenzelm@11581
   114
  if [ "$RC" -eq 0 -a -f "root.$OUTFORMAT" ]; then
wenzelm@11844
   115
    cp -f "root.$OUTFORMAT" "../document.$OUTFORMAT"
wenzelm@11581
   116
  fi
wenzelm@8211
   117
wenzelm@8217
   118
  exit "$RC"
wenzelm@8211
   119
)
wenzelm@9788
   120
RC="$?"
wenzelm@7793
   121
wenzelm@7793
   122
wenzelm@7814
   123
# install
wenzelm@7793
   124
wenzelm@8211
   125
[ "$RC" -ne 0 ] && fail "Failed to prepare document in directory '$DIR'"
wenzelm@8211
   126
wenzelm@8211
   127
#beware!
wenzelm@8211
   128
[ -n "$CLEAN" ] && rm -rf "$DIR"
wenzelm@8211
   129
wenzelm@8211
   130
exit "$RC"