blob: b78a642eaf8144e55d4b1798e2e896611580bd25 [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
Fred Drakeef146221998-02-19 21:02:26 +0000246% {fulllineitems} is used in one place in libregex.tex, but is really for
247% internal use in this file.
248%
Fred Drakefb5e54d1998-02-19 06:23:06 +0000249\newenvironment{fulllineitems}{
250 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
251 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
252 \itemsep -\parsep
253 \let\makelabel=\itemnewline}
254}{\end{list}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000255
256
Guido van Rossum36f35021997-05-22 20:43:24 +0000257% cfuncdesc should be called as
258% \begin{cfuncdesc}{type}{name}{arglist}
259% ... description ...
260% \end{cfuncdesc}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000261\newenvironment{cfuncdesc}[3]{%
262 \begin{fulllineitems}%
263 \item[\code{#1 \bfcode{#2}(\varvars{#3})}]%
264 \index{#2@{\idxcode{#2()}}}%
265}{\end{fulllineitems}}
Fred Drakeeb33c781996-10-29 15:55:08 +0000266
Fred Drakefb5e54d1998-02-19 06:23:06 +0000267\newenvironment{cvardesc}[2]{%
268 \begin{fulllineitems}%
269 \item[\code{#1 \bfcode{#2}}]%
270 \index{#2@{\idxcode{#2}}}%
271}{\end{fulllineitems}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000272
Fred Drakefb5e54d1998-02-19 06:23:06 +0000273\newenvironment{ctypedesc}[1]{%
274 \begin{fulllineitems}%
275 \item[\bfcode{#1}]\ttindex{#1}
276}{\end{fulllineitems}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000277
Fred Drakefb5e54d1998-02-19 06:23:06 +0000278\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
279\newenvironment{funcdesc}[2]{%
280 \begin{fulllineitems}%
281 \funcline{#1}{#2}%
282}{\end{fulllineitems}}
283
284\newcommand{\optional}[1]{%
285 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000286
Fred Drakeaebc6f31998-02-13 14:34:04 +0000287% similar to {funcdesc}, but doesn't add to the index
288\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000289\newenvironment{funcdescni}[2]{%
290 \begin{fulllineitems}%
291 \funclineni{#1}{#2}%
292}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000293
Fred Drakefb5e54d1998-02-19 06:23:06 +0000294\newenvironment{classdesc}[2]{%
295 \begin{fulllineitems}%
296 \item[\code{\bfcode{#1}(\varvars{#2})}]%
297 \ttindex{#1}%
298 \def\baseclasses##1{}%
299}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000300
Fred Drakefb5e54d1998-02-19 06:23:06 +0000301\newenvironment{excdesc}[1]{%
302 \begin{fulllineitems}%
303 \item[\bfcode{#1}]\ttindex{#1}%
304}{\end{fulllineitems}}
305
Fred Drakeaebc6f31998-02-13 14:34:04 +0000306\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000307\newenvironment{datadesc}[1]{%
308 \begin{fulllineitems}%
309 \dataline{#1}%
310}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000311
Fred Drakeaebc6f31998-02-13 14:34:04 +0000312% similar to {datadesc}, but doesn't add to the index
313\newcommand{\datalineni}[1]{\item[\bfcode{#1}]}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000314\newenvironment{datadescni}[1]{%
315 \begin{fulllineitems}%
316 \datalineni{#1}%
317}{\end{fulllineitems}}
Fred Drakeaebc6f31998-02-13 14:34:04 +0000318
Fred Drakefb5e54d1998-02-19 06:23:06 +0000319\newenvironment{opcodedesc}[2]{%
320 \begin{fulllineitems}%
321 \item[\bfcode{#1}\quad\var{#2}]%
322}{\end{fulllineitems}}
Fred Drakea610f9f1997-12-03 03:42:39 +0000323
324
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000325\let\nodename=\label
326
Fred Drakedc8af0a1998-02-13 06:48:05 +0000327% For these commands, use \command{} to get the typography right, not
328% {\command}. This works better with the texinfo translation.
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000329\newcommand{\ABC}{{\sc abc}}
330\newcommand{\UNIX}{{\sc Unix}}
Fred Drake311c1961998-01-20 05:07:19 +0000331\newcommand{\POSIX}{POSIX}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000332\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000333\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000334\newcommand{\C}{C}
335\newcommand{\EOF}{{\sc eof}}
Guido van Rossum9231c8f1997-05-15 21:43:21 +0000336\newcommand{\NULL}{\code{NULL}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000337
338% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000339\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 +0000340\mbox{\codefont{#1}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000341
Fred Drakefb5e54d1998-02-19 06:23:06 +0000342\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000343\newcommand{\kbd}[1]{\mbox{\tt #1}}
344\newcommand{\key}[1]{\mbox{\tt #1}}
345\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000346% This weird definition of \var{} allows it to always appear in roman
347% italics, and won't get funky in code fragments when we play around
348% with fonts.
349\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000350\renewcommand{\emph}[1]{{\em #1\/}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000351\newcommand{\dfn}[1]{\emph{#1}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000352\newcommand{\strong}[1]{{\bf #1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000353% let's experiment with a new font:
Fred Drakedc8af0a1998-02-13 06:48:05 +0000354\newcommand{\file}[1]{\mbox{`\small\textsf{#1}'}}
Fred Drake0c17d661998-02-18 14:24:19 +0000355\@ifundefined{pdfannotlink}{%
Fred Drake53740451998-02-17 15:13:01 +0000356 \newcommand{\url}[1]{\mbox{\small\textsf{#1}}}%
Fred Drake0c17d661998-02-18 14:24:19 +0000357}{
358 \input{pdfcolor}% this really isn't a package
359 \newcommand{\url}[1]{{%
360 \pdfannotlink user{/C [1 1 1] /S /URI /URI (#1)}%
361 \NavyBlue% color of the link text
362 \mbox{\small\textsf{#1}}%
363 \Black% Turn it back off; these are declarative
364 \pdfendlink}}% and don't appear bound to the current
365}% formatting "box".
Fred Drake4186cd31998-02-18 17:21:09 +0000366\newcommand{\email}[1]{\mbox{\small\textsf{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000367
Fred Drake9b550d91996-11-11 20:43:46 +0000368\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000369
370\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000371\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000372
Fred Drakedc8af0a1998-02-13 06:48:05 +0000373% These should be used for all references to identifiers which are
374% used to refer to instances of specific language constructs. See the
375% names for specific semantic assignments.
Fred Drake311c1961998-01-20 05:07:19 +0000376%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000377% For now, don't do anything really fancy with them; just use them as
378% logical markup. This might change in the future.
Fred Drake311c1961998-01-20 05:07:19 +0000379%
380\let\module=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000381\let\keyword=\code
382\let\exception=\code
Fred Drake311c1961998-01-20 05:07:19 +0000383\let\class=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000384\let\function=\code
Fred Drakefb5e54d1998-02-19 06:23:06 +0000385\let\member=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000386\let\method=\code
387
Fred Drakefb5e54d1998-02-19 06:23:06 +0000388\let\cfunction=\code
389\let\ctype=\code
390\let\cdata=\code
391
392% constants defined in Python modules or C headers, not language constants:
Fred Drakedd28d571998-01-22 15:55:21 +0000393\let\constant=\code
Fred Drake311c1961998-01-20 05:07:19 +0000394
395\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake06f169b1998-02-11 23:08:20 +0000396\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000397\newcommand{\program}[1]{\strong{#1}}
Fred Drake311c1961998-01-20 05:07:19 +0000398
399
Fred Drakefb5e54d1998-02-19 06:23:06 +0000400\newenvironment{tableii}[4]{%
401 \begin{center}%
402 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
403 \begin{tabular}{#1}\hline#3&#4\\ \hline%
404}{%
405 \hline%
406 \end{tabular}%
407 \end{center}%
408}
Guido van Rossume7af5a01994-08-01 12:39:35 +0000409
Fred Drakefb5e54d1998-02-19 06:23:06 +0000410\newenvironment{tableiii}[5]{%
411 \begin{center}%
412 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
413 \begin{tabular}{#1}\hline#3&#4&#5\\%
414 \hline%
415}{%
416 \hline%
417 \end{tabular}%
418 \end{center}%
419}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000420
Fred Drakefb5e54d1998-02-19 06:23:06 +0000421\newcommand{\itemnewline}[1]{%
422 \@tempdima\linewidth%
423 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
424}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000425
Fred Drake9e243091998-01-18 05:09:54 +0000426\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000427
428% Cross-referencing (AMK)
429% Sample usage:
430% \begin{seealso}
431% \seemodule{rand}{Uniform random number generator}; % Module xref
Fred Drakedc8af0a1998-02-13 06:48:05 +0000432% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000433% \end{seealso}
434
Fred Drakefb5e54d1998-02-19 06:23:06 +0000435\newenvironment{seealso}[0]{
436 \strong{See Also:}\par
437 % These should only be defined within the {seealso} environment:
438 \def\seemodule##1##2{\ref{module-##1}:\quad Module \module{##1}\quad (##2)}
439 \def\seetext##1{\par{##1}}
440}{\par}
441
Fred Drakeda941ef1998-01-02 02:57:41 +0000442
Fred Drakedc8af0a1998-02-13 06:48:05 +0000443% Fix the theindex environment to add an entry to the Table of
444% Contents; this is much nicer than just having to jump to the end of
445% the book and flip around, especially with multiple indexes.
Fred Drakeda941ef1998-01-02 02:57:41 +0000446%
447\let\OldTheindex=\theindex
Fred Drakefb5e54d1998-02-19 06:23:06 +0000448\renewcommand{\theindex}{
449 \cleardoublepage
450 \OldTheindex
451 \addcontentsline{toc}{chapter}{\indexname}
Fred Drakeda941ef1998-01-02 02:57:41 +0000452}
Fred Drake031ad4b1998-01-09 05:34:23 +0000453
454% Use a similar trick to catch the end of the {abstract} environment,
455% but here make sure the abstract is followed by a blank page if the
456% 'openright' option is used.
457%
458\let\OldEndAbstract=\endabstract
Fred Drake06f169b1998-02-11 23:08:20 +0000459\renewcommand{\endabstract}{
Fred Drake737e73e1998-01-13 22:40:08 +0000460 \if@openright
461 \ifodd\value{page}
462 \typeout{Adding blank page after the abstract.}
463 \vfil\pagebreak
Fred Drake031ad4b1998-01-09 05:34:23 +0000464 \fi
Fred Drake737e73e1998-01-13 22:40:08 +0000465 \fi
466 \OldEndAbstract
Fred Drake031ad4b1998-01-09 05:34:23 +0000467}
468
Fred Drakedc8af0a1998-02-13 06:48:05 +0000469% This wraps the \tableofcontents macro with all the magic to get the
470% spacing right and have the right number of pages if the 'openright'
Fred Drake031ad4b1998-01-09 05:34:23 +0000471% option has been used. This eliminates a fair amount of crud in the
472% individual document files.
473%
Fred Drake737e73e1998-01-13 22:40:08 +0000474\let\OldTableofcontents=\tableofcontents
Fred Drake06f169b1998-02-11 23:08:20 +0000475\renewcommand{\tableofcontents}[0]{%
476 \setcounter{page}{1}%
477 \pagebreak%
478 \pagestyle{plain}%
479 {%
480 \parskip = 0mm%
481 \OldTableofcontents%
482 \if@openright%
483 \ifodd\value{page}%
484 \typeout{Adding blank page after the table of contents.}%
485 \pagebreak\hspace{0pt}%
486 \fi%
487 \fi%
488 }%
Fred Drake4c689631998-02-13 16:58:49 +0000489 \cleardoublepage%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000490 \pagenumbering{arabic}%
Fred Drake76183c01998-02-16 22:30:10 +0000491 \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
Fred Drake06f169b1998-02-11 23:08:20 +0000492}
493
Fred Drakedc8af0a1998-02-13 06:48:05 +0000494% Allow the release number to be specified independently of the
495% \date{}. This allows the date to reflect the document's date and
496% release to specify the Python release that is documented.
497%
Fred Drake06f169b1998-02-11 23:08:20 +0000498\newcommand{\@release}{}
499\newcommand{\version}{}
500\newcommand{\releasename}{Release}
501\newcommand{\release}[1]{%
502 \renewcommand{\@release}{\releasename\space\version}%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000503 \renewcommand{\version}{#1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000504
Fred Drakedc8af0a1998-02-13 06:48:05 +0000505% Allow specification of the author's address separately from the
506% author's name. This can be used to format them differently, which
507% is a good thing.
508%
Fred Drake06f169b1998-02-11 23:08:20 +0000509\newcommand{\@authoraddress}{}
510\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
511
Fred Drakedc8af0a1998-02-13 06:48:05 +0000512% Change the title page to look a bit better, and fit in with the
513% fncychap ``Bjarne'' style a bit better.
514%
Fred Drakefb5e54d1998-02-19 06:23:06 +0000515\renewcommand{\maketitle}{%
516 \begin{titlepage}%
517 \let\footnotesize\small
518 \let\footnoterule\relax
519 \@ifundefined{ChTitleVar}{}{%
520 \mghrulefill{\RW}}%
521 \@ifundefined{pdfinfo}{}{
522 \pdfinfo
523 author {\@author}
524 title {\@title}
525 }
526 \begin{flushright}%
527 {\rm\Huge\HeaderFamily \@title \par}%
528 {\em\LARGE\HeaderFamily \@release \par}
529 \vfill
530 {\LARGE\HeaderFamily \@author \par}
531 \vfill\vfill
532 {\large
533 \@date \par
534 \vskip 3em
535 \@authoraddress \par
536 }%
537 \end{flushright}%\par
538 \@thanks
Fred Drake06f169b1998-02-11 23:08:20 +0000539 \end{titlepage}%
540 \setcounter{footnote}{0}%
541 \let\thanks\relax\let\maketitle\relax
542 \gdef\@thanks{}\gdef\@author{}\gdef\@title{}
543}
544
Fred Drakedc8af0a1998-02-13 06:48:05 +0000545% ``minitoc'' support; works fairly well but not all chapters do well
546% with it. Has some weird side effects that I haven't tracked down;
547% don't use it for real at this time.
Fred Drake06f169b1998-02-11 23:08:20 +0000548%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000549% To enable, uncomment the following line only (don't do it!):
Fred Drake06f169b1998-02-11 23:08:20 +0000550%\RequirePackage{minitoc}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000551%
552% Maybe this should all be removed. But I think something like this
553% would be really nice if it can be integrated with the ``list of
554% modules'' at the top of module-documentation chapters. But it might
555% require a completely new environment, perhaps based on {list}.
Fred Drake06f169b1998-02-11 23:08:20 +0000556
Fred Drake06f169b1998-02-11 23:08:20 +0000557\newif\if@minitocprinted
558\newcommand{\suppressminitoc}{\@minitocprintedtrue}
559\@ifundefined{minitoc}{
560 % allow \minitoc to be used even if the package hasn't been loaded.
561 \newcommand{\minitoc}{\@minitocprintedtrue}
562}{
563 \dominitoc
564 \newif\if@firstsection
565 \let\OldChapter=\chapter
566 \let\OldSection=\section
567 \let\OldMinitoc=\minitoc
568 % This will only include the minitoc once per chapter
569 \renewcommand{\minitoc}{%
570 \if@minitocprinted{}\else%
571 \OldMinitoc%
572 \@minitocprintedtrue%
573 \fi%
Fred Drake031ad4b1998-01-09 05:34:23 +0000574 }
Fred Drake06f169b1998-02-11 23:08:20 +0000575 % This includes a minitoc before the first \section{}, if it hasn't
576 % already been printed using an explicit \minitoc call.
577 \newcommand{\NewSection}[1]{%
578 \if@firstsection%
579 \if@minitocprinted{}\else%
580 \vskip 15pt%
581 \minitoc%
582 \@firstsectionfalse%
583 \fi%
584 \fi%
585 \OldSection{#1}%
586 }
587 % Reset the flags for each chaper to let the automatic stuff work.
588 \newcommand{\NewChapter}[1]{%
589 \OldChapter{#1}%
590 \@firstsectiontrue%
591 \@minitocprintedfalse%
592 }
593 \let\chapter=\NewChapter
594 \let\section=\NewSection
595 \typeout{Including mini Tables of Contents in each chapter.}
596}
597
Fred Drakedc8af0a1998-02-13 06:48:05 +0000598% This sets up the fancy chapter headings that make the documents look
599% at least a little better than the usual LaTeX output.
Fred Drake06f169b1998-02-11 23:08:20 +0000600%
Fred Drake06f169b1998-02-11 23:08:20 +0000601\@ifundefined{ChTitleVar}{}{
Fred Drakedc8af0a1998-02-13 06:48:05 +0000602 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
603 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
604 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
Fred Drake06f169b1998-02-11 23:08:20 +0000605 % This creates chapter heads without the leading \vspace*{}:
606 \def\@makechapterhead#1{%
607 {\parindent \z@ \raggedright \normalfont
608 \ifnum \c@secnumdepth >\m@ne
609 \DOCH
610 \fi
611 \interlinepenalty\@M
612 \DOTI{#1}
613 }
614 }
615 \typeout{Using fancy chapter headings.}
Fred Drake031ad4b1998-01-09 05:34:23 +0000616}