blob: 1f480a9e150bd037e5e8318c0da38d7a7f6a3895 [file] [log] [blame]
Fred Drake6659c301998-03-03 22:02:19 +00001%
Walter Dörwaldf0dfc7a2003-10-20 14:01:56 +00002% python.sty for the Python docummentation [works only 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 Drakeda72b932000-09-21 15:58:02 +00009\RequirePackage{longtable}
10
Fred Drake9466b9a1999-03-18 16:18:27 +000011% Uncomment these two lines to ignore the paper size and make the page
12% size more like a typical published manual.
13%\renewcommand{\paperheight}{9in}
14%\renewcommand{\paperwidth}{8.5in} % typical squarish manual
15%\renewcommand{\paperwidth}{7in} % O'Reilly ``Programmming Python''
16
Fred Drake454a4fb1998-04-01 22:20:14 +000017% These packages can be used to add marginal annotations which indicate
18% index entries and labels; useful for reviewing this messy documentation!
19%
20%\RequirePackage{showkeys}
21%\RequirePackage{showidx}
22
Fred Drakecdd6e4d2004-12-01 06:30:31 +000023% If we ever want to indent paragraphs, this needs to be changed.
24% This is used inside the macros defined here instead of coding
25% \noindent directly.
26\let\py@parindent=\noindent
27
Fred Drakec0b2e451998-03-25 14:53:43 +000028% for PDF output, use maximal compression & a lot of other stuff
29% (test for PDF recommended by Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov>)
30%
Fred Drake24340ea1998-04-28 18:30:34 +000031\newif\ifpy@doing@page@targets
32\py@doing@page@targetsfalse
Fred Drake6cb71491998-03-27 05:22:53 +000033
Fred Drakee59feb52001-10-29 21:02:28 +000034\newif\ifpdf\pdffalse
Fred Drakec0b2e451998-03-25 14:53:43 +000035\ifx\pdfoutput\undefined\else\ifcase\pdfoutput
Fred Drakec0b2e451998-03-25 14:53:43 +000036\else
Fred Drakee59feb52001-10-29 21:02:28 +000037 \pdftrue
Fred Drake6659c301998-03-03 22:02:19 +000038 \input{pdfcolor}
Fred Drake24340ea1998-04-28 18:30:34 +000039 \let\py@LinkColor=\NavyBlue
40 \let\py@NormalColor=\Black
Fred Drake6659c301998-03-03 22:02:19 +000041 \pdfcompresslevel=9
Fred Drakeba1700c1998-05-11 20:42:54 +000042 \pdfpagewidth=\paperwidth % page width of PDF output
43 \pdfpageheight=\paperheight % page height of PDF output
Fred Drakeebcb6581998-03-06 21:25:17 +000044 %
Fred Drakea2c2a831998-04-15 17:50:01 +000045 % Pad the number with '0' to 3 digits wide so no page name is a prefix
46 % of any other.
47 %
Fred Drakea488f301998-07-23 17:50:45 +000048 \newcommand{\py@targetno}[1]{\ifnum#1<100 0\fi\ifnum#1<10 0\fi#1}
49 \newcommand{\py@pageno}{\py@targetno\thepage}
Fred Drakea2c2a831998-04-15 17:50:01 +000050 %
Fred Drakeebcb6581998-03-06 21:25:17 +000051 % This definition allows the entries in the page-view of the ToC to be
52 % active links. Some work, some don't.
53 %
Fred Drake24340ea1998-04-28 18:30:34 +000054 \let\py@OldContentsline=\contentsline
Fred Drakeaa2aea01999-01-27 17:37:36 +000055 %
Fred Drake0e4cd7f2002-03-16 04:52:36 +000056 % Backward compatibility hack: pdfTeX 0.13 defined \pdfannotlink,
57 % but it changed to \pdfstartlink in 0.14. This let's us use either
58 % version and still get useful behavior.
59 %
60 \@ifundefined{pdfstartlink}{
61 \let\pdfstartlink=\pdfannotlink
62 }{}
63 %
Fred Drakecdd6e4d2004-12-01 06:30:31 +000064 % The \py@parindent here is a hack -- we're forcing pdfTeX into
65 % horizontal mode since \pdfstartlink requires that.
66 \def\py@pdfstartlink{%
67 \ifvmode\py@parindent\fi%
68 \pdfstartlink%
69 }
70 %
Fred Drakeaa2aea01999-01-27 17:37:36 +000071 % Macro that takes two args: the name to link to and the content of
72 % the link. This takes care of the PDF magic, getting the colors
73 % the same for each link, and avoids having lots of garbage all over
74 % this style file.
75 \newcommand{\py@linkToName}[2]{%
Fred Drakecdd6e4d2004-12-01 06:30:31 +000076 \py@pdfstartlink attr{/Border [0 0 0]} goto name{#1}%
Fred Drakeaa2aea01999-01-27 17:37:36 +000077 \py@LinkColor#2\py@NormalColor%
78 \pdfendlink%
Fred Drake53815882002-03-15 23:21:37 +000079 }
Fred Drakea2c2a831998-04-15 17:50:01 +000080 % Compute the padded page number separately since we end up with a pair of
81 % \relax tokens; this gets the right string computed and works.
Fred Drake6659c301998-03-03 22:02:19 +000082 \renewcommand{\contentsline}[3]{%
Fred Drakea2c2a831998-04-15 17:50:01 +000083 \def\my@pageno{\py@targetno{#3}}%
Fred Drakeaa2aea01999-01-27 17:37:36 +000084 \py@OldContentsline{#1}{\py@linkToName{page\my@pageno}{#2}}{#3}%
Fred Drake6659c301998-03-03 22:02:19 +000085 }
Fred Drakeebcb6581998-03-06 21:25:17 +000086 \AtEndDocument{
Neal Norwitz5268c392004-08-21 15:13:52 +000087 \def\_{\string_}
Fred Drakec0b2e451998-03-25 14:53:43 +000088 \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
Fred Drakeebcb6581998-03-06 21:25:17 +000089 }
Fred Drakea2c2a831998-04-15 17:50:01 +000090 \newcommand{\py@target}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000091 \ifpy@doing@page@targets%
Fred Drake9b8afde1999-03-24 14:16:17 +000092 {\pdfdest name{#1} xyz}%
Fred Drakea2c2a831998-04-15 17:50:01 +000093 \fi%
94 }
Fred Drake24340ea1998-04-28 18:30:34 +000095 \let\py@OldLabel=\label
Fred Drake6659c301998-03-03 22:02:19 +000096 \renewcommand{\label}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000097 \py@OldLabel{#1}%
Fred Drakea2c2a831998-04-15 17:50:01 +000098 \py@target{label-#1}%
Fred Drake6659c301998-03-03 22:02:19 +000099 }
Fred Drakeba1700c1998-05-11 20:42:54 +0000100 % This stuff adds a page# destination to every PDF page, where # is three
101 % digits wide, padded with leading zeros. This doesn't really help with
102 % the frontmatter, but does fine with the body.
Fred Drake6659c301998-03-03 22:02:19 +0000103 %
104 % This is *heavily* based on the hyperref package.
105 %
Fred Drake1c8d0e01998-03-07 05:29:15 +0000106 \def\@begindvi{%
107 \unvbox \@begindvibox
108 \@hyperfixhead
Fred Drake6659c301998-03-03 22:02:19 +0000109 }
Fred Drake1c8d0e01998-03-07 05:29:15 +0000110 \def\@hyperfixhead{%
111 \let\H@old@thehead\@thehead
Fred Drakea2c2a831998-04-15 17:50:01 +0000112 \global\def\@foo{\py@target{page\py@pageno}}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000113 \expandafter\ifx\expandafter\@empty\H@old@thehead
114 \def\H@old@thehead{\hfil}\fi
115 \def\@thehead{\@foo\relax\H@old@thehead}%
Fred Drake6659c301998-03-03 22:02:19 +0000116 }
Fred Drakec0b2e451998-03-25 14:53:43 +0000117\fi\fi
Fred Drake6659c301998-03-03 22:02:19 +0000118
119% Increase printable page size (copied from fullpage.sty)
120\topmargin 0pt
121\advance \topmargin by -\headheight
122\advance \topmargin by -\headsep
123
124% attempt to work a little better for A4 users
Fred Drake9466b9a1999-03-18 16:18:27 +0000125\textheight \paperheight
126\advance\textheight by -2in
Fred Drake6659c301998-03-03 22:02:19 +0000127
128\oddsidemargin 0pt
Fred Drake9466b9a1999-03-18 16:18:27 +0000129\evensidemargin 0pt
130%\evensidemargin -.25in % for ``manual size'' documents
Fred Drake6659c301998-03-03 22:02:19 +0000131\marginparwidth 0.5in
132
Fred Drake9466b9a1999-03-18 16:18:27 +0000133\textwidth \paperwidth
134\advance\textwidth by -2in
Fred Drake6659c301998-03-03 22:02:19 +0000135
136
137% Style parameters and macros used by most documents here
138\raggedbottom
139\sloppy
140\parindent = 0mm
Fred Drake24340ea1998-04-28 18:30:34 +0000141\parskip = 2mm
Fred Drakeab357ec2001-03-02 18:57:05 +0000142\hbadness = 5000 % don't print trivial gripes
Fred Drake6659c301998-03-03 22:02:19 +0000143
Fred Drakeab357ec2001-03-02 18:57:05 +0000144\pagestyle{empty} % start this way; change for
145\pagenumbering{roman} % ToC & chapters
Fred Drake6659c301998-03-03 22:02:19 +0000146
147% Use this to set the font family for headers and other decor:
Fred Drake24340ea1998-04-28 18:30:34 +0000148\newcommand{\py@HeaderFamily}{\sffamily}
Fred Drake6659c301998-03-03 22:02:19 +0000149
Fred Drakeff031cf2002-10-31 21:04:34 +0000150% Set up abstract ways to get the normal and smaller font sizes that
151% work even in footnote context.
152\newif\ifpy@infootnote \py@infootnotefalse
Fred Drake2eba52f2002-11-04 16:29:31 +0000153\let\py@oldmakefntext\@makefntext
154\def\@makefntext#1{%
Fred Drakeff031cf2002-10-31 21:04:34 +0000155 \bgroup%
156 \py@infootnotetrue
Fred Drake2eba52f2002-11-04 16:29:31 +0000157 \py@oldmakefntext{#1}%
Fred Drakeff031cf2002-10-31 21:04:34 +0000158 \egroup%
159}
160\def\py@defaultsize{%
161 \ifpy@infootnote\footnotesize\else\normalsize\fi%
162}
163\def\py@smallsize{%
164 \ifpy@infootnote\scriptsize\else\small\fi%
165}
166
Fred Drake6659c301998-03-03 22:02:19 +0000167% Redefine the 'normal' header/footer style when using "fancyhdr" package:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000168\@ifundefined{fancyhf}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000169 % Use \pagestyle{normal} as the primary pagestyle for text.
170 \fancypagestyle{normal}{
171 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000172 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
173 \fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
174 \fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
Fred Drake6659c301998-03-03 22:02:19 +0000175 \renewcommand{\headrulewidth}{0pt}
176 \renewcommand{\footrulewidth}{0.4pt}
177 }
178 % Update the plain style so we get the page number & footer line,
179 % but not a chapter or section title. This is to keep the first
180 % page of a chapter and the blank page between chapters `clean.'
181 \fancypagestyle{plain}{
182 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000183 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
Fred Drake6659c301998-03-03 22:02:19 +0000184 \renewcommand{\headrulewidth}{0pt}
185 \renewcommand{\footrulewidth}{0.4pt}
186 }
187 % Redefine \cleardoublepage so that the blank page between chapters
188 % gets the plain style and not the fancy style. This is described
189 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000190 \@ifundefined{chapter}{}{
Fred Drake28f13911998-03-04 21:47:59 +0000191 \renewcommand{\cleardoublepage}{
Fred Drake1c8d0e01998-03-07 05:29:15 +0000192 \clearpage\if@openright \ifodd\c@page\else
Fred Drake28f13911998-03-04 21:47:59 +0000193 \hbox{}
194 \thispagestyle{plain}
195 \newpage
Fred Drake1c8d0e01998-03-07 05:29:15 +0000196 \if@twocolumn\hbox{}\newpage\fi\fi\fi
Fred Drake28f13911998-03-04 21:47:59 +0000197 }
198 }
Fred Drake6659c301998-03-03 22:02:19 +0000199}
200
Fred Drake6659c301998-03-03 22:02:19 +0000201% This sets up the {verbatim} environment to be indented and a minipage,
202% and to have all the other mostly nice properties that we want for
203% code samples.
204
Fred Drake9466b9a1999-03-18 16:18:27 +0000205\let\py@OldVerbatim=\verbatim
206\let\py@OldEndVerbatim=\endverbatim
207\RequirePackage{verbatim}
Fred Drake00f712e2002-03-28 22:28:43 +0000208\let\py@OldVerbatimInput=\verbatiminput
Fred Drake9466b9a1999-03-18 16:18:27 +0000209
Fred Drake6659c301998-03-03 22:02:19 +0000210% Variable used by begin code command
Fred Drake24340ea1998-04-28 18:30:34 +0000211\newlength{\py@codewidth}
Fred Drake6659c301998-03-03 22:02:19 +0000212
Fred Drake6659c301998-03-03 22:02:19 +0000213\renewcommand{\verbatim}{%
Fred Drake9466b9a1999-03-18 16:18:27 +0000214 \setlength{\parindent}{1cm}%
Fred Drake6659c301998-03-03 22:02:19 +0000215 % Calculate the text width for the minipage:
Fred Drake24340ea1998-04-28 18:30:34 +0000216 \setlength{\py@codewidth}{\linewidth}%
217 \addtolength{\py@codewidth}{-\parindent}%
Fred Drake6659c301998-03-03 22:02:19 +0000218 %
Fred Drake9466b9a1999-03-18 16:18:27 +0000219 \par\indent%
Fred Drake24340ea1998-04-28 18:30:34 +0000220 \begin{minipage}[t]{\py@codewidth}%
Fred Drake6659c301998-03-03 22:02:19 +0000221 \small%
Fred Drake24340ea1998-04-28 18:30:34 +0000222 \py@OldVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000223}
224\renewcommand{\endverbatim}{%
Fred Drake24340ea1998-04-28 18:30:34 +0000225 \py@OldEndVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000226 \end{minipage}%
Fred Drake6659c301998-03-03 22:02:19 +0000227}
Fred Drake00f712e2002-03-28 22:28:43 +0000228\renewcommand{\verbatiminput}[1]{%
229 {\setlength{\parindent}{1cm}%
230 % Calculate the text width for the minipage:
231 \setlength{\py@codewidth}{\linewidth}%
232 \addtolength{\py@codewidth}{-\parindent}%
233 %
234 \small%
235 \begin{list}{}{\setlength{\leftmargin}{1cm}}
236 \item%
237 \py@OldVerbatimInput{#1}%
238 \end{list}
239 }%
240}
Fred Drake6659c301998-03-03 22:02:19 +0000241
Fred Drakeb5309a92001-04-10 15:53:06 +0000242% This does a similar thing for the {alltt} environment:
243\RequirePackage{alltt}
244\let\py@OldAllTT=\alltt
245\let\py@OldEndAllTT=\endalltt
246
247\renewcommand{\alltt}{%
248 \setlength{\parindent}{1cm}%
249 % Calculate the text width for the minipage:
250 \setlength{\py@codewidth}{\linewidth}%
251 \addtolength{\py@codewidth}{-\parindent}%
Fred Drake29f59332004-02-10 18:30:22 +0000252 \let\e=\textbackslash%
Fred Drakeb5309a92001-04-10 15:53:06 +0000253 %
254 \par\indent%
255 \begin{minipage}[t]{\py@codewidth}%
256 \small%
257 \py@OldAllTT%
258}
259\renewcommand{\endalltt}{%
260 \py@OldEndAllTT%
261 \end{minipage}%
262}
263
Fred Drake6cb71491998-03-27 05:22:53 +0000264
Fred Drakea488f301998-07-23 17:50:45 +0000265\newcommand{\py@modulebadkey}{{--just-some-junk--}}
Fred Drake6659c301998-03-03 22:02:19 +0000266
Fred Drake6659c301998-03-03 22:02:19 +0000267
268%% Lots of index-entry generation support.
269
270% Command to wrap around stuff that refers to function / module /
271% attribute names in the index. Default behavior: like \code{}. To
272% just keep the index entries in the roman font, uncomment the second
Fred Drakea488f301998-07-23 17:50:45 +0000273% definition; it matches O'Reilly style more.
Fred Drake6659c301998-03-03 22:02:19 +0000274%
Fred Drake24340ea1998-04-28 18:30:34 +0000275\newcommand{\py@idxcode}[1]{\texttt{#1}}
276%\renewcommand{\py@idxcode}[1]{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000277
278% Command to generate two index entries (using subentries)
279\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
280
281% And three entries (using only one level of subentries)
282\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
283
284% And four (again, using only one level of subentries)
285\newcommand{\indexiv}[4]{
286\index{#1!#2 #3 #4}
287\index{#2!#3 #4, #1}
288\index{#3!#4, #1 #2}
289\index{#4!#1 #2 #3}
290}
291
292% Command to generate a reference to a function, statement, keyword,
293% operator.
Fred Drake0cabff91998-05-06 19:36:01 +0000294\newcommand{\kwindex}[1]{\indexii{keyword}{#1@{\py@idxcode{#1}}}}
Fred Drake24340ea1998-04-28 18:30:34 +0000295\newcommand{\stindex}[1]{\indexii{statement}{#1@{\py@idxcode{#1}}}}
296\newcommand{\opindex}[1]{\indexii{operator}{#1@{\py@idxcode{#1}}}}
297\newcommand{\exindex}[1]{\indexii{exception}{#1@{\py@idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000298\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakea33c5662000-10-29 05:19:16 +0000299\newcommand{\bifuncindex}[1]{%
300 \index{#1@{\py@idxcode{#1()}} (built-in function)}}
Fred Drake6659c301998-03-03 22:02:19 +0000301
302% Add an index entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000303\newcommand{\py@refmodule}[2]{\index{#1@{\py@idxcode{#1}} (#2module)}}
304\newcommand{\refmodindex}[1]{\py@refmodule{#1}{}}
305\newcommand{\refbimodindex}[1]{\py@refmodule{#1}{built-in }}
306\newcommand{\refexmodindex}[1]{\py@refmodule{#1}{extension }}
307\newcommand{\refstmodindex}[1]{\py@refmodule{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000308
Fred Drakeda943741999-01-13 17:09:06 +0000309% Refer to a module's documentation using a hyperlink of the module's
310% name, at least if we're building PDF:
Fred Drakee59feb52001-10-29 21:02:28 +0000311\ifpdf
Fred Drakeaa2aea01999-01-27 17:37:36 +0000312 \newcommand{\refmodule}[2][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000313 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drakeaa2aea01999-01-27 17:37:36 +0000314 \py@linkToName{label-module-\py@modulekey}{\module{#2}}%
Fred Drakeda943741999-01-13 17:09:06 +0000315 }
Fred Drakee59feb52001-10-29 21:02:28 +0000316\else
317 \newcommand{\refmodule}[2][\py@modulebadkey]{\module{#2}}
318\fi
Fred Drakeda943741999-01-13 17:09:06 +0000319
Fred Drake6659c301998-03-03 22:02:19 +0000320% support for the module index
Fred Drake24340ea1998-04-28 18:30:34 +0000321\newif\ifpy@UseModuleIndex
322\py@UseModuleIndexfalse
Fred Drakeb390daf1998-03-09 16:35:36 +0000323
Fred Drakeb390daf1998-03-09 16:35:36 +0000324\newcommand{\makemodindex}{
325 \newwrite\modindexfile
326 \openout\modindexfile=mod\jobname.idx
Fred Drake24340ea1998-04-28 18:30:34 +0000327 \py@UseModuleIndextrue
Fred Drakeb390daf1998-03-09 16:35:36 +0000328}
329
Fred Drake0ee9f721998-03-12 06:41:40 +0000330% Add the defining entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000331\newcommand{\py@modindex}[2]{%
Fred Drakea488f301998-07-23 17:50:45 +0000332 \renewcommand{\py@thismodule}{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000333 \setindexsubitem{(in module #1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000334 \index{#1@{\py@idxcode{#1}} (#2module)|textbf}%
335 \ifpy@UseModuleIndex%
Fred Drake0c275fa1999-03-02 16:17:44 +0000336 \@ifundefined{py@modplat@\py@thismodulekey}{
337 \write\modindexfile{\protect\indexentry{#1@{\texttt{#1}}}{\thepage}}%
338 }{\write\modindexfile{\protect\indexentry{#1@{\texttt{#1} %
Fred Drake9466b9a1999-03-18 16:18:27 +0000339 \emph{(\py@platformof[\py@thismodulekey]{})}}}{\thepage}}%
Fred Drake0c275fa1999-03-02 16:17:44 +0000340 }
Fred Drake0ee9f721998-03-12 06:41:40 +0000341 \fi%
342}
343
Fred Drake9466b9a1999-03-18 16:18:27 +0000344% *** XXX *** THE NEXT FOUR MACROS ARE NOW OBSOLETE !!! ***
345
Fred Drake6659c301998-03-03 22:02:19 +0000346% built-in & Python modules in the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000347\newcommand{\bimodindex}[1]{\py@modindex{#1}{built-in }%
348 \typeout{*** MACRO bimodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
349\newcommand{\stmodindex}[1]{\py@modindex{#1}{standard }%
350 \typeout{*** MACRO stmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000351
352% Python & extension modules outside the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000353\newcommand{\modindex}[1]{\py@modindex{#1}{}%
354 \typeout{*** MACRO modindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
355\newcommand{\exmodindex}[1]{\py@modindex{#1}{extension }%
356 \typeout{*** MACRO exmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000357
358% Additional string for an index entry
Fred Drakeba828782000-04-03 04:19:14 +0000359\newif\ifpy@usingsubitem\py@usingsubitemfalse
360\newcommand{\py@indexsubitem}{}
361\newcommand{\setindexsubitem}[1]{\renewcommand{\py@indexsubitem}{ #1}%
362 \py@usingsubitemtrue}
363\newcommand{\ttindex}[1]{%
364 \ifpy@usingsubitem
365 \index{#1@{\py@idxcode{#1}}\py@indexsubitem}%
366 \else%
367 \index{#1@{\py@idxcode{#1}}}%
368 \fi%
369}
Fred Drake0ee9f721998-03-12 06:41:40 +0000370\newcommand{\withsubitem}[2]{%
371 \begingroup%
Fred Drakeec77e652000-10-30 06:22:22 +0000372 \def\ttindex##1{\index{##1@{\py@idxcode{##1}} #1}}%
373 #2%
Fred Drake0ee9f721998-03-12 06:41:40 +0000374 \endgroup%
375}
Fred Drake6659c301998-03-03 22:02:19 +0000376
Fred Drake53714971998-04-02 22:33:16 +0000377
Fred Drakea488f301998-07-23 17:50:45 +0000378% Module synopsis processing -----------------------------------------------
379%
Fred Drake0c275fa1999-03-02 16:17:44 +0000380\newcommand{\py@thisclass}{}
381\newcommand{\py@thismodule}{}
382\newcommand{\py@thismodulekey}{}
383\newcommand{\py@thismoduletype}{}
384
Fred Drake9466b9a1999-03-18 16:18:27 +0000385\newcommand{\py@standardIndexModule}[1]{\py@modindex{#1}{standard }}
386\newcommand{\py@builtinIndexModule}[1]{\py@modindex{#1}{built-in }}
387\newcommand{\py@extensionIndexModule}[1]{\py@modindex{#1}{extension }}
388\newcommand{\py@IndexModule}[1]{\py@modindex{#1}{}}
Fred Drakea488f301998-07-23 17:50:45 +0000389
Fred Drake0c275fa1999-03-02 16:17:44 +0000390\newif\ifpy@HaveModSynopsis \py@HaveModSynopsisfalse
391\newif\ifpy@ModSynopsisFileIsOpen \py@ModSynopsisFileIsOpenfalse
392\newif\ifpy@HaveModPlatform \py@HaveModPlatformfalse
Fred Drakea488f301998-07-23 17:50:45 +0000393
394% \declaremodule[key]{type}{name}
395\newcommand{\declaremodule}[3][\py@modulebadkey]{
396 \py@openModSynopsisFile
397 \renewcommand{\py@thismoduletype}{#2}
Fred Drakea488f301998-07-23 17:50:45 +0000398 \ifx\py@modulebadkey#1
399 \renewcommand{\py@thismodulekey}{#3}
400 \else
401 \renewcommand{\py@thismodulekey}{#1}
402 \fi
Fred Drake5bc8d991999-05-17 14:47:10 +0000403 \@ifundefined{py@#2IndexModule}{%
404 \typeout{*** MACRO declaremodule called with unknown module type: `#2'}
Fred Drake66823021999-05-17 14:57:26 +0000405 \py@IndexModule{#3}%
Fred Drake5bc8d991999-05-17 14:47:10 +0000406 }{%
407 \csname py@#2IndexModule\endcsname{#3}%
408 }
Fred Drakea488f301998-07-23 17:50:45 +0000409 \label{module-\py@thismodulekey}
Fred Drakea488f301998-07-23 17:50:45 +0000410}
Fred Drake0c275fa1999-03-02 16:17:44 +0000411\newif\ifpy@ModPlatformFileIsOpen \py@ModPlatformFileIsOpenfalse
412\newcommand{\py@ModPlatformFilename}{\jobname.pla}
413\newcommand{\platform}[1]{
414 \ifpy@ModPlatformFileIsOpen\else
415 \newwrite\py@ModPlatformFile
416 \openout\py@ModPlatformFile=\py@ModPlatformFilename
417 \py@ModPlatformFileIsOpentrue
418 \fi
Fred Drake0c275fa1999-03-02 16:17:44 +0000419}
420\InputIfFileExists{\jobname.pla}{}{}
Fred Drake9466b9a1999-03-18 16:18:27 +0000421\newcommand{\py@platformof}[2][\py@modulebadkey]{%
Fred Drake0c275fa1999-03-02 16:17:44 +0000422 \ifx\py@modulebadkey#1 \def\py@key{#2}%
423 \else \def\py@key{#1}%
424 \fi%
425 \csname py@modplat@\py@key\endcsname%
426}
427\newcommand{\ignorePlatformAnnotation}[1]{}
Fred Drakea488f301998-07-23 17:50:45 +0000428
Fred Drakeb75c6151998-08-10 18:41:43 +0000429% \moduleauthor{name}{email}
430\newcommand{\moduleauthor}[2]{}
431
432% \sectionauthor{name}{email}
433\newcommand{\sectionauthor}[2]{}
434
Fred Drakea488f301998-07-23 17:50:45 +0000435
436\newcommand{\py@defsynopsis}{Module has no synopsis.}
437\newcommand{\py@modulesynopsis}{\py@defsynopsis}
438\newcommand{\modulesynopsis}[1]{
Fred Drake0c275fa1999-03-02 16:17:44 +0000439 \py@HaveModSynopsistrue
Fred Drakea488f301998-07-23 17:50:45 +0000440 \renewcommand{\py@modulesynopsis}{#1}
441}
442
443% define the file
444\newwrite\py@ModSynopsisFile
445
446% hacked from \addtocontents from latex.ltx:
447\long\def\py@writeModSynopsisFile#1{%
448 \protected@write\py@ModSynopsisFile%
449 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
450 {\string#1}%
451}
452\newcommand{\py@closeModSynopsisFile}{
453 \ifpy@ModSynopsisFileIsOpen
454 \closeout\py@ModSynopsisFile
455 \py@ModSynopsisFileIsOpenfalse
456 \fi
457}
458\newcommand{\py@openModSynopsisFile}{
459 \ifpy@ModSynopsisFileIsOpen\else
460 \openout\py@ModSynopsisFile=\py@ModSynopsisFilename
461 \py@ModSynopsisFileIsOpentrue
462 \fi
463}
464
465\newcommand{\py@ProcessModSynopsis}{
466 \ifpy@HaveModSynopsis
467 \py@writeModSynopsisFile{\modulesynopsis%
468 {\py@thismodulekey}{\py@thismodule}%
469 {\py@thismoduletype}{\py@modulesynopsis}}%
470 \py@HaveModSynopsisfalse
471 \fi
472 \renewcommand{\py@modulesynopsis}{\py@defsynopsis}
473}
474\AtEndDocument{\py@ProcessModSynopsis\py@closeModSynopsisFile}
475
Fred Drake0c275fa1999-03-02 16:17:44 +0000476
477\long\def\py@writeModPlatformFile#1{%
478 \protected@write\py@ModPlatformFile%
479 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
480 {\string#1}%
481}
482
483
Fred Drakea488f301998-07-23 17:50:45 +0000484\newcommand{\localmoduletable}{
485 \IfFileExists{\py@ModSynopsisFilename}{
486 \begin{synopsistable}
487 \input{\py@ModSynopsisFilename}
488 \end{synopsistable}
489 }{}
490}
491
Fred Drakee59feb52001-10-29 21:02:28 +0000492\ifpdf
Fred Drakeaa2aea01999-01-27 17:37:36 +0000493 \newcommand{\py@ModSynopsisSummary}[4]{%
494 \py@linkToName{label-module-#1}{\bfcode{#2}} & #4\\
495 }
Fred Drakee59feb52001-10-29 21:02:28 +0000496\else
497 \newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
498\fi
Fred Drakea488f301998-07-23 17:50:45 +0000499\newenvironment{synopsistable}{
500 % key, name, type, synopsis
501 \let\modulesynopsis=\py@ModSynopsisSummary
502 \begin{tabular}{ll}
503}{
504 \end{tabular}
505}
506%
507% --------------------------------------------------------------------------
508
509
Fred Drakea488f301998-07-23 17:50:45 +0000510\newcommand{\py@reset}{
Fred Drakeba828782000-04-03 04:19:14 +0000511 \py@usingsubitemfalse
Fred Drakea488f301998-07-23 17:50:45 +0000512 \py@ProcessModSynopsis
513 \renewcommand{\py@thisclass}{}
514 \renewcommand{\py@thismodule}{}
515 \renewcommand{\py@thismodulekey}{}
516 \renewcommand{\py@thismoduletype}{}
517}
518
519% Augment the sectioning commands used to get our own font family in place,
520% and reset some internal data items:
521\renewcommand{\section}{\py@reset%
522 \@startsection{section}{1}{\z@}%
523 {-3.5ex \@plus -1ex \@minus -.2ex}%
524 {2.3ex \@plus.2ex}%
525 {\reset@font\Large\py@HeaderFamily}}
526\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
527 {-3.25ex\@plus -1ex \@minus -.2ex}%
528 {1.5ex \@plus .2ex}%
529 {\reset@font\large\py@HeaderFamily}}
530\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
531 {-3.25ex\@plus -1ex \@minus -.2ex}%
532 {1.5ex \@plus .2ex}%
533 {\reset@font\normalsize\py@HeaderFamily}}
534\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
535 {3.25ex \@plus1ex \@minus.2ex}%
536 {-1em}%
537 {\reset@font\normalsize\py@HeaderFamily}}
538\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
539 {3.25ex \@plus1ex \@minus .2ex}%
540 {-1em}%
541 {\reset@font\normalsize\py@HeaderFamily}}
542
543
Fred Drake5420f331998-07-23 21:41:02 +0000544% This gets the underscores closer to the right width; the only change
545% from standard LaTeX is the width specified.
546
547\DeclareTextCommandDefault{\textunderscore}{%
548 \leavevmode \kern.06em\vbox{\hrule\@width.55em}}
549
Fred Drakea488f301998-07-23 17:50:45 +0000550% Underscore hack (only act like subscript operator if in math mode)
551%
552% The following is due to Mark Wooding (the old version didn't work with
553% Latex 2e.
554
555\DeclareRobustCommand\hackscore{%
556 \ifmmode_\else\textunderscore\fi%
557}
558\begingroup
559\catcode`\_\active
560\def\next{%
561 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
562}
563\expandafter\endgroup\next
564
565
Fred Drake53714971998-04-02 22:33:16 +0000566% Now for a lot of semantically-loaded environments that do a ton of magical
567% things to get the right formatting and index entries for the stuff in
568% Python modules and C API.
569
570
Fred Drake6659c301998-03-03 22:02:19 +0000571% {fulllineitems} is used in one place in libregex.tex, but is really for
572% internal use in this file.
573%
Fred Drakef9acc591998-09-09 15:27:43 +0000574\newcommand{\py@itemnewline}[1]{%
575 \@tempdima\linewidth%
576 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
577}
578
Fred Drake6659c301998-03-03 22:02:19 +0000579\newenvironment{fulllineitems}{
580 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
581 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
582 \itemsep -\parsep
Fred Drakef9acc591998-09-09 15:27:43 +0000583 \let\makelabel=\py@itemnewline}
Fred Drake6659c301998-03-03 22:02:19 +0000584}{\end{list}}
585
Fred Drake6cb71491998-03-27 05:22:53 +0000586% \optional is mostly for use in the arguments parameters to the various
587% {*desc} environments defined below, but may be used elsewhere. Known to
588% be used in the debugger chapter.
Fred Drake24340ea1998-04-28 18:30:34 +0000589%
590% Typical usage:
591%
592% \begin{funcdesc}{myfunc}{reqparm\optional{, optparm}}
593% ^^^ ^^^
594% No space here No space here
595%
596% When a function has multiple optional parameters, \optional should be
597% nested, not chained. This is right:
598%
599% \begin{funcdesc}{myfunc}{\optional{parm1\optional{, parm2}}}
600%
Fred Drakeba828782000-04-03 04:19:14 +0000601\let\py@badkey=\@undefined
602
Fred Drake6659c301998-03-03 22:02:19 +0000603\newcommand{\optional}[1]{%
604 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
605
Fred Drakeba828782000-04-03 04:19:14 +0000606% This can be used when a function or method accepts an varying number
607% of arguments, such as by using the *args syntax in the parameter list.
608\newcommand{\py@moreargs}{...}
609
610% This can be used when you don't want to document the parameters to a
611% function or method, but simply state that it's an alias for
612% something else.
613\newcommand{\py@unspecified}{...}
614
Fred Drakead74b7d2002-07-02 20:32:50 +0000615
616\newlength{\py@argswidth}
617\newcommand{\py@sigparams}[1]{%
618 \parbox[t]{\py@argswidth}{\py@varvars{#1}\code{)}}}
619\newcommand{\py@sigline}[2]{%
620 \settowidth{\py@argswidth}{#1\code{(}}%
621 \addtolength{\py@argswidth}{-2\py@argswidth}%
622 \addtolength{\py@argswidth}{\textwidth}%
623 \item[#1\code{(}\py@sigparams{#2}]}
624
Fred Drake6cb71491998-03-27 05:22:53 +0000625% C functions ------------------------------------------------------------
Fred Drakeba828782000-04-03 04:19:14 +0000626% \begin{cfuncdesc}[refcount]{type}{name}{arglist}
627% Note that the [refcount] slot should only be filled in by
628% tools/anno-api.py; it pulls the value from the refcounts database.
Fred Drake34adb8a2002-04-15 20:48:40 +0000629\newcommand{\cfuncline}[3]{
Fred Drakead74b7d2002-07-02 20:32:50 +0000630 \py@sigline{\code{#1 \bfcode{#2}}}{#3}%
631 \index{#2@{\py@idxcode{#2()}}}
Fred Drake34adb8a2002-04-15 20:48:40 +0000632}
Fred Drakeba828782000-04-03 04:19:14 +0000633\newenvironment{cfuncdesc}[4][\py@badkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000634 \begin{fulllineitems}
Fred Drake34adb8a2002-04-15 20:48:40 +0000635 \cfuncline{#2}{#3}{#4}
Fred Drakeba828782000-04-03 04:19:14 +0000636 \ifx#1\@undefined\else%
Fred Drake0a863da2000-04-10 18:21:38 +0000637 \emph{Return value: \textbf{#1}.}\\
Fred Drakeba828782000-04-03 04:19:14 +0000638 \fi
Fred Drake6cb71491998-03-27 05:22:53 +0000639}{\end{fulllineitems}}
640
641% C variables ------------------------------------------------------------
642% \begin{cvardesc}{type}{name}
643\newenvironment{cvardesc}[2]{
644 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000645 \item[\code{#1 \bfcode{#2}}\index{#2@{\py@idxcode{#2}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000646}{\end{fulllineitems}}
647
648% C data types -----------------------------------------------------------
Fred Drakeba828782000-04-03 04:19:14 +0000649% \begin{ctypedesc}[index name]{typedef name}
650\newenvironment{ctypedesc}[2][\py@badkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000651 \begin{fulllineitems}
Fred Drakeba828782000-04-03 04:19:14 +0000652 \item[\bfcode{#2}%
653 \ifx#1\@undefined%
Fred Drakea33c5662000-10-29 05:19:16 +0000654 \index{#2@{\py@idxcode{#2}} (C type)}
Fred Drakeba828782000-04-03 04:19:14 +0000655 \else%
Fred Drakea33c5662000-10-29 05:19:16 +0000656 \index{#2@{\py@idxcode{#1}} (C type)}
Fred Drakeba828782000-04-03 04:19:14 +0000657 \fi]
658}{\end{fulllineitems}}
659
Fred Drake01e94612002-04-12 22:48:02 +0000660% C type fields ----------------------------------------------------------
661% \begin{cmemberdesc}{container type}{ctype}{membername}
662\newcommand{\cmemberline}[3]{
663 \item[\code{#2 \bfcode{#3}}]
664 \index{#3@{\py@idxcode{#3}} (#1 member)}
665}
666\newenvironment{cmemberdesc}[3]{
667 \begin{fulllineitems}
668 \cmemberline{#1}{#2}{#3}
669}{\end{fulllineitems}}
670
Fred Drakeba828782000-04-03 04:19:14 +0000671% Funky macros -----------------------------------------------------------
Fred Drake19f827e2002-04-09 20:16:47 +0000672% \begin{csimplemacrodesc}{name}
Fred Drakeba828782000-04-03 04:19:14 +0000673% -- "simple" because it has no args; NOT for constant definitions!
674\newenvironment{csimplemacrodesc}[1]{
675 \begin{fulllineitems}
Fred Drakea33c5662000-10-29 05:19:16 +0000676 \item[\bfcode{#1}\index{#1@{\py@idxcode{#1}} (macro)}]
Fred Drake6cb71491998-03-27 05:22:53 +0000677}{\end{fulllineitems}}
678
679% simple functions (not methods) -----------------------------------------
680% \begin{funcdesc}{name}{args}
Fred Drakeec77e652000-10-30 06:22:22 +0000681\newcommand{\funcline}[2]{%
682 \funclineni{#1}{#2}%
683 \index{#1@{\py@idxcode{#1()}} (in module \py@thismodule)}}
Fred Drake6cb71491998-03-27 05:22:53 +0000684\newenvironment{funcdesc}[2]{
685 \begin{fulllineitems}
686 \funcline{#1}{#2}
687}{\end{fulllineitems}}
688
Fred Drake6659c301998-03-03 22:02:19 +0000689% similar to {funcdesc}, but doesn't add to the index
Fred Drakead74b7d2002-07-02 20:32:50 +0000690\newcommand{\funclineni}[2]{%
691 \py@sigline{\bfcode{#1}}{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000692\newenvironment{funcdescni}[2]{
693 \begin{fulllineitems}
694 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000695}{\end{fulllineitems}}
696
Fred Drake6cb71491998-03-27 05:22:53 +0000697% classes ----------------------------------------------------------------
698% \begin{classdesc}{name}{constructor args}
699\newenvironment{classdesc}[2]{
Fred Drake1cbd1961998-11-25 17:13:28 +0000700 % Using \renewcommand doesn't work for this, for unknown reasons:
701 \global\def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000702 \begin{fulllineitems}
Fred Drakead74b7d2002-07-02 20:32:50 +0000703 \py@sigline{\strong{class }\bfcode{#1}}{#2}%
704 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}
Fred Drake6659c301998-03-03 22:02:19 +0000705}{\end{fulllineitems}}
706
Fred Drake06a01e82001-05-11 01:00:30 +0000707% \begin{classdesc*}{name}
708\newenvironment{classdesc*}[1]{
709 % Using \renewcommand doesn't work for this, for unknown reasons:
710 \global\def\py@thisclass{#1}
711 \begin{fulllineitems}
712 \item[\strong{class }\code{\bfcode{#1}}%
713 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}]
714}{\end{fulllineitems}}
715
Fred Drake4e607962000-09-09 06:01:25 +0000716% \begin{excclassdesc}{name}{constructor args}
717% but indexes as an exception
718\newenvironment{excclassdesc}[2]{
719 % Using \renewcommand doesn't work for this, for unknown reasons:
720 \global\def\py@thisclass{#1}
721 \begin{fulllineitems}
Fred Drakead74b7d2002-07-02 20:32:50 +0000722 \py@sigline{\strong{exception }\bfcode{#1}}{#2}%
723 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}
Fred Drake4e607962000-09-09 06:01:25 +0000724}{\end{fulllineitems}}
725
Fred Drake06a01e82001-05-11 01:00:30 +0000726% There is no corresponding {excclassdesc*} environment. To describe
727% a class exception without parameters, use the {excdesc} environment.
728
Fred Drake6cb71491998-03-27 05:22:53 +0000729
Fred Drake24340ea1998-04-28 18:30:34 +0000730\let\py@classbadkey=\@undefined
Fred Drake6cb71491998-03-27 05:22:53 +0000731
732% object method ----------------------------------------------------------
733% \begin{methoddesc}[classname]{methodname}{args}
Fred Drakea33c5662000-10-29 05:19:16 +0000734\newcommand{\methodline}[3][\@undefined]{
Fred Drake6cb71491998-03-27 05:22:53 +0000735 \methodlineni{#2}{#3}
736 \ifx#1\@undefined
Fred Drakea33c5662000-10-29 05:19:16 +0000737 \index{#2@{\py@idxcode{#2()}} (\py@thisclass\ method)}
Fred Drake6cb71491998-03-27 05:22:53 +0000738 \else
Fred Drakea33c5662000-10-29 05:19:16 +0000739 \index{#2@{\py@idxcode{#2()}} (#1 method)}
Fred Drake6cb71491998-03-27 05:22:53 +0000740 \fi
741}
Fred Drakea33c5662000-10-29 05:19:16 +0000742\newenvironment{methoddesc}[3][\@undefined]{
Fred Drake6cb71491998-03-27 05:22:53 +0000743 \begin{fulllineitems}
744 \ifx#1\@undefined
745 \methodline{#2}{#3}
746 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000747 \def\py@thisclass{#1}
Fred Drakea33c5662000-10-29 05:19:16 +0000748 \methodline{#2}{#3}
Fred Drake6cb71491998-03-27 05:22:53 +0000749 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000750}{\end{fulllineitems}}
751
Fred Drake6cb71491998-03-27 05:22:53 +0000752% similar to {methoddesc}, but doesn't add to the index
753% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000754\newcommand{\methodlineni}[3][\py@classbadkey]{%
Fred Drakead74b7d2002-07-02 20:32:50 +0000755 \py@sigline{\bfcode{#2}}{#3}}
Fred Drake24340ea1998-04-28 18:30:34 +0000756\newenvironment{methoddescni}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000757 \begin{fulllineitems}
758 \methodlineni{#2}{#3}
759}{\end{fulllineitems}}
760
761% object data attribute --------------------------------------------------
762% \begin{memberdesc}[classname]{membername}
Fred Drake24340ea1998-04-28 18:30:34 +0000763\newcommand{\memberline}[2][\py@classbadkey]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000764 \ifx#1\@undefined
765 \memberlineni{#2}
Fred Drakea33c5662000-10-29 05:19:16 +0000766 \index{#2@{\py@idxcode{#2}} (\py@thisclass\ attribute)}
Fred Drake6cb71491998-03-27 05:22:53 +0000767 \else
768 \memberlineni{#2}
Fred Drakea33c5662000-10-29 05:19:16 +0000769 \index{#2@{\py@idxcode{#2}} (#1 attribute)}
Fred Drake6cb71491998-03-27 05:22:53 +0000770 \fi
771}
Fred Drake24340ea1998-04-28 18:30:34 +0000772\newenvironment{memberdesc}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000773 \begin{fulllineitems}
774 \ifx#1\@undefined
775 \memberline{#2}
776 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000777 \def\py@thisclass{#1}
Fred Drakea33c5662000-10-29 05:19:16 +0000778 \memberline{#2}
Fred Drake6cb71491998-03-27 05:22:53 +0000779 \fi
780}{\end{fulllineitems}}
781
782% similar to {memberdesc}, but doesn't add to the index
783% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000784\newcommand{\memberlineni}[2][\py@classbadkey]{\item[\bfcode{#2}]}
785\newenvironment{memberdescni}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000786 \begin{fulllineitems}
787 \memberlineni{#2}
788}{\end{fulllineitems}}
789
790% For exceptions: --------------------------------------------------------
791% \begin{excdesc}{name}
Fred Drakea33c5662000-10-29 05:19:16 +0000792% -- for constructor information, use excclassdesc instead
Fred Drake6cb71491998-03-27 05:22:53 +0000793\newenvironment{excdesc}[1]{
794 \begin{fulllineitems}
Fred Drakeab357ec2001-03-02 18:57:05 +0000795 \item[\strong{exception }\bfcode{#1}%
Fred Drakea33c5662000-10-29 05:19:16 +0000796 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}]
Fred Drake6cb71491998-03-27 05:22:53 +0000797}{\end{fulllineitems}}
798
799% Module data or constants: ----------------------------------------------
800% \begin{datadesc}{name}
Fred Drakea33c5662000-10-29 05:19:16 +0000801\newcommand{\dataline}[1]{%
802 \datalineni{#1}\index{#1@{\py@idxcode{#1}} (data in \py@thismodule)}}
Fred Drake6cb71491998-03-27 05:22:53 +0000803\newenvironment{datadesc}[1]{
804 \begin{fulllineitems}
805 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000806}{\end{fulllineitems}}
807
808% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000809\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
810\newenvironment{datadescni}[1]{
811 \begin{fulllineitems}
812 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000813}{\end{fulllineitems}}
814
Fred Drake6cb71491998-03-27 05:22:53 +0000815% bytecode instruction ---------------------------------------------------
816% \begin{opcodedesc}{name}{var}
817% -- {var} may be {}
818\newenvironment{opcodedesc}[2]{
819 \begin{fulllineitems}
820 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000821}{\end{fulllineitems}}
822
823
Fred Drake24340ea1998-04-28 18:30:34 +0000824\newcommand{\nodename}[1]{\label{#1}}
Fred Drake55730311998-03-25 15:41:23 +0000825
Fred Drake6659c301998-03-03 22:02:19 +0000826% For these commands, use \command{} to get the typography right, not
827% {\command}. This works better with the texinfo translation.
828\newcommand{\ABC}{{\sc abc}}
829\newcommand{\UNIX}{{\sc Unix}}
830\newcommand{\POSIX}{POSIX}
831\newcommand{\ASCII}{{\sc ascii}}
832\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
833\newcommand{\C}{C}
834\newcommand{\EOF}{{\sc eof}}
Fred Drake24340ea1998-04-28 18:30:34 +0000835\newcommand{\NULL}{\constant{NULL}}
Fred Drake5445e5e2001-06-23 03:11:45 +0000836\newcommand{\infinity}{\ensuremath{\infty}}
837\newcommand{\plusminus}{\ensuremath{\pm}}
Fred Drakef0f6d122004-01-23 08:52:28 +0000838
839% \guilabel{Start}
840\newcommand{\guilabel}[1]{\textsf{#1}}
Fred Drakeb4812862002-08-02 18:30:22 +0000841% \menuselection{Start \sub Programs \sub Python}
Fred Drakef0f6d122004-01-23 08:52:28 +0000842\newcommand{\menuselection}[1]{\guilabel{{\def\sub{ \ensuremath{>} }#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000843
Fred Drake53714971998-04-02 22:33:16 +0000844% Also for consistency: spell Python "Python", not "python"!
845
Fred Drake6659c301998-03-03 22:02:19 +0000846% code is the most difficult one...
Fred Drake46346ec2000-06-30 17:57:05 +0000847\newcommand{\code}[1]{\textrm{\@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 +0000848\texttt{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000849
850\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Fred Drake19f827e2002-04-09 20:16:47 +0000851\newcommand{\csimplemacro}[1]{\code{#1}}
Fred Drake8e54abe1998-07-01 14:49:25 +0000852\newcommand{\kbd}[1]{\code{#1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000853\newcommand{\samp}[1]{`\code{#1}'}
Fred Drakefa1cceb1998-11-30 14:42:59 +0000854\newcommand{\var}[1]{%
855 \ifmmode%
Fred Drakeff031cf2002-10-31 21:04:34 +0000856 \hbox{\py@defaultsize\textrm{\textit{#1\/}}}%
Fred Drakefa1cceb1998-11-30 14:42:59 +0000857 \else%
Fred Drakeff031cf2002-10-31 21:04:34 +0000858 \py@defaultsize\textrm{\textit{#1\/}}%
Fred Drakefa1cceb1998-11-30 14:42:59 +0000859 \fi%
860}
Fred Drake24340ea1998-04-28 18:30:34 +0000861\renewcommand{\emph}[1]{{\em #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000862\newcommand{\dfn}[1]{\emph{#1}}
863\newcommand{\strong}[1]{{\bf #1}}
864% let's experiment with a new font:
Fred Drakeff031cf2002-10-31 21:04:34 +0000865\newcommand{\file}[1]{`\filenq{#1}'}
Fred Drake52feb812004-02-09 20:58:08 +0000866\newcommand{\filenq}[1]{{\py@smallsize\textsf{\let\e=\textbackslash#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000867
868% Use this def/redef approach for \url{} since hyperref defined this already,
869% but only if we actually used hyperref:
Fred Drakee59feb52001-10-29 21:02:28 +0000870\ifpdf
871 \newcommand{\url}[1]{{%
Fred Drakecdd6e4d2004-12-01 06:30:31 +0000872 \py@pdfstartlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
Fred Drakeab357ec2001-03-02 18:57:05 +0000873 \py@LinkColor% color of the link text
Fred Drakeff031cf2002-10-31 21:04:34 +0000874 \py@smallsize\sf #1%
Fred Drakeab357ec2001-03-02 18:57:05 +0000875 \py@NormalColor% Turn it back off; these are declarative
876 \pdfendlink}% and don't appear bound to the current
877 }% formatting "box".
Fred Drakee59feb52001-10-29 21:02:28 +0000878\else
Fred Drakeff031cf2002-10-31 21:04:34 +0000879 \newcommand{\url}[1]{\mbox{\py@smallsize\textsf{#1}}}
Fred Drakee59feb52001-10-29 21:02:28 +0000880\fi
Fred Drakeff031cf2002-10-31 21:04:34 +0000881\newcommand{\email}[1]{{\py@smallsize\textsf{#1}}}
882\newcommand{\newsgroup}[1]{{\py@smallsize\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000883
Fred Drakecc2b81e2000-08-03 17:38:30 +0000884\newcommand{\py@varvars}[1]{{%
Fred Drakeba828782000-04-03 04:19:14 +0000885 {\let\unspecified=\py@unspecified%
886 \let\moreargs=\py@moreargs%
Fred Drakecc2b81e2000-08-03 17:38:30 +0000887 \var{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000888
Fred Drake24340ea1998-04-28 18:30:34 +0000889% I'd really like to get rid of this!
Fred Drake6659c301998-03-03 22:02:19 +0000890\newif\iftexi\texifalse
Fred Drake6659c301998-03-03 22:02:19 +0000891
Fred Drake1e4973b1998-07-28 21:52:17 +0000892% This is used to get l2h to put the copyright and abstract on
893% a separate HTML page.
894\newif\ifhtml\htmlfalse
895
896
Fred Drake6659c301998-03-03 22:02:19 +0000897% These should be used for all references to identifiers which are
898% used to refer to instances of specific language constructs. See the
899% names for specific semantic assignments.
900%
901% For now, don't do anything really fancy with them; just use them as
902% logical markup. This might change in the future.
903%
Fred Drake24340ea1998-04-28 18:30:34 +0000904\newcommand{\module}[1]{\texttt{#1}}
905\newcommand{\keyword}[1]{\texttt{#1}}
906\newcommand{\exception}[1]{\texttt{#1}}
907\newcommand{\class}[1]{\texttt{#1}}
908\newcommand{\function}[1]{\texttt{#1}}
909\newcommand{\member}[1]{\texttt{#1}}
910\newcommand{\method}[1]{\texttt{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000911
Fred Drakeab357ec2001-03-02 18:57:05 +0000912\newcommand{\pytype}[1]{#1} % built-in Python type
Fred Drake53714971998-04-02 22:33:16 +0000913
Fred Drake24340ea1998-04-28 18:30:34 +0000914\newcommand{\cfunction}[1]{\texttt{#1}}
Fred Drakeab357ec2001-03-02 18:57:05 +0000915\newcommand{\ctype}[1]{\texttt{#1}} % C struct or typedef name
916\newcommand{\cdata}[1]{\texttt{#1}} % C variable, typically global
Fred Drake6659c301998-03-03 22:02:19 +0000917
Fred Drakeff031cf2002-10-31 21:04:34 +0000918\newcommand{\mailheader}[1]{{\py@smallsize\textsf{#1:}}}
919\newcommand{\mimetype}[1]{{\py@smallsize\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000920% The \! is a "negative thin space" in math mode.
921\newcommand{\regexp}[1]{%
922 {\tiny$^{^\lceil}\!\!$%
Fred Drakeff031cf2002-10-31 21:04:34 +0000923 {\py@defaultsize\code{#1}}%
Fred Drake47cfd031998-04-03 21:22:31 +0000924 $\!\rfloor\!$%
Fred Drake94fac131998-03-12 19:37:03 +0000925 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000926\newcommand{\envvar}[1]{%
Fred Drake31ab2982001-01-22 17:50:42 +0000927 #1%
Fred Drakee59feb52001-10-29 21:02:28 +0000928 \index{#1}%
Fred Drake31ab2982001-01-22 17:50:42 +0000929 \index{environment variables!{#1}}%
Fred Drake0ee9f721998-03-12 06:41:40 +0000930}
Fred Drakeab357ec2001-03-02 18:57:05 +0000931\newcommand{\makevar}[1]{#1} % variable in a Makefile
Fred Drake24340ea1998-04-28 18:30:34 +0000932\newcommand{\character}[1]{\samp{#1}}
Fred Drake0ee9f721998-03-12 06:41:40 +0000933
Fred Drake6659c301998-03-03 22:02:19 +0000934% constants defined in Python modules or C headers, not language constants:
Fred Drakeab357ec2001-03-02 18:57:05 +0000935\newcommand{\constant}[1]{\code{#1}} % manifest constant, not syntactic
Fred Drake6659c301998-03-03 22:02:19 +0000936
937\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake4e607962000-09-09 06:01:25 +0000938\newcommand{\pep}[1]{PEP #1\index{Python Enhancement Proposals!PEP #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000939\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
940\newcommand{\program}[1]{\strong{#1}}
Fred Drake7b8195a1999-11-09 17:02:11 +0000941\newcommand{\programopt}[1]{\strong{#1}}
Fred Drake49362492000-04-11 18:47:59 +0000942% Note that \longprogramopt provides the '--'!
943\newcommand{\longprogramopt}[1]{\strong{-{}-#1}}
Fred Drakee59feb52001-10-29 21:02:28 +0000944
Fred Drakeb4b64da2001-07-06 22:44:48 +0000945% \ulink{link text}{URL}
Fred Drakee59feb52001-10-29 21:02:28 +0000946\ifpdf
Fred Drakecdd6e4d2004-12-01 06:30:31 +0000947 \newcommand{\ulink}[2]{{%
948 % For PDF, we *should* only generate a link when the URL is absolute.
949 \py@pdfstartlink attr{/Border [0 0 0]} user{/S /URI /URI (#2)}%
Fred Drakee59feb52001-10-29 21:02:28 +0000950 \py@LinkColor% color of the link text
951 #1%
952 \py@NormalColor% Turn it back off; these are declarative
953 \pdfendlink}% and don't appear bound to the current
954 }% formatting "box".
955\else
956 \newcommand{\ulink}[2]{#1}
957\fi
Fred Drake7b8195a1999-11-09 17:02:11 +0000958
959% cited titles: \citetitle{Title of Work}
960% online: \citetitle[url-to-resource]{Title of Work}
Fred Drakee59feb52001-10-29 21:02:28 +0000961\ifpdf
962 \newcommand{\citetitle}[2][\py@modulebadkey]{%
963 \ifx\py@modulebadkey#1\emph{#2}\else\ulink{\emph{#2}}{#1}\fi%
964 }
965\else
Fred Drake622087a2001-11-02 20:53:19 +0000966 \newcommand{\citetitle}[2][URL]{\emph{#2}}
Fred Drakee59feb52001-10-29 21:02:28 +0000967\fi
968
Fred Drake6659c301998-03-03 22:02:19 +0000969
970
Fred Drakec82bd722001-12-11 18:47:36 +0000971% This version is being checked in for the historical record; it shows
972% how I've managed to get some aspects of this to work. It will not
973% be used in practice, so a subsequent revision will change things
974% again. This version has problems, but shows how to do something
975% that proved more tedious than I'd expected, so I don't want to lose
976% the example completely.
977%
Fred Drake16bb4192001-08-20 21:36:38 +0000978\newcommand{\grammartoken}[1]{\texttt{#1}}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000979\newenvironment{productionlist}[1][\py@badkey]{
980 \def\optional##1{{\Large[}##1{\Large]}}
981 \def\production##1##2{\code{##1}&::=&\code{##2}\\}
Fred Drake53815882002-03-15 23:21:37 +0000982 \def\productioncont##1{& &\code{##1}\\}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000983 \def\token##1{##1}
Fred Drake16bb4192001-08-20 21:36:38 +0000984 \let\grammartoken=\token
Fred Drakec82bd722001-12-11 18:47:36 +0000985 \parindent=2em
986 \indent
987 \begin{tabular}{lcl}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000988}{%
Fred Drakec82bd722001-12-11 18:47:36 +0000989 \end{tabular}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000990}
991
Fred Drake862b46b2004-03-31 08:08:34 +0000992\newlength{\py@noticelength}
993
994\newcommand{\py@heavybox}{
995 \setlength{\fboxrule}{2pt}
996 \setlength{\fboxsep}{7pt}
997 \setlength{\py@noticelength}{\linewidth}
998 \addtolength{\py@noticelength}{-2\fboxsep}
999 \addtolength{\py@noticelength}{-2\fboxrule}
1000 \setlength{\shadowsize}{3pt}
1001 \Sbox
1002 \minipage{\py@noticelength}
1003}
1004\newcommand{\py@endheavybox}{
1005 \endminipage
1006 \endSbox
1007 \fbox{\TheSbox}
1008}
1009
1010% a 'note' is as plain as it gets:
Fred Drake6ca33772001-12-14 22:50:06 +00001011\newcommand{\py@noticelabel@note}{Note:}
Fred Drake862b46b2004-03-31 08:08:34 +00001012\newcommand{\py@noticestart@note}{}
1013\newcommand{\py@noticeend@note}{}
1014
1015% a 'warning' gets more visible distinction:
Fred Drake6ca33772001-12-14 22:50:06 +00001016\newcommand{\py@noticelabel@warning}{Warning:}
Fred Drake862b46b2004-03-31 08:08:34 +00001017\newcommand{\py@noticestart@warning}{\py@heavybox}
1018\newcommand{\py@noticeend@warning}{\py@endheavybox}
1019
Fred Drake6ca33772001-12-14 22:50:06 +00001020\newenvironment{notice}[1][note]{
Fred Drake862b46b2004-03-31 08:08:34 +00001021 \def\py@noticetype{#1}
1022 \csname py@noticestart@#1\endcsname
Fred Drake6ca33772001-12-14 22:50:06 +00001023 \par\strong{\csname py@noticelabel@#1\endcsname}
Fred Drake862b46b2004-03-31 08:08:34 +00001024}{\csname py@noticeend@\py@noticetype\endcsname}
Fred Drake6ca33772001-12-14 22:50:06 +00001025\newcommand{\note}[1]{\strong{\py@noticelabel@note} #1}
1026\newcommand{\warning}[1]{\strong{\py@noticelabel@warning} #1}
Fred Drake92350b32001-10-09 18:01:23 +00001027
Fred Drake6659c301998-03-03 22:02:19 +00001028% Deprecation stuff.
1029% Should be extended to allow an index / list of deprecated stuff. But
1030% there's a lot of stuff that needs to be done to make that automatable.
1031%
1032% First parameter is the release number that deprecates the feature, the
1033% second is the action the should be taken by users of the feature.
1034%
1035% Example:
Fred Drake24340ea1998-04-28 18:30:34 +00001036% \deprecated{1.5.1}{Use \method{frobnicate()} instead.}
Fred Drake6659c301998-03-03 22:02:19 +00001037%
1038\newcommand{\deprecated}[2]{%
1039 \strong{Deprecated since release #1.} #2\par}
1040
Fred Drakeaf958c71998-07-27 20:32:33 +00001041% New stuff.
1042% This should be used to mark things which have been added to the
1043% development tree but that aren't in the release, but are documented.
1044% This allows release of documentation that already includes updated
Fred Drake2116d981999-02-02 18:02:48 +00001045% descriptions. Place at end of descriptor environment.
Fred Drakeaf958c71998-07-27 20:32:33 +00001046%
1047% Example:
1048% \versionadded{1.5.2}
Fred Drake46346ec2000-06-30 17:57:05 +00001049% \versionchanged[short explanation]{2.0}
Fred Drakeaf958c71998-07-27 20:32:33 +00001050%
Fred Drakefdfb05b2001-04-18 03:08:54 +00001051\newcommand{\versionadded}[2][\py@badkey]{%
1052 \ifx#1\@undefined%
1053 { New in version #2. }%
1054 \else%
1055 { New in version #2:\ #1. }%
1056 \fi%
1057}
Fred Drakea6e83392000-05-02 17:28:36 +00001058\newcommand{\versionchanged}[2][\py@badkey]{%
1059 \ifx#1\@undefined%
1060 { Changed in version #2. }%
1061 \else%
1062 { Changed in version #2:\ #1. }%
1063 \fi%
1064}
Fred Drake6659c301998-03-03 22:02:19 +00001065
Fred Drakeaf958c71998-07-27 20:32:33 +00001066
1067% Tables.
1068%
Fred Drake6659c301998-03-03 22:02:19 +00001069\newenvironment{tableii}[4]{%
1070 \begin{center}%
1071 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakef61eac42000-10-24 02:18:30 +00001072 \begin{tabular}{#1}\strong{#3}&\strong{#4} \\* \hline%
Fred Drake6659c301998-03-03 22:02:19 +00001073}{%
Fred Drake6659c301998-03-03 22:02:19 +00001074 \end{tabular}%
1075 \end{center}%
1076}
1077
Fred Drakeda72b932000-09-21 15:58:02 +00001078\newenvironment{longtableii}[4]{%
1079 \begin{center}%
1080 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakef61eac42000-10-24 02:18:30 +00001081 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4} \\* \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001082}{%
1083 \end{longtable}%
1084 \end{center}%
1085}
1086
Fred Drake6659c301998-03-03 22:02:19 +00001087\newenvironment{tableiii}[5]{%
1088 \begin{center}%
1089 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
Fred Drakeda72b932000-09-21 15:58:02 +00001090 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001091 \hline%
Fred Drake6659c301998-03-03 22:02:19 +00001092}{%
Fred Drake6659c301998-03-03 22:02:19 +00001093 \end{tabular}%
1094 \end{center}%
1095}
1096
Fred Drakeda72b932000-09-21 15:58:02 +00001097\newenvironment{longtableiii}[5]{%
1098 \begin{center}%
1099 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
1100 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001101 \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001102}{%
1103 \end{longtable}%
1104 \end{center}%
1105}
1106
Fred Drake30e52651998-07-24 22:11:29 +00001107\newenvironment{tableiv}[6]{%
1108 \begin{center}%
1109 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
1110 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001111 \hline%
Fred Drake30e52651998-07-24 22:11:29 +00001112}{%
1113 \end{tabular}%
1114 \end{center}%
1115}
1116
Fred Drakeda72b932000-09-21 15:58:02 +00001117\newenvironment{longtableiv}[6]{%
1118 \begin{center}%
1119 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
1120 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}%
1121 \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001122 \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001123}{%
1124 \end{longtable}%
1125 \end{center}%
1126}
1127
Fred Drakef269e592001-07-17 23:05:57 +00001128\newenvironment{tablev}[7]{%
1129 \begin{center}%
1130 \def\linev##1##2##3##4##5{\csname#2\endcsname{##1}&##2&##3&##4&##5\\}%
1131 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}&\strong{#7} \\%
1132 \hline%
1133}{%
1134 \end{tabular}%
1135 \end{center}%
1136}
1137
1138\newenvironment{longtablev}[7]{%
1139 \begin{center}%
1140 \def\linev##1##2##3##4##5{\csname#2\endcsname{##1}&##2&##3&##4&##5\\}%
1141 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}&\strong{#7}%
1142 \\%
1143 \hline\endhead%
1144}{%
1145 \end{longtable}%
1146 \end{center}%
1147}
1148
Fred Drake567332a2002-12-30 20:51:27 +00001149% XXX Don't think we can use this yet, though it cleans up some
1150% tedious markup. There's no equivalent for the HTML transform yet,
1151% and that needs to exist. I don't know how to write it.
1152%
1153% This should really have something that makes it easier to bind a
1154% table's ``Notes'' column and an associated tablenotes environment,
1155% and generates the right magic for getting the numbers right in the
1156% table.
1157%
1158% So this is quite incomplete.
1159%
1160\newcounter{py@tablenotescounter}
1161\newenvironment{tablenotes}{%
1162 \noindent Notes:
1163 \par
1164 \setcounter{py@tablenotescounter}{0}
1165 \begin{list}{(\arabic{py@tablenotescounter})}%
1166 {\usecounter{py@tablenotescounter}}
1167}{\end{list}}
1168
1169
Fred Drake24340ea1998-04-28 18:30:34 +00001170% Cross-referencing (AMK, new impl. FLD)
Fred Drake6659c301998-03-03 22:02:19 +00001171% Sample usage:
1172% \begin{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +00001173% \seemodule{rand}{Uniform random number generator.}; % Module xref
1174% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +00001175%
1176% % A funky case: module name contains '_'; have to supply an optional key
Fred Drake84bd6f31999-05-11 15:42:51 +00001177% \seemodule[copyreg]{copy_reg}{Interface constructor registration for
1178% \module{pickle}.}
Fred Drake6659c301998-03-03 22:02:19 +00001179% \end{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +00001180%
1181% Note that the last parameter for \seemodule and \seetext should be complete
1182% sentences and be terminated with the proper punctuation.
Fred Drake6659c301998-03-03 22:02:19 +00001183
Fred Drakee59feb52001-10-29 21:02:28 +00001184\ifpdf
Fred Drake24340ea1998-04-28 18:30:34 +00001185 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +00001186 \par%
Fred Drake24340ea1998-04-28 18:30:34 +00001187 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drake84bd6f31999-05-11 15:42:51 +00001188 \begin{fulllineitems}
Fred Drake84bd6f31999-05-11 15:42:51 +00001189 \item[\py@linkToName{label-module-\py@modulekey}{Module \module{#2}}
1190 (section \ref{module-\py@modulekey}):]
1191 #3
1192 \end{fulllineitems}
Fred Drakeebcb6581998-03-06 21:25:17 +00001193 }
Fred Drakee59feb52001-10-29 21:02:28 +00001194\else
1195 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
1196 \par%
1197 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
1198 \begin{fulllineitems}
1199 \item[Module \module{#2} (section \ref{module-\py@modulekey}):]
1200 #3
1201 \end{fulllineitems}
1202 }
1203\fi
1204
Fred Drake1592c4c2005-03-10 04:01:14 +00001205% \seelink{url}{link text}{why it's interesting}
Fred Drake4f687b32004-01-08 14:57:27 +00001206\newcommand{\py@seelink}[3]{%
1207 \par
1208 \begin{fulllineitems}
1209 \item[\ulink{#2}{#1}]
1210 #3
1211 \end{fulllineitems}
1212}
Fred Drake48449982000-09-12 17:52:33 +00001213% \seetitle[url]{title}{why it's interesting}
1214\newcommand{\py@seetitle}[3][\py@modulebadkey]{%
1215 \par
1216 \begin{fulllineitems}
1217 \item[\citetitle{#2}]
1218 \ifx\py@modulebadkey#1\else
1219 \item[{\small{(\url{#1})}}]
1220 \fi
1221 #3
1222 \end{fulllineitems}
1223}
Fred Drake4e607962000-09-09 06:01:25 +00001224% \seepep{number}{title}{why it's interesting}
1225\newcommand{\py@seepep}[3]{%
1226 \par%
1227 \begin{fulllineitems}
1228 \item[\pep{#1}, ``\emph{#2}'']
1229 #3
1230 \end{fulllineitems}
1231}
Fred Drake64b72b62000-04-26 18:13:58 +00001232% \seerfc{number}{title}{why it's interesting}
1233\newcommand{\py@seerfc}[3]{%
1234 \par%
1235 \begin{fulllineitems}
1236 \item[\rfc{#1}, ``\emph{#2}'']
1237 #3
1238 \end{fulllineitems}
1239}
Fred Drake51313f12000-05-09 16:18:44 +00001240% \seeurl{url}{why it's interesting}
1241\newcommand{\py@seeurl}[2]{%
1242 \par%
1243 \begin{fulllineitems}
1244 \item[\url{#1}]
1245 #2
1246 \end{fulllineitems}
1247}
Fred Drake5ed35fd2001-11-30 18:09:54 +00001248
1249\newenvironment{seealso*}{
Fred Drake9466b9a1999-03-18 16:18:27 +00001250 \par
Fred Drake6659c301998-03-03 22:02:19 +00001251 \def\seetext##1{\par{##1}}
Fred Drake24340ea1998-04-28 18:30:34 +00001252 \let\seemodule=\py@seemodule
Fred Drake48449982000-09-12 17:52:33 +00001253 \let\seepep=\py@seepep
Fred Drake64b72b62000-04-26 18:13:58 +00001254 \let\seerfc=\py@seerfc
Fred Drake48449982000-09-12 17:52:33 +00001255 \let\seetitle=\py@seetitle
Fred Drake51313f12000-05-09 16:18:44 +00001256 \let\seeurl=\py@seeurl
Fred Drake4f687b32004-01-08 14:57:27 +00001257 \let\seelink=\py@seelink
Fred Drake6659c301998-03-03 22:02:19 +00001258}{\par}
Fred Drake5ed35fd2001-11-30 18:09:54 +00001259\newenvironment{seealso}{
1260 \par
1261 \strong{See Also:}
1262 \par
1263 \def\seetext##1{\par{##1}}
1264 \let\seemodule=\py@seemodule
1265 \let\seepep=\py@seepep
1266 \let\seerfc=\py@seerfc
1267 \let\seetitle=\py@seetitle
1268 \let\seeurl=\py@seeurl
Fred Drake4f687b32004-01-08 14:57:27 +00001269 \let\seelink=\py@seelink
Fred Drake5ed35fd2001-11-30 18:09:54 +00001270}{\par}
Fred Drake6659c301998-03-03 22:02:19 +00001271
Fred Drakeaf958c71998-07-27 20:32:33 +00001272% Allow the Python release number to be specified independently of the
Fred Drake6659c301998-03-03 22:02:19 +00001273% \date{}. This allows the date to reflect the document's date and
1274% release to specify the Python release that is documented.
1275%
Fred Drake24340ea1998-04-28 18:30:34 +00001276\newcommand{\py@release}{}
Fred Drake6659c301998-03-03 22:02:19 +00001277\newcommand{\version}{}
Fred Drakeaf2b7142000-09-14 20:11:05 +00001278\newcommand{\shortversion}{}
Fred Drakec65218e2001-06-20 21:17:09 +00001279\newcommand{\releaseinfo}{}
Fred Drake6659c301998-03-03 22:02:19 +00001280\newcommand{\releasename}{Release}
1281\newcommand{\release}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +00001282 \renewcommand{\py@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +00001283 \renewcommand{\version}{#1}}
Fred Drakeaf2b7142000-09-14 20:11:05 +00001284\newcommand{\setshortversion}[1]{%
1285 \renewcommand{\shortversion}{#1}}
Fred Drakec65218e2001-06-20 21:17:09 +00001286\newcommand{\setreleaseinfo}[1]{%
1287 \renewcommand{\releaseinfo}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +00001288
1289% Allow specification of the author's address separately from the
1290% author's name. This can be used to format them differently, which
1291% is a good thing.
1292%
Fred Drake24340ea1998-04-28 18:30:34 +00001293\newcommand{\py@authoraddress}{}
1294\newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress}{#1}}
Fred Drake6df93ef1998-05-14 20:56:31 +00001295\let\developersaddress=\authoraddress
1296\let\developer=\author
1297\let\developers=\author
Fred Drake6659c301998-03-03 22:02:19 +00001298
Fred Drake6659c301998-03-03 22:02:19 +00001299% This sets up the fancy chapter headings that make the documents look
1300% at least a little better than the usual LaTeX output.
1301%
Fred Drake1c8d0e01998-03-07 05:29:15 +00001302\@ifundefined{ChTitleVar}{}{
Fred Drake24340ea1998-04-28 18:30:34 +00001303 \ChNameVar{\raggedleft\normalsize\py@HeaderFamily}
1304 \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily}
1305 \ChTitleVar{\raggedleft \rm\Huge\py@HeaderFamily}
Fred Drake6659c301998-03-03 22:02:19 +00001306 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +00001307 \def\@makechapterhead#1{%
1308 {\parindent \z@ \raggedright \normalfont
1309 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +00001310 \DOCH
1311 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +00001312 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +00001313 \DOTI{#1}
1314 }
1315 }
Fred Drake6659c301998-03-03 22:02:19 +00001316}
1317
Fred Drake3bf78651998-05-20 17:42:17 +00001318
1319% Definition lists; requested by AMK for HOWTO documents. Probably useful
1320% elsewhere as well, so keep in in the general style support.
1321%
1322\newenvironment{definitions}{%
1323 \begin{description}%
Fred Drakef9acc591998-09-09 15:27:43 +00001324 \def\term##1{\item[##1]\mbox{}\\*[0mm]}
Fred Drake3bf78651998-05-20 17:42:17 +00001325}{%
1326 \end{description}%
1327}
1328
Fred Drake6659c301998-03-03 22:02:19 +00001329% Tell TeX about pathological hyphenation cases:
1330\hyphenation{Base-HTTP-Re-quest-Hand-ler}