blob: 56b32591cab21c59e5dc4807d069033e01aa0b7b [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 Drake0c17d661998-02-18 14:24:19 +0000316\@ifundefined{pdfannotlink}{%
Fred Drake53740451998-02-17 15:13:01 +0000317 \newcommand{\url}[1]{\mbox{\small\textsf{#1}}}%
Fred Drake0c17d661998-02-18 14:24:19 +0000318}{
319 \input{pdfcolor}% this really isn't a package
320 \newcommand{\url}[1]{{%
321 \pdfannotlink user{/C [1 1 1] /S /URI /URI (#1)}%
322 \NavyBlue% color of the link text
323 \mbox{\small\textsf{#1}}%
324 \Black% Turn it back off; these are declarative
325 \pdfendlink}}% and don't appear bound to the current
326}% formatting "box".
327\let\email=\code
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000328
Fred Drake9b550d91996-11-11 20:43:46 +0000329\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000330
331\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000332\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000333
Fred Drakedc8af0a1998-02-13 06:48:05 +0000334% These should be used for all references to identifiers which are
335% used to refer to instances of specific language constructs. See the
336% names for specific semantic assignments.
Fred Drake311c1961998-01-20 05:07:19 +0000337%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000338% For now, don't do anything really fancy with them; just use them as
339% logical markup. This might change in the future.
Fred Drake311c1961998-01-20 05:07:19 +0000340%
341\let\module=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000342\let\keyword=\code
343\let\exception=\code
Fred Drake311c1961998-01-20 05:07:19 +0000344\let\class=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000345\let\function=\code
346\let\cfunction=\code
347\let\method=\code
348
349% constants defined in Python modules, not language constants:
350\let\constant=\code
Fred Drake311c1961998-01-20 05:07:19 +0000351
352\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake06f169b1998-02-11 23:08:20 +0000353\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000354\newcommand{\program}[1]{\strong{#1}}
Fred Drake311c1961998-01-20 05:07:19 +0000355
356
Guido van Rossume7af5a01994-08-01 12:39:35 +0000357\newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3&#4\\
358\hline}{\hline\end{tabular}\end{center}}
359
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000360\newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3&#4&#5\\
361\hline}{\hline\end{tabular}\end{center}}
362
363\newcommand{\itemnewline}[1]{\@tempdima\linewidth
364\advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}}
365
Fred Drake9e243091998-01-18 05:09:54 +0000366\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000367
368% Cross-referencing (AMK)
369% Sample usage:
370% \begin{seealso}
371% \seemodule{rand}{Uniform random number generator}; % Module xref
Fred Drakedc8af0a1998-02-13 06:48:05 +0000372% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000373% \end{seealso}
374
Fred Drakedc8af0a1998-02-13 06:48:05 +0000375\newenvironment{seealso}[0]{\strong{See Also:}\par}{\par}
Fred Drakeaebc6f31998-02-13 14:34:04 +0000376\newcommand{\seemodule}[2]{\ref{module-#1}:%
377 \quad Module \module{#1}\quad(#2)}
378\newcommand{\seebimodule}[2]{\ref{module-#1}:%
379 \quad Built-in Module \module{#1}\quad(#2)}
380\newcommand{\seestmodule}[2]{\ref{module-#1}:%
381 \quad Standard Module \module{#1}\quad(#2)}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000382\newcommand{\seetext}[1]{\par{#1}}
Fred Drakeda941ef1998-01-02 02:57:41 +0000383
Fred Drakedc8af0a1998-02-13 06:48:05 +0000384% Fix the theindex environment to add an entry to the Table of
385% Contents; this is much nicer than just having to jump to the end of
386% the book and flip around, especially with multiple indexes.
Fred Drakeda941ef1998-01-02 02:57:41 +0000387%
388\let\OldTheindex=\theindex
Fred Drake06f169b1998-02-11 23:08:20 +0000389\renewcommand{\theindex}{%
Fred Drakef1a41501998-02-16 05:30:27 +0000390 \cleardoublepage%
Fred Drakeda941ef1998-01-02 02:57:41 +0000391 \OldTheindex%
392 \addcontentsline{toc}{chapter}{\indexname}%
393}
Fred Drake031ad4b1998-01-09 05:34:23 +0000394
395% Use a similar trick to catch the end of the {abstract} environment,
396% but here make sure the abstract is followed by a blank page if the
397% 'openright' option is used.
398%
399\let\OldEndAbstract=\endabstract
Fred Drake06f169b1998-02-11 23:08:20 +0000400\renewcommand{\endabstract}{
Fred Drake737e73e1998-01-13 22:40:08 +0000401 \if@openright
402 \ifodd\value{page}
403 \typeout{Adding blank page after the abstract.}
404 \vfil\pagebreak
Fred Drake031ad4b1998-01-09 05:34:23 +0000405 \fi
Fred Drake737e73e1998-01-13 22:40:08 +0000406 \fi
407 \OldEndAbstract
Fred Drake031ad4b1998-01-09 05:34:23 +0000408}
409
Fred Drakedc8af0a1998-02-13 06:48:05 +0000410% This wraps the \tableofcontents macro with all the magic to get the
411% spacing right and have the right number of pages if the 'openright'
Fred Drake031ad4b1998-01-09 05:34:23 +0000412% option has been used. This eliminates a fair amount of crud in the
413% individual document files.
414%
Fred Drake737e73e1998-01-13 22:40:08 +0000415\let\OldTableofcontents=\tableofcontents
Fred Drake06f169b1998-02-11 23:08:20 +0000416\renewcommand{\tableofcontents}[0]{%
417 \setcounter{page}{1}%
418 \pagebreak%
419 \pagestyle{plain}%
420 {%
421 \parskip = 0mm%
422 \OldTableofcontents%
423 \if@openright%
424 \ifodd\value{page}%
425 \typeout{Adding blank page after the table of contents.}%
426 \pagebreak\hspace{0pt}%
427 \fi%
428 \fi%
429 }%
Fred Drake4c689631998-02-13 16:58:49 +0000430 \cleardoublepage%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000431 \pagenumbering{arabic}%
Fred Drake76183c01998-02-16 22:30:10 +0000432 \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
Fred Drake06f169b1998-02-11 23:08:20 +0000433}
434
Fred Drakedc8af0a1998-02-13 06:48:05 +0000435% Allow the release number to be specified independently of the
436% \date{}. This allows the date to reflect the document's date and
437% release to specify the Python release that is documented.
438%
Fred Drake06f169b1998-02-11 23:08:20 +0000439\newcommand{\@release}{}
440\newcommand{\version}{}
441\newcommand{\releasename}{Release}
442\newcommand{\release}[1]{%
443 \renewcommand{\@release}{\releasename\space\version}%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000444 \renewcommand{\version}{#1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000445
Fred Drakedc8af0a1998-02-13 06:48:05 +0000446% Allow specification of the author's address separately from the
447% author's name. This can be used to format them differently, which
448% is a good thing.
449%
Fred Drake06f169b1998-02-11 23:08:20 +0000450\newcommand{\@authoraddress}{}
451\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
452
Fred Drakedc8af0a1998-02-13 06:48:05 +0000453% Change the title page to look a bit better, and fit in with the
454% fncychap ``Bjarne'' style a bit better.
455%
Fred Drake06f169b1998-02-11 23:08:20 +0000456\renewcommand{\maketitle}{\begin{titlepage}%
457 \let\footnotesize\small
458 \let\footnoterule\relax
459 \@ifundefined{ChTitleVar}{}{%
460 \mghrulefill{\RW}}%
Fred Drake53740451998-02-17 15:13:01 +0000461 \@ifundefined{pdfinfo}{}{
462 \pdfinfo
463 author {\@author}
464 title {\@title}
465 }
Fred Drake06f169b1998-02-11 23:08:20 +0000466 \begin{flushright}%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000467 {\rm\Huge\HeaderFamily \@title \par}%
468 {\em\LARGE\HeaderFamily \@release \par}
Fred Drake06f169b1998-02-11 23:08:20 +0000469 \vfill
Fred Drakedc8af0a1998-02-13 06:48:05 +0000470 {\LARGE\HeaderFamily \@author \par}
Fred Drake06f169b1998-02-11 23:08:20 +0000471 \vfill\vfill
472 {\large
473 \@date \par
474 \vskip 3em
475 \@authoraddress \par
476 }%
477 \end{flushright}%\par
478 \@thanks
479 \end{titlepage}%
480 \setcounter{footnote}{0}%
481 \let\thanks\relax\let\maketitle\relax
482 \gdef\@thanks{}\gdef\@author{}\gdef\@title{}
483}
484
Fred Drakedc8af0a1998-02-13 06:48:05 +0000485% ``minitoc'' support; works fairly well but not all chapters do well
486% with it. Has some weird side effects that I haven't tracked down;
487% don't use it for real at this time.
Fred Drake06f169b1998-02-11 23:08:20 +0000488%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000489% To enable, uncomment the following line only (don't do it!):
Fred Drake06f169b1998-02-11 23:08:20 +0000490%\RequirePackage{minitoc}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000491%
492% Maybe this should all be removed. But I think something like this
493% would be really nice if it can be integrated with the ``list of
494% modules'' at the top of module-documentation chapters. But it might
495% require a completely new environment, perhaps based on {list}.
Fred Drake06f169b1998-02-11 23:08:20 +0000496
497% Leave the rest as-is:
498\newif\if@minitocprinted
499\newcommand{\suppressminitoc}{\@minitocprintedtrue}
500\@ifundefined{minitoc}{
501 % allow \minitoc to be used even if the package hasn't been loaded.
502 \newcommand{\minitoc}{\@minitocprintedtrue}
503}{
504 \dominitoc
505 \newif\if@firstsection
506 \let\OldChapter=\chapter
507 \let\OldSection=\section
508 \let\OldMinitoc=\minitoc
509 % This will only include the minitoc once per chapter
510 \renewcommand{\minitoc}{%
511 \if@minitocprinted{}\else%
512 \OldMinitoc%
513 \@minitocprintedtrue%
514 \fi%
Fred Drake031ad4b1998-01-09 05:34:23 +0000515 }
Fred Drake06f169b1998-02-11 23:08:20 +0000516 % This includes a minitoc before the first \section{}, if it hasn't
517 % already been printed using an explicit \minitoc call.
518 \newcommand{\NewSection}[1]{%
519 \if@firstsection%
520 \if@minitocprinted{}\else%
521 \vskip 15pt%
522 \minitoc%
523 \@firstsectionfalse%
524 \fi%
525 \fi%
526 \OldSection{#1}%
527 }
528 % Reset the flags for each chaper to let the automatic stuff work.
529 \newcommand{\NewChapter}[1]{%
530 \OldChapter{#1}%
531 \@firstsectiontrue%
532 \@minitocprintedfalse%
533 }
534 \let\chapter=\NewChapter
535 \let\section=\NewSection
536 \typeout{Including mini Tables of Contents in each chapter.}
537}
538
Fred Drakedc8af0a1998-02-13 06:48:05 +0000539% This sets up the fancy chapter headings that make the documents look
540% at least a little better than the usual LaTeX output.
Fred Drake06f169b1998-02-11 23:08:20 +0000541%
542\RequirePackage[Bjarne]{fncychap}
543\@ifundefined{ChTitleVar}{}{
Fred Drakedc8af0a1998-02-13 06:48:05 +0000544 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
545 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
546 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
Fred Drake06f169b1998-02-11 23:08:20 +0000547 % This creates chapter heads without the leading \vspace*{}:
548 \def\@makechapterhead#1{%
549 {\parindent \z@ \raggedright \normalfont
550 \ifnum \c@secnumdepth >\m@ne
551 \DOCH
552 \fi
553 \interlinepenalty\@M
554 \DOTI{#1}
555 }
556 }
557 \typeout{Using fancy chapter headings.}
Fred Drake031ad4b1998-01-09 05:34:23 +0000558}