blob: e634ce7010dade187de011dc7abd0903f4d4e3d5 [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}
Fred Drakec0b2e451998-03-25 14:53:43 +00007 [1998/01/11 LaTeX package (Python markup)]
Fred Drake6659c301998-03-03 22:02:19 +00008
Fred Drake454a4fb1998-04-01 22:20:14 +00009% These packages can be used to add marginal annotations which indicate
10% index entries and labels; useful for reviewing this messy documentation!
11%
12%\RequirePackage{showkeys}
13%\RequirePackage{showidx}
14
Fred Drakec0b2e451998-03-25 14:53:43 +000015% for PDF output, use maximal compression & a lot of other stuff
16% (test for PDF recommended by Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov>)
17%
Fred Drake6cb71491998-03-27 05:22:53 +000018\newif\if@doing@page@targets
19\@doing@page@targetsfalse
20
Fred Drakec0b2e451998-03-25 14:53:43 +000021\ifx\pdfoutput\undefined\else\ifcase\pdfoutput
Fred Drake6659c301998-03-03 22:02:19 +000022 \let\LinkColor=\relax
23 \let\NormalColor=\relax
Fred Drakec0b2e451998-03-25 14:53:43 +000024\else
Fred Drake6659c301998-03-03 22:02:19 +000025 \input{pdfcolor}
26 \let\LinkColor=\NavyBlue
27 \let\NormalColor=\Black
28 \pdfcompresslevel=9
Fred Drakeebcb6581998-03-06 21:25:17 +000029 %
Fred Drakea2c2a831998-04-15 17:50:01 +000030 % Pad the number with '0' to 3 digits wide so no page name is a prefix
31 % of any other.
32 %
33 \def\py@targetno#1{\ifnum#1<100 0\fi\ifnum#1<10 0\fi#1}
34 \def\py@pageno{\py@targetno\thepage}
35 %
Fred Drakeebcb6581998-03-06 21:25:17 +000036 % This definition allows the entries in the page-view of the ToC to be
37 % active links. Some work, some don't.
38 %
Fred Drake6659c301998-03-03 22:02:19 +000039 \let\OldContentsline=\contentsline
Fred Drakea2c2a831998-04-15 17:50:01 +000040 % Compute the padded page number separately since we end up with a pair of
41 % \relax tokens; this gets the right string computed and works.
Fred Drake6659c301998-03-03 22:02:19 +000042 \renewcommand{\contentsline}[3]{%
Fred Drakea2c2a831998-04-15 17:50:01 +000043 \def\my@pageno{\py@targetno{#3}}%
Fred Drake6659c301998-03-03 22:02:19 +000044 \OldContentsline{#1}{%
Fred Drakea2c2a831998-04-15 17:50:01 +000045 \pdfannotlink attr{/Border [0 0 0]} goto name{page\my@pageno}%
Fred Drake6659c301998-03-03 22:02:19 +000046 \LinkColor#2\NormalColor%
47 \pdfendlink%
48 }{#3}%
49 }
Fred Drakeebcb6581998-03-06 21:25:17 +000050 %
51 % This is supposed to build the "outline" view of the document; it seems
52 % quite fragile. The breakages are the same as in the ToC.
53 %
54 \AtEndDocument{
Fred Drakec0b2e451998-03-25 14:53:43 +000055 \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
Fred Drakeebcb6581998-03-06 21:25:17 +000056 }
Fred Drakea2c2a831998-04-15 17:50:01 +000057 \newcommand{\py@target}[1]{%
58 \if@doing@page@targets%
59 {\pdfdest name{#1} fit}%
60 \fi%
61 }
Fred Drake6659c301998-03-03 22:02:19 +000062 \let\OldLabel=\label
63 \renewcommand{\label}[1]{%
64 \OldLabel{#1}%
Fred Drakea2c2a831998-04-15 17:50:01 +000065 \py@target{label-#1}%
Fred Drake6659c301998-03-03 22:02:19 +000066 }
Fred Drakea2c2a831998-04-15 17:50:01 +000067 % This stuff adds a page# destination to every PDF page, where # has
Fred Drake6659c301998-03-03 22:02:19 +000068 % the same formatting as the displayed page number. This doesn't really
69 % help with the frontmatter, but does fine with the body.
70 %
71 % This is *heavily* based on the hyperref package.
72 %
Fred Drake1c8d0e01998-03-07 05:29:15 +000073 \def\@begindvi{%
74 \unvbox \@begindvibox
75 \@hyperfixhead
Fred Drake6659c301998-03-03 22:02:19 +000076 }
Fred Drake1c8d0e01998-03-07 05:29:15 +000077 \def\@hyperfixhead{%
78 \let\H@old@thehead\@thehead
Fred Drakea2c2a831998-04-15 17:50:01 +000079 \global\def\@foo{\py@target{page\py@pageno}}%
Fred Drake1c8d0e01998-03-07 05:29:15 +000080 \expandafter\ifx\expandafter\@empty\H@old@thehead
81 \def\H@old@thehead{\hfil}\fi
82 \def\@thehead{\@foo\relax\H@old@thehead}%
Fred Drake6659c301998-03-03 22:02:19 +000083 }
Fred Drakec0b2e451998-03-25 14:53:43 +000084\fi\fi
Fred Drake6659c301998-03-03 22:02:19 +000085
86% Increase printable page size (copied from fullpage.sty)
87\topmargin 0pt
88\advance \topmargin by -\headheight
89\advance \topmargin by -\headsep
90
91% attempt to work a little better for A4 users
Fred Drake1c8d0e01998-03-07 05:29:15 +000092\@ifundefined{paperheight}{
Fred Drake6659c301998-03-03 22:02:19 +000093 \textheight 9in
94}{
95 \textheight \paperheight
96 \advance\textheight by -2in
97}
98
99\oddsidemargin 0pt
100\evensidemargin \oddsidemargin
101\marginparwidth 0.5in
102
Fred Drake1c8d0e01998-03-07 05:29:15 +0000103\@ifundefined{paperwidth}{
Fred Drake6659c301998-03-03 22:02:19 +0000104 \textwidth 6.5in
105}{
106 \textwidth \paperwidth
107 \advance\textwidth by -2in
108}
109
110
111% Style parameters and macros used by most documents here
112\raggedbottom
113\sloppy
114\parindent = 0mm
115\parskip = 2mm
116\hbadness = 5000 % don't print trivial gripes
117
118\pagestyle{empty} % start this way; change for
119\pagenumbering{roman} % ToC & chapters
120\setcounter{secnumdepth}{1}
121
122% Use this to set the font family for headers and other decor:
123\newcommand{\HeaderFamily}{\sffamily}
124
125% Redefine the 'normal' header/footer style when using "fancyhdr" package:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000126\@ifundefined{fancyhf}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000127 % Use \pagestyle{normal} as the primary pagestyle for text.
128 \fancypagestyle{normal}{
129 \fancyhf{}
130 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
131 \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}
132 \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}
133 \renewcommand{\headrulewidth}{0pt}
134 \renewcommand{\footrulewidth}{0.4pt}
135 }
136 % Update the plain style so we get the page number & footer line,
137 % but not a chapter or section title. This is to keep the first
138 % page of a chapter and the blank page between chapters `clean.'
139 \fancypagestyle{plain}{
140 \fancyhf{}
141 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
142 \renewcommand{\headrulewidth}{0pt}
143 \renewcommand{\footrulewidth}{0.4pt}
144 }
145 % Redefine \cleardoublepage so that the blank page between chapters
146 % gets the plain style and not the fancy style. This is described
147 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000148 \@ifundefined{chapter}{}{
Fred Drake28f13911998-03-04 21:47:59 +0000149 \renewcommand{\cleardoublepage}{
Fred Drake1c8d0e01998-03-07 05:29:15 +0000150 \clearpage\if@openright \ifodd\c@page\else
Fred Drake28f13911998-03-04 21:47:59 +0000151 \hbox{}
152 \thispagestyle{plain}
153 \newpage
Fred Drake1c8d0e01998-03-07 05:29:15 +0000154 \if@twocolumn\hbox{}\newpage\fi\fi\fi
Fred Drake28f13911998-03-04 21:47:59 +0000155 }
156 }
Fred Drake6659c301998-03-03 22:02:19 +0000157}
158
159% old code font selections:
160\let\codefont=\tt
161\let\sectcodefont=\tt
162
163% (Haven't found a new one that gets <, >, and _ right without being
164% monospaced.)
165
166
167% This sets up the {verbatim} environment to be indented and a minipage,
168% and to have all the other mostly nice properties that we want for
169% code samples.
170
171% Variable used by begin code command
172\newlength{\codewidth}
173
174\newcommand{\examplevspace}{2mm}
175\newcommand{\exampleindent}{1cm}
176
177\let\OldVerbatim=\verbatim
178\let\OldEndVerbatim=\endverbatim
179\renewcommand{\verbatim}{%
180 \begingroup%
181 \setlength{\parindent}\exampleindent%
182 % Calculate the text width for the minipage:
183 \setlength{\codewidth}{\linewidth}%
184 \addtolength{\codewidth}{-\parindent}%
185 %
186 \par%
187 \vspace\examplevspace%
188 \indent%
189 \begin{minipage}[t]{\codewidth}%
190 \small%
191 \OldVerbatim%
192}
193\renewcommand{\endverbatim}{%
194 \OldEndVerbatim%
195 \end{minipage}%
196 \endgroup%
197}
198
Fred Drake6cb71491998-03-27 05:22:53 +0000199\newcommand{\reset@python}{
200 \global\let\@thisclass=\@undefined
201 \global\let\@thismodule=\@undefined
202}
203\reset@python
204
205% Augment the sectioning commands used to get our own font family in place,
206% and reset some internal data items:
207\renewcommand{\section}{\reset@python%
Fred Drakea2c2a831998-04-15 17:50:01 +0000208 \@startsection{section}{1}{\z@}%
209 {-3.5ex \@plus -1ex \@minus -.2ex}%
210 {2.3ex \@plus.2ex}%
211 {\reset@font\Large\HeaderFamily}}
Fred Drake1c8d0e01998-03-07 05:29:15 +0000212\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
Fred Drakea2c2a831998-04-15 17:50:01 +0000213 {-3.25ex\@plus -1ex \@minus -.2ex}%
214 {1.5ex \@plus .2ex}%
215 {\reset@font\large\HeaderFamily}}
Fred Drake1c8d0e01998-03-07 05:29:15 +0000216\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
Fred Drakea2c2a831998-04-15 17:50:01 +0000217 {-3.25ex\@plus -1ex \@minus -.2ex}%
218 {1.5ex \@plus .2ex}%
219 {\reset@font\normalsize\HeaderFamily}}
Fred Drake1c8d0e01998-03-07 05:29:15 +0000220\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
Fred Drakea2c2a831998-04-15 17:50:01 +0000221 {3.25ex \@plus1ex \@minus.2ex}%
222 {-1em}%
223 {\reset@font\normalsize\HeaderFamily}}
Fred Drake1c8d0e01998-03-07 05:29:15 +0000224\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
225 {3.25ex \@plus1ex \@minus .2ex}%
Fred Drake6659c301998-03-03 22:02:19 +0000226 {-1em}%
Fred Drakea2c2a831998-04-15 17:50:01 +0000227 {\reset@font\normalsize\HeaderFamily}}
Fred Drake6659c301998-03-03 22:02:19 +0000228
229
230% Underscore hack (only act like subscript operator if in math mode)
231%
232% The following is due to Mark Wooding (the old version didn't work with
233% Latex 2e.
234
235\DeclareRobustCommand\hackscore{%
236 \ifmmode_\else\textunderscore\fi%
237}
238\begingroup
239\catcode`\_\active
240\def\next{%
241 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
242}
243\expandafter\endgroup\next
244
Fred Drake6659c301998-03-03 22:02:19 +0000245
246%% Lots of index-entry generation support.
247
248% Command to wrap around stuff that refers to function / module /
249% attribute names in the index. Default behavior: like \code{}. To
250% just keep the index entries in the roman font, uncomment the second
251% definition to use instead; it matches O'Reilly style more.
252%
253\newcommand{\idxcode}[1]{\codefont{#1}}
254%\renewcommand{\idxcode}[1]{#1}
255
256% Command to generate two index entries (using subentries)
257\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
258
259% And three entries (using only one level of subentries)
260\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
261
262% And four (again, using only one level of subentries)
263\newcommand{\indexiv}[4]{
264\index{#1!#2 #3 #4}
265\index{#2!#3 #4, #1}
266\index{#3!#4, #1 #2}
267\index{#4!#1 #2 #3}
268}
269
270% Command to generate a reference to a function, statement, keyword,
271% operator.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000272\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
273\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
274\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000275\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drake2351c801998-04-02 18:48:32 +0000276\newcommand{\bifuncindex}[1]{\withsubitem{(built-in function)}{\ttindex{#1()}}}
Fred Drake6659c301998-03-03 22:02:19 +0000277
278% Add an index entry for a module
Fred Drake1c8d0e01998-03-07 05:29:15 +0000279\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake6659c301998-03-03 22:02:19 +0000280\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
281\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
282\newcommand{\refexmodindex}[1]{\refmodule{#1}{extension }}
283\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
284
285% support for the module index
Fred Drakeb390daf1998-03-09 16:35:36 +0000286\newif\if@UseModuleIndex
287\@UseModuleIndexfalse
288
Fred Drakeb390daf1998-03-09 16:35:36 +0000289% Fix the theindex environment to add an entry to the Table of
290% Contents; this is much nicer than just having to jump to the end of
291% the book and flip around, especially with multiple indexes.
292%
293\let\OldTheindex=\theindex
294\renewcommand{\theindex}{
295 \cleardoublepage
296 \OldTheindex
297 \addcontentsline{toc}{chapter}{\indexname}
Fred Drakeb390daf1998-03-09 16:35:36 +0000298}
299
Fred Drakeb390daf1998-03-09 16:35:36 +0000300\newcommand{\makemodindex}{
301 \newwrite\modindexfile
302 \openout\modindexfile=mod\jobname.idx
303 \@UseModuleIndextrue
304}
305
Fred Drake0ee9f721998-03-12 06:41:40 +0000306% Add the defining entry for a module
307\newcommand{\@modindex}[2]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000308 \global\def\@thismodule{#1}
309 \setindexsubitem{(in module #1)}%
Fred Drake0ee9f721998-03-12 06:41:40 +0000310 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
311 \if@UseModuleIndex%
312 \write\modindexfile{\protect\indexentry{#1@{\tt #1}}{\thepage}}%
313 \fi%
314}
315
Fred Drake6659c301998-03-03 22:02:19 +0000316% built-in & Python modules in the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000317\newcommand{\bimodindex}[1]{\@modindex{#1}{built-in }}
318\newcommand{\stmodindex}[1]{\@modindex{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000319
320% Python & extension modules outside the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000321\newcommand{\modindex}[1]{\@modindex{#1}{}}
322\newcommand{\exmodindex}[1]{\@modindex{#1}{extension }}
Fred Drake6659c301998-03-03 22:02:19 +0000323
324% Additional string for an index entry
Fred Drake1c8d0e01998-03-07 05:29:15 +0000325\newcommand{\index@subitem}{}
326\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
327\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Fred Drake6659c301998-03-03 22:02:19 +0000328
Fred Drake0ee9f721998-03-12 06:41:40 +0000329\newcommand{\withsubitem}[2]{%
330 \begingroup%
331 \def\index@subitem{#1}#2%
332 \endgroup%
333}
Fred Drake6659c301998-03-03 22:02:19 +0000334
Fred Drake53714971998-04-02 22:33:16 +0000335
336% Now for a lot of semantically-loaded environments that do a ton of magical
337% things to get the right formatting and index entries for the stuff in
338% Python modules and C API.
339
340
Fred Drake6659c301998-03-03 22:02:19 +0000341% {fulllineitems} is used in one place in libregex.tex, but is really for
342% internal use in this file.
343%
344\newenvironment{fulllineitems}{
345 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
346 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
347 \itemsep -\parsep
348 \let\makelabel=\itemnewline}
349}{\end{list}}
350
Fred Drake6cb71491998-03-27 05:22:53 +0000351% \optional is mostly for use in the arguments parameters to the various
352% {*desc} environments defined below, but may be used elsewhere. Known to
353% be used in the debugger chapter.
Fred Drake6659c301998-03-03 22:02:19 +0000354\newcommand{\optional}[1]{%
355 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
356
Fred Drake6cb71491998-03-27 05:22:53 +0000357% C functions ------------------------------------------------------------
358% \begin{cfuncdesc}{type}{name}{arglist}
359\newenvironment{cfuncdesc}[3]{
360 \begin{fulllineitems}
361 \item[\code{#1 \bfcode{#2}(\varvars{#3})}\index{#2@{\idxcode{#2()}}}]
362}{\end{fulllineitems}}
363
364% C variables ------------------------------------------------------------
365% \begin{cvardesc}{type}{name}
366\newenvironment{cvardesc}[2]{
367 \begin{fulllineitems}
368 \item[\code{#1 \bfcode{#2}}\index{#2@{\idxcode{#2}}}]
369}{\end{fulllineitems}}
370
371% C data types -----------------------------------------------------------
372% \begin{ctypedesc}{typedef name}
373\newenvironment{ctypedesc}[1]{
374 \begin{fulllineitems}
375 \item[\bfcode{#1}\ttindex{#1}]
376}{\end{fulllineitems}}
377
378% simple functions (not methods) -----------------------------------------
379% \begin{funcdesc}{name}{args}
380\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
381\newenvironment{funcdesc}[2]{
382 \begin{fulllineitems}
383 \funcline{#1}{#2}
384}{\end{fulllineitems}}
385
Fred Drake6659c301998-03-03 22:02:19 +0000386% similar to {funcdesc}, but doesn't add to the index
387\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
Fred Drake6cb71491998-03-27 05:22:53 +0000388\newenvironment{funcdescni}[2]{
389 \begin{fulllineitems}
390 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000391}{\end{fulllineitems}}
392
Fred Drake6cb71491998-03-27 05:22:53 +0000393% classes ----------------------------------------------------------------
394% \begin{classdesc}{name}{constructor args}
395\newenvironment{classdesc}[2]{
396 \global\def\@thisclass{#1}
397 \begin{fulllineitems}
398 \item[\code{\bfcode{#1}(\varvars{#2})}%
399 \withsubitem{(class in \@thismodule)}{\ttindex{#1}}]
400 \def\baseclasses##1{}
Fred Drake6659c301998-03-03 22:02:19 +0000401}{\end{fulllineitems}}
402
Fred Drake6cb71491998-03-27 05:22:53 +0000403
404\newcommand{\@classbadkey}{--bad current class--}
405\let\@classbadkey=\@undefined
406
407% object method ----------------------------------------------------------
408% \begin{methoddesc}[classname]{methodname}{args}
409\newcommand{\methodline}[3][\@classbadkey]{
410 \methodlineni{#2}{#3}
411 \ifx#1\@undefined
412 \withsubitem{(\@thisclass\ method)}{\ttindex{#2()}}
413 \else
414 \withsubitem{(#1 method)}{\ttindex{#2()}}
415 \fi
416}
417\newenvironment{methoddesc}[3][\@classbadkey]{
418 \begin{fulllineitems}
419 \ifx#1\@undefined
420 \methodline{#2}{#3}
421 \else
422 \def\@thisclass{#1}
423 \methodline[#1]{#2}{#3}
424 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000425}{\end{fulllineitems}}
426
Fred Drake6cb71491998-03-27 05:22:53 +0000427% similar to {methoddesc}, but doesn't add to the index
428% (never actually uses the optional argument)
429\newcommand{\methodlineni}[3][\@classbadkey]{%
430 \item[\code{\bfcode{#2}(\varvars{#3})}]}
431\newenvironment{methoddescni}[3][\@classbadkey]{
432 \begin{fulllineitems}
433 \methodlineni{#2}{#3}
434}{\end{fulllineitems}}
435
436% object data attribute --------------------------------------------------
437% \begin{memberdesc}[classname]{membername}
438\newcommand{\memberline}[2][\@classbadkey]{%
439 \ifx#1\@undefined
440 \memberlineni{#2}
Fred Drake41565f61998-04-07 19:32:40 +0000441 \withsubitem{(\@thisclass\ attribute)}{\ttindex{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000442 \else
443 \memberlineni{#2}
Fred Drake41565f61998-04-07 19:32:40 +0000444 \withsubitem{(#1 attribute)}{\ttindex{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000445 \fi
446}
447\newenvironment{memberdesc}[2][\@classbadkey]{
448 \begin{fulllineitems}
449 \ifx#1\@undefined
450 \memberline{#2}
451 \else
452 \def\@thisclass{#1}
453 \memberline[#1]{#2}
454 \fi
455}{\end{fulllineitems}}
456
457% similar to {memberdesc}, but doesn't add to the index
458% (never actually uses the optional argument)
459\newcommand{\memberlineni}[2][\@classbadkey]{\item[\bfcode{#2}]}
460\newenvironment{memberdescni}[2][\@classbadkey]{
461 \begin{fulllineitems}
462 \memberlineni{#2}
463}{\end{fulllineitems}}
464
465% For exceptions: --------------------------------------------------------
466% \begin{excdesc}{name}
467% -- need support for constructor; maybe use optional parameter?
468\newenvironment{excdesc}[1]{
469 \begin{fulllineitems}
470 \item[\bfcode{#1}\ttindex{#1}]
471}{\end{fulllineitems}}
472
473% Module data or constants: ----------------------------------------------
474% \begin{datadesc}{name}
Fred Drake6659c301998-03-03 22:02:19 +0000475\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drake6cb71491998-03-27 05:22:53 +0000476\newenvironment{datadesc}[1]{
477 \begin{fulllineitems}
478 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000479}{\end{fulllineitems}}
480
481% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000482\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
483\newenvironment{datadescni}[1]{
484 \begin{fulllineitems}
485 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000486}{\end{fulllineitems}}
487
Fred Drake6cb71491998-03-27 05:22:53 +0000488% bytecode instruction ---------------------------------------------------
489% \begin{opcodedesc}{name}{var}
490% -- {var} may be {}
491\newenvironment{opcodedesc}[2]{
492 \begin{fulllineitems}
493 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000494}{\end{fulllineitems}}
495
496
497\let\nodename=\label
498
Fred Drake55730311998-03-25 15:41:23 +0000499\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
500
Fred Drake6659c301998-03-03 22:02:19 +0000501% For these commands, use \command{} to get the typography right, not
502% {\command}. This works better with the texinfo translation.
503\newcommand{\ABC}{{\sc abc}}
504\newcommand{\UNIX}{{\sc Unix}}
505\newcommand{\POSIX}{POSIX}
506\newcommand{\ASCII}{{\sc ascii}}
507\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
508\newcommand{\C}{C}
509\newcommand{\EOF}{{\sc eof}}
Fred Drake55730311998-03-25 15:41:23 +0000510\newcommand{\NULL}{\sectcode{NULL}}
Fred Drake6659c301998-03-03 22:02:19 +0000511
Fred Drake53714971998-04-02 22:33:16 +0000512% Also for consistency: spell Python "Python", not "python"!
513
Fred Drake6659c301998-03-03 22:02:19 +0000514% code is the most difficult one...
Fred Drake1c8d0e01998-03-07 05:29:15 +0000515\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 +0000516\mbox{\codefont{#1}}}}
517
518\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
519\newcommand{\kbd}[1]{\mbox{\tt #1}}
520\newcommand{\key}[1]{\mbox{\tt #1}}
521\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
522% This weird definition of \var{} allows it to always appear in roman
523% italics, and won't get funky in code fragments when we play around
524% with fonts.
525\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
526\renewcommand{\emph}[1]{{\em #1\/}}
527\newcommand{\dfn}[1]{\emph{#1}}
528\newcommand{\strong}[1]{{\bf #1}}
529% let's experiment with a new font:
Fred Drake0ee9f721998-03-12 06:41:40 +0000530\newcommand{\file}[1]{`{\small\textsf{#1}}'}
Fred Drake6659c301998-03-03 22:02:19 +0000531
532% Use this def/redef approach for \url{} since hyperref defined this already,
533% but only if we actually used hyperref:
Fred Drake6cb71491998-03-27 05:22:53 +0000534\@ifundefined{pdfannotlink}{
Fred Drakea2c2a831998-04-15 17:50:01 +0000535 \newcommand{\py@url}[1]{\mbox{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000536}{
Fred Drakea2c2a831998-04-15 17:50:01 +0000537 \newcommand{\py@url}[1]{{%
Fred Drake6659c301998-03-03 22:02:19 +0000538 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
539 \LinkColor% color of the link text
Fred Drake6cb71491998-03-27 05:22:53 +0000540 {\small\textsf{#1}}%
Fred Drake6659c301998-03-03 22:02:19 +0000541 \NormalColor% Turn it back off; these are declarative
542 \pdfendlink}% and don't appear bound to the current
543 }% formatting "box".
544}
Fred Drakea2c2a831998-04-15 17:50:01 +0000545\let\url=\py@url
Fred Drake0ee9f721998-03-12 06:41:40 +0000546\newcommand{\email}[1]{{\small\textsf{#1}}}
Fred Drake454a4fb1998-04-01 22:20:14 +0000547\newcommand{\newsgroup}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000548
549\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
550
551\newif\iftexi\texifalse
552\newif\iflatex\latextrue
553
554% These should be used for all references to identifiers which are
555% used to refer to instances of specific language constructs. See the
556% names for specific semantic assignments.
557%
558% For now, don't do anything really fancy with them; just use them as
559% logical markup. This might change in the future.
560%
Fred Drake55730311998-03-25 15:41:23 +0000561\let\module=\sectcode
562\let\keyword=\sectcode
563\let\exception=\sectcode
564\let\class=\sectcode
565\let\function=\sectcode
566\let\member=\sectcode
567\let\method=\sectcode
Fred Drake6659c301998-03-03 22:02:19 +0000568
Fred Drake53714971998-04-02 22:33:16 +0000569\newcommand{\pytype}[1]{#1} % built-in Python type
570
Fred Drake55730311998-03-25 15:41:23 +0000571\let\cfunction=\sectcode
572\let\ctype=\sectcode
573\let\cdata=\sectcode
Fred Drake6659c301998-03-03 22:02:19 +0000574
Fred Drake0ee9f721998-03-12 06:41:40 +0000575\newcommand{\mimetype}[1]{{\small\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000576% The \! is a "negative thin space" in math mode.
577\newcommand{\regexp}[1]{%
578 {\tiny$^{^\lceil}\!\!$%
579 {\normalsize\code{#1}}%
Fred Drake47cfd031998-04-03 21:22:31 +0000580 $\!\rfloor\!$%
Fred Drake94fac131998-03-12 19:37:03 +0000581 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000582\newcommand{\envvar}[1]{%
Fred Drake94fac131998-03-12 19:37:03 +0000583 \$#1% $ <-- bow to font-lock 3 times!
584 \index{#1@{\$#1}}% $
585 \index{environment variables!{\$#1}}% $
Fred Drake0ee9f721998-03-12 06:41:40 +0000586}
Fred Drakef14e2f81998-04-02 16:09:02 +0000587\newcommand{\makevar}[1]{#1}
Fred Drake0ee9f721998-03-12 06:41:40 +0000588\let\character=\samp
589
Fred Drake6659c301998-03-03 22:02:19 +0000590% constants defined in Python modules or C headers, not language constants:
Fred Drakef14e2f81998-04-02 16:09:02 +0000591\let\constant=\sectcode
Fred Drake6659c301998-03-03 22:02:19 +0000592
593\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
594\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
595\newcommand{\program}[1]{\strong{#1}}
596
597
598% Deprecation stuff.
599% Should be extended to allow an index / list of deprecated stuff. But
600% there's a lot of stuff that needs to be done to make that automatable.
601%
602% First parameter is the release number that deprecates the feature, the
603% second is the action the should be taken by users of the feature.
604%
605% Example:
606%
607% \deprecated {1.5.1}
608% {Use \method{frobnicate()} instead.}
609%
610\newcommand{\deprecated}[2]{%
611 \strong{Deprecated since release #1.} #2\par}
612
613
614\newenvironment{tableii}[4]{%
615 \begin{center}%
616 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakeee601911998-04-11 20:53:03 +0000617 \begin{tabular}{#1}\strong{#3}&\strong{#4} \\ \hline%
Fred Drake6659c301998-03-03 22:02:19 +0000618}{%
Fred Drake6659c301998-03-03 22:02:19 +0000619 \end{tabular}%
620 \end{center}%
621}
622
623\newenvironment{tableiii}[5]{%
624 \begin{center}%
625 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
Fred Drakeee601911998-04-11 20:53:03 +0000626 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\ \hline%
Fred Drake6659c301998-03-03 22:02:19 +0000627}{%
Fred Drake6659c301998-03-03 22:02:19 +0000628 \end{tabular}%
629 \end{center}%
630}
631
632\newcommand{\itemnewline}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000633 \@tempdima\linewidth%
634 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
Fred Drake6659c301998-03-03 22:02:19 +0000635}
636
Fred Drake6659c301998-03-03 22:02:19 +0000637% Cross-referencing (AMK)
638% Sample usage:
639% \begin{seealso}
640% \seemodule{rand}{Uniform random number generator}; % Module xref
641% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +0000642%
643% % A funky case: module name contains '_'; have to supply an optional key
644% \seemodule[copyreg]{copy_reg}{pickle interface constructor registration}
645%
Fred Drake6659c301998-03-03 22:02:19 +0000646% \end{seealso}
647
Fred Drake1c8d0e01998-03-07 05:29:15 +0000648\newcommand{\@modulebadkey}{{--just-some-junk--}}
Fred Drakeebcb6581998-03-06 21:25:17 +0000649
Fred Drake1c8d0e01998-03-07 05:29:15 +0000650\@ifundefined{pdfannotlink}{%
651 \newcommand{\seemodule}[3][\@modulebadkey]{%
652 \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
653 \ref{module-\@modulekey}:\quad %
Fred Drakeebcb6581998-03-06 21:25:17 +0000654 Module \module{#2}%
655 \quad (#3)%
656 }
Fred Drake1c8d0e01998-03-07 05:29:15 +0000657}{\newcommand{\seemodule}[3][\@modulebadkey]{%
658 \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
659 \ref{module-\@modulekey}:\quad %
Fred Drakea2c2a831998-04-15 17:50:01 +0000660 {\pdfannotlink attr{/Border [0 0 0]} goto name{label-module-\@modulekey}%
Fred Drakeebcb6581998-03-06 21:25:17 +0000661 \LinkColor Module \module{#2} \NormalColor%
662 \pdfendlink%
663 }%
664 \quad (#3)%
665 }
666}
Fred Drake6659c301998-03-03 22:02:19 +0000667\newenvironment{seealso}[0]{
668 \strong{See Also:}\par
Fred Drake6659c301998-03-03 22:02:19 +0000669 \def\seetext##1{\par{##1}}
670}{\par}
671
672
Fred Drake6659c301998-03-03 22:02:19 +0000673% Allow the release number to be specified independently of the
674% \date{}. This allows the date to reflect the document's date and
675% release to specify the Python release that is documented.
676%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000677\newcommand{\@release}{}
Fred Drake6659c301998-03-03 22:02:19 +0000678\newcommand{\version}{}
679\newcommand{\releasename}{Release}
680\newcommand{\release}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000681 \renewcommand{\@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +0000682 \renewcommand{\version}{#1}}
683
684% Allow specification of the author's address separately from the
685% author's name. This can be used to format them differently, which
686% is a good thing.
687%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000688\newcommand{\@authoraddress}{}
689\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000690
Fred Drake6659c301998-03-03 22:02:19 +0000691% This sets up the fancy chapter headings that make the documents look
692% at least a little better than the usual LaTeX output.
693%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000694\@ifundefined{ChTitleVar}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000695 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
696 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
697 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
698 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000699 \def\@makechapterhead#1{%
700 {\parindent \z@ \raggedright \normalfont
701 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +0000702 \DOCH
703 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +0000704 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +0000705 \DOTI{#1}
706 }
707 }
Fred Drake6659c301998-03-03 22:02:19 +0000708}
709
710% Tell TeX about pathological hyphenation cases:
711\hyphenation{Base-HTTP-Re-quest-Hand-ler}