blob: 1fab4f67008edf4f09f472c258c962dd5b32d295 [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
Fred Drakeb390daf1998-03-09 16:35:36 +0000275% Fix the theindex environment to add an entry to the Table of
276% Contents; this is much nicer than just having to jump to the end of
277% the book and flip around, especially with multiple indexes.
278%
279\let\OldTheindex=\theindex
280\renewcommand{\theindex}{
281 \cleardoublepage
282 \OldTheindex
283 \addcontentsline{toc}{chapter}{\indexname}
Fred Drakeb390daf1998-03-09 16:35:36 +0000284}
285
Fred Drake0ee9f721998-03-12 06:41:40 +0000286% these should dump an error or warning to the transcript
Fred Drakeb390daf1998-03-09 16:35:36 +0000287\newcommand{\@thismodule}{$<<$ ERROR - NO CURRENT MODULE $>>$}
Fred Drake0ee9f721998-03-12 06:41:40 +0000288\newcommand{\@thisclass}{$<<$ ERROR - NO CURRENT CLASS $>>$}
Fred Drakeb390daf1998-03-09 16:35:36 +0000289
290\newcommand{\makemodindex}{
291 \newwrite\modindexfile
292 \openout\modindexfile=mod\jobname.idx
293 \@UseModuleIndextrue
294}
295
296\newcommand{\inputindex}[1]{
297 \IfFileExists{#1}{\input{#1}}{\begin{theindex}\end{theindex}}
298}
Fred Drake6659c301998-03-03 22:02:19 +0000299
Fred Drake0ee9f721998-03-12 06:41:40 +0000300% Add the defining entry for a module
301\newcommand{\@modindex}[2]{%
302 \renewcommand{\@thismodule}{#1}
303 \setindexsubitem{(in module \@thismodule)}%
304 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
305 \if@UseModuleIndex%
306 \write\modindexfile{\protect\indexentry{#1@{\tt #1}}{\thepage}}%
307 \fi%
308}
309
Fred Drake6659c301998-03-03 22:02:19 +0000310% built-in & Python modules in the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000311\newcommand{\bimodindex}[1]{\@modindex{#1}{built-in }}
312\newcommand{\stmodindex}[1]{\@modindex{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000313
314% Python & extension modules outside the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000315\newcommand{\modindex}[1]{\@modindex{#1}{}}
316\newcommand{\exmodindex}[1]{\@modindex{#1}{extension }}
Fred Drake6659c301998-03-03 22:02:19 +0000317
318% Additional string for an index entry
Fred Drake1c8d0e01998-03-07 05:29:15 +0000319\newcommand{\index@subitem}{}
320\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
321\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Fred Drake6659c301998-03-03 22:02:19 +0000322
Fred Drake0ee9f721998-03-12 06:41:40 +0000323\newcommand{\withsubitem}[2]{%
324 \begingroup%
325 \def\index@subitem{#1}#2%
326 \endgroup%
327}
Fred Drake6659c301998-03-03 22:02:19 +0000328
329% {fulllineitems} is used in one place in libregex.tex, but is really for
330% internal use in this file.
331%
332\newenvironment{fulllineitems}{
333 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
334 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
335 \itemsep -\parsep
336 \let\makelabel=\itemnewline}
337}{\end{list}}
338
339
340% cfuncdesc should be called as
341% \begin{cfuncdesc}{type}{name}{arglist}
342% ... description ...
343% \end{cfuncdesc}
344\newenvironment{cfuncdesc}[3]{%
345 \begin{fulllineitems}%
346 \item[\code{#1 \bfcode{#2}(\varvars{#3})}]%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000347 \index{#2@{\idxcode{#2()}}}%
Fred Drake6659c301998-03-03 22:02:19 +0000348}{\end{fulllineitems}}
349
350\newenvironment{cvardesc}[2]{%
351 \begin{fulllineitems}%
352 \item[\code{#1 \bfcode{#2}}]%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000353 \index{#2@{\idxcode{#2}}}%
Fred Drake6659c301998-03-03 22:02:19 +0000354}{\end{fulllineitems}}
355
356\newenvironment{ctypedesc}[1]{%
357 \begin{fulllineitems}%
358 \item[\bfcode{#1}]\ttindex{#1}
359}{\end{fulllineitems}}
360
361\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
362\newenvironment{funcdesc}[2]{%
363 \begin{fulllineitems}%
364 \funcline{#1}{#2}%
365}{\end{fulllineitems}}
366
367\newcommand{\optional}[1]{%
368 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
369
370% similar to {funcdesc}, but doesn't add to the index
371\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
372\newenvironment{funcdescni}[2]{%
373 \begin{fulllineitems}%
374 \funclineni{#1}{#2}%
375}{\end{fulllineitems}}
376
377\newenvironment{classdesc}[2]{%
Fred Drake0ee9f721998-03-12 06:41:40 +0000378 \renewcommand{\@thisclass}{#1}%
Fred Drake6659c301998-03-03 22:02:19 +0000379 \begin{fulllineitems}%
380 \item[\code{\bfcode{#1}(\varvars{#2})}]%
Fred Drakeae25be21998-03-16 05:26:10 +0000381 \withsubitem{(class in \@thismodule)}{\ttindex{#1}}%
Fred Drake6659c301998-03-03 22:02:19 +0000382 \def\baseclasses##1{}%
383}{\end{fulllineitems}}
384
385\newenvironment{excdesc}[1]{%
386 \begin{fulllineitems}%
387 \item[\bfcode{#1}]\ttindex{#1}%
388}{\end{fulllineitems}}
389
390\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
391\newenvironment{datadesc}[1]{%
392 \begin{fulllineitems}%
393 \dataline{#1}%
394}{\end{fulllineitems}}
395
396% similar to {datadesc}, but doesn't add to the index
397\newcommand{\datalineni}[1]{\item[\bfcode{#1}]}
398\newenvironment{datadescni}[1]{%
399 \begin{fulllineitems}%
400 \datalineni{#1}%
401}{\end{fulllineitems}}
402
403\newenvironment{opcodedesc}[2]{%
404 \begin{fulllineitems}%
405 \item[\bfcode{#1}\quad\var{#2}]%
406}{\end{fulllineitems}}
407
408
409\let\nodename=\label
410
411% For these commands, use \command{} to get the typography right, not
412% {\command}. This works better with the texinfo translation.
413\newcommand{\ABC}{{\sc abc}}
414\newcommand{\UNIX}{{\sc Unix}}
415\newcommand{\POSIX}{POSIX}
416\newcommand{\ASCII}{{\sc ascii}}
417\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
418\newcommand{\C}{C}
419\newcommand{\EOF}{{\sc eof}}
420\newcommand{\NULL}{\code{NULL}}
421
422% code is the most difficult one...
Fred Drake1c8d0e01998-03-07 05:29:15 +0000423\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 +0000424\mbox{\codefont{#1}}}}
425
426\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
427\newcommand{\kbd}[1]{\mbox{\tt #1}}
428\newcommand{\key}[1]{\mbox{\tt #1}}
429\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
430% This weird definition of \var{} allows it to always appear in roman
431% italics, and won't get funky in code fragments when we play around
432% with fonts.
433\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
434\renewcommand{\emph}[1]{{\em #1\/}}
435\newcommand{\dfn}[1]{\emph{#1}}
436\newcommand{\strong}[1]{{\bf #1}}
437% let's experiment with a new font:
Fred Drake0ee9f721998-03-12 06:41:40 +0000438\newcommand{\file}[1]{`{\small\textsf{#1}}'}
Fred Drake6659c301998-03-03 22:02:19 +0000439
440% Use this def/redef approach for \url{} since hyperref defined this already,
441% but only if we actually used hyperref:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000442\@ifundefined{pdfannotlink}{%
Fred Drake6659c301998-03-03 22:02:19 +0000443 \newcommand{\pythonurl}[1]{\mbox{\small\textsf{#1}}}%
444}{
445 \newcommand{\pythonurl}[1]{{%
446 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
447 \LinkColor% color of the link text
448 \mbox{\small\textsf{#1}}%
449 \NormalColor% Turn it back off; these are declarative
450 \pdfendlink}% and don't appear bound to the current
451 }% formatting "box".
452}
453\let\url=\pythonurl
Fred Drake0ee9f721998-03-12 06:41:40 +0000454\newcommand{\email}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000455
456\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
457
458\newif\iftexi\texifalse
459\newif\iflatex\latextrue
460
461% These should be used for all references to identifiers which are
462% used to refer to instances of specific language constructs. See the
463% names for specific semantic assignments.
464%
465% For now, don't do anything really fancy with them; just use them as
466% logical markup. This might change in the future.
467%
468\let\module=\code
469\let\keyword=\code
470\let\exception=\code
471\let\class=\code
472\let\function=\code
473\let\member=\code
474\let\method=\code
475
476\let\cfunction=\code
477\let\ctype=\code
478\let\cdata=\code
479
Fred Drake0ee9f721998-03-12 06:41:40 +0000480\newcommand{\mimetype}[1]{{\small\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000481% The \! is a "negative thin space" in math mode.
482\newcommand{\regexp}[1]{%
483 {\tiny$^{^\lceil}\!\!$%
484 {\normalsize\code{#1}}%
485 $\!\!\rfloor\!$%
486 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000487\newcommand{\envvar}[1]{%
Fred Drake94fac131998-03-12 19:37:03 +0000488 \$#1% $ <-- bow to font-lock 3 times!
489 \index{#1@{\$#1}}% $
490 \index{environment variables!{\$#1}}% $
Fred Drake0ee9f721998-03-12 06:41:40 +0000491}
492\let\character=\samp
493
Fred Drake6659c301998-03-03 22:02:19 +0000494% constants defined in Python modules or C headers, not language constants:
495\let\constant=\code
496
497\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
498\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
499\newcommand{\program}[1]{\strong{#1}}
500
501
502% Deprecation stuff.
503% Should be extended to allow an index / list of deprecated stuff. But
504% there's a lot of stuff that needs to be done to make that automatable.
505%
506% First parameter is the release number that deprecates the feature, the
507% second is the action the should be taken by users of the feature.
508%
509% Example:
510%
511% \deprecated {1.5.1}
512% {Use \method{frobnicate()} instead.}
513%
514\newcommand{\deprecated}[2]{%
515 \strong{Deprecated since release #1.} #2\par}
516
517
518\newenvironment{tableii}[4]{%
519 \begin{center}%
520 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
521 \begin{tabular}{#1}\hline \strong{#3}&\strong{#4} \\ \hline%
522}{%
523 \hline%
524 \end{tabular}%
525 \end{center}%
526}
527
528\newenvironment{tableiii}[5]{%
529 \begin{center}%
530 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
531 \begin{tabular}{#1}\hline \strong{#3}&\strong{#4}&\strong{#5} \\ \hline%
532}{%
533 \hline%
534 \end{tabular}%
535 \end{center}%
536}
537
538\newcommand{\itemnewline}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000539 \@tempdima\linewidth%
540 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
Fred Drake6659c301998-03-03 22:02:19 +0000541}
542
543\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
544
545% Cross-referencing (AMK)
546% Sample usage:
547% \begin{seealso}
548% \seemodule{rand}{Uniform random number generator}; % Module xref
549% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +0000550%
551% % A funky case: module name contains '_'; have to supply an optional key
552% \seemodule[copyreg]{copy_reg}{pickle interface constructor registration}
553%
Fred Drake6659c301998-03-03 22:02:19 +0000554% \end{seealso}
555
Fred Drake1c8d0e01998-03-07 05:29:15 +0000556\newif\if@keyedmodule\@keyedmodulefalse
557\newcommand{\@modulebadkey}{{--just-some-junk--}}
Fred Drakeebcb6581998-03-06 21:25:17 +0000558
Fred Drake1c8d0e01998-03-07 05:29:15 +0000559\@ifundefined{pdfannotlink}{%
560 \newcommand{\seemodule}[3][\@modulebadkey]{%
561 \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
562 \ref{module-\@modulekey}:\quad %
Fred Drakeebcb6581998-03-06 21:25:17 +0000563 Module \module{#2}%
564 \quad (#3)%
565 }
Fred Drake1c8d0e01998-03-07 05:29:15 +0000566}{\newcommand{\seemodule}[3][\@modulebadkey]{%
567 \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
568 \ref{module-\@modulekey}:\quad %
569 {\pdfannotlink attr{/Border [0 0 0]} goto name{label.module-\@modulekey}%
Fred Drakeebcb6581998-03-06 21:25:17 +0000570 \LinkColor Module \module{#2} \NormalColor%
571 \pdfendlink%
572 }%
573 \quad (#3)%
574 }
575}
Fred Drake6659c301998-03-03 22:02:19 +0000576\newenvironment{seealso}[0]{
577 \strong{See Also:}\par
Fred Drake6659c301998-03-03 22:02:19 +0000578 \def\seetext##1{\par{##1}}
579}{\par}
580
581
Fred Drake6659c301998-03-03 22:02:19 +0000582% Allow the release number to be specified independently of the
583% \date{}. This allows the date to reflect the document's date and
584% release to specify the Python release that is documented.
585%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000586\newcommand{\@release}{}
Fred Drake6659c301998-03-03 22:02:19 +0000587\newcommand{\version}{}
588\newcommand{\releasename}{Release}
589\newcommand{\release}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000590 \renewcommand{\@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +0000591 \renewcommand{\version}{#1}}
592
593% Allow specification of the author's address separately from the
594% author's name. This can be used to format them differently, which
595% is a good thing.
596%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000597\newcommand{\@authoraddress}{}
598\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000599
Fred Drake6659c301998-03-03 22:02:19 +0000600% This sets up the fancy chapter headings that make the documents look
601% at least a little better than the usual LaTeX output.
602%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000603\@ifundefined{ChTitleVar}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000604 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
605 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
606 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
607 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000608 \def\@makechapterhead#1{%
609 {\parindent \z@ \raggedright \normalfont
610 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +0000611 \DOCH
612 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +0000613 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +0000614 \DOTI{#1}
615 }
616 }
Fred Drake6659c301998-03-03 22:02:19 +0000617}
618
619% Tell TeX about pathological hyphenation cases:
620\hyphenation{Base-HTTP-Re-quest-Hand-ler}