blob: ef194a44a3d42428fbf9bfd0609c51b570d56c6d [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 Drake9cf4bbd1998-02-25 15:29:43 +000034% for PDF output, use maximal compression
Fred Drakeeb9b8311998-02-23 21:37:27 +000035\@ifundefined{pdfannotlink}{
Fred Drake9cf4bbd1998-02-25 15:29:43 +000036 \let\LinkColor=\relax
37 \let\NormalColor=\relax
Fred Drakeeb9b8311998-02-23 21:37:27 +000038}{%
Fred Drake9cf4bbd1998-02-25 15:29:43 +000039 \input{pdfcolor}
40 \let\LinkColor=\NavyBlue
41 \let\NormalColor=\Black
Fred Drake4186cd31998-02-18 17:21:09 +000042 \pdfcompresslevel=9
Fred Drake9cf4bbd1998-02-25 15:29:43 +000043 \let\OldContentsline=\contentsline
44 \renewcommand{\contentsline}[3]{%
45 \OldContentsline{#1}{%
46 \pdfannotlink attr{/Border [0 0 0]} goto name{page.#3}%
47 \LinkColor#2\NormalColor%
48 \pdfendlink%
49 }{#3}%
50 }
Fred Drake4186cd31998-02-18 17:21:09 +000051 \let\OldLabel=\label
52 \renewcommand{\label}[1]{%
53 \OldLabel{#1}%
Fred Drake9cf4bbd1998-02-25 15:29:43 +000054 {\pdfdest name{label.#1} fit}%
Fred Drake4186cd31998-02-18 17:21:09 +000055 }
Fred Drake9cf4bbd1998-02-25 15:29:43 +000056 % This stuff adds a page.# destination to every PDF page, where # has
57 % the same formatting as the displayed page number. This doesn't really
58 % help with the frontmatter, but does fine with the body.
59 %
60 % This is *heavily* based on the hyperref package.
61 %
62 \def\@begindvi{%
63 \unvbox \@begindvibox
64 \@hyperfixhead
65 \global\let \@begindvi \@hyperfixhead
66 }
67 \def\hyperpageanchor{%
68 \hyper@anchorstart{page.\thepage}\hyper@anchorend
69 }
70 \let\HYPERPAGEANCHOR\hyperpageanchor
71 \def\@hyperfixhead{%
72 \let\H@old@thehead\@thehead
73 \gdef\@foo{\pdfdest name{page.\thepage} fit}%
74 \expandafter\ifx\expandafter\@empty\H@old@thehead
75 \def\H@old@thehead{\hfil}\fi
76 \def\@thehead{\@foo\relax\H@old@thehead}%
77 }
Fred Drake4186cd31998-02-18 17:21:09 +000078}
Fred Drake30d17821998-02-17 15:56:55 +000079
Guido van Rossumdaff1751997-06-02 17:35:01 +000080% Increase printable page size (copied from fullpage.sty)
81\topmargin 0pt
82\advance \topmargin by -\headheight
83\advance \topmargin by -\headsep
Fred Drake9e243091998-01-18 05:09:54 +000084
Fred Drake9cf4bbd1998-02-25 15:29:43 +000085% attempt to work a little better for A4 users
86\@ifundefined{paperheight}{
87 \textheight 9in
88}{
89 \textheight \paperheight
90 \advance\textheight by -2in
91}
Fred Drake9e243091998-01-18 05:09:54 +000092
Guido van Rossumdaff1751997-06-02 17:35:01 +000093\oddsidemargin 0pt
94\evensidemargin \oddsidemargin
95\marginparwidth 0.5in
Fred Drake9e243091998-01-18 05:09:54 +000096
Guido van Rossumdaff1751997-06-02 17:35:01 +000097\textwidth 6.5in
98
Guido van Rossum643d9321992-03-31 18:53:47 +000099% Style parameters and macros used by most documents here
Guido van Rossum5badc751992-03-06 10:55:46 +0000100\raggedbottom
101\sloppy
Fred Drakefb5e54d1998-02-19 06:23:06 +0000102\parindent = 0mm
103\parskip = 2mm
104\hbadness = 5000 % don't print trivial gripes
Guido van Rossum5badc751992-03-06 10:55:46 +0000105
Fred Drakefb5e54d1998-02-19 06:23:06 +0000106\pagestyle{empty} % start this way; change for
107\pagenumbering{roman} % ToC & chapters
Fred Drakedc8af0a1998-02-13 06:48:05 +0000108\setcounter{secnumdepth}{1}
109
Fred Drakefb5e54d1998-02-19 06:23:06 +0000110% Use this to set the font family for headers and other decor:
111\newcommand{\HeaderFamily}{\sffamily}
112
Fred Drake76183c01998-02-16 22:30:10 +0000113% Redefine the 'normal' header/footer style when using "fancyhdr" package:
114\@ifundefined{fancyhf}{}{
Fred Drakefb5e54d1998-02-19 06:23:06 +0000115 % Use \pagestyle{normal} as the primary pagestyle for text.
116 \fancypagestyle{normal}{
117 \fancyhf{}
118 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
119 \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}
120 \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}
121 \renewcommand{\headrulewidth}{0pt}
122 \renewcommand{\footrulewidth}{0.4pt}
Fred Drake76183c01998-02-16 22:30:10 +0000123 }
124 % Update the plain style so we get the page number & footer line,
125 % but not a chapter or section title. This is to keep the first
126 % page of a chapter and the blank page between chapters `clean.'
Fred Drakefb5e54d1998-02-19 06:23:06 +0000127 \fancypagestyle{plain}{
128 \fancyhf{}
129 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
130 \renewcommand{\headrulewidth}{0pt}
131 \renewcommand{\footrulewidth}{0.4pt}
Fred Drake76183c01998-02-16 22:30:10 +0000132 }
133 % Redefine \cleardoublepage so that the blank page between chapters
Fred Drakefb5e54d1998-02-19 06:23:06 +0000134 % gets the plain style and not the fancy style. This is described
135 % in the documentation for the fancyhdr package by Piet von Oostrum.
136 \renewcommand{\cleardoublepage}{
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000137 \clearpage\if@openright \ifodd\c@page\else
Fred Drake76183c01998-02-16 22:30:10 +0000138 \hbox{}
139 \thispagestyle{plain}
140 \newpage
141 \if@twocolumn\hbox{}\newpage\fi\fi\fi}
142}
143
Fred Drake9e243091998-01-18 05:09:54 +0000144% old code font selections:
145\let\codefont=\tt
146\let\sectcodefont=\tt
147
148% (Haven't found a new one that gets <, >, and _ right without being
149% monospaced.)
150
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000151
152% This sets up the {verbatim} environment to be indented and a minipage,
153% and to have all the other mostly nice properties that we want for
154% code samples.
155
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000156% Variable used by begin code command
Guido van Rossum44000ed1991-01-24 16:54:29 +0000157\newlength{\codewidth}
Guido van Rossum44000ed1991-01-24 16:54:29 +0000158
Fred Drakedc8af0a1998-02-13 06:48:05 +0000159\newcommand{\examplevspace}{2mm}
160\newcommand{\exampleindent}{1cm}
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000161
162\let\OldVerbatim=\verbatim
163\let\OldEndVerbatim=\endverbatim
164\renewcommand{\verbatim}{%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000165 \begingroup%
166 \setlength{\parindent}\exampleindent%
167 % Calculate the text width for the minipage:
168 \setlength{\codewidth}{\linewidth}%
169 \addtolength{\codewidth}{-\parindent}%
170 %
171 \par%
172 \vspace\examplevspace%
173 \indent%
174 \begin{minipage}[t]{\codewidth}%
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000175 \small%
176 \OldVerbatim%
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000177}
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000178\renewcommand{\endverbatim}{%
179 \OldEndVerbatim%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000180 \end{minipage}%
181 \endgroup%
Guido van Rossum4c22cb21991-01-25 13:28:15 +0000182}
Guido van Rossum5badc751992-03-06 10:55:46 +0000183
Fred Drakefb5e54d1998-02-19 06:23:06 +0000184% Augment the sectioning commands used to get our own font family in place:
Fred Drakedc8af0a1998-02-13 06:48:05 +0000185\renewcommand{\section}{\@startsection {section}{1}{\z@}%
186 {-3.5ex \@plus -1ex \@minus -.2ex}%
187 {2.3ex \@plus.2ex}%
188 {\reset@font\Large\HeaderFamily}}
189\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
190 {-3.25ex\@plus -1ex \@minus -.2ex}%
191 {1.5ex \@plus .2ex}%
192 {\reset@font\large\HeaderFamily}}
193\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
194 {-3.25ex\@plus -1ex \@minus -.2ex}%
195 {1.5ex \@plus .2ex}%
196 {\reset@font\normalsize\HeaderFamily}}
197\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
198 {3.25ex \@plus1ex \@minus.2ex}%
199 {-1em}%
200 {\reset@font\normalsize\HeaderFamily}}
201\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
202 {3.25ex \@plus1ex \@minus .2ex}%
203 {-1em}%
204 {\reset@font\normalsize\HeaderFamily}}
205
206
Guido van Rossumecae0b71996-06-26 19:03:20 +0000207% Underscore hack (only act like subscript operator if in math mode)
208%
209% The following is due to Mark Wooding (the old version didn't work with
210% Latex 2e.
211
212\DeclareRobustCommand\hackscore{%
213 \ifmmode_\else\textunderscore\fi%
214}
215\begingroup
216\catcode`\_\active
217\def\next{%
218 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
219}
220\expandafter\endgroup\next
221
222%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000223% This is the old hack, which didn't work with 2e.
224% You should not need this since the rest of the documentation is now
225% LaTeX2e-only.
Guido van Rossumecae0b71996-06-26 19:03:20 +0000226%
227%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
228%\catcode`\_=12
229%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
Guido van Rossum5badc751992-03-06 10:55:46 +0000230
Fred Drakeb37a3951998-02-06 22:52:52 +0000231
Fred Drakedc8af0a1998-02-13 06:48:05 +0000232
Fred Drakeb37a3951998-02-06 22:52:52 +0000233%% Lots of index-entry generation support.
234
Fred Drakedc8af0a1998-02-13 06:48:05 +0000235% Command to wrap around stuff that refers to function / module /
236% attribute names in the index. Default behavior: like \code{}. To
237% just keep the index entries in the roman font, uncomment the second
238% definition to use instead; it matches O'Reilly style more.
239%
Fred Drakeb37a3951998-02-06 22:52:52 +0000240\newcommand{\idxcode}[1]{\codefont{#1}}
241%\renewcommand{\idxcode}[1]{#1}
Guido van Rossum5badc751992-03-06 10:55:46 +0000242
243% Command to generate two index entries (using subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +0000244\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000245
246% And three entries (using only one level of subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +0000247\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000248
249% And four (again, using only one level of subentries)
250\newcommand{\indexiv}[4]{
251\index{#1!#2 #3 #4}
252\index{#2!#3 #4, #1}
253\index{#3!#4, #1 #2}
254\index{#4!#1 #2 #3}
255}
256
Fred Drakedc8af0a1998-02-13 06:48:05 +0000257% Command to generate a reference to a function, statement, keyword,
258% operator.
Fred Drakeb37a3951998-02-06 22:52:52 +0000259\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
260\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
261\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Guido van Rossum6886c831992-04-03 14:44:27 +0000262\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000263\newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1()}} (built-in function)}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000264
265% Add an index entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000266\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake4af18141997-12-15 22:08:14 +0000267\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000268\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
269\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
270
Fred Drakeda941ef1998-01-02 02:57:41 +0000271% support for the module index
272\newwrite\modindexfile
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000273\openout\modindexfile=mod\jobname.idx
Fred Drakeda941ef1998-01-02 02:57:41 +0000274
Fred Drake207e57b1997-12-15 21:37:45 +0000275% Add the defining entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000276\newcommand{\defmodindex}[2]{%
277 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
Fred Drakeda941ef1998-01-02 02:57:41 +0000278 \write\modindexfile{#1 \thepage}}
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000279
280% built-in & Python modules in the main distribution
Fred Drake207e57b1997-12-15 21:37:45 +0000281\newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }}
282\newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }}
Guido van Rossum5badc751992-03-06 10:55:46 +0000283
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000284% Python & extension modules outside the main distribution
285\newcommand{\modindex}[1]{\defmodindex{#1}{}}
286\newcommand{\exmodindex}[1]{\defmodindex{#1}{}}
287
Guido van Rossum5badc751992-03-06 10:55:46 +0000288% Additional string for an index entry
Fred Drakedc8af0a1998-02-13 06:48:05 +0000289\newcommand{\index@subitem}{}
290\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
291\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000292
Guido van Rossum5badc751992-03-06 10:55:46 +0000293
Fred Drakeef146221998-02-19 21:02:26 +0000294% {fulllineitems} is used in one place in libregex.tex, but is really for
295% internal use in this file.
296%
Fred Drakefb5e54d1998-02-19 06:23:06 +0000297\newenvironment{fulllineitems}{
298 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
299 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
300 \itemsep -\parsep
301 \let\makelabel=\itemnewline}
302}{\end{list}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000303
304
Guido van Rossum36f35021997-05-22 20:43:24 +0000305% cfuncdesc should be called as
306% \begin{cfuncdesc}{type}{name}{arglist}
307% ... description ...
308% \end{cfuncdesc}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000309\newenvironment{cfuncdesc}[3]{%
310 \begin{fulllineitems}%
311 \item[\code{#1 \bfcode{#2}(\varvars{#3})}]%
312 \index{#2@{\idxcode{#2()}}}%
313}{\end{fulllineitems}}
Fred Drakeeb33c781996-10-29 15:55:08 +0000314
Fred Drakefb5e54d1998-02-19 06:23:06 +0000315\newenvironment{cvardesc}[2]{%
316 \begin{fulllineitems}%
317 \item[\code{#1 \bfcode{#2}}]%
318 \index{#2@{\idxcode{#2}}}%
319}{\end{fulllineitems}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000320
Fred Drakefb5e54d1998-02-19 06:23:06 +0000321\newenvironment{ctypedesc}[1]{%
322 \begin{fulllineitems}%
323 \item[\bfcode{#1}]\ttindex{#1}
324}{\end{fulllineitems}}
Guido van Rossum36f35021997-05-22 20:43:24 +0000325
Fred Drakefb5e54d1998-02-19 06:23:06 +0000326\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
327\newenvironment{funcdesc}[2]{%
328 \begin{fulllineitems}%
329 \funcline{#1}{#2}%
330}{\end{fulllineitems}}
331
332\newcommand{\optional}[1]{%
333 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000334
Fred Drakeaebc6f31998-02-13 14:34:04 +0000335% similar to {funcdesc}, but doesn't add to the index
336\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000337\newenvironment{funcdescni}[2]{%
338 \begin{fulllineitems}%
339 \funclineni{#1}{#2}%
340}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000341
Fred Drakefb5e54d1998-02-19 06:23:06 +0000342\newenvironment{classdesc}[2]{%
343 \begin{fulllineitems}%
344 \item[\code{\bfcode{#1}(\varvars{#2})}]%
345 \ttindex{#1}%
346 \def\baseclasses##1{}%
347}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000348
Fred Drakefb5e54d1998-02-19 06:23:06 +0000349\newenvironment{excdesc}[1]{%
350 \begin{fulllineitems}%
351 \item[\bfcode{#1}]\ttindex{#1}%
352}{\end{fulllineitems}}
353
Fred Drakeaebc6f31998-02-13 14:34:04 +0000354\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000355\newenvironment{datadesc}[1]{%
356 \begin{fulllineitems}%
357 \dataline{#1}%
358}{\end{fulllineitems}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000359
Fred Drakeaebc6f31998-02-13 14:34:04 +0000360% similar to {datadesc}, but doesn't add to the index
361\newcommand{\datalineni}[1]{\item[\bfcode{#1}]}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000362\newenvironment{datadescni}[1]{%
363 \begin{fulllineitems}%
364 \datalineni{#1}%
365}{\end{fulllineitems}}
Fred Drakeaebc6f31998-02-13 14:34:04 +0000366
Fred Drakefb5e54d1998-02-19 06:23:06 +0000367\newenvironment{opcodedesc}[2]{%
368 \begin{fulllineitems}%
369 \item[\bfcode{#1}\quad\var{#2}]%
370}{\end{fulllineitems}}
Fred Drakea610f9f1997-12-03 03:42:39 +0000371
372
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000373\let\nodename=\label
374
Fred Drakedc8af0a1998-02-13 06:48:05 +0000375% For these commands, use \command{} to get the typography right, not
376% {\command}. This works better with the texinfo translation.
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000377\newcommand{\ABC}{{\sc abc}}
378\newcommand{\UNIX}{{\sc Unix}}
Fred Drake311c1961998-01-20 05:07:19 +0000379\newcommand{\POSIX}{POSIX}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000380\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000381\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000382\newcommand{\C}{C}
383\newcommand{\EOF}{{\sc eof}}
Guido van Rossum9231c8f1997-05-15 21:43:21 +0000384\newcommand{\NULL}{\code{NULL}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000385
386% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000387\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 +0000388\mbox{\codefont{#1}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000389
Fred Drakefb5e54d1998-02-19 06:23:06 +0000390\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000391\newcommand{\kbd}[1]{\mbox{\tt #1}}
392\newcommand{\key}[1]{\mbox{\tt #1}}
393\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000394% This weird definition of \var{} allows it to always appear in roman
395% italics, and won't get funky in code fragments when we play around
396% with fonts.
397\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000398\renewcommand{\emph}[1]{{\em #1\/}}
Fred Drakefb5e54d1998-02-19 06:23:06 +0000399\newcommand{\dfn}[1]{\emph{#1}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000400\newcommand{\strong}[1]{{\bf #1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000401% let's experiment with a new font:
Fred Drakedc8af0a1998-02-13 06:48:05 +0000402\newcommand{\file}[1]{\mbox{`\small\textsf{#1}'}}
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000403
404% Use this def/redef approach for \url{} since hyperref defined this already,
405% but only if we actually used hyperref:
Fred Drake0c17d661998-02-18 14:24:19 +0000406\@ifundefined{pdfannotlink}{%
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000407 \newcommand{\pythonurl}[1]{\mbox{\small\textsf{#1}}}%
Fred Drake0c17d661998-02-18 14:24:19 +0000408}{
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000409 \newcommand{\pythonurl}[1]{{%
410 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
411 \LinkColor% color of the link text
Fred Drake0c17d661998-02-18 14:24:19 +0000412 \mbox{\small\textsf{#1}}%
Fred Drake9cf4bbd1998-02-25 15:29:43 +0000413 \NormalColor% Turn it back off; these are declarative
414 \pdfendlink}% and don't appear bound to the current
415 }% formatting "box".
416}
417\let\url=\pythonurl
Fred Drake4186cd31998-02-18 17:21:09 +0000418\newcommand{\email}[1]{\mbox{\small\textsf{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000419
Fred Drake9b550d91996-11-11 20:43:46 +0000420\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000421
422\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000423\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000424
Fred Drakedc8af0a1998-02-13 06:48:05 +0000425% These should be used for all references to identifiers which are
426% used to refer to instances of specific language constructs. See the
427% names for specific semantic assignments.
Fred Drake311c1961998-01-20 05:07:19 +0000428%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000429% For now, don't do anything really fancy with them; just use them as
430% logical markup. This might change in the future.
Fred Drake311c1961998-01-20 05:07:19 +0000431%
432\let\module=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000433\let\keyword=\code
434\let\exception=\code
Fred Drake311c1961998-01-20 05:07:19 +0000435\let\class=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000436\let\function=\code
Fred Drakefb5e54d1998-02-19 06:23:06 +0000437\let\member=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000438\let\method=\code
439
Fred Drakefb5e54d1998-02-19 06:23:06 +0000440\let\cfunction=\code
441\let\ctype=\code
442\let\cdata=\code
443
444% constants defined in Python modules or C headers, not language constants:
Fred Drakedd28d571998-01-22 15:55:21 +0000445\let\constant=\code
Fred Drake311c1961998-01-20 05:07:19 +0000446
447\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake06f169b1998-02-11 23:08:20 +0000448\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
Fred Drakedc8af0a1998-02-13 06:48:05 +0000449\newcommand{\program}[1]{\strong{#1}}
Fred Drake311c1961998-01-20 05:07:19 +0000450
451
Fred Drakefb5e54d1998-02-19 06:23:06 +0000452\newenvironment{tableii}[4]{%
453 \begin{center}%
454 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
455 \begin{tabular}{#1}\hline#3&#4\\ \hline%
456}{%
457 \hline%
458 \end{tabular}%
459 \end{center}%
460}
Guido van Rossume7af5a01994-08-01 12:39:35 +0000461
Fred Drakefb5e54d1998-02-19 06:23:06 +0000462\newenvironment{tableiii}[5]{%
463 \begin{center}%
464 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
465 \begin{tabular}{#1}\hline#3&#4&#5\\%
466 \hline%
467}{%
468 \hline%
469 \end{tabular}%
470 \end{center}%
471}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000472
Fred Drakefb5e54d1998-02-19 06:23:06 +0000473\newcommand{\itemnewline}[1]{%
474 \@tempdima\linewidth%
475 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
476}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000477
Fred Drake9e243091998-01-18 05:09:54 +0000478\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000479
480% Cross-referencing (AMK)
481% Sample usage:
482% \begin{seealso}
483% \seemodule{rand}{Uniform random number generator}; % Module xref
Fred Drakedc8af0a1998-02-13 06:48:05 +0000484% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000485% \end{seealso}
486
Fred Drakefb5e54d1998-02-19 06:23:06 +0000487\newenvironment{seealso}[0]{
488 \strong{See Also:}\par
489 % These should only be defined within the {seealso} environment:
490 \def\seemodule##1##2{\ref{module-##1}:\quad Module \module{##1}\quad (##2)}
491 \def\seetext##1{\par{##1}}
492}{\par}
493
Fred Drakeda941ef1998-01-02 02:57:41 +0000494
Fred Drakedc8af0a1998-02-13 06:48:05 +0000495% Fix the theindex environment to add an entry to the Table of
496% Contents; this is much nicer than just having to jump to the end of
497% the book and flip around, especially with multiple indexes.
Fred Drakeda941ef1998-01-02 02:57:41 +0000498%
499\let\OldTheindex=\theindex
Fred Drakefb5e54d1998-02-19 06:23:06 +0000500\renewcommand{\theindex}{
501 \cleardoublepage
502 \OldTheindex
503 \addcontentsline{toc}{chapter}{\indexname}
Fred Drakeda941ef1998-01-02 02:57:41 +0000504}
Fred Drake031ad4b1998-01-09 05:34:23 +0000505
506% Use a similar trick to catch the end of the {abstract} environment,
507% but here make sure the abstract is followed by a blank page if the
508% 'openright' option is used.
509%
510\let\OldEndAbstract=\endabstract
Fred Drake06f169b1998-02-11 23:08:20 +0000511\renewcommand{\endabstract}{
Fred Drake737e73e1998-01-13 22:40:08 +0000512 \if@openright
513 \ifodd\value{page}
514 \typeout{Adding blank page after the abstract.}
515 \vfil\pagebreak
Fred Drake031ad4b1998-01-09 05:34:23 +0000516 \fi
Fred Drake737e73e1998-01-13 22:40:08 +0000517 \fi
518 \OldEndAbstract
Fred Drake031ad4b1998-01-09 05:34:23 +0000519}
520
Fred Drakedc8af0a1998-02-13 06:48:05 +0000521% This wraps the \tableofcontents macro with all the magic to get the
522% spacing right and have the right number of pages if the 'openright'
Fred Drake031ad4b1998-01-09 05:34:23 +0000523% option has been used. This eliminates a fair amount of crud in the
524% individual document files.
525%
Fred Drake737e73e1998-01-13 22:40:08 +0000526\let\OldTableofcontents=\tableofcontents
Fred Drake06f169b1998-02-11 23:08:20 +0000527\renewcommand{\tableofcontents}[0]{%
528 \setcounter{page}{1}%
529 \pagebreak%
530 \pagestyle{plain}%
531 {%
532 \parskip = 0mm%
533 \OldTableofcontents%
534 \if@openright%
535 \ifodd\value{page}%
536 \typeout{Adding blank page after the table of contents.}%
537 \pagebreak\hspace{0pt}%
538 \fi%
539 \fi%
540 }%
Fred Drake4c689631998-02-13 16:58:49 +0000541 \cleardoublepage%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000542 \pagenumbering{arabic}%
Fred Drake76183c01998-02-16 22:30:10 +0000543 \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
Fred Drake06f169b1998-02-11 23:08:20 +0000544}
545
Fred Drakedc8af0a1998-02-13 06:48:05 +0000546% Allow the release number to be specified independently of the
547% \date{}. This allows the date to reflect the document's date and
548% release to specify the Python release that is documented.
549%
Fred Drake06f169b1998-02-11 23:08:20 +0000550\newcommand{\@release}{}
551\newcommand{\version}{}
552\newcommand{\releasename}{Release}
553\newcommand{\release}[1]{%
554 \renewcommand{\@release}{\releasename\space\version}%
Fred Drakedc8af0a1998-02-13 06:48:05 +0000555 \renewcommand{\version}{#1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000556
Fred Drakedc8af0a1998-02-13 06:48:05 +0000557% Allow specification of the author's address separately from the
558% author's name. This can be used to format them differently, which
559% is a good thing.
560%
Fred Drake06f169b1998-02-11 23:08:20 +0000561\newcommand{\@authoraddress}{}
562\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
563
Fred Drakedc8af0a1998-02-13 06:48:05 +0000564% Change the title page to look a bit better, and fit in with the
565% fncychap ``Bjarne'' style a bit better.
566%
Fred Drakefb5e54d1998-02-19 06:23:06 +0000567\renewcommand{\maketitle}{%
568 \begin{titlepage}%
569 \let\footnotesize\small
570 \let\footnoterule\relax
571 \@ifundefined{ChTitleVar}{}{%
572 \mghrulefill{\RW}}%
573 \@ifundefined{pdfinfo}{}{
574 \pdfinfo
575 author {\@author}
576 title {\@title}
577 }
578 \begin{flushright}%
579 {\rm\Huge\HeaderFamily \@title \par}%
580 {\em\LARGE\HeaderFamily \@release \par}
581 \vfill
582 {\LARGE\HeaderFamily \@author \par}
583 \vfill\vfill
584 {\large
585 \@date \par
586 \vskip 3em
587 \@authoraddress \par
588 }%
589 \end{flushright}%\par
590 \@thanks
Fred Drake06f169b1998-02-11 23:08:20 +0000591 \end{titlepage}%
592 \setcounter{footnote}{0}%
593 \let\thanks\relax\let\maketitle\relax
594 \gdef\@thanks{}\gdef\@author{}\gdef\@title{}
595}
596
Fred Drakedc8af0a1998-02-13 06:48:05 +0000597% This sets up the fancy chapter headings that make the documents look
598% at least a little better than the usual LaTeX output.
Fred Drake06f169b1998-02-11 23:08:20 +0000599%
Fred Drake06f169b1998-02-11 23:08:20 +0000600\@ifundefined{ChTitleVar}{}{
Fred Drakedc8af0a1998-02-13 06:48:05 +0000601 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
602 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
603 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
Fred Drake06f169b1998-02-11 23:08:20 +0000604 % This creates chapter heads without the leading \vspace*{}:
605 \def\@makechapterhead#1{%
606 {\parindent \z@ \raggedright \normalfont
607 \ifnum \c@secnumdepth >\m@ne
608 \DOCH
609 \fi
610 \interlinepenalty\@M
611 \DOTI{#1}
612 }
613 }
614 \typeout{Using fancy chapter headings.}
Fred Drake031ad4b1998-01-09 05:34:23 +0000615}
Fred Drake5c19c7b1998-02-20 06:08:07 +0000616
617% Tell TeX about pathological hyphenation cases:
618\hyphenation{Base-HTTP-Re-quest-Hand-ler}