lib/Tools/latex
author kuncar
Mon, 26 Mar 2012 17:58:47 +0200
changeset 47118 2fe7a42ece1d
parent 40893 7d88ebdce380
child 48515 3e17f343deb5
permissions -rwxr-xr-x
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10555
2323ec838401 /usr/bin/env bash;
wenzelm
parents: 10511
diff changeset
     1
#!/usr/bin/env bash
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
     2
#
9788
wenzelm
parents: 8568
diff changeset
     3
# Author: Markus Wenzel, TU Muenchen
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
     4
#
7794
37069d910cbe pass RC;
wenzelm
parents: 7777
diff changeset
     5
# DESCRIPTION: run LaTeX (and related tools)
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
     6
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
     7
10511
wenzelm
parents: 9788
diff changeset
     8
PRG="$(basename "$0")"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
     9
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    10
function usage()
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    11
{
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    12
  echo
28650
a7ba12e0d3b7 tuned usage line;
wenzelm
parents: 26979
diff changeset
    13
  echo "Usage: isabelle $PRG [OPTIONS] [FILE]"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    14
  echo
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    15
  echo "  Options are:"
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    16
  echo "    -o FORMAT    specify output format: dvi (default), dvi.gz, ps, ps.gz,"
26908
25fb7241f32e removed obsolete thumbpdf;
wenzelm
parents: 26576
diff changeset
    17
  echo "                 pdf, bbl, idx, sty, syms"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    18
  echo
7857
a49a3978fe3a tuned usage;
wenzelm
parents: 7815
diff changeset
    19
  echo "  Run LaTeX (and related tools) on FILE (default root.tex),"
a49a3978fe3a tuned usage;
wenzelm
parents: 7815
diff changeset
    20
  echo "  producing the specified output format."
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    21
  echo
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    22
  exit 1
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    23
}
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    24
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    25
function fail()
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    26
{
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    27
  echo "$1" >&2
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    28
  exit 2
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    29
}
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    30
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    31
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    32
## process command line
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    33
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    34
# options
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    35
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    36
OUTFORMAT=dvi
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    37
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    38
while getopts "o:" OPT
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    39
do
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    40
  case "$OPT" in
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    41
    o)
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    42
      OUTFORMAT="$OPTARG"
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    43
      ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    44
    \?)
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    45
      usage
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    46
      ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    47
  esac
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    48
done
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    49
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    50
shift $(($OPTIND - 1))
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    51
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    52
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    53
# args
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    54
7794
37069d910cbe pass RC;
wenzelm
parents: 7777
diff changeset
    55
FILE="root.tex"
9788
wenzelm
parents: 8568
diff changeset
    56
[ "$#" -ge 1 ] && { FILE="$1"; shift; }
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    57
9788
wenzelm
parents: 8568
diff changeset
    58
[ "$#" -ne 0 ] && usage
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    59
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    60
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    61
## main
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    62
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
    63
# root file
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    64
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    65
DIR=$(dirname "$FILE")
9788
wenzelm
parents: 8568
diff changeset
    66
FILEBASE=$(basename "$FILE" .tex)
wenzelm
parents: 8568
diff changeset
    67
[ "$DIR" = . ] || FILEBASE="$DIR/$FILEBASE"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    68
8568
wenzelm
parents: 8565
diff changeset
    69
function check_root () { [ -f "$FILEBASE.tex" ] || fail "Bad file '$FILE'"; }
7794
37069d910cbe pass RC;
wenzelm
parents: 7777
diff changeset
    70
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    71
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    72
# operations
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    73
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    74
function run_latex () { $ISABELLE_LATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    75
function run_pdflatex () { $ISABELLE_PDFLATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    76
function run_bibtex () { $ISABELLE_BIBTEX </dev/null "$FILEBASE"; }
14344
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
    77
function run_makeindex () { $ISABELLE_MAKEINDEX </dev/null "$FILEBASE"; }
11845
6d9d2b1d455d dvips -q;
wenzelm
parents: 10555
diff changeset
    78
function run_dvips () { $ISABELLE_DVIPS -q -o "$FILEBASE.ps" "$FILEBASE.dvi"; }
16064
7953879aa6cf ML_idf antiquotation
haftmann
parents: 15847
diff changeset
    79
function copy_styles ()
7953879aa6cf ML_idf antiquotation
haftmann
parents: 15847
diff changeset
    80
{
16161
519d717ae9e3 improved *.sty handling
haftmann
parents: 16064
diff changeset
    81
  for STYLEFILE in "$ISABELLE_HOME/lib/texinputs"/*.sty
519d717ae9e3 improved *.sty handling
haftmann
parents: 16064
diff changeset
    82
  do
16874
wenzelm
parents: 16171
diff changeset
    83
    TARGET="$DIR"/$(basename "$STYLEFILE")
26576
fc76b7b79ba9 removed obsolete AUTO_PERL feature;
wenzelm
parents: 16874
diff changeset
    84
    perl -p -e 's/\$[I]d:?(?:\s)*([^\$]*)\$//g' "$STYLEFILE" > "$TARGET"
16161
519d717ae9e3 improved *.sty handling
haftmann
parents: 16064
diff changeset
    85
  done
16064
7953879aa6cf ML_idf antiquotation
haftmann
parents: 15847
diff changeset
    86
}
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    87
14921
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    88
function extract_syms ()
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    89
{
26576
fc76b7b79ba9 removed obsolete AUTO_PERL feature;
wenzelm
parents: 16874
diff changeset
    90
  perl -n \
40893
7d88ebdce380 isabellesym.sty: eliminated dependency on latin1, to allow documents using utf8 instead;
wenzelm
parents: 29143
diff changeset
    91
    -e '(!m,%requires, || m,%requires amssymb, || m,%requires textcomp,) && m,\\newcommand\{\\isasym(\w+)\}, && print "$1\n";' \
14921
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    92
    "$ISABELLE_HOME/lib/texinputs/isabellesym.sty" > "$DIR/syms.lst"
26576
fc76b7b79ba9 removed obsolete AUTO_PERL feature;
wenzelm
parents: 16874
diff changeset
    93
  perl -n \
14921
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    94
    -e 'm,\\newcommand\{\\isactrl(\w+)\}, && print "$1\n";' \
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    95
    "$ISABELLE_HOME/lib/texinputs/isabelle.sty" > "$DIR/ctrls.lst"
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    96
}
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    97
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    98
case "$OUTFORMAT" in
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    99
  dvi)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   100
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   101
    run_latex
9788
wenzelm
parents: 8568
diff changeset
   102
    RC="$?"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   103
    ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   104
  dvi.gz)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   105
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   106
    run_latex && \
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   107
    gzip -f "$FILEBASE.dvi"
9788
wenzelm
parents: 8568
diff changeset
   108
    RC="$?"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   109
    ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   110
  ps)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   111
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   112
    run_latex && \
26954
3a3816ca44bb proper handling of the return code for the ps-format (fixes a bug)
urbanc
parents: 26908
diff changeset
   113
    run_dvips
9788
wenzelm
parents: 8568
diff changeset
   114
    RC="$?"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   115
    ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   116
  ps.gz)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   117
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   118
    run_latex && \
26979
c58778bdf146 fixed improper handling of return code (pdf and ps.gz formats)
urbanc
parents: 26954
diff changeset
   119
    run_dvips && \
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   120
    gzip -f "$FILEBASE.ps"
9788
wenzelm
parents: 8568
diff changeset
   121
    RC="$?"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   122
    ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   123
  pdf)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   124
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   125
    run_pdflatex
9788
wenzelm
parents: 8568
diff changeset
   126
    RC="$?"
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   127
    ;;
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   128
  bbl)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   129
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   130
    run_bibtex
9788
wenzelm
parents: 8568
diff changeset
   131
    RC="$?"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   132
    ;;
14344
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
   133
  idx)
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
   134
    check_root && \
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
   135
    run_makeindex
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
   136
    RC="$?"
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
   137
    ;;
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   138
  sty)
12846
0fce95478e19 copy_styles replaces overly conservative update_styles;
wenzelm
parents: 11845
diff changeset
   139
    copy_styles
9788
wenzelm
parents: 8568
diff changeset
   140
    RC="$?"
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   141
    ;;
14921
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   142
  syms)
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   143
    extract_syms
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   144
    RC="$?"
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   145
    ;;
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   146
  *)
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   147
    fail "Bad output format '$OUTFORMAT'"
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   148
    ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   149
esac
7794
37069d910cbe pass RC;
wenzelm
parents: 7777
diff changeset
   150
9788
wenzelm
parents: 8568
diff changeset
   151
exit "$RC"