blob: 3d19e46dd72b7b1bf1c870377b80c94b2e5d17cf [file] [log] [blame]
Fred Drake6659c301998-03-03 22:02:19 +00001%
Fred Drake6663b221998-03-06 22:33:06 +00002% python.sty for the Python docummentation [works only with with Latex2e]
Fred Drake6659c301998-03-03 22:02:19 +00003%
4
5\NeedsTeXFormat{LaTeX2e}[1995/12/01]
6\ProvidesPackage{python}
7 [1998/01/11 LaTeX package (Python manual markup)]
8
9% The "fncychap" package is used to get the nice chapter headers. The
10% .sty file is distributed with Python, so you should not need to disable
11% it. You'd also end up with a mixed page style; uglier than stock LaTeX!
12%
Fred Drake28f13911998-03-04 21:47:59 +000013\RequirePackage[Bjarne]{fncychap}\typeout{Using fancy chapter headings.}
Fred Drake6659c301998-03-03 22:02:19 +000014
Fred Drake6659c301998-03-03 22:02:19 +000015% for PDF output, use maximal compression
Fred Drake1c8d0e01998-03-07 05:29:15 +000016\@ifundefined{pdfannotlink}{
Fred Drake6659c301998-03-03 22:02:19 +000017 \let\LinkColor=\relax
18 \let\NormalColor=\relax
19}{%
20 \input{pdfcolor}
21 \let\LinkColor=\NavyBlue
22 \let\NormalColor=\Black
23 \pdfcompresslevel=9
Fred Drakeebcb6581998-03-06 21:25:17 +000024 %
25 % This definition allows the entries in the page-view of the ToC to be
26 % active links. Some work, some don't.
27 %
Fred Drake6659c301998-03-03 22:02:19 +000028 \let\OldContentsline=\contentsline
29 \renewcommand{\contentsline}[3]{%
30 \OldContentsline{#1}{%
31 \pdfannotlink attr{/Border [0 0 0]} goto name{page.#3}%
32 \LinkColor#2\NormalColor%
33 \pdfendlink%
34 }{#3}%
35 }
Fred Drakeebcb6581998-03-06 21:25:17 +000036 \renewcommand{\thepage}{\roman{page}}
37 %
38 % This is supposed to build the "outline" view of the document; it seems
39 % quite fragile. The breakages are the same as in the ToC.
40 %
41 \AtEndDocument{
42 \InputIfFileExists{\jobname.bkm}{\pdfcatalog pagemode{/UseOutlines}}{}
43 }
Fred Drake6659c301998-03-03 22:02:19 +000044 \let\OldLabel=\label
45 \renewcommand{\label}[1]{%
46 \OldLabel{#1}%
47 {\pdfdest name{label.#1} fit}%
48 }
49 % This stuff adds a page.# destination to every PDF page, where # has
50 % the same formatting as the displayed page number. This doesn't really
51 % help with the frontmatter, but does fine with the body.
52 %
53 % This is *heavily* based on the hyperref package.
54 %
Fred Drake1c8d0e01998-03-07 05:29:15 +000055 \def\@begindvi{%
56 \unvbox \@begindvibox
57 \@hyperfixhead
Fred Drake6659c301998-03-03 22:02:19 +000058 }
Fred Drakeebcb6581998-03-06 21:25:17 +000059 \def\hyperpageanchor{\pdfdest name{page.\thepage}}
Fred Drake6659c301998-03-03 22:02:19 +000060 \let\HYPERPAGEANCHOR\hyperpageanchor
Fred Drake1c8d0e01998-03-07 05:29:15 +000061 \def\@hyperfixhead{%
62 \let\H@old@thehead\@thehead
63 \gdef\@foo{\pdfdest name{page.\thepage} fit}%
64 \expandafter\ifx\expandafter\@empty\H@old@thehead
65 \def\H@old@thehead{\hfil}\fi
66 \def\@thehead{\@foo\relax\H@old@thehead}%
Fred Drake6659c301998-03-03 22:02:19 +000067 }
68}
69
70% Increase printable page size (copied from fullpage.sty)
71\topmargin 0pt
72\advance \topmargin by -\headheight
73\advance \topmargin by -\headsep
74
75% attempt to work a little better for A4 users
Fred Drake1c8d0e01998-03-07 05:29:15 +000076\@ifundefined{paperheight}{
Fred Drake6659c301998-03-03 22:02:19 +000077 \textheight 9in
78}{
79 \textheight \paperheight
80 \advance\textheight by -2in
81}
82
83\oddsidemargin 0pt
84\evensidemargin \oddsidemargin
85\marginparwidth 0.5in
86
Fred Drake1c8d0e01998-03-07 05:29:15 +000087\@ifundefined{paperwidth}{
Fred Drake6659c301998-03-03 22:02:19 +000088 \textwidth 6.5in
89}{
90 \textwidth \paperwidth
91 \advance\textwidth by -2in
92}
93
94
95% Style parameters and macros used by most documents here
96\raggedbottom
97\sloppy
98\parindent = 0mm
99\parskip = 2mm
100\hbadness = 5000 % don't print trivial gripes
101
102\pagestyle{empty} % start this way; change for
103\pagenumbering{roman} % ToC & chapters
104\setcounter{secnumdepth}{1}
105
106% Use this to set the font family for headers and other decor:
107\newcommand{\HeaderFamily}{\sffamily}
108
109% Redefine the 'normal' header/footer style when using "fancyhdr" package:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000110\@ifundefined{fancyhf}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000111 % Use \pagestyle{normal} as the primary pagestyle for text.
112 \fancypagestyle{normal}{
113 \fancyhf{}
114 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
115 \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}
116 \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}
117 \renewcommand{\headrulewidth}{0pt}
118 \renewcommand{\footrulewidth}{0.4pt}
119 }
120 % Update the plain style so we get the page number & footer line,
121 % but not a chapter or section title. This is to keep the first
122 % page of a chapter and the blank page between chapters `clean.'
123 \fancypagestyle{plain}{
124 \fancyhf{}
125 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
126 \renewcommand{\headrulewidth}{0pt}
127 \renewcommand{\footrulewidth}{0.4pt}
128 }
129 % Redefine \cleardoublepage so that the blank page between chapters
130 % gets the plain style and not the fancy style. This is described
131 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000132 \@ifundefined{chapter}{}{
Fred Drake28f13911998-03-04 21:47:59 +0000133 \renewcommand{\cleardoublepage}{
Fred Drake1c8d0e01998-03-07 05:29:15 +0000134 \clearpage\if@openright \ifodd\c@page\else
Fred Drake28f13911998-03-04 21:47:59 +0000135 \hbox{}
136 \thispagestyle{plain}
137 \newpage
Fred Drake1c8d0e01998-03-07 05:29:15 +0000138 \if@twocolumn\hbox{}\newpage\fi\fi\fi
Fred Drake28f13911998-03-04 21:47:59 +0000139 }
140 }
Fred Drake6659c301998-03-03 22:02:19 +0000141}
142
143% old code font selections:
144\let\codefont=\tt
145\let\sectcodefont=\tt
146
147% (Haven't found a new one that gets <, >, and _ right without being
148% monospaced.)
149
150
151% This sets up the {verbatim} environment to be indented and a minipage,
152% and to have all the other mostly nice properties that we want for
153% code samples.
154
155% Variable used by begin code command
156\newlength{\codewidth}
157
158\newcommand{\examplevspace}{2mm}
159\newcommand{\exampleindent}{1cm}
160
161\let\OldVerbatim=\verbatim
162\let\OldEndVerbatim=\endverbatim
163\renewcommand{\verbatim}{%
164 \begingroup%
165 \setlength{\parindent}\exampleindent%
166 % Calculate the text width for the minipage:
167 \setlength{\codewidth}{\linewidth}%
168 \addtolength{\codewidth}{-\parindent}%
169 %
170 \par%
171 \vspace\examplevspace%
172 \indent%
173 \begin{minipage}[t]{\codewidth}%
174 \small%
175 \OldVerbatim%
176}
177\renewcommand{\endverbatim}{%
178 \OldEndVerbatim%
179 \end{minipage}%
180 \endgroup%
181}
182
183% Augment the sectioning commands used to get our own font family in place:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000184\renewcommand{\section}{\@startsection {section}{1}{\z@}%
185 {-3.5ex \@plus -1ex \@minus -.2ex}%
186 {2.3ex \@plus.2ex}%
187 {\reset@font\Large\HeaderFamily}}
188\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
189 {-3.25ex\@plus -1ex \@minus -.2ex}%
190 {1.5ex \@plus .2ex}%
191 {\reset@font\large\HeaderFamily}}
192\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
193 {-3.25ex\@plus -1ex \@minus -.2ex}%
194 {1.5ex \@plus .2ex}%
195 {\reset@font\normalsize\HeaderFamily}}
196\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
197 {3.25ex \@plus1ex \@minus.2ex}%
Fred Drake6659c301998-03-03 22:02:19 +0000198 {-1em}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000199 {\reset@font\normalsize\HeaderFamily}}
200\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
201 {3.25ex \@plus1ex \@minus .2ex}%
Fred Drake6659c301998-03-03 22:02:19 +0000202 {-1em}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000203 {\reset@font\normalsize\HeaderFamily}}
Fred Drake6659c301998-03-03 22:02:19 +0000204
205
206% Underscore hack (only act like subscript operator if in math mode)
207%
208% The following is due to Mark Wooding (the old version didn't work with
209% Latex 2e.
210
211\DeclareRobustCommand\hackscore{%
212 \ifmmode_\else\textunderscore\fi%
213}
214\begingroup
215\catcode`\_\active
216\def\next{%
217 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
218}
219\expandafter\endgroup\next
220
221%
222% This is the old hack, which didn't work with 2e.
223% You should not need this since the rest of the documentation is now
224% LaTeX2e-only.
225%
226%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
227%\catcode`\_=12
228%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
229
230
231
232%% Lots of index-entry generation support.
233
234% Command to wrap around stuff that refers to function / module /
235% attribute names in the index. Default behavior: like \code{}. To
236% just keep the index entries in the roman font, uncomment the second
237% definition to use instead; it matches O'Reilly style more.
238%
239\newcommand{\idxcode}[1]{\codefont{#1}}
240%\renewcommand{\idxcode}[1]{#1}
241
242% Command to generate two index entries (using subentries)
243\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
244
245% And three entries (using only one level of subentries)
246\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
247
248% And four (again, using only one level of subentries)
249\newcommand{\indexiv}[4]{
250\index{#1!#2 #3 #4}
251\index{#2!#3 #4, #1}
252\index{#3!#4, #1 #2}
253\index{#4!#1 #2 #3}
254}
255
256% Command to generate a reference to a function, statement, keyword,
257% operator.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000258\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
259\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
260\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000261\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drake1c8d0e01998-03-07 05:29:15 +0000262\newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1()}} (built-in function)}}
Fred Drake6659c301998-03-03 22:02:19 +0000263
264% Add an index entry for a module
Fred Drake1c8d0e01998-03-07 05:29:15 +0000265\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake6659c301998-03-03 22:02:19 +0000266\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
267\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
268\newcommand{\refexmodindex}[1]{\refmodule{#1}{extension }}
269\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
270
271% support for the module index
Fred Drakeb390daf1998-03-09 16:35:36 +0000272\newif\if@UseModuleIndex
273\@UseModuleIndexfalse
274
275\newcommand{\indexlabel}{genindex}
276
277% Fix the theindex environment to add an entry to the Table of
278% Contents; this is much nicer than just having to jump to the end of
279% the book and flip around, especially with multiple indexes.
280%
281\let\OldTheindex=\theindex
282\renewcommand{\theindex}{
283 \cleardoublepage
284 \OldTheindex
285 \addcontentsline{toc}{chapter}{\indexname}
286 \label{\indexlabel}
287}
288
Fred Drake0ee9f721998-03-12 06:41:40 +0000289% these should dump an error or warning to the transcript
Fred Drakeb390daf1998-03-09 16:35:36 +0000290\newcommand{\@thismodule}{$<<$ ERROR - NO CURRENT MODULE $>>$}
Fred Drake0ee9f721998-03-12 06:41:40 +0000291\newcommand{\@thisclass}{$<<$ ERROR - NO CURRENT CLASS $>>$}
Fred Drakeb390daf1998-03-09 16:35:36 +0000292
293\newcommand{\makemodindex}{
294 \newwrite\modindexfile
295 \openout\modindexfile=mod\jobname.idx
296 \@UseModuleIndextrue
297}
298
299\newcommand{\inputindex}[1]{
300 \IfFileExists{#1}{\input{#1}}{\begin{theindex}\end{theindex}}
301}
Fred Drake6659c301998-03-03 22:02:19 +0000302
Fred Drake0ee9f721998-03-12 06:41:40 +0000303% Add the defining entry for a module
304\newcommand{\@modindex}[2]{%
305 \renewcommand{\@thismodule}{#1}
306 \setindexsubitem{(in module \@thismodule)}%
307 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
308 \if@UseModuleIndex%
309 \write\modindexfile{\protect\indexentry{#1@{\tt #1}}{\thepage}}%
310 \fi%
311}
312
Fred Drake6659c301998-03-03 22:02:19 +0000313% built-in & Python modules in the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000314\newcommand{\bimodindex}[1]{\@modindex{#1}{built-in }}
315\newcommand{\stmodindex}[1]{\@modindex{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000316
317% Python & extension modules outside the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000318\newcommand{\modindex}[1]{\@modindex{#1}{}}
319\newcommand{\exmodindex}[1]{\@modindex{#1}{extension }}
Fred Drake6659c301998-03-03 22:02:19 +0000320
321% Additional string for an index entry
Fred Drake1c8d0e01998-03-07 05:29:15 +0000322\newcommand{\index@subitem}{}
323\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
324\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Fred Drake6659c301998-03-03 22:02:19 +0000325
Fred Drake0ee9f721998-03-12 06:41:40 +0000326\newcommand{\withsubitem}[2]{%
327 \begingroup%
328 \def\index@subitem{#1}#2%
329 \endgroup%
330}
Fred Drake6659c301998-03-03 22:02:19 +0000331
332% {fulllineitems} is used in one place in libregex.tex, but is really for
333% internal use in this file.
334%
335\newenvironment{fulllineitems}{
336 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
337 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
338 \itemsep -\parsep
339 \let\makelabel=\itemnewline}
340}{\end{list}}
341
342
343% cfuncdesc should be called as
344% \begin{cfuncdesc}{type}{name}{arglist}
345% ... description ...
346% \end{cfuncdesc}
347\newenvironment{cfuncdesc}[3]{%
348 \begin{fulllineitems}%
349 \item[\code{#1 \bfcode{#2}(\varvars{#3})}]%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000350 \index{#2@{\idxcode{#2()}}}%
Fred Drake6659c301998-03-03 22:02:19 +0000351}{\end{fulllineitems}}
352
353\newenvironment{cvardesc}[2]{%
354 \begin{fulllineitems}%
355 \item[\code{#1 \bfcode{#2}}]%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000356 \index{#2@{\idxcode{#2}}}%
Fred Drake6659c301998-03-03 22:02:19 +0000357}{\end{fulllineitems}}
358
359\newenvironment{ctypedesc}[1]{%
360 \begin{fulllineitems}%
361 \item[\bfcode{#1}]\ttindex{#1}
362}{\end{fulllineitems}}
363
364\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
365\newenvironment{funcdesc}[2]{%
366 \begin{fulllineitems}%
367 \funcline{#1}{#2}%
368}{\end{fulllineitems}}
369
370\newcommand{\optional}[1]{%
371 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
372
373% similar to {funcdesc}, but doesn't add to the index
374\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
375\newenvironment{funcdescni}[2]{%
376 \begin{fulllineitems}%
377 \funclineni{#1}{#2}%
378}{\end{fulllineitems}}
379
380\newenvironment{classdesc}[2]{%
Fred Drake0ee9f721998-03-12 06:41:40 +0000381 \renewcommand{\@thisclass}{#1}%
Fred Drake6659c301998-03-03 22:02:19 +0000382 \begin{fulllineitems}%
383 \item[\code{\bfcode{#1}(\varvars{#2})}]%
Fred Drakeae25be21998-03-16 05:26:10 +0000384 \withsubitem{(class in \@thismodule)}{\ttindex{#1}}%
Fred Drake6659c301998-03-03 22:02:19 +0000385 \def\baseclasses##1{}%
386}{\end{fulllineitems}}
387
388\newenvironment{excdesc}[1]{%
389 \begin{fulllineitems}%
390 \item[\bfcode{#1}]\ttindex{#1}%
391}{\end{fulllineitems}}
392
393\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
394\newenvironment{datadesc}[1]{%
395 \begin{fulllineitems}%
396 \dataline{#1}%
397}{\end{fulllineitems}}
398
399% similar to {datadesc}, but doesn't add to the index
400\newcommand{\datalineni}[1]{\item[\bfcode{#1}]}
401\newenvironment{datadescni}[1]{%
402 \begin{fulllineitems}%
403 \datalineni{#1}%
404}{\end{fulllineitems}}
405
406\newenvironment{opcodedesc}[2]{%
407 \begin{fulllineitems}%
408 \item[\bfcode{#1}\quad\var{#2}]%
409}{\end{fulllineitems}}
410
411
412\let\nodename=\label
413
414% For these commands, use \command{} to get the typography right, not
415% {\command}. This works better with the texinfo translation.
416\newcommand{\ABC}{{\sc abc}}
417\newcommand{\UNIX}{{\sc Unix}}
418\newcommand{\POSIX}{POSIX}
419\newcommand{\ASCII}{{\sc ascii}}
420\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
421\newcommand{\C}{C}
422\newcommand{\EOF}{{\sc eof}}
423\newcommand{\NULL}{\code{NULL}}
424
425% code is the most difficult one...
Fred Drake1c8d0e01998-03-07 05:29:15 +0000426\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 Drake6659c301998-03-03 22:02:19 +0000427\mbox{\codefont{#1}}}}
428
429\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
430\newcommand{\kbd}[1]{\mbox{\tt #1}}
431\newcommand{\key}[1]{\mbox{\tt #1}}
432\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
433% This weird definition of \var{} allows it to always appear in roman
434% italics, and won't get funky in code fragments when we play around
435% with fonts.
436\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
437\renewcommand{\emph}[1]{{\em #1\/}}
438\newcommand{\dfn}[1]{\emph{#1}}
439\newcommand{\strong}[1]{{\bf #1}}
440% let's experiment with a new font:
Fred Drake0ee9f721998-03-12 06:41:40 +0000441\newcommand{\file}[1]{`{\small\textsf{#1}}'}
Fred Drake6659c301998-03-03 22:02:19 +0000442
443% Use this def/redef approach for \url{} since hyperref defined this already,
444% but only if we actually used hyperref:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000445\@ifundefined{pdfannotlink}{%
Fred Drake6659c301998-03-03 22:02:19 +0000446 \newcommand{\pythonurl}[1]{\mbox{\small\textsf{#1}}}%
447}{
448 \newcommand{\pythonurl}[1]{{%
449 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
450 \LinkColor% color of the link text
451 \mbox{\small\textsf{#1}}%
452 \NormalColor% Turn it back off; these are declarative
453 \pdfendlink}% and don't appear bound to the current
454 }% formatting "box".
455}
456\let\url=\pythonurl
Fred Drake0ee9f721998-03-12 06:41:40 +0000457\newcommand{\email}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000458
459\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
460
461\newif\iftexi\texifalse
462\newif\iflatex\latextrue
463
464% These should be used for all references to identifiers which are
465% used to refer to instances of specific language constructs. See the
466% names for specific semantic assignments.
467%
468% For now, don't do anything really fancy with them; just use them as
469% logical markup. This might change in the future.
470%
471\let\module=\code
472\let\keyword=\code
473\let\exception=\code
474\let\class=\code
475\let\function=\code
476\let\member=\code
477\let\method=\code
478
479\let\cfunction=\code
480\let\ctype=\code
481\let\cdata=\code
482
Fred Drake0ee9f721998-03-12 06:41:40 +0000483\newcommand{\mimetype}[1]{{\small\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000484% The \! is a "negative thin space" in math mode.
485\newcommand{\regexp}[1]{%
486 {\tiny$^{^\lceil}\!\!$%
487 {\normalsize\code{#1}}%
488 $\!\!\rfloor\!$%
489 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000490\newcommand{\envvar}[1]{%
Fred Drake94fac131998-03-12 19:37:03 +0000491 \$#1% $ <-- bow to font-lock 3 times!
492 \index{#1@{\$#1}}% $
493 \index{environment variables!{\$#1}}% $
Fred Drake0ee9f721998-03-12 06:41:40 +0000494}
495\let\character=\samp
496
Fred Drake6659c301998-03-03 22:02:19 +0000497% constants defined in Python modules or C headers, not language constants:
498\let\constant=\code
499
500\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
501\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
502\newcommand{\program}[1]{\strong{#1}}
503
504
505% Deprecation stuff.
506% Should be extended to allow an index / list of deprecated stuff. But
507% there's a lot of stuff that needs to be done to make that automatable.
508%
509% First parameter is the release number that deprecates the feature, the
510% second is the action the should be taken by users of the feature.
511%
512% Example:
513%
514% \deprecated {1.5.1}
515% {Use \method{frobnicate()} instead.}
516%
517\newcommand{\deprecated}[2]{%
518 \strong{Deprecated since release #1.} #2\par}
519
520
521\newenvironment{tableii}[4]{%
522 \begin{center}%
523 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
524 \begin{tabular}{#1}\hline \strong{#3}&\strong{#4} \\ \hline%
525}{%
526 \hline%
527 \end{tabular}%
528 \end{center}%
529}
530
531\newenvironment{tableiii}[5]{%
532 \begin{center}%
533 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
534 \begin{tabular}{#1}\hline \strong{#3}&\strong{#4}&\strong{#5} \\ \hline%
535}{%
536 \hline%
537 \end{tabular}%
538 \end{center}%
539}
540
541\newcommand{\itemnewline}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000542 \@tempdima\linewidth%
543 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
Fred Drake6659c301998-03-03 22:02:19 +0000544}
545
546\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
547
548% Cross-referencing (AMK)
549% Sample usage:
550% \begin{seealso}
551% \seemodule{rand}{Uniform random number generator}; % Module xref
552% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +0000553%
554% % A funky case: module name contains '_'; have to supply an optional key
555% \seemodule[copyreg]{copy_reg}{pickle interface constructor registration}
556%
Fred Drake6659c301998-03-03 22:02:19 +0000557% \end{seealso}
558
Fred Drake1c8d0e01998-03-07 05:29:15 +0000559\newif\if@keyedmodule\@keyedmodulefalse
560\newcommand{\@modulebadkey}{{--just-some-junk--}}
Fred Drakeebcb6581998-03-06 21:25:17 +0000561
Fred Drake1c8d0e01998-03-07 05:29:15 +0000562\@ifundefined{pdfannotlink}{%
563 \newcommand{\seemodule}[3][\@modulebadkey]{%
564 \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
565 \ref{module-\@modulekey}:\quad %
Fred Drakeebcb6581998-03-06 21:25:17 +0000566 Module \module{#2}%
567 \quad (#3)%
568 }
Fred Drake1c8d0e01998-03-07 05:29:15 +0000569}{\newcommand{\seemodule}[3][\@modulebadkey]{%
570 \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
571 \ref{module-\@modulekey}:\quad %
572 {\pdfannotlink attr{/Border [0 0 0]} goto name{label.module-\@modulekey}%
Fred Drakeebcb6581998-03-06 21:25:17 +0000573 \LinkColor Module \module{#2} \NormalColor%
574 \pdfendlink%
575 }%
576 \quad (#3)%
577 }
578}
Fred Drake6659c301998-03-03 22:02:19 +0000579\newenvironment{seealso}[0]{
580 \strong{See Also:}\par
Fred Drake6659c301998-03-03 22:02:19 +0000581 \def\seetext##1{\par{##1}}
582}{\par}
583
584
Fred Drake6659c301998-03-03 22:02:19 +0000585% Allow the release number to be specified independently of the
586% \date{}. This allows the date to reflect the document's date and
587% release to specify the Python release that is documented.
588%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000589\newcommand{\@release}{}
Fred Drake6659c301998-03-03 22:02:19 +0000590\newcommand{\version}{}
591\newcommand{\releasename}{Release}
592\newcommand{\release}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000593 \renewcommand{\@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +0000594 \renewcommand{\version}{#1}}
595
596% Allow specification of the author's address separately from the
597% author's name. This can be used to format them differently, which
598% is a good thing.
599%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000600\newcommand{\@authoraddress}{}
601\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000602
Fred Drake6659c301998-03-03 22:02:19 +0000603% This sets up the fancy chapter headings that make the documents look
604% at least a little better than the usual LaTeX output.
605%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000606\@ifundefined{ChTitleVar}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000607 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
608 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
609 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
610 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000611 \def\@makechapterhead#1{%
612 {\parindent \z@ \raggedright \normalfont
613 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +0000614 \DOCH
615 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +0000616 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +0000617 \DOTI{#1}
618 }
619 }
Fred Drake6659c301998-03-03 22:02:19 +0000620}
621
622% Tell TeX about pathological hyphenation cases:
623\hyphenation{Base-HTTP-Re-quest-Hand-ler}