blob: 5e1ea2bdc18ee02eecf5a8b547cd931e689bf5cf [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{
Fred Drakec0b2e451998-03-25 14:53:43 +000075 \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
Fred Drakeebcb6581998-03-06 21:25:17 +000076 }
Fred Drakea2c2a831998-04-15 17:50:01 +000077 \newcommand{\py@target}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000078 \ifpy@doing@page@targets%
Fred Drake9b8afde1999-03-24 14:16:17 +000079 {\pdfdest name{#1} xyz}%
Fred Drakea2c2a831998-04-15 17:50:01 +000080 \fi%
81 }
Fred Drake24340ea1998-04-28 18:30:34 +000082 \let\py@OldLabel=\label
Fred Drake6659c301998-03-03 22:02:19 +000083 \renewcommand{\label}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000084 \py@OldLabel{#1}%
Fred Drakea2c2a831998-04-15 17:50:01 +000085 \py@target{label-#1}%
Fred Drake6659c301998-03-03 22:02:19 +000086 }
Fred Drakeba1700c1998-05-11 20:42:54 +000087 % This stuff adds a page# destination to every PDF page, where # is three
88 % digits wide, padded with leading zeros. This doesn't really help with
89 % the frontmatter, but does fine with the body.
Fred Drake6659c301998-03-03 22:02:19 +000090 %
91 % This is *heavily* based on the hyperref package.
92 %
Fred Drake1c8d0e01998-03-07 05:29:15 +000093 \def\@begindvi{%
94 \unvbox \@begindvibox
95 \@hyperfixhead
Fred Drake6659c301998-03-03 22:02:19 +000096 }
Fred Drake1c8d0e01998-03-07 05:29:15 +000097 \def\@hyperfixhead{%
98 \let\H@old@thehead\@thehead
Fred Drakea2c2a831998-04-15 17:50:01 +000099 \global\def\@foo{\py@target{page\py@pageno}}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000100 \expandafter\ifx\expandafter\@empty\H@old@thehead
101 \def\H@old@thehead{\hfil}\fi
102 \def\@thehead{\@foo\relax\H@old@thehead}%
Fred Drake6659c301998-03-03 22:02:19 +0000103 }
Fred Drakec0b2e451998-03-25 14:53:43 +0000104\fi\fi
Fred Drake6659c301998-03-03 22:02:19 +0000105
106% Increase printable page size (copied from fullpage.sty)
107\topmargin 0pt
108\advance \topmargin by -\headheight
109\advance \topmargin by -\headsep
110
111% attempt to work a little better for A4 users
Fred Drake9466b9a1999-03-18 16:18:27 +0000112\textheight \paperheight
113\advance\textheight by -2in
Fred Drake6659c301998-03-03 22:02:19 +0000114
115\oddsidemargin 0pt
Fred Drake9466b9a1999-03-18 16:18:27 +0000116\evensidemargin 0pt
117%\evensidemargin -.25in % for ``manual size'' documents
Fred Drake6659c301998-03-03 22:02:19 +0000118\marginparwidth 0.5in
119
Fred Drake9466b9a1999-03-18 16:18:27 +0000120\textwidth \paperwidth
121\advance\textwidth by -2in
Fred Drake6659c301998-03-03 22:02:19 +0000122
123
124% Style parameters and macros used by most documents here
125\raggedbottom
126\sloppy
127\parindent = 0mm
Fred Drake24340ea1998-04-28 18:30:34 +0000128\parskip = 2mm
Fred Drakeab357ec2001-03-02 18:57:05 +0000129\hbadness = 5000 % don't print trivial gripes
Fred Drake6659c301998-03-03 22:02:19 +0000130
Fred Drakeab357ec2001-03-02 18:57:05 +0000131\pagestyle{empty} % start this way; change for
132\pagenumbering{roman} % ToC & chapters
Fred Drake6659c301998-03-03 22:02:19 +0000133
134% Use this to set the font family for headers and other decor:
Fred Drake24340ea1998-04-28 18:30:34 +0000135\newcommand{\py@HeaderFamily}{\sffamily}
Fred Drake6659c301998-03-03 22:02:19 +0000136
Fred Drakeff031cf2002-10-31 21:04:34 +0000137% Set up abstract ways to get the normal and smaller font sizes that
138% work even in footnote context.
139\newif\ifpy@infootnote \py@infootnotefalse
Fred Drake2eba52f2002-11-04 16:29:31 +0000140\let\py@oldmakefntext\@makefntext
141\def\@makefntext#1{%
Fred Drakeff031cf2002-10-31 21:04:34 +0000142 \bgroup%
143 \py@infootnotetrue
Fred Drake2eba52f2002-11-04 16:29:31 +0000144 \py@oldmakefntext{#1}%
Fred Drakeff031cf2002-10-31 21:04:34 +0000145 \egroup%
146}
147\def\py@defaultsize{%
148 \ifpy@infootnote\footnotesize\else\normalsize\fi%
149}
150\def\py@smallsize{%
151 \ifpy@infootnote\scriptsize\else\small\fi%
152}
153
Fred Drake6659c301998-03-03 22:02:19 +0000154% Redefine the 'normal' header/footer style when using "fancyhdr" package:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000155\@ifundefined{fancyhf}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000156 % Use \pagestyle{normal} as the primary pagestyle for text.
157 \fancypagestyle{normal}{
158 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000159 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
160 \fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
161 \fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
Fred Drake6659c301998-03-03 22:02:19 +0000162 \renewcommand{\headrulewidth}{0pt}
163 \renewcommand{\footrulewidth}{0.4pt}
164 }
165 % Update the plain style so we get the page number & footer line,
166 % but not a chapter or section title. This is to keep the first
167 % page of a chapter and the blank page between chapters `clean.'
168 \fancypagestyle{plain}{
169 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000170 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
Fred Drake6659c301998-03-03 22:02:19 +0000171 \renewcommand{\headrulewidth}{0pt}
172 \renewcommand{\footrulewidth}{0.4pt}
173 }
174 % Redefine \cleardoublepage so that the blank page between chapters
175 % gets the plain style and not the fancy style. This is described
176 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000177 \@ifundefined{chapter}{}{
Fred Drake28f13911998-03-04 21:47:59 +0000178 \renewcommand{\cleardoublepage}{
Fred Drake1c8d0e01998-03-07 05:29:15 +0000179 \clearpage\if@openright \ifodd\c@page\else
Fred Drake28f13911998-03-04 21:47:59 +0000180 \hbox{}
181 \thispagestyle{plain}
182 \newpage
Fred Drake1c8d0e01998-03-07 05:29:15 +0000183 \if@twocolumn\hbox{}\newpage\fi\fi\fi
Fred Drake28f13911998-03-04 21:47:59 +0000184 }
185 }
Fred Drake6659c301998-03-03 22:02:19 +0000186}
187
Fred Drake6659c301998-03-03 22:02:19 +0000188% This sets up the {verbatim} environment to be indented and a minipage,
189% and to have all the other mostly nice properties that we want for
190% code samples.
191
Fred Drake9466b9a1999-03-18 16:18:27 +0000192\let\py@OldVerbatim=\verbatim
193\let\py@OldEndVerbatim=\endverbatim
194\RequirePackage{verbatim}
Fred Drake00f712e2002-03-28 22:28:43 +0000195\let\py@OldVerbatimInput=\verbatiminput
Fred Drake9466b9a1999-03-18 16:18:27 +0000196
Fred Drake6659c301998-03-03 22:02:19 +0000197% Variable used by begin code command
Fred Drake24340ea1998-04-28 18:30:34 +0000198\newlength{\py@codewidth}
Fred Drake6659c301998-03-03 22:02:19 +0000199
Fred Drake6659c301998-03-03 22:02:19 +0000200\renewcommand{\verbatim}{%
Fred Drake9466b9a1999-03-18 16:18:27 +0000201 \setlength{\parindent}{1cm}%
Fred Drake6659c301998-03-03 22:02:19 +0000202 % Calculate the text width for the minipage:
Fred Drake24340ea1998-04-28 18:30:34 +0000203 \setlength{\py@codewidth}{\linewidth}%
204 \addtolength{\py@codewidth}{-\parindent}%
Fred Drake6659c301998-03-03 22:02:19 +0000205 %
Fred Drake9466b9a1999-03-18 16:18:27 +0000206 \par\indent%
Fred Drake24340ea1998-04-28 18:30:34 +0000207 \begin{minipage}[t]{\py@codewidth}%
Fred Drake6659c301998-03-03 22:02:19 +0000208 \small%
Fred Drake24340ea1998-04-28 18:30:34 +0000209 \py@OldVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000210}
211\renewcommand{\endverbatim}{%
Fred Drake24340ea1998-04-28 18:30:34 +0000212 \py@OldEndVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000213 \end{minipage}%
Fred Drake6659c301998-03-03 22:02:19 +0000214}
Fred Drake00f712e2002-03-28 22:28:43 +0000215\renewcommand{\verbatiminput}[1]{%
216 {\setlength{\parindent}{1cm}%
217 % Calculate the text width for the minipage:
218 \setlength{\py@codewidth}{\linewidth}%
219 \addtolength{\py@codewidth}{-\parindent}%
220 %
221 \small%
222 \begin{list}{}{\setlength{\leftmargin}{1cm}}
223 \item%
224 \py@OldVerbatimInput{#1}%
225 \end{list}
226 }%
227}
Fred Drake6659c301998-03-03 22:02:19 +0000228
Fred Drakeb5309a92001-04-10 15:53:06 +0000229% This does a similar thing for the {alltt} environment:
230\RequirePackage{alltt}
231\let\py@OldAllTT=\alltt
232\let\py@OldEndAllTT=\endalltt
233
234\renewcommand{\alltt}{%
235 \setlength{\parindent}{1cm}%
236 % Calculate the text width for the minipage:
237 \setlength{\py@codewidth}{\linewidth}%
238 \addtolength{\py@codewidth}{-\parindent}%
Fred Drake29f59332004-02-10 18:30:22 +0000239 \let\e=\textbackslash%
Fred Drakeb5309a92001-04-10 15:53:06 +0000240 %
241 \par\indent%
242 \begin{minipage}[t]{\py@codewidth}%
243 \small%
244 \py@OldAllTT%
245}
246\renewcommand{\endalltt}{%
247 \py@OldEndAllTT%
248 \end{minipage}%
249}
250
Fred Drake6cb71491998-03-27 05:22:53 +0000251
Fred Drakea488f301998-07-23 17:50:45 +0000252\newcommand{\py@modulebadkey}{{--just-some-junk--}}
Fred Drake6659c301998-03-03 22:02:19 +0000253
Fred Drake6659c301998-03-03 22:02:19 +0000254
255%% Lots of index-entry generation support.
256
257% Command to wrap around stuff that refers to function / module /
258% attribute names in the index. Default behavior: like \code{}. To
259% just keep the index entries in the roman font, uncomment the second
Fred Drakea488f301998-07-23 17:50:45 +0000260% definition; it matches O'Reilly style more.
Fred Drake6659c301998-03-03 22:02:19 +0000261%
Fred Drake24340ea1998-04-28 18:30:34 +0000262\newcommand{\py@idxcode}[1]{\texttt{#1}}
263%\renewcommand{\py@idxcode}[1]{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000264
265% Command to generate two index entries (using subentries)
266\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
267
268% And three entries (using only one level of subentries)
269\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
270
271% And four (again, using only one level of subentries)
272\newcommand{\indexiv}[4]{
273\index{#1!#2 #3 #4}
274\index{#2!#3 #4, #1}
275\index{#3!#4, #1 #2}
276\index{#4!#1 #2 #3}
277}
278
279% Command to generate a reference to a function, statement, keyword,
280% operator.
Fred Drake0cabff91998-05-06 19:36:01 +0000281\newcommand{\kwindex}[1]{\indexii{keyword}{#1@{\py@idxcode{#1}}}}
Fred Drake24340ea1998-04-28 18:30:34 +0000282\newcommand{\stindex}[1]{\indexii{statement}{#1@{\py@idxcode{#1}}}}
283\newcommand{\opindex}[1]{\indexii{operator}{#1@{\py@idxcode{#1}}}}
284\newcommand{\exindex}[1]{\indexii{exception}{#1@{\py@idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000285\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakea33c5662000-10-29 05:19:16 +0000286\newcommand{\bifuncindex}[1]{%
287 \index{#1@{\py@idxcode{#1()}} (built-in function)}}
Fred Drake6659c301998-03-03 22:02:19 +0000288
289% Add an index entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000290\newcommand{\py@refmodule}[2]{\index{#1@{\py@idxcode{#1}} (#2module)}}
291\newcommand{\refmodindex}[1]{\py@refmodule{#1}{}}
292\newcommand{\refbimodindex}[1]{\py@refmodule{#1}{built-in }}
293\newcommand{\refexmodindex}[1]{\py@refmodule{#1}{extension }}
294\newcommand{\refstmodindex}[1]{\py@refmodule{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000295
Fred Drakeda943741999-01-13 17:09:06 +0000296% Refer to a module's documentation using a hyperlink of the module's
297% name, at least if we're building PDF:
Fred Drakee59feb52001-10-29 21:02:28 +0000298\ifpdf
Fred Drakeaa2aea01999-01-27 17:37:36 +0000299 \newcommand{\refmodule}[2][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000300 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drakeaa2aea01999-01-27 17:37:36 +0000301 \py@linkToName{label-module-\py@modulekey}{\module{#2}}%
Fred Drakeda943741999-01-13 17:09:06 +0000302 }
Fred Drakee59feb52001-10-29 21:02:28 +0000303\else
304 \newcommand{\refmodule}[2][\py@modulebadkey]{\module{#2}}
305\fi
Fred Drakeda943741999-01-13 17:09:06 +0000306
Fred Drake6659c301998-03-03 22:02:19 +0000307% support for the module index
Fred Drake24340ea1998-04-28 18:30:34 +0000308\newif\ifpy@UseModuleIndex
309\py@UseModuleIndexfalse
Fred Drakeb390daf1998-03-09 16:35:36 +0000310
Fred Drakeb390daf1998-03-09 16:35:36 +0000311\newcommand{\makemodindex}{
312 \newwrite\modindexfile
313 \openout\modindexfile=mod\jobname.idx
Fred Drake24340ea1998-04-28 18:30:34 +0000314 \py@UseModuleIndextrue
Fred Drakeb390daf1998-03-09 16:35:36 +0000315}
316
Fred Drake0ee9f721998-03-12 06:41:40 +0000317% Add the defining entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000318\newcommand{\py@modindex}[2]{%
Fred Drakea488f301998-07-23 17:50:45 +0000319 \renewcommand{\py@thismodule}{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000320 \setindexsubitem{(in module #1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000321 \index{#1@{\py@idxcode{#1}} (#2module)|textbf}%
322 \ifpy@UseModuleIndex%
Fred Drake0c275fa1999-03-02 16:17:44 +0000323 \@ifundefined{py@modplat@\py@thismodulekey}{
324 \write\modindexfile{\protect\indexentry{#1@{\texttt{#1}}}{\thepage}}%
325 }{\write\modindexfile{\protect\indexentry{#1@{\texttt{#1} %
Fred Drake9466b9a1999-03-18 16:18:27 +0000326 \emph{(\py@platformof[\py@thismodulekey]{})}}}{\thepage}}%
Fred Drake0c275fa1999-03-02 16:17:44 +0000327 }
Fred Drake0ee9f721998-03-12 06:41:40 +0000328 \fi%
329}
330
Fred Drake9466b9a1999-03-18 16:18:27 +0000331% *** XXX *** THE NEXT FOUR MACROS ARE NOW OBSOLETE !!! ***
332
Fred Drake6659c301998-03-03 22:02:19 +0000333% built-in & Python modules in the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000334\newcommand{\bimodindex}[1]{\py@modindex{#1}{built-in }%
335 \typeout{*** MACRO bimodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
336\newcommand{\stmodindex}[1]{\py@modindex{#1}{standard }%
337 \typeout{*** MACRO stmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000338
339% Python & extension modules outside the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000340\newcommand{\modindex}[1]{\py@modindex{#1}{}%
341 \typeout{*** MACRO modindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
342\newcommand{\exmodindex}[1]{\py@modindex{#1}{extension }%
343 \typeout{*** MACRO exmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000344
345% Additional string for an index entry
Fred Drakeba828782000-04-03 04:19:14 +0000346\newif\ifpy@usingsubitem\py@usingsubitemfalse
347\newcommand{\py@indexsubitem}{}
348\newcommand{\setindexsubitem}[1]{\renewcommand{\py@indexsubitem}{ #1}%
349 \py@usingsubitemtrue}
350\newcommand{\ttindex}[1]{%
351 \ifpy@usingsubitem
352 \index{#1@{\py@idxcode{#1}}\py@indexsubitem}%
353 \else%
354 \index{#1@{\py@idxcode{#1}}}%
355 \fi%
356}
Fred Drake0ee9f721998-03-12 06:41:40 +0000357\newcommand{\withsubitem}[2]{%
358 \begingroup%
Fred Drakeec77e652000-10-30 06:22:22 +0000359 \def\ttindex##1{\index{##1@{\py@idxcode{##1}} #1}}%
360 #2%
Fred Drake0ee9f721998-03-12 06:41:40 +0000361 \endgroup%
362}
Fred Drake6659c301998-03-03 22:02:19 +0000363
Fred Drake53714971998-04-02 22:33:16 +0000364
Fred Drakea488f301998-07-23 17:50:45 +0000365% Module synopsis processing -----------------------------------------------
366%
Fred Drake0c275fa1999-03-02 16:17:44 +0000367\newcommand{\py@thisclass}{}
368\newcommand{\py@thismodule}{}
369\newcommand{\py@thismodulekey}{}
370\newcommand{\py@thismoduletype}{}
371
Fred Drake9466b9a1999-03-18 16:18:27 +0000372\newcommand{\py@standardIndexModule}[1]{\py@modindex{#1}{standard }}
373\newcommand{\py@builtinIndexModule}[1]{\py@modindex{#1}{built-in }}
374\newcommand{\py@extensionIndexModule}[1]{\py@modindex{#1}{extension }}
375\newcommand{\py@IndexModule}[1]{\py@modindex{#1}{}}
Fred Drakea488f301998-07-23 17:50:45 +0000376
Fred Drake0c275fa1999-03-02 16:17:44 +0000377\newif\ifpy@HaveModSynopsis \py@HaveModSynopsisfalse
378\newif\ifpy@ModSynopsisFileIsOpen \py@ModSynopsisFileIsOpenfalse
379\newif\ifpy@HaveModPlatform \py@HaveModPlatformfalse
Fred Drakea488f301998-07-23 17:50:45 +0000380
381% \declaremodule[key]{type}{name}
382\newcommand{\declaremodule}[3][\py@modulebadkey]{
383 \py@openModSynopsisFile
384 \renewcommand{\py@thismoduletype}{#2}
Fred Drakea488f301998-07-23 17:50:45 +0000385 \ifx\py@modulebadkey#1
386 \renewcommand{\py@thismodulekey}{#3}
387 \else
388 \renewcommand{\py@thismodulekey}{#1}
389 \fi
Fred Drake5bc8d991999-05-17 14:47:10 +0000390 \@ifundefined{py@#2IndexModule}{%
391 \typeout{*** MACRO declaremodule called with unknown module type: `#2'}
Fred Drake66823021999-05-17 14:57:26 +0000392 \py@IndexModule{#3}%
Fred Drake5bc8d991999-05-17 14:47:10 +0000393 }{%
394 \csname py@#2IndexModule\endcsname{#3}%
395 }
Fred Drakea488f301998-07-23 17:50:45 +0000396 \label{module-\py@thismodulekey}
Fred Drakea488f301998-07-23 17:50:45 +0000397}
Fred Drake0c275fa1999-03-02 16:17:44 +0000398\newif\ifpy@ModPlatformFileIsOpen \py@ModPlatformFileIsOpenfalse
399\newcommand{\py@ModPlatformFilename}{\jobname.pla}
400\newcommand{\platform}[1]{
401 \ifpy@ModPlatformFileIsOpen\else
402 \newwrite\py@ModPlatformFile
403 \openout\py@ModPlatformFile=\py@ModPlatformFilename
404 \py@ModPlatformFileIsOpentrue
405 \fi
Fred Drake0c275fa1999-03-02 16:17:44 +0000406}
407\InputIfFileExists{\jobname.pla}{}{}
Fred Drake9466b9a1999-03-18 16:18:27 +0000408\newcommand{\py@platformof}[2][\py@modulebadkey]{%
Fred Drake0c275fa1999-03-02 16:17:44 +0000409 \ifx\py@modulebadkey#1 \def\py@key{#2}%
410 \else \def\py@key{#1}%
411 \fi%
412 \csname py@modplat@\py@key\endcsname%
413}
414\newcommand{\ignorePlatformAnnotation}[1]{}
Fred Drakea488f301998-07-23 17:50:45 +0000415
Fred Drakeb75c6151998-08-10 18:41:43 +0000416% \moduleauthor{name}{email}
417\newcommand{\moduleauthor}[2]{}
418
419% \sectionauthor{name}{email}
420\newcommand{\sectionauthor}[2]{}
421
Fred Drakea488f301998-07-23 17:50:45 +0000422
423\newcommand{\py@defsynopsis}{Module has no synopsis.}
424\newcommand{\py@modulesynopsis}{\py@defsynopsis}
425\newcommand{\modulesynopsis}[1]{
Fred Drake0c275fa1999-03-02 16:17:44 +0000426 \py@HaveModSynopsistrue
Fred Drakea488f301998-07-23 17:50:45 +0000427 \renewcommand{\py@modulesynopsis}{#1}
428}
429
430% define the file
431\newwrite\py@ModSynopsisFile
432
433% hacked from \addtocontents from latex.ltx:
434\long\def\py@writeModSynopsisFile#1{%
435 \protected@write\py@ModSynopsisFile%
436 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
437 {\string#1}%
438}
439\newcommand{\py@closeModSynopsisFile}{
440 \ifpy@ModSynopsisFileIsOpen
441 \closeout\py@ModSynopsisFile
442 \py@ModSynopsisFileIsOpenfalse
443 \fi
444}
445\newcommand{\py@openModSynopsisFile}{
446 \ifpy@ModSynopsisFileIsOpen\else
447 \openout\py@ModSynopsisFile=\py@ModSynopsisFilename
448 \py@ModSynopsisFileIsOpentrue
449 \fi
450}
451
452\newcommand{\py@ProcessModSynopsis}{
453 \ifpy@HaveModSynopsis
454 \py@writeModSynopsisFile{\modulesynopsis%
455 {\py@thismodulekey}{\py@thismodule}%
456 {\py@thismoduletype}{\py@modulesynopsis}}%
457 \py@HaveModSynopsisfalse
458 \fi
459 \renewcommand{\py@modulesynopsis}{\py@defsynopsis}
460}
461\AtEndDocument{\py@ProcessModSynopsis\py@closeModSynopsisFile}
462
Fred Drake0c275fa1999-03-02 16:17:44 +0000463
464\long\def\py@writeModPlatformFile#1{%
465 \protected@write\py@ModPlatformFile%
466 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
467 {\string#1}%
468}
469
470
Fred Drakea488f301998-07-23 17:50:45 +0000471\newcommand{\localmoduletable}{
472 \IfFileExists{\py@ModSynopsisFilename}{
473 \begin{synopsistable}
474 \input{\py@ModSynopsisFilename}
475 \end{synopsistable}
476 }{}
477}
478
Fred Drakee59feb52001-10-29 21:02:28 +0000479\ifpdf
Fred Drakeaa2aea01999-01-27 17:37:36 +0000480 \newcommand{\py@ModSynopsisSummary}[4]{%
481 \py@linkToName{label-module-#1}{\bfcode{#2}} & #4\\
482 }
Fred Drakee59feb52001-10-29 21:02:28 +0000483\else
484 \newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
485\fi
Fred Drakea488f301998-07-23 17:50:45 +0000486\newenvironment{synopsistable}{
487 % key, name, type, synopsis
488 \let\modulesynopsis=\py@ModSynopsisSummary
489 \begin{tabular}{ll}
490}{
491 \end{tabular}
492}
493%
494% --------------------------------------------------------------------------
495
496
Fred Drakea488f301998-07-23 17:50:45 +0000497\newcommand{\py@reset}{
Fred Drakeba828782000-04-03 04:19:14 +0000498 \py@usingsubitemfalse
Fred Drakea488f301998-07-23 17:50:45 +0000499 \py@ProcessModSynopsis
500 \renewcommand{\py@thisclass}{}
501 \renewcommand{\py@thismodule}{}
502 \renewcommand{\py@thismodulekey}{}
503 \renewcommand{\py@thismoduletype}{}
504}
505
506% Augment the sectioning commands used to get our own font family in place,
507% and reset some internal data items:
508\renewcommand{\section}{\py@reset%
509 \@startsection{section}{1}{\z@}%
510 {-3.5ex \@plus -1ex \@minus -.2ex}%
511 {2.3ex \@plus.2ex}%
512 {\reset@font\Large\py@HeaderFamily}}
513\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
514 {-3.25ex\@plus -1ex \@minus -.2ex}%
515 {1.5ex \@plus .2ex}%
516 {\reset@font\large\py@HeaderFamily}}
517\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
518 {-3.25ex\@plus -1ex \@minus -.2ex}%
519 {1.5ex \@plus .2ex}%
520 {\reset@font\normalsize\py@HeaderFamily}}
521\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
522 {3.25ex \@plus1ex \@minus.2ex}%
523 {-1em}%
524 {\reset@font\normalsize\py@HeaderFamily}}
525\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
526 {3.25ex \@plus1ex \@minus .2ex}%
527 {-1em}%
528 {\reset@font\normalsize\py@HeaderFamily}}
529
530
Fred Drake5420f331998-07-23 21:41:02 +0000531% This gets the underscores closer to the right width; the only change
532% from standard LaTeX is the width specified.
533
534\DeclareTextCommandDefault{\textunderscore}{%
535 \leavevmode \kern.06em\vbox{\hrule\@width.55em}}
536
Fred Drakea488f301998-07-23 17:50:45 +0000537% Underscore hack (only act like subscript operator if in math mode)
538%
539% The following is due to Mark Wooding (the old version didn't work with
540% Latex 2e.
541
542\DeclareRobustCommand\hackscore{%
543 \ifmmode_\else\textunderscore\fi%
544}
545\begingroup
546\catcode`\_\active
547\def\next{%
548 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
549}
550\expandafter\endgroup\next
551
552
Fred Drake53714971998-04-02 22:33:16 +0000553% Now for a lot of semantically-loaded environments that do a ton of magical
554% things to get the right formatting and index entries for the stuff in
555% Python modules and C API.
556
557
Fred Drake6659c301998-03-03 22:02:19 +0000558% {fulllineitems} is used in one place in libregex.tex, but is really for
559% internal use in this file.
560%
Fred Drakef9acc591998-09-09 15:27:43 +0000561\newcommand{\py@itemnewline}[1]{%
562 \@tempdima\linewidth%
563 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
564}
565
Fred Drake6659c301998-03-03 22:02:19 +0000566\newenvironment{fulllineitems}{
567 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
568 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
569 \itemsep -\parsep
Fred Drakef9acc591998-09-09 15:27:43 +0000570 \let\makelabel=\py@itemnewline}
Fred Drake6659c301998-03-03 22:02:19 +0000571}{\end{list}}
572
Fred Drake6cb71491998-03-27 05:22:53 +0000573% \optional is mostly for use in the arguments parameters to the various
574% {*desc} environments defined below, but may be used elsewhere. Known to
575% be used in the debugger chapter.
Fred Drake24340ea1998-04-28 18:30:34 +0000576%
577% Typical usage:
578%
579% \begin{funcdesc}{myfunc}{reqparm\optional{, optparm}}
580% ^^^ ^^^
581% No space here No space here
582%
583% When a function has multiple optional parameters, \optional should be
584% nested, not chained. This is right:
585%
586% \begin{funcdesc}{myfunc}{\optional{parm1\optional{, parm2}}}
587%
Fred Drakeba828782000-04-03 04:19:14 +0000588\let\py@badkey=\@undefined
589
Fred Drake6659c301998-03-03 22:02:19 +0000590\newcommand{\optional}[1]{%
591 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
592
Fred Drakeba828782000-04-03 04:19:14 +0000593% This can be used when a function or method accepts an varying number
594% of arguments, such as by using the *args syntax in the parameter list.
595\newcommand{\py@moreargs}{...}
596
597% This can be used when you don't want to document the parameters to a
598% function or method, but simply state that it's an alias for
599% something else.
600\newcommand{\py@unspecified}{...}
601
Fred Drakead74b7d2002-07-02 20:32:50 +0000602
603\newlength{\py@argswidth}
604\newcommand{\py@sigparams}[1]{%
605 \parbox[t]{\py@argswidth}{\py@varvars{#1}\code{)}}}
606\newcommand{\py@sigline}[2]{%
607 \settowidth{\py@argswidth}{#1\code{(}}%
608 \addtolength{\py@argswidth}{-2\py@argswidth}%
609 \addtolength{\py@argswidth}{\textwidth}%
610 \item[#1\code{(}\py@sigparams{#2}]}
611
Fred Drake6cb71491998-03-27 05:22:53 +0000612% C functions ------------------------------------------------------------
Fred Drakeba828782000-04-03 04:19:14 +0000613% \begin{cfuncdesc}[refcount]{type}{name}{arglist}
614% Note that the [refcount] slot should only be filled in by
615% tools/anno-api.py; it pulls the value from the refcounts database.
Fred Drake34adb8a2002-04-15 20:48:40 +0000616\newcommand{\cfuncline}[3]{
Fred Drakead74b7d2002-07-02 20:32:50 +0000617 \py@sigline{\code{#1 \bfcode{#2}}}{#3}%
618 \index{#2@{\py@idxcode{#2()}}}
Fred Drake34adb8a2002-04-15 20:48:40 +0000619}
Fred Drakeba828782000-04-03 04:19:14 +0000620\newenvironment{cfuncdesc}[4][\py@badkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000621 \begin{fulllineitems}
Fred Drake34adb8a2002-04-15 20:48:40 +0000622 \cfuncline{#2}{#3}{#4}
Fred Drakeba828782000-04-03 04:19:14 +0000623 \ifx#1\@undefined\else%
Fred Drake0a863da2000-04-10 18:21:38 +0000624 \emph{Return value: \textbf{#1}.}\\
Fred Drakeba828782000-04-03 04:19:14 +0000625 \fi
Fred Drake6cb71491998-03-27 05:22:53 +0000626}{\end{fulllineitems}}
627
628% C variables ------------------------------------------------------------
629% \begin{cvardesc}{type}{name}
630\newenvironment{cvardesc}[2]{
631 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000632 \item[\code{#1 \bfcode{#2}}\index{#2@{\py@idxcode{#2}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000633}{\end{fulllineitems}}
634
635% C data types -----------------------------------------------------------
Fred Drakeba828782000-04-03 04:19:14 +0000636% \begin{ctypedesc}[index name]{typedef name}
637\newenvironment{ctypedesc}[2][\py@badkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000638 \begin{fulllineitems}
Fred Drakeba828782000-04-03 04:19:14 +0000639 \item[\bfcode{#2}%
640 \ifx#1\@undefined%
Fred Drakea33c5662000-10-29 05:19:16 +0000641 \index{#2@{\py@idxcode{#2}} (C type)}
Fred Drakeba828782000-04-03 04:19:14 +0000642 \else%
Fred Drakea33c5662000-10-29 05:19:16 +0000643 \index{#2@{\py@idxcode{#1}} (C type)}
Fred Drakeba828782000-04-03 04:19:14 +0000644 \fi]
645}{\end{fulllineitems}}
646
Fred Drake01e94612002-04-12 22:48:02 +0000647% C type fields ----------------------------------------------------------
648% \begin{cmemberdesc}{container type}{ctype}{membername}
649\newcommand{\cmemberline}[3]{
650 \item[\code{#2 \bfcode{#3}}]
651 \index{#3@{\py@idxcode{#3}} (#1 member)}
652}
653\newenvironment{cmemberdesc}[3]{
654 \begin{fulllineitems}
655 \cmemberline{#1}{#2}{#3}
656}{\end{fulllineitems}}
657
Fred Drakeba828782000-04-03 04:19:14 +0000658% Funky macros -----------------------------------------------------------
Fred Drake19f827e2002-04-09 20:16:47 +0000659% \begin{csimplemacrodesc}{name}
Fred Drakeba828782000-04-03 04:19:14 +0000660% -- "simple" because it has no args; NOT for constant definitions!
661\newenvironment{csimplemacrodesc}[1]{
662 \begin{fulllineitems}
Fred Drakea33c5662000-10-29 05:19:16 +0000663 \item[\bfcode{#1}\index{#1@{\py@idxcode{#1}} (macro)}]
Fred Drake6cb71491998-03-27 05:22:53 +0000664}{\end{fulllineitems}}
665
666% simple functions (not methods) -----------------------------------------
667% \begin{funcdesc}{name}{args}
Fred Drakeec77e652000-10-30 06:22:22 +0000668\newcommand{\funcline}[2]{%
669 \funclineni{#1}{#2}%
670 \index{#1@{\py@idxcode{#1()}} (in module \py@thismodule)}}
Fred Drake6cb71491998-03-27 05:22:53 +0000671\newenvironment{funcdesc}[2]{
672 \begin{fulllineitems}
673 \funcline{#1}{#2}
674}{\end{fulllineitems}}
675
Fred Drake6659c301998-03-03 22:02:19 +0000676% similar to {funcdesc}, but doesn't add to the index
Fred Drakead74b7d2002-07-02 20:32:50 +0000677\newcommand{\funclineni}[2]{%
678 \py@sigline{\bfcode{#1}}{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000679\newenvironment{funcdescni}[2]{
680 \begin{fulllineitems}
681 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000682}{\end{fulllineitems}}
683
Fred Drake6cb71491998-03-27 05:22:53 +0000684% classes ----------------------------------------------------------------
685% \begin{classdesc}{name}{constructor args}
686\newenvironment{classdesc}[2]{
Fred Drake1cbd1961998-11-25 17:13:28 +0000687 % Using \renewcommand doesn't work for this, for unknown reasons:
688 \global\def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000689 \begin{fulllineitems}
Fred Drakead74b7d2002-07-02 20:32:50 +0000690 \py@sigline{\strong{class }\bfcode{#1}}{#2}%
691 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}
Fred Drake6659c301998-03-03 22:02:19 +0000692}{\end{fulllineitems}}
693
Fred Drake06a01e82001-05-11 01:00:30 +0000694% \begin{classdesc*}{name}
695\newenvironment{classdesc*}[1]{
696 % Using \renewcommand doesn't work for this, for unknown reasons:
697 \global\def\py@thisclass{#1}
698 \begin{fulllineitems}
699 \item[\strong{class }\code{\bfcode{#1}}%
700 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}]
701}{\end{fulllineitems}}
702
Fred Drake4e607962000-09-09 06:01:25 +0000703% \begin{excclassdesc}{name}{constructor args}
704% but indexes as an exception
705\newenvironment{excclassdesc}[2]{
706 % Using \renewcommand doesn't work for this, for unknown reasons:
707 \global\def\py@thisclass{#1}
708 \begin{fulllineitems}
Fred Drakead74b7d2002-07-02 20:32:50 +0000709 \py@sigline{\strong{exception }\bfcode{#1}}{#2}%
710 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}
Fred Drake4e607962000-09-09 06:01:25 +0000711}{\end{fulllineitems}}
712
Fred Drake06a01e82001-05-11 01:00:30 +0000713% There is no corresponding {excclassdesc*} environment. To describe
714% a class exception without parameters, use the {excdesc} environment.
715
Fred Drake6cb71491998-03-27 05:22:53 +0000716
Fred Drake24340ea1998-04-28 18:30:34 +0000717\let\py@classbadkey=\@undefined
Fred Drake6cb71491998-03-27 05:22:53 +0000718
719% object method ----------------------------------------------------------
720% \begin{methoddesc}[classname]{methodname}{args}
Fred Drakea33c5662000-10-29 05:19:16 +0000721\newcommand{\methodline}[3][\@undefined]{
Fred Drake6cb71491998-03-27 05:22:53 +0000722 \methodlineni{#2}{#3}
723 \ifx#1\@undefined
Fred Drakea33c5662000-10-29 05:19:16 +0000724 \index{#2@{\py@idxcode{#2()}} (\py@thisclass\ method)}
Fred Drake6cb71491998-03-27 05:22:53 +0000725 \else
Fred Drakea33c5662000-10-29 05:19:16 +0000726 \index{#2@{\py@idxcode{#2()}} (#1 method)}
Fred Drake6cb71491998-03-27 05:22:53 +0000727 \fi
728}
Fred Drakea33c5662000-10-29 05:19:16 +0000729\newenvironment{methoddesc}[3][\@undefined]{
Fred Drake6cb71491998-03-27 05:22:53 +0000730 \begin{fulllineitems}
731 \ifx#1\@undefined
732 \methodline{#2}{#3}
733 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000734 \def\py@thisclass{#1}
Fred Drakea33c5662000-10-29 05:19:16 +0000735 \methodline{#2}{#3}
Fred Drake6cb71491998-03-27 05:22:53 +0000736 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000737}{\end{fulllineitems}}
738
Fred Drake6cb71491998-03-27 05:22:53 +0000739% similar to {methoddesc}, but doesn't add to the index
740% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000741\newcommand{\methodlineni}[3][\py@classbadkey]{%
Fred Drakead74b7d2002-07-02 20:32:50 +0000742 \py@sigline{\bfcode{#2}}{#3}}
Fred Drake24340ea1998-04-28 18:30:34 +0000743\newenvironment{methoddescni}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000744 \begin{fulllineitems}
745 \methodlineni{#2}{#3}
746}{\end{fulllineitems}}
747
748% object data attribute --------------------------------------------------
749% \begin{memberdesc}[classname]{membername}
Fred Drake24340ea1998-04-28 18:30:34 +0000750\newcommand{\memberline}[2][\py@classbadkey]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000751 \ifx#1\@undefined
752 \memberlineni{#2}
Fred Drakea33c5662000-10-29 05:19:16 +0000753 \index{#2@{\py@idxcode{#2}} (\py@thisclass\ attribute)}
Fred Drake6cb71491998-03-27 05:22:53 +0000754 \else
755 \memberlineni{#2}
Fred Drakea33c5662000-10-29 05:19:16 +0000756 \index{#2@{\py@idxcode{#2}} (#1 attribute)}
Fred Drake6cb71491998-03-27 05:22:53 +0000757 \fi
758}
Fred Drake24340ea1998-04-28 18:30:34 +0000759\newenvironment{memberdesc}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000760 \begin{fulllineitems}
761 \ifx#1\@undefined
762 \memberline{#2}
763 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000764 \def\py@thisclass{#1}
Fred Drakea33c5662000-10-29 05:19:16 +0000765 \memberline{#2}
Fred Drake6cb71491998-03-27 05:22:53 +0000766 \fi
767}{\end{fulllineitems}}
768
769% similar to {memberdesc}, but doesn't add to the index
770% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000771\newcommand{\memberlineni}[2][\py@classbadkey]{\item[\bfcode{#2}]}
772\newenvironment{memberdescni}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000773 \begin{fulllineitems}
774 \memberlineni{#2}
775}{\end{fulllineitems}}
776
777% For exceptions: --------------------------------------------------------
778% \begin{excdesc}{name}
Fred Drakea33c5662000-10-29 05:19:16 +0000779% -- for constructor information, use excclassdesc instead
Fred Drake6cb71491998-03-27 05:22:53 +0000780\newenvironment{excdesc}[1]{
781 \begin{fulllineitems}
Fred Drakeab357ec2001-03-02 18:57:05 +0000782 \item[\strong{exception }\bfcode{#1}%
Fred Drakea33c5662000-10-29 05:19:16 +0000783 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}]
Fred Drake6cb71491998-03-27 05:22:53 +0000784}{\end{fulllineitems}}
785
786% Module data or constants: ----------------------------------------------
787% \begin{datadesc}{name}
Fred Drakea33c5662000-10-29 05:19:16 +0000788\newcommand{\dataline}[1]{%
789 \datalineni{#1}\index{#1@{\py@idxcode{#1}} (data in \py@thismodule)}}
Fred Drake6cb71491998-03-27 05:22:53 +0000790\newenvironment{datadesc}[1]{
791 \begin{fulllineitems}
792 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000793}{\end{fulllineitems}}
794
795% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000796\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
797\newenvironment{datadescni}[1]{
798 \begin{fulllineitems}
799 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000800}{\end{fulllineitems}}
801
Fred Drake6cb71491998-03-27 05:22:53 +0000802% bytecode instruction ---------------------------------------------------
803% \begin{opcodedesc}{name}{var}
804% -- {var} may be {}
805\newenvironment{opcodedesc}[2]{
806 \begin{fulllineitems}
807 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000808}{\end{fulllineitems}}
809
810
Fred Drake24340ea1998-04-28 18:30:34 +0000811\newcommand{\nodename}[1]{\label{#1}}
Fred Drake55730311998-03-25 15:41:23 +0000812
Fred Drake6659c301998-03-03 22:02:19 +0000813% For these commands, use \command{} to get the typography right, not
814% {\command}. This works better with the texinfo translation.
815\newcommand{\ABC}{{\sc abc}}
816\newcommand{\UNIX}{{\sc Unix}}
817\newcommand{\POSIX}{POSIX}
818\newcommand{\ASCII}{{\sc ascii}}
819\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
820\newcommand{\C}{C}
821\newcommand{\EOF}{{\sc eof}}
Fred Drake24340ea1998-04-28 18:30:34 +0000822\newcommand{\NULL}{\constant{NULL}}
Fred Drake5445e5e2001-06-23 03:11:45 +0000823\newcommand{\infinity}{\ensuremath{\infty}}
824\newcommand{\plusminus}{\ensuremath{\pm}}
Fred Drakef0f6d122004-01-23 08:52:28 +0000825
826% \guilabel{Start}
827\newcommand{\guilabel}[1]{\textsf{#1}}
Fred Drakeb4812862002-08-02 18:30:22 +0000828% \menuselection{Start \sub Programs \sub Python}
Fred Drakef0f6d122004-01-23 08:52:28 +0000829\newcommand{\menuselection}[1]{\guilabel{{\def\sub{ \ensuremath{>} }#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000830
Fred Drake53714971998-04-02 22:33:16 +0000831% Also for consistency: spell Python "Python", not "python"!
832
Fred Drake6659c301998-03-03 22:02:19 +0000833% code is the most difficult one...
Fred Drake46346ec2000-06-30 17:57:05 +0000834\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 +0000835\texttt{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000836
837\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Fred Drake19f827e2002-04-09 20:16:47 +0000838\newcommand{\csimplemacro}[1]{\code{#1}}
Fred Drake8e54abe1998-07-01 14:49:25 +0000839\newcommand{\kbd}[1]{\code{#1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000840\newcommand{\samp}[1]{`\code{#1}'}
Fred Drakefa1cceb1998-11-30 14:42:59 +0000841\newcommand{\var}[1]{%
842 \ifmmode%
Fred Drakeff031cf2002-10-31 21:04:34 +0000843 \hbox{\py@defaultsize\textrm{\textit{#1\/}}}%
Fred Drakefa1cceb1998-11-30 14:42:59 +0000844 \else%
Fred Drakeff031cf2002-10-31 21:04:34 +0000845 \py@defaultsize\textrm{\textit{#1\/}}%
Fred Drakefa1cceb1998-11-30 14:42:59 +0000846 \fi%
847}
Fred Drake24340ea1998-04-28 18:30:34 +0000848\renewcommand{\emph}[1]{{\em #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000849\newcommand{\dfn}[1]{\emph{#1}}
850\newcommand{\strong}[1]{{\bf #1}}
851% let's experiment with a new font:
Fred Drakeff031cf2002-10-31 21:04:34 +0000852\newcommand{\file}[1]{`\filenq{#1}'}
Fred Drake52feb812004-02-09 20:58:08 +0000853\newcommand{\filenq}[1]{{\py@smallsize\textsf{\let\e=\textbackslash#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000854
855% Use this def/redef approach for \url{} since hyperref defined this already,
856% but only if we actually used hyperref:
Fred Drakee59feb52001-10-29 21:02:28 +0000857\ifpdf
858 \newcommand{\url}[1]{{%
Fred Drake15fc72c2002-03-26 19:14:41 +0000859 \noindent%
Fred Drake53815882002-03-15 23:21:37 +0000860 \pdfstartlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
Fred Drakeab357ec2001-03-02 18:57:05 +0000861 \py@LinkColor% color of the link text
Fred Drakeff031cf2002-10-31 21:04:34 +0000862 \py@smallsize\sf #1%
Fred Drakeab357ec2001-03-02 18:57:05 +0000863 \py@NormalColor% Turn it back off; these are declarative
864 \pdfendlink}% and don't appear bound to the current
865 }% formatting "box".
Fred Drakee59feb52001-10-29 21:02:28 +0000866\else
Fred Drakeff031cf2002-10-31 21:04:34 +0000867 \newcommand{\url}[1]{\mbox{\py@smallsize\textsf{#1}}}
Fred Drakee59feb52001-10-29 21:02:28 +0000868\fi
Fred Drakeff031cf2002-10-31 21:04:34 +0000869\newcommand{\email}[1]{{\py@smallsize\textsf{#1}}}
870\newcommand{\newsgroup}[1]{{\py@smallsize\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000871
Fred Drakecc2b81e2000-08-03 17:38:30 +0000872\newcommand{\py@varvars}[1]{{%
Fred Drakeba828782000-04-03 04:19:14 +0000873 {\let\unspecified=\py@unspecified%
874 \let\moreargs=\py@moreargs%
Fred Drakecc2b81e2000-08-03 17:38:30 +0000875 \var{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000876
Fred Drake24340ea1998-04-28 18:30:34 +0000877% I'd really like to get rid of this!
Fred Drake6659c301998-03-03 22:02:19 +0000878\newif\iftexi\texifalse
Fred Drake6659c301998-03-03 22:02:19 +0000879
Fred Drake1e4973b1998-07-28 21:52:17 +0000880% This is used to get l2h to put the copyright and abstract on
881% a separate HTML page.
882\newif\ifhtml\htmlfalse
883
884
Fred Drake6659c301998-03-03 22:02:19 +0000885% These should be used for all references to identifiers which are
886% used to refer to instances of specific language constructs. See the
887% names for specific semantic assignments.
888%
889% For now, don't do anything really fancy with them; just use them as
890% logical markup. This might change in the future.
891%
Fred Drake24340ea1998-04-28 18:30:34 +0000892\newcommand{\module}[1]{\texttt{#1}}
893\newcommand{\keyword}[1]{\texttt{#1}}
894\newcommand{\exception}[1]{\texttt{#1}}
895\newcommand{\class}[1]{\texttt{#1}}
896\newcommand{\function}[1]{\texttt{#1}}
897\newcommand{\member}[1]{\texttt{#1}}
898\newcommand{\method}[1]{\texttt{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000899
Fred Drakeab357ec2001-03-02 18:57:05 +0000900\newcommand{\pytype}[1]{#1} % built-in Python type
Fred Drake53714971998-04-02 22:33:16 +0000901
Fred Drake24340ea1998-04-28 18:30:34 +0000902\newcommand{\cfunction}[1]{\texttt{#1}}
Fred Drakeab357ec2001-03-02 18:57:05 +0000903\newcommand{\ctype}[1]{\texttt{#1}} % C struct or typedef name
904\newcommand{\cdata}[1]{\texttt{#1}} % C variable, typically global
Fred Drake6659c301998-03-03 22:02:19 +0000905
Fred Drakeff031cf2002-10-31 21:04:34 +0000906\newcommand{\mailheader}[1]{{\py@smallsize\textsf{#1:}}}
907\newcommand{\mimetype}[1]{{\py@smallsize\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000908% The \! is a "negative thin space" in math mode.
909\newcommand{\regexp}[1]{%
910 {\tiny$^{^\lceil}\!\!$%
Fred Drakeff031cf2002-10-31 21:04:34 +0000911 {\py@defaultsize\code{#1}}%
Fred Drake47cfd031998-04-03 21:22:31 +0000912 $\!\rfloor\!$%
Fred Drake94fac131998-03-12 19:37:03 +0000913 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000914\newcommand{\envvar}[1]{%
Fred Drake31ab2982001-01-22 17:50:42 +0000915 #1%
Fred Drakee59feb52001-10-29 21:02:28 +0000916 \index{#1}%
Fred Drake31ab2982001-01-22 17:50:42 +0000917 \index{environment variables!{#1}}%
Fred Drake0ee9f721998-03-12 06:41:40 +0000918}
Fred Drakeab357ec2001-03-02 18:57:05 +0000919\newcommand{\makevar}[1]{#1} % variable in a Makefile
Fred Drake24340ea1998-04-28 18:30:34 +0000920\newcommand{\character}[1]{\samp{#1}}
Fred Drake0ee9f721998-03-12 06:41:40 +0000921
Fred Drake6659c301998-03-03 22:02:19 +0000922% constants defined in Python modules or C headers, not language constants:
Fred Drakeab357ec2001-03-02 18:57:05 +0000923\newcommand{\constant}[1]{\code{#1}} % manifest constant, not syntactic
Fred Drake6659c301998-03-03 22:02:19 +0000924
925\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake4e607962000-09-09 06:01:25 +0000926\newcommand{\pep}[1]{PEP #1\index{Python Enhancement Proposals!PEP #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000927\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
928\newcommand{\program}[1]{\strong{#1}}
Fred Drake7b8195a1999-11-09 17:02:11 +0000929\newcommand{\programopt}[1]{\strong{#1}}
Fred Drake49362492000-04-11 18:47:59 +0000930% Note that \longprogramopt provides the '--'!
931\newcommand{\longprogramopt}[1]{\strong{-{}-#1}}
Fred Drakee59feb52001-10-29 21:02:28 +0000932
Fred Drakeb4b64da2001-07-06 22:44:48 +0000933% \ulink{link text}{URL}
Fred Drakee59feb52001-10-29 21:02:28 +0000934\ifpdf
935 % The \noindent here is a hack -- we're forcing pdfTeX into
Fred Drake53815882002-03-15 23:21:37 +0000936 % horizontal mode since \pdfstartlink requires that.
Fred Drakec8b08b42003-09-06 04:19:43 +0000937 % For PDF, we *should* only generate a link when the URL is absolute.
Fred Drakee59feb52001-10-29 21:02:28 +0000938 \newcommand{\ulink}[2]{\noindent{%
Fred Drake53815882002-03-15 23:21:37 +0000939 \pdfstartlink attr{/Border [0 0 0]} user{/S /URI /URI (#2)}%
Fred Drakee59feb52001-10-29 21:02:28 +0000940 \py@LinkColor% color of the link text
941 #1%
942 \py@NormalColor% Turn it back off; these are declarative
943 \pdfendlink}% and don't appear bound to the current
944 }% formatting "box".
945\else
946 \newcommand{\ulink}[2]{#1}
947\fi
Fred Drake7b8195a1999-11-09 17:02:11 +0000948
949% cited titles: \citetitle{Title of Work}
950% online: \citetitle[url-to-resource]{Title of Work}
Fred Drakee59feb52001-10-29 21:02:28 +0000951\ifpdf
952 \newcommand{\citetitle}[2][\py@modulebadkey]{%
953 \ifx\py@modulebadkey#1\emph{#2}\else\ulink{\emph{#2}}{#1}\fi%
954 }
955\else
Fred Drake622087a2001-11-02 20:53:19 +0000956 \newcommand{\citetitle}[2][URL]{\emph{#2}}
Fred Drakee59feb52001-10-29 21:02:28 +0000957\fi
958
Fred Drake6659c301998-03-03 22:02:19 +0000959
960
Fred Drakec82bd722001-12-11 18:47:36 +0000961% This version is being checked in for the historical record; it shows
962% how I've managed to get some aspects of this to work. It will not
963% be used in practice, so a subsequent revision will change things
964% again. This version has problems, but shows how to do something
965% that proved more tedious than I'd expected, so I don't want to lose
966% the example completely.
967%
Fred Drake16bb4192001-08-20 21:36:38 +0000968\newcommand{\grammartoken}[1]{\texttt{#1}}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000969\newenvironment{productionlist}[1][\py@badkey]{
970 \def\optional##1{{\Large[}##1{\Large]}}
971 \def\production##1##2{\code{##1}&::=&\code{##2}\\}
Fred Drake53815882002-03-15 23:21:37 +0000972 \def\productioncont##1{& &\code{##1}\\}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000973 \def\token##1{##1}
Fred Drake16bb4192001-08-20 21:36:38 +0000974 \let\grammartoken=\token
Fred Drakec82bd722001-12-11 18:47:36 +0000975 \parindent=2em
976 \indent
977 \begin{tabular}{lcl}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000978}{%
Fred Drakec82bd722001-12-11 18:47:36 +0000979 \end{tabular}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000980}
981
Fred Drake862b46b2004-03-31 08:08:34 +0000982\newlength{\py@noticelength}
983
984\newcommand{\py@heavybox}{
985 \setlength{\fboxrule}{2pt}
986 \setlength{\fboxsep}{7pt}
987 \setlength{\py@noticelength}{\linewidth}
988 \addtolength{\py@noticelength}{-2\fboxsep}
989 \addtolength{\py@noticelength}{-2\fboxrule}
990 \setlength{\shadowsize}{3pt}
991 \Sbox
992 \minipage{\py@noticelength}
993}
994\newcommand{\py@endheavybox}{
995 \endminipage
996 \endSbox
997 \fbox{\TheSbox}
998}
999
1000% a 'note' is as plain as it gets:
Fred Drake6ca33772001-12-14 22:50:06 +00001001\newcommand{\py@noticelabel@note}{Note:}
Fred Drake862b46b2004-03-31 08:08:34 +00001002\newcommand{\py@noticestart@note}{}
1003\newcommand{\py@noticeend@note}{}
1004
1005% a 'warning' gets more visible distinction:
Fred Drake6ca33772001-12-14 22:50:06 +00001006\newcommand{\py@noticelabel@warning}{Warning:}
Fred Drake862b46b2004-03-31 08:08:34 +00001007\newcommand{\py@noticestart@warning}{\py@heavybox}
1008\newcommand{\py@noticeend@warning}{\py@endheavybox}
1009
Fred Drake6ca33772001-12-14 22:50:06 +00001010\newenvironment{notice}[1][note]{
Fred Drake862b46b2004-03-31 08:08:34 +00001011 \def\py@noticetype{#1}
1012 \csname py@noticestart@#1\endcsname
Fred Drake6ca33772001-12-14 22:50:06 +00001013 \par\strong{\csname py@noticelabel@#1\endcsname}
Fred Drake862b46b2004-03-31 08:08:34 +00001014}{\csname py@noticeend@\py@noticetype\endcsname}
Fred Drake6ca33772001-12-14 22:50:06 +00001015\newcommand{\note}[1]{\strong{\py@noticelabel@note} #1}
1016\newcommand{\warning}[1]{\strong{\py@noticelabel@warning} #1}
Fred Drake92350b32001-10-09 18:01:23 +00001017
Fred Drake6659c301998-03-03 22:02:19 +00001018% Deprecation stuff.
1019% Should be extended to allow an index / list of deprecated stuff. But
1020% there's a lot of stuff that needs to be done to make that automatable.
1021%
1022% First parameter is the release number that deprecates the feature, the
1023% second is the action the should be taken by users of the feature.
1024%
1025% Example:
Fred Drake24340ea1998-04-28 18:30:34 +00001026% \deprecated{1.5.1}{Use \method{frobnicate()} instead.}
Fred Drake6659c301998-03-03 22:02:19 +00001027%
1028\newcommand{\deprecated}[2]{%
1029 \strong{Deprecated since release #1.} #2\par}
1030
Fred Drakeaf958c71998-07-27 20:32:33 +00001031% New stuff.
1032% This should be used to mark things which have been added to the
1033% development tree but that aren't in the release, but are documented.
1034% This allows release of documentation that already includes updated
Fred Drake2116d981999-02-02 18:02:48 +00001035% descriptions. Place at end of descriptor environment.
Fred Drakeaf958c71998-07-27 20:32:33 +00001036%
1037% Example:
1038% \versionadded{1.5.2}
Fred Drake46346ec2000-06-30 17:57:05 +00001039% \versionchanged[short explanation]{2.0}
Fred Drakeaf958c71998-07-27 20:32:33 +00001040%
Fred Drakefdfb05b2001-04-18 03:08:54 +00001041\newcommand{\versionadded}[2][\py@badkey]{%
1042 \ifx#1\@undefined%
1043 { New in version #2. }%
1044 \else%
1045 { New in version #2:\ #1. }%
1046 \fi%
1047}
Fred Drakea6e83392000-05-02 17:28:36 +00001048\newcommand{\versionchanged}[2][\py@badkey]{%
1049 \ifx#1\@undefined%
1050 { Changed in version #2. }%
1051 \else%
1052 { Changed in version #2:\ #1. }%
1053 \fi%
1054}
Fred Drake6659c301998-03-03 22:02:19 +00001055
Fred Drakeaf958c71998-07-27 20:32:33 +00001056
1057% Tables.
1058%
Fred Drake6659c301998-03-03 22:02:19 +00001059\newenvironment{tableii}[4]{%
1060 \begin{center}%
1061 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakef61eac42000-10-24 02:18:30 +00001062 \begin{tabular}{#1}\strong{#3}&\strong{#4} \\* \hline%
Fred Drake6659c301998-03-03 22:02:19 +00001063}{%
Fred Drake6659c301998-03-03 22:02:19 +00001064 \end{tabular}%
1065 \end{center}%
1066}
1067
Fred Drakeda72b932000-09-21 15:58:02 +00001068\newenvironment{longtableii}[4]{%
1069 \begin{center}%
1070 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakef61eac42000-10-24 02:18:30 +00001071 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4} \\* \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001072}{%
1073 \end{longtable}%
1074 \end{center}%
1075}
1076
Fred Drake6659c301998-03-03 22:02:19 +00001077\newenvironment{tableiii}[5]{%
1078 \begin{center}%
1079 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
Fred Drakeda72b932000-09-21 15:58:02 +00001080 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001081 \hline%
Fred Drake6659c301998-03-03 22:02:19 +00001082}{%
Fred Drake6659c301998-03-03 22:02:19 +00001083 \end{tabular}%
1084 \end{center}%
1085}
1086
Fred Drakeda72b932000-09-21 15:58:02 +00001087\newenvironment{longtableiii}[5]{%
1088 \begin{center}%
1089 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
1090 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001091 \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001092}{%
1093 \end{longtable}%
1094 \end{center}%
1095}
1096
Fred Drake30e52651998-07-24 22:11:29 +00001097\newenvironment{tableiv}[6]{%
1098 \begin{center}%
1099 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
1100 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001101 \hline%
Fred Drake30e52651998-07-24 22:11:29 +00001102}{%
1103 \end{tabular}%
1104 \end{center}%
1105}
1106
Fred Drakeda72b932000-09-21 15:58:02 +00001107\newenvironment{longtableiv}[6]{%
1108 \begin{center}%
1109 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
1110 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}%
1111 \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001112 \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001113}{%
1114 \end{longtable}%
1115 \end{center}%
1116}
1117
Fred Drakef269e592001-07-17 23:05:57 +00001118\newenvironment{tablev}[7]{%
1119 \begin{center}%
1120 \def\linev##1##2##3##4##5{\csname#2\endcsname{##1}&##2&##3&##4&##5\\}%
1121 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}&\strong{#7} \\%
1122 \hline%
1123}{%
1124 \end{tabular}%
1125 \end{center}%
1126}
1127
1128\newenvironment{longtablev}[7]{%
1129 \begin{center}%
1130 \def\linev##1##2##3##4##5{\csname#2\endcsname{##1}&##2&##3&##4&##5\\}%
1131 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}&\strong{#7}%
1132 \\%
1133 \hline\endhead%
1134}{%
1135 \end{longtable}%
1136 \end{center}%
1137}
1138
Fred Drake567332a2002-12-30 20:51:27 +00001139% XXX Don't think we can use this yet, though it cleans up some
1140% tedious markup. There's no equivalent for the HTML transform yet,
1141% and that needs to exist. I don't know how to write it.
1142%
1143% This should really have something that makes it easier to bind a
1144% table's ``Notes'' column and an associated tablenotes environment,
1145% and generates the right magic for getting the numbers right in the
1146% table.
1147%
1148% So this is quite incomplete.
1149%
1150\newcounter{py@tablenotescounter}
1151\newenvironment{tablenotes}{%
1152 \noindent Notes:
1153 \par
1154 \setcounter{py@tablenotescounter}{0}
1155 \begin{list}{(\arabic{py@tablenotescounter})}%
1156 {\usecounter{py@tablenotescounter}}
1157}{\end{list}}
1158
1159
Fred Drake24340ea1998-04-28 18:30:34 +00001160% Cross-referencing (AMK, new impl. FLD)
Fred Drake6659c301998-03-03 22:02:19 +00001161% Sample usage:
1162% \begin{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +00001163% \seemodule{rand}{Uniform random number generator.}; % Module xref
1164% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +00001165%
1166% % A funky case: module name contains '_'; have to supply an optional key
Fred Drake84bd6f31999-05-11 15:42:51 +00001167% \seemodule[copyreg]{copy_reg}{Interface constructor registration for
1168% \module{pickle}.}
Fred Drake6659c301998-03-03 22:02:19 +00001169% \end{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +00001170%
1171% Note that the last parameter for \seemodule and \seetext should be complete
1172% sentences and be terminated with the proper punctuation.
Fred Drake6659c301998-03-03 22:02:19 +00001173
Fred Drakee59feb52001-10-29 21:02:28 +00001174\ifpdf
Fred Drake24340ea1998-04-28 18:30:34 +00001175 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +00001176 \par%
Fred Drake24340ea1998-04-28 18:30:34 +00001177 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drake84bd6f31999-05-11 15:42:51 +00001178 \begin{fulllineitems}
Fred Drake84bd6f31999-05-11 15:42:51 +00001179 \item[\py@linkToName{label-module-\py@modulekey}{Module \module{#2}}
1180 (section \ref{module-\py@modulekey}):]
1181 #3
1182 \end{fulllineitems}
Fred Drakeebcb6581998-03-06 21:25:17 +00001183 }
Fred Drakee59feb52001-10-29 21:02:28 +00001184\else
1185 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
1186 \par%
1187 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
1188 \begin{fulllineitems}
1189 \item[Module \module{#2} (section \ref{module-\py@modulekey}):]
1190 #3
1191 \end{fulllineitems}
1192 }
1193\fi
1194
Fred Drake4f687b32004-01-08 14:57:27 +00001195% \seelink{url}{link text}
1196\newcommand{\py@seelink}[3]{%
1197 \par
1198 \begin{fulllineitems}
1199 \item[\ulink{#2}{#1}]
1200 #3
1201 \end{fulllineitems}
1202}
Fred Drake48449982000-09-12 17:52:33 +00001203% \seetitle[url]{title}{why it's interesting}
1204\newcommand{\py@seetitle}[3][\py@modulebadkey]{%
1205 \par
1206 \begin{fulllineitems}
1207 \item[\citetitle{#2}]
1208 \ifx\py@modulebadkey#1\else
1209 \item[{\small{(\url{#1})}}]
1210 \fi
1211 #3
1212 \end{fulllineitems}
1213}
Fred Drake4e607962000-09-09 06:01:25 +00001214% \seepep{number}{title}{why it's interesting}
1215\newcommand{\py@seepep}[3]{%
1216 \par%
1217 \begin{fulllineitems}
1218 \item[\pep{#1}, ``\emph{#2}'']
1219 #3
1220 \end{fulllineitems}
1221}
Fred Drake64b72b62000-04-26 18:13:58 +00001222% \seerfc{number}{title}{why it's interesting}
1223\newcommand{\py@seerfc}[3]{%
1224 \par%
1225 \begin{fulllineitems}
1226 \item[\rfc{#1}, ``\emph{#2}'']
1227 #3
1228 \end{fulllineitems}
1229}
Fred Drake51313f12000-05-09 16:18:44 +00001230% \seeurl{url}{why it's interesting}
1231\newcommand{\py@seeurl}[2]{%
1232 \par%
1233 \begin{fulllineitems}
1234 \item[\url{#1}]
1235 #2
1236 \end{fulllineitems}
1237}
Fred Drake5ed35fd2001-11-30 18:09:54 +00001238
1239\newenvironment{seealso*}{
Fred Drake9466b9a1999-03-18 16:18:27 +00001240 \par
Fred Drake6659c301998-03-03 22:02:19 +00001241 \def\seetext##1{\par{##1}}
Fred Drake24340ea1998-04-28 18:30:34 +00001242 \let\seemodule=\py@seemodule
Fred Drake48449982000-09-12 17:52:33 +00001243 \let\seepep=\py@seepep
Fred Drake64b72b62000-04-26 18:13:58 +00001244 \let\seerfc=\py@seerfc
Fred Drake48449982000-09-12 17:52:33 +00001245 \let\seetitle=\py@seetitle
Fred Drake51313f12000-05-09 16:18:44 +00001246 \let\seeurl=\py@seeurl
Fred Drake4f687b32004-01-08 14:57:27 +00001247 \let\seelink=\py@seelink
Fred Drake6659c301998-03-03 22:02:19 +00001248}{\par}
Fred Drake5ed35fd2001-11-30 18:09:54 +00001249\newenvironment{seealso}{
1250 \par
1251 \strong{See Also:}
1252 \par
1253 \def\seetext##1{\par{##1}}
1254 \let\seemodule=\py@seemodule
1255 \let\seepep=\py@seepep
1256 \let\seerfc=\py@seerfc
1257 \let\seetitle=\py@seetitle
1258 \let\seeurl=\py@seeurl
Fred Drake4f687b32004-01-08 14:57:27 +00001259 \let\seelink=\py@seelink
Fred Drake5ed35fd2001-11-30 18:09:54 +00001260}{\par}
Fred Drake6659c301998-03-03 22:02:19 +00001261
Fred Drakeaf958c71998-07-27 20:32:33 +00001262% Allow the Python release number to be specified independently of the
Fred Drake6659c301998-03-03 22:02:19 +00001263% \date{}. This allows the date to reflect the document's date and
1264% release to specify the Python release that is documented.
1265%
Fred Drake24340ea1998-04-28 18:30:34 +00001266\newcommand{\py@release}{}
Fred Drake6659c301998-03-03 22:02:19 +00001267\newcommand{\version}{}
Fred Drakeaf2b7142000-09-14 20:11:05 +00001268\newcommand{\shortversion}{}
Fred Drakec65218e2001-06-20 21:17:09 +00001269\newcommand{\releaseinfo}{}
Fred Drake6659c301998-03-03 22:02:19 +00001270\newcommand{\releasename}{Release}
1271\newcommand{\release}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +00001272 \renewcommand{\py@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +00001273 \renewcommand{\version}{#1}}
Fred Drakeaf2b7142000-09-14 20:11:05 +00001274\newcommand{\setshortversion}[1]{%
1275 \renewcommand{\shortversion}{#1}}
Fred Drakec65218e2001-06-20 21:17:09 +00001276\newcommand{\setreleaseinfo}[1]{%
1277 \renewcommand{\releaseinfo}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +00001278
1279% Allow specification of the author's address separately from the
1280% author's name. This can be used to format them differently, which
1281% is a good thing.
1282%
Fred Drake24340ea1998-04-28 18:30:34 +00001283\newcommand{\py@authoraddress}{}
1284\newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress}{#1}}
Fred Drake6df93ef1998-05-14 20:56:31 +00001285\let\developersaddress=\authoraddress
1286\let\developer=\author
1287\let\developers=\author
Fred Drake6659c301998-03-03 22:02:19 +00001288
Fred Drake6659c301998-03-03 22:02:19 +00001289% This sets up the fancy chapter headings that make the documents look
1290% at least a little better than the usual LaTeX output.
1291%
Fred Drake1c8d0e01998-03-07 05:29:15 +00001292\@ifundefined{ChTitleVar}{}{
Fred Drake24340ea1998-04-28 18:30:34 +00001293 \ChNameVar{\raggedleft\normalsize\py@HeaderFamily}
1294 \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily}
1295 \ChTitleVar{\raggedleft \rm\Huge\py@HeaderFamily}
Fred Drake6659c301998-03-03 22:02:19 +00001296 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +00001297 \def\@makechapterhead#1{%
1298 {\parindent \z@ \raggedright \normalfont
1299 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +00001300 \DOCH
1301 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +00001302 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +00001303 \DOTI{#1}
1304 }
1305 }
Fred Drake6659c301998-03-03 22:02:19 +00001306}
1307
Fred Drake3bf78651998-05-20 17:42:17 +00001308
1309% Definition lists; requested by AMK for HOWTO documents. Probably useful
1310% elsewhere as well, so keep in in the general style support.
1311%
1312\newenvironment{definitions}{%
1313 \begin{description}%
Fred Drakef9acc591998-09-09 15:27:43 +00001314 \def\term##1{\item[##1]\mbox{}\\*[0mm]}
Fred Drake3bf78651998-05-20 17:42:17 +00001315}{%
1316 \end{description}%
1317}
1318
Fred Drake6659c301998-03-03 22:02:19 +00001319% Tell TeX about pathological hyphenation cases:
1320\hyphenation{Base-HTTP-Re-quest-Hand-ler}