blob: 6159d6fa8f97f999f71084d68163022dd1217964 [file] [log] [blame]
Fred Drake2fe79782003-12-18 05:28:30 +00001#!/bin/sh
Skip Montanaro15f742d2003-02-13 18:30:08 +00002
3# Simple little checker for individual libref manual sections
4#
5# usage: makesec.sh section
6#
7
8# This script builds the minimal file necessary to run a single section
9# through latex, does so, then converts the resulting dvi file to ps or pdf
10# and feeds the result into a viewer. It's by no means foolproof, but seems
11# to work okay for me (knock wood). It sure beats manually commenting out
12# most of the man lib.tex file and running everything manually.
13
14# It attempts to locate an appropriate dvi converter and viewer for the
15# selected output format. It understands the following environment
16# variables:
17#
18# PYSRC - refers to the root of your build tree (dir containing Doc)
19# DVICVT - refers to a dvi converter like dvips or dvipdf
20# VIEWER - refers to an appropriate viewer for the ps/pdf file
21#
22# Of the three, only PYSRC is currently required. The other two can be set
23# to specify unusual tools which perform those tasks.
24
25# Known issues:
26# - It would be nice if the script could determine PYSRC on its own.
27# - Something about \seealso{}s blows the latex stack, so they need
28# to be commented out for now.
29
30if [ x$PYSRC = x ] ; then
31 echo "PYSRC must refer to the Python source tree" 1>&2
32 exit 1
33fi
34
35if [ ! -d $PYSRC/Doc ] ; then
36 echo "Can't find a Doc subdirectory in $PYSRC" 1>&2
37 exit 1
38fi
39
40if [ "$#" -ne 1 ] ; then
41 echo "Must specify a single libref manual section on cmd line" 1>&2
42 exit 1
43fi
44
45# settle on a dvi converter
46if [ x$DVICVT != x ] ; then
47 converter=$DVICVT
48 ext=`echo $DVICVT | sed -e 's/^dvi//'`
49 result=lib.$ext
50elif [ x`which dvipdf` != x ] ; then
51 converter=`which dvipdf`
52 ext=.pdf
53elif [ x`which dvips` != x ] ; then
54 converter=`which dvips`
55 ext=.ps
56else
57 echo "Can't find a reasonable dvi converter" 1>&2
58 echo "Set DVICVT to refer to one" 1>&2
59 exit 1
60fi
61
62# how about a viewer?
63if [ x$VIEWER != x ] ; then
64 viewer=$VIEWER
65elif [ $ext = ".ps" -a x`which gv` != x ] ; then
66 viewer=gv
67elif [ $ext = ".ps" -a x`which gs` != x ] ; then
68 viewer=gs
69elif [ $ext = ".pdf" -a x`which acroread` != x ] ; then
70 viewer=acroread
71elif [ $ext = ".pdf" -a "`uname`" = "Darwin" -a x`which open` != x ] ; then
72 viewer=open
73elif [ $ext = ".pdf" -a x`which acroread` != x ] ; then
74 viewer=acroread
75else
76 echo "Can't find a reasonable viewer" 1>&2
77 echo "Set VIEWER to refer to one" 1>&2
78 exit 1
79fi
80
81# make sure necessary links are in place
82for f in howto.cls pypaper.sty ; do
83 rm -f $f
84 ln -s $PYSRC/Doc/$f
85done
86
87export TEXINPUTS=.:$PYSRC/Doc/texinputs:
88
89# strip extension in case they gave full filename
90inp=`basename $1 .tex`
91
92# create the minimal framework necessary to run section through latex
93tmpf=lib.tex
94cat > $tmpf <<EOF
95\documentclass{manual}
96
97% NOTE: this file controls which chapters/sections of the library
98% manual are actually printed. It is easy to customize your manual
99% by commenting out sections that you are not interested in.
100
101\title{Python Library Reference}
102
103\input{boilerplate}
104
105\makeindex % tell \index to actually write the
106 % .idx file
107\makemodindex % ... and the module index as well.
108
109
110\begin{document}
111
112\maketitle
113
114\ifhtml
115\chapter*{Front Matter\label{front}}
116\fi
117
118\input{$inp}
119\end{document}
120EOF
121
122latex $tmpf
123
124$converter lib
125
126$viewer lib.pdf
127
128rm -f $tmpf howto.cls pypaper.sty *.idx *.syn
Fred Drake2fe79782003-12-18 05:28:30 +0000129rm -f lib.aux lib.log