summaryrefslogtreecommitdiffstats
path: root/Doc/tools/makesec.sh
blob: 6159d6fa8f97f999f71084d68163022dd1217964 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh

# Simple little checker for individual libref manual sections
#
# usage: makesec.sh section
#

# This script builds the minimal file necessary to run a single section
# through latex, does so, then converts the resulting dvi file to ps or pdf
# and feeds the result into a viewer.  It's by no means foolproof, but seems
# to work okay for me (knock wood).  It sure beats manually commenting out
# most of the man lib.tex file and running everything manually.

# It attempts to locate an appropriate dvi converter and viewer for the
# selected output format.  It understands the following environment
# variables:
#
#	PYSRC - refers to the root of your build tree (dir containing Doc)
#	DVICVT - refers to a dvi converter like dvips or dvipdf
#	VIEWER - refers to an appropriate viewer for the ps/pdf file
#
# Of the three, only PYSRC is currently required.  The other two can be set
# to specify unusual tools which perform those tasks.

# Known issues:
#   - It would be nice if the script could determine PYSRC on its own.
#   - Something about \seealso{}s blows the latex stack, so they need
#     to be commented out for now.

if [ x$PYSRC = x ] ; then
    echo "PYSRC must refer to the Python source tree" 1>&2
    exit 1
fi

if [ ! -d $PYSRC/Doc ] ; then
    echo "Can't find a Doc subdirectory in $PYSRC" 1>&2
    exit 1
fi

if [ "$#" -ne 1 ] ; then
    echo "Must specify a single libref manual section on cmd line" 1>&2
    exit 1
fi

# settle on a dvi converter
if [ x$DVICVT != x ] ; then
    converter=$DVICVT
    ext=`echo $DVICVT | sed -e 's/^dvi//'`
    result=lib.$ext
elif [ x`which dvipdf` != x ] ; then
    converter=`which dvipdf`
    ext=.pdf
elif [ x`which dvips` != x ] ; then
    converter=`which dvips`
    ext=.ps
else
    echo "Can't find a reasonable dvi converter" 1>&2
    echo "Set DVICVT to refer to one" 1>&2
    exit 1
fi

# how about a viewer?
if [ x$VIEWER != x ] ; then
    viewer=$VIEWER
elif [ $ext = ".ps" -a x`which gv` != x ] ; then
    viewer=gv
elif [ $ext = ".ps" -a x`which gs` != x ] ; then
    viewer=gs
elif [ $ext = ".pdf" -a x`which acroread` != x ] ; then
    viewer=acroread
elif [ $ext = ".pdf" -a "`uname`" = "Darwin" -a x`which open` != x ] ; then
    viewer=open
elif [ $ext = ".pdf" -a x`which acroread` != x ] ; then
    viewer=acroread
else
    echo "Can't find a reasonable viewer" 1>&2
    echo "Set VIEWER to refer to one" 1>&2
    exit 1
fi

# make sure necessary links are in place
for f in howto.cls pypaper.sty ; do
    rm -f $f
    ln -s $PYSRC/Doc/$f
done

export TEXINPUTS=.:$PYSRC/Doc/texinputs:

# strip extension in case they gave full filename
inp=`basename $1 .tex`

# create the minimal framework necessary to run section through latex
tmpf=lib.tex
cat > $tmpf <<EOF
\documentclass{manual}

% NOTE: this file controls which chapters/sections of the library
% manual are actually printed.  It is easy to customize your manual
% by commenting out sections that you are not interested in.

\title{Python Library Reference}

\input{boilerplate}

\makeindex                      % tell \index to actually write the
                                % .idx file
\makemodindex                   % ... and the module index as well.


\begin{document}

\maketitle

\ifhtml
\chapter*{Front Matter\label{front}}
\fi

\input{$inp}
\end{document}
EOF

latex $tmpf

$converter lib

$viewer lib.pdf

rm -f $tmpf howto.cls pypaper.sty *.idx *.syn
rm -f lib.aux lib.log