blob: b4b6aea31d628b8650f3f8a671a3be932f6dca83 [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 Drakec0b2e451998-03-25 14:53:43 +000029\ifx\pdfoutput\undefined\else\ifcase\pdfoutput
Fred Drakec0b2e451998-03-25 14:53:43 +000030\else
Fred Drake6659c301998-03-03 22:02:19 +000031 \input{pdfcolor}
Fred Drake24340ea1998-04-28 18:30:34 +000032 \let\py@LinkColor=\NavyBlue
33 \let\py@NormalColor=\Black
Fred Drake6659c301998-03-03 22:02:19 +000034 \pdfcompresslevel=9
Fred Drakeba1700c1998-05-11 20:42:54 +000035 \pdfpagewidth=\paperwidth % page width of PDF output
36 \pdfpageheight=\paperheight % page height of PDF output
Fred Drakeebcb6581998-03-06 21:25:17 +000037 %
Fred Drakea2c2a831998-04-15 17:50:01 +000038 % Pad the number with '0' to 3 digits wide so no page name is a prefix
39 % of any other.
40 %
Fred Drakea488f301998-07-23 17:50:45 +000041 \newcommand{\py@targetno}[1]{\ifnum#1<100 0\fi\ifnum#1<10 0\fi#1}
42 \newcommand{\py@pageno}{\py@targetno\thepage}
Fred Drakea2c2a831998-04-15 17:50:01 +000043 %
Fred Drakeebcb6581998-03-06 21:25:17 +000044 % This definition allows the entries in the page-view of the ToC to be
45 % active links. Some work, some don't.
46 %
Fred Drake24340ea1998-04-28 18:30:34 +000047 \let\py@OldContentsline=\contentsline
Fred Drakeaa2aea01999-01-27 17:37:36 +000048 %
49 % Macro that takes two args: the name to link to and the content of
50 % the link. This takes care of the PDF magic, getting the colors
51 % the same for each link, and avoids having lots of garbage all over
52 % this style file.
53 \newcommand{\py@linkToName}[2]{%
54 \pdfannotlink attr{/Border [0 0 0]} goto name{#1}%
55 \py@LinkColor#2\py@NormalColor%
56 \pdfendlink%
57 }
Fred Drakea2c2a831998-04-15 17:50:01 +000058 % Compute the padded page number separately since we end up with a pair of
59 % \relax tokens; this gets the right string computed and works.
Fred Drake6659c301998-03-03 22:02:19 +000060 \renewcommand{\contentsline}[3]{%
Fred Drakea2c2a831998-04-15 17:50:01 +000061 \def\my@pageno{\py@targetno{#3}}%
Fred Drakeaa2aea01999-01-27 17:37:36 +000062 \py@OldContentsline{#1}{\py@linkToName{page\my@pageno}{#2}}{#3}%
Fred Drake6659c301998-03-03 22:02:19 +000063 }
Fred Drakeebcb6581998-03-06 21:25:17 +000064 \AtEndDocument{
Fred Drakec0b2e451998-03-25 14:53:43 +000065 \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
Fred Drakeebcb6581998-03-06 21:25:17 +000066 }
Fred Drakea2c2a831998-04-15 17:50:01 +000067 \newcommand{\py@target}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000068 \ifpy@doing@page@targets%
Fred Drake9b8afde1999-03-24 14:16:17 +000069 {\pdfdest name{#1} xyz}%
Fred Drakea2c2a831998-04-15 17:50:01 +000070 \fi%
71 }
Fred Drake24340ea1998-04-28 18:30:34 +000072 \let\py@OldLabel=\label
Fred Drake6659c301998-03-03 22:02:19 +000073 \renewcommand{\label}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000074 \py@OldLabel{#1}%
Fred Drakea2c2a831998-04-15 17:50:01 +000075 \py@target{label-#1}%
Fred Drake6659c301998-03-03 22:02:19 +000076 }
Fred Drakeba1700c1998-05-11 20:42:54 +000077 % This stuff adds a page# destination to every PDF page, where # is three
78 % digits wide, padded with leading zeros. This doesn't really help with
79 % the frontmatter, but does fine with the body.
Fred Drake6659c301998-03-03 22:02:19 +000080 %
81 % This is *heavily* based on the hyperref package.
82 %
Fred Drake1c8d0e01998-03-07 05:29:15 +000083 \def\@begindvi{%
84 \unvbox \@begindvibox
85 \@hyperfixhead
Fred Drake6659c301998-03-03 22:02:19 +000086 }
Fred Drake1c8d0e01998-03-07 05:29:15 +000087 \def\@hyperfixhead{%
88 \let\H@old@thehead\@thehead
Fred Drakea2c2a831998-04-15 17:50:01 +000089 \global\def\@foo{\py@target{page\py@pageno}}%
Fred Drake1c8d0e01998-03-07 05:29:15 +000090 \expandafter\ifx\expandafter\@empty\H@old@thehead
91 \def\H@old@thehead{\hfil}\fi
92 \def\@thehead{\@foo\relax\H@old@thehead}%
Fred Drake6659c301998-03-03 22:02:19 +000093 }
Fred Drakec0b2e451998-03-25 14:53:43 +000094\fi\fi
Fred Drake6659c301998-03-03 22:02:19 +000095
96% Increase printable page size (copied from fullpage.sty)
97\topmargin 0pt
98\advance \topmargin by -\headheight
99\advance \topmargin by -\headsep
100
101% attempt to work a little better for A4 users
Fred Drake9466b9a1999-03-18 16:18:27 +0000102\textheight \paperheight
103\advance\textheight by -2in
Fred Drake6659c301998-03-03 22:02:19 +0000104
105\oddsidemargin 0pt
Fred Drake9466b9a1999-03-18 16:18:27 +0000106\evensidemargin 0pt
107%\evensidemargin -.25in % for ``manual size'' documents
Fred Drake6659c301998-03-03 22:02:19 +0000108\marginparwidth 0.5in
109
Fred Drake9466b9a1999-03-18 16:18:27 +0000110\textwidth \paperwidth
111\advance\textwidth by -2in
Fred Drake6659c301998-03-03 22:02:19 +0000112
113
114% Style parameters and macros used by most documents here
115\raggedbottom
116\sloppy
117\parindent = 0mm
Fred Drake24340ea1998-04-28 18:30:34 +0000118\parskip = 2mm
Fred Drake6659c301998-03-03 22:02:19 +0000119\hbadness = 5000 % don't print trivial gripes
120
121\pagestyle{empty} % start this way; change for
122\pagenumbering{roman} % ToC & chapters
Fred Drake6659c301998-03-03 22:02:19 +0000123
124% Use this to set the font family for headers and other decor:
Fred Drake24340ea1998-04-28 18:30:34 +0000125\newcommand{\py@HeaderFamily}{\sffamily}
Fred Drake6659c301998-03-03 22:02:19 +0000126
127% Redefine the 'normal' header/footer style when using "fancyhdr" package:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000128\@ifundefined{fancyhf}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000129 % Use \pagestyle{normal} as the primary pagestyle for text.
130 \fancypagestyle{normal}{
131 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000132 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
133 \fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
134 \fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
Fred Drake6659c301998-03-03 22:02:19 +0000135 \renewcommand{\headrulewidth}{0pt}
136 \renewcommand{\footrulewidth}{0.4pt}
137 }
138 % Update the plain style so we get the page number & footer line,
139 % but not a chapter or section title. This is to keep the first
140 % page of a chapter and the blank page between chapters `clean.'
141 \fancypagestyle{plain}{
142 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000143 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
Fred Drake6659c301998-03-03 22:02:19 +0000144 \renewcommand{\headrulewidth}{0pt}
145 \renewcommand{\footrulewidth}{0.4pt}
146 }
147 % Redefine \cleardoublepage so that the blank page between chapters
148 % gets the plain style and not the fancy style. This is described
149 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000150 \@ifundefined{chapter}{}{
Fred Drake28f13911998-03-04 21:47:59 +0000151 \renewcommand{\cleardoublepage}{
Fred Drake1c8d0e01998-03-07 05:29:15 +0000152 \clearpage\if@openright \ifodd\c@page\else
Fred Drake28f13911998-03-04 21:47:59 +0000153 \hbox{}
154 \thispagestyle{plain}
155 \newpage
Fred Drake1c8d0e01998-03-07 05:29:15 +0000156 \if@twocolumn\hbox{}\newpage\fi\fi\fi
Fred Drake28f13911998-03-04 21:47:59 +0000157 }
158 }
Fred Drake6659c301998-03-03 22:02:19 +0000159}
160
Fred Drake6659c301998-03-03 22:02:19 +0000161% This sets up the {verbatim} environment to be indented and a minipage,
162% and to have all the other mostly nice properties that we want for
163% code samples.
164
Fred Drake9466b9a1999-03-18 16:18:27 +0000165\let\py@OldVerbatim=\verbatim
166\let\py@OldEndVerbatim=\endverbatim
167\RequirePackage{verbatim}
168
Fred Drake6659c301998-03-03 22:02:19 +0000169% Variable used by begin code command
Fred Drake24340ea1998-04-28 18:30:34 +0000170\newlength{\py@codewidth}
Fred Drake6659c301998-03-03 22:02:19 +0000171
Fred Drake6659c301998-03-03 22:02:19 +0000172\renewcommand{\verbatim}{%
Fred Drake9466b9a1999-03-18 16:18:27 +0000173 \setlength{\parindent}{1cm}%
Fred Drake6659c301998-03-03 22:02:19 +0000174 % Calculate the text width for the minipage:
Fred Drake24340ea1998-04-28 18:30:34 +0000175 \setlength{\py@codewidth}{\linewidth}%
176 \addtolength{\py@codewidth}{-\parindent}%
Fred Drake6659c301998-03-03 22:02:19 +0000177 %
Fred Drake9466b9a1999-03-18 16:18:27 +0000178 \par\indent%
Fred Drake24340ea1998-04-28 18:30:34 +0000179 \begin{minipage}[t]{\py@codewidth}%
Fred Drake6659c301998-03-03 22:02:19 +0000180 \small%
Fred Drake24340ea1998-04-28 18:30:34 +0000181 \py@OldVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000182}
183\renewcommand{\endverbatim}{%
Fred Drake24340ea1998-04-28 18:30:34 +0000184 \py@OldEndVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000185 \end{minipage}%
Fred Drake6659c301998-03-03 22:02:19 +0000186}
187
Fred Drake6cb71491998-03-27 05:22:53 +0000188
Fred Drakea488f301998-07-23 17:50:45 +0000189\newcommand{\py@modulebadkey}{{--just-some-junk--}}
Fred Drake6659c301998-03-03 22:02:19 +0000190
Fred Drake6659c301998-03-03 22:02:19 +0000191
192%% Lots of index-entry generation support.
193
194% Command to wrap around stuff that refers to function / module /
195% attribute names in the index. Default behavior: like \code{}. To
196% just keep the index entries in the roman font, uncomment the second
Fred Drakea488f301998-07-23 17:50:45 +0000197% definition; it matches O'Reilly style more.
Fred Drake6659c301998-03-03 22:02:19 +0000198%
Fred Drake24340ea1998-04-28 18:30:34 +0000199\newcommand{\py@idxcode}[1]{\texttt{#1}}
200%\renewcommand{\py@idxcode}[1]{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000201
202% Command to generate two index entries (using subentries)
203\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
204
205% And three entries (using only one level of subentries)
206\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
207
208% And four (again, using only one level of subentries)
209\newcommand{\indexiv}[4]{
210\index{#1!#2 #3 #4}
211\index{#2!#3 #4, #1}
212\index{#3!#4, #1 #2}
213\index{#4!#1 #2 #3}
214}
215
216% Command to generate a reference to a function, statement, keyword,
217% operator.
Fred Drake0cabff91998-05-06 19:36:01 +0000218\newcommand{\kwindex}[1]{\indexii{keyword}{#1@{\py@idxcode{#1}}}}
Fred Drake24340ea1998-04-28 18:30:34 +0000219\newcommand{\stindex}[1]{\indexii{statement}{#1@{\py@idxcode{#1}}}}
220\newcommand{\opindex}[1]{\indexii{operator}{#1@{\py@idxcode{#1}}}}
221\newcommand{\exindex}[1]{\indexii{exception}{#1@{\py@idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000222\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakea33c5662000-10-29 05:19:16 +0000223\newcommand{\bifuncindex}[1]{%
224 \index{#1@{\py@idxcode{#1()}} (built-in function)}}
Fred Drake6659c301998-03-03 22:02:19 +0000225
226% Add an index entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000227\newcommand{\py@refmodule}[2]{\index{#1@{\py@idxcode{#1}} (#2module)}}
228\newcommand{\refmodindex}[1]{\py@refmodule{#1}{}}
229\newcommand{\refbimodindex}[1]{\py@refmodule{#1}{built-in }}
230\newcommand{\refexmodindex}[1]{\py@refmodule{#1}{extension }}
231\newcommand{\refstmodindex}[1]{\py@refmodule{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000232
Fred Drakeda943741999-01-13 17:09:06 +0000233% Refer to a module's documentation using a hyperlink of the module's
234% name, at least if we're building PDF:
235\@ifundefined{pdfannotlink}{%
236 \newcommand{\refmodule}[2][\py@modulebadkey]{\module{#2}}
Fred Drakeaa2aea01999-01-27 17:37:36 +0000237}{%
238 \newcommand{\refmodule}[2][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000239 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drakeaa2aea01999-01-27 17:37:36 +0000240 \py@linkToName{label-module-\py@modulekey}{\module{#2}}%
Fred Drakeda943741999-01-13 17:09:06 +0000241 }
242}
243
Fred Drake6659c301998-03-03 22:02:19 +0000244% support for the module index
Fred Drake24340ea1998-04-28 18:30:34 +0000245\newif\ifpy@UseModuleIndex
246\py@UseModuleIndexfalse
Fred Drakeb390daf1998-03-09 16:35:36 +0000247
Fred Drakeb390daf1998-03-09 16:35:36 +0000248\newcommand{\makemodindex}{
249 \newwrite\modindexfile
250 \openout\modindexfile=mod\jobname.idx
Fred Drake24340ea1998-04-28 18:30:34 +0000251 \py@UseModuleIndextrue
Fred Drakeb390daf1998-03-09 16:35:36 +0000252}
253
Fred Drake0ee9f721998-03-12 06:41:40 +0000254% Add the defining entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000255\newcommand{\py@modindex}[2]{%
Fred Drakea488f301998-07-23 17:50:45 +0000256 \renewcommand{\py@thismodule}{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000257 \setindexsubitem{(in module #1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000258 \index{#1@{\py@idxcode{#1}} (#2module)|textbf}%
259 \ifpy@UseModuleIndex%
Fred Drake0c275fa1999-03-02 16:17:44 +0000260 \@ifundefined{py@modplat@\py@thismodulekey}{
261 \write\modindexfile{\protect\indexentry{#1@{\texttt{#1}}}{\thepage}}%
262 }{\write\modindexfile{\protect\indexentry{#1@{\texttt{#1} %
Fred Drake9466b9a1999-03-18 16:18:27 +0000263 \emph{(\py@platformof[\py@thismodulekey]{})}}}{\thepage}}%
Fred Drake0c275fa1999-03-02 16:17:44 +0000264 }
Fred Drake0ee9f721998-03-12 06:41:40 +0000265 \fi%
266}
267
Fred Drake9466b9a1999-03-18 16:18:27 +0000268% *** XXX *** THE NEXT FOUR MACROS ARE NOW OBSOLETE !!! ***
269
Fred Drake6659c301998-03-03 22:02:19 +0000270% built-in & Python modules in the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000271\newcommand{\bimodindex}[1]{\py@modindex{#1}{built-in }%
272 \typeout{*** MACRO bimodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
273\newcommand{\stmodindex}[1]{\py@modindex{#1}{standard }%
274 \typeout{*** MACRO stmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000275
276% Python & extension modules outside the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000277\newcommand{\modindex}[1]{\py@modindex{#1}{}%
278 \typeout{*** MACRO modindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
279\newcommand{\exmodindex}[1]{\py@modindex{#1}{extension }%
280 \typeout{*** MACRO exmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000281
282% Additional string for an index entry
Fred Drakeba828782000-04-03 04:19:14 +0000283\newif\ifpy@usingsubitem\py@usingsubitemfalse
284\newcommand{\py@indexsubitem}{}
285\newcommand{\setindexsubitem}[1]{\renewcommand{\py@indexsubitem}{ #1}%
286 \py@usingsubitemtrue}
287\newcommand{\ttindex}[1]{%
288 \ifpy@usingsubitem
289 \index{#1@{\py@idxcode{#1}}\py@indexsubitem}%
290 \else%
291 \index{#1@{\py@idxcode{#1}}}%
292 \fi%
293}
Fred Drake0ee9f721998-03-12 06:41:40 +0000294\newcommand{\withsubitem}[2]{%
295 \begingroup%
Fred Drakeec77e652000-10-30 06:22:22 +0000296 \def\ttindex##1{\index{##1@{\py@idxcode{##1}} #1}}%
297 #2%
Fred Drake0ee9f721998-03-12 06:41:40 +0000298 \endgroup%
299}
Fred Drake6659c301998-03-03 22:02:19 +0000300
Fred Drake53714971998-04-02 22:33:16 +0000301
Fred Drakea488f301998-07-23 17:50:45 +0000302% Module synopsis processing -----------------------------------------------
303%
Fred Drake0c275fa1999-03-02 16:17:44 +0000304\newcommand{\py@thisclass}{}
305\newcommand{\py@thismodule}{}
306\newcommand{\py@thismodulekey}{}
307\newcommand{\py@thismoduletype}{}
308
Fred Drake9466b9a1999-03-18 16:18:27 +0000309\newcommand{\py@standardIndexModule}[1]{\py@modindex{#1}{standard }}
310\newcommand{\py@builtinIndexModule}[1]{\py@modindex{#1}{built-in }}
311\newcommand{\py@extensionIndexModule}[1]{\py@modindex{#1}{extension }}
312\newcommand{\py@IndexModule}[1]{\py@modindex{#1}{}}
Fred Drakea488f301998-07-23 17:50:45 +0000313
Fred Drake0c275fa1999-03-02 16:17:44 +0000314\newif\ifpy@HaveModSynopsis \py@HaveModSynopsisfalse
315\newif\ifpy@ModSynopsisFileIsOpen \py@ModSynopsisFileIsOpenfalse
316\newif\ifpy@HaveModPlatform \py@HaveModPlatformfalse
Fred Drakea488f301998-07-23 17:50:45 +0000317
318% \declaremodule[key]{type}{name}
319\newcommand{\declaremodule}[3][\py@modulebadkey]{
320 \py@openModSynopsisFile
321 \renewcommand{\py@thismoduletype}{#2}
Fred Drakea488f301998-07-23 17:50:45 +0000322 \ifx\py@modulebadkey#1
323 \renewcommand{\py@thismodulekey}{#3}
324 \else
325 \renewcommand{\py@thismodulekey}{#1}
326 \fi
Fred Drake5bc8d991999-05-17 14:47:10 +0000327 \@ifundefined{py@#2IndexModule}{%
328 \typeout{*** MACRO declaremodule called with unknown module type: `#2'}
Fred Drake66823021999-05-17 14:57:26 +0000329 \py@IndexModule{#3}%
Fred Drake5bc8d991999-05-17 14:47:10 +0000330 }{%
331 \csname py@#2IndexModule\endcsname{#3}%
332 }
Fred Drakea488f301998-07-23 17:50:45 +0000333 \label{module-\py@thismodulekey}
Fred Drakea488f301998-07-23 17:50:45 +0000334}
Fred Drake0c275fa1999-03-02 16:17:44 +0000335\newif\ifpy@ModPlatformFileIsOpen \py@ModPlatformFileIsOpenfalse
336\newcommand{\py@ModPlatformFilename}{\jobname.pla}
337\newcommand{\platform}[1]{
338 \ifpy@ModPlatformFileIsOpen\else
339 \newwrite\py@ModPlatformFile
340 \openout\py@ModPlatformFile=\py@ModPlatformFilename
341 \py@ModPlatformFileIsOpentrue
342 \fi
Fred Drake0c275fa1999-03-02 16:17:44 +0000343}
344\InputIfFileExists{\jobname.pla}{}{}
Fred Drake9466b9a1999-03-18 16:18:27 +0000345\newcommand{\py@platformof}[2][\py@modulebadkey]{%
Fred Drake0c275fa1999-03-02 16:17:44 +0000346 \ifx\py@modulebadkey#1 \def\py@key{#2}%
347 \else \def\py@key{#1}%
348 \fi%
349 \csname py@modplat@\py@key\endcsname%
350}
351\newcommand{\ignorePlatformAnnotation}[1]{}
Fred Drakea488f301998-07-23 17:50:45 +0000352
Fred Drakeb75c6151998-08-10 18:41:43 +0000353% \moduleauthor{name}{email}
354\newcommand{\moduleauthor}[2]{}
355
356% \sectionauthor{name}{email}
357\newcommand{\sectionauthor}[2]{}
358
Fred Drakea488f301998-07-23 17:50:45 +0000359
360\newcommand{\py@defsynopsis}{Module has no synopsis.}
361\newcommand{\py@modulesynopsis}{\py@defsynopsis}
362\newcommand{\modulesynopsis}[1]{
Fred Drake0c275fa1999-03-02 16:17:44 +0000363 \py@HaveModSynopsistrue
Fred Drakea488f301998-07-23 17:50:45 +0000364 \renewcommand{\py@modulesynopsis}{#1}
365}
366
367% define the file
368\newwrite\py@ModSynopsisFile
369
370% hacked from \addtocontents from latex.ltx:
371\long\def\py@writeModSynopsisFile#1{%
372 \protected@write\py@ModSynopsisFile%
373 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
374 {\string#1}%
375}
376\newcommand{\py@closeModSynopsisFile}{
377 \ifpy@ModSynopsisFileIsOpen
378 \closeout\py@ModSynopsisFile
379 \py@ModSynopsisFileIsOpenfalse
380 \fi
381}
382\newcommand{\py@openModSynopsisFile}{
383 \ifpy@ModSynopsisFileIsOpen\else
384 \openout\py@ModSynopsisFile=\py@ModSynopsisFilename
385 \py@ModSynopsisFileIsOpentrue
386 \fi
387}
388
389\newcommand{\py@ProcessModSynopsis}{
390 \ifpy@HaveModSynopsis
391 \py@writeModSynopsisFile{\modulesynopsis%
392 {\py@thismodulekey}{\py@thismodule}%
393 {\py@thismoduletype}{\py@modulesynopsis}}%
394 \py@HaveModSynopsisfalse
395 \fi
396 \renewcommand{\py@modulesynopsis}{\py@defsynopsis}
397}
398\AtEndDocument{\py@ProcessModSynopsis\py@closeModSynopsisFile}
399
Fred Drake0c275fa1999-03-02 16:17:44 +0000400
401\long\def\py@writeModPlatformFile#1{%
402 \protected@write\py@ModPlatformFile%
403 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
404 {\string#1}%
405}
406
407
Fred Drakea488f301998-07-23 17:50:45 +0000408\newcommand{\localmoduletable}{
409 \IfFileExists{\py@ModSynopsisFilename}{
410 \begin{synopsistable}
411 \input{\py@ModSynopsisFilename}
412 \end{synopsistable}
413 }{}
414}
415
416\@ifundefined{pdfoutput}{
417 \newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
418}{
Fred Drakeaa2aea01999-01-27 17:37:36 +0000419 \newcommand{\py@ModSynopsisSummary}[4]{%
420 \py@linkToName{label-module-#1}{\bfcode{#2}} & #4\\
421 }
Fred Drakea488f301998-07-23 17:50:45 +0000422}
423\newenvironment{synopsistable}{
424 % key, name, type, synopsis
425 \let\modulesynopsis=\py@ModSynopsisSummary
426 \begin{tabular}{ll}
427}{
428 \end{tabular}
429}
430%
431% --------------------------------------------------------------------------
432
433
Fred Drakea488f301998-07-23 17:50:45 +0000434\newcommand{\py@reset}{
Fred Drakeba828782000-04-03 04:19:14 +0000435 \py@usingsubitemfalse
Fred Drakea488f301998-07-23 17:50:45 +0000436 \py@ProcessModSynopsis
437 \renewcommand{\py@thisclass}{}
438 \renewcommand{\py@thismodule}{}
439 \renewcommand{\py@thismodulekey}{}
440 \renewcommand{\py@thismoduletype}{}
441}
442
443% Augment the sectioning commands used to get our own font family in place,
444% and reset some internal data items:
445\renewcommand{\section}{\py@reset%
446 \@startsection{section}{1}{\z@}%
447 {-3.5ex \@plus -1ex \@minus -.2ex}%
448 {2.3ex \@plus.2ex}%
449 {\reset@font\Large\py@HeaderFamily}}
450\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
451 {-3.25ex\@plus -1ex \@minus -.2ex}%
452 {1.5ex \@plus .2ex}%
453 {\reset@font\large\py@HeaderFamily}}
454\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
455 {-3.25ex\@plus -1ex \@minus -.2ex}%
456 {1.5ex \@plus .2ex}%
457 {\reset@font\normalsize\py@HeaderFamily}}
458\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
459 {3.25ex \@plus1ex \@minus.2ex}%
460 {-1em}%
461 {\reset@font\normalsize\py@HeaderFamily}}
462\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
463 {3.25ex \@plus1ex \@minus .2ex}%
464 {-1em}%
465 {\reset@font\normalsize\py@HeaderFamily}}
466
467
Fred Drake5420f331998-07-23 21:41:02 +0000468% This gets the underscores closer to the right width; the only change
469% from standard LaTeX is the width specified.
470
471\DeclareTextCommandDefault{\textunderscore}{%
472 \leavevmode \kern.06em\vbox{\hrule\@width.55em}}
473
Fred Drakea488f301998-07-23 17:50:45 +0000474% Underscore hack (only act like subscript operator if in math mode)
475%
476% The following is due to Mark Wooding (the old version didn't work with
477% Latex 2e.
478
479\DeclareRobustCommand\hackscore{%
480 \ifmmode_\else\textunderscore\fi%
481}
482\begingroup
483\catcode`\_\active
484\def\next{%
485 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
486}
487\expandafter\endgroup\next
488
489
Fred Drake53714971998-04-02 22:33:16 +0000490% Now for a lot of semantically-loaded environments that do a ton of magical
491% things to get the right formatting and index entries for the stuff in
492% Python modules and C API.
493
494
Fred Drake6659c301998-03-03 22:02:19 +0000495% {fulllineitems} is used in one place in libregex.tex, but is really for
496% internal use in this file.
497%
Fred Drakef9acc591998-09-09 15:27:43 +0000498\newcommand{\py@itemnewline}[1]{%
499 \@tempdima\linewidth%
500 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
501}
502
Fred Drake6659c301998-03-03 22:02:19 +0000503\newenvironment{fulllineitems}{
504 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
505 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
506 \itemsep -\parsep
Fred Drakef9acc591998-09-09 15:27:43 +0000507 \let\makelabel=\py@itemnewline}
Fred Drake6659c301998-03-03 22:02:19 +0000508}{\end{list}}
509
Fred Drake6cb71491998-03-27 05:22:53 +0000510% \optional is mostly for use in the arguments parameters to the various
511% {*desc} environments defined below, but may be used elsewhere. Known to
512% be used in the debugger chapter.
Fred Drake24340ea1998-04-28 18:30:34 +0000513%
514% Typical usage:
515%
516% \begin{funcdesc}{myfunc}{reqparm\optional{, optparm}}
517% ^^^ ^^^
518% No space here No space here
519%
520% When a function has multiple optional parameters, \optional should be
521% nested, not chained. This is right:
522%
523% \begin{funcdesc}{myfunc}{\optional{parm1\optional{, parm2}}}
524%
Fred Drakeba828782000-04-03 04:19:14 +0000525\let\py@badkey=\@undefined
526
Fred Drake6659c301998-03-03 22:02:19 +0000527\newcommand{\optional}[1]{%
528 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
529
Fred Drakeba828782000-04-03 04:19:14 +0000530% This can be used when a function or method accepts an varying number
531% of arguments, such as by using the *args syntax in the parameter list.
532\newcommand{\py@moreargs}{...}
533
534% This can be used when you don't want to document the parameters to a
535% function or method, but simply state that it's an alias for
536% something else.
537\newcommand{\py@unspecified}{...}
538
Fred Drake6cb71491998-03-27 05:22:53 +0000539% C functions ------------------------------------------------------------
Fred Drakeba828782000-04-03 04:19:14 +0000540% \begin{cfuncdesc}[refcount]{type}{name}{arglist}
541% Note that the [refcount] slot should only be filled in by
542% tools/anno-api.py; it pulls the value from the refcounts database.
543\newenvironment{cfuncdesc}[4][\py@badkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000544 \begin{fulllineitems}
Fred Drakeba828782000-04-03 04:19:14 +0000545 \item[\code{#2 \bfcode{#3}(\py@varvars{#4})}\index{#3@{\py@idxcode{#3()}}}]
546 \ifx#1\@undefined\else%
Fred Drake0a863da2000-04-10 18:21:38 +0000547 \emph{Return value: \textbf{#1}.}\\
Fred Drakeba828782000-04-03 04:19:14 +0000548 \fi
Fred Drake6cb71491998-03-27 05:22:53 +0000549}{\end{fulllineitems}}
550
551% C variables ------------------------------------------------------------
552% \begin{cvardesc}{type}{name}
553\newenvironment{cvardesc}[2]{
554 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000555 \item[\code{#1 \bfcode{#2}}\index{#2@{\py@idxcode{#2}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000556}{\end{fulllineitems}}
557
558% C data types -----------------------------------------------------------
Fred Drakeba828782000-04-03 04:19:14 +0000559% \begin{ctypedesc}[index name]{typedef name}
560\newenvironment{ctypedesc}[2][\py@badkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000561 \begin{fulllineitems}
Fred Drakeba828782000-04-03 04:19:14 +0000562 \item[\bfcode{#2}%
563 \ifx#1\@undefined%
Fred Drakea33c5662000-10-29 05:19:16 +0000564 \index{#2@{\py@idxcode{#2}} (C type)}
Fred Drakeba828782000-04-03 04:19:14 +0000565 \else%
Fred Drakea33c5662000-10-29 05:19:16 +0000566 \index{#2@{\py@idxcode{#1}} (C type)}
Fred Drakeba828782000-04-03 04:19:14 +0000567 \fi]
568}{\end{fulllineitems}}
569
570% Funky macros -----------------------------------------------------------
571% \begin{csimplemacro}{name}
572% -- "simple" because it has no args; NOT for constant definitions!
573\newenvironment{csimplemacrodesc}[1]{
574 \begin{fulllineitems}
Fred Drakea33c5662000-10-29 05:19:16 +0000575 \item[\bfcode{#1}\index{#1@{\py@idxcode{#1}} (macro)}]
Fred Drake6cb71491998-03-27 05:22:53 +0000576}{\end{fulllineitems}}
577
578% simple functions (not methods) -----------------------------------------
579% \begin{funcdesc}{name}{args}
Fred Drakeec77e652000-10-30 06:22:22 +0000580\newcommand{\funcline}[2]{%
581 \funclineni{#1}{#2}%
582 \index{#1@{\py@idxcode{#1()}} (in module \py@thismodule)}}
Fred Drake6cb71491998-03-27 05:22:53 +0000583\newenvironment{funcdesc}[2]{
584 \begin{fulllineitems}
585 \funcline{#1}{#2}
586}{\end{fulllineitems}}
587
Fred Drake6659c301998-03-03 22:02:19 +0000588% similar to {funcdesc}, but doesn't add to the index
Fred Drake300775d1998-04-17 02:17:00 +0000589\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\py@varvars{#2})}]}
Fred Drake6cb71491998-03-27 05:22:53 +0000590\newenvironment{funcdescni}[2]{
591 \begin{fulllineitems}
592 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000593}{\end{fulllineitems}}
594
Fred Drake6cb71491998-03-27 05:22:53 +0000595% classes ----------------------------------------------------------------
596% \begin{classdesc}{name}{constructor args}
597\newenvironment{classdesc}[2]{
Fred Drake1cbd1961998-11-25 17:13:28 +0000598 % Using \renewcommand doesn't work for this, for unknown reasons:
599 \global\def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000600 \begin{fulllineitems}
Fred Drake300775d1998-04-17 02:17:00 +0000601 \item[\code{\bfcode{#1}(\py@varvars{#2})}%
Fred Drakea33c5662000-10-29 05:19:16 +0000602 \index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}]
Fred Drake6659c301998-03-03 22:02:19 +0000603}{\end{fulllineitems}}
604
Fred Drake4e607962000-09-09 06:01:25 +0000605% \begin{excclassdesc}{name}{constructor args}
606% but indexes as an exception
607\newenvironment{excclassdesc}[2]{
608 % Using \renewcommand doesn't work for this, for unknown reasons:
609 \global\def\py@thisclass{#1}
610 \begin{fulllineitems}
611 \item[\code{\bfcode{#1}(\py@varvars{#2})}%
Fred Drakea33c5662000-10-29 05:19:16 +0000612 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}]
Fred Drake4e607962000-09-09 06:01:25 +0000613}{\end{fulllineitems}}
614
Fred Drake6cb71491998-03-27 05:22:53 +0000615
Fred Drake24340ea1998-04-28 18:30:34 +0000616\let\py@classbadkey=\@undefined
Fred Drake6cb71491998-03-27 05:22:53 +0000617
618% object method ----------------------------------------------------------
619% \begin{methoddesc}[classname]{methodname}{args}
Fred Drakea33c5662000-10-29 05:19:16 +0000620\newcommand{\methodline}[3][\@undefined]{
Fred Drake6cb71491998-03-27 05:22:53 +0000621 \methodlineni{#2}{#3}
622 \ifx#1\@undefined
Fred Drakea33c5662000-10-29 05:19:16 +0000623 \index{#2@{\py@idxcode{#2()}} (\py@thisclass\ method)}
Fred Drake6cb71491998-03-27 05:22:53 +0000624 \else
Fred Drakea33c5662000-10-29 05:19:16 +0000625 \index{#2@{\py@idxcode{#2()}} (#1 method)}
Fred Drake6cb71491998-03-27 05:22:53 +0000626 \fi
627}
Fred Drakea33c5662000-10-29 05:19:16 +0000628\newenvironment{methoddesc}[3][\@undefined]{
Fred Drake6cb71491998-03-27 05:22:53 +0000629 \begin{fulllineitems}
630 \ifx#1\@undefined
631 \methodline{#2}{#3}
632 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000633 \def\py@thisclass{#1}
Fred Drakea33c5662000-10-29 05:19:16 +0000634 \methodline{#2}{#3}
Fred Drake6cb71491998-03-27 05:22:53 +0000635 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000636}{\end{fulllineitems}}
637
Fred Drake6cb71491998-03-27 05:22:53 +0000638% similar to {methoddesc}, but doesn't add to the index
639% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000640\newcommand{\methodlineni}[3][\py@classbadkey]{%
Fred Drake300775d1998-04-17 02:17:00 +0000641 \item[\code{\bfcode{#2}(\py@varvars{#3})}]}
Fred Drake24340ea1998-04-28 18:30:34 +0000642\newenvironment{methoddescni}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000643 \begin{fulllineitems}
644 \methodlineni{#2}{#3}
645}{\end{fulllineitems}}
646
647% object data attribute --------------------------------------------------
648% \begin{memberdesc}[classname]{membername}
Fred Drake24340ea1998-04-28 18:30:34 +0000649\newcommand{\memberline}[2][\py@classbadkey]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000650 \ifx#1\@undefined
651 \memberlineni{#2}
Fred Drakea33c5662000-10-29 05:19:16 +0000652 \index{#2@{\py@idxcode{#2}} (\py@thisclass\ attribute)}
Fred Drake6cb71491998-03-27 05:22:53 +0000653 \else
654 \memberlineni{#2}
Fred Drakea33c5662000-10-29 05:19:16 +0000655 \index{#2@{\py@idxcode{#2}} (#1 attribute)}
Fred Drake6cb71491998-03-27 05:22:53 +0000656 \fi
657}
Fred Drake24340ea1998-04-28 18:30:34 +0000658\newenvironment{memberdesc}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000659 \begin{fulllineitems}
660 \ifx#1\@undefined
661 \memberline{#2}
662 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000663 \def\py@thisclass{#1}
Fred Drakea33c5662000-10-29 05:19:16 +0000664 \memberline{#2}
Fred Drake6cb71491998-03-27 05:22:53 +0000665 \fi
666}{\end{fulllineitems}}
667
668% similar to {memberdesc}, but doesn't add to the index
669% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000670\newcommand{\memberlineni}[2][\py@classbadkey]{\item[\bfcode{#2}]}
671\newenvironment{memberdescni}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000672 \begin{fulllineitems}
673 \memberlineni{#2}
674}{\end{fulllineitems}}
675
676% For exceptions: --------------------------------------------------------
677% \begin{excdesc}{name}
Fred Drakea33c5662000-10-29 05:19:16 +0000678% -- for constructor information, use excclassdesc instead
Fred Drake6cb71491998-03-27 05:22:53 +0000679\newenvironment{excdesc}[1]{
680 \begin{fulllineitems}
Fred Drakea33c5662000-10-29 05:19:16 +0000681 \item[\bfcode{#1}%
682 \index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}]
Fred Drake6cb71491998-03-27 05:22:53 +0000683}{\end{fulllineitems}}
684
685% Module data or constants: ----------------------------------------------
686% \begin{datadesc}{name}
Fred Drakea33c5662000-10-29 05:19:16 +0000687\newcommand{\dataline}[1]{%
688 \datalineni{#1}\index{#1@{\py@idxcode{#1}} (data in \py@thismodule)}}
Fred Drake6cb71491998-03-27 05:22:53 +0000689\newenvironment{datadesc}[1]{
690 \begin{fulllineitems}
691 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000692}{\end{fulllineitems}}
693
694% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000695\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
696\newenvironment{datadescni}[1]{
697 \begin{fulllineitems}
698 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000699}{\end{fulllineitems}}
700
Fred Drake6cb71491998-03-27 05:22:53 +0000701% bytecode instruction ---------------------------------------------------
702% \begin{opcodedesc}{name}{var}
703% -- {var} may be {}
704\newenvironment{opcodedesc}[2]{
705 \begin{fulllineitems}
706 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000707}{\end{fulllineitems}}
708
709
Fred Drake24340ea1998-04-28 18:30:34 +0000710\newcommand{\nodename}[1]{\label{#1}}
Fred Drake55730311998-03-25 15:41:23 +0000711
Fred Drake6659c301998-03-03 22:02:19 +0000712% For these commands, use \command{} to get the typography right, not
713% {\command}. This works better with the texinfo translation.
714\newcommand{\ABC}{{\sc abc}}
715\newcommand{\UNIX}{{\sc Unix}}
716\newcommand{\POSIX}{POSIX}
717\newcommand{\ASCII}{{\sc ascii}}
718\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
719\newcommand{\C}{C}
720\newcommand{\EOF}{{\sc eof}}
Fred Drake24340ea1998-04-28 18:30:34 +0000721\newcommand{\NULL}{\constant{NULL}}
Fred Drake6659c301998-03-03 22:02:19 +0000722
Fred Drake53714971998-04-02 22:33:16 +0000723% Also for consistency: spell Python "Python", not "python"!
724
Fred Drake6659c301998-03-03 22:02:19 +0000725% code is the most difficult one...
Fred Drake46346ec2000-06-30 17:57:05 +0000726\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 +0000727\texttt{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000728
729\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Fred Drake8e54abe1998-07-01 14:49:25 +0000730\newcommand{\kbd}[1]{\code{#1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000731\newcommand{\samp}[1]{`\code{#1}'}
Fred Drake6659c301998-03-03 22:02:19 +0000732% This weird definition of \var{} allows it to always appear in roman
733% italics, and won't get funky in code fragments when we play around
Fred Drakefa1cceb1998-11-30 14:42:59 +0000734% with fonts. This also works directly in math mode.
735\newcommand{\var}[1]{%
736 \ifmmode%
737 \hbox{\normalsize\textrm{\textit{#1\/}}}%
738 \else%
739 \normalsize\textrm{\textit{#1\/}}%
740 \fi%
741}
Fred Drake24340ea1998-04-28 18:30:34 +0000742\renewcommand{\emph}[1]{{\em #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000743\newcommand{\dfn}[1]{\emph{#1}}
744\newcommand{\strong}[1]{{\bf #1}}
745% let's experiment with a new font:
Fred Drake0ee9f721998-03-12 06:41:40 +0000746\newcommand{\file}[1]{`{\small\textsf{#1}}'}
Fred Drake0a0fd591999-04-28 14:59:44 +0000747\newcommand{\filenq}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000748
749% Use this def/redef approach for \url{} since hyperref defined this already,
750% but only if we actually used hyperref:
Fred Drake6cb71491998-03-27 05:22:53 +0000751\@ifundefined{pdfannotlink}{
Fred Drakea2c2a831998-04-15 17:50:01 +0000752 \newcommand{\py@url}[1]{\mbox{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000753}{
Fred Drakea2c2a831998-04-15 17:50:01 +0000754 \newcommand{\py@url}[1]{{%
Fred Drake6659c301998-03-03 22:02:19 +0000755 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000756 \py@LinkColor% color of the link text
757 \mbox{\small\textsf{#1}}%
758 \py@NormalColor% Turn it back off; these are declarative
Fred Drake6659c301998-03-03 22:02:19 +0000759 \pdfendlink}% and don't appear bound to the current
760 }% formatting "box".
761}
Fred Drakea2c2a831998-04-15 17:50:01 +0000762\let\url=\py@url
Fred Drake0ee9f721998-03-12 06:41:40 +0000763\newcommand{\email}[1]{{\small\textsf{#1}}}
Fred Drake454a4fb1998-04-01 22:20:14 +0000764\newcommand{\newsgroup}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000765
Fred Drakecc2b81e2000-08-03 17:38:30 +0000766\newcommand{\py@varvars}[1]{{%
Fred Drakeba828782000-04-03 04:19:14 +0000767 {\let\unspecified=\py@unspecified%
768 \let\moreargs=\py@moreargs%
Fred Drakecc2b81e2000-08-03 17:38:30 +0000769 \var{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000770
Fred Drake24340ea1998-04-28 18:30:34 +0000771% I'd really like to get rid of this!
Fred Drake6659c301998-03-03 22:02:19 +0000772\newif\iftexi\texifalse
Fred Drake6659c301998-03-03 22:02:19 +0000773
Fred Drake1e4973b1998-07-28 21:52:17 +0000774% This is used to get l2h to put the copyright and abstract on
775% a separate HTML page.
776\newif\ifhtml\htmlfalse
777
778
Fred Drake6659c301998-03-03 22:02:19 +0000779% These should be used for all references to identifiers which are
780% used to refer to instances of specific language constructs. See the
781% names for specific semantic assignments.
782%
783% For now, don't do anything really fancy with them; just use them as
784% logical markup. This might change in the future.
785%
Fred Drake24340ea1998-04-28 18:30:34 +0000786\newcommand{\module}[1]{\texttt{#1}}
787\newcommand{\keyword}[1]{\texttt{#1}}
788\newcommand{\exception}[1]{\texttt{#1}}
789\newcommand{\class}[1]{\texttt{#1}}
790\newcommand{\function}[1]{\texttt{#1}}
791\newcommand{\member}[1]{\texttt{#1}}
792\newcommand{\method}[1]{\texttt{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000793
Fred Drake53714971998-04-02 22:33:16 +0000794\newcommand{\pytype}[1]{#1} % built-in Python type
795
Fred Drake24340ea1998-04-28 18:30:34 +0000796\newcommand{\cfunction}[1]{\texttt{#1}}
797\newcommand{\ctype}[1]{\texttt{#1}} % C struct or typedef name
798\newcommand{\cdata}[1]{\texttt{#1}} % C variable, typically global
Fred Drake6659c301998-03-03 22:02:19 +0000799
Fred Drake0ee9f721998-03-12 06:41:40 +0000800\newcommand{\mimetype}[1]{{\small\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000801% The \! is a "negative thin space" in math mode.
802\newcommand{\regexp}[1]{%
803 {\tiny$^{^\lceil}\!\!$%
804 {\normalsize\code{#1}}%
Fred Drake47cfd031998-04-03 21:22:31 +0000805 $\!\rfloor\!$%
Fred Drake94fac131998-03-12 19:37:03 +0000806 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000807\newcommand{\envvar}[1]{%
Fred Drake94fac131998-03-12 19:37:03 +0000808 \$#1% $ <-- bow to font-lock 3 times!
809 \index{#1@{\$#1}}% $
810 \index{environment variables!{\$#1}}% $
Fred Drake0ee9f721998-03-12 06:41:40 +0000811}
Fred Drake24340ea1998-04-28 18:30:34 +0000812\newcommand{\makevar}[1]{#1} % variable in a Makefile
813\newcommand{\character}[1]{\samp{#1}}
Fred Drake0ee9f721998-03-12 06:41:40 +0000814
Fred Drake6659c301998-03-03 22:02:19 +0000815% constants defined in Python modules or C headers, not language constants:
Fred Drake24340ea1998-04-28 18:30:34 +0000816\newcommand{\constant}[1]{\code{#1}} % manifest constant, not syntactic
Fred Drake6659c301998-03-03 22:02:19 +0000817
818\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake4e607962000-09-09 06:01:25 +0000819\newcommand{\pep}[1]{PEP #1\index{Python Enhancement Proposals!PEP #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000820\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
821\newcommand{\program}[1]{\strong{#1}}
Fred Drake7b8195a1999-11-09 17:02:11 +0000822\newcommand{\programopt}[1]{\strong{#1}}
Fred Drake49362492000-04-11 18:47:59 +0000823% Note that \longprogramopt provides the '--'!
824\newcommand{\longprogramopt}[1]{\strong{-{}-#1}}
Fred Drake7b8195a1999-11-09 17:02:11 +0000825
826% cited titles: \citetitle{Title of Work}
827% online: \citetitle[url-to-resource]{Title of Work}
Fred Drakede9fec52000-08-17 04:25:59 +0000828\newcommand{\citetitle}[2][URL]{\emph{#2}}
Fred Drake6659c301998-03-03 22:02:19 +0000829
830
831% Deprecation stuff.
832% Should be extended to allow an index / list of deprecated stuff. But
833% there's a lot of stuff that needs to be done to make that automatable.
834%
835% First parameter is the release number that deprecates the feature, the
836% second is the action the should be taken by users of the feature.
837%
838% Example:
Fred Drake24340ea1998-04-28 18:30:34 +0000839% \deprecated{1.5.1}{Use \method{frobnicate()} instead.}
Fred Drake6659c301998-03-03 22:02:19 +0000840%
841\newcommand{\deprecated}[2]{%
842 \strong{Deprecated since release #1.} #2\par}
843
Fred Drakeaf958c71998-07-27 20:32:33 +0000844% New stuff.
845% This should be used to mark things which have been added to the
846% development tree but that aren't in the release, but are documented.
847% This allows release of documentation that already includes updated
Fred Drake2116d981999-02-02 18:02:48 +0000848% descriptions. Place at end of descriptor environment.
Fred Drakeaf958c71998-07-27 20:32:33 +0000849%
850% Example:
851% \versionadded{1.5.2}
Fred Drake46346ec2000-06-30 17:57:05 +0000852% \versionchanged[short explanation]{2.0}
Fred Drakeaf958c71998-07-27 20:32:33 +0000853%
854\newcommand{\versionadded}[1]{%
Fred Drake2116d981999-02-02 18:02:48 +0000855 { New in version #1. }}
Fred Drakea6e83392000-05-02 17:28:36 +0000856\newcommand{\versionchanged}[2][\py@badkey]{%
857 \ifx#1\@undefined%
858 { Changed in version #2. }%
859 \else%
860 { Changed in version #2:\ #1. }%
861 \fi%
862}
Fred Drake6659c301998-03-03 22:02:19 +0000863
Fred Drakeaf958c71998-07-27 20:32:33 +0000864
865% Tables.
866%
Fred Drake6659c301998-03-03 22:02:19 +0000867\newenvironment{tableii}[4]{%
868 \begin{center}%
869 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakef61eac42000-10-24 02:18:30 +0000870 \begin{tabular}{#1}\strong{#3}&\strong{#4} \\* \hline%
Fred Drake6659c301998-03-03 22:02:19 +0000871}{%
Fred Drake6659c301998-03-03 22:02:19 +0000872 \end{tabular}%
873 \end{center}%
874}
875
Fred Drakeda72b932000-09-21 15:58:02 +0000876\newenvironment{longtableii}[4]{%
877 \begin{center}%
878 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakef61eac42000-10-24 02:18:30 +0000879 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4} \\* \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +0000880}{%
881 \end{longtable}%
882 \end{center}%
883}
884
Fred Drake6659c301998-03-03 22:02:19 +0000885\newenvironment{tableiii}[5]{%
886 \begin{center}%
887 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
Fred Drakeda72b932000-09-21 15:58:02 +0000888 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
Fred Drakef61eac42000-10-24 02:18:30 +0000889 \hline%
Fred Drake6659c301998-03-03 22:02:19 +0000890}{%
Fred Drake6659c301998-03-03 22:02:19 +0000891 \end{tabular}%
892 \end{center}%
893}
894
Fred Drakeda72b932000-09-21 15:58:02 +0000895\newenvironment{longtableiii}[5]{%
896 \begin{center}%
897 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
898 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
Fred Drakef61eac42000-10-24 02:18:30 +0000899 \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +0000900}{%
901 \end{longtable}%
902 \end{center}%
903}
904
Fred Drake30e52651998-07-24 22:11:29 +0000905\newenvironment{tableiv}[6]{%
906 \begin{center}%
907 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
908 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6} \\%
Fred Drakef61eac42000-10-24 02:18:30 +0000909 \hline%
Fred Drake30e52651998-07-24 22:11:29 +0000910}{%
911 \end{tabular}%
912 \end{center}%
913}
914
Fred Drakeda72b932000-09-21 15:58:02 +0000915\newenvironment{longtableiv}[6]{%
916 \begin{center}%
917 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
918 \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}%
919 \\%
Fred Drakef61eac42000-10-24 02:18:30 +0000920 \hline\endhead%
Fred Drakeda72b932000-09-21 15:58:02 +0000921}{%
922 \end{longtable}%
923 \end{center}%
924}
925
Fred Drake24340ea1998-04-28 18:30:34 +0000926% Cross-referencing (AMK, new impl. FLD)
Fred Drake6659c301998-03-03 22:02:19 +0000927% Sample usage:
928% \begin{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +0000929% \seemodule{rand}{Uniform random number generator.}; % Module xref
930% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +0000931%
932% % A funky case: module name contains '_'; have to supply an optional key
Fred Drake84bd6f31999-05-11 15:42:51 +0000933% \seemodule[copyreg]{copy_reg}{Interface constructor registration for
934% \module{pickle}.}
Fred Drake6659c301998-03-03 22:02:19 +0000935% \end{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +0000936%
937% Note that the last parameter for \seemodule and \seetext should be complete
938% sentences and be terminated with the proper punctuation.
Fred Drake6659c301998-03-03 22:02:19 +0000939
Fred Drake1c8d0e01998-03-07 05:29:15 +0000940\@ifundefined{pdfannotlink}{%
Fred Drake24340ea1998-04-28 18:30:34 +0000941 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000942 \par%
Fred Drake24340ea1998-04-28 18:30:34 +0000943 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drake84bd6f31999-05-11 15:42:51 +0000944 \begin{fulllineitems}
945 \item[Module \module{#2} (section \ref{module-\py@modulekey}):]
946 #3
947 \end{fulllineitems}
Fred Drakeebcb6581998-03-06 21:25:17 +0000948 }
Fred Drake24340ea1998-04-28 18:30:34 +0000949}{\newcommand{\py@seemodule}[3][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000950 \par%
Fred Drake24340ea1998-04-28 18:30:34 +0000951 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drake84bd6f31999-05-11 15:42:51 +0000952 \begin{fulllineitems}
953 \item[\py@linkToName{label-module-\py@modulekey}{Module \module{#2}}
954 (section \ref{module-\py@modulekey}):]
955 #3
956 \end{fulllineitems}
Fred Drakeebcb6581998-03-06 21:25:17 +0000957 }
958}
Fred Drake48449982000-09-12 17:52:33 +0000959% \seetitle[url]{title}{why it's interesting}
960\newcommand{\py@seetitle}[3][\py@modulebadkey]{%
961 \par
962 \begin{fulllineitems}
963 \item[\citetitle{#2}]
964 \ifx\py@modulebadkey#1\else
965 \item[{\small{(\url{#1})}}]
966 \fi
967 #3
968 \end{fulllineitems}
969}
Fred Drake4e607962000-09-09 06:01:25 +0000970% \seepep{number}{title}{why it's interesting}
971\newcommand{\py@seepep}[3]{%
972 \par%
973 \begin{fulllineitems}
974 \item[\pep{#1}, ``\emph{#2}'']
975 #3
976 \end{fulllineitems}
977}
Fred Drake64b72b62000-04-26 18:13:58 +0000978% \seerfc{number}{title}{why it's interesting}
979\newcommand{\py@seerfc}[3]{%
980 \par%
981 \begin{fulllineitems}
982 \item[\rfc{#1}, ``\emph{#2}'']
983 #3
984 \end{fulllineitems}
985}
Fred Drake51313f12000-05-09 16:18:44 +0000986% \seeurl{url}{why it's interesting}
987\newcommand{\py@seeurl}[2]{%
988 \par%
989 \begin{fulllineitems}
990 \item[\url{#1}]
991 #2
992 \end{fulllineitems}
993}
Fred Drake6659c301998-03-03 22:02:19 +0000994\newenvironment{seealso}[0]{
Fred Drake9466b9a1999-03-18 16:18:27 +0000995 \par
Fred Drake6659c301998-03-03 22:02:19 +0000996 \strong{See Also:}\par
Fred Drake6659c301998-03-03 22:02:19 +0000997 \def\seetext##1{\par{##1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000998 \let\seemodule=\py@seemodule
Fred Drake48449982000-09-12 17:52:33 +0000999 \let\seepep=\py@seepep
Fred Drake64b72b62000-04-26 18:13:58 +00001000 \let\seerfc=\py@seerfc
Fred Drake48449982000-09-12 17:52:33 +00001001 \let\seetitle=\py@seetitle
Fred Drake51313f12000-05-09 16:18:44 +00001002 \let\seeurl=\py@seeurl
Fred Drake6659c301998-03-03 22:02:19 +00001003}{\par}
1004
1005
Fred Drakeaf958c71998-07-27 20:32:33 +00001006% Allow the Python release number to be specified independently of the
Fred Drake6659c301998-03-03 22:02:19 +00001007% \date{}. This allows the date to reflect the document's date and
1008% release to specify the Python release that is documented.
1009%
Fred Drake24340ea1998-04-28 18:30:34 +00001010\newcommand{\py@release}{}
Fred Drake6659c301998-03-03 22:02:19 +00001011\newcommand{\version}{}
Fred Drakeaf2b7142000-09-14 20:11:05 +00001012\newcommand{\shortversion}{}
Fred Drake6659c301998-03-03 22:02:19 +00001013\newcommand{\releasename}{Release}
1014\newcommand{\release}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +00001015 \renewcommand{\py@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +00001016 \renewcommand{\version}{#1}}
Fred Drakeaf2b7142000-09-14 20:11:05 +00001017\newcommand{\setshortversion}[1]{%
1018 \renewcommand{\shortversion}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +00001019
1020% Allow specification of the author's address separately from the
1021% author's name. This can be used to format them differently, which
1022% is a good thing.
1023%
Fred Drake24340ea1998-04-28 18:30:34 +00001024\newcommand{\py@authoraddress}{}
1025\newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress}{#1}}
Fred Drake6df93ef1998-05-14 20:56:31 +00001026\let\developersaddress=\authoraddress
1027\let\developer=\author
1028\let\developers=\author
Fred Drake6659c301998-03-03 22:02:19 +00001029
Fred Drake6659c301998-03-03 22:02:19 +00001030% This sets up the fancy chapter headings that make the documents look
1031% at least a little better than the usual LaTeX output.
1032%
Fred Drake1c8d0e01998-03-07 05:29:15 +00001033\@ifundefined{ChTitleVar}{}{
Fred Drake24340ea1998-04-28 18:30:34 +00001034 \ChNameVar{\raggedleft\normalsize\py@HeaderFamily}
1035 \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily}
1036 \ChTitleVar{\raggedleft \rm\Huge\py@HeaderFamily}
Fred Drake6659c301998-03-03 22:02:19 +00001037 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +00001038 \def\@makechapterhead#1{%
1039 {\parindent \z@ \raggedright \normalfont
1040 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +00001041 \DOCH
1042 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +00001043 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +00001044 \DOTI{#1}
1045 }
1046 }
Fred Drake6659c301998-03-03 22:02:19 +00001047}
1048
Fred Drake3bf78651998-05-20 17:42:17 +00001049
1050% Definition lists; requested by AMK for HOWTO documents. Probably useful
1051% elsewhere as well, so keep in in the general style support.
1052%
1053\newenvironment{definitions}{%
1054 \begin{description}%
Fred Drakef9acc591998-09-09 15:27:43 +00001055 \def\term##1{\item[##1]\mbox{}\\*[0mm]}
Fred Drake3bf78651998-05-20 17:42:17 +00001056}{%
1057 \end{description}%
1058}
1059
Fred Drake6659c301998-03-03 22:02:19 +00001060% Tell TeX about pathological hyphenation cases:
1061\hyphenation{Base-HTTP-Re-quest-Hand-ler}