blob: 6e6fa6d0aee1ce8746abf07c11a02ceb6397712b [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
Fred Drake30d17821998-02-17 15:56:55 +000029% for PDF output, use maximal compression:
30\@ifundefined{pdfannotlink}{}{\pdfcompresslevel=9}
31
Guido van Rossumdaff1751997-06-02 17:35:01 +000032% Increase printable page size (copied from fullpage.sty)
33\topmargin 0pt
34\advance \topmargin by -\headheight
35\advance \topmargin by -\headsep
Fred Drake9e243091998-01-18 05:09:54 +000036
Fred Drake76183c01998-02-16 22:30:10 +000037\textheight 8.7in
Fred Drake9e243091998-01-18 05:09:54 +000038
Guido van Rossumdaff1751997-06-02 17:35:01 +000039\oddsidemargin 0pt
40\evensidemargin \oddsidemargin
41\marginparwidth 0.5in
Fred Drake9e243091998-01-18 05:09:54 +000042
Guido van Rossumdaff1751997-06-02 17:35:01 +000043\textwidth 6.5in
44
Guido van Rossum643d9321992-03-31 18:53:47 +000045% Style parameters and macros used by most documents here
Guido van Rossum5badc751992-03-06 10:55:46 +000046\raggedbottom
47\sloppy
48\parindent = 0mm
49\parskip = 2mm
50
Fred Drake76183c01998-02-16 22:30:10 +000051% uncomment the following line if you have the fancyhdr package available:
Fred Drakedc8af0a1998-02-13 06:48:05 +000052\pagestyle{empty} % start this way; change for
53\pagenumbering{roman} % ToC & chapters
54\setcounter{secnumdepth}{1}
55
Fred Drake76183c01998-02-16 22:30:10 +000056% Redefine the 'normal' header/footer style when using "fancyhdr" package:
57\@ifundefined{fancyhf}{}{
58 \fancypagestyle{normal}{%
59 \fancyhf{}%
60 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}%
61 \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}%
62 \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}%
63 \renewcommand{\headrulewidth}{0pt}%
64 \renewcommand{\footrulewidth}{0.4pt}%
65 }
66 % Update the plain style so we get the page number & footer line,
67 % but not a chapter or section title. This is to keep the first
68 % page of a chapter and the blank page between chapters `clean.'
69 \fancypagestyle{plain}{%
70 \fancyhf{}%
71 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}%
72 \renewcommand{\headrulewidth}{0pt}%
73 \renewcommand{\footrulewidth}{0.4pt}%
74 }
75 % Redefine \cleardoublepage so that the blank page between chapters
76 % gets the plain style and not the fancy style.
77 \renewcommand{\cleardoublepage}{\clearpage\if@twoside \ifodd\c@page\else
78 \hbox{}
79 \thispagestyle{plain}
80 \newpage
81 \if@twocolumn\hbox{}\newpage\fi\fi\fi}
82}
83
Fred Drake9e243091998-01-18 05:09:54 +000084% old code font selections:
85\let\codefont=\tt
86\let\sectcodefont=\tt
87
88% (Haven't found a new one that gets <, >, and _ right without being
89% monospaced.)
90
Guido van Rossum4c22cb21991-01-25 13:28:15 +000091% Variable used by begin code command
Guido van Rossum44000ed1991-01-24 16:54:29 +000092\newlength{\codewidth}
Guido van Rossum44000ed1991-01-24 16:54:29 +000093
Fred Drakedc8af0a1998-02-13 06:48:05 +000094\newcommand{\examplevspace}{2mm}
95\newcommand{\exampleindent}{1cm}
Guido van Rossum5badc751992-03-06 10:55:46 +000096% Command to start a code block (follow this by \begin{verbatim})
Fred Drakedc8af0a1998-02-13 06:48:05 +000097\newcommand{\b@code}{%
98 \begingroup%
99 \setlength{\parindent}\exampleindent%
100 % Calculate the text width for the minipage:
101 \setlength{\codewidth}{\linewidth}%
102 \addtolength{\codewidth}{-\parindent}%
103 %
104 \par%
105 \vspace\examplevspace%
106 \indent%
107 \begin{minipage}[t]{\codewidth}%
108 \small%
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000109}
110
Guido van Rossum5badc751992-03-06 10:55:46 +0000111% Command to end a code block (precede this by \end{verbatim})
Fred Drakedc8af0a1998-02-13 06:48:05 +0000112\newcommand{\e@code}{%
113 \end{minipage}%
114 \endgroup%
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000115}
Guido van Rossum5badc751992-03-06 10:55:46 +0000116
Fred Drakedc8af0a1998-02-13 06:48:05 +0000117\let\OldVerbatim=\verbatim
118\let\OldEndVerbatim=\endverbatim
119\renewcommand{\verbatim}{\b@code\OldVerbatim}
120\renewcommand{\endverbatim}{\OldEndVerbatim\e@code}
121
122% Augment the sectioning commands used to get our own font family in
123% place:
124\newcommand{\HeaderFamily}{\sffamily}
125\renewcommand{\section}{\@startsection {section}{1}{\z@}%
126 {-3.5ex \@plus -1ex \@minus -.2ex}%
127 {2.3ex \@plus.2ex}%
128 {\reset@font\Large\HeaderFamily}}
129\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
130 {-3.25ex\@plus -1ex \@minus -.2ex}%
131 {1.5ex \@plus .2ex}%
132 {\reset@font\large\HeaderFamily}}
133\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
134 {-3.25ex\@plus -1ex \@minus -.2ex}%
135 {1.5ex \@plus .2ex}%
136 {\reset@font\normalsize\HeaderFamily}}
137\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
138 {3.25ex \@plus1ex \@minus.2ex}%
139 {-1em}%
140 {\reset@font\normalsize\HeaderFamily}}
141\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
142 {3.25ex \@plus1ex \@minus .2ex}%
143 {-1em}%
144 {\reset@font\normalsize\HeaderFamily}}
145
146
Guido van Rossumecae0b71996-06-26 19:03:20 +0000147% Underscore hack (only act like subscript operator if in math mode)
148%
149% The following is due to Mark Wooding (the old version didn't work with
150% Latex 2e.
151
152\DeclareRobustCommand\hackscore{%
153 \ifmmode_\else\textunderscore\fi%
154}
155\begingroup
156\catcode`\_\active
157\def\next{%
158 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
159}
160\expandafter\endgroup\next
161
162%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000163% This is the old hack, which didn't work with 2e.
164% You should not need this since the rest of the documentation is now
165% LaTeX2e-only.
Guido van Rossumecae0b71996-06-26 19:03:20 +0000166%
167%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
168%\catcode`\_=12
169%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
Guido van Rossum5badc751992-03-06 10:55:46 +0000170
Fred Drakeb37a3951998-02-06 22:52:52 +0000171
Fred Drakedc8af0a1998-02-13 06:48:05 +0000172
Fred Drakeb37a3951998-02-06 22:52:52 +0000173%% Lots of index-entry generation support.
174
Fred Drakedc8af0a1998-02-13 06:48:05 +0000175% Command to wrap around stuff that refers to function / module /
176% attribute names in the index. Default behavior: like \code{}. To
177% just keep the index entries in the roman font, uncomment the second
178% definition to use instead; it matches O'Reilly style more.
179%
Fred Drakeb37a3951998-02-06 22:52:52 +0000180\newcommand{\idxcode}[1]{\codefont{#1}}
181%\renewcommand{\idxcode}[1]{#1}
Guido van Rossum5badc751992-03-06 10:55:46 +0000182
183% Command to generate two index entries (using subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +0000184\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000185
186% And three entries (using only one level of subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +0000187\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000188
189% And four (again, using only one level of subentries)
190\newcommand{\indexiv}[4]{
191\index{#1!#2 #3 #4}
192\index{#2!#3 #4, #1}
193\index{#3!#4, #1 #2}
194\index{#4!#1 #2 #3}
195}
196
Fred Drakedc8af0a1998-02-13 06:48:05 +0000197% Command to generate a reference to a function, statement, keyword,
198% operator.
Fred Drakeb37a3951998-02-06 22:52:52 +0000199\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
200\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
201\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Guido van Rossum6886c831992-04-03 14:44:27 +0000202\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakeb37a3951998-02-06 22:52:52 +0000203\newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1}} (built-in function)}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000204
205% Add an index entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000206\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake4af18141997-12-15 22:08:14 +0000207\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000208\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
209\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
210
Fred Drakeda941ef1998-01-02 02:57:41 +0000211% support for the module index
212\newwrite\modindexfile
213\openout\modindexfile=modules.idx
214
Fred Drake207e57b1997-12-15 21:37:45 +0000215% Add the defining entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000216\newcommand{\defmodindex}[2]{%
217 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
Fred Drakeda941ef1998-01-02 02:57:41 +0000218 \write\modindexfile{#1 \thepage}}
Fred Drakeb1927471998-02-04 14:43:36 +0000219\newcommand{\modindex}[1]{\defmodindex{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000220\newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }}
221\newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }}
Guido van Rossum5badc751992-03-06 10:55:46 +0000222
223% Additional string for an index entry
Fred Drakedc8af0a1998-02-13 06:48:05 +0000224\newcommand{\index@subitem}{}
225\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
226\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000227
Guido van Rossum5badc751992-03-06 10:55:46 +0000228
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000229% from user-level, fulllineitems should be called as an environment
230\def\fulllineitems{\list{}{\labelwidth \leftmargin \labelsep 0pt
231\rightmargin 0pt \topsep -\parskip \partopsep \parskip
232\itemsep -\parsep
233\let\makelabel\itemnewline}}
234\let\endfulllineitems\endlist
235
236
Guido van Rossum36f35021997-05-22 20:43:24 +0000237% cfuncdesc should be called as
238% \begin{cfuncdesc}{type}{name}{arglist}
239% ... description ...
240% \end{cfuncdesc}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000241\newcommand{\cfuncline}[3]{\item[\code{#1 \bfcode{#2}(\varvars{#3})}]\ttindex{#2}}
Fred Drakeeb33c781996-10-29 15:55:08 +0000242\newcommand{\cfuncdesc}[3]{\fulllineitems\cfuncline{#1}{#2}{#3}}
243\let\endcfuncdesc\endfulllineitems
244
Fred Drakedc8af0a1998-02-13 06:48:05 +0000245\newcommand{\cvarline}[2]{\item[\code{#1 \bfcode{#2}}]\ttindex{#2}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000246\newcommand{\cvardesc}[2]{\fulllineitems\cvarline{#1}{#2}}
247\let\endcvardesc\endfulllineitems
248
Fred Drakedc8af0a1998-02-13 06:48:05 +0000249\newcommand{\ctypeline}[1]{\item[\bfcode{#1}]\ttindex{#1}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000250\newcommand{\ctypedesc}[1]{\fulllineitems\ctypeline{#1}}
251\let\endctypedesc\endfulllineitems
252
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000253% funcdesc should be called as an \begin{funcdesc} ... \end{funcdesc}
Fred Drakeaebc6f31998-02-13 14:34:04 +0000254\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000255\newcommand{\funcdesc}[2]{\fulllineitems\funcline{#1}{#2}}
256\let\endfuncdesc\endfulllineitems
Fred Drakedc8af0a1998-02-13 06:48:05 +0000257\newcommand{\optional}[1]{{\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000258
Fred Drakeaebc6f31998-02-13 14:34:04 +0000259% similar to {funcdesc}, but doesn't add to the index
260\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
261\newcommand{\funcdescni}[2]{\fulllineitems\funclineni{#1}{#2}}
262\let\endfuncdescni\endfulllineitems
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000263
264% same for excdesc
Fred Drakedc8af0a1998-02-13 06:48:05 +0000265\newcommand{\excline}[1]{\item[\bfcode{#1}]\ttindex{#1}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000266\newcommand{\excdesc}[1]{\fulllineitems\excline{#1}}
267\let\endexcdesc\endfulllineitems
268
269% same for datadesc
Fred Drakeaebc6f31998-02-13 14:34:04 +0000270\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000271\newcommand{\datadesc}[1]{\fulllineitems\dataline{#1}}
272\let\enddatadesc\endfulllineitems
273
Fred Drakeaebc6f31998-02-13 14:34:04 +0000274% similar to {datadesc}, but doesn't add to the index
275\newcommand{\datalineni}[1]{\item[\bfcode{#1}]}
276\newcommand{\datadescni}[1]{\fulllineitems\datalineni{#1}}
277\let\enddatadescni\endfulllineitems
278
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000279
Fred Drakea610f9f1997-12-03 03:42:39 +0000280% opcodedesc should be called as an \begin{opcodedesc} ... \end{opcodedesc}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000281\newcommand{\opcodeline}[2]{\item[\bfcode{#1}\quad\var{#2}]}
Fred Drakea610f9f1997-12-03 03:42:39 +0000282\newcommand{\opcodedesc}[2]{\fulllineitems\opcodeline{#1}{#2}}
283\let\endopcodedesc\endfulllineitems
284
285
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000286\let\nodename=\label
287
Fred Drakedc8af0a1998-02-13 06:48:05 +0000288% For these commands, use \command{} to get the typography right, not
289% {\command}. This works better with the texinfo translation.
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000290\newcommand{\ABC}{{\sc abc}}
291\newcommand{\UNIX}{{\sc Unix}}
Fred Drake311c1961998-01-20 05:07:19 +0000292\newcommand{\POSIX}{POSIX}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000293\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000294\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000295\newcommand{\C}{C}
296\newcommand{\EOF}{{\sc eof}}
Guido van Rossum9231c8f1997-05-15 21:43:21 +0000297\newcommand{\NULL}{\code{NULL}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000298
299% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000300\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 +0000301\mbox{\codefont{#1}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000302
Fred Drakedc8af0a1998-02-13 06:48:05 +0000303\newcommand{\bfcode}[1]{\code{\bfseries#1}} %bold-faced code font
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000304\newcommand{\kbd}[1]{\mbox{\tt #1}}
305\newcommand{\key}[1]{\mbox{\tt #1}}
306\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000307% This weird definition of \var{} allows it to always appear in roman
308% italics, and won't get funky in code fragments when we play around
309% with fonts.
310\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
Guido van Rossum45416021995-03-30 16:00:58 +0000311\newcommand{\dfn}[1]{{\em #1\/}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000312\renewcommand{\emph}[1]{{\em #1\/}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000313\newcommand{\strong}[1]{{\bf #1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000314% let's experiment with a new font:
Fred Drakedc8af0a1998-02-13 06:48:05 +0000315\newcommand{\file}[1]{\mbox{`\small\textsf{#1}'}}
Fred Drake53740451998-02-17 15:13:01 +0000316%\@ifundefined{pdfannotlink}{%
317 \newcommand{\url}[1]{\mbox{\small\textsf{#1}}}%
318%}{
319% \newcommand{\url}[1]{{%
320% \pdfannotlink user{/S /URI /URI (#1)}%
321% \mbox{\small\textsf{#1}}}}%
322%}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000323\let\email=\url
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000324
Fred Drake9b550d91996-11-11 20:43:46 +0000325\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000326
327\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000328\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000329
Fred Drakedc8af0a1998-02-13 06:48:05 +0000330% These should be used for all references to identifiers which are
331% used to refer to instances of specific language constructs. See the
332% names for specific semantic assignments.
Fred Drake311c1961998-01-20 05:07:19 +0000333%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000334% For now, don't do anything really fancy with them; just use them as
335% logical markup. This might change in the future.
Fred Drake311c1961998-01-20 05:07:19 +0000336%
337\let\module=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000338\let\keyword=\code
339\let\exception=\code
Fred Drake311c1961998-01-20 05:07:19 +0000340\let\class=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000341\let\function=\code
342\let\cfunction=\code
343\let\method=\code
344
345% constants defined in Python modules, not language constants:
346\let\constant=\code
Fred Drake311c1961998-01-20 05:07:19 +0000347
348\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake06f169b1998-02-11 23:08:20 +0000349\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000350\newcommand{\program}[1]{\strong{#1}}
Fred Drake311c1961998-01-20 05:07:19 +0000351
352
Guido van Rossume7af5a01994-08-01 12:39:35 +0000353\newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3&#4\\
354\hline}{\hline\end{tabular}\end{center}}
355
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000356\newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3&#4&#5\\
357\hline}{\hline\end{tabular}\end{center}}
358
359\newcommand{\itemnewline}[1]{\@tempdima\linewidth
360\advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}}
361
Fred Drake9e243091998-01-18 05:09:54 +0000362\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000363
364% Cross-referencing (AMK)
365% Sample usage:
366% \begin{seealso}
367% \seemodule{rand}{Uniform random number generator}; % Module xref
Fred Drakedc8af0a1998-02-13 06:48:05 +0000368% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000369% \end{seealso}
370
Fred Drakedc8af0a1998-02-13 06:48:05 +0000371\newenvironment{seealso}[0]{\strong{See Also:}\par}{\par}
Fred Drakeaebc6f31998-02-13 14:34:04 +0000372\newcommand{\seemodule}[2]{\ref{module-#1}:%
373 \quad Module \module{#1}\quad(#2)}
374\newcommand{\seebimodule}[2]{\ref{module-#1}:%
375 \quad Built-in Module \module{#1}\quad(#2)}
376\newcommand{\seestmodule}[2]{\ref{module-#1}:%
377 \quad Standard Module \module{#1}\quad(#2)}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000378\newcommand{\seetext}[1]{\par{#1}}
Fred Drakeda941ef1998-01-02 02:57:41 +0000379
Fred Drakedc8af0a1998-02-13 06:48:05 +0000380% Fix the theindex environment to add an entry to the Table of
381% Contents; this is much nicer than just having to jump to the end of
382% the book and flip around, especially with multiple indexes.
Fred Drakeda941ef1998-01-02 02:57:41 +0000383%
384\let\OldTheindex=\theindex
Fred Drake06f169b1998-02-11 23:08:20 +0000385\renewcommand{\theindex}{%
Fred Drakef1a41501998-02-16 05:30:27 +0000386 \cleardoublepage%
Fred Drakeda941ef1998-01-02 02:57:41 +0000387 \OldTheindex%
388 \addcontentsline{toc}{chapter}{\indexname}%
389}
Fred Drake031ad4b1998-01-09 05:34:23 +0000390
391% Use a similar trick to catch the end of the {abstract} environment,
392% but here make sure the abstract is followed by a blank page if the
393% 'openright' option is used.
394%
395\let\OldEndAbstract=\endabstract
Fred Drake06f169b1998-02-11 23:08:20 +0000396\renewcommand{\endabstract}{
Fred Drake737e73e1998-01-13 22:40:08 +0000397 \if@openright
398 \ifodd\value{page}
399 \typeout{Adding blank page after the abstract.}
400 \vfil\pagebreak
Fred Drake031ad4b1998-01-09 05:34:23 +0000401 \fi
Fred Drake737e73e1998-01-13 22:40:08 +0000402 \fi
403 \OldEndAbstract
Fred Drake031ad4b1998-01-09 05:34:23 +0000404}
405
Fred Drakedc8af0a1998-02-13 06:48:05 +0000406% This wraps the \tableofcontents macro with all the magic to get the
407% spacing right and have the right number of pages if the 'openright'
Fred Drake031ad4b1998-01-09 05:34:23 +0000408% option has been used. This eliminates a fair amount of crud in the
409% individual document files.
410%
Fred Drake737e73e1998-01-13 22:40:08 +0000411\let\OldTableofcontents=\tableofcontents
Fred Drake06f169b1998-02-11 23:08:20 +0000412\renewcommand{\tableofcontents}[0]{%
413 \setcounter{page}{1}%
414 \pagebreak%
415 \pagestyle{plain}%
416 {%
417 \parskip = 0mm%
418 \OldTableofcontents%
419 \if@openright%
420 \ifodd\value{page}%
421 \typeout{Adding blank page after the table of contents.}%
422 \pagebreak\hspace{0pt}%
423 \fi%
424 \fi%
425 }%
Fred Drake4c689631998-02-13 16:58:49 +0000426 \cleardoublepage%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000427 \pagenumbering{arabic}%
Fred Drake76183c01998-02-16 22:30:10 +0000428 \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
Fred Drake06f169b1998-02-11 23:08:20 +0000429}
430
Fred Drakedc8af0a1998-02-13 06:48:05 +0000431% Allow the release number to be specified independently of the
432% \date{}. This allows the date to reflect the document's date and
433% release to specify the Python release that is documented.
434%
Fred Drake06f169b1998-02-11 23:08:20 +0000435\newcommand{\@release}{}
436\newcommand{\version}{}
437\newcommand{\releasename}{Release}
438\newcommand{\release}[1]{%
439 \renewcommand{\@release}{\releasename\space\version}%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000440 \renewcommand{\version}{#1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000441
Fred Drakedc8af0a1998-02-13 06:48:05 +0000442% Allow specification of the author's address separately from the
443% author's name. This can be used to format them differently, which
444% is a good thing.
445%
Fred Drake06f169b1998-02-11 23:08:20 +0000446\newcommand{\@authoraddress}{}
447\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
448
Fred Drakedc8af0a1998-02-13 06:48:05 +0000449% Change the title page to look a bit better, and fit in with the
450% fncychap ``Bjarne'' style a bit better.
451%
Fred Drake06f169b1998-02-11 23:08:20 +0000452\renewcommand{\maketitle}{\begin{titlepage}%
453 \let\footnotesize\small
454 \let\footnoterule\relax
455 \@ifundefined{ChTitleVar}{}{%
456 \mghrulefill{\RW}}%
Fred Drake53740451998-02-17 15:13:01 +0000457 \@ifundefined{pdfinfo}{}{
458 \pdfinfo
459 author {\@author}
460 title {\@title}
461 }
Fred Drake06f169b1998-02-11 23:08:20 +0000462 \begin{flushright}%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000463 {\rm\Huge\HeaderFamily \@title \par}%
464 {\em\LARGE\HeaderFamily \@release \par}
Fred Drake06f169b1998-02-11 23:08:20 +0000465 \vfill
Fred Drakedc8af0a1998-02-13 06:48:05 +0000466 {\LARGE\HeaderFamily \@author \par}
Fred Drake06f169b1998-02-11 23:08:20 +0000467 \vfill\vfill
468 {\large
469 \@date \par
470 \vskip 3em
471 \@authoraddress \par
472 }%
473 \end{flushright}%\par
474 \@thanks
475 \end{titlepage}%
476 \setcounter{footnote}{0}%
477 \let\thanks\relax\let\maketitle\relax
478 \gdef\@thanks{}\gdef\@author{}\gdef\@title{}
479}
480
Fred Drakedc8af0a1998-02-13 06:48:05 +0000481% ``minitoc'' support; works fairly well but not all chapters do well
482% with it. Has some weird side effects that I haven't tracked down;
483% don't use it for real at this time.
Fred Drake06f169b1998-02-11 23:08:20 +0000484%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000485% To enable, uncomment the following line only (don't do it!):
Fred Drake06f169b1998-02-11 23:08:20 +0000486%\RequirePackage{minitoc}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000487%
488% Maybe this should all be removed. But I think something like this
489% would be really nice if it can be integrated with the ``list of
490% modules'' at the top of module-documentation chapters. But it might
491% require a completely new environment, perhaps based on {list}.
Fred Drake06f169b1998-02-11 23:08:20 +0000492
493% Leave the rest as-is:
494\newif\if@minitocprinted
495\newcommand{\suppressminitoc}{\@minitocprintedtrue}
496\@ifundefined{minitoc}{
497 % allow \minitoc to be used even if the package hasn't been loaded.
498 \newcommand{\minitoc}{\@minitocprintedtrue}
499}{
500 \dominitoc
501 \newif\if@firstsection
502 \let\OldChapter=\chapter
503 \let\OldSection=\section
504 \let\OldMinitoc=\minitoc
505 % This will only include the minitoc once per chapter
506 \renewcommand{\minitoc}{%
507 \if@minitocprinted{}\else%
508 \OldMinitoc%
509 \@minitocprintedtrue%
510 \fi%
Fred Drake031ad4b1998-01-09 05:34:23 +0000511 }
Fred Drake06f169b1998-02-11 23:08:20 +0000512 % This includes a minitoc before the first \section{}, if it hasn't
513 % already been printed using an explicit \minitoc call.
514 \newcommand{\NewSection}[1]{%
515 \if@firstsection%
516 \if@minitocprinted{}\else%
517 \vskip 15pt%
518 \minitoc%
519 \@firstsectionfalse%
520 \fi%
521 \fi%
522 \OldSection{#1}%
523 }
524 % Reset the flags for each chaper to let the automatic stuff work.
525 \newcommand{\NewChapter}[1]{%
526 \OldChapter{#1}%
527 \@firstsectiontrue%
528 \@minitocprintedfalse%
529 }
530 \let\chapter=\NewChapter
531 \let\section=\NewSection
532 \typeout{Including mini Tables of Contents in each chapter.}
533}
534
Fred Drakedc8af0a1998-02-13 06:48:05 +0000535% This sets up the fancy chapter headings that make the documents look
536% at least a little better than the usual LaTeX output.
Fred Drake06f169b1998-02-11 23:08:20 +0000537%
538\RequirePackage[Bjarne]{fncychap}
539\@ifundefined{ChTitleVar}{}{
Fred Drakedc8af0a1998-02-13 06:48:05 +0000540 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
541 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
542 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
Fred Drake06f169b1998-02-11 23:08:20 +0000543 % This creates chapter heads without the leading \vspace*{}:
544 \def\@makechapterhead#1{%
545 {\parindent \z@ \raggedright \normalfont
546 \ifnum \c@secnumdepth >\m@ne
547 \DOCH
548 \fi
549 \interlinepenalty\@M
550 \DOTI{#1}
551 }
552 }
553 \typeout{Using fancy chapter headings.}
Fred Drake031ad4b1998-01-09 05:34:23 +0000554}