blob: 5f4aff4f7acdbcd4425ed91e644b811bf039b423 [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
Fred Drakeeb9b8311998-02-23 21:37:27 +000027% it. You'd also end up with a mixed page style; uglier than stock LaTeX!
Fred Drakefb5e54d1998-02-19 06:23:06 +000028%
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.
Fred Drakeeb9b8311998-02-23 21:37:27 +000036\@ifundefined{pdfannotlink}{
37 \RequirePackage{hyperref}
38}{%
Fred Drake4186cd31998-02-18 17:21:09 +000039 \pdfcompresslevel=9
40 \let\OldLabel=\label
41 \renewcommand{\label}[1]{%
42 \OldLabel{#1}%
43 {\pdfdest name {#1} fit}%
44 }
Fred Drakeeb9b8311998-02-23 21:37:27 +000045 \RequirePackage[pdftex]{hyperref}
Fred Drake4186cd31998-02-18 17:21:09 +000046}
Fred Drake30d17821998-02-17 15:56:55 +000047
Guido van Rossumdaff1751997-06-02 17:35:01 +000048% Increase printable page size (copied from fullpage.sty)
49\topmargin 0pt
50\advance \topmargin by -\headheight
51\advance \topmargin by -\headsep
Fred Drake9e243091998-01-18 05:09:54 +000052
Fred Drake76183c01998-02-16 22:30:10 +000053\textheight 8.7in
Fred Drake9e243091998-01-18 05:09:54 +000054
Guido van Rossumdaff1751997-06-02 17:35:01 +000055\oddsidemargin 0pt
56\evensidemargin \oddsidemargin
57\marginparwidth 0.5in
Fred Drake9e243091998-01-18 05:09:54 +000058
Guido van Rossumdaff1751997-06-02 17:35:01 +000059\textwidth 6.5in
60
Guido van Rossum643d9321992-03-31 18:53:47 +000061% Style parameters and macros used by most documents here
Guido van Rossum5badc751992-03-06 10:55:46 +000062\raggedbottom
63\sloppy
Fred Drakefb5e54d1998-02-19 06:23:06 +000064\parindent = 0mm
65\parskip = 2mm
66\hbadness = 5000 % don't print trivial gripes
Guido van Rossum5badc751992-03-06 10:55:46 +000067
Fred Drakefb5e54d1998-02-19 06:23:06 +000068\pagestyle{empty} % start this way; change for
69\pagenumbering{roman} % ToC & chapters
Fred Drakedc8af0a1998-02-13 06:48:05 +000070\setcounter{secnumdepth}{1}
71
Fred Drakefb5e54d1998-02-19 06:23:06 +000072% Use this to set the font family for headers and other decor:
73\newcommand{\HeaderFamily}{\sffamily}
74
Fred Drake76183c01998-02-16 22:30:10 +000075% Redefine the 'normal' header/footer style when using "fancyhdr" package:
76\@ifundefined{fancyhf}{}{
Fred Drakefb5e54d1998-02-19 06:23:06 +000077 % Use \pagestyle{normal} as the primary pagestyle for text.
78 \fancypagestyle{normal}{
79 \fancyhf{}
80 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
81 \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}
82 \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}
83 \renewcommand{\headrulewidth}{0pt}
84 \renewcommand{\footrulewidth}{0.4pt}
Fred Drake76183c01998-02-16 22:30:10 +000085 }
86 % Update the plain style so we get the page number & footer line,
87 % but not a chapter or section title. This is to keep the first
88 % page of a chapter and the blank page between chapters `clean.'
Fred Drakefb5e54d1998-02-19 06:23:06 +000089 \fancypagestyle{plain}{
90 \fancyhf{}
91 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
92 \renewcommand{\headrulewidth}{0pt}
93 \renewcommand{\footrulewidth}{0.4pt}
Fred Drake76183c01998-02-16 22:30:10 +000094 }
95 % Redefine \cleardoublepage so that the blank page between chapters
Fred Drakefb5e54d1998-02-19 06:23:06 +000096 % gets the plain style and not the fancy style. This is described
97 % in the documentation for the fancyhdr package by Piet von Oostrum.
98 \renewcommand{\cleardoublepage}{
99 \clearpage\if@twoside \ifodd\c@page\else
Fred Drake76183c01998-02-16 22:30:10 +0000100 \hbox{}
101 \thispagestyle{plain}
102 \newpage
103 \if@twocolumn\hbox{}\newpage\fi\fi\fi}
104}
105
Fred Drake9e243091998-01-18 05:09:54 +0000106% old code font selections:
107\let\codefont=\tt
108\let\sectcodefont=\tt
109
110% (Haven't found a new one that gets <, >, and _ right without being
111% monospaced.)
112
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000113% Variable used by begin code command
Guido van Rossum44000ed1991-01-24 16:54:29 +0000114\newlength{\codewidth}
Guido van Rossum44000ed1991-01-24 16:54:29 +0000115
Fred Drakedc8af0a1998-02-13 06:48:05 +0000116\newcommand{\examplevspace}{2mm}
117\newcommand{\exampleindent}{1cm}
Guido van Rossum5badc751992-03-06 10:55:46 +0000118% Command to start a code block (follow this by \begin{verbatim})
Fred Drakedc8af0a1998-02-13 06:48:05 +0000119\newcommand{\b@code}{%
120 \begingroup%
121 \setlength{\parindent}\exampleindent%
122 % Calculate the text width for the minipage:
123 \setlength{\codewidth}{\linewidth}%
124 \addtolength{\codewidth}{-\parindent}%
125 %
126 \par%
127 \vspace\examplevspace%
128 \indent%
129 \begin{minipage}[t]{\codewidth}%
130 \small%
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000131}
132
Guido van Rossum5badc751992-03-06 10:55:46 +0000133% Command to end a code block (precede this by \end{verbatim})
Fred Drakedc8af0a1998-02-13 06:48:05 +0000134\newcommand{\e@code}{%
135 \end{minipage}%
136 \endgroup%
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000137}
Guido van Rossum5badc751992-03-06 10:55:46 +0000138
Fred Drakedc8af0a1998-02-13 06:48:05 +0000139\let\OldVerbatim=\verbatim
140\let\OldEndVerbatim=\endverbatim
141\renewcommand{\verbatim}{\b@code\OldVerbatim}
142\renewcommand{\endverbatim}{\OldEndVerbatim\e@code}
143
Fred Drakefb5e54d1998-02-19 06:23:06 +0000144% Augment the sectioning commands used to get our own font family in place:
Fred Drakedc8af0a1998-02-13 06:48:05 +0000145\renewcommand{\section}{\@startsection {section}{1}{\z@}%
146 {-3.5ex \@plus -1ex \@minus -.2ex}%
147 {2.3ex \@plus.2ex}%
148 {\reset@font\Large\HeaderFamily}}
149\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
150 {-3.25ex\@plus -1ex \@minus -.2ex}%
151 {1.5ex \@plus .2ex}%
152 {\reset@font\large\HeaderFamily}}
153\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
154 {-3.25ex\@plus -1ex \@minus -.2ex}%
155 {1.5ex \@plus .2ex}%
156 {\reset@font\normalsize\HeaderFamily}}
157\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
158 {3.25ex \@plus1ex \@minus.2ex}%
159 {-1em}%
160 {\reset@font\normalsize\HeaderFamily}}
161\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
162 {3.25ex \@plus1ex \@minus .2ex}%
163 {-1em}%
164 {\reset@font\normalsize\HeaderFamily}}
165
166
Guido van Rossumecae0b71996-06-26 19:03:20 +0000167% Underscore hack (only act like subscript operator if in math mode)
168%
169% The following is due to Mark Wooding (the old version didn't work with
170% Latex 2e.
171
172\DeclareRobustCommand\hackscore{%
173 \ifmmode_\else\textunderscore\fi%
174}
175\begingroup
176\catcode`\_\active
177\def\next{%
178 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
179}
180\expandafter\endgroup\next
181
182%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000183% This is the old hack, which didn't work with 2e.
184% You should not need this since the rest of the documentation is now
185% LaTeX2e-only.
Guido van Rossumecae0b71996-06-26 19:03:20 +0000186%
187%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
188%\catcode`\_=12
189%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
Guido van Rossum5badc751992-03-06 10:55:46 +0000190
Fred Drakeb37a3951998-02-06 22:52:52 +0000191
Fred Drakedc8af0a1998-02-13 06:48:05 +0000192
Fred Drakeb37a3951998-02-06 22:52:52 +0000193%% Lots of index-entry generation support.
194
Fred Drakedc8af0a1998-02-13 06:48:05 +0000195% Command to wrap around stuff that refers to function / module /
196% attribute names in the index. Default behavior: like \code{}. To
197% just keep the index entries in the roman font, uncomment the second
198% definition to use instead; it matches O'Reilly style more.
199%
Fred Drakeb37a3951998-02-06 22:52:52 +0000200\newcommand{\idxcode}[1]{\codefont{#1}}
201%\renewcommand{\idxcode}[1]{#1}
Guido van Rossum5badc751992-03-06 10:55:46 +0000202
203% Command to generate two index entries (using subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +0000204\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000205
206% And three entries (using only one level of subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +0000207\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000208
209% And four (again, using only one level of subentries)
210\newcommand{\indexiv}[4]{
211\index{#1!#2 #3 #4}
212\index{#2!#3 #4, #1}
213\index{#3!#4, #1 #2}
214\index{#4!#1 #2 #3}
215}
216
Fred Drakedc8af0a1998-02-13 06:48:05 +0000217% Command to generate a reference to a function, statement, keyword,
218% operator.
Fred Drakeb37a3951998-02-06 22:52:52 +0000219\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
220\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
221\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Guido van Rossum6886c831992-04-03 14:44:27 +0000222\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000223\newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1()}} (built-in function)}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000224
225% Add an index entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000226\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake4af18141997-12-15 22:08:14 +0000227\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000228\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
229\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
230
Fred Drakeda941ef1998-01-02 02:57:41 +0000231% support for the module index
232\newwrite\modindexfile
233\openout\modindexfile=modules.idx
234
Fred Drake207e57b1997-12-15 21:37:45 +0000235% Add the defining entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000236\newcommand{\defmodindex}[2]{%
237 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
Fred Drakeda941ef1998-01-02 02:57:41 +0000238 \write\modindexfile{#1 \thepage}}
Fred Drakeb1927471998-02-04 14:43:36 +0000239\newcommand{\modindex}[1]{\defmodindex{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000240\newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }}
241\newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }}
Guido van Rossum5badc751992-03-06 10:55:46 +0000242
243% Additional string for an index entry
Fred Drakedc8af0a1998-02-13 06:48:05 +0000244\newcommand{\index@subitem}{}
245\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
246\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000247
Guido van Rossum5badc751992-03-06 10:55:46 +0000248
Fred Drakeef146221998-02-19 21:02:26 +0000249% {fulllineitems} is used in one place in libregex.tex, but is really for
250% internal use in this file.
251%
Fred Drakefb5e54d1998-02-19 06:23:06 +0000252\newenvironment{fulllineitems}{
253 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
254 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
255 \itemsep -\parsep
256 \let\makelabel=\itemnewline}
257}{\end{list}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000258
259
Guido van Rossum36f35021997-05-22 20:43:24 +0000260% cfuncdesc should be called as
261% \begin{cfuncdesc}{type}{name}{arglist}
262% ... description ...
263% \end{cfuncdesc}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000264\newenvironment{cfuncdesc}[3]{%
265 \begin{fulllineitems}%
266 \item[\code{#1 \bfcode{#2}(\varvars{#3})}]%
267 \index{#2@{\idxcode{#2()}}}%
268}{\end{fulllineitems}}
Fred Drakeeb33c781996-10-29 15:55:08 +0000269
Fred Drakefb5e54d1998-02-19 06:23:06 +0000270\newenvironment{cvardesc}[2]{%
271 \begin{fulllineitems}%
272 \item[\code{#1 \bfcode{#2}}]%
273 \index{#2@{\idxcode{#2}}}%
274}{\end{fulllineitems}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000275
Fred Drakefb5e54d1998-02-19 06:23:06 +0000276\newenvironment{ctypedesc}[1]{%
277 \begin{fulllineitems}%
278 \item[\bfcode{#1}]\ttindex{#1}
279}{\end{fulllineitems}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000280
Fred Drakefb5e54d1998-02-19 06:23:06 +0000281\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
282\newenvironment{funcdesc}[2]{%
283 \begin{fulllineitems}%
284 \funcline{#1}{#2}%
285}{\end{fulllineitems}}
286
287\newcommand{\optional}[1]{%
288 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000289
Fred Drakeaebc6f31998-02-13 14:34:04 +0000290% similar to {funcdesc}, but doesn't add to the index
291\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000292\newenvironment{funcdescni}[2]{%
293 \begin{fulllineitems}%
294 \funclineni{#1}{#2}%
295}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000296
Fred Drakefb5e54d1998-02-19 06:23:06 +0000297\newenvironment{classdesc}[2]{%
298 \begin{fulllineitems}%
299 \item[\code{\bfcode{#1}(\varvars{#2})}]%
300 \ttindex{#1}%
301 \def\baseclasses##1{}%
302}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000303
Fred Drakefb5e54d1998-02-19 06:23:06 +0000304\newenvironment{excdesc}[1]{%
305 \begin{fulllineitems}%
306 \item[\bfcode{#1}]\ttindex{#1}%
307}{\end{fulllineitems}}
308
Fred Drakeaebc6f31998-02-13 14:34:04 +0000309\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000310\newenvironment{datadesc}[1]{%
311 \begin{fulllineitems}%
312 \dataline{#1}%
313}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000314
Fred Drakeaebc6f31998-02-13 14:34:04 +0000315% similar to {datadesc}, but doesn't add to the index
316\newcommand{\datalineni}[1]{\item[\bfcode{#1}]}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000317\newenvironment{datadescni}[1]{%
318 \begin{fulllineitems}%
319 \datalineni{#1}%
320}{\end{fulllineitems}}
Fred Drakeaebc6f31998-02-13 14:34:04 +0000321
Fred Drakefb5e54d1998-02-19 06:23:06 +0000322\newenvironment{opcodedesc}[2]{%
323 \begin{fulllineitems}%
324 \item[\bfcode{#1}\quad\var{#2}]%
325}{\end{fulllineitems}}
Fred Drakea610f9f1997-12-03 03:42:39 +0000326
327
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000328\let\nodename=\label
329
Fred Drakedc8af0a1998-02-13 06:48:05 +0000330% For these commands, use \command{} to get the typography right, not
331% {\command}. This works better with the texinfo translation.
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000332\newcommand{\ABC}{{\sc abc}}
333\newcommand{\UNIX}{{\sc Unix}}
Fred Drake311c1961998-01-20 05:07:19 +0000334\newcommand{\POSIX}{POSIX}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000335\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000336\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000337\newcommand{\C}{C}
338\newcommand{\EOF}{{\sc eof}}
Guido van Rossum9231c8f1997-05-15 21:43:21 +0000339\newcommand{\NULL}{\code{NULL}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000340
341% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000342\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 +0000343\mbox{\codefont{#1}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000344
Fred Drakefb5e54d1998-02-19 06:23:06 +0000345\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000346\newcommand{\kbd}[1]{\mbox{\tt #1}}
347\newcommand{\key}[1]{\mbox{\tt #1}}
348\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000349% This weird definition of \var{} allows it to always appear in roman
350% italics, and won't get funky in code fragments when we play around
351% with fonts.
352\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000353\renewcommand{\emph}[1]{{\em #1\/}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000354\newcommand{\dfn}[1]{\emph{#1}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000355\newcommand{\strong}[1]{{\bf #1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000356% let's experiment with a new font:
Fred Drakedc8af0a1998-02-13 06:48:05 +0000357\newcommand{\file}[1]{\mbox{`\small\textsf{#1}'}}
Fred Drake0c17d661998-02-18 14:24:19 +0000358\@ifundefined{pdfannotlink}{%
Fred Drakeeb9b8311998-02-23 21:37:27 +0000359 % Use \renew since hyperref defined this already:
360 \renewcommand{\url}[1]{\mbox{\small\textsf{#1}}}%
Fred Drake0c17d661998-02-18 14:24:19 +0000361}{
362 \input{pdfcolor}% this really isn't a package
Fred Drakeeb9b8311998-02-23 21:37:27 +0000363 % Use \renew since hyperref defined this already:
364 \renewcommand{\url}[1]{{%
Fred Drake0c17d661998-02-18 14:24:19 +0000365 \pdfannotlink user{/C [1 1 1] /S /URI /URI (#1)}%
366 \NavyBlue% color of the link text
367 \mbox{\small\textsf{#1}}%
368 \Black% Turn it back off; these are declarative
369 \pdfendlink}}% and don't appear bound to the current
370}% formatting "box".
Fred Drake4186cd31998-02-18 17:21:09 +0000371\newcommand{\email}[1]{\mbox{\small\textsf{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000372
Fred Drake9b550d91996-11-11 20:43:46 +0000373\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000374
375\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000376\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000377
Fred Drakedc8af0a1998-02-13 06:48:05 +0000378% These should be used for all references to identifiers which are
379% used to refer to instances of specific language constructs. See the
380% names for specific semantic assignments.
Fred Drake311c1961998-01-20 05:07:19 +0000381%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000382% For now, don't do anything really fancy with them; just use them as
383% logical markup. This might change in the future.
Fred Drake311c1961998-01-20 05:07:19 +0000384%
385\let\module=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000386\let\keyword=\code
387\let\exception=\code
Fred Drake311c1961998-01-20 05:07:19 +0000388\let\class=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000389\let\function=\code
Fred Drakefb5e54d1998-02-19 06:23:06 +0000390\let\member=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000391\let\method=\code
392
Fred Drakefb5e54d1998-02-19 06:23:06 +0000393\let\cfunction=\code
394\let\ctype=\code
395\let\cdata=\code
396
397% constants defined in Python modules or C headers, not language constants:
Fred Drakedd28d571998-01-22 15:55:21 +0000398\let\constant=\code
Fred Drake311c1961998-01-20 05:07:19 +0000399
400\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake06f169b1998-02-11 23:08:20 +0000401\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000402\newcommand{\program}[1]{\strong{#1}}
Fred Drake311c1961998-01-20 05:07:19 +0000403
404
Fred Drakefb5e54d1998-02-19 06:23:06 +0000405\newenvironment{tableii}[4]{%
406 \begin{center}%
407 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
408 \begin{tabular}{#1}\hline#3&#4\\ \hline%
409}{%
410 \hline%
411 \end{tabular}%
412 \end{center}%
413}
Guido van Rossume7af5a01994-08-01 12:39:35 +0000414
Fred Drakefb5e54d1998-02-19 06:23:06 +0000415\newenvironment{tableiii}[5]{%
416 \begin{center}%
417 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
418 \begin{tabular}{#1}\hline#3&#4&#5\\%
419 \hline%
420}{%
421 \hline%
422 \end{tabular}%
423 \end{center}%
424}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000425
Fred Drakefb5e54d1998-02-19 06:23:06 +0000426\newcommand{\itemnewline}[1]{%
427 \@tempdima\linewidth%
428 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
429}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000430
Fred Drake9e243091998-01-18 05:09:54 +0000431\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000432
433% Cross-referencing (AMK)
434% Sample usage:
435% \begin{seealso}
436% \seemodule{rand}{Uniform random number generator}; % Module xref
Fred Drakedc8af0a1998-02-13 06:48:05 +0000437% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000438% \end{seealso}
439
Fred Drakefb5e54d1998-02-19 06:23:06 +0000440\newenvironment{seealso}[0]{
441 \strong{See Also:}\par
442 % These should only be defined within the {seealso} environment:
443 \def\seemodule##1##2{\ref{module-##1}:\quad Module \module{##1}\quad (##2)}
444 \def\seetext##1{\par{##1}}
445}{\par}
446
Fred Drakeda941ef1998-01-02 02:57:41 +0000447
Fred Drakedc8af0a1998-02-13 06:48:05 +0000448% Fix the theindex environment to add an entry to the Table of
449% Contents; this is much nicer than just having to jump to the end of
450% the book and flip around, especially with multiple indexes.
Fred Drakeda941ef1998-01-02 02:57:41 +0000451%
452\let\OldTheindex=\theindex
Fred Drakefb5e54d1998-02-19 06:23:06 +0000453\renewcommand{\theindex}{
454 \cleardoublepage
455 \OldTheindex
456 \addcontentsline{toc}{chapter}{\indexname}
Fred Drakeda941ef1998-01-02 02:57:41 +0000457}
Fred Drake031ad4b1998-01-09 05:34:23 +0000458
459% Use a similar trick to catch the end of the {abstract} environment,
460% but here make sure the abstract is followed by a blank page if the
461% 'openright' option is used.
462%
463\let\OldEndAbstract=\endabstract
Fred Drake06f169b1998-02-11 23:08:20 +0000464\renewcommand{\endabstract}{
Fred Drake737e73e1998-01-13 22:40:08 +0000465 \if@openright
466 \ifodd\value{page}
467 \typeout{Adding blank page after the abstract.}
468 \vfil\pagebreak
Fred Drake031ad4b1998-01-09 05:34:23 +0000469 \fi
Fred Drake737e73e1998-01-13 22:40:08 +0000470 \fi
471 \OldEndAbstract
Fred Drake031ad4b1998-01-09 05:34:23 +0000472}
473
Fred Drakedc8af0a1998-02-13 06:48:05 +0000474% This wraps the \tableofcontents macro with all the magic to get the
475% spacing right and have the right number of pages if the 'openright'
Fred Drake031ad4b1998-01-09 05:34:23 +0000476% option has been used. This eliminates a fair amount of crud in the
477% individual document files.
478%
Fred Drake737e73e1998-01-13 22:40:08 +0000479\let\OldTableofcontents=\tableofcontents
Fred Drake06f169b1998-02-11 23:08:20 +0000480\renewcommand{\tableofcontents}[0]{%
481 \setcounter{page}{1}%
482 \pagebreak%
483 \pagestyle{plain}%
484 {%
485 \parskip = 0mm%
486 \OldTableofcontents%
487 \if@openright%
488 \ifodd\value{page}%
489 \typeout{Adding blank page after the table of contents.}%
490 \pagebreak\hspace{0pt}%
491 \fi%
492 \fi%
493 }%
Fred Drake4c689631998-02-13 16:58:49 +0000494 \cleardoublepage%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000495 \pagenumbering{arabic}%
Fred Drake76183c01998-02-16 22:30:10 +0000496 \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
Fred Drake06f169b1998-02-11 23:08:20 +0000497}
498
Fred Drakedc8af0a1998-02-13 06:48:05 +0000499% Allow the release number to be specified independently of the
500% \date{}. This allows the date to reflect the document's date and
501% release to specify the Python release that is documented.
502%
Fred Drake06f169b1998-02-11 23:08:20 +0000503\newcommand{\@release}{}
504\newcommand{\version}{}
505\newcommand{\releasename}{Release}
506\newcommand{\release}[1]{%
507 \renewcommand{\@release}{\releasename\space\version}%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000508 \renewcommand{\version}{#1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000509
Fred Drakedc8af0a1998-02-13 06:48:05 +0000510% Allow specification of the author's address separately from the
511% author's name. This can be used to format them differently, which
512% is a good thing.
513%
Fred Drake06f169b1998-02-11 23:08:20 +0000514\newcommand{\@authoraddress}{}
515\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
516
Fred Drakedc8af0a1998-02-13 06:48:05 +0000517% Change the title page to look a bit better, and fit in with the
518% fncychap ``Bjarne'' style a bit better.
519%
Fred Drakefb5e54d1998-02-19 06:23:06 +0000520\renewcommand{\maketitle}{%
521 \begin{titlepage}%
522 \let\footnotesize\small
523 \let\footnoterule\relax
524 \@ifundefined{ChTitleVar}{}{%
525 \mghrulefill{\RW}}%
526 \@ifundefined{pdfinfo}{}{
527 \pdfinfo
528 author {\@author}
529 title {\@title}
530 }
531 \begin{flushright}%
532 {\rm\Huge\HeaderFamily \@title \par}%
533 {\em\LARGE\HeaderFamily \@release \par}
534 \vfill
535 {\LARGE\HeaderFamily \@author \par}
536 \vfill\vfill
537 {\large
538 \@date \par
539 \vskip 3em
540 \@authoraddress \par
541 }%
542 \end{flushright}%\par
543 \@thanks
Fred Drake06f169b1998-02-11 23:08:20 +0000544 \end{titlepage}%
545 \setcounter{footnote}{0}%
546 \let\thanks\relax\let\maketitle\relax
547 \gdef\@thanks{}\gdef\@author{}\gdef\@title{}
548}
549
Fred Drakedc8af0a1998-02-13 06:48:05 +0000550% This sets up the fancy chapter headings that make the documents look
551% at least a little better than the usual LaTeX output.
Fred Drake06f169b1998-02-11 23:08:20 +0000552%
Fred Drake06f169b1998-02-11 23:08:20 +0000553\@ifundefined{ChTitleVar}{}{
Fred Drakedc8af0a1998-02-13 06:48:05 +0000554 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
555 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
556 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
Fred Drake06f169b1998-02-11 23:08:20 +0000557 % This creates chapter heads without the leading \vspace*{}:
558 \def\@makechapterhead#1{%
559 {\parindent \z@ \raggedright \normalfont
560 \ifnum \c@secnumdepth >\m@ne
561 \DOCH
562 \fi
563 \interlinepenalty\@M
564 \DOTI{#1}
565 }
566 }
567 \typeout{Using fancy chapter headings.}
Fred Drake031ad4b1998-01-09 05:34:23 +0000568}
Fred Drake5c19c7b1998-02-20 06:08:07 +0000569
570% Tell TeX about pathological hyphenation cases:
571\hyphenation{Base-HTTP-Re-quest-Hand-ler}