lib/Tools/latex
author wenzelm
Wed, 01 Feb 2006 22:20:40 +0100
changeset 18888 3b643f81b378
parent 16874 3057990d20e0
child 26576 fc76b7b79ba9
permissions -rwxr-xr-x
updated;
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
#
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
     3
# $Id$
9788
wenzelm
parents: 8568
diff changeset
     4
# Author: Markus Wenzel, TU Muenchen
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
     5
#
7794
37069d910cbe pass RC;
wenzelm
parents: 7777
diff changeset
     6
# DESCRIPTION: run LaTeX (and related tools)
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
     7
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
     8
10511
wenzelm
parents: 9788
diff changeset
     9
PRG="$(basename "$0")"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    10
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    11
function usage()
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    12
{
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    13
  echo
7794
37069d910cbe pass RC;
wenzelm
parents: 7777
diff changeset
    14
  echo "Usage: $PRG [OPTIONS] [FILE]"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    15
  echo
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    16
  echo "  Options are:"
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    17
  echo "    -o FORMAT    specify output format: dvi (default), dvi.gz, ps, ps.gz,"
14921
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    18
  echo "                 pdf, bbl, png, sty, syms"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    19
  echo
7857
a49a3978fe3a tuned usage;
wenzelm
parents: 7815
diff changeset
    20
  echo "  Run LaTeX (and related tools) on FILE (default root.tex),"
a49a3978fe3a tuned usage;
wenzelm
parents: 7815
diff changeset
    21
  echo "  producing the specified output format."
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    22
  echo
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    23
  exit 1
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    24
}
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    25
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    26
function fail()
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    27
{
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    28
  echo "$1" >&2
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    29
  exit 2
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
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    33
## process command line
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    34
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    35
# options
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    36
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    37
OUTFORMAT=dvi
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    38
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    39
while getopts "o:" OPT
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    40
do
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    41
  case "$OPT" in
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    42
    o)
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    43
      OUTFORMAT="$OPTARG"
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    44
      ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    45
    \?)
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    46
      usage
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    47
      ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    48
  esac
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    49
done
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    50
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    51
shift $(($OPTIND - 1))
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    52
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    53
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    54
# args
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    55
7794
37069d910cbe pass RC;
wenzelm
parents: 7777
diff changeset
    56
FILE="root.tex"
9788
wenzelm
parents: 8568
diff changeset
    57
[ "$#" -ge 1 ] && { FILE="$1"; shift; }
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    58
9788
wenzelm
parents: 8568
diff changeset
    59
[ "$#" -ne 0 ] && usage
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    60
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    61
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    62
## main
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    63
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
    64
# root file
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    65
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    66
DIR=$(dirname "$FILE")
9788
wenzelm
parents: 8568
diff changeset
    67
FILEBASE=$(basename "$FILE" .tex)
wenzelm
parents: 8568
diff changeset
    68
[ "$DIR" = . ] || FILEBASE="$DIR/$FILEBASE"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
    69
8568
wenzelm
parents: 8565
diff changeset
    70
function check_root () { [ -f "$FILEBASE.tex" ] || fail "Bad file '$FILE'"; }
7794
37069d910cbe pass RC;
wenzelm
parents: 7777
diff changeset
    71
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    72
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    73
# operations
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    74
14921
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    75
#set by configure
15847
c05c7670f166 restored AUTO_BASH/PERL -- beware of ./configure!
wenzelm
parents: 15779
diff changeset
    76
AUTO_PERL=perl
14921
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    77
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    78
function run_latex () { $ISABELLE_LATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    79
function run_pdflatex () { $ISABELLE_PDFLATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    80
function run_bibtex () { $ISABELLE_BIBTEX </dev/null "$FILEBASE"; }
14344
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
    81
function run_makeindex () { $ISABELLE_MAKEINDEX </dev/null "$FILEBASE"; }
11845
6d9d2b1d455d dvips -q;
wenzelm
parents: 10555
diff changeset
    82
function run_dvips () { $ISABELLE_DVIPS -q -o "$FILEBASE.ps" "$FILEBASE.dvi"; }
7865
d9be8bc5624e support thumbpdf (via 'png' output format);
wenzelm
parents: 7857
diff changeset
    83
function run_thumbpdf () { [ -n "$ISABELLE_THUMBPDF" ] && $ISABELLE_THUMBPDF "$FILEBASE"; }
16064
7953879aa6cf ML_idf antiquotation
haftmann
parents: 15847
diff changeset
    84
function copy_styles ()
7953879aa6cf ML_idf antiquotation
haftmann
parents: 15847
diff changeset
    85
{
16161
519d717ae9e3 improved *.sty handling
haftmann
parents: 16064
diff changeset
    86
  for STYLEFILE in "$ISABELLE_HOME/lib/texinputs"/*.sty
519d717ae9e3 improved *.sty handling
haftmann
parents: 16064
diff changeset
    87
  do
16874
wenzelm
parents: 16171
diff changeset
    88
    TARGET="$DIR"/$(basename "$STYLEFILE")
wenzelm
parents: 16171
diff changeset
    89
    "$AUTO_PERL" -p -e 's/\$[I]d:?(?:\s)*([^\$]*)\$//g' "$STYLEFILE" > "$TARGET"
16161
519d717ae9e3 improved *.sty handling
haftmann
parents: 16064
diff changeset
    90
  done
16064
7953879aa6cf ML_idf antiquotation
haftmann
parents: 15847
diff changeset
    91
}
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
    92
14921
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    93
function extract_syms ()
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    94
{
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    95
  "$AUTO_PERL" -n \
14970
8159ade98144 more generous treatment of packages in draft prints;
wenzelm
parents: 14921
diff changeset
    96
    -e '(!m,%requires, || m,%requires latin1, || 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
    97
    "$ISABELLE_HOME/lib/texinputs/isabellesym.sty" > "$DIR/syms.lst"
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    98
  "$AUTO_PERL" -n \
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
    99
    -e 'm,\\newcommand\{\\isactrl(\w+)\}, && print "$1\n";' \
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   100
    "$ISABELLE_HOME/lib/texinputs/isabelle.sty" > "$DIR/ctrls.lst"
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   101
}
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   102
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   103
case "$OUTFORMAT" in
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   104
  dvi)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   105
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   106
    run_latex
9788
wenzelm
parents: 8568
diff changeset
   107
    RC="$?"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   108
    ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   109
  dvi.gz)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   110
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   111
    run_latex && \
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   112
    gzip -f "$FILEBASE.dvi"
9788
wenzelm
parents: 8568
diff changeset
   113
    RC="$?"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   114
    ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   115
  ps)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   116
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   117
    run_latex && \
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   118
    run_dvips &&
9788
wenzelm
parents: 8568
diff changeset
   119
    RC="$?"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   120
    ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   121
  ps.gz)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   122
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   123
    run_latex && \
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   124
    run_dvips &&
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   125
    gzip -f "$FILEBASE.ps"
9788
wenzelm
parents: 8568
diff changeset
   126
    RC="$?"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   127
    ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   128
  pdf)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   129
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   130
    run_pdflatex
9788
wenzelm
parents: 8568
diff changeset
   131
    RC="$?"
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   132
    ;;
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   133
  bbl)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   134
    check_root && \
7815
cd0fe98db185 support bibtex;
wenzelm
parents: 7794
diff changeset
   135
    run_bibtex
9788
wenzelm
parents: 8568
diff changeset
   136
    RC="$?"
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   137
    ;;
14344
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
   138
  idx)
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
   139
    check_root && \
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
   140
    run_makeindex
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
   141
    RC="$?"
0f0a2148a099 run makeindex if necessary
kleing
parents: 12846
diff changeset
   142
    ;;
7865
d9be8bc5624e support thumbpdf (via 'png' output format);
wenzelm
parents: 7857
diff changeset
   143
  png)
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   144
    check_root && \
7865
d9be8bc5624e support thumbpdf (via 'png' output format);
wenzelm
parents: 7857
diff changeset
   145
    run_thumbpdf
9788
wenzelm
parents: 8568
diff changeset
   146
    RC="$?"
7865
d9be8bc5624e support thumbpdf (via 'png' output format);
wenzelm
parents: 7857
diff changeset
   147
    ;;
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   148
  sty)
12846
0fce95478e19 copy_styles replaces overly conservative update_styles;
wenzelm
parents: 11845
diff changeset
   149
    copy_styles
9788
wenzelm
parents: 8568
diff changeset
   150
    RC="$?"
8564
37a1e855390a -o sty;
wenzelm
parents: 7865
diff changeset
   151
    ;;
14921
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   152
  syms)
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   153
    extract_syms
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   154
    RC="$?"
4ad751fa50c1 added option 'isatool latex -o syms';
wenzelm
parents: 14344
diff changeset
   155
    ;;
7772
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   156
  *)
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   157
    fail "Bad output format '$OUTFORMAT'"
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   158
    ;;
c7b2f68c79fb Isabelle wrapper for LaTeX (and friends);
wenzelm
parents:
diff changeset
   159
esac
7794
37069d910cbe pass RC;
wenzelm
parents: 7777
diff changeset
   160
9788
wenzelm
parents: 8568
diff changeset
   161
exit "$RC"