blob: ba564c8df622bee9e47140abb7dabde6354823f3 [file] [log] [blame]
Guido van Rossumecae0b71996-06-26 19:03:20 +00001%
Fred Drakefb5e54d1998-02-19 06:23:06 +00002% myformat.sty for the Python doc [works only with with Latex2e]
Guido van Rossumecae0b71996-06-26 19:03:20 +00003%
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%
Fred Drakefb5e54d1998-02-19 06:23:06 +000025% The "fncychap" package is used to get the nice chapter headers. The
26% .sty file is distributed with Python, so you should not need to disable
27% it.
28%
29\RequirePackage{fancyhdr}\typeout{Using fancier footers than usual.}
Fred Drake76183c01998-02-16 22:30:10 +000030\RequirePackage{times}\typeout{Using times fonts instead of Computer Modern.}
Fred Drakefb5e54d1998-02-19 06:23:06 +000031\RequirePackage[Bjarne]{fncychap}\typeout{Using nice chapter headings.}
Fred Drake76183c01998-02-16 22:30:10 +000032
33
Fred Drake4186cd31998-02-18 17:21:09 +000034% for PDF output, use maximal compression, revise \label{} to support named
35% targets for later linking operations.
36\@ifundefined{pdfannotlink}{}{%
37 \pdfcompresslevel=9
38 \let\OldLabel=\label
39 \renewcommand{\label}[1]{%
40 \OldLabel{#1}%
41 {\pdfdest name {#1} fit}%
42 }
43}
Fred Drake30d17821998-02-17 15:56:55 +000044
Guido van Rossumdaff1751997-06-02 17:35:01 +000045% Increase printable page size (copied from fullpage.sty)
46\topmargin 0pt
47\advance \topmargin by -\headheight
48\advance \topmargin by -\headsep
Fred Drake9e243091998-01-18 05:09:54 +000049
Fred Drake76183c01998-02-16 22:30:10 +000050\textheight 8.7in
Fred Drake9e243091998-01-18 05:09:54 +000051
Guido van Rossumdaff1751997-06-02 17:35:01 +000052\oddsidemargin 0pt
53\evensidemargin \oddsidemargin
54\marginparwidth 0.5in
Fred Drake9e243091998-01-18 05:09:54 +000055
Guido van Rossumdaff1751997-06-02 17:35:01 +000056\textwidth 6.5in
57
Guido van Rossum643d9321992-03-31 18:53:47 +000058% Style parameters and macros used by most documents here
Guido van Rossum5badc751992-03-06 10:55:46 +000059\raggedbottom
60\sloppy
Fred Drakefb5e54d1998-02-19 06:23:06 +000061\parindent = 0mm
62\parskip = 2mm
63\hbadness = 5000 % don't print trivial gripes
Guido van Rossum5badc751992-03-06 10:55:46 +000064
Fred Drakefb5e54d1998-02-19 06:23:06 +000065\pagestyle{empty} % start this way; change for
66\pagenumbering{roman} % ToC & chapters
Fred Drakedc8af0a1998-02-13 06:48:05 +000067\setcounter{secnumdepth}{1}
68
Fred Drakefb5e54d1998-02-19 06:23:06 +000069% Use this to set the font family for headers and other decor:
70\newcommand{\HeaderFamily}{\sffamily}
71
Fred Drake76183c01998-02-16 22:30:10 +000072% Redefine the 'normal' header/footer style when using "fancyhdr" package:
73\@ifundefined{fancyhf}{}{
Fred Drakefb5e54d1998-02-19 06:23:06 +000074 % Use \pagestyle{normal} as the primary pagestyle for text.
75 \fancypagestyle{normal}{
76 \fancyhf{}
77 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
78 \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}
79 \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}
80 \renewcommand{\headrulewidth}{0pt}
81 \renewcommand{\footrulewidth}{0.4pt}
Fred Drake76183c01998-02-16 22:30:10 +000082 }
83 % Update the plain style so we get the page number & footer line,
84 % but not a chapter or section title. This is to keep the first
85 % page of a chapter and the blank page between chapters `clean.'
Fred Drakefb5e54d1998-02-19 06:23:06 +000086 \fancypagestyle{plain}{
87 \fancyhf{}
88 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
89 \renewcommand{\headrulewidth}{0pt}
90 \renewcommand{\footrulewidth}{0.4pt}
Fred Drake76183c01998-02-16 22:30:10 +000091 }
92 % Redefine \cleardoublepage so that the blank page between chapters
Fred Drakefb5e54d1998-02-19 06:23:06 +000093 % gets the plain style and not the fancy style. This is described
94 % in the documentation for the fancyhdr package by Piet von Oostrum.
95 \renewcommand{\cleardoublepage}{
96 \clearpage\if@twoside \ifodd\c@page\else
Fred Drake76183c01998-02-16 22:30:10 +000097 \hbox{}
98 \thispagestyle{plain}
99 \newpage
100 \if@twocolumn\hbox{}\newpage\fi\fi\fi}
101}
102
Fred Drake9e243091998-01-18 05:09:54 +0000103% old code font selections:
104\let\codefont=\tt
105\let\sectcodefont=\tt
106
107% (Haven't found a new one that gets <, >, and _ right without being
108% monospaced.)
109
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000110% Variable used by begin code command
Guido van Rossum44000ed1991-01-24 16:54:29 +0000111\newlength{\codewidth}
Guido van Rossum44000ed1991-01-24 16:54:29 +0000112
Fred Drakedc8af0a1998-02-13 06:48:05 +0000113\newcommand{\examplevspace}{2mm}
114\newcommand{\exampleindent}{1cm}
Guido van Rossum5badc751992-03-06 10:55:46 +0000115% Command to start a code block (follow this by \begin{verbatim})
Fred Drakedc8af0a1998-02-13 06:48:05 +0000116\newcommand{\b@code}{%
117 \begingroup%
118 \setlength{\parindent}\exampleindent%
119 % Calculate the text width for the minipage:
120 \setlength{\codewidth}{\linewidth}%
121 \addtolength{\codewidth}{-\parindent}%
122 %
123 \par%
124 \vspace\examplevspace%
125 \indent%
126 \begin{minipage}[t]{\codewidth}%
127 \small%
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000128}
129
Guido van Rossum5badc751992-03-06 10:55:46 +0000130% Command to end a code block (precede this by \end{verbatim})
Fred Drakedc8af0a1998-02-13 06:48:05 +0000131\newcommand{\e@code}{%
132 \end{minipage}%
133 \endgroup%
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000134}
Guido van Rossum5badc751992-03-06 10:55:46 +0000135
Fred Drakedc8af0a1998-02-13 06:48:05 +0000136\let\OldVerbatim=\verbatim
137\let\OldEndVerbatim=\endverbatim
138\renewcommand{\verbatim}{\b@code\OldVerbatim}
139\renewcommand{\endverbatim}{\OldEndVerbatim\e@code}
140
Fred Drakefb5e54d1998-02-19 06:23:06 +0000141% Augment the sectioning commands used to get our own font family in place:
Fred Drakedc8af0a1998-02-13 06:48:05 +0000142\renewcommand{\section}{\@startsection {section}{1}{\z@}%
143 {-3.5ex \@plus -1ex \@minus -.2ex}%
144 {2.3ex \@plus.2ex}%
145 {\reset@font\Large\HeaderFamily}}
146\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
147 {-3.25ex\@plus -1ex \@minus -.2ex}%
148 {1.5ex \@plus .2ex}%
149 {\reset@font\large\HeaderFamily}}
150\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
151 {-3.25ex\@plus -1ex \@minus -.2ex}%
152 {1.5ex \@plus .2ex}%
153 {\reset@font\normalsize\HeaderFamily}}
154\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
155 {3.25ex \@plus1ex \@minus.2ex}%
156 {-1em}%
157 {\reset@font\normalsize\HeaderFamily}}
158\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
159 {3.25ex \@plus1ex \@minus .2ex}%
160 {-1em}%
161 {\reset@font\normalsize\HeaderFamily}}
162
163
Guido van Rossumecae0b71996-06-26 19:03:20 +0000164% Underscore hack (only act like subscript operator if in math mode)
165%
166% The following is due to Mark Wooding (the old version didn't work with
167% Latex 2e.
168
169\DeclareRobustCommand\hackscore{%
170 \ifmmode_\else\textunderscore\fi%
171}
172\begingroup
173\catcode`\_\active
174\def\next{%
175 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
176}
177\expandafter\endgroup\next
178
179%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000180% This is the old hack, which didn't work with 2e.
181% You should not need this since the rest of the documentation is now
182% LaTeX2e-only.
Guido van Rossumecae0b71996-06-26 19:03:20 +0000183%
184%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
185%\catcode`\_=12
186%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
Guido van Rossum5badc751992-03-06 10:55:46 +0000187
Fred Drakeb37a3951998-02-06 22:52:52 +0000188
Fred Drakedc8af0a1998-02-13 06:48:05 +0000189
Fred Drakeb37a3951998-02-06 22:52:52 +0000190%% Lots of index-entry generation support.
191
Fred Drakedc8af0a1998-02-13 06:48:05 +0000192% Command to wrap around stuff that refers to function / module /
193% attribute names in the index. Default behavior: like \code{}. To
194% just keep the index entries in the roman font, uncomment the second
195% definition to use instead; it matches O'Reilly style more.
196%
Fred Drakeb37a3951998-02-06 22:52:52 +0000197\newcommand{\idxcode}[1]{\codefont{#1}}
198%\renewcommand{\idxcode}[1]{#1}
Guido van Rossum5badc751992-03-06 10:55:46 +0000199
200% Command to generate two index entries (using subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +0000201\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000202
203% And three entries (using only one level of subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +0000204\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000205
206% And four (again, using only one level of subentries)
207\newcommand{\indexiv}[4]{
208\index{#1!#2 #3 #4}
209\index{#2!#3 #4, #1}
210\index{#3!#4, #1 #2}
211\index{#4!#1 #2 #3}
212}
213
Fred Drakedc8af0a1998-02-13 06:48:05 +0000214% Command to generate a reference to a function, statement, keyword,
215% operator.
Fred Drakeb37a3951998-02-06 22:52:52 +0000216\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
217\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
218\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Guido van Rossum6886c831992-04-03 14:44:27 +0000219\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000220\newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1()}} (built-in function)}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000221
222% Add an index entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000223\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake4af18141997-12-15 22:08:14 +0000224\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000225\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
226\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
227
Fred Drakeda941ef1998-01-02 02:57:41 +0000228% support for the module index
229\newwrite\modindexfile
230\openout\modindexfile=modules.idx
231
Fred Drake207e57b1997-12-15 21:37:45 +0000232% Add the defining entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000233\newcommand{\defmodindex}[2]{%
234 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
Fred Drakeda941ef1998-01-02 02:57:41 +0000235 \write\modindexfile{#1 \thepage}}
Fred Drakeb1927471998-02-04 14:43:36 +0000236\newcommand{\modindex}[1]{\defmodindex{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000237\newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }}
238\newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }}
Guido van Rossum5badc751992-03-06 10:55:46 +0000239
240% Additional string for an index entry
Fred Drakedc8af0a1998-02-13 06:48:05 +0000241\newcommand{\index@subitem}{}
242\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
243\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000244
Guido van Rossum5badc751992-03-06 10:55:46 +0000245
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000246% from user-level, fulllineitems should be called as an environment
Fred Drakefb5e54d1998-02-19 06:23:06 +0000247\newenvironment{fulllineitems}{
248 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
249 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
250 \itemsep -\parsep
251 \let\makelabel=\itemnewline}
252}{\end{list}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000253
254
Guido van Rossum36f35021997-05-22 20:43:24 +0000255% cfuncdesc should be called as
256% \begin{cfuncdesc}{type}{name}{arglist}
257% ... description ...
258% \end{cfuncdesc}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000259\newenvironment{cfuncdesc}[3]{%
260 \begin{fulllineitems}%
261 \item[\code{#1 \bfcode{#2}(\varvars{#3})}]%
262 \index{#2@{\idxcode{#2()}}}%
263}{\end{fulllineitems}}
Fred Drakeeb33c781996-10-29 15:55:08 +0000264
Fred Drakefb5e54d1998-02-19 06:23:06 +0000265\newenvironment{cvardesc}[2]{%
266 \begin{fulllineitems}%
267 \item[\code{#1 \bfcode{#2}}]%
268 \index{#2@{\idxcode{#2}}}%
269}{\end{fulllineitems}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000270
Fred Drakefb5e54d1998-02-19 06:23:06 +0000271\newenvironment{ctypedesc}[1]{%
272 \begin{fulllineitems}%
273 \item[\bfcode{#1}]\ttindex{#1}
274}{\end{fulllineitems}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000275
Fred Drakefb5e54d1998-02-19 06:23:06 +0000276\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
277\newenvironment{funcdesc}[2]{%
278 \begin{fulllineitems}%
279 \funcline{#1}{#2}%
280}{\end{fulllineitems}}
281
282\newcommand{\optional}[1]{%
283 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000284
Fred Drakeaebc6f31998-02-13 14:34:04 +0000285% similar to {funcdesc}, but doesn't add to the index
286\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000287\newenvironment{funcdescni}[2]{%
288 \begin{fulllineitems}%
289 \funclineni{#1}{#2}%
290}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000291
Fred Drakefb5e54d1998-02-19 06:23:06 +0000292\newenvironment{classdesc}[2]{%
293 \begin{fulllineitems}%
294 \item[\code{\bfcode{#1}(\varvars{#2})}]%
295 \ttindex{#1}%
296 \def\baseclasses##1{}%
297}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000298
Fred Drakefb5e54d1998-02-19 06:23:06 +0000299\newenvironment{excdesc}[1]{%
300 \begin{fulllineitems}%
301 \item[\bfcode{#1}]\ttindex{#1}%
302}{\end{fulllineitems}}
303
Fred Drakeaebc6f31998-02-13 14:34:04 +0000304\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000305\newenvironment{datadesc}[1]{%
306 \begin{fulllineitems}%
307 \dataline{#1}%
308}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000309
Fred Drakeaebc6f31998-02-13 14:34:04 +0000310% similar to {datadesc}, but doesn't add to the index
311\newcommand{\datalineni}[1]{\item[\bfcode{#1}]}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000312\newenvironment{datadescni}[1]{%
313 \begin{fulllineitems}%
314 \datalineni{#1}%
315}{\end{fulllineitems}}
Fred Drakeaebc6f31998-02-13 14:34:04 +0000316
Fred Drakefb5e54d1998-02-19 06:23:06 +0000317\newenvironment{opcodedesc}[2]{%
318 \begin{fulllineitems}%
319 \item[\bfcode{#1}\quad\var{#2}]%
320}{\end{fulllineitems}}
Fred Drakea610f9f1997-12-03 03:42:39 +0000321
322
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000323\let\nodename=\label
324
Fred Drakedc8af0a1998-02-13 06:48:05 +0000325% For these commands, use \command{} to get the typography right, not
326% {\command}. This works better with the texinfo translation.
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000327\newcommand{\ABC}{{\sc abc}}
328\newcommand{\UNIX}{{\sc Unix}}
Fred Drake311c1961998-01-20 05:07:19 +0000329\newcommand{\POSIX}{POSIX}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000330\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000331\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000332\newcommand{\C}{C}
333\newcommand{\EOF}{{\sc eof}}
Guido van Rossum9231c8f1997-05-15 21:43:21 +0000334\newcommand{\NULL}{\code{NULL}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000335
336% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000337\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 +0000338\mbox{\codefont{#1}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000339
Fred Drakefb5e54d1998-02-19 06:23:06 +0000340\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000341\newcommand{\kbd}[1]{\mbox{\tt #1}}
342\newcommand{\key}[1]{\mbox{\tt #1}}
343\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000344% This weird definition of \var{} allows it to always appear in roman
345% italics, and won't get funky in code fragments when we play around
346% with fonts.
347\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000348\renewcommand{\emph}[1]{{\em #1\/}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000349\newcommand{\dfn}[1]{\emph{#1}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000350\newcommand{\strong}[1]{{\bf #1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000351% let's experiment with a new font:
Fred Drakedc8af0a1998-02-13 06:48:05 +0000352\newcommand{\file}[1]{\mbox{`\small\textsf{#1}'}}
Fred Drake0c17d661998-02-18 14:24:19 +0000353\@ifundefined{pdfannotlink}{%
Fred Drake53740451998-02-17 15:13:01 +0000354 \newcommand{\url}[1]{\mbox{\small\textsf{#1}}}%
Fred Drake0c17d661998-02-18 14:24:19 +0000355}{
356 \input{pdfcolor}% this really isn't a package
357 \newcommand{\url}[1]{{%
358 \pdfannotlink user{/C [1 1 1] /S /URI /URI (#1)}%
359 \NavyBlue% color of the link text
360 \mbox{\small\textsf{#1}}%
361 \Black% Turn it back off; these are declarative
362 \pdfendlink}}% and don't appear bound to the current
363}% formatting "box".
Fred Drake4186cd31998-02-18 17:21:09 +0000364\newcommand{\email}[1]{\mbox{\small\textsf{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000365
Fred Drake9b550d91996-11-11 20:43:46 +0000366\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000367
368\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000369\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000370
Fred Drakedc8af0a1998-02-13 06:48:05 +0000371% These should be used for all references to identifiers which are
372% used to refer to instances of specific language constructs. See the
373% names for specific semantic assignments.
Fred Drake311c1961998-01-20 05:07:19 +0000374%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000375% For now, don't do anything really fancy with them; just use them as
376% logical markup. This might change in the future.
Fred Drake311c1961998-01-20 05:07:19 +0000377%
378\let\module=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000379\let\keyword=\code
380\let\exception=\code
Fred Drake311c1961998-01-20 05:07:19 +0000381\let\class=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000382\let\function=\code
Fred Drakefb5e54d1998-02-19 06:23:06 +0000383\let\member=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000384\let\method=\code
385
Fred Drakefb5e54d1998-02-19 06:23:06 +0000386\let\cfunction=\code
387\let\ctype=\code
388\let\cdata=\code
389
390% constants defined in Python modules or C headers, not language constants:
Fred Drakedd28d571998-01-22 15:55:21 +0000391\let\constant=\code
Fred Drake311c1961998-01-20 05:07:19 +0000392
393\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake06f169b1998-02-11 23:08:20 +0000394\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000395\newcommand{\program}[1]{\strong{#1}}
Fred Drake311c1961998-01-20 05:07:19 +0000396
397
Fred Drakefb5e54d1998-02-19 06:23:06 +0000398\newenvironment{tableii}[4]{%
399 \begin{center}%
400 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
401 \begin{tabular}{#1}\hline#3&#4\\ \hline%
402}{%
403 \hline%
404 \end{tabular}%
405 \end{center}%
406}
Guido van Rossume7af5a01994-08-01 12:39:35 +0000407
Fred Drakefb5e54d1998-02-19 06:23:06 +0000408\newenvironment{tableiii}[5]{%
409 \begin{center}%
410 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
411 \begin{tabular}{#1}\hline#3&#4&#5\\%
412 \hline%
413}{%
414 \hline%
415 \end{tabular}%
416 \end{center}%
417}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000418
Fred Drakefb5e54d1998-02-19 06:23:06 +0000419\newcommand{\itemnewline}[1]{%
420 \@tempdima\linewidth%
421 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
422}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000423
Fred Drake9e243091998-01-18 05:09:54 +0000424\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000425
426% Cross-referencing (AMK)
427% Sample usage:
428% \begin{seealso}
429% \seemodule{rand}{Uniform random number generator}; % Module xref
Fred Drakedc8af0a1998-02-13 06:48:05 +0000430% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000431% \end{seealso}
432
Fred Drakefb5e54d1998-02-19 06:23:06 +0000433\newenvironment{seealso}[0]{
434 \strong{See Also:}\par
435 % These should only be defined within the {seealso} environment:
436 \def\seemodule##1##2{\ref{module-##1}:\quad Module \module{##1}\quad (##2)}
437 \def\seetext##1{\par{##1}}
438}{\par}
439
Fred Drakeda941ef1998-01-02 02:57:41 +0000440
Fred Drakedc8af0a1998-02-13 06:48:05 +0000441% Fix the theindex environment to add an entry to the Table of
442% Contents; this is much nicer than just having to jump to the end of
443% the book and flip around, especially with multiple indexes.
Fred Drakeda941ef1998-01-02 02:57:41 +0000444%
445\let\OldTheindex=\theindex
Fred Drakefb5e54d1998-02-19 06:23:06 +0000446\renewcommand{\theindex}{
447 \cleardoublepage
448 \OldTheindex
449 \addcontentsline{toc}{chapter}{\indexname}
Fred Drakeda941ef1998-01-02 02:57:41 +0000450}
Fred Drake031ad4b1998-01-09 05:34:23 +0000451
452% Use a similar trick to catch the end of the {abstract} environment,
453% but here make sure the abstract is followed by a blank page if the
454% 'openright' option is used.
455%
456\let\OldEndAbstract=\endabstract
Fred Drake06f169b1998-02-11 23:08:20 +0000457\renewcommand{\endabstract}{
Fred Drake737e73e1998-01-13 22:40:08 +0000458 \if@openright
459 \ifodd\value{page}
460 \typeout{Adding blank page after the abstract.}
461 \vfil\pagebreak
Fred Drake031ad4b1998-01-09 05:34:23 +0000462 \fi
Fred Drake737e73e1998-01-13 22:40:08 +0000463 \fi
464 \OldEndAbstract
Fred Drake031ad4b1998-01-09 05:34:23 +0000465}
466
Fred Drakedc8af0a1998-02-13 06:48:05 +0000467% This wraps the \tableofcontents macro with all the magic to get the
468% spacing right and have the right number of pages if the 'openright'
Fred Drake031ad4b1998-01-09 05:34:23 +0000469% option has been used. This eliminates a fair amount of crud in the
470% individual document files.
471%
Fred Drake737e73e1998-01-13 22:40:08 +0000472\let\OldTableofcontents=\tableofcontents
Fred Drake06f169b1998-02-11 23:08:20 +0000473\renewcommand{\tableofcontents}[0]{%
474 \setcounter{page}{1}%
475 \pagebreak%
476 \pagestyle{plain}%
477 {%
478 \parskip = 0mm%
479 \OldTableofcontents%
480 \if@openright%
481 \ifodd\value{page}%
482 \typeout{Adding blank page after the table of contents.}%
483 \pagebreak\hspace{0pt}%
484 \fi%
485 \fi%
486 }%
Fred Drake4c689631998-02-13 16:58:49 +0000487 \cleardoublepage%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000488 \pagenumbering{arabic}%
Fred Drake76183c01998-02-16 22:30:10 +0000489 \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
Fred Drake06f169b1998-02-11 23:08:20 +0000490}
491
Fred Drakedc8af0a1998-02-13 06:48:05 +0000492% Allow the release number to be specified independently of the
493% \date{}. This allows the date to reflect the document's date and
494% release to specify the Python release that is documented.
495%
Fred Drake06f169b1998-02-11 23:08:20 +0000496\newcommand{\@release}{}
497\newcommand{\version}{}
498\newcommand{\releasename}{Release}
499\newcommand{\release}[1]{%
500 \renewcommand{\@release}{\releasename\space\version}%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000501 \renewcommand{\version}{#1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000502
Fred Drakedc8af0a1998-02-13 06:48:05 +0000503% Allow specification of the author's address separately from the
504% author's name. This can be used to format them differently, which
505% is a good thing.
506%
Fred Drake06f169b1998-02-11 23:08:20 +0000507\newcommand{\@authoraddress}{}
508\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
509
Fred Drakedc8af0a1998-02-13 06:48:05 +0000510% Change the title page to look a bit better, and fit in with the
511% fncychap ``Bjarne'' style a bit better.
512%
Fred Drakefb5e54d1998-02-19 06:23:06 +0000513\renewcommand{\maketitle}{%
514 \begin{titlepage}%
515 \let\footnotesize\small
516 \let\footnoterule\relax
517 \@ifundefined{ChTitleVar}{}{%
518 \mghrulefill{\RW}}%
519 \@ifundefined{pdfinfo}{}{
520 \pdfinfo
521 author {\@author}
522 title {\@title}
523 }
524 \begin{flushright}%
525 {\rm\Huge\HeaderFamily \@title \par}%
526 {\em\LARGE\HeaderFamily \@release \par}
527 \vfill
528 {\LARGE\HeaderFamily \@author \par}
529 \vfill\vfill
530 {\large
531 \@date \par
532 \vskip 3em
533 \@authoraddress \par
534 }%
535 \end{flushright}%\par
536 \@thanks
Fred Drake06f169b1998-02-11 23:08:20 +0000537 \end{titlepage}%
538 \setcounter{footnote}{0}%
539 \let\thanks\relax\let\maketitle\relax
540 \gdef\@thanks{}\gdef\@author{}\gdef\@title{}
541}
542
Fred Drakedc8af0a1998-02-13 06:48:05 +0000543% ``minitoc'' support; works fairly well but not all chapters do well
544% with it. Has some weird side effects that I haven't tracked down;
545% don't use it for real at this time.
Fred Drake06f169b1998-02-11 23:08:20 +0000546%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000547% To enable, uncomment the following line only (don't do it!):
Fred Drake06f169b1998-02-11 23:08:20 +0000548%\RequirePackage{minitoc}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000549%
550% Maybe this should all be removed. But I think something like this
551% would be really nice if it can be integrated with the ``list of
552% modules'' at the top of module-documentation chapters. But it might
553% require a completely new environment, perhaps based on {list}.
Fred Drake06f169b1998-02-11 23:08:20 +0000554
Fred Drake06f169b1998-02-11 23:08:20 +0000555\newif\if@minitocprinted
556\newcommand{\suppressminitoc}{\@minitocprintedtrue}
557\@ifundefined{minitoc}{
558 % allow \minitoc to be used even if the package hasn't been loaded.
559 \newcommand{\minitoc}{\@minitocprintedtrue}
560}{
561 \dominitoc
562 \newif\if@firstsection
563 \let\OldChapter=\chapter
564 \let\OldSection=\section
565 \let\OldMinitoc=\minitoc
566 % This will only include the minitoc once per chapter
567 \renewcommand{\minitoc}{%
568 \if@minitocprinted{}\else%
569 \OldMinitoc%
570 \@minitocprintedtrue%
571 \fi%
Fred Drake031ad4b1998-01-09 05:34:23 +0000572 }
Fred Drake06f169b1998-02-11 23:08:20 +0000573 % This includes a minitoc before the first \section{}, if it hasn't
574 % already been printed using an explicit \minitoc call.
575 \newcommand{\NewSection}[1]{%
576 \if@firstsection%
577 \if@minitocprinted{}\else%
578 \vskip 15pt%
579 \minitoc%
580 \@firstsectionfalse%
581 \fi%
582 \fi%
583 \OldSection{#1}%
584 }
585 % Reset the flags for each chaper to let the automatic stuff work.
586 \newcommand{\NewChapter}[1]{%
587 \OldChapter{#1}%
588 \@firstsectiontrue%
589 \@minitocprintedfalse%
590 }
591 \let\chapter=\NewChapter
592 \let\section=\NewSection
593 \typeout{Including mini Tables of Contents in each chapter.}
594}
595
Fred Drakedc8af0a1998-02-13 06:48:05 +0000596% This sets up the fancy chapter headings that make the documents look
597% at least a little better than the usual LaTeX output.
Fred Drake06f169b1998-02-11 23:08:20 +0000598%
Fred Drake06f169b1998-02-11 23:08:20 +0000599\@ifundefined{ChTitleVar}{}{
Fred Drakedc8af0a1998-02-13 06:48:05 +0000600 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
601 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
602 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
Fred Drake06f169b1998-02-11 23:08:20 +0000603 % This creates chapter heads without the leading \vspace*{}:
604 \def\@makechapterhead#1{%
605 {\parindent \z@ \raggedright \normalfont
606 \ifnum \c@secnumdepth >\m@ne
607 \DOCH
608 \fi
609 \interlinepenalty\@M
610 \DOTI{#1}
611 }
612 }
613 \typeout{Using fancy chapter headings.}
Fred Drake031ad4b1998-01-09 05:34:23 +0000614}