blob: dd043e1727fca0cdac1ea52faa160044960f859c [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 Drakec0b2e451998-03-25 14:53:43 +000023% for PDF output, use maximal compression & a lot of other stuff
24% (test for PDF recommended by Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov>)
25%
Fred Drake24340ea1998-04-28 18:30:34 +000026\newif\ifpy@doing@page@targets
27\py@doing@page@targetsfalse
Fred Drake6cb71491998-03-27 05:22:53 +000028
Fred Drakee59feb52001-10-29 21:02:28 +000029\newif\ifpdf\pdffalse
Fred Drakec0b2e451998-03-25 14:53:43 +000030\ifx\pdfoutput\undefined\else\ifcase\pdfoutput
Fred Drakec0b2e451998-03-25 14:53:43 +000031\else
Fred Drakee59feb52001-10-29 21:02:28 +000032 \pdftrue
Fred Drake6659c301998-03-03 22:02:19 +000033 \input{pdfcolor}
Fred Drake24340ea1998-04-28 18:30:34 +000034 \let\py@LinkColor=\NavyBlue
35 \let\py@NormalColor=\Black
Fred Drake6659c301998-03-03 22:02:19 +000036 \pdfcompresslevel=9
Fred Drakeba1700c1998-05-11 20:42:54 +000037 \pdfpagewidth=\paperwidth % page width of PDF output
38 \pdfpageheight=\paperheight % page height of PDF output
Fred Drakeebcb6581998-03-06 21:25:17 +000039 %
Fred Drakea2c2a831998-04-15 17:50:01 +000040 % Pad the number with '0' to 3 digits wide so no page name is a prefix
41 % of any other.
42 %
Fred Drakea488f301998-07-23 17:50:45 +000043 \newcommand{\py@targetno}[1]{\ifnum#1<100 0\fi\ifnum#1<10 0\fi#1}
44 \newcommand{\py@pageno}{\py@targetno\thepage}
Fred Drakea2c2a831998-04-15 17:50:01 +000045 %
Fred Drakeebcb6581998-03-06 21:25:17 +000046 % This definition allows the entries in the page-view of the ToC to be
47 % active links. Some work, some don't.
48 %
Fred Drake24340ea1998-04-28 18:30:34 +000049 \let\py@OldContentsline=\contentsline
Fred Drakeaa2aea01999-01-27 17:37:36 +000050 %
Fred Drake0e4cd7f2002-03-16 04:52:36 +000051 % Backward compatibility hack: pdfTeX 0.13 defined \pdfannotlink,
52 % but it changed to \pdfstartlink in 0.14. This let's us use either
53 % version and still get useful behavior.
54 %
55 \@ifundefined{pdfstartlink}{
56 \let\pdfstartlink=\pdfannotlink
57 }{}
58 %
Fred Drakeaa2aea01999-01-27 17:37:36 +000059 % Macro that takes two args: the name to link to and the content of
60 % the link. This takes care of the PDF magic, getting the colors
61 % the same for each link, and avoids having lots of garbage all over
62 % this style file.
63 \newcommand{\py@linkToName}[2]{%
Fred Drake53815882002-03-15 23:21:37 +000064 \pdfstartlink attr{/Border [0 0 0]} goto name{#1}%
Fred Drakeaa2aea01999-01-27 17:37:36 +000065 \py@LinkColor#2\py@NormalColor%
66 \pdfendlink%
Fred Drake53815882002-03-15 23:21:37 +000067 }
Fred Drakea2c2a831998-04-15 17:50:01 +000068 % Compute the padded page number separately since we end up with a pair of
69 % \relax tokens; this gets the right string computed and works.
Fred Drake6659c301998-03-03 22:02:19 +000070 \renewcommand{\contentsline}[3]{%
Fred Drakea2c2a831998-04-15 17:50:01 +000071 \def\my@pageno{\py@targetno{#3}}%
Fred Drakeaa2aea01999-01-27 17:37:36 +000072 \py@OldContentsline{#1}{\py@linkToName{page\my@pageno}{#2}}{#3}%
Fred Drake6659c301998-03-03 22:02:19 +000073 }
Fred Drakeebcb6581998-03-06 21:25:17 +000074 \AtEndDocument{
Neal Norwitz5268c392004-08-21 15:13:52 +000075 \def\_{\string_}
Fred Drakec0b2e451998-03-25 14:53:43 +000076 \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
Fred Drakeebcb6581998-03-06 21:25:17 +000077 }
Fred Drakea2c2a831998-04-15 17:50:01 +000078 \newcommand{\py@target}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000079 \ifpy@doing@page@targets%
Fred Drake9b8afde1999-03-24 14:16:17 +000080 {\pdfdest name{#1} xyz}%
Fred Drakea2c2a831998-04-15 17:50:01 +000081 \fi%
82 }
Fred Drake24340ea1998-04-28 18:30:34 +000083 \let\py@OldLabel=\label
Fred Drake6659c301998-03-03 22:02:19 +000084 \renewcommand{\label}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000085 \py@OldLabel{#1}%
Fred Drakea2c2a831998-04-15 17:50:01 +000086 \py@target{label-#1}%
Fred Drake6659c301998-03-03 22:02:19 +000087 }
Fred Drakeba1700c1998-05-11 20:42:54 +000088 % This stuff adds a page# destination to every PDF page, where # is three
89 % digits wide, padded with leading zeros. This doesn't really help with
90 % the frontmatter, but does fine with the body.
Fred Drake6659c301998-03-03 22:02:19 +000091 %
92 % This is *heavily* based on the hyperref package.
93 %
Fred Drake1c8d0e01998-03-07 05:29:15 +000094 \def\@begindvi{%
95 \unvbox \@begindvibox
96 \@hyperfixhead
Fred Drake6659c301998-03-03 22:02:19 +000097 }
Fred Drake1c8d0e01998-03-07 05:29:15 +000098 \def\@hyperfixhead{%
99 \let\H@old@thehead\@thehead
Fred Drakea2c2a831998-04-15 17:50:01 +0000100 \global\def\@foo{\py@target{page\py@pageno}}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000101 \expandafter\ifx\expandafter\@empty\H@old@thehead
102 \def\H@old@thehead{\hfil}\fi
103 \def\@thehead{\@foo\relax\H@old@thehead}%
Fred Drake6659c301998-03-03 22:02:19 +0000104 }
Fred Drakec0b2e451998-03-25 14:53:43 +0000105\fi\fi
Fred Drake6659c301998-03-03 22:02:19 +0000106
107% Increase printable page size (copied from fullpage.sty)
108\topmargin 0pt
109\advance \topmargin by -\headheight
110\advance \topmargin by -\headsep
111
112% attempt to work a little better for A4 users
Fred Drake9466b9a1999-03-18 16:18:27 +0000113\textheight \paperheight
114\advance\textheight by -2in
Fred Drake6659c301998-03-03 22:02:19 +0000115
116\oddsidemargin 0pt
Fred Drake9466b9a1999-03-18 16:18:27 +0000117\evensidemargin 0pt
118%\evensidemargin -.25in % for ``manual size'' documents
Fred Drake6659c301998-03-03 22:02:19 +0000119\marginparwidth 0.5in
120
Fred Drake9466b9a1999-03-18 16:18:27 +0000121\textwidth \paperwidth
122\advance\textwidth by -2in
Fred Drake6659c301998-03-03 22:02:19 +0000123
124
125% Style parameters and macros used by most documents here
126\raggedbottom
127\sloppy
128\parindent = 0mm
Fred Drake24340ea1998-04-28 18:30:34 +0000129\parskip = 2mm
Fred Drakeab357ec2001-03-02 18:57:05 +0000130\hbadness = 5000 % don't print trivial gripes
Fred Drake6659c301998-03-03 22:02:19 +0000131
Fred Drakeab357ec2001-03-02 18:57:05 +0000132\pagestyle{empty} % start this way; change for
133\pagenumbering{roman} % ToC & chapters
Fred Drake6659c301998-03-03 22:02:19 +0000134
135% Use this to set the font family for headers and other decor:
Fred Drake24340ea1998-04-28 18:30:34 +0000136\newcommand{\py@HeaderFamily}{\sffamily}
Fred Drake6659c301998-03-03 22:02:19 +0000137
Fred Drakeff031cf2002-10-31 21:04:34 +0000138% Set up abstract ways to get the normal and smaller font sizes that
139% work even in footnote context.
140\newif\ifpy@infootnote \py@infootnotefalse
Fred Drake2eba52f2002-11-04 16:29:31 +0000141\let\py@oldmakefntext\@makefntext
142\def\@makefntext#1{%
Fred Drakeff031cf2002-10-31 21:04:34 +0000143 \bgroup%
144 \py@infootnotetrue
Fred Drake2eba52f2002-11-04 16:29:31 +0000145 \py@oldmakefntext{#1}%
Fred Drakeff031cf2002-10-31 21:04:34 +0000146 \egroup%
147}
148\def\py@defaultsize{%
149 \ifpy@infootnote\footnotesize\else\normalsize\fi%
150}
151\def\py@smallsize{%
152 \ifpy@infootnote\scriptsize\else\small\fi%
153}
154
Fred Drake6659c301998-03-03 22:02:19 +0000155% Redefine the 'normal' header/footer style when using "fancyhdr" package:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000156\@ifundefined{fancyhf}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000157 % Use \pagestyle{normal} as the primary pagestyle for text.
158 \fancypagestyle{normal}{
159 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000160 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
161 \fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
162 \fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
Fred Drake6659c301998-03-03 22:02:19 +0000163 \renewcommand{\headrulewidth}{0pt}
164 \renewcommand{\footrulewidth}{0.4pt}
165 }
166 % Update the plain style so we get the page number & footer line,
167 % but not a chapter or section title. This is to keep the first
168 % page of a chapter and the blank page between chapters `clean.'
169 \fancypagestyle{plain}{
170 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000171 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
Fred Drake6659c301998-03-03 22:02:19 +0000172 \renewcommand{\headrulewidth}{0pt}
173 \renewcommand{\footrulewidth}{0.4pt}
174 }
175 % Redefine \cleardoublepage so that the blank page between chapters
176 % gets the plain style and not the fancy style. This is described
177 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000178 \@ifundefined{chapter}{}{
Fred Drake28f13911998-03-04 21:47:59 +0000179 \renewcommand{\cleardoublepage}{
Fred Drake1c8d0e01998-03-07 05:29:15 +0000180 \clearpage\if@openright \ifodd\c@page\else
Fred Drake28f13911998-03-04 21:47:59 +0000181 \hbox{}
182 \thispagestyle{plain}
183 \newpage
Fred Drake1c8d0e01998-03-07 05:29:15 +0000184 \if@twocolumn\hbox{}\newpage\fi\fi\fi
Fred Drake28f13911998-03-04 21:47:59 +0000185 }
186 }
Fred Drake6659c301998-03-03 22:02:19 +0000187}
188
Fred Drake6659c301998-03-03 22:02:19 +0000189% This sets up the {verbatim} environment to be indented and a minipage,
190% and to have all the other mostly nice properties that we want for
191% code samples.
192
Fred Drake9466b9a1999-03-18 16:18:27 +0000193\let\py@OldVerbatim=\verbatim
194\let\py@OldEndVerbatim=\endverbatim
195\RequirePackage{verbatim}
Fred Drake00f712e2002-03-28 22:28:43 +0000196\let\py@OldVerbatimInput=\verbatiminput
Fred Drake9466b9a1999-03-18 16:18:27 +0000197
Fred Drake6659c301998-03-03 22:02:19 +0000198% Variable used by begin code command
Fred Drake24340ea1998-04-28 18:30:34 +0000199\newlength{\py@codewidth}
Fred Drake6659c301998-03-03 22:02:19 +0000200
Fred Drake6659c301998-03-03 22:02:19 +0000201\renewcommand{\verbatim}{%
Fred Drake9466b9a1999-03-18 16:18:27 +0000202 \setlength{\parindent}{1cm}%
Fred Drake6659c301998-03-03 22:02:19 +0000203 % Calculate the text width for the minipage:
Fred Drake24340ea1998-04-28 18:30:34 +0000204 \setlength{\py@codewidth}{\linewidth}%
205 \addtolength{\py@codewidth}{-\parindent}%
Fred Drake6659c301998-03-03 22:02:19 +0000206 %
Fred Drake9466b9a1999-03-18 16:18:27 +0000207 \par\indent%
Fred Drake24340ea1998-04-28 18:30:34 +0000208 \begin{minipage}[t]{\py@codewidth}%
Fred Drake6659c301998-03-03 22:02:19 +0000209 \small%
Fred Drake24340ea1998-04-28 18:30:34 +0000210 \py@OldVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000211}
212\renewcommand{\endverbatim}{%
Fred Drake24340ea1998-04-28 18:30:34 +0000213 \py@OldEndVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000214 \end{minipage}%
Fred Drake6659c301998-03-03 22:02:19 +0000215}
Fred Drake00f712e2002-03-28 22:28:43 +0000216\renewcommand{\verbatiminput}[1]{%
217 {\setlength{\parindent}{1cm}%
218 % Calculate the text width for the minipage:
219 \setlength{\py@codewidth}{\linewidth}%
220 \addtolength{\py@codewidth}{-\parindent}%
221 %
222 \small%
223 \begin{list}{}{\setlength{\leftmargin}{1cm}}
224 \item%
225 \py@OldVerbatimInput{#1}%
226 \end{list}
227 }%
228}
Fred Drake6659c301998-03-03 22:02:19 +0000229
Fred Drakeb5309a92001-04-10 15:53:06 +0000230% This does a similar thing for the {alltt} environment:
231\RequirePackage{alltt}
232\let\py@OldAllTT=\alltt
233\let\py@OldEndAllTT=\endalltt
234
235\renewcommand{\alltt}{%
236 \setlength{\parindent}{1cm}%
237 % Calculate the text width for the minipage:
238 \setlength{\py@codewidth}{\linewidth}%
239 \addtolength{\py@codewidth}{-\parindent}%
Fred Drake29f59332004-02-10 18:30:22 +0000240 \let\e=\textbackslash%
Fred Drakeb5309a92001-04-10 15:53:06 +0000241 %
242 \par\indent%
243 \begin{minipage}[t]{\py@codewidth}%
244 \small%
245 \py@OldAllTT%
246}
247\renewcommand{\endalltt}{%
248 \py@OldEndAllTT%
249 \end{minipage}%
250}
251
Fred Drake6cb71491998-03-27 05:22:53 +0000252
Fred Drakea488f301998-07-23 17:50:45 +0000253\newcommand{\py@modulebadkey}{{--just-some-junk--}}
Fred Drake6659c301998-03-03 22:02:19 +0000254
Fred Drake6659c301998-03-03 22:02:19 +0000255
256%% Lots of index-entry generation support.
257
258% Command to wrap around stuff that refers to function / module /
259% attribute names in the index. Default behavior: like \code{}. To
260% just keep the index entries in the roman font, uncomment the second
Fred Drakea488f301998-07-23 17:50:45 +0000261% definition; it matches O'Reilly style more.
Fred Drake6659c301998-03-03 22:02:19 +0000262%
Fred Drake24340ea1998-04-28 18:30:34 +0000263\newcommand{\py@idxcode}[1]{\texttt{#1}}
264%\renewcommand{\py@idxcode}[1]{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000265
266% Command to generate two index entries (using subentries)
267\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
268
269% And three entries (using only one level of subentries)
270\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
271
272% And four (again, using only one level of subentries)
273\newcommand{\indexiv}[4]{
274\index{#1!#2 #3 #4}
275\index{#2!#3 #4, #1}
276\index{#3!#4, #1 #2}
277\index{#4!#1 #2 #3}
278}
279
280% Command to generate a reference to a function, statement, keyword,
281% operator.
Fred Drake0cabff91998-05-06 19:36:01 +0000282\newcommand{\kwindex}[1]{\indexii{keyword}{#1@{\py@idxcode{#1}}}}
Fred Drake24340ea1998-04-28 18:30:34 +0000283\newcommand{\stindex}[1]{\indexii{statement}{#1@{\py@idxcode{#1}}}}
284\newcommand{\opindex}[1]{\indexii{operator}{#1@{\py@idxcode{#1}}}}
285\newcommand{\exindex}[1]{\indexii{exception}{#1@{\py@idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000286\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakea33c5662000-10-29 05:19:16 +0000287\newcommand{\bifuncindex}[1]{%
288 \index{#1@{\py@idxcode{#1()}} (built-in function)}}
Fred Drake6659c301998-03-03 22:02:19 +0000289
290% Add an index entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000291\newcommand{\py@refmodule}[2]{\index{#1@{\py@idxcode{#1}} (#2module)}}
292\newcommand{\refmodindex}[1]{\py@refmodule{#1}{}}
293\newcommand{\refbimodindex}[1]{\py@refmodule{#1}{built-in }}
294\newcommand{\refexmodindex}[1]{\py@refmodule{#1}{extension }}
295\newcommand{\refstmodindex}[1]{\py@refmodule{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000296
Fred Drakeda943741999-01-13 17:09:06 +0000297% Refer to a module's documentation using a hyperlink of the module's
298% name, at least if we're building PDF:
Fred Drakee59feb52001-10-29 21:02:28 +0000299\ifpdf
Fred Drakeaa2aea01999-01-27 17:37:36 +0000300 \newcommand{\refmodule}[2][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000301 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drakeaa2aea01999-01-27 17:37:36 +0000302 \py@linkToName{label-module-\py@modulekey}{\module{#2}}%
Fred Drakeda943741999-01-13 17:09:06 +0000303 }
Fred Drakee59feb52001-10-29 21:02:28 +0000304\else
305 \newcommand{\refmodule}[2][\py@modulebadkey]{\module{#2}}
306\fi
Fred Drakeda943741999-01-13 17:09:06 +0000307
Fred Drake6659c301998-03-03 22:02:19 +0000308% support for the module index
Fred Drake24340ea1998-04-28 18:30:34 +0000309\newif\ifpy@UseModuleIndex
310\py@UseModuleIndexfalse
Fred Drakeb390daf1998-03-09 16:35:36 +0000311
Fred Drakeb390daf1998-03-09 16:35:36 +0000312\newcommand{\makemodindex}{
313 \newwrite\modindexfile
314 \openout\modindexfile=mod\jobname.idx
Fred Drake24340ea1998-04-28 18:30:34 +0000315 \py@UseModuleIndextrue
Fred Drakeb390daf1998-03-09 16:35:36 +0000316}
317
Fred Drake0ee9f721998-03-12 06:41:40 +0000318% Add the defining entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000319\newcommand{\py@modindex}[2]{%
Fred Drakea488f301998-07-23 17:50:45 +0000320 \renewcommand{\py@thismodule}{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000321 \setindexsubitem{(in module #1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000322 \index{#1@{\py@idxcode{#1}} (#2module)|textbf}%
323 \ifpy@UseModuleIndex%
Fred Drake0c275fa1999-03-02 16:17:44 +0000324 \@ifundefined{py@modplat@\py@thismodulekey}{
325 \write\modindexfile{\protect\indexentry{#1@{\texttt{#1}}}{\thepage}}%
326 }{\write\modindexfile{\protect\indexentry{#1@{\texttt{#1} %
Fred Drake9466b9a1999-03-18 16:18:27 +0000327 \emph{(\py@platformof[\py@thismodulekey]{})}}}{\thepage}}%
Fred Drake0c275fa1999-03-02 16:17:44 +0000328 }
Fred Drake0ee9f721998-03-12 06:41:40 +0000329 \fi%
330}
331
Fred Drake9466b9a1999-03-18 16:18:27 +0000332% *** XXX *** THE NEXT FOUR MACROS ARE NOW OBSOLETE !!! ***
333
Fred Drake6659c301998-03-03 22:02:19 +0000334% built-in & Python modules in the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000335\newcommand{\bimodindex}[1]{\py@modindex{#1}{built-in }%
336 \typeout{*** MACRO bimodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
337\newcommand{\stmodindex}[1]{\py@modindex{#1}{standard }%
338 \typeout{*** MACRO stmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000339
340% Python & extension modules outside the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000341\newcommand{\modindex}[1]{\py@modindex{#1}{}%
342 \typeout{*** MACRO modindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
343\newcommand{\exmodindex}[1]{\py@modindex{#1}{extension }%
344 \typeout{*** MACRO exmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000345
346% Additional string for an index entry
Fred Drakeba828782000-04-03 04:19:14 +0000347\newif\ifpy@usingsubitem\py@usingsubitemfalse
348\newcommand{\py@indexsubitem}{}
349\newcommand{\setindexsubitem}[1]{\renewcommand{\py@indexsubitem}{ #1}%
350 \py@usingsubitemtrue}
351\newcommand{\ttindex}[1]{%
352 \ifpy@usingsubitem
353 \index{#1@{\py@idxcode{#1}}\py@indexsubitem}%
354 \else%
355 \index{#1@{\py@idxcode{#1}}}%
356 \fi%
357}
Fred Drake0ee9f721998-03-12 06:41:40 +0000358\newcommand{\withsubitem}[2]{%
359 \begingroup%
Fred Drakeec77e652000-10-30 06:22:22 +0000360 \def\ttindex##1{\index{##1@{\py@idxcode{##1}} #1}}%
361 #2%
Fred Drake0ee9f721998-03-12 06:41:40 +0000362 \endgroup%
363}
Fred Drake6659c301998-03-03 22:02:19 +0000364
Fred Drake53714971998-04-02 22:33:16 +0000365
Fred Drakea488f301998-07-23 17:50:45 +0000366% Module synopsis processing -----------------------------------------------
367%
Fred Drake0c275fa1999-03-02 16:17:44 +0000368\newcommand{\py@thisclass}{}
369\newcommand{\py@thismodule}{}
370\newcommand{\py@thismodulekey}{}
371\newcommand{\py@thismoduletype}{}
372
Fred Drake9466b9a1999-03-18 16:18:27 +0000373\newcommand{\py@standardIndexModule}[1]{\py@modindex{#1}{standard }}
374\newcommand{\py@builtinIndexModule}[1]{\py@modindex{#1}{built-in }}
375\newcommand{\py@extensionIndexModule}[1]{\py@modindex{#1}{extension }}
376\newcommand{\py@IndexModule}[1]{\py@modindex{#1}{}}
Fred Drakea488f301998-07-23 17:50:45 +0000377
Fred Drake0c275fa1999-03-02 16:17:44 +0000378\newif\ifpy@HaveModSynopsis \py@HaveModSynopsisfalse
379\newif\ifpy@ModSynopsisFileIsOpen \py@ModSynopsisFileIsOpenfalse
380\newif\ifpy@HaveModPlatform \py@HaveModPlatformfalse
Fred Drakea488f301998-07-23 17:50:45 +0000381
382% \declaremodule[key]{type}{name}
383\newcommand{\declaremodule}[3][\py@modulebadkey]{
384 \py@openModSynopsisFile
385 \renewcommand{\py@thismoduletype}{#2}
Fred Drakea488f301998-07-23 17:50:45 +0000386 \ifx\py@modulebadkey#1
387 \renewcommand{\py@thismodulekey}{#3}
388 \else
389 \renewcommand{\py@thismodulekey}{#1}
390 \fi
Fred Drake5bc8d991999-05-17 14:47:10 +0000391 \@ifundefined{py@#2IndexModule}{%
392 \typeout{*** MACRO declaremodule called with unknown module type: `#2'}
Fred Drake66823021999-05-17 14:57:26 +0000393 \py@IndexModule{#3}%
Fred Drake5bc8d991999-05-17 14:47:10 +0000394 }{%
395 \csname py@#2IndexModule\endcsname{#3}%
396 }
Fred Drakea488f301998-07-23 17:50:45 +0000397 \label{module-\py@thismodulekey}
Fred Drakea488f301998-07-23 17:50:45 +0000398}
Fred Drake0c275fa1999-03-02 16:17:44 +0000399\newif\ifpy@ModPlatformFileIsOpen \py@ModPlatformFileIsOpenfalse
400\newcommand{\py@ModPlatformFilename}{\jobname.pla}
401\newcommand{\platform}[1]{
402 \ifpy@ModPlatformFileIsOpen\else
403 \newwrite\py@ModPlatformFile
404 \openout\py@ModPlatformFile=\py@ModPlatformFilename
405 \py@ModPlatformFileIsOpentrue
406 \fi
Fred Drake0c275fa1999-03-02 16:17:44 +0000407}
408\InputIfFileExists{\jobname.pla}{}{}
Fred Drake9466b9a1999-03-18 16:18:27 +0000409\newcommand{\py@platformof}[2][\py@modulebadkey]{%
Fred Drake0c275fa1999-03-02 16:17:44 +0000410 \ifx\py@modulebadkey#1 \def\py@key{#2}%
411 \else \def\py@key{#1}%
412 \fi%
413 \csname py@modplat@\py@key\endcsname%
414}
415\newcommand{\ignorePlatformAnnotation}[1]{}
Fred Drakea488f301998-07-23 17:50:45 +0000416
Fred Drakeb75c6151998-08-10 18:41:43 +0000417% \moduleauthor{name}{email}
418\newcommand{\moduleauthor}[2]{}
419
420% \sectionauthor{name}{email}
421\newcommand{\sectionauthor}[2]{}
422
Fred Drakea488f301998-07-23 17:50:45 +0000423
424\newcommand{\py@defsynopsis}{Module has no synopsis.}
425\newcommand{\py@modulesynopsis}{\py@defsynopsis}
426\newcommand{\modulesynopsis}[1]{
Fred Drake0c275fa1999-03-02 16:17:44 +0000427 \py@HaveModSynopsistrue
Fred Drakea488f301998-07-23 17:50:45 +0000428 \renewcommand{\py@modulesynopsis}{#1}
429}
430
431% define the file
432\newwrite\py@ModSynopsisFile
433
434% hacked from \addtocontents from latex.ltx:
435\long\def\py@writeModSynopsisFile#1{%
436 \protected@write\py@ModSynopsisFile%
437 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
438 {\string#1}%
439}
440\newcommand{\py@closeModSynopsisFile}{
441 \ifpy@ModSynopsisFileIsOpen
442 \closeout\py@ModSynopsisFile
443 \py@ModSynopsisFileIsOpenfalse
444 \fi
445}
446\newcommand{\py@openModSynopsisFile}{
447 \ifpy@ModSynopsisFileIsOpen\else
448 \openout\py@ModSynopsisFile=\py@ModSynopsisFilename
449 \py@ModSynopsisFileIsOpentrue
450 \fi
451}
452
453\newcommand{\py@ProcessModSynopsis}{
454 \ifpy@HaveModSynopsis
455 \py@writeModSynopsisFile{\modulesynopsis%
456 {\py@thismodulekey}{\py@thismodule}%
457 {\py@thismoduletype}{\py@modulesynopsis}}%
458 \py@HaveModSynopsisfalse
459 \fi
460 \renewcommand{\py@modulesynopsis}{\py@defsynopsis}
461}
462\AtEndDocument{\py@ProcessModSynopsis\py@closeModSynopsisFile}
463
Fred Drake0c275fa1999-03-02 16:17:44 +0000464
465\long\def\py@writeModPlatformFile#1{%
466 \protected@write\py@ModPlatformFile%
467 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
468 {\string#1}%
469}
470
471
Fred Drakea488f301998-07-23 17:50:45 +0000472\newcommand{\localmoduletable}{
473 \IfFileExists{\py@ModSynopsisFilename}{
474 \begin{synopsistable}
475 \input{\py@ModSynopsisFilename}
476 \end{synopsistable}
477 }{}
478}
479
Fred Drakee59feb52001-10-29 21:02:28 +0000480\ifpdf
Fred Drakeaa2aea01999-01-27 17:37:36 +0000481 \newcommand{\py@ModSynopsisSummary}[4]{%
482 \py@linkToName{label-module-#1}{\bfcode{#2}} & #4\\
483 }
Fred Drakee59feb52001-10-29 21:02:28 +0000484\else
485 \newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
486\fi
Fred Drakea488f301998-07-23 17:50:45 +0000487\newenvironment{synopsistable}{
488 % key, name, type, synopsis
489 \let\modulesynopsis=\py@ModSynopsisSummary
490 \begin{tabular}{ll}
491}{
492 \end{tabular}
493}
494%
495% --------------------------------------------------------------------------
496
497
Fred Drakea488f301998-07-23 17:50:45 +0000498\newcommand{\py@reset}{
Fred Drakeba828782000-04-03 04:19:14 +0000499 \py@usingsubitemfalse
Fred Drakea488f301998-07-23 17:50:45 +0000500 \py@ProcessModSynopsis
501 \renewcommand{\py@thisclass}{}
502 \renewcommand{\py@thismodule}{}
503 \renewcommand{\py@thismodulekey}{}
504 \renewcommand{\py@thismoduletype}{}
505}
506
507% Augment the sectioning commands used to get our own font family in place,
508% and reset some internal data items:
509\renewcommand{\section}{\py@reset%
510 \@startsection{section}{1}{\z@}%
511 {-3.5ex \@plus -1ex \@minus -.2ex}%
512 {2.3ex \@plus.2ex}%
513 {\reset@font\Large\py@HeaderFamily}}
514\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
515 {-3.25ex\@plus -1ex \@minus -.2ex}%
516 {1.5ex \@plus .2ex}%
517 {\reset@font\large\py@HeaderFamily}}
518\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
519 {-3.25ex\@plus -1ex \@minus -.2ex}%
520 {1.5ex \@plus .2ex}%
521 {\reset@font\normalsize\py@HeaderFamily}}
522\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
523 {3.25ex \@plus1ex \@minus.2ex}%
524 {-1em}%
525 {\reset@font\normalsize\py@HeaderFamily}}
526\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
527 {3.25ex \@plus1ex \@minus .2ex}%
528 {-1em}%
529 {\reset@font\normalsize\py@HeaderFamily}}
530
531
Fred Drake5420f331998-07-23 21:41:02 +0000532% This gets the underscores closer to the right width; the only change
533% from standard LaTeX is the width specified.
534
535\DeclareTextCommandDefault{\textunderscore}{%
536 \leavevmode \kern.06em\vbox{\hrule\@width.55em}}
537
Fred Drakea488f301998-07-23 17:50:45 +0000538% Underscore hack (only act like subscript operator if in math mode)
539%
540% The following is due to Mark Wooding (the old version didn't work with
541% Latex 2e.
542
543\DeclareRobustCommand\hackscore{%
544 \ifmmode_\else\textunderscore\fi%
545}
546\begingroup
547\catcode`\_\active
548\def\next{%
549 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
550}
551\expandafter\endgroup\next
552
553
Fred Drake53714971998-04-02 22:33:16 +0000554% Now for a lot of semantically-loaded environments that do a ton of magical
555% things to get the right formatting and index entries for the stuff in
556% Python modules and C API.
557
558
Fred Drake6659c301998-03-03 22:02:19 +0000559% {fulllineitems} is used in one place in libregex.tex, but is really for
560% internal use in this file.
561%
Fred Drakef9acc591998-09-09 15:27:43 +0000562\newcommand{\py@itemnewline}[1]{%
563 \@tempdima\linewidth%
564 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
565}
566
Fred Drake6659c301998-03-03 22:02:19 +0000567\newenvironment{fulllineitems}{
568 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
569 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
570 \itemsep -\parsep
Fred Drakef9acc591998-09-09 15:27:43 +0000571 \let\makelabel=\py@itemnewline}
Fred Drake6659c301998-03-03 22:02:19 +0000572}{\end{list}}
573
Fred Drake6cb71491998-03-27 05:22:53 +0000574% \optional is mostly for use in the arguments parameters to the various
575% {*desc} environments defined below, but may be used elsewhere. Known to
576% be used in the debugger chapter.
Fred Drake24340ea1998-04-28 18:30:34 +0000577%
578% Typical usage:
579%
580% \begin{funcdesc}{myfunc}{reqparm\optional{, optparm}}
581% ^^^ ^^^
582% No space here No space here
583%
584% When a function has multiple optional parameters, \optional should be
585% nested, not chained. This is right:
586%
587% \begin{funcdesc}{myfunc}{\optional{parm1\optional{, parm2}}}
588%
Fred Drakeba828782000-04-03 04:19:14 +0000589\let\py@badkey=\@undefined
590
Fred Drake6659c301998-03-03 22:02:19 +0000591\newcommand{\optional}[1]{%
592 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
593
Fred Drakeba828782000-04-03 04:19:14 +0000594% This can be used when a function or method accepts an varying number
595% of arguments, such as by using the *args syntax in the parameter list.
596\newcommand{\py@moreargs}{...}
597
598% This can be used when you don't want to document the parameters to a
599% function or method, but simply state that it's an alias for
600% something else.
601\newcommand{\py@unspecified}{...}
602
Fred Drakead74b7d2002-07-02 20:32:50 +0000603
604\newlength{\py@argswidth}
605\newcommand{\py@sigparams}[1]{%
606 \parbox[t]{\py@argswidth}{\py@varvars{#1}\code{)}}}
607\newcommand{\py@sigline}[2]{%
608 \settowidth{\py@argswidth}{#1\code{(}}%
609 \addtolength{\py@argswidth}{-2\py@argswidth}%
610 \addtolength{\py@argswidth}{\textwidth}%
611 \item[#1\code{(}\py@sigparams{#2}]}
612
Fred Drake6cb71491998-03-27 05:22:53 +0000613% C functions ------------------------------------------------------------
Fred Drakeba828782000-04-03 04:19:14 +0000614% \begin{cfuncdesc}[refcount]{type}{name}{arglist}
615% Note that the [refcount] slot should only be filled in by
616% tools/anno-api.py; it pulls the value from the refcounts database.
Fred Drake34adb8a2002-04-15 20:48:40 +0000617\newcommand{\cfuncline}[3]{
Fred Drakead74b7d2002-07-02 20:32:50 +0000618 \py@sigline{\code{#1 \bfcode{#2}}}{#3}%
619 \index{#2@{\py@idxcode{#2()}}}
Fred Drake34adb8a2002-04-15 20:48:40 +0000620}
Fred Drakeba828782000-04-03 04:19:14 +0000621\newenvironment{cfuncdesc}[4][\py@badkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000622 \begin{fulllineitems}
Fred Drake34adb8a2002-04-15 20:48:40 +0000623 \cfuncline{#2}{#3}{#4}
Fred Drakeba828782000-04-03 04:19:14 +0000624 \ifx#1\@undefined\else%
Fred Drake0a863da2000-04-10 18:21:38 +0000625 \emph{Return value: \textbf{#1}.}\\
Fred Drakeba828782000-04-03 04:19:14 +0000626 \fi
Fred Drake6cb71491998-03-27 05:22:53 +0000627}{\end{fulllineitems}}
628
629% C variables ------------------------------------------------------------
630% \begin{cvardesc}{type}{name}
631\newenvironment{cvardesc}[2]{
632 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000633 \item[\code{#1 \bfcode{#2}}\index{#2@{\py@idxcode{#2}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000634}{\end{fulllineitems}}
635
636% C data types -----------------------------------------------------------
Fred Drakeba828782000-04-03 04:19:14 +0000637% \begin{ctypedesc}[index name]{typedef name}
638\newenvironment{ctypedesc}[2][\py@badkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000639 \begin{fulllineitems}
Fred Drakeba828782000-04-03 04:19:14 +0000640 \item[\bfcode{#2}%
641 \ifx#1\@undefined%
Fred Drakea33c5662000-10-29 05:19:16 +0000642 \index{#2@{\py@idxcode{#2}} (C type)}
Fred Drakeba828782000-04-03 04:19:14 +0000643 \else%
Fred Drakea33c5662000-10-29 05:19:16 +0000644 \index{#2@{\py@idxcode{#1}} (C type)}
Fred Drakeba828782000-04-03 04:19:14 +0000645 \fi]
646}{\end{fulllineitems}}
647
Fred Drake01e94612002-04-12 22:48:02 +0000648% C type fields ----------------------------------------------------------
649% \begin{cmemberdesc}{container type}{ctype}{membername}
650\newcommand{\cmemberline}[3]{
651 \item[\code{#2 \bfcode{#3}}]
652 \index{#3@{\py@idxcode{#3}} (#1 member)}
653}
654\newenvironment{cmemberdesc}[3]{
655 \begin{fulllineitems}
656 \cmemberline{#1}{#2}{#3}
657}{\end{fulllineitems}}
658
Fred Drakeba828782000-04-03 04:19:14 +0000659% Funky macros -----------------------------------------------------------
Fred Drake19f827e2002-04-09 20:16:47 +0000660% \begin{csimplemacrodesc}{name}
Fred Drakeba828782000-04-03 04:19:14 +0000661% -- "simple" because it has no args; NOT for constant definitions!
662\newenvironment{csimplemacrodesc}[1]{
663 \begin{fulllineitems}
Fred Drakea33c5662000-10-29 05:19:16 +0000664 \item[\bfcode{#1}\index{#1@{\py@idxcode{#1}} (macro)}]
Fred Drake6cb71491998-03-27 05:22:53 +0000665}{\end{fulllineitems}}
666
667% simple functions (not methods) -----------------------------------------
668% \begin{funcdesc}{name}{args}
Fred Drakeec77e652000-10-30 06:22:22 +0000669\newcommand{\funcline}[2]{%
670 \funclineni{#1}{#2}%
671 \index{#1@{\py@idxcode{#1()}} (in module \py@thismodule)}}
Fred Drake6cb71491998-03-27 05:22:53 +0000672\newenvironment{funcdesc}[2]{
673 \begin{fulllineitems}
674 \funcline{#1}{#2}
675}{\end{fulllineitems}}
676
Fred Drake6659c301998-03-03 22:02:19 +0000677% similar to {funcdesc}, but doesn't add to the index
Fred Drakead74b7d2002-07-02 20:32:50 +0000678\newcommand{\funclineni}[2]{%
679 \py@sigline{\bfcode{#1}}{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000680\newenvironment{funcdescni}[2]{
681 \begin{fulllineitems}
682 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000683}{\end{fulllineitems}}
684
Fred Drake6cb71491998-03-27 05:22:53 +0000685% classes ----------------------------------------------------------------
686% \begin{classdesc}{name}{constructor args}
687\newenvironment{classdesc}[2]{
Fred Drake1cbd1961998-11-25 17:13:28 +0000688 % Using \renewcommand doesn't work for this, for unknown reasons:
689 \global\def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000690 \begin{fulllineitems}
Fred Drakead74b7d2002-07-02 20:32:50 +0000691 \py@sigline{\strong{class }\bfcode{#1}}{#2}%
692 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}
Fred Drake6659c301998-03-03 22:02:19 +0000693}{\end{fulllineitems}}
694
Fred Drake06a01e82001-05-11 01:00:30 +0000695% \begin{classdesc*}{name}
696\newenvironment{classdesc*}[1]{
697 % Using \renewcommand doesn't work for this, for unknown reasons:
698 \global\def\py@thisclass{#1}
699 \begin{fulllineitems}
700 \item[\strong{class }\code{\bfcode{#1}}%
701 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}]
702}{\end{fulllineitems}}
703
Fred Drake4e607962000-09-09 06:01:25 +0000704% \begin{excclassdesc}{name}{constructor args}
705% but indexes as an exception
706\newenvironment{excclassdesc}[2]{
707 % Using \renewcommand doesn't work for this, for unknown reasons:
708 \global\def\py@thisclass{#1}
709 \begin{fulllineitems}
Fred Drakead74b7d2002-07-02 20:32:50 +0000710 \py@sigline{\strong{exception }\bfcode{#1}}{#2}%
711 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}
Fred Drake4e607962000-09-09 06:01:25 +0000712}{\end{fulllineitems}}
713
Fred Drake06a01e82001-05-11 01:00:30 +0000714% There is no corresponding {excclassdesc*} environment. To describe
715% a class exception without parameters, use the {excdesc} environment.
716
Fred Drake6cb71491998-03-27 05:22:53 +0000717
Fred Drake24340ea1998-04-28 18:30:34 +0000718\let\py@classbadkey=\@undefined
Fred Drake6cb71491998-03-27 05:22:53 +0000719
720% object method ----------------------------------------------------------
721% \begin{methoddesc}[classname]{methodname}{args}
Fred Drakea33c5662000-10-29 05:19:16 +0000722\newcommand{\methodline}[3][\@undefined]{
Fred Drake6cb71491998-03-27 05:22:53 +0000723 \methodlineni{#2}{#3}
724 \ifx#1\@undefined
Fred Drakea33c5662000-10-29 05:19:16 +0000725 \index{#2@{\py@idxcode{#2()}} (\py@thisclass\ method)}
Fred Drake6cb71491998-03-27 05:22:53 +0000726 \else
Fred Drakea33c5662000-10-29 05:19:16 +0000727 \index{#2@{\py@idxcode{#2()}} (#1 method)}
Fred Drake6cb71491998-03-27 05:22:53 +0000728 \fi
729}
Fred Drakea33c5662000-10-29 05:19:16 +0000730\newenvironment{methoddesc}[3][\@undefined]{
Fred Drake6cb71491998-03-27 05:22:53 +0000731 \begin{fulllineitems}
732 \ifx#1\@undefined
733 \methodline{#2}{#3}
734 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000735 \def\py@thisclass{#1}
Fred Drakea33c5662000-10-29 05:19:16 +0000736 \methodline{#2}{#3}
Fred Drake6cb71491998-03-27 05:22:53 +0000737 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000738}{\end{fulllineitems}}
739
Fred Drake6cb71491998-03-27 05:22:53 +0000740% similar to {methoddesc}, but doesn't add to the index
741% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000742\newcommand{\methodlineni}[3][\py@classbadkey]{%
Fred Drakead74b7d2002-07-02 20:32:50 +0000743 \py@sigline{\bfcode{#2}}{#3}}
Fred Drake24340ea1998-04-28 18:30:34 +0000744\newenvironment{methoddescni}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000745 \begin{fulllineitems}
746 \methodlineni{#2}{#3}
747}{\end{fulllineitems}}
748
749% object data attribute --------------------------------------------------
750% \begin{memberdesc}[classname]{membername}
Fred Drake24340ea1998-04-28 18:30:34 +0000751\newcommand{\memberline}[2][\py@classbadkey]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000752 \ifx#1\@undefined
753 \memberlineni{#2}
Fred Drakea33c5662000-10-29 05:19:16 +0000754 \index{#2@{\py@idxcode{#2}} (\py@thisclass\ attribute)}
Fred Drake6cb71491998-03-27 05:22:53 +0000755 \else
756 \memberlineni{#2}
Fred Drakea33c5662000-10-29 05:19:16 +0000757 \index{#2@{\py@idxcode{#2}} (#1 attribute)}
Fred Drake6cb71491998-03-27 05:22:53 +0000758 \fi
759}
Fred Drake24340ea1998-04-28 18:30:34 +0000760\newenvironment{memberdesc}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000761 \begin{fulllineitems}
762 \ifx#1\@undefined
763 \memberline{#2}
764 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000765 \def\py@thisclass{#1}
Fred Drakea33c5662000-10-29 05:19:16 +0000766 \memberline{#2}
Fred Drake6cb71491998-03-27 05:22:53 +0000767 \fi
768}{\end{fulllineitems}}
769
770% similar to {memberdesc}, but doesn't add to the index
771% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000772\newcommand{\memberlineni}[2][\py@classbadkey]{\item[\bfcode{#2}]}
773\newenvironment{memberdescni}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000774 \begin{fulllineitems}
775 \memberlineni{#2}
776}{\end{fulllineitems}}
777
778% For exceptions: --------------------------------------------------------
779% \begin{excdesc}{name}
Fred Drakea33c5662000-10-29 05:19:16 +0000780% -- for constructor information, use excclassdesc instead
Fred Drake6cb71491998-03-27 05:22:53 +0000781\newenvironment{excdesc}[1]{
782 \begin{fulllineitems}
Fred Drakeab357ec2001-03-02 18:57:05 +0000783 \item[\strong{exception }\bfcode{#1}%
Fred Drakea33c5662000-10-29 05:19:16 +0000784 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}]
Fred Drake6cb71491998-03-27 05:22:53 +0000785}{\end{fulllineitems}}
786
787% Module data or constants: ----------------------------------------------
788% \begin{datadesc}{name}
Fred Drakea33c5662000-10-29 05:19:16 +0000789\newcommand{\dataline}[1]{%
790 \datalineni{#1}\index{#1@{\py@idxcode{#1}} (data in \py@thismodule)}}
Fred Drake6cb71491998-03-27 05:22:53 +0000791\newenvironment{datadesc}[1]{
792 \begin{fulllineitems}
793 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000794}{\end{fulllineitems}}
795
796% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000797\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
798\newenvironment{datadescni}[1]{
799 \begin{fulllineitems}
800 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000801}{\end{fulllineitems}}
802
Fred Drake6cb71491998-03-27 05:22:53 +0000803% bytecode instruction ---------------------------------------------------
804% \begin{opcodedesc}{name}{var}
805% -- {var} may be {}
806\newenvironment{opcodedesc}[2]{
807 \begin{fulllineitems}
808 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000809}{\end{fulllineitems}}
810
811
Fred Drake24340ea1998-04-28 18:30:34 +0000812\newcommand{\nodename}[1]{\label{#1}}
Fred Drake55730311998-03-25 15:41:23 +0000813
Fred Drake6659c301998-03-03 22:02:19 +0000814% For these commands, use \command{} to get the typography right, not
815% {\command}. This works better with the texinfo translation.
816\newcommand{\ABC}{{\sc abc}}
817\newcommand{\UNIX}{{\sc Unix}}
818\newcommand{\POSIX}{POSIX}
819\newcommand{\ASCII}{{\sc ascii}}
820\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
821\newcommand{\C}{C}
822\newcommand{\EOF}{{\sc eof}}
Fred Drake24340ea1998-04-28 18:30:34 +0000823\newcommand{\NULL}{\constant{NULL}}
Fred Drake5445e5e2001-06-23 03:11:45 +0000824\newcommand{\infinity}{\ensuremath{\infty}}
825\newcommand{\plusminus}{\ensuremath{\pm}}
Fred Drakef0f6d122004-01-23 08:52:28 +0000826
827% \guilabel{Start}
828\newcommand{\guilabel}[1]{\textsf{#1}}
Fred Drakeb4812862002-08-02 18:30:22 +0000829% \menuselection{Start \sub Programs \sub Python}
Fred Drakef0f6d122004-01-23 08:52:28 +0000830\newcommand{\menuselection}[1]{\guilabel{{\def\sub{ \ensuremath{>} }#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000831
Fred Drake53714971998-04-02 22:33:16 +0000832% Also for consistency: spell Python "Python", not "python"!
833
Fred Drake6659c301998-03-03 22:02:19 +0000834% code is the most difficult one...
Fred Drake46346ec2000-06-30 17:57:05 +0000835\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 +0000836\texttt{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000837
838\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Fred Drake19f827e2002-04-09 20:16:47 +0000839\newcommand{\csimplemacro}[1]{\code{#1}}
Fred Drake8e54abe1998-07-01 14:49:25 +0000840\newcommand{\kbd}[1]{\code{#1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000841\newcommand{\samp}[1]{`\code{#1}'}
Fred Drakefa1cceb1998-11-30 14:42:59 +0000842\newcommand{\var}[1]{%
843 \ifmmode%
Fred Drakeff031cf2002-10-31 21:04:34 +0000844 \hbox{\py@defaultsize\textrm{\textit{#1\/}}}%
Fred Drakefa1cceb1998-11-30 14:42:59 +0000845 \else%
Fred Drakeff031cf2002-10-31 21:04:34 +0000846 \py@defaultsize\textrm{\textit{#1\/}}%
Fred Drakefa1cceb1998-11-30 14:42:59 +0000847 \fi%
848}
Fred Drake24340ea1998-04-28 18:30:34 +0000849\renewcommand{\emph}[1]{{\em #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000850\newcommand{\dfn}[1]{\emph{#1}}
851\newcommand{\strong}[1]{{\bf #1}}
852% let's experiment with a new font:
Fred Drakeff031cf2002-10-31 21:04:34 +0000853\newcommand{\file}[1]{`\filenq{#1}'}
Fred Drake52feb812004-02-09 20:58:08 +0000854\newcommand{\filenq}[1]{{\py@smallsize\textsf{\let\e=\textbackslash#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000855
856% Use this def/redef approach for \url{} since hyperref defined this already,
857% but only if we actually used hyperref:
Fred Drakee59feb52001-10-29 21:02:28 +0000858\ifpdf
859 \newcommand{\url}[1]{{%
Fred Drake15fc72c2002-03-26 19:14:41 +0000860 \noindent%
Fred Drake53815882002-03-15 23:21:37 +0000861 \pdfstartlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
Fred Drakeab357ec2001-03-02 18:57:05 +0000862 \py@LinkColor% color of the link text
Fred Drakeff031cf2002-10-31 21:04:34 +0000863 \py@smallsize\sf #1%
Fred Drakeab357ec2001-03-02 18:57:05 +0000864 \py@NormalColor% Turn it back off; these are declarative
865 \pdfendlink}% and don't appear bound to the current
866 }% formatting "box".
Fred Drakee59feb52001-10-29 21:02:28 +0000867\else
Fred Drakeff031cf2002-10-31 21:04:34 +0000868 \newcommand{\url}[1]{\mbox{\py@smallsize\textsf{#1}}}
Fred Drakee59feb52001-10-29 21:02:28 +0000869\fi
Fred Drakeff031cf2002-10-31 21:04:34 +0000870\newcommand{\email}[1]{{\py@smallsize\textsf{#1}}}
871\newcommand{\newsgroup}[1]{{\py@smallsize\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000872
Fred Drakecc2b81e2000-08-03 17:38:30 +0000873\newcommand{\py@varvars}[1]{{%
Fred Drakeba828782000-04-03 04:19:14 +0000874 {\let\unspecified=\py@unspecified%
875 \let\moreargs=\py@moreargs%
Fred Drakecc2b81e2000-08-03 17:38:30 +0000876 \var{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000877
Fred Drake24340ea1998-04-28 18:30:34 +0000878% I'd really like to get rid of this!
Fred Drake6659c301998-03-03 22:02:19 +0000879\newif\iftexi\texifalse
Fred Drake6659c301998-03-03 22:02:19 +0000880
Fred Drake1e4973b1998-07-28 21:52:17 +0000881% This is used to get l2h to put the copyright and abstract on
882% a separate HTML page.
883\newif\ifhtml\htmlfalse
884
885
Fred Drake6659c301998-03-03 22:02:19 +0000886% These should be used for all references to identifiers which are
887% used to refer to instances of specific language constructs. See the
888% names for specific semantic assignments.
889%
890% For now, don't do anything really fancy with them; just use them as
891% logical markup. This might change in the future.
892%
Fred Drake24340ea1998-04-28 18:30:34 +0000893\newcommand{\module}[1]{\texttt{#1}}
894\newcommand{\keyword}[1]{\texttt{#1}}
895\newcommand{\exception}[1]{\texttt{#1}}
896\newcommand{\class}[1]{\texttt{#1}}
897\newcommand{\function}[1]{\texttt{#1}}
898\newcommand{\member}[1]{\texttt{#1}}
899\newcommand{\method}[1]{\texttt{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000900
Fred Drakeab357ec2001-03-02 18:57:05 +0000901\newcommand{\pytype}[1]{#1} % built-in Python type
Fred Drake53714971998-04-02 22:33:16 +0000902
Fred Drake24340ea1998-04-28 18:30:34 +0000903\newcommand{\cfunction}[1]{\texttt{#1}}
Fred Drakeab357ec2001-03-02 18:57:05 +0000904\newcommand{\ctype}[1]{\texttt{#1}} % C struct or typedef name
905\newcommand{\cdata}[1]{\texttt{#1}} % C variable, typically global
Fred Drake6659c301998-03-03 22:02:19 +0000906
Fred Drakeff031cf2002-10-31 21:04:34 +0000907\newcommand{\mailheader}[1]{{\py@smallsize\textsf{#1:}}}
908\newcommand{\mimetype}[1]{{\py@smallsize\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000909% The \! is a "negative thin space" in math mode.
910\newcommand{\regexp}[1]{%
911 {\tiny$^{^\lceil}\!\!$%
Fred Drakeff031cf2002-10-31 21:04:34 +0000912 {\py@defaultsize\code{#1}}%
Fred Drake47cfd031998-04-03 21:22:31 +0000913 $\!\rfloor\!$%
Fred Drake94fac131998-03-12 19:37:03 +0000914 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000915\newcommand{\envvar}[1]{%
Fred Drake31ab2982001-01-22 17:50:42 +0000916 #1%
Fred Drakee59feb52001-10-29 21:02:28 +0000917 \index{#1}%
Fred Drake31ab2982001-01-22 17:50:42 +0000918 \index{environment variables!{#1}}%
Fred Drake0ee9f721998-03-12 06:41:40 +0000919}
Fred Drakeab357ec2001-03-02 18:57:05 +0000920\newcommand{\makevar}[1]{#1} % variable in a Makefile
Fred Drake24340ea1998-04-28 18:30:34 +0000921\newcommand{\character}[1]{\samp{#1}}
Fred Drake0ee9f721998-03-12 06:41:40 +0000922
Fred Drake6659c301998-03-03 22:02:19 +0000923% constants defined in Python modules or C headers, not language constants:
Fred Drakeab357ec2001-03-02 18:57:05 +0000924\newcommand{\constant}[1]{\code{#1}} % manifest constant, not syntactic
Fred Drake6659c301998-03-03 22:02:19 +0000925
926\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake4e607962000-09-09 06:01:25 +0000927\newcommand{\pep}[1]{PEP #1\index{Python Enhancement Proposals!PEP #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000928\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
929\newcommand{\program}[1]{\strong{#1}}
Fred Drake7b8195a1999-11-09 17:02:11 +0000930\newcommand{\programopt}[1]{\strong{#1}}
Fred Drake49362492000-04-11 18:47:59 +0000931% Note that \longprogramopt provides the '--'!
932\newcommand{\longprogramopt}[1]{\strong{-{}-#1}}
Fred Drakee59feb52001-10-29 21:02:28 +0000933
Fred Drakeb4b64da2001-07-06 22:44:48 +0000934% \ulink{link text}{URL}
Fred Drakee59feb52001-10-29 21:02:28 +0000935\ifpdf
936 % The \noindent here is a hack -- we're forcing pdfTeX into
Fred Drake53815882002-03-15 23:21:37 +0000937 % horizontal mode since \pdfstartlink requires that.
Fred Drakec8b08b42003-09-06 04:19:43 +0000938 % For PDF, we *should* only generate a link when the URL is absolute.
Fred Drakee59feb52001-10-29 21:02:28 +0000939 \newcommand{\ulink}[2]{\noindent{%
Fred Drake53815882002-03-15 23:21:37 +0000940 \pdfstartlink attr{/Border [0 0 0]} user{/S /URI /URI (#2)}%
Fred Drakee59feb52001-10-29 21:02:28 +0000941 \py@LinkColor% color of the link text
942 #1%
943 \py@NormalColor% Turn it back off; these are declarative
944 \pdfendlink}% and don't appear bound to the current
945 }% formatting "box".
946\else
947 \newcommand{\ulink}[2]{#1}
948\fi
Fred Drake7b8195a1999-11-09 17:02:11 +0000949
950% cited titles: \citetitle{Title of Work}
951% online: \citetitle[url-to-resource]{Title of Work}
Fred Drakee59feb52001-10-29 21:02:28 +0000952\ifpdf
953 \newcommand{\citetitle}[2][\py@modulebadkey]{%
954 \ifx\py@modulebadkey#1\emph{#2}\else\ulink{\emph{#2}}{#1}\fi%
955 }
956\else
Fred Drake622087a2001-11-02 20:53:19 +0000957 \newcommand{\citetitle}[2][URL]{\emph{#2}}
Fred Drakee59feb52001-10-29 21:02:28 +0000958\fi
959
Fred Drake6659c301998-03-03 22:02:19 +0000960
961
Fred Drakec82bd722001-12-11 18:47:36 +0000962% This version is being checked in for the historical record; it shows
963% how I've managed to get some aspects of this to work. It will not
964% be used in practice, so a subsequent revision will change things
965% again. This version has problems, but shows how to do something
966% that proved more tedious than I'd expected, so I don't want to lose
967% the example completely.
968%
Fred Drake16bb4192001-08-20 21:36:38 +0000969\newcommand{\grammartoken}[1]{\texttt{#1}}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000970\newenvironment{productionlist}[1][\py@badkey]{
971 \def\optional##1{{\Large[}##1{\Large]}}
972 \def\production##1##2{\code{##1}&::=&\code{##2}\\}
Fred Drake53815882002-03-15 23:21:37 +0000973 \def\productioncont##1{& &\code{##1}\\}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000974 \def\token##1{##1}
Fred Drake16bb4192001-08-20 21:36:38 +0000975 \let\grammartoken=\token
Fred Drakec82bd722001-12-11 18:47:36 +0000976 \parindent=2em
977 \indent
978 \begin{tabular}{lcl}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000979}{%
Fred Drakec82bd722001-12-11 18:47:36 +0000980 \end{tabular}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000981}
982
Fred Drake862b46b2004-03-31 08:08:34 +0000983\newlength{\py@noticelength}
984
985\newcommand{\py@heavybox}{
986 \setlength{\fboxrule}{2pt}
987 \setlength{\fboxsep}{7pt}
988 \setlength{\py@noticelength}{\linewidth}
989 \addtolength{\py@noticelength}{-2\fboxsep}
990 \addtolength{\py@noticelength}{-2\fboxrule}
991 \setlength{\shadowsize}{3pt}
992 \Sbox
993 \minipage{\py@noticelength}
994}
995\newcommand{\py@endheavybox}{
996 \endminipage
997 \endSbox
998 \fbox{\TheSbox}
999}
1000
1001% a 'note' is as plain as it gets:
Fred Drake6ca33772001-12-14 22:50:06 +00001002\newcommand{\py@noticelabel@note}{Note:}
Fred Drake862b46b2004-03-31 08:08:34 +00001003\newcommand{\py@noticestart@note}{}
1004\newcommand{\py@noticeend@note}{}
1005
1006% a 'warning' gets more visible distinction:
Fred Drake6ca33772001-12-14 22:50:06 +00001007\newcommand{\py@noticelabel@warning}{Warning:}
Fred Drake862b46b2004-03-31 08:08:34 +00001008\newcommand{\py@noticestart@warning}{\py@heavybox}
1009\newcommand{\py@noticeend@warning}{\py@endheavybox}
1010
Fred Drake6ca33772001-12-14 22:50:06 +00001011\newenvironment{notice}[1][note]{
Fred Drake862b46b2004-03-31 08:08:34 +00001012 \def\py@noticetype{#1}
1013 \csname py@noticestart@#1\endcsname
Fred Drake6ca33772001-12-14 22:50:06 +00001014 \par\strong{\csname py@noticelabel@#1\endcsname}
Fred Drake862b46b2004-03-31 08:08:34 +00001015}{\csname py@noticeend@\py@noticetype\endcsname}
Fred Drake6ca33772001-12-14 22:50:06 +00001016\newcommand{\note}[1]{\strong{\py@noticelabel@note} #1}
1017\newcommand{\warning}[1]{\strong{\py@noticelabel@warning} #1}
Fred Drake92350b32001-10-09 18:01:23 +00001018
Fred Drake6659c301998-03-03 22:02:19 +00001019% Deprecation stuff.
1020% Should be extended to allow an index / list of deprecated stuff. But
1021% there's a lot of stuff that needs to be done to make that automatable.
1022%
1023% First parameter is the release number that deprecates the feature, the
1024% second is the action the should be taken by users of the feature.
1025%
1026% Example:
Fred Drake24340ea1998-04-28 18:30:34 +00001027% \deprecated{1.5.1}{Use \method{frobnicate()} instead.}
Fred Drake6659c301998-03-03 22:02:19 +00001028%
1029\newcommand{\deprecated}[2]{%
1030 \strong{Deprecated since release #1.} #2\par}
1031
Fred Drakeaf958c71998-07-27 20:32:33 +00001032% New stuff.
1033% This should be used to mark things which have been added to the
1034% development tree but that aren't in the release, but are documented.
1035% This allows release of documentation that already includes updated
Fred Drake2116d981999-02-02 18:02:48 +00001036% descriptions. Place at end of descriptor environment.
Fred Drakeaf958c71998-07-27 20:32:33 +00001037%
1038% Example:
1039% \versionadded{1.5.2}
Fred Drake46346ec2000-06-30 17:57:05 +00001040% \versionchanged[short explanation]{2.0}
Fred Drakeaf958c71998-07-27 20:32:33 +00001041%
Fred Drakefdfb05b2001-04-18 03:08:54 +00001042\newcommand{\versionadded}[2][\py@badkey]{%
1043 \ifx#1\@undefined%
1044 { New in version #2. }%
1045 \else%
1046 { New in version #2:\ #1. }%
1047 \fi%
1048}
Fred Drakea6e83392000-05-02 17:28:36 +00001049\newcommand{\versionchanged}[2][\py@badkey]{%
1050 \ifx#1\@undefined%
1051 { Changed in version #2. }%
1052 \else%
1053 { Changed in version #2:\ #1. }%
1054 \fi%
1055}
Fred Drake6659c301998-03-03 22:02:19 +00001056
Fred Drakeaf958c71998-07-27 20:32:33 +00001057
1058% Tables.
1059%
Fred Drake6659c301998-03-03 22:02:19 +00001060\newenvironment{tableii}[4]{%
1061 \begin{center}%
1062 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakef61eac42000-10-24 02:18:30 +00001063 \begin{tabular}{#1}\strong{#3}&\strong{#4} \\* \hline%
Fred Drake6659c301998-03-03 22:02:19 +00001064}{%
Fred Drake6659c301998-03-03 22:02:19 +00001065 \end{tabular}%
1066 \end{center}%
1067}
1068
Fred Drakeda72b932000-09-21 15:58:02 +00001069\newenvironment{longtableii}[4]{%
1070 \begin{center}%
1071 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakef61eac42000-10-24 02:18:30 +00001072 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4} \\* \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001073}{%
1074 \end{longtable}%
1075 \end{center}%
1076}
1077
Fred Drake6659c301998-03-03 22:02:19 +00001078\newenvironment{tableiii}[5]{%
1079 \begin{center}%
1080 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
Fred Drakeda72b932000-09-21 15:58:02 +00001081 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001082 \hline%
Fred Drake6659c301998-03-03 22:02:19 +00001083}{%
Fred Drake6659c301998-03-03 22:02:19 +00001084 \end{tabular}%
1085 \end{center}%
1086}
1087
Fred Drakeda72b932000-09-21 15:58:02 +00001088\newenvironment{longtableiii}[5]{%
1089 \begin{center}%
1090 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
1091 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001092 \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001093}{%
1094 \end{longtable}%
1095 \end{center}%
1096}
1097
Fred Drake30e52651998-07-24 22:11:29 +00001098\newenvironment{tableiv}[6]{%
1099 \begin{center}%
1100 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
1101 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001102 \hline%
Fred Drake30e52651998-07-24 22:11:29 +00001103}{%
1104 \end{tabular}%
1105 \end{center}%
1106}
1107
Fred Drakeda72b932000-09-21 15:58:02 +00001108\newenvironment{longtableiv}[6]{%
1109 \begin{center}%
1110 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
1111 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}%
1112 \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001113 \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001114}{%
1115 \end{longtable}%
1116 \end{center}%
1117}
1118
Fred Drakef269e592001-07-17 23:05:57 +00001119\newenvironment{tablev}[7]{%
1120 \begin{center}%
1121 \def\linev##1##2##3##4##5{\csname#2\endcsname{##1}&##2&##3&##4&##5\\}%
1122 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}&\strong{#7} \\%
1123 \hline%
1124}{%
1125 \end{tabular}%
1126 \end{center}%
1127}
1128
1129\newenvironment{longtablev}[7]{%
1130 \begin{center}%
1131 \def\linev##1##2##3##4##5{\csname#2\endcsname{##1}&##2&##3&##4&##5\\}%
1132 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}&\strong{#7}%
1133 \\%
1134 \hline\endhead%
1135}{%
1136 \end{longtable}%
1137 \end{center}%
1138}
1139
Fred Drake567332a2002-12-30 20:51:27 +00001140% XXX Don't think we can use this yet, though it cleans up some
1141% tedious markup. There's no equivalent for the HTML transform yet,
1142% and that needs to exist. I don't know how to write it.
1143%
1144% This should really have something that makes it easier to bind a
1145% table's ``Notes'' column and an associated tablenotes environment,
1146% and generates the right magic for getting the numbers right in the
1147% table.
1148%
1149% So this is quite incomplete.
1150%
1151\newcounter{py@tablenotescounter}
1152\newenvironment{tablenotes}{%
1153 \noindent Notes:
1154 \par
1155 \setcounter{py@tablenotescounter}{0}
1156 \begin{list}{(\arabic{py@tablenotescounter})}%
1157 {\usecounter{py@tablenotescounter}}
1158}{\end{list}}
1159
1160
Fred Drake24340ea1998-04-28 18:30:34 +00001161% Cross-referencing (AMK, new impl. FLD)
Fred Drake6659c301998-03-03 22:02:19 +00001162% Sample usage:
1163% \begin{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +00001164% \seemodule{rand}{Uniform random number generator.}; % Module xref
1165% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +00001166%
1167% % A funky case: module name contains '_'; have to supply an optional key
Fred Drake84bd6f31999-05-11 15:42:51 +00001168% \seemodule[copyreg]{copy_reg}{Interface constructor registration for
1169% \module{pickle}.}
Fred Drake6659c301998-03-03 22:02:19 +00001170% \end{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +00001171%
1172% Note that the last parameter for \seemodule and \seetext should be complete
1173% sentences and be terminated with the proper punctuation.
Fred Drake6659c301998-03-03 22:02:19 +00001174
Fred Drakee59feb52001-10-29 21:02:28 +00001175\ifpdf
Fred Drake24340ea1998-04-28 18:30:34 +00001176 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +00001177 \par%
Fred Drake24340ea1998-04-28 18:30:34 +00001178 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drake84bd6f31999-05-11 15:42:51 +00001179 \begin{fulllineitems}
Fred Drake84bd6f31999-05-11 15:42:51 +00001180 \item[\py@linkToName{label-module-\py@modulekey}{Module \module{#2}}
1181 (section \ref{module-\py@modulekey}):]
1182 #3
1183 \end{fulllineitems}
Fred Drakeebcb6581998-03-06 21:25:17 +00001184 }
Fred Drakee59feb52001-10-29 21:02:28 +00001185\else
1186 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
1187 \par%
1188 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
1189 \begin{fulllineitems}
1190 \item[Module \module{#2} (section \ref{module-\py@modulekey}):]
1191 #3
1192 \end{fulllineitems}
1193 }
1194\fi
1195
Fred Drake4f687b32004-01-08 14:57:27 +00001196% \seelink{url}{link text}
1197\newcommand{\py@seelink}[3]{%
1198 \par
1199 \begin{fulllineitems}
1200 \item[\ulink{#2}{#1}]
1201 #3
1202 \end{fulllineitems}
1203}
Fred Drake48449982000-09-12 17:52:33 +00001204% \seetitle[url]{title}{why it's interesting}
1205\newcommand{\py@seetitle}[3][\py@modulebadkey]{%
1206 \par
1207 \begin{fulllineitems}
1208 \item[\citetitle{#2}]
1209 \ifx\py@modulebadkey#1\else
1210 \item[{\small{(\url{#1})}}]
1211 \fi
1212 #3
1213 \end{fulllineitems}
1214}
Fred Drake4e607962000-09-09 06:01:25 +00001215% \seepep{number}{title}{why it's interesting}
1216\newcommand{\py@seepep}[3]{%
1217 \par%
1218 \begin{fulllineitems}
1219 \item[\pep{#1}, ``\emph{#2}'']
1220 #3
1221 \end{fulllineitems}
1222}
Fred Drake64b72b62000-04-26 18:13:58 +00001223% \seerfc{number}{title}{why it's interesting}
1224\newcommand{\py@seerfc}[3]{%
1225 \par%
1226 \begin{fulllineitems}
1227 \item[\rfc{#1}, ``\emph{#2}'']
1228 #3
1229 \end{fulllineitems}
1230}
Fred Drake51313f12000-05-09 16:18:44 +00001231% \seeurl{url}{why it's interesting}
1232\newcommand{\py@seeurl}[2]{%
1233 \par%
1234 \begin{fulllineitems}
1235 \item[\url{#1}]
1236 #2
1237 \end{fulllineitems}
1238}
Fred Drake5ed35fd2001-11-30 18:09:54 +00001239
1240\newenvironment{seealso*}{
Fred Drake9466b9a1999-03-18 16:18:27 +00001241 \par
Fred Drake6659c301998-03-03 22:02:19 +00001242 \def\seetext##1{\par{##1}}
Fred Drake24340ea1998-04-28 18:30:34 +00001243 \let\seemodule=\py@seemodule
Fred Drake48449982000-09-12 17:52:33 +00001244 \let\seepep=\py@seepep
Fred Drake64b72b62000-04-26 18:13:58 +00001245 \let\seerfc=\py@seerfc
Fred Drake48449982000-09-12 17:52:33 +00001246 \let\seetitle=\py@seetitle
Fred Drake51313f12000-05-09 16:18:44 +00001247 \let\seeurl=\py@seeurl
Fred Drake4f687b32004-01-08 14:57:27 +00001248 \let\seelink=\py@seelink
Fred Drake6659c301998-03-03 22:02:19 +00001249}{\par}
Fred Drake5ed35fd2001-11-30 18:09:54 +00001250\newenvironment{seealso}{
1251 \par
1252 \strong{See Also:}
1253 \par
1254 \def\seetext##1{\par{##1}}
1255 \let\seemodule=\py@seemodule
1256 \let\seepep=\py@seepep
1257 \let\seerfc=\py@seerfc
1258 \let\seetitle=\py@seetitle
1259 \let\seeurl=\py@seeurl
Fred Drake4f687b32004-01-08 14:57:27 +00001260 \let\seelink=\py@seelink
Fred Drake5ed35fd2001-11-30 18:09:54 +00001261}{\par}
Fred Drake6659c301998-03-03 22:02:19 +00001262
Fred Drakeaf958c71998-07-27 20:32:33 +00001263% Allow the Python release number to be specified independently of the
Fred Drake6659c301998-03-03 22:02:19 +00001264% \date{}. This allows the date to reflect the document's date and
1265% release to specify the Python release that is documented.
1266%
Fred Drake24340ea1998-04-28 18:30:34 +00001267\newcommand{\py@release}{}
Fred Drake6659c301998-03-03 22:02:19 +00001268\newcommand{\version}{}
Fred Drakeaf2b7142000-09-14 20:11:05 +00001269\newcommand{\shortversion}{}
Fred Drakec65218e2001-06-20 21:17:09 +00001270\newcommand{\releaseinfo}{}
Fred Drake6659c301998-03-03 22:02:19 +00001271\newcommand{\releasename}{Release}
1272\newcommand{\release}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +00001273 \renewcommand{\py@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +00001274 \renewcommand{\version}{#1}}
Fred Drakeaf2b7142000-09-14 20:11:05 +00001275\newcommand{\setshortversion}[1]{%
1276 \renewcommand{\shortversion}{#1}}
Fred Drakec65218e2001-06-20 21:17:09 +00001277\newcommand{\setreleaseinfo}[1]{%
1278 \renewcommand{\releaseinfo}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +00001279
1280% Allow specification of the author's address separately from the
1281% author's name. This can be used to format them differently, which
1282% is a good thing.
1283%
Fred Drake24340ea1998-04-28 18:30:34 +00001284\newcommand{\py@authoraddress}{}
1285\newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress}{#1}}
Fred Drake6df93ef1998-05-14 20:56:31 +00001286\let\developersaddress=\authoraddress
1287\let\developer=\author
1288\let\developers=\author
Fred Drake6659c301998-03-03 22:02:19 +00001289
Fred Drake6659c301998-03-03 22:02:19 +00001290% This sets up the fancy chapter headings that make the documents look
1291% at least a little better than the usual LaTeX output.
1292%
Fred Drake1c8d0e01998-03-07 05:29:15 +00001293\@ifundefined{ChTitleVar}{}{
Fred Drake24340ea1998-04-28 18:30:34 +00001294 \ChNameVar{\raggedleft\normalsize\py@HeaderFamily}
1295 \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily}
1296 \ChTitleVar{\raggedleft \rm\Huge\py@HeaderFamily}
Fred Drake6659c301998-03-03 22:02:19 +00001297 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +00001298 \def\@makechapterhead#1{%
1299 {\parindent \z@ \raggedright \normalfont
1300 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +00001301 \DOCH
1302 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +00001303 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +00001304 \DOTI{#1}
1305 }
1306 }
Fred Drake6659c301998-03-03 22:02:19 +00001307}
1308
Fred Drake3bf78651998-05-20 17:42:17 +00001309
1310% Definition lists; requested by AMK for HOWTO documents. Probably useful
1311% elsewhere as well, so keep in in the general style support.
1312%
1313\newenvironment{definitions}{%
1314 \begin{description}%
Fred Drakef9acc591998-09-09 15:27:43 +00001315 \def\term##1{\item[##1]\mbox{}\\*[0mm]}
Fred Drake3bf78651998-05-20 17:42:17 +00001316}{%
1317 \end{description}%
1318}
1319
Fred Drake6659c301998-03-03 22:02:19 +00001320% Tell TeX about pathological hyphenation cases:
1321\hyphenation{Base-HTTP-Re-quest-Hand-ler}