blob: 85fe52f415351d1d9e6ef589af92806d72a110da [file] [log] [blame]
Fred Drake6659c301998-03-03 22:02:19 +00001%
Fred Drake6663b221998-03-06 22:33:06 +00002% python.sty for the Python docummentation [works only with with Latex2e]
Fred Drake6659c301998-03-03 22:02:19 +00003%
4
5\NeedsTeXFormat{LaTeX2e}[1995/12/01]
6\ProvidesPackage{python}
Fred Drakec0b2e451998-03-25 14:53:43 +00007 [1998/01/11 LaTeX package (Python markup)]
Fred Drake6659c301998-03-03 22:02:19 +00008
Fred 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}%
239 %
240 \par\indent%
241 \begin{minipage}[t]{\py@codewidth}%
242 \small%
243 \py@OldAllTT%
244}
245\renewcommand{\endalltt}{%
246 \py@OldEndAllTT%
247 \end{minipage}%
248}
249
Fred Drake6cb71491998-03-27 05:22:53 +0000250
Fred Drakea488f301998-07-23 17:50:45 +0000251\newcommand{\py@modulebadkey}{{--just-some-junk--}}
Fred Drake6659c301998-03-03 22:02:19 +0000252
Fred Drake6659c301998-03-03 22:02:19 +0000253
254%% Lots of index-entry generation support.
255
256% Command to wrap around stuff that refers to function / module /
257% attribute names in the index. Default behavior: like \code{}. To
258% just keep the index entries in the roman font, uncomment the second
Fred Drakea488f301998-07-23 17:50:45 +0000259% definition; it matches O'Reilly style more.
Fred Drake6659c301998-03-03 22:02:19 +0000260%
Fred Drake24340ea1998-04-28 18:30:34 +0000261\newcommand{\py@idxcode}[1]{\texttt{#1}}
262%\renewcommand{\py@idxcode}[1]{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000263
264% Command to generate two index entries (using subentries)
265\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
266
267% And three entries (using only one level of subentries)
268\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
269
270% And four (again, using only one level of subentries)
271\newcommand{\indexiv}[4]{
272\index{#1!#2 #3 #4}
273\index{#2!#3 #4, #1}
274\index{#3!#4, #1 #2}
275\index{#4!#1 #2 #3}
276}
277
278% Command to generate a reference to a function, statement, keyword,
279% operator.
Fred Drake0cabff91998-05-06 19:36:01 +0000280\newcommand{\kwindex}[1]{\indexii{keyword}{#1@{\py@idxcode{#1}}}}
Fred Drake24340ea1998-04-28 18:30:34 +0000281\newcommand{\stindex}[1]{\indexii{statement}{#1@{\py@idxcode{#1}}}}
282\newcommand{\opindex}[1]{\indexii{operator}{#1@{\py@idxcode{#1}}}}
283\newcommand{\exindex}[1]{\indexii{exception}{#1@{\py@idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000284\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakea33c5662000-10-29 05:19:16 +0000285\newcommand{\bifuncindex}[1]{%
286 \index{#1@{\py@idxcode{#1()}} (built-in function)}}
Fred Drake6659c301998-03-03 22:02:19 +0000287
288% Add an index entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000289\newcommand{\py@refmodule}[2]{\index{#1@{\py@idxcode{#1}} (#2module)}}
290\newcommand{\refmodindex}[1]{\py@refmodule{#1}{}}
291\newcommand{\refbimodindex}[1]{\py@refmodule{#1}{built-in }}
292\newcommand{\refexmodindex}[1]{\py@refmodule{#1}{extension }}
293\newcommand{\refstmodindex}[1]{\py@refmodule{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000294
Fred Drakeda943741999-01-13 17:09:06 +0000295% Refer to a module's documentation using a hyperlink of the module's
296% name, at least if we're building PDF:
Fred Drakee59feb52001-10-29 21:02:28 +0000297\ifpdf
Fred Drakeaa2aea01999-01-27 17:37:36 +0000298 \newcommand{\refmodule}[2][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000299 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drakeaa2aea01999-01-27 17:37:36 +0000300 \py@linkToName{label-module-\py@modulekey}{\module{#2}}%
Fred Drakeda943741999-01-13 17:09:06 +0000301 }
Fred Drakee59feb52001-10-29 21:02:28 +0000302\else
303 \newcommand{\refmodule}[2][\py@modulebadkey]{\module{#2}}
304\fi
Fred Drakeda943741999-01-13 17:09:06 +0000305
Fred Drake6659c301998-03-03 22:02:19 +0000306% support for the module index
Fred Drake24340ea1998-04-28 18:30:34 +0000307\newif\ifpy@UseModuleIndex
308\py@UseModuleIndexfalse
Fred Drakeb390daf1998-03-09 16:35:36 +0000309
Fred Drakeb390daf1998-03-09 16:35:36 +0000310\newcommand{\makemodindex}{
311 \newwrite\modindexfile
312 \openout\modindexfile=mod\jobname.idx
Fred Drake24340ea1998-04-28 18:30:34 +0000313 \py@UseModuleIndextrue
Fred Drakeb390daf1998-03-09 16:35:36 +0000314}
315
Fred Drake0ee9f721998-03-12 06:41:40 +0000316% Add the defining entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000317\newcommand{\py@modindex}[2]{%
Fred Drakea488f301998-07-23 17:50:45 +0000318 \renewcommand{\py@thismodule}{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000319 \setindexsubitem{(in module #1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000320 \index{#1@{\py@idxcode{#1}} (#2module)|textbf}%
321 \ifpy@UseModuleIndex%
Fred Drake0c275fa1999-03-02 16:17:44 +0000322 \@ifundefined{py@modplat@\py@thismodulekey}{
323 \write\modindexfile{\protect\indexentry{#1@{\texttt{#1}}}{\thepage}}%
324 }{\write\modindexfile{\protect\indexentry{#1@{\texttt{#1} %
Fred Drake9466b9a1999-03-18 16:18:27 +0000325 \emph{(\py@platformof[\py@thismodulekey]{})}}}{\thepage}}%
Fred Drake0c275fa1999-03-02 16:17:44 +0000326 }
Fred Drake0ee9f721998-03-12 06:41:40 +0000327 \fi%
328}
329
Fred Drake9466b9a1999-03-18 16:18:27 +0000330% *** XXX *** THE NEXT FOUR MACROS ARE NOW OBSOLETE !!! ***
331
Fred Drake6659c301998-03-03 22:02:19 +0000332% built-in & Python modules in the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000333\newcommand{\bimodindex}[1]{\py@modindex{#1}{built-in }%
334 \typeout{*** MACRO bimodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
335\newcommand{\stmodindex}[1]{\py@modindex{#1}{standard }%
336 \typeout{*** MACRO stmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000337
338% Python & extension modules outside the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000339\newcommand{\modindex}[1]{\py@modindex{#1}{}%
340 \typeout{*** MACRO modindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
341\newcommand{\exmodindex}[1]{\py@modindex{#1}{extension }%
342 \typeout{*** MACRO exmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000343
344% Additional string for an index entry
Fred Drakeba828782000-04-03 04:19:14 +0000345\newif\ifpy@usingsubitem\py@usingsubitemfalse
346\newcommand{\py@indexsubitem}{}
347\newcommand{\setindexsubitem}[1]{\renewcommand{\py@indexsubitem}{ #1}%
348 \py@usingsubitemtrue}
349\newcommand{\ttindex}[1]{%
350 \ifpy@usingsubitem
351 \index{#1@{\py@idxcode{#1}}\py@indexsubitem}%
352 \else%
353 \index{#1@{\py@idxcode{#1}}}%
354 \fi%
355}
Fred Drake0ee9f721998-03-12 06:41:40 +0000356\newcommand{\withsubitem}[2]{%
357 \begingroup%
Fred Drakeec77e652000-10-30 06:22:22 +0000358 \def\ttindex##1{\index{##1@{\py@idxcode{##1}} #1}}%
359 #2%
Fred Drake0ee9f721998-03-12 06:41:40 +0000360 \endgroup%
361}
Fred Drake6659c301998-03-03 22:02:19 +0000362
Fred Drake53714971998-04-02 22:33:16 +0000363
Fred Drakea488f301998-07-23 17:50:45 +0000364% Module synopsis processing -----------------------------------------------
365%
Fred Drake0c275fa1999-03-02 16:17:44 +0000366\newcommand{\py@thisclass}{}
367\newcommand{\py@thismodule}{}
368\newcommand{\py@thismodulekey}{}
369\newcommand{\py@thismoduletype}{}
370
Fred Drake9466b9a1999-03-18 16:18:27 +0000371\newcommand{\py@standardIndexModule}[1]{\py@modindex{#1}{standard }}
372\newcommand{\py@builtinIndexModule}[1]{\py@modindex{#1}{built-in }}
373\newcommand{\py@extensionIndexModule}[1]{\py@modindex{#1}{extension }}
374\newcommand{\py@IndexModule}[1]{\py@modindex{#1}{}}
Fred Drakea488f301998-07-23 17:50:45 +0000375
Fred Drake0c275fa1999-03-02 16:17:44 +0000376\newif\ifpy@HaveModSynopsis \py@HaveModSynopsisfalse
377\newif\ifpy@ModSynopsisFileIsOpen \py@ModSynopsisFileIsOpenfalse
378\newif\ifpy@HaveModPlatform \py@HaveModPlatformfalse
Fred Drakea488f301998-07-23 17:50:45 +0000379
380% \declaremodule[key]{type}{name}
381\newcommand{\declaremodule}[3][\py@modulebadkey]{
382 \py@openModSynopsisFile
383 \renewcommand{\py@thismoduletype}{#2}
Fred Drakea488f301998-07-23 17:50:45 +0000384 \ifx\py@modulebadkey#1
385 \renewcommand{\py@thismodulekey}{#3}
386 \else
387 \renewcommand{\py@thismodulekey}{#1}
388 \fi
Fred Drake5bc8d991999-05-17 14:47:10 +0000389 \@ifundefined{py@#2IndexModule}{%
390 \typeout{*** MACRO declaremodule called with unknown module type: `#2'}
Fred Drake66823021999-05-17 14:57:26 +0000391 \py@IndexModule{#3}%
Fred Drake5bc8d991999-05-17 14:47:10 +0000392 }{%
393 \csname py@#2IndexModule\endcsname{#3}%
394 }
Fred Drakea488f301998-07-23 17:50:45 +0000395 \label{module-\py@thismodulekey}
Fred Drakea488f301998-07-23 17:50:45 +0000396}
Fred Drake0c275fa1999-03-02 16:17:44 +0000397\newif\ifpy@ModPlatformFileIsOpen \py@ModPlatformFileIsOpenfalse
398\newcommand{\py@ModPlatformFilename}{\jobname.pla}
399\newcommand{\platform}[1]{
400 \ifpy@ModPlatformFileIsOpen\else
401 \newwrite\py@ModPlatformFile
402 \openout\py@ModPlatformFile=\py@ModPlatformFilename
403 \py@ModPlatformFileIsOpentrue
404 \fi
Fred Drake0c275fa1999-03-02 16:17:44 +0000405}
406\InputIfFileExists{\jobname.pla}{}{}
Fred Drake9466b9a1999-03-18 16:18:27 +0000407\newcommand{\py@platformof}[2][\py@modulebadkey]{%
Fred Drake0c275fa1999-03-02 16:17:44 +0000408 \ifx\py@modulebadkey#1 \def\py@key{#2}%
409 \else \def\py@key{#1}%
410 \fi%
411 \csname py@modplat@\py@key\endcsname%
412}
413\newcommand{\ignorePlatformAnnotation}[1]{}
Fred Drakea488f301998-07-23 17:50:45 +0000414
Fred Drakeb75c6151998-08-10 18:41:43 +0000415% \moduleauthor{name}{email}
416\newcommand{\moduleauthor}[2]{}
417
418% \sectionauthor{name}{email}
419\newcommand{\sectionauthor}[2]{}
420
Fred Drakea488f301998-07-23 17:50:45 +0000421
422\newcommand{\py@defsynopsis}{Module has no synopsis.}
423\newcommand{\py@modulesynopsis}{\py@defsynopsis}
424\newcommand{\modulesynopsis}[1]{
Fred Drake0c275fa1999-03-02 16:17:44 +0000425 \py@HaveModSynopsistrue
Fred Drakea488f301998-07-23 17:50:45 +0000426 \renewcommand{\py@modulesynopsis}{#1}
427}
428
429% define the file
430\newwrite\py@ModSynopsisFile
431
432% hacked from \addtocontents from latex.ltx:
433\long\def\py@writeModSynopsisFile#1{%
434 \protected@write\py@ModSynopsisFile%
435 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
436 {\string#1}%
437}
438\newcommand{\py@closeModSynopsisFile}{
439 \ifpy@ModSynopsisFileIsOpen
440 \closeout\py@ModSynopsisFile
441 \py@ModSynopsisFileIsOpenfalse
442 \fi
443}
444\newcommand{\py@openModSynopsisFile}{
445 \ifpy@ModSynopsisFileIsOpen\else
446 \openout\py@ModSynopsisFile=\py@ModSynopsisFilename
447 \py@ModSynopsisFileIsOpentrue
448 \fi
449}
450
451\newcommand{\py@ProcessModSynopsis}{
452 \ifpy@HaveModSynopsis
453 \py@writeModSynopsisFile{\modulesynopsis%
454 {\py@thismodulekey}{\py@thismodule}%
455 {\py@thismoduletype}{\py@modulesynopsis}}%
456 \py@HaveModSynopsisfalse
457 \fi
458 \renewcommand{\py@modulesynopsis}{\py@defsynopsis}
459}
460\AtEndDocument{\py@ProcessModSynopsis\py@closeModSynopsisFile}
461
Fred Drake0c275fa1999-03-02 16:17:44 +0000462
463\long\def\py@writeModPlatformFile#1{%
464 \protected@write\py@ModPlatformFile%
465 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
466 {\string#1}%
467}
468
469
Fred Drakea488f301998-07-23 17:50:45 +0000470\newcommand{\localmoduletable}{
471 \IfFileExists{\py@ModSynopsisFilename}{
472 \begin{synopsistable}
473 \input{\py@ModSynopsisFilename}
474 \end{synopsistable}
475 }{}
476}
477
Fred Drakee59feb52001-10-29 21:02:28 +0000478\ifpdf
Fred Drakeaa2aea01999-01-27 17:37:36 +0000479 \newcommand{\py@ModSynopsisSummary}[4]{%
480 \py@linkToName{label-module-#1}{\bfcode{#2}} & #4\\
481 }
Fred Drakee59feb52001-10-29 21:02:28 +0000482\else
483 \newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
484\fi
Fred Drakea488f301998-07-23 17:50:45 +0000485\newenvironment{synopsistable}{
486 % key, name, type, synopsis
487 \let\modulesynopsis=\py@ModSynopsisSummary
488 \begin{tabular}{ll}
489}{
490 \end{tabular}
491}
492%
493% --------------------------------------------------------------------------
494
495
Fred Drakea488f301998-07-23 17:50:45 +0000496\newcommand{\py@reset}{
Fred Drakeba828782000-04-03 04:19:14 +0000497 \py@usingsubitemfalse
Fred Drakea488f301998-07-23 17:50:45 +0000498 \py@ProcessModSynopsis
499 \renewcommand{\py@thisclass}{}
500 \renewcommand{\py@thismodule}{}
501 \renewcommand{\py@thismodulekey}{}
502 \renewcommand{\py@thismoduletype}{}
503}
504
505% Augment the sectioning commands used to get our own font family in place,
506% and reset some internal data items:
507\renewcommand{\section}{\py@reset%
508 \@startsection{section}{1}{\z@}%
509 {-3.5ex \@plus -1ex \@minus -.2ex}%
510 {2.3ex \@plus.2ex}%
511 {\reset@font\Large\py@HeaderFamily}}
512\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
513 {-3.25ex\@plus -1ex \@minus -.2ex}%
514 {1.5ex \@plus .2ex}%
515 {\reset@font\large\py@HeaderFamily}}
516\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
517 {-3.25ex\@plus -1ex \@minus -.2ex}%
518 {1.5ex \@plus .2ex}%
519 {\reset@font\normalsize\py@HeaderFamily}}
520\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
521 {3.25ex \@plus1ex \@minus.2ex}%
522 {-1em}%
523 {\reset@font\normalsize\py@HeaderFamily}}
524\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
525 {3.25ex \@plus1ex \@minus .2ex}%
526 {-1em}%
527 {\reset@font\normalsize\py@HeaderFamily}}
528
529
Fred Drake5420f331998-07-23 21:41:02 +0000530% This gets the underscores closer to the right width; the only change
531% from standard LaTeX is the width specified.
532
533\DeclareTextCommandDefault{\textunderscore}{%
534 \leavevmode \kern.06em\vbox{\hrule\@width.55em}}
535
Fred Drakea488f301998-07-23 17:50:45 +0000536% Underscore hack (only act like subscript operator if in math mode)
537%
538% The following is due to Mark Wooding (the old version didn't work with
539% Latex 2e.
540
541\DeclareRobustCommand\hackscore{%
542 \ifmmode_\else\textunderscore\fi%
543}
544\begingroup
545\catcode`\_\active
546\def\next{%
547 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
548}
549\expandafter\endgroup\next
550
551
Fred Drake53714971998-04-02 22:33:16 +0000552% Now for a lot of semantically-loaded environments that do a ton of magical
553% things to get the right formatting and index entries for the stuff in
554% Python modules and C API.
555
556
Fred Drake6659c301998-03-03 22:02:19 +0000557% {fulllineitems} is used in one place in libregex.tex, but is really for
558% internal use in this file.
559%
Fred Drakef9acc591998-09-09 15:27:43 +0000560\newcommand{\py@itemnewline}[1]{%
561 \@tempdima\linewidth%
562 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
563}
564
Fred Drake6659c301998-03-03 22:02:19 +0000565\newenvironment{fulllineitems}{
566 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
567 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
568 \itemsep -\parsep
Fred Drakef9acc591998-09-09 15:27:43 +0000569 \let\makelabel=\py@itemnewline}
Fred Drake6659c301998-03-03 22:02:19 +0000570}{\end{list}}
571
Fred Drake6cb71491998-03-27 05:22:53 +0000572% \optional is mostly for use in the arguments parameters to the various
573% {*desc} environments defined below, but may be used elsewhere. Known to
574% be used in the debugger chapter.
Fred Drake24340ea1998-04-28 18:30:34 +0000575%
576% Typical usage:
577%
578% \begin{funcdesc}{myfunc}{reqparm\optional{, optparm}}
579% ^^^ ^^^
580% No space here No space here
581%
582% When a function has multiple optional parameters, \optional should be
583% nested, not chained. This is right:
584%
585% \begin{funcdesc}{myfunc}{\optional{parm1\optional{, parm2}}}
586%
Fred Drakeba828782000-04-03 04:19:14 +0000587\let\py@badkey=\@undefined
588
Fred Drake6659c301998-03-03 22:02:19 +0000589\newcommand{\optional}[1]{%
590 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
591
Fred Drakeba828782000-04-03 04:19:14 +0000592% This can be used when a function or method accepts an varying number
593% of arguments, such as by using the *args syntax in the parameter list.
594\newcommand{\py@moreargs}{...}
595
596% This can be used when you don't want to document the parameters to a
597% function or method, but simply state that it's an alias for
598% something else.
599\newcommand{\py@unspecified}{...}
600
Fred Drakead74b7d2002-07-02 20:32:50 +0000601
602\newlength{\py@argswidth}
603\newcommand{\py@sigparams}[1]{%
604 \parbox[t]{\py@argswidth}{\py@varvars{#1}\code{)}}}
605\newcommand{\py@sigline}[2]{%
606 \settowidth{\py@argswidth}{#1\code{(}}%
607 \addtolength{\py@argswidth}{-2\py@argswidth}%
608 \addtolength{\py@argswidth}{\textwidth}%
609 \item[#1\code{(}\py@sigparams{#2}]}
610
Fred Drake6cb71491998-03-27 05:22:53 +0000611% C functions ------------------------------------------------------------
Fred Drakeba828782000-04-03 04:19:14 +0000612% \begin{cfuncdesc}[refcount]{type}{name}{arglist}
613% Note that the [refcount] slot should only be filled in by
614% tools/anno-api.py; it pulls the value from the refcounts database.
Fred Drake34adb8a2002-04-15 20:48:40 +0000615\newcommand{\cfuncline}[3]{
Fred Drakead74b7d2002-07-02 20:32:50 +0000616 \py@sigline{\code{#1 \bfcode{#2}}}{#3}%
617 \index{#2@{\py@idxcode{#2()}}}
Fred Drake34adb8a2002-04-15 20:48:40 +0000618}
Fred Drakeba828782000-04-03 04:19:14 +0000619\newenvironment{cfuncdesc}[4][\py@badkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000620 \begin{fulllineitems}
Fred Drake34adb8a2002-04-15 20:48:40 +0000621 \cfuncline{#2}{#3}{#4}
Fred Drakeba828782000-04-03 04:19:14 +0000622 \ifx#1\@undefined\else%
Fred Drake0a863da2000-04-10 18:21:38 +0000623 \emph{Return value: \textbf{#1}.}\\
Fred Drakeba828782000-04-03 04:19:14 +0000624 \fi
Fred Drake6cb71491998-03-27 05:22:53 +0000625}{\end{fulllineitems}}
626
627% C variables ------------------------------------------------------------
628% \begin{cvardesc}{type}{name}
629\newenvironment{cvardesc}[2]{
630 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000631 \item[\code{#1 \bfcode{#2}}\index{#2@{\py@idxcode{#2}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000632}{\end{fulllineitems}}
633
634% C data types -----------------------------------------------------------
Fred Drakeba828782000-04-03 04:19:14 +0000635% \begin{ctypedesc}[index name]{typedef name}
636\newenvironment{ctypedesc}[2][\py@badkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000637 \begin{fulllineitems}
Fred Drakeba828782000-04-03 04:19:14 +0000638 \item[\bfcode{#2}%
639 \ifx#1\@undefined%
Fred Drakea33c5662000-10-29 05:19:16 +0000640 \index{#2@{\py@idxcode{#2}} (C type)}
Fred Drakeba828782000-04-03 04:19:14 +0000641 \else%
Fred Drakea33c5662000-10-29 05:19:16 +0000642 \index{#2@{\py@idxcode{#1}} (C type)}
Fred Drakeba828782000-04-03 04:19:14 +0000643 \fi]
644}{\end{fulllineitems}}
645
Fred Drake01e94612002-04-12 22:48:02 +0000646% C type fields ----------------------------------------------------------
647% \begin{cmemberdesc}{container type}{ctype}{membername}
648\newcommand{\cmemberline}[3]{
649 \item[\code{#2 \bfcode{#3}}]
650 \index{#3@{\py@idxcode{#3}} (#1 member)}
651}
652\newenvironment{cmemberdesc}[3]{
653 \begin{fulllineitems}
654 \cmemberline{#1}{#2}{#3}
655}{\end{fulllineitems}}
656
Fred Drakeba828782000-04-03 04:19:14 +0000657% Funky macros -----------------------------------------------------------
Fred Drake19f827e2002-04-09 20:16:47 +0000658% \begin{csimplemacrodesc}{name}
Fred Drakeba828782000-04-03 04:19:14 +0000659% -- "simple" because it has no args; NOT for constant definitions!
660\newenvironment{csimplemacrodesc}[1]{
661 \begin{fulllineitems}
Fred Drakea33c5662000-10-29 05:19:16 +0000662 \item[\bfcode{#1}\index{#1@{\py@idxcode{#1}} (macro)}]
Fred Drake6cb71491998-03-27 05:22:53 +0000663}{\end{fulllineitems}}
664
665% simple functions (not methods) -----------------------------------------
666% \begin{funcdesc}{name}{args}
Fred Drakeec77e652000-10-30 06:22:22 +0000667\newcommand{\funcline}[2]{%
668 \funclineni{#1}{#2}%
669 \index{#1@{\py@idxcode{#1()}} (in module \py@thismodule)}}
Fred Drake6cb71491998-03-27 05:22:53 +0000670\newenvironment{funcdesc}[2]{
671 \begin{fulllineitems}
672 \funcline{#1}{#2}
673}{\end{fulllineitems}}
674
Fred Drake6659c301998-03-03 22:02:19 +0000675% similar to {funcdesc}, but doesn't add to the index
Fred Drakead74b7d2002-07-02 20:32:50 +0000676\newcommand{\funclineni}[2]{%
677 \py@sigline{\bfcode{#1}}{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000678\newenvironment{funcdescni}[2]{
679 \begin{fulllineitems}
680 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000681}{\end{fulllineitems}}
682
Fred Drake6cb71491998-03-27 05:22:53 +0000683% classes ----------------------------------------------------------------
684% \begin{classdesc}{name}{constructor args}
685\newenvironment{classdesc}[2]{
Fred Drake1cbd1961998-11-25 17:13:28 +0000686 % Using \renewcommand doesn't work for this, for unknown reasons:
687 \global\def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000688 \begin{fulllineitems}
Fred Drakead74b7d2002-07-02 20:32:50 +0000689 \py@sigline{\strong{class }\bfcode{#1}}{#2}%
690 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}
Fred Drake6659c301998-03-03 22:02:19 +0000691}{\end{fulllineitems}}
692
Fred Drake06a01e82001-05-11 01:00:30 +0000693% \begin{classdesc*}{name}
694\newenvironment{classdesc*}[1]{
695 % Using \renewcommand doesn't work for this, for unknown reasons:
696 \global\def\py@thisclass{#1}
697 \begin{fulllineitems}
698 \item[\strong{class }\code{\bfcode{#1}}%
699 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}]
700}{\end{fulllineitems}}
701
Fred Drake4e607962000-09-09 06:01:25 +0000702% \begin{excclassdesc}{name}{constructor args}
703% but indexes as an exception
704\newenvironment{excclassdesc}[2]{
705 % Using \renewcommand doesn't work for this, for unknown reasons:
706 \global\def\py@thisclass{#1}
707 \begin{fulllineitems}
Fred Drakead74b7d2002-07-02 20:32:50 +0000708 \py@sigline{\strong{exception }\bfcode{#1}}{#2}%
709 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}
Fred Drake4e607962000-09-09 06:01:25 +0000710}{\end{fulllineitems}}
711
Fred Drake06a01e82001-05-11 01:00:30 +0000712% There is no corresponding {excclassdesc*} environment. To describe
713% a class exception without parameters, use the {excdesc} environment.
714
Fred Drake6cb71491998-03-27 05:22:53 +0000715
Fred Drake24340ea1998-04-28 18:30:34 +0000716\let\py@classbadkey=\@undefined
Fred Drake6cb71491998-03-27 05:22:53 +0000717
718% object method ----------------------------------------------------------
719% \begin{methoddesc}[classname]{methodname}{args}
Fred Drakea33c5662000-10-29 05:19:16 +0000720\newcommand{\methodline}[3][\@undefined]{
Fred Drake6cb71491998-03-27 05:22:53 +0000721 \methodlineni{#2}{#3}
722 \ifx#1\@undefined
Fred Drakea33c5662000-10-29 05:19:16 +0000723 \index{#2@{\py@idxcode{#2()}} (\py@thisclass\ method)}
Fred Drake6cb71491998-03-27 05:22:53 +0000724 \else
Fred Drakea33c5662000-10-29 05:19:16 +0000725 \index{#2@{\py@idxcode{#2()}} (#1 method)}
Fred Drake6cb71491998-03-27 05:22:53 +0000726 \fi
727}
Fred Drakea33c5662000-10-29 05:19:16 +0000728\newenvironment{methoddesc}[3][\@undefined]{
Fred Drake6cb71491998-03-27 05:22:53 +0000729 \begin{fulllineitems}
730 \ifx#1\@undefined
731 \methodline{#2}{#3}
732 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000733 \def\py@thisclass{#1}
Fred Drakea33c5662000-10-29 05:19:16 +0000734 \methodline{#2}{#3}
Fred Drake6cb71491998-03-27 05:22:53 +0000735 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000736}{\end{fulllineitems}}
737
Fred Drake6cb71491998-03-27 05:22:53 +0000738% similar to {methoddesc}, but doesn't add to the index
739% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000740\newcommand{\methodlineni}[3][\py@classbadkey]{%
Fred Drakead74b7d2002-07-02 20:32:50 +0000741 \py@sigline{\bfcode{#2}}{#3}}
Fred Drake24340ea1998-04-28 18:30:34 +0000742\newenvironment{methoddescni}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000743 \begin{fulllineitems}
744 \methodlineni{#2}{#3}
745}{\end{fulllineitems}}
746
747% object data attribute --------------------------------------------------
748% \begin{memberdesc}[classname]{membername}
Fred Drake24340ea1998-04-28 18:30:34 +0000749\newcommand{\memberline}[2][\py@classbadkey]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000750 \ifx#1\@undefined
751 \memberlineni{#2}
Fred Drakea33c5662000-10-29 05:19:16 +0000752 \index{#2@{\py@idxcode{#2}} (\py@thisclass\ attribute)}
Fred Drake6cb71491998-03-27 05:22:53 +0000753 \else
754 \memberlineni{#2}
Fred Drakea33c5662000-10-29 05:19:16 +0000755 \index{#2@{\py@idxcode{#2}} (#1 attribute)}
Fred Drake6cb71491998-03-27 05:22:53 +0000756 \fi
757}
Fred Drake24340ea1998-04-28 18:30:34 +0000758\newenvironment{memberdesc}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000759 \begin{fulllineitems}
760 \ifx#1\@undefined
761 \memberline{#2}
762 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000763 \def\py@thisclass{#1}
Fred Drakea33c5662000-10-29 05:19:16 +0000764 \memberline{#2}
Fred Drake6cb71491998-03-27 05:22:53 +0000765 \fi
766}{\end{fulllineitems}}
767
768% similar to {memberdesc}, but doesn't add to the index
769% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000770\newcommand{\memberlineni}[2][\py@classbadkey]{\item[\bfcode{#2}]}
771\newenvironment{memberdescni}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000772 \begin{fulllineitems}
773 \memberlineni{#2}
774}{\end{fulllineitems}}
775
776% For exceptions: --------------------------------------------------------
777% \begin{excdesc}{name}
Fred Drakea33c5662000-10-29 05:19:16 +0000778% -- for constructor information, use excclassdesc instead
Fred Drake6cb71491998-03-27 05:22:53 +0000779\newenvironment{excdesc}[1]{
780 \begin{fulllineitems}
Fred Drakeab357ec2001-03-02 18:57:05 +0000781 \item[\strong{exception }\bfcode{#1}%
Fred Drakea33c5662000-10-29 05:19:16 +0000782 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}]
Fred Drake6cb71491998-03-27 05:22:53 +0000783}{\end{fulllineitems}}
784
785% Module data or constants: ----------------------------------------------
786% \begin{datadesc}{name}
Fred Drakea33c5662000-10-29 05:19:16 +0000787\newcommand{\dataline}[1]{%
788 \datalineni{#1}\index{#1@{\py@idxcode{#1}} (data in \py@thismodule)}}
Fred Drake6cb71491998-03-27 05:22:53 +0000789\newenvironment{datadesc}[1]{
790 \begin{fulllineitems}
791 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000792}{\end{fulllineitems}}
793
794% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000795\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
796\newenvironment{datadescni}[1]{
797 \begin{fulllineitems}
798 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000799}{\end{fulllineitems}}
800
Fred Drake6cb71491998-03-27 05:22:53 +0000801% bytecode instruction ---------------------------------------------------
802% \begin{opcodedesc}{name}{var}
803% -- {var} may be {}
804\newenvironment{opcodedesc}[2]{
805 \begin{fulllineitems}
806 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000807}{\end{fulllineitems}}
808
809
Fred Drake24340ea1998-04-28 18:30:34 +0000810\newcommand{\nodename}[1]{\label{#1}}
Fred Drake55730311998-03-25 15:41:23 +0000811
Fred Drake6659c301998-03-03 22:02:19 +0000812% For these commands, use \command{} to get the typography right, not
813% {\command}. This works better with the texinfo translation.
814\newcommand{\ABC}{{\sc abc}}
815\newcommand{\UNIX}{{\sc Unix}}
816\newcommand{\POSIX}{POSIX}
817\newcommand{\ASCII}{{\sc ascii}}
818\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
819\newcommand{\C}{C}
820\newcommand{\EOF}{{\sc eof}}
Fred Drake24340ea1998-04-28 18:30:34 +0000821\newcommand{\NULL}{\constant{NULL}}
Fred Drake5445e5e2001-06-23 03:11:45 +0000822\newcommand{\infinity}{\ensuremath{\infty}}
823\newcommand{\plusminus}{\ensuremath{\pm}}
Fred Drakeb4812862002-08-02 18:30:22 +0000824% \menuselection{Start \sub Programs \sub Python}
Fred Drakebd5fdd92003-07-16 14:01:56 +0000825\newcommand{\menuselection}[1]{\textsf{\def\sub{ \ensuremath{>} }#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000826
Fred Drake53714971998-04-02 22:33:16 +0000827% Also for consistency: spell Python "Python", not "python"!
828
Fred Drake6659c301998-03-03 22:02:19 +0000829% code is the most difficult one...
Fred Drake46346ec2000-06-30 17:57:05 +0000830\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 +0000831\texttt{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000832
833\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Fred Drake19f827e2002-04-09 20:16:47 +0000834\newcommand{\csimplemacro}[1]{\code{#1}}
Fred Drake8e54abe1998-07-01 14:49:25 +0000835\newcommand{\kbd}[1]{\code{#1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000836\newcommand{\samp}[1]{`\code{#1}'}
Fred Drakefa1cceb1998-11-30 14:42:59 +0000837\newcommand{\var}[1]{%
838 \ifmmode%
Fred Drakeff031cf2002-10-31 21:04:34 +0000839 \hbox{\py@defaultsize\textrm{\textit{#1\/}}}%
Fred Drakefa1cceb1998-11-30 14:42:59 +0000840 \else%
Fred Drakeff031cf2002-10-31 21:04:34 +0000841 \py@defaultsize\textrm{\textit{#1\/}}%
Fred Drakefa1cceb1998-11-30 14:42:59 +0000842 \fi%
843}
Fred Drake24340ea1998-04-28 18:30:34 +0000844\renewcommand{\emph}[1]{{\em #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000845\newcommand{\dfn}[1]{\emph{#1}}
846\newcommand{\strong}[1]{{\bf #1}}
847% let's experiment with a new font:
Fred Drakeff031cf2002-10-31 21:04:34 +0000848\newcommand{\file}[1]{`\filenq{#1}'}
849\newcommand{\filenq}[1]{{\py@smallsize\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000850
851% Use this def/redef approach for \url{} since hyperref defined this already,
852% but only if we actually used hyperref:
Fred Drakee59feb52001-10-29 21:02:28 +0000853\ifpdf
854 \newcommand{\url}[1]{{%
Fred Drake15fc72c2002-03-26 19:14:41 +0000855 \noindent%
Fred Drake53815882002-03-15 23:21:37 +0000856 \pdfstartlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
Fred Drakeab357ec2001-03-02 18:57:05 +0000857 \py@LinkColor% color of the link text
Fred Drakeff031cf2002-10-31 21:04:34 +0000858 \py@smallsize\sf #1%
Fred Drakeab357ec2001-03-02 18:57:05 +0000859 \py@NormalColor% Turn it back off; these are declarative
860 \pdfendlink}% and don't appear bound to the current
861 }% formatting "box".
Fred Drakee59feb52001-10-29 21:02:28 +0000862\else
Fred Drakeff031cf2002-10-31 21:04:34 +0000863 \newcommand{\url}[1]{\mbox{\py@smallsize\textsf{#1}}}
Fred Drakee59feb52001-10-29 21:02:28 +0000864\fi
Fred Drakeff031cf2002-10-31 21:04:34 +0000865\newcommand{\email}[1]{{\py@smallsize\textsf{#1}}}
866\newcommand{\newsgroup}[1]{{\py@smallsize\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000867
Fred Drakecc2b81e2000-08-03 17:38:30 +0000868\newcommand{\py@varvars}[1]{{%
Fred Drakeba828782000-04-03 04:19:14 +0000869 {\let\unspecified=\py@unspecified%
870 \let\moreargs=\py@moreargs%
Fred Drakecc2b81e2000-08-03 17:38:30 +0000871 \var{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000872
Fred Drake24340ea1998-04-28 18:30:34 +0000873% I'd really like to get rid of this!
Fred Drake6659c301998-03-03 22:02:19 +0000874\newif\iftexi\texifalse
Fred Drake6659c301998-03-03 22:02:19 +0000875
Fred Drake1e4973b1998-07-28 21:52:17 +0000876% This is used to get l2h to put the copyright and abstract on
877% a separate HTML page.
878\newif\ifhtml\htmlfalse
879
880
Fred Drake6659c301998-03-03 22:02:19 +0000881% These should be used for all references to identifiers which are
882% used to refer to instances of specific language constructs. See the
883% names for specific semantic assignments.
884%
885% For now, don't do anything really fancy with them; just use them as
886% logical markup. This might change in the future.
887%
Fred Drake24340ea1998-04-28 18:30:34 +0000888\newcommand{\module}[1]{\texttt{#1}}
889\newcommand{\keyword}[1]{\texttt{#1}}
890\newcommand{\exception}[1]{\texttt{#1}}
891\newcommand{\class}[1]{\texttt{#1}}
892\newcommand{\function}[1]{\texttt{#1}}
893\newcommand{\member}[1]{\texttt{#1}}
894\newcommand{\method}[1]{\texttt{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000895
Fred Drakeab357ec2001-03-02 18:57:05 +0000896\newcommand{\pytype}[1]{#1} % built-in Python type
Fred Drake53714971998-04-02 22:33:16 +0000897
Fred Drake24340ea1998-04-28 18:30:34 +0000898\newcommand{\cfunction}[1]{\texttt{#1}}
Fred Drakeab357ec2001-03-02 18:57:05 +0000899\newcommand{\ctype}[1]{\texttt{#1}} % C struct or typedef name
900\newcommand{\cdata}[1]{\texttt{#1}} % C variable, typically global
Fred Drake6659c301998-03-03 22:02:19 +0000901
Fred Drakeff031cf2002-10-31 21:04:34 +0000902\newcommand{\mailheader}[1]{{\py@smallsize\textsf{#1:}}}
903\newcommand{\mimetype}[1]{{\py@smallsize\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000904% The \! is a "negative thin space" in math mode.
905\newcommand{\regexp}[1]{%
906 {\tiny$^{^\lceil}\!\!$%
Fred Drakeff031cf2002-10-31 21:04:34 +0000907 {\py@defaultsize\code{#1}}%
Fred Drake47cfd031998-04-03 21:22:31 +0000908 $\!\rfloor\!$%
Fred Drake94fac131998-03-12 19:37:03 +0000909 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000910\newcommand{\envvar}[1]{%
Fred Drake31ab2982001-01-22 17:50:42 +0000911 #1%
Fred Drakee59feb52001-10-29 21:02:28 +0000912 \index{#1}%
Fred Drake31ab2982001-01-22 17:50:42 +0000913 \index{environment variables!{#1}}%
Fred Drake0ee9f721998-03-12 06:41:40 +0000914}
Fred Drakeab357ec2001-03-02 18:57:05 +0000915\newcommand{\makevar}[1]{#1} % variable in a Makefile
Fred Drake24340ea1998-04-28 18:30:34 +0000916\newcommand{\character}[1]{\samp{#1}}
Fred Drake0ee9f721998-03-12 06:41:40 +0000917
Fred Drake6659c301998-03-03 22:02:19 +0000918% constants defined in Python modules or C headers, not language constants:
Fred Drakeab357ec2001-03-02 18:57:05 +0000919\newcommand{\constant}[1]{\code{#1}} % manifest constant, not syntactic
Fred Drake6659c301998-03-03 22:02:19 +0000920
921\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake4e607962000-09-09 06:01:25 +0000922\newcommand{\pep}[1]{PEP #1\index{Python Enhancement Proposals!PEP #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000923\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
924\newcommand{\program}[1]{\strong{#1}}
Fred Drake7b8195a1999-11-09 17:02:11 +0000925\newcommand{\programopt}[1]{\strong{#1}}
Fred Drake49362492000-04-11 18:47:59 +0000926% Note that \longprogramopt provides the '--'!
927\newcommand{\longprogramopt}[1]{\strong{-{}-#1}}
Fred Drakee59feb52001-10-29 21:02:28 +0000928
Fred Drakeb4b64da2001-07-06 22:44:48 +0000929% \ulink{link text}{URL}
Fred Drakee59feb52001-10-29 21:02:28 +0000930\ifpdf
931 % The \noindent here is a hack -- we're forcing pdfTeX into
Fred Drake53815882002-03-15 23:21:37 +0000932 % horizontal mode since \pdfstartlink requires that.
Fred Drakec8b08b42003-09-06 04:19:43 +0000933 % For PDF, we *should* only generate a link when the URL is absolute.
Fred Drakee59feb52001-10-29 21:02:28 +0000934 \newcommand{\ulink}[2]{\noindent{%
Fred Drake53815882002-03-15 23:21:37 +0000935 \pdfstartlink attr{/Border [0 0 0]} user{/S /URI /URI (#2)}%
Fred Drakee59feb52001-10-29 21:02:28 +0000936 \py@LinkColor% color of the link text
937 #1%
938 \py@NormalColor% Turn it back off; these are declarative
939 \pdfendlink}% and don't appear bound to the current
940 }% formatting "box".
941\else
942 \newcommand{\ulink}[2]{#1}
943\fi
Fred Drake7b8195a1999-11-09 17:02:11 +0000944
945% cited titles: \citetitle{Title of Work}
946% online: \citetitle[url-to-resource]{Title of Work}
Fred Drakee59feb52001-10-29 21:02:28 +0000947\ifpdf
948 \newcommand{\citetitle}[2][\py@modulebadkey]{%
949 \ifx\py@modulebadkey#1\emph{#2}\else\ulink{\emph{#2}}{#1}\fi%
950 }
951\else
Fred Drake622087a2001-11-02 20:53:19 +0000952 \newcommand{\citetitle}[2][URL]{\emph{#2}}
Fred Drakee59feb52001-10-29 21:02:28 +0000953\fi
954
Fred Drake6659c301998-03-03 22:02:19 +0000955
956
Fred Drakec82bd722001-12-11 18:47:36 +0000957% This version is being checked in for the historical record; it shows
958% how I've managed to get some aspects of this to work. It will not
959% be used in practice, so a subsequent revision will change things
960% again. This version has problems, but shows how to do something
961% that proved more tedious than I'd expected, so I don't want to lose
962% the example completely.
963%
Fred Drake16bb4192001-08-20 21:36:38 +0000964\newcommand{\grammartoken}[1]{\texttt{#1}}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000965\newenvironment{productionlist}[1][\py@badkey]{
966 \def\optional##1{{\Large[}##1{\Large]}}
967 \def\production##1##2{\code{##1}&::=&\code{##2}\\}
Fred Drake53815882002-03-15 23:21:37 +0000968 \def\productioncont##1{& &\code{##1}\\}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000969 \def\token##1{##1}
Fred Drake16bb4192001-08-20 21:36:38 +0000970 \let\grammartoken=\token
Fred Drakec82bd722001-12-11 18:47:36 +0000971 \parindent=2em
972 \indent
973 \begin{tabular}{lcl}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000974}{%
Fred Drakec82bd722001-12-11 18:47:36 +0000975 \end{tabular}
Fred Drakeb4b64da2001-07-06 22:44:48 +0000976}
977
Fred Drake6ca33772001-12-14 22:50:06 +0000978\newcommand{\py@noticelabel@note}{Note:}
979\newcommand{\py@noticelabel@warning}{Warning:}
980\newenvironment{notice}[1][note]{
981 \par\strong{\csname py@noticelabel@#1\endcsname}
982}{}
983\newcommand{\note}[1]{\strong{\py@noticelabel@note} #1}
984\newcommand{\warning}[1]{\strong{\py@noticelabel@warning} #1}
Fred Drake92350b32001-10-09 18:01:23 +0000985
Fred Drake6659c301998-03-03 22:02:19 +0000986% Deprecation stuff.
987% Should be extended to allow an index / list of deprecated stuff. But
988% there's a lot of stuff that needs to be done to make that automatable.
989%
990% First parameter is the release number that deprecates the feature, the
991% second is the action the should be taken by users of the feature.
992%
993% Example:
Fred Drake24340ea1998-04-28 18:30:34 +0000994% \deprecated{1.5.1}{Use \method{frobnicate()} instead.}
Fred Drake6659c301998-03-03 22:02:19 +0000995%
996\newcommand{\deprecated}[2]{%
997 \strong{Deprecated since release #1.} #2\par}
998
Fred Drakeaf958c71998-07-27 20:32:33 +0000999% New stuff.
1000% This should be used to mark things which have been added to the
1001% development tree but that aren't in the release, but are documented.
1002% This allows release of documentation that already includes updated
Fred Drake2116d981999-02-02 18:02:48 +00001003% descriptions. Place at end of descriptor environment.
Fred Drakeaf958c71998-07-27 20:32:33 +00001004%
1005% Example:
1006% \versionadded{1.5.2}
Fred Drake46346ec2000-06-30 17:57:05 +00001007% \versionchanged[short explanation]{2.0}
Fred Drakeaf958c71998-07-27 20:32:33 +00001008%
Fred Drakefdfb05b2001-04-18 03:08:54 +00001009\newcommand{\versionadded}[2][\py@badkey]{%
1010 \ifx#1\@undefined%
1011 { New in version #2. }%
1012 \else%
1013 { New in version #2:\ #1. }%
1014 \fi%
1015}
Fred Drakea6e83392000-05-02 17:28:36 +00001016\newcommand{\versionchanged}[2][\py@badkey]{%
1017 \ifx#1\@undefined%
1018 { Changed in version #2. }%
1019 \else%
1020 { Changed in version #2:\ #1. }%
1021 \fi%
1022}
Fred Drake6659c301998-03-03 22:02:19 +00001023
Fred Drakeaf958c71998-07-27 20:32:33 +00001024
1025% Tables.
1026%
Fred Drake6659c301998-03-03 22:02:19 +00001027\newenvironment{tableii}[4]{%
1028 \begin{center}%
1029 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakef61eac42000-10-24 02:18:30 +00001030 \begin{tabular}{#1}\strong{#3}&\strong{#4} \\* \hline%
Fred Drake6659c301998-03-03 22:02:19 +00001031}{%
Fred Drake6659c301998-03-03 22:02:19 +00001032 \end{tabular}%
1033 \end{center}%
1034}
1035
Fred Drakeda72b932000-09-21 15:58:02 +00001036\newenvironment{longtableii}[4]{%
1037 \begin{center}%
1038 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakef61eac42000-10-24 02:18:30 +00001039 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4} \\* \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001040}{%
1041 \end{longtable}%
1042 \end{center}%
1043}
1044
Fred Drake6659c301998-03-03 22:02:19 +00001045\newenvironment{tableiii}[5]{%
1046 \begin{center}%
1047 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
Fred Drakeda72b932000-09-21 15:58:02 +00001048 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001049 \hline%
Fred Drake6659c301998-03-03 22:02:19 +00001050}{%
Fred Drake6659c301998-03-03 22:02:19 +00001051 \end{tabular}%
1052 \end{center}%
1053}
1054
Fred Drakeda72b932000-09-21 15:58:02 +00001055\newenvironment{longtableiii}[5]{%
1056 \begin{center}%
1057 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
1058 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001059 \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001060}{%
1061 \end{longtable}%
1062 \end{center}%
1063}
1064
Fred Drake30e52651998-07-24 22:11:29 +00001065\newenvironment{tableiv}[6]{%
1066 \begin{center}%
1067 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
1068 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6} \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001069 \hline%
Fred Drake30e52651998-07-24 22:11:29 +00001070}{%
1071 \end{tabular}%
1072 \end{center}%
1073}
1074
Fred Drakeda72b932000-09-21 15:58:02 +00001075\newenvironment{longtableiv}[6]{%
1076 \begin{center}%
1077 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
1078 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}%
1079 \\%
Fred Drakef61eac42000-10-24 02:18:30 +00001080 \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +00001081}{%
1082 \end{longtable}%
1083 \end{center}%
1084}
1085
Fred Drakef269e592001-07-17 23:05:57 +00001086\newenvironment{tablev}[7]{%
1087 \begin{center}%
1088 \def\linev##1##2##3##4##5{\csname#2\endcsname{##1}&##2&##3&##4&##5\\}%
1089 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}&\strong{#7} \\%
1090 \hline%
1091}{%
1092 \end{tabular}%
1093 \end{center}%
1094}
1095
1096\newenvironment{longtablev}[7]{%
1097 \begin{center}%
1098 \def\linev##1##2##3##4##5{\csname#2\endcsname{##1}&##2&##3&##4&##5\\}%
1099 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}&\strong{#7}%
1100 \\%
1101 \hline\endhead%
1102}{%
1103 \end{longtable}%
1104 \end{center}%
1105}
1106
Fred Drake567332a2002-12-30 20:51:27 +00001107% XXX Don't think we can use this yet, though it cleans up some
1108% tedious markup. There's no equivalent for the HTML transform yet,
1109% and that needs to exist. I don't know how to write it.
1110%
1111% This should really have something that makes it easier to bind a
1112% table's ``Notes'' column and an associated tablenotes environment,
1113% and generates the right magic for getting the numbers right in the
1114% table.
1115%
1116% So this is quite incomplete.
1117%
1118\newcounter{py@tablenotescounter}
1119\newenvironment{tablenotes}{%
1120 \noindent Notes:
1121 \par
1122 \setcounter{py@tablenotescounter}{0}
1123 \begin{list}{(\arabic{py@tablenotescounter})}%
1124 {\usecounter{py@tablenotescounter}}
1125}{\end{list}}
1126
1127
Fred Drake24340ea1998-04-28 18:30:34 +00001128% Cross-referencing (AMK, new impl. FLD)
Fred Drake6659c301998-03-03 22:02:19 +00001129% Sample usage:
1130% \begin{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +00001131% \seemodule{rand}{Uniform random number generator.}; % Module xref
1132% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +00001133%
1134% % A funky case: module name contains '_'; have to supply an optional key
Fred Drake84bd6f31999-05-11 15:42:51 +00001135% \seemodule[copyreg]{copy_reg}{Interface constructor registration for
1136% \module{pickle}.}
Fred Drake6659c301998-03-03 22:02:19 +00001137% \end{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +00001138%
1139% Note that the last parameter for \seemodule and \seetext should be complete
1140% sentences and be terminated with the proper punctuation.
Fred Drake6659c301998-03-03 22:02:19 +00001141
Fred Drakee59feb52001-10-29 21:02:28 +00001142\ifpdf
Fred Drake24340ea1998-04-28 18:30:34 +00001143 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +00001144 \par%
Fred Drake24340ea1998-04-28 18:30:34 +00001145 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drake84bd6f31999-05-11 15:42:51 +00001146 \begin{fulllineitems}
Fred Drake84bd6f31999-05-11 15:42:51 +00001147 \item[\py@linkToName{label-module-\py@modulekey}{Module \module{#2}}
1148 (section \ref{module-\py@modulekey}):]
1149 #3
1150 \end{fulllineitems}
Fred Drakeebcb6581998-03-06 21:25:17 +00001151 }
Fred Drakee59feb52001-10-29 21:02:28 +00001152\else
1153 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
1154 \par%
1155 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
1156 \begin{fulllineitems}
1157 \item[Module \module{#2} (section \ref{module-\py@modulekey}):]
1158 #3
1159 \end{fulllineitems}
1160 }
1161\fi
1162
Fred Drake48449982000-09-12 17:52:33 +00001163% \seetitle[url]{title}{why it's interesting}
1164\newcommand{\py@seetitle}[3][\py@modulebadkey]{%
1165 \par
1166 \begin{fulllineitems}
1167 \item[\citetitle{#2}]
1168 \ifx\py@modulebadkey#1\else
1169 \item[{\small{(\url{#1})}}]
1170 \fi
1171 #3
1172 \end{fulllineitems}
1173}
Fred Drake4e607962000-09-09 06:01:25 +00001174% \seepep{number}{title}{why it's interesting}
1175\newcommand{\py@seepep}[3]{%
1176 \par%
1177 \begin{fulllineitems}
1178 \item[\pep{#1}, ``\emph{#2}'']
1179 #3
1180 \end{fulllineitems}
1181}
Fred Drake64b72b62000-04-26 18:13:58 +00001182% \seerfc{number}{title}{why it's interesting}
1183\newcommand{\py@seerfc}[3]{%
1184 \par%
1185 \begin{fulllineitems}
1186 \item[\rfc{#1}, ``\emph{#2}'']
1187 #3
1188 \end{fulllineitems}
1189}
Fred Drake51313f12000-05-09 16:18:44 +00001190% \seeurl{url}{why it's interesting}
1191\newcommand{\py@seeurl}[2]{%
1192 \par%
1193 \begin{fulllineitems}
1194 \item[\url{#1}]
1195 #2
1196 \end{fulllineitems}
1197}
Fred Drake5ed35fd2001-11-30 18:09:54 +00001198
1199\newenvironment{seealso*}{
Fred Drake9466b9a1999-03-18 16:18:27 +00001200 \par
Fred Drake6659c301998-03-03 22:02:19 +00001201 \def\seetext##1{\par{##1}}
Fred Drake24340ea1998-04-28 18:30:34 +00001202 \let\seemodule=\py@seemodule
Fred Drake48449982000-09-12 17:52:33 +00001203 \let\seepep=\py@seepep
Fred Drake64b72b62000-04-26 18:13:58 +00001204 \let\seerfc=\py@seerfc
Fred Drake48449982000-09-12 17:52:33 +00001205 \let\seetitle=\py@seetitle
Fred Drake51313f12000-05-09 16:18:44 +00001206 \let\seeurl=\py@seeurl
Fred Drake6659c301998-03-03 22:02:19 +00001207}{\par}
Fred Drake5ed35fd2001-11-30 18:09:54 +00001208\newenvironment{seealso}{
1209 \par
1210 \strong{See Also:}
1211 \par
1212 \def\seetext##1{\par{##1}}
1213 \let\seemodule=\py@seemodule
1214 \let\seepep=\py@seepep
1215 \let\seerfc=\py@seerfc
1216 \let\seetitle=\py@seetitle
1217 \let\seeurl=\py@seeurl
1218}{\par}
Fred Drake6659c301998-03-03 22:02:19 +00001219
Fred Drakeaf958c71998-07-27 20:32:33 +00001220% Allow the Python release number to be specified independently of the
Fred Drake6659c301998-03-03 22:02:19 +00001221% \date{}. This allows the date to reflect the document's date and
1222% release to specify the Python release that is documented.
1223%
Fred Drake24340ea1998-04-28 18:30:34 +00001224\newcommand{\py@release}{}
Fred Drake6659c301998-03-03 22:02:19 +00001225\newcommand{\version}{}
Fred Drakeaf2b7142000-09-14 20:11:05 +00001226\newcommand{\shortversion}{}
Fred Drakec65218e2001-06-20 21:17:09 +00001227\newcommand{\releaseinfo}{}
Fred Drake6659c301998-03-03 22:02:19 +00001228\newcommand{\releasename}{Release}
1229\newcommand{\release}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +00001230 \renewcommand{\py@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +00001231 \renewcommand{\version}{#1}}
Fred Drakeaf2b7142000-09-14 20:11:05 +00001232\newcommand{\setshortversion}[1]{%
1233 \renewcommand{\shortversion}{#1}}
Fred Drakec65218e2001-06-20 21:17:09 +00001234\newcommand{\setreleaseinfo}[1]{%
1235 \renewcommand{\releaseinfo}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +00001236
1237% Allow specification of the author's address separately from the
1238% author's name. This can be used to format them differently, which
1239% is a good thing.
1240%
Fred Drake24340ea1998-04-28 18:30:34 +00001241\newcommand{\py@authoraddress}{}
1242\newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress}{#1}}
Fred Drake6df93ef1998-05-14 20:56:31 +00001243\let\developersaddress=\authoraddress
1244\let\developer=\author
1245\let\developers=\author
Fred Drake6659c301998-03-03 22:02:19 +00001246
Fred Drake6659c301998-03-03 22:02:19 +00001247% This sets up the fancy chapter headings that make the documents look
1248% at least a little better than the usual LaTeX output.
1249%
Fred Drake1c8d0e01998-03-07 05:29:15 +00001250\@ifundefined{ChTitleVar}{}{
Fred Drake24340ea1998-04-28 18:30:34 +00001251 \ChNameVar{\raggedleft\normalsize\py@HeaderFamily}
1252 \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily}
1253 \ChTitleVar{\raggedleft \rm\Huge\py@HeaderFamily}
Fred Drake6659c301998-03-03 22:02:19 +00001254 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +00001255 \def\@makechapterhead#1{%
1256 {\parindent \z@ \raggedright \normalfont
1257 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +00001258 \DOCH
1259 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +00001260 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +00001261 \DOTI{#1}
1262 }
1263 }
Fred Drake6659c301998-03-03 22:02:19 +00001264}
1265
Fred Drake3bf78651998-05-20 17:42:17 +00001266
1267% Definition lists; requested by AMK for HOWTO documents. Probably useful
1268% elsewhere as well, so keep in in the general style support.
1269%
1270\newenvironment{definitions}{%
1271 \begin{description}%
Fred Drakef9acc591998-09-09 15:27:43 +00001272 \def\term##1{\item[##1]\mbox{}\\*[0mm]}
Fred Drake3bf78651998-05-20 17:42:17 +00001273}{%
1274 \end{description}%
1275}
1276
Fred Drake6659c301998-03-03 22:02:19 +00001277% Tell TeX about pathological hyphenation cases:
1278\hyphenation{Base-HTTP-Re-quest-Hand-ler}