blob: 9fc95e5ae72d0c6f9168a4b195c8214be26efca6 [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 Drake24340ea1998-04-28 18:30:34 +000018\newif\ifpy@doing@page@targets
19\py@doing@page@targetsfalse
Fred Drake6cb71491998-03-27 05:22:53 +000020
Fred Drakec0b2e451998-03-25 14:53:43 +000021\ifx\pdfoutput\undefined\else\ifcase\pdfoutput
Fred Drakec0b2e451998-03-25 14:53:43 +000022\else
Fred Drake6659c301998-03-03 22:02:19 +000023 \input{pdfcolor}
Fred Drake24340ea1998-04-28 18:30:34 +000024 \let\py@LinkColor=\NavyBlue
25 \let\py@NormalColor=\Black
Fred Drake6659c301998-03-03 22:02:19 +000026 \pdfcompresslevel=9
Fred Drakeebcb6581998-03-06 21:25:17 +000027 %
Fred Drakea2c2a831998-04-15 17:50:01 +000028 % Pad the number with '0' to 3 digits wide so no page name is a prefix
29 % of any other.
30 %
31 \def\py@targetno#1{\ifnum#1<100 0\fi\ifnum#1<10 0\fi#1}
32 \def\py@pageno{\py@targetno\thepage}
33 %
Fred Drakeebcb6581998-03-06 21:25:17 +000034 % This definition allows the entries in the page-view of the ToC to be
35 % active links. Some work, some don't.
36 %
Fred Drake24340ea1998-04-28 18:30:34 +000037 \let\py@OldContentsline=\contentsline
Fred Drakea2c2a831998-04-15 17:50:01 +000038 % Compute the padded page number separately since we end up with a pair of
39 % \relax tokens; this gets the right string computed and works.
Fred Drake6659c301998-03-03 22:02:19 +000040 \renewcommand{\contentsline}[3]{%
Fred Drakea2c2a831998-04-15 17:50:01 +000041 \def\my@pageno{\py@targetno{#3}}%
Fred Drake24340ea1998-04-28 18:30:34 +000042 \py@OldContentsline{#1}{%
Fred Drakea2c2a831998-04-15 17:50:01 +000043 \pdfannotlink attr{/Border [0 0 0]} goto name{page\my@pageno}%
Fred Drake24340ea1998-04-28 18:30:34 +000044 \py@LinkColor#2\py@NormalColor%
Fred Drake6659c301998-03-03 22:02:19 +000045 \pdfendlink%
46 }{#3}%
47 }
Fred Drakeebcb6581998-03-06 21:25:17 +000048 %
49 % This is supposed to build the "outline" view of the document; it seems
50 % quite fragile. The breakages are the same as in the ToC.
51 %
52 \AtEndDocument{
Fred Drakec0b2e451998-03-25 14:53:43 +000053 \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
Fred Drakeebcb6581998-03-06 21:25:17 +000054 }
Fred Drakea2c2a831998-04-15 17:50:01 +000055 \newcommand{\py@target}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000056 \ifpy@doing@page@targets%
Fred Drakea2c2a831998-04-15 17:50:01 +000057 {\pdfdest name{#1} fit}%
58 \fi%
59 }
Fred Drake24340ea1998-04-28 18:30:34 +000060 \let\py@OldLabel=\label
Fred Drake6659c301998-03-03 22:02:19 +000061 \renewcommand{\label}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000062 \py@OldLabel{#1}%
Fred Drakea2c2a831998-04-15 17:50:01 +000063 \py@target{label-#1}%
Fred Drake6659c301998-03-03 22:02:19 +000064 }
Fred Drakea2c2a831998-04-15 17:50:01 +000065 % This stuff adds a page# destination to every PDF page, where # has
Fred Drake6659c301998-03-03 22:02:19 +000066 % the same formatting as the displayed page number. This doesn't really
67 % help with the frontmatter, but does fine with the body.
68 %
69 % This is *heavily* based on the hyperref package.
70 %
Fred Drake1c8d0e01998-03-07 05:29:15 +000071 \def\@begindvi{%
72 \unvbox \@begindvibox
73 \@hyperfixhead
Fred Drake6659c301998-03-03 22:02:19 +000074 }
Fred Drake1c8d0e01998-03-07 05:29:15 +000075 \def\@hyperfixhead{%
76 \let\H@old@thehead\@thehead
Fred Drakea2c2a831998-04-15 17:50:01 +000077 \global\def\@foo{\py@target{page\py@pageno}}%
Fred Drake1c8d0e01998-03-07 05:29:15 +000078 \expandafter\ifx\expandafter\@empty\H@old@thehead
79 \def\H@old@thehead{\hfil}\fi
80 \def\@thehead{\@foo\relax\H@old@thehead}%
Fred Drake6659c301998-03-03 22:02:19 +000081 }
Fred Drakec0b2e451998-03-25 14:53:43 +000082\fi\fi
Fred Drake6659c301998-03-03 22:02:19 +000083
84% Increase printable page size (copied from fullpage.sty)
85\topmargin 0pt
86\advance \topmargin by -\headheight
87\advance \topmargin by -\headsep
88
89% attempt to work a little better for A4 users
Fred Drake1c8d0e01998-03-07 05:29:15 +000090\@ifundefined{paperheight}{
Fred Drake6659c301998-03-03 22:02:19 +000091 \textheight 9in
92}{
93 \textheight \paperheight
94 \advance\textheight by -2in
95}
96
97\oddsidemargin 0pt
98\evensidemargin \oddsidemargin
99\marginparwidth 0.5in
100
Fred Drake1c8d0e01998-03-07 05:29:15 +0000101\@ifundefined{paperwidth}{
Fred Drake6659c301998-03-03 22:02:19 +0000102 \textwidth 6.5in
103}{
104 \textwidth \paperwidth
105 \advance\textwidth by -2in
106}
107
108
109% Style parameters and macros used by most documents here
110\raggedbottom
111\sloppy
112\parindent = 0mm
Fred Drake24340ea1998-04-28 18:30:34 +0000113\parskip = 2mm
Fred Drake6659c301998-03-03 22:02:19 +0000114\hbadness = 5000 % don't print trivial gripes
115
116\pagestyle{empty} % start this way; change for
117\pagenumbering{roman} % ToC & chapters
118\setcounter{secnumdepth}{1}
119
120% Use this to set the font family for headers and other decor:
Fred Drake24340ea1998-04-28 18:30:34 +0000121\newcommand{\py@HeaderFamily}{\sffamily}
Fred Drake6659c301998-03-03 22:02:19 +0000122
123% Redefine the 'normal' header/footer style when using "fancyhdr" package:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000124\@ifundefined{fancyhf}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000125 % Use \pagestyle{normal} as the primary pagestyle for text.
126 \fancypagestyle{normal}{
127 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000128 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
129 \fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
130 \fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
Fred Drake6659c301998-03-03 22:02:19 +0000131 \renewcommand{\headrulewidth}{0pt}
132 \renewcommand{\footrulewidth}{0.4pt}
133 }
134 % Update the plain style so we get the page number & footer line,
135 % but not a chapter or section title. This is to keep the first
136 % page of a chapter and the blank page between chapters `clean.'
137 \fancypagestyle{plain}{
138 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000139 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
Fred Drake6659c301998-03-03 22:02:19 +0000140 \renewcommand{\headrulewidth}{0pt}
141 \renewcommand{\footrulewidth}{0.4pt}
142 }
143 % Redefine \cleardoublepage so that the blank page between chapters
144 % gets the plain style and not the fancy style. This is described
145 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000146 \@ifundefined{chapter}{}{
Fred Drake28f13911998-03-04 21:47:59 +0000147 \renewcommand{\cleardoublepage}{
Fred Drake1c8d0e01998-03-07 05:29:15 +0000148 \clearpage\if@openright \ifodd\c@page\else
Fred Drake28f13911998-03-04 21:47:59 +0000149 \hbox{}
150 \thispagestyle{plain}
151 \newpage
Fred Drake1c8d0e01998-03-07 05:29:15 +0000152 \if@twocolumn\hbox{}\newpage\fi\fi\fi
Fred Drake28f13911998-03-04 21:47:59 +0000153 }
154 }
Fred Drake6659c301998-03-03 22:02:19 +0000155}
156
Fred Drake6659c301998-03-03 22:02:19 +0000157% This sets up the {verbatim} environment to be indented and a minipage,
158% and to have all the other mostly nice properties that we want for
159% code samples.
160
161% Variable used by begin code command
Fred Drake24340ea1998-04-28 18:30:34 +0000162\newlength{\py@codewidth}
Fred Drake6659c301998-03-03 22:02:19 +0000163
Fred Drake24340ea1998-04-28 18:30:34 +0000164\newcommand{\py@examplevspace}{2mm}
165\newcommand{\py@exampleindent}{1cm}
Fred Drake6659c301998-03-03 22:02:19 +0000166
Fred Drake24340ea1998-04-28 18:30:34 +0000167\let\py@OldVerbatim=\verbatim
168\let\py@OldEndVerbatim=\endverbatim
Fred Drake6659c301998-03-03 22:02:19 +0000169\renewcommand{\verbatim}{%
170 \begingroup%
Fred Drake24340ea1998-04-28 18:30:34 +0000171 \setlength{\parindent}\py@exampleindent%
Fred Drake6659c301998-03-03 22:02:19 +0000172 % Calculate the text width for the minipage:
Fred Drake24340ea1998-04-28 18:30:34 +0000173 \setlength{\py@codewidth}{\linewidth}%
174 \addtolength{\py@codewidth}{-\parindent}%
Fred Drake6659c301998-03-03 22:02:19 +0000175 %
176 \par%
Fred Drake24340ea1998-04-28 18:30:34 +0000177 \vspace\py@examplevspace%
Fred Drake6659c301998-03-03 22:02:19 +0000178 \indent%
Fred Drake24340ea1998-04-28 18:30:34 +0000179 \begin{minipage}[t]{\py@codewidth}%
Fred Drake6659c301998-03-03 22:02:19 +0000180 \small%
Fred Drake24340ea1998-04-28 18:30:34 +0000181 \py@OldVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000182}
183\renewcommand{\endverbatim}{%
Fred Drake24340ea1998-04-28 18:30:34 +0000184 \py@OldEndVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000185 \end{minipage}%
186 \endgroup%
187}
188
Fred Drake6cb71491998-03-27 05:22:53 +0000189\newcommand{\reset@python}{
Fred Drake24340ea1998-04-28 18:30:34 +0000190 \global\let\py@thisclass=\@undefined
191 \global\let\py@thismodule=\@undefined
Fred Drake6cb71491998-03-27 05:22:53 +0000192}
193\reset@python
194
195% Augment the sectioning commands used to get our own font family in place,
196% and reset some internal data items:
197\renewcommand{\section}{\reset@python%
Fred Drakea2c2a831998-04-15 17:50:01 +0000198 \@startsection{section}{1}{\z@}%
Fred Drake24340ea1998-04-28 18:30:34 +0000199 {-3.5ex \@plus -1ex \@minus -.2ex}%
200 {2.3ex \@plus.2ex}%
201 {\reset@font\Large\py@HeaderFamily}}
Fred Drake1c8d0e01998-03-07 05:29:15 +0000202\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
Fred Drake24340ea1998-04-28 18:30:34 +0000203 {-3.25ex\@plus -1ex \@minus -.2ex}%
204 {1.5ex \@plus .2ex}%
205 {\reset@font\large\py@HeaderFamily}}
Fred Drake1c8d0e01998-03-07 05:29:15 +0000206\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
Fred Drake24340ea1998-04-28 18:30:34 +0000207 {-3.25ex\@plus -1ex \@minus -.2ex}%
208 {1.5ex \@plus .2ex}%
209 {\reset@font\normalsize\py@HeaderFamily}}
Fred Drake1c8d0e01998-03-07 05:29:15 +0000210\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
Fred Drake24340ea1998-04-28 18:30:34 +0000211 {3.25ex \@plus1ex \@minus.2ex}%
212 {-1em}%
213 {\reset@font\normalsize\py@HeaderFamily}}
Fred Drake1c8d0e01998-03-07 05:29:15 +0000214\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
Fred Drake24340ea1998-04-28 18:30:34 +0000215 {3.25ex \@plus1ex \@minus .2ex}%
216 {-1em}%
217 {\reset@font\normalsize\py@HeaderFamily}}
Fred Drake6659c301998-03-03 22:02:19 +0000218
219
220% Underscore hack (only act like subscript operator if in math mode)
221%
222% The following is due to Mark Wooding (the old version didn't work with
223% Latex 2e.
224
225\DeclareRobustCommand\hackscore{%
226 \ifmmode_\else\textunderscore\fi%
227}
228\begingroup
229\catcode`\_\active
230\def\next{%
231 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
232}
233\expandafter\endgroup\next
234
Fred Drake6659c301998-03-03 22:02:19 +0000235
236%% Lots of index-entry generation support.
237
238% Command to wrap around stuff that refers to function / module /
239% attribute names in the index. Default behavior: like \code{}. To
240% just keep the index entries in the roman font, uncomment the second
241% definition to use instead; it matches O'Reilly style more.
242%
Fred Drake24340ea1998-04-28 18:30:34 +0000243\newcommand{\py@idxcode}[1]{\texttt{#1}}
244%\renewcommand{\py@idxcode}[1]{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000245
246% Command to generate two index entries (using subentries)
247\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
248
249% And three entries (using only one level of subentries)
250\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
251
252% And four (again, using only one level of subentries)
253\newcommand{\indexiv}[4]{
254\index{#1!#2 #3 #4}
255\index{#2!#3 #4, #1}
256\index{#3!#4, #1 #2}
257\index{#4!#1 #2 #3}
258}
259
260% Command to generate a reference to a function, statement, keyword,
261% operator.
Fred Drake24340ea1998-04-28 18:30:34 +0000262\newcommand{\stindex}[1]{\indexii{statement}{#1@{\py@idxcode{#1}}}}
263\newcommand{\opindex}[1]{\indexii{operator}{#1@{\py@idxcode{#1}}}}
264\newcommand{\exindex}[1]{\indexii{exception}{#1@{\py@idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000265\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drake2351c801998-04-02 18:48:32 +0000266\newcommand{\bifuncindex}[1]{\withsubitem{(built-in function)}{\ttindex{#1()}}}
Fred Drake6659c301998-03-03 22:02:19 +0000267
268% Add an index entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000269\newcommand{\py@refmodule}[2]{\index{#1@{\py@idxcode{#1}} (#2module)}}
270\newcommand{\refmodindex}[1]{\py@refmodule{#1}{}}
271\newcommand{\refbimodindex}[1]{\py@refmodule{#1}{built-in }}
272\newcommand{\refexmodindex}[1]{\py@refmodule{#1}{extension }}
273\newcommand{\refstmodindex}[1]{\py@refmodule{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000274
275% support for the module index
Fred Drake24340ea1998-04-28 18:30:34 +0000276\newif\ifpy@UseModuleIndex
277\py@UseModuleIndexfalse
Fred Drakeb390daf1998-03-09 16:35:36 +0000278
Fred Drakeb390daf1998-03-09 16:35:36 +0000279\newcommand{\makemodindex}{
280 \newwrite\modindexfile
281 \openout\modindexfile=mod\jobname.idx
Fred Drake24340ea1998-04-28 18:30:34 +0000282 \py@UseModuleIndextrue
Fred Drakeb390daf1998-03-09 16:35:36 +0000283}
284
Fred Drake0ee9f721998-03-12 06:41:40 +0000285% Add the defining entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000286\newcommand{\py@modindex}[2]{%
287 \global\def\py@thismodule{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000288 \setindexsubitem{(in module #1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000289 \index{#1@{\py@idxcode{#1}} (#2module)|textbf}%
290 \ifpy@UseModuleIndex%
Fred Drake0ee9f721998-03-12 06:41:40 +0000291 \write\modindexfile{\protect\indexentry{#1@{\tt #1}}{\thepage}}%
292 \fi%
293}
294
Fred Drake6659c301998-03-03 22:02:19 +0000295% built-in & Python modules in the main distribution
Fred Drake24340ea1998-04-28 18:30:34 +0000296\newcommand{\bimodindex}[1]{\py@modindex{#1}{built-in }}
297\newcommand{\stmodindex}[1]{\py@modindex{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000298
299% Python & extension modules outside the main distribution
Fred Drake24340ea1998-04-28 18:30:34 +0000300\newcommand{\modindex}[1]{\py@modindex{#1}{}}
301\newcommand{\exmodindex}[1]{\py@modindex{#1}{extension }}
Fred Drake6659c301998-03-03 22:02:19 +0000302
303% Additional string for an index entry
Fred Drake1c8d0e01998-03-07 05:29:15 +0000304\newcommand{\index@subitem}{}
305\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000306\newcommand{\ttindex}[1]{\index{#1@{\py@idxcode{#1}} \index@subitem}}
Fred Drake6659c301998-03-03 22:02:19 +0000307
Fred Drake0ee9f721998-03-12 06:41:40 +0000308\newcommand{\withsubitem}[2]{%
309 \begingroup%
310 \def\index@subitem{#1}#2%
311 \endgroup%
312}
Fred Drake6659c301998-03-03 22:02:19 +0000313
Fred Drake53714971998-04-02 22:33:16 +0000314
315% Now for a lot of semantically-loaded environments that do a ton of magical
316% things to get the right formatting and index entries for the stuff in
317% Python modules and C API.
318
319
Fred Drake6659c301998-03-03 22:02:19 +0000320% {fulllineitems} is used in one place in libregex.tex, but is really for
321% internal use in this file.
322%
323\newenvironment{fulllineitems}{
324 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
325 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
326 \itemsep -\parsep
327 \let\makelabel=\itemnewline}
328}{\end{list}}
329
Fred Drake6cb71491998-03-27 05:22:53 +0000330% \optional is mostly for use in the arguments parameters to the various
331% {*desc} environments defined below, but may be used elsewhere. Known to
332% be used in the debugger chapter.
Fred Drake24340ea1998-04-28 18:30:34 +0000333%
334% Typical usage:
335%
336% \begin{funcdesc}{myfunc}{reqparm\optional{, optparm}}
337% ^^^ ^^^
338% No space here No space here
339%
340% When a function has multiple optional parameters, \optional should be
341% nested, not chained. This is right:
342%
343% \begin{funcdesc}{myfunc}{\optional{parm1\optional{, parm2}}}
344%
Fred Drake6659c301998-03-03 22:02:19 +0000345\newcommand{\optional}[1]{%
346 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
347
Fred Drake6cb71491998-03-27 05:22:53 +0000348% C functions ------------------------------------------------------------
349% \begin{cfuncdesc}{type}{name}{arglist}
350\newenvironment{cfuncdesc}[3]{
351 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000352 \item[\code{#1 \bfcode{#2}(\py@varvars{#3})}\index{#2@{\py@idxcode{#2()}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000353}{\end{fulllineitems}}
354
355% C variables ------------------------------------------------------------
356% \begin{cvardesc}{type}{name}
357\newenvironment{cvardesc}[2]{
358 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000359 \item[\code{#1 \bfcode{#2}}\index{#2@{\py@idxcode{#2}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000360}{\end{fulllineitems}}
361
362% C data types -----------------------------------------------------------
363% \begin{ctypedesc}{typedef name}
364\newenvironment{ctypedesc}[1]{
365 \begin{fulllineitems}
366 \item[\bfcode{#1}\ttindex{#1}]
367}{\end{fulllineitems}}
368
369% simple functions (not methods) -----------------------------------------
370% \begin{funcdesc}{name}{args}
371\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
372\newenvironment{funcdesc}[2]{
373 \begin{fulllineitems}
374 \funcline{#1}{#2}
375}{\end{fulllineitems}}
376
Fred Drake6659c301998-03-03 22:02:19 +0000377% similar to {funcdesc}, but doesn't add to the index
Fred Drake300775d1998-04-17 02:17:00 +0000378\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\py@varvars{#2})}]}
Fred Drake6cb71491998-03-27 05:22:53 +0000379\newenvironment{funcdescni}[2]{
380 \begin{fulllineitems}
381 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000382}{\end{fulllineitems}}
383
Fred Drake6cb71491998-03-27 05:22:53 +0000384% classes ----------------------------------------------------------------
385% \begin{classdesc}{name}{constructor args}
386\newenvironment{classdesc}[2]{
Fred Drake24340ea1998-04-28 18:30:34 +0000387 \global\def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000388 \begin{fulllineitems}
Fred Drake300775d1998-04-17 02:17:00 +0000389 \item[\code{\bfcode{#1}(\py@varvars{#2})}%
Fred Drake24340ea1998-04-28 18:30:34 +0000390 \withsubitem{(class in \py@thismodule)}{\ttindex{#1}}]
Fred Drake6659c301998-03-03 22:02:19 +0000391}{\end{fulllineitems}}
392
Fred Drake6cb71491998-03-27 05:22:53 +0000393
Fred Drake24340ea1998-04-28 18:30:34 +0000394\let\py@classbadkey=\@undefined
Fred Drake6cb71491998-03-27 05:22:53 +0000395
396% object method ----------------------------------------------------------
397% \begin{methoddesc}[classname]{methodname}{args}
Fred Drake24340ea1998-04-28 18:30:34 +0000398\newcommand{\methodline}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000399 \methodlineni{#2}{#3}
400 \ifx#1\@undefined
Fred Drake24340ea1998-04-28 18:30:34 +0000401 \withsubitem{(\py@thisclass\ method)}{\ttindex{#2()}}
Fred Drake6cb71491998-03-27 05:22:53 +0000402 \else
403 \withsubitem{(#1 method)}{\ttindex{#2()}}
404 \fi
405}
Fred Drake24340ea1998-04-28 18:30:34 +0000406\newenvironment{methoddesc}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000407 \begin{fulllineitems}
408 \ifx#1\@undefined
409 \methodline{#2}{#3}
410 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000411 \def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000412 \methodline[#1]{#2}{#3}
413 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000414}{\end{fulllineitems}}
415
Fred Drake6cb71491998-03-27 05:22:53 +0000416% similar to {methoddesc}, but doesn't add to the index
417% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000418\newcommand{\methodlineni}[3][\py@classbadkey]{%
Fred Drake300775d1998-04-17 02:17:00 +0000419 \item[\code{\bfcode{#2}(\py@varvars{#3})}]}
Fred Drake24340ea1998-04-28 18:30:34 +0000420\newenvironment{methoddescni}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000421 \begin{fulllineitems}
422 \methodlineni{#2}{#3}
423}{\end{fulllineitems}}
424
425% object data attribute --------------------------------------------------
426% \begin{memberdesc}[classname]{membername}
Fred Drake24340ea1998-04-28 18:30:34 +0000427\newcommand{\memberline}[2][\py@classbadkey]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000428 \ifx#1\@undefined
429 \memberlineni{#2}
Fred Drake24340ea1998-04-28 18:30:34 +0000430 \withsubitem{(\py@thisclass\ attribute)}{\ttindex{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000431 \else
432 \memberlineni{#2}
Fred Drake41565f61998-04-07 19:32:40 +0000433 \withsubitem{(#1 attribute)}{\ttindex{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000434 \fi
435}
Fred Drake24340ea1998-04-28 18:30:34 +0000436\newenvironment{memberdesc}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000437 \begin{fulllineitems}
438 \ifx#1\@undefined
439 \memberline{#2}
440 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000441 \def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000442 \memberline[#1]{#2}
443 \fi
444}{\end{fulllineitems}}
445
446% similar to {memberdesc}, but doesn't add to the index
447% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000448\newcommand{\memberlineni}[2][\py@classbadkey]{\item[\bfcode{#2}]}
449\newenvironment{memberdescni}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000450 \begin{fulllineitems}
451 \memberlineni{#2}
452}{\end{fulllineitems}}
453
454% For exceptions: --------------------------------------------------------
455% \begin{excdesc}{name}
456% -- need support for constructor; maybe use optional parameter?
457\newenvironment{excdesc}[1]{
458 \begin{fulllineitems}
459 \item[\bfcode{#1}\ttindex{#1}]
460}{\end{fulllineitems}}
461
462% Module data or constants: ----------------------------------------------
463% \begin{datadesc}{name}
Fred Drake6659c301998-03-03 22:02:19 +0000464\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drake6cb71491998-03-27 05:22:53 +0000465\newenvironment{datadesc}[1]{
466 \begin{fulllineitems}
467 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000468}{\end{fulllineitems}}
469
470% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000471\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
472\newenvironment{datadescni}[1]{
473 \begin{fulllineitems}
474 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000475}{\end{fulllineitems}}
476
Fred Drake6cb71491998-03-27 05:22:53 +0000477% bytecode instruction ---------------------------------------------------
478% \begin{opcodedesc}{name}{var}
479% -- {var} may be {}
480\newenvironment{opcodedesc}[2]{
481 \begin{fulllineitems}
482 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000483}{\end{fulllineitems}}
484
485
Fred Drake24340ea1998-04-28 18:30:34 +0000486\newcommand{\nodename}[1]{\label{#1}}
Fred Drake55730311998-03-25 15:41:23 +0000487
Fred Drake6659c301998-03-03 22:02:19 +0000488% For these commands, use \command{} to get the typography right, not
489% {\command}. This works better with the texinfo translation.
490\newcommand{\ABC}{{\sc abc}}
491\newcommand{\UNIX}{{\sc Unix}}
492\newcommand{\POSIX}{POSIX}
493\newcommand{\ASCII}{{\sc ascii}}
494\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
495\newcommand{\C}{C}
496\newcommand{\EOF}{{\sc eof}}
Fred Drake24340ea1998-04-28 18:30:34 +0000497\newcommand{\NULL}{\constant{NULL}}
Fred Drake6659c301998-03-03 22:02:19 +0000498
Fred Drake53714971998-04-02 22:33:16 +0000499% Also for consistency: spell Python "Python", not "python"!
500
Fred Drake6659c301998-03-03 22:02:19 +0000501% code is the most difficult one...
Fred Drake1c8d0e01998-03-07 05:29:15 +0000502\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 Drake24340ea1998-04-28 18:30:34 +0000503\texttt{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000504
505\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Fred Drake24340ea1998-04-28 18:30:34 +0000506\newcommand{\kbd}[1]{\tt #1}
507\newcommand{\samp}[1]{`\code{#1}'}
Fred Drake6659c301998-03-03 22:02:19 +0000508% This weird definition of \var{} allows it to always appear in roman
509% italics, and won't get funky in code fragments when we play around
510% with fonts.
Fred Drake24340ea1998-04-28 18:30:34 +0000511\newcommand{\var}[1]{\normalsize\textrm{\textit{#1\/}}}
512\renewcommand{\emph}[1]{{\em #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000513\newcommand{\dfn}[1]{\emph{#1}}
514\newcommand{\strong}[1]{{\bf #1}}
515% let's experiment with a new font:
Fred Drake0ee9f721998-03-12 06:41:40 +0000516\newcommand{\file}[1]{`{\small\textsf{#1}}'}
Fred Drake6659c301998-03-03 22:02:19 +0000517
518% Use this def/redef approach for \url{} since hyperref defined this already,
519% but only if we actually used hyperref:
Fred Drake6cb71491998-03-27 05:22:53 +0000520\@ifundefined{pdfannotlink}{
Fred Drakea2c2a831998-04-15 17:50:01 +0000521 \newcommand{\py@url}[1]{\mbox{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000522}{
Fred Drakea2c2a831998-04-15 17:50:01 +0000523 \newcommand{\py@url}[1]{{%
Fred Drake6659c301998-03-03 22:02:19 +0000524 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000525 \py@LinkColor% color of the link text
526 \mbox{\small\textsf{#1}}%
527 \py@NormalColor% Turn it back off; these are declarative
Fred Drake6659c301998-03-03 22:02:19 +0000528 \pdfendlink}% and don't appear bound to the current
529 }% formatting "box".
530}
Fred Drakea2c2a831998-04-15 17:50:01 +0000531\let\url=\py@url
Fred Drake0ee9f721998-03-12 06:41:40 +0000532\newcommand{\email}[1]{{\small\textsf{#1}}}
Fred Drake454a4fb1998-04-01 22:20:14 +0000533\newcommand{\newsgroup}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000534
Fred Drake300775d1998-04-17 02:17:00 +0000535\newcommand{\py@varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Fred Drake24340ea1998-04-28 18:30:34 +0000536% let's see if this breaks anything now; we may be able to simplify...
537\renewcommand{\py@varvars}[1]{\var{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000538
Fred Drake24340ea1998-04-28 18:30:34 +0000539% I'd really like to get rid of this!
Fred Drake6659c301998-03-03 22:02:19 +0000540\newif\iftexi\texifalse
Fred Drake6659c301998-03-03 22:02:19 +0000541
542% These should be used for all references to identifiers which are
543% used to refer to instances of specific language constructs. See the
544% names for specific semantic assignments.
545%
546% For now, don't do anything really fancy with them; just use them as
547% logical markup. This might change in the future.
548%
Fred Drake24340ea1998-04-28 18:30:34 +0000549\newcommand{\module}[1]{\texttt{#1}}
550\newcommand{\keyword}[1]{\texttt{#1}}
551\newcommand{\exception}[1]{\texttt{#1}}
552\newcommand{\class}[1]{\texttt{#1}}
553\newcommand{\function}[1]{\texttt{#1}}
554\newcommand{\member}[1]{\texttt{#1}}
555\newcommand{\method}[1]{\texttt{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000556
Fred Drake53714971998-04-02 22:33:16 +0000557\newcommand{\pytype}[1]{#1} % built-in Python type
558
Fred Drake24340ea1998-04-28 18:30:34 +0000559\newcommand{\cfunction}[1]{\texttt{#1}}
560\newcommand{\ctype}[1]{\texttt{#1}} % C struct or typedef name
561\newcommand{\cdata}[1]{\texttt{#1}} % C variable, typically global
Fred Drake6659c301998-03-03 22:02:19 +0000562
Fred Drake0ee9f721998-03-12 06:41:40 +0000563\newcommand{\mimetype}[1]{{\small\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000564% The \! is a "negative thin space" in math mode.
565\newcommand{\regexp}[1]{%
566 {\tiny$^{^\lceil}\!\!$%
567 {\normalsize\code{#1}}%
Fred Drake47cfd031998-04-03 21:22:31 +0000568 $\!\rfloor\!$%
Fred Drake94fac131998-03-12 19:37:03 +0000569 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000570\newcommand{\envvar}[1]{%
Fred Drake94fac131998-03-12 19:37:03 +0000571 \$#1% $ <-- bow to font-lock 3 times!
572 \index{#1@{\$#1}}% $
573 \index{environment variables!{\$#1}}% $
Fred Drake0ee9f721998-03-12 06:41:40 +0000574}
Fred Drake24340ea1998-04-28 18:30:34 +0000575\newcommand{\makevar}[1]{#1} % variable in a Makefile
576\newcommand{\character}[1]{\samp{#1}}
Fred Drake0ee9f721998-03-12 06:41:40 +0000577
Fred Drake6659c301998-03-03 22:02:19 +0000578% constants defined in Python modules or C headers, not language constants:
Fred Drake24340ea1998-04-28 18:30:34 +0000579\newcommand{\constant}[1]{\code{#1}} % manifest constant, not syntactic
Fred Drake6659c301998-03-03 22:02:19 +0000580
581\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
582\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
583\newcommand{\program}[1]{\strong{#1}}
584
585
586% Deprecation stuff.
587% Should be extended to allow an index / list of deprecated stuff. But
588% there's a lot of stuff that needs to be done to make that automatable.
589%
590% First parameter is the release number that deprecates the feature, the
591% second is the action the should be taken by users of the feature.
592%
593% Example:
594%
Fred Drake24340ea1998-04-28 18:30:34 +0000595% \deprecated{1.5.1}{Use \method{frobnicate()} instead.}
Fred Drake6659c301998-03-03 22:02:19 +0000596%
597\newcommand{\deprecated}[2]{%
598 \strong{Deprecated since release #1.} #2\par}
599
600
601\newenvironment{tableii}[4]{%
602 \begin{center}%
603 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakeee601911998-04-11 20:53:03 +0000604 \begin{tabular}{#1}\strong{#3}&\strong{#4} \\ \hline%
Fred Drake6659c301998-03-03 22:02:19 +0000605}{%
Fred Drake6659c301998-03-03 22:02:19 +0000606 \end{tabular}%
607 \end{center}%
608}
609
610\newenvironment{tableiii}[5]{%
611 \begin{center}%
612 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
Fred Drakeee601911998-04-11 20:53:03 +0000613 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\ \hline%
Fred Drake6659c301998-03-03 22:02:19 +0000614}{%
Fred Drake6659c301998-03-03 22:02:19 +0000615 \end{tabular}%
616 \end{center}%
617}
618
619\newcommand{\itemnewline}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000620 \@tempdima\linewidth%
621 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
Fred Drake6659c301998-03-03 22:02:19 +0000622}
623
Fred Drake24340ea1998-04-28 18:30:34 +0000624% Cross-referencing (AMK, new impl. FLD)
Fred Drake6659c301998-03-03 22:02:19 +0000625% Sample usage:
626% \begin{seealso}
627% \seemodule{rand}{Uniform random number generator}; % Module xref
628% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +0000629%
630% % A funky case: module name contains '_'; have to supply an optional key
631% \seemodule[copyreg]{copy_reg}{pickle interface constructor registration}
632%
Fred Drake6659c301998-03-03 22:02:19 +0000633% \end{seealso}
634
Fred Drake24340ea1998-04-28 18:30:34 +0000635\newcommand{\py@modulebadkey}{{--just-some-junk--}}
Fred Drakeebcb6581998-03-06 21:25:17 +0000636
Fred Drake1c8d0e01998-03-07 05:29:15 +0000637\@ifundefined{pdfannotlink}{%
Fred Drake24340ea1998-04-28 18:30:34 +0000638 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
639 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
640 \ref{module-\py@modulekey}:\quad %
Fred Drakeebcb6581998-03-06 21:25:17 +0000641 Module \module{#2}%
642 \quad (#3)%
643 }
Fred Drake24340ea1998-04-28 18:30:34 +0000644}{\newcommand{\py@seemodule}[3][\py@modulebadkey]{%
645 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
646 \ref{module-\py@modulekey}:\quad %
647 {\pdfannotlink attr{/Border [0 0 0]} goto name{label-module-\py@modulekey}%
648 \py@LinkColor Module \module{#2} \py@NormalColor%
Fred Drakeebcb6581998-03-06 21:25:17 +0000649 \pdfendlink%
650 }%
651 \quad (#3)%
652 }
653}
Fred Drake6659c301998-03-03 22:02:19 +0000654\newenvironment{seealso}[0]{
655 \strong{See Also:}\par
Fred Drake6659c301998-03-03 22:02:19 +0000656 \def\seetext##1{\par{##1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000657 \let\seemodule=\py@seemodule
Fred Drake6659c301998-03-03 22:02:19 +0000658}{\par}
659
660
Fred Drake6659c301998-03-03 22:02:19 +0000661% Allow the release number to be specified independently of the
662% \date{}. This allows the date to reflect the document's date and
663% release to specify the Python release that is documented.
664%
Fred Drake24340ea1998-04-28 18:30:34 +0000665\newcommand{\py@release}{}
Fred Drake6659c301998-03-03 22:02:19 +0000666\newcommand{\version}{}
667\newcommand{\releasename}{Release}
668\newcommand{\release}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +0000669 \renewcommand{\py@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +0000670 \renewcommand{\version}{#1}}
671
672% Allow specification of the author's address separately from the
673% author's name. This can be used to format them differently, which
674% is a good thing.
675%
Fred Drake24340ea1998-04-28 18:30:34 +0000676\newcommand{\py@authoraddress}{}
677\newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000678
Fred Drake6659c301998-03-03 22:02:19 +0000679% This sets up the fancy chapter headings that make the documents look
680% at least a little better than the usual LaTeX output.
681%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000682\@ifundefined{ChTitleVar}{}{
Fred Drake24340ea1998-04-28 18:30:34 +0000683 \ChNameVar{\raggedleft\normalsize\py@HeaderFamily}
684 \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily}
685 \ChTitleVar{\raggedleft \rm\Huge\py@HeaderFamily}
Fred Drake6659c301998-03-03 22:02:19 +0000686 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000687 \def\@makechapterhead#1{%
688 {\parindent \z@ \raggedright \normalfont
689 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +0000690 \DOCH
691 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +0000692 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +0000693 \DOTI{#1}
694 }
695 }
Fred Drake6659c301998-03-03 22:02:19 +0000696}
697
698% Tell TeX about pathological hyphenation cases:
699\hyphenation{Base-HTTP-Re-quest-Hand-ler}