blob: b7d3629d421f90412d8f8ea5a910a28bfbb89349 [file] [log] [blame]
Guido van Rossumecae0b71996-06-26 19:03:20 +00001%
2% myformat.sty for the Python doc [updated to work with Latex2e]
3%
4
Fred Drake06f169b1998-02-11 23:08:20 +00005\NeedsTeXFormat{LaTeX2e}[1995/12/01]
6\ProvidesPackage{myformat}
Fred Drake76183c01998-02-16 22:30:10 +00007 [1998/01/11
Fred Drake06f169b1998-02-11 23:08:20 +00008 LaTeX package (Python manual markup)]
9
Fred Drake76183c01998-02-16 22:30:10 +000010% Optional packages:
11%
12% If processing of these documents fails at your TeX installation,
13% these may be commented out (independently) to make things work.
14% These are both supplied with the current version of the teTeX
15% distribution.
16%
17% The "fancyhdr" package makes nicer page footers reasonable to
18% implement, and is used to put the chapter and section information in
19% the footers.
20%
21% The "times" package makes the default font the PostScript Times
22% font, which makes for smaller PostScript and a font that more people
23% like.
24%
25\RequirePackage{fancyhdr}\typeout{Using fancier footers than usual....}
26\RequirePackage{times}\typeout{Using times fonts instead of Computer Modern.}
27
28
Guido van Rossumdaff1751997-06-02 17:35:01 +000029% Increase printable page size (copied from fullpage.sty)
30\topmargin 0pt
31\advance \topmargin by -\headheight
32\advance \topmargin by -\headsep
Fred Drake9e243091998-01-18 05:09:54 +000033
Fred Drake76183c01998-02-16 22:30:10 +000034\textheight 8.7in
Fred Drake9e243091998-01-18 05:09:54 +000035
Guido van Rossumdaff1751997-06-02 17:35:01 +000036\oddsidemargin 0pt
37\evensidemargin \oddsidemargin
38\marginparwidth 0.5in
Fred Drake9e243091998-01-18 05:09:54 +000039
Guido van Rossumdaff1751997-06-02 17:35:01 +000040\textwidth 6.5in
41
Guido van Rossum643d9321992-03-31 18:53:47 +000042% Style parameters and macros used by most documents here
Guido van Rossum5badc751992-03-06 10:55:46 +000043\raggedbottom
44\sloppy
45\parindent = 0mm
46\parskip = 2mm
47
Fred Drake76183c01998-02-16 22:30:10 +000048% uncomment the following line if you have the fancyhdr package available:
Fred Drakedc8af0a1998-02-13 06:48:05 +000049\pagestyle{empty} % start this way; change for
50\pagenumbering{roman} % ToC & chapters
51\setcounter{secnumdepth}{1}
52
Fred Drake76183c01998-02-16 22:30:10 +000053% Redefine the 'normal' header/footer style when using "fancyhdr" package:
54\@ifundefined{fancyhf}{}{
55 \fancypagestyle{normal}{%
56 \fancyhf{}%
57 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}%
58 \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}%
59 \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}%
60 \renewcommand{\headrulewidth}{0pt}%
61 \renewcommand{\footrulewidth}{0.4pt}%
62 }
63 % Update the plain style so we get the page number & footer line,
64 % but not a chapter or section title. This is to keep the first
65 % page of a chapter and the blank page between chapters `clean.'
66 \fancypagestyle{plain}{%
67 \fancyhf{}%
68 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}%
69 \renewcommand{\headrulewidth}{0pt}%
70 \renewcommand{\footrulewidth}{0.4pt}%
71 }
72 % Redefine \cleardoublepage so that the blank page between chapters
73 % gets the plain style and not the fancy style.
74 \renewcommand{\cleardoublepage}{\clearpage\if@twoside \ifodd\c@page\else
75 \hbox{}
76 \thispagestyle{plain}
77 \newpage
78 \if@twocolumn\hbox{}\newpage\fi\fi\fi}
79}
80
Fred Drake9e243091998-01-18 05:09:54 +000081% old code font selections:
82\let\codefont=\tt
83\let\sectcodefont=\tt
84
85% (Haven't found a new one that gets <, >, and _ right without being
86% monospaced.)
87
Guido van Rossum4c22cb21991-01-25 13:28:15 +000088% Variable used by begin code command
Guido van Rossum44000ed1991-01-24 16:54:29 +000089\newlength{\codewidth}
Guido van Rossum44000ed1991-01-24 16:54:29 +000090
Fred Drakedc8af0a1998-02-13 06:48:05 +000091\newcommand{\examplevspace}{2mm}
92\newcommand{\exampleindent}{1cm}
Guido van Rossum5badc751992-03-06 10:55:46 +000093% Command to start a code block (follow this by \begin{verbatim})
Fred Drakedc8af0a1998-02-13 06:48:05 +000094\newcommand{\b@code}{%
95 \begingroup%
96 \setlength{\parindent}\exampleindent%
97 % Calculate the text width for the minipage:
98 \setlength{\codewidth}{\linewidth}%
99 \addtolength{\codewidth}{-\parindent}%
100 %
101 \par%
102 \vspace\examplevspace%
103 \indent%
104 \begin{minipage}[t]{\codewidth}%
105 \small%
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000106}
107
Guido van Rossum5badc751992-03-06 10:55:46 +0000108% Command to end a code block (precede this by \end{verbatim})
Fred Drakedc8af0a1998-02-13 06:48:05 +0000109\newcommand{\e@code}{%
110 \end{minipage}%
111 \endgroup%
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000112}
Guido van Rossum5badc751992-03-06 10:55:46 +0000113
Fred Drakedc8af0a1998-02-13 06:48:05 +0000114\let\OldVerbatim=\verbatim
115\let\OldEndVerbatim=\endverbatim
116\renewcommand{\verbatim}{\b@code\OldVerbatim}
117\renewcommand{\endverbatim}{\OldEndVerbatim\e@code}
118
119% Augment the sectioning commands used to get our own font family in
120% place:
121\newcommand{\HeaderFamily}{\sffamily}
122\renewcommand{\section}{\@startsection {section}{1}{\z@}%
123 {-3.5ex \@plus -1ex \@minus -.2ex}%
124 {2.3ex \@plus.2ex}%
125 {\reset@font\Large\HeaderFamily}}
126\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
127 {-3.25ex\@plus -1ex \@minus -.2ex}%
128 {1.5ex \@plus .2ex}%
129 {\reset@font\large\HeaderFamily}}
130\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
131 {-3.25ex\@plus -1ex \@minus -.2ex}%
132 {1.5ex \@plus .2ex}%
133 {\reset@font\normalsize\HeaderFamily}}
134\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
135 {3.25ex \@plus1ex \@minus.2ex}%
136 {-1em}%
137 {\reset@font\normalsize\HeaderFamily}}
138\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
139 {3.25ex \@plus1ex \@minus .2ex}%
140 {-1em}%
141 {\reset@font\normalsize\HeaderFamily}}
142
143
Guido van Rossumecae0b71996-06-26 19:03:20 +0000144% Underscore hack (only act like subscript operator if in math mode)
145%
146% The following is due to Mark Wooding (the old version didn't work with
147% Latex 2e.
148
149\DeclareRobustCommand\hackscore{%
150 \ifmmode_\else\textunderscore\fi%
151}
152\begingroup
153\catcode`\_\active
154\def\next{%
155 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
156}
157\expandafter\endgroup\next
158
159%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000160% This is the old hack, which didn't work with 2e.
161% You should not need this since the rest of the documentation is now
162% LaTeX2e-only.
Guido van Rossumecae0b71996-06-26 19:03:20 +0000163%
164%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
165%\catcode`\_=12
166%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
Guido van Rossum5badc751992-03-06 10:55:46 +0000167
Fred Drakeb37a3951998-02-06 22:52:52 +0000168
Fred Drakedc8af0a1998-02-13 06:48:05 +0000169
Fred Drakeb37a3951998-02-06 22:52:52 +0000170%% Lots of index-entry generation support.
171
Fred Drakedc8af0a1998-02-13 06:48:05 +0000172% Command to wrap around stuff that refers to function / module /
173% attribute names in the index. Default behavior: like \code{}. To
174% just keep the index entries in the roman font, uncomment the second
175% definition to use instead; it matches O'Reilly style more.
176%
Fred Drakeb37a3951998-02-06 22:52:52 +0000177\newcommand{\idxcode}[1]{\codefont{#1}}
178%\renewcommand{\idxcode}[1]{#1}
Guido van Rossum5badc751992-03-06 10:55:46 +0000179
180% Command to generate two index entries (using subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +0000181\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000182
183% And three entries (using only one level of subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +0000184\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000185
186% And four (again, using only one level of subentries)
187\newcommand{\indexiv}[4]{
188\index{#1!#2 #3 #4}
189\index{#2!#3 #4, #1}
190\index{#3!#4, #1 #2}
191\index{#4!#1 #2 #3}
192}
193
Fred Drakedc8af0a1998-02-13 06:48:05 +0000194% Command to generate a reference to a function, statement, keyword,
195% operator.
Fred Drakeb37a3951998-02-06 22:52:52 +0000196\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
197\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
198\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Guido van Rossum6886c831992-04-03 14:44:27 +0000199\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakeb37a3951998-02-06 22:52:52 +0000200\newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1}} (built-in function)}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000201
202% Add an index entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000203\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake4af18141997-12-15 22:08:14 +0000204\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000205\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
206\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
207
Fred Drakeda941ef1998-01-02 02:57:41 +0000208% support for the module index
209\newwrite\modindexfile
210\openout\modindexfile=modules.idx
211
Fred Drake207e57b1997-12-15 21:37:45 +0000212% Add the defining entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000213\newcommand{\defmodindex}[2]{%
214 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
Fred Drakeda941ef1998-01-02 02:57:41 +0000215 \write\modindexfile{#1 \thepage}}
Fred Drakeb1927471998-02-04 14:43:36 +0000216\newcommand{\modindex}[1]{\defmodindex{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000217\newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }}
218\newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }}
Guido van Rossum5badc751992-03-06 10:55:46 +0000219
220% Additional string for an index entry
Fred Drakedc8af0a1998-02-13 06:48:05 +0000221\newcommand{\index@subitem}{}
222\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
223\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000224
Guido van Rossum5badc751992-03-06 10:55:46 +0000225
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000226% from user-level, fulllineitems should be called as an environment
227\def\fulllineitems{\list{}{\labelwidth \leftmargin \labelsep 0pt
228\rightmargin 0pt \topsep -\parskip \partopsep \parskip
229\itemsep -\parsep
230\let\makelabel\itemnewline}}
231\let\endfulllineitems\endlist
232
233
Guido van Rossum36f35021997-05-22 20:43:24 +0000234% cfuncdesc should be called as
235% \begin{cfuncdesc}{type}{name}{arglist}
236% ... description ...
237% \end{cfuncdesc}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000238\newcommand{\cfuncline}[3]{\item[\code{#1 \bfcode{#2}(\varvars{#3})}]\ttindex{#2}}
Fred Drakeeb33c781996-10-29 15:55:08 +0000239\newcommand{\cfuncdesc}[3]{\fulllineitems\cfuncline{#1}{#2}{#3}}
240\let\endcfuncdesc\endfulllineitems
241
Fred Drakedc8af0a1998-02-13 06:48:05 +0000242\newcommand{\cvarline}[2]{\item[\code{#1 \bfcode{#2}}]\ttindex{#2}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000243\newcommand{\cvardesc}[2]{\fulllineitems\cvarline{#1}{#2}}
244\let\endcvardesc\endfulllineitems
245
Fred Drakedc8af0a1998-02-13 06:48:05 +0000246\newcommand{\ctypeline}[1]{\item[\bfcode{#1}]\ttindex{#1}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000247\newcommand{\ctypedesc}[1]{\fulllineitems\ctypeline{#1}}
248\let\endctypedesc\endfulllineitems
249
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000250% funcdesc should be called as an \begin{funcdesc} ... \end{funcdesc}
Fred Drakeaebc6f31998-02-13 14:34:04 +0000251\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000252\newcommand{\funcdesc}[2]{\fulllineitems\funcline{#1}{#2}}
253\let\endfuncdesc\endfulllineitems
Fred Drakedc8af0a1998-02-13 06:48:05 +0000254\newcommand{\optional}[1]{{\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000255
Fred Drakeaebc6f31998-02-13 14:34:04 +0000256% similar to {funcdesc}, but doesn't add to the index
257\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
258\newcommand{\funcdescni}[2]{\fulllineitems\funclineni{#1}{#2}}
259\let\endfuncdescni\endfulllineitems
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000260
261% same for excdesc
Fred Drakedc8af0a1998-02-13 06:48:05 +0000262\newcommand{\excline}[1]{\item[\bfcode{#1}]\ttindex{#1}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000263\newcommand{\excdesc}[1]{\fulllineitems\excline{#1}}
264\let\endexcdesc\endfulllineitems
265
266% same for datadesc
Fred Drakeaebc6f31998-02-13 14:34:04 +0000267\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000268\newcommand{\datadesc}[1]{\fulllineitems\dataline{#1}}
269\let\enddatadesc\endfulllineitems
270
Fred Drakeaebc6f31998-02-13 14:34:04 +0000271% similar to {datadesc}, but doesn't add to the index
272\newcommand{\datalineni}[1]{\item[\bfcode{#1}]}
273\newcommand{\datadescni}[1]{\fulllineitems\datalineni{#1}}
274\let\enddatadescni\endfulllineitems
275
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000276
Fred Drakea610f9f1997-12-03 03:42:39 +0000277% opcodedesc should be called as an \begin{opcodedesc} ... \end{opcodedesc}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000278\newcommand{\opcodeline}[2]{\item[\bfcode{#1}\quad\var{#2}]}
Fred Drakea610f9f1997-12-03 03:42:39 +0000279\newcommand{\opcodedesc}[2]{\fulllineitems\opcodeline{#1}{#2}}
280\let\endopcodedesc\endfulllineitems
281
282
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000283\let\nodename=\label
284
Fred Drakedc8af0a1998-02-13 06:48:05 +0000285% For these commands, use \command{} to get the typography right, not
286% {\command}. This works better with the texinfo translation.
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000287\newcommand{\ABC}{{\sc abc}}
288\newcommand{\UNIX}{{\sc Unix}}
Fred Drake311c1961998-01-20 05:07:19 +0000289\newcommand{\POSIX}{POSIX}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000290\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000291\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000292\newcommand{\C}{C}
293\newcommand{\EOF}{{\sc eof}}
Guido van Rossum9231c8f1997-05-15 21:43:21 +0000294\newcommand{\NULL}{\code{NULL}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000295
296% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000297\newcommand{\code}[1]{{\@vobeyspaces\@noligs\def\{{\char`\{}\def\}{\char`\}}\def\~{\char`\~}\def\^{\char`\^}\def\e{\char`\\}\def\${\char`\$}\def\#{\char`\#}\def\&{\char`\&}\def\%{\char`\%}%
Fred Drake9e243091998-01-18 05:09:54 +0000298\mbox{\codefont{#1}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000299
Fred Drakedc8af0a1998-02-13 06:48:05 +0000300\newcommand{\bfcode}[1]{\code{\bfseries#1}} %bold-faced code font
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000301\newcommand{\kbd}[1]{\mbox{\tt #1}}
302\newcommand{\key}[1]{\mbox{\tt #1}}
303\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000304% This weird definition of \var{} allows it to always appear in roman
305% italics, and won't get funky in code fragments when we play around
306% with fonts.
307\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
Guido van Rossum45416021995-03-30 16:00:58 +0000308\newcommand{\dfn}[1]{{\em #1\/}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000309\renewcommand{\emph}[1]{{\em #1\/}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000310\newcommand{\strong}[1]{{\bf #1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000311% let's experiment with a new font:
Fred Drakedc8af0a1998-02-13 06:48:05 +0000312\newcommand{\file}[1]{\mbox{`\small\textsf{#1}'}}
Fred Drake53740451998-02-17 15:13:01 +0000313%\@ifundefined{pdfannotlink}{%
314 \newcommand{\url}[1]{\mbox{\small\textsf{#1}}}%
315%}{
316% \newcommand{\url}[1]{{%
317% \pdfannotlink user{/S /URI /URI (#1)}%
318% \mbox{\small\textsf{#1}}}}%
319%}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000320\let\email=\url
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000321
Fred Drake9b550d91996-11-11 20:43:46 +0000322\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000323
324\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000325\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000326
Fred Drakedc8af0a1998-02-13 06:48:05 +0000327% These should be used for all references to identifiers which are
328% used to refer to instances of specific language constructs. See the
329% names for specific semantic assignments.
Fred Drake311c1961998-01-20 05:07:19 +0000330%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000331% For now, don't do anything really fancy with them; just use them as
332% logical markup. This might change in the future.
Fred Drake311c1961998-01-20 05:07:19 +0000333%
334\let\module=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000335\let\keyword=\code
336\let\exception=\code
Fred Drake311c1961998-01-20 05:07:19 +0000337\let\class=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000338\let\function=\code
339\let\cfunction=\code
340\let\method=\code
341
342% constants defined in Python modules, not language constants:
343\let\constant=\code
Fred Drake311c1961998-01-20 05:07:19 +0000344
345\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake06f169b1998-02-11 23:08:20 +0000346\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000347\newcommand{\program}[1]{\strong{#1}}
Fred Drake311c1961998-01-20 05:07:19 +0000348
349
Guido van Rossume7af5a01994-08-01 12:39:35 +0000350\newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3&#4\\
351\hline}{\hline\end{tabular}\end{center}}
352
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000353\newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3&#4&#5\\
354\hline}{\hline\end{tabular}\end{center}}
355
356\newcommand{\itemnewline}[1]{\@tempdima\linewidth
357\advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}}
358
Fred Drake9e243091998-01-18 05:09:54 +0000359\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000360
361% Cross-referencing (AMK)
362% Sample usage:
363% \begin{seealso}
364% \seemodule{rand}{Uniform random number generator}; % Module xref
Fred Drakedc8af0a1998-02-13 06:48:05 +0000365% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000366% \end{seealso}
367
Fred Drakedc8af0a1998-02-13 06:48:05 +0000368\newenvironment{seealso}[0]{\strong{See Also:}\par}{\par}
Fred Drakeaebc6f31998-02-13 14:34:04 +0000369\newcommand{\seemodule}[2]{\ref{module-#1}:%
370 \quad Module \module{#1}\quad(#2)}
371\newcommand{\seebimodule}[2]{\ref{module-#1}:%
372 \quad Built-in Module \module{#1}\quad(#2)}
373\newcommand{\seestmodule}[2]{\ref{module-#1}:%
374 \quad Standard Module \module{#1}\quad(#2)}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000375\newcommand{\seetext}[1]{\par{#1}}
Fred Drakeda941ef1998-01-02 02:57:41 +0000376
Fred Drakedc8af0a1998-02-13 06:48:05 +0000377% Fix the theindex environment to add an entry to the Table of
378% Contents; this is much nicer than just having to jump to the end of
379% the book and flip around, especially with multiple indexes.
Fred Drakeda941ef1998-01-02 02:57:41 +0000380%
381\let\OldTheindex=\theindex
Fred Drake06f169b1998-02-11 23:08:20 +0000382\renewcommand{\theindex}{%
Fred Drakef1a41501998-02-16 05:30:27 +0000383 \cleardoublepage%
Fred Drakeda941ef1998-01-02 02:57:41 +0000384 \OldTheindex%
385 \addcontentsline{toc}{chapter}{\indexname}%
386}
Fred Drake031ad4b1998-01-09 05:34:23 +0000387
388% Use a similar trick to catch the end of the {abstract} environment,
389% but here make sure the abstract is followed by a blank page if the
390% 'openright' option is used.
391%
392\let\OldEndAbstract=\endabstract
Fred Drake06f169b1998-02-11 23:08:20 +0000393\renewcommand{\endabstract}{
Fred Drake737e73e1998-01-13 22:40:08 +0000394 \if@openright
395 \ifodd\value{page}
396 \typeout{Adding blank page after the abstract.}
397 \vfil\pagebreak
Fred Drake031ad4b1998-01-09 05:34:23 +0000398 \fi
Fred Drake737e73e1998-01-13 22:40:08 +0000399 \fi
400 \OldEndAbstract
Fred Drake031ad4b1998-01-09 05:34:23 +0000401}
402
Fred Drakedc8af0a1998-02-13 06:48:05 +0000403% This wraps the \tableofcontents macro with all the magic to get the
404% spacing right and have the right number of pages if the 'openright'
Fred Drake031ad4b1998-01-09 05:34:23 +0000405% option has been used. This eliminates a fair amount of crud in the
406% individual document files.
407%
Fred Drake737e73e1998-01-13 22:40:08 +0000408\let\OldTableofcontents=\tableofcontents
Fred Drake06f169b1998-02-11 23:08:20 +0000409\renewcommand{\tableofcontents}[0]{%
410 \setcounter{page}{1}%
411 \pagebreak%
412 \pagestyle{plain}%
413 {%
414 \parskip = 0mm%
415 \OldTableofcontents%
416 \if@openright%
417 \ifodd\value{page}%
418 \typeout{Adding blank page after the table of contents.}%
419 \pagebreak\hspace{0pt}%
420 \fi%
421 \fi%
422 }%
Fred Drake4c689631998-02-13 16:58:49 +0000423 \cleardoublepage%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000424 \pagenumbering{arabic}%
Fred Drake76183c01998-02-16 22:30:10 +0000425 \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
Fred Drake06f169b1998-02-11 23:08:20 +0000426}
427
Fred Drakedc8af0a1998-02-13 06:48:05 +0000428% Allow the release number to be specified independently of the
429% \date{}. This allows the date to reflect the document's date and
430% release to specify the Python release that is documented.
431%
Fred Drake06f169b1998-02-11 23:08:20 +0000432\newcommand{\@release}{}
433\newcommand{\version}{}
434\newcommand{\releasename}{Release}
435\newcommand{\release}[1]{%
436 \renewcommand{\@release}{\releasename\space\version}%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000437 \renewcommand{\version}{#1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000438
Fred Drakedc8af0a1998-02-13 06:48:05 +0000439% Allow specification of the author's address separately from the
440% author's name. This can be used to format them differently, which
441% is a good thing.
442%
Fred Drake06f169b1998-02-11 23:08:20 +0000443\newcommand{\@authoraddress}{}
444\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
445
Fred Drakedc8af0a1998-02-13 06:48:05 +0000446% Change the title page to look a bit better, and fit in with the
447% fncychap ``Bjarne'' style a bit better.
448%
Fred Drake06f169b1998-02-11 23:08:20 +0000449\renewcommand{\maketitle}{\begin{titlepage}%
450 \let\footnotesize\small
451 \let\footnoterule\relax
452 \@ifundefined{ChTitleVar}{}{%
453 \mghrulefill{\RW}}%
Fred Drake53740451998-02-17 15:13:01 +0000454 \@ifundefined{pdfinfo}{}{
455 \pdfinfo
456 author {\@author}
457 title {\@title}
458 }
Fred Drake06f169b1998-02-11 23:08:20 +0000459 \begin{flushright}%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000460 {\rm\Huge\HeaderFamily \@title \par}%
461 {\em\LARGE\HeaderFamily \@release \par}
Fred Drake06f169b1998-02-11 23:08:20 +0000462 \vfill
Fred Drakedc8af0a1998-02-13 06:48:05 +0000463 {\LARGE\HeaderFamily \@author \par}
Fred Drake06f169b1998-02-11 23:08:20 +0000464 \vfill\vfill
465 {\large
466 \@date \par
467 \vskip 3em
468 \@authoraddress \par
469 }%
470 \end{flushright}%\par
471 \@thanks
472 \end{titlepage}%
473 \setcounter{footnote}{0}%
474 \let\thanks\relax\let\maketitle\relax
475 \gdef\@thanks{}\gdef\@author{}\gdef\@title{}
476}
477
Fred Drakedc8af0a1998-02-13 06:48:05 +0000478% ``minitoc'' support; works fairly well but not all chapters do well
479% with it. Has some weird side effects that I haven't tracked down;
480% don't use it for real at this time.
Fred Drake06f169b1998-02-11 23:08:20 +0000481%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000482% To enable, uncomment the following line only (don't do it!):
Fred Drake06f169b1998-02-11 23:08:20 +0000483%\RequirePackage{minitoc}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000484%
485% Maybe this should all be removed. But I think something like this
486% would be really nice if it can be integrated with the ``list of
487% modules'' at the top of module-documentation chapters. But it might
488% require a completely new environment, perhaps based on {list}.
Fred Drake06f169b1998-02-11 23:08:20 +0000489
490% Leave the rest as-is:
491\newif\if@minitocprinted
492\newcommand{\suppressminitoc}{\@minitocprintedtrue}
493\@ifundefined{minitoc}{
494 % allow \minitoc to be used even if the package hasn't been loaded.
495 \newcommand{\minitoc}{\@minitocprintedtrue}
496}{
497 \dominitoc
498 \newif\if@firstsection
499 \let\OldChapter=\chapter
500 \let\OldSection=\section
501 \let\OldMinitoc=\minitoc
502 % This will only include the minitoc once per chapter
503 \renewcommand{\minitoc}{%
504 \if@minitocprinted{}\else%
505 \OldMinitoc%
506 \@minitocprintedtrue%
507 \fi%
Fred Drake031ad4b1998-01-09 05:34:23 +0000508 }
Fred Drake06f169b1998-02-11 23:08:20 +0000509 % This includes a minitoc before the first \section{}, if it hasn't
510 % already been printed using an explicit \minitoc call.
511 \newcommand{\NewSection}[1]{%
512 \if@firstsection%
513 \if@minitocprinted{}\else%
514 \vskip 15pt%
515 \minitoc%
516 \@firstsectionfalse%
517 \fi%
518 \fi%
519 \OldSection{#1}%
520 }
521 % Reset the flags for each chaper to let the automatic stuff work.
522 \newcommand{\NewChapter}[1]{%
523 \OldChapter{#1}%
524 \@firstsectiontrue%
525 \@minitocprintedfalse%
526 }
527 \let\chapter=\NewChapter
528 \let\section=\NewSection
529 \typeout{Including mini Tables of Contents in each chapter.}
530}
531
Fred Drakedc8af0a1998-02-13 06:48:05 +0000532% This sets up the fancy chapter headings that make the documents look
533% at least a little better than the usual LaTeX output.
Fred Drake06f169b1998-02-11 23:08:20 +0000534%
535\RequirePackage[Bjarne]{fncychap}
536\@ifundefined{ChTitleVar}{}{
Fred Drakedc8af0a1998-02-13 06:48:05 +0000537 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
538 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
539 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
Fred Drake06f169b1998-02-11 23:08:20 +0000540 % This creates chapter heads without the leading \vspace*{}:
541 \def\@makechapterhead#1{%
542 {\parindent \z@ \raggedright \normalfont
543 \ifnum \c@secnumdepth >\m@ne
544 \DOCH
545 \fi
546 \interlinepenalty\@M
547 \DOTI{#1}
548 }
549 }
550 \typeout{Using fancy chapter headings.}
Fred Drake031ad4b1998-01-09 05:34:23 +0000551}