blob: 121d045d9580f845a456082525995ff3a050324c [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 Drake9466b9a1999-03-18 16:18:27 +00009% Uncomment these two lines to ignore the paper size and make the page
10% size more like a typical published manual.
11%\renewcommand{\paperheight}{9in}
12%\renewcommand{\paperwidth}{8.5in} % typical squarish manual
13%\renewcommand{\paperwidth}{7in} % O'Reilly ``Programmming Python''
14
Fred Drake454a4fb1998-04-01 22:20:14 +000015% These packages can be used to add marginal annotations which indicate
16% index entries and labels; useful for reviewing this messy documentation!
17%
18%\RequirePackage{showkeys}
19%\RequirePackage{showidx}
20
Fred Drakec0b2e451998-03-25 14:53:43 +000021% for PDF output, use maximal compression & a lot of other stuff
22% (test for PDF recommended by Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov>)
23%
Fred Drake24340ea1998-04-28 18:30:34 +000024\newif\ifpy@doing@page@targets
25\py@doing@page@targetsfalse
Fred Drake6cb71491998-03-27 05:22:53 +000026
Fred Drakec0b2e451998-03-25 14:53:43 +000027\ifx\pdfoutput\undefined\else\ifcase\pdfoutput
Fred Drakec0b2e451998-03-25 14:53:43 +000028\else
Fred Drake6659c301998-03-03 22:02:19 +000029 \input{pdfcolor}
Fred Drake24340ea1998-04-28 18:30:34 +000030 \let\py@LinkColor=\NavyBlue
31 \let\py@NormalColor=\Black
Fred Drake6659c301998-03-03 22:02:19 +000032 \pdfcompresslevel=9
Fred Drakeba1700c1998-05-11 20:42:54 +000033 \pdfpagewidth=\paperwidth % page width of PDF output
34 \pdfpageheight=\paperheight % page height of PDF output
Fred Drakeebcb6581998-03-06 21:25:17 +000035 %
Fred Drakea2c2a831998-04-15 17:50:01 +000036 % Pad the number with '0' to 3 digits wide so no page name is a prefix
37 % of any other.
38 %
Fred Drakea488f301998-07-23 17:50:45 +000039 \newcommand{\py@targetno}[1]{\ifnum#1<100 0\fi\ifnum#1<10 0\fi#1}
40 \newcommand{\py@pageno}{\py@targetno\thepage}
Fred Drakea2c2a831998-04-15 17:50:01 +000041 %
Fred Drakeebcb6581998-03-06 21:25:17 +000042 % This definition allows the entries in the page-view of the ToC to be
43 % active links. Some work, some don't.
44 %
Fred Drake24340ea1998-04-28 18:30:34 +000045 \let\py@OldContentsline=\contentsline
Fred Drakeaa2aea01999-01-27 17:37:36 +000046 %
47 % Macro that takes two args: the name to link to and the content of
48 % the link. This takes care of the PDF magic, getting the colors
49 % the same for each link, and avoids having lots of garbage all over
50 % this style file.
51 \newcommand{\py@linkToName}[2]{%
52 \pdfannotlink attr{/Border [0 0 0]} goto name{#1}%
53 \py@LinkColor#2\py@NormalColor%
54 \pdfendlink%
55 }
Fred Drakea2c2a831998-04-15 17:50:01 +000056 % Compute the padded page number separately since we end up with a pair of
57 % \relax tokens; this gets the right string computed and works.
Fred Drake6659c301998-03-03 22:02:19 +000058 \renewcommand{\contentsline}[3]{%
Fred Drakea2c2a831998-04-15 17:50:01 +000059 \def\my@pageno{\py@targetno{#3}}%
Fred Drakeaa2aea01999-01-27 17:37:36 +000060 \py@OldContentsline{#1}{\py@linkToName{page\my@pageno}{#2}}{#3}%
Fred Drake6659c301998-03-03 22:02:19 +000061 }
Fred Drakeebcb6581998-03-06 21:25:17 +000062 \AtEndDocument{
Fred Drakec0b2e451998-03-25 14:53:43 +000063 \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
Fred Drakeebcb6581998-03-06 21:25:17 +000064 }
Fred Drakea2c2a831998-04-15 17:50:01 +000065 \newcommand{\py@target}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000066 \ifpy@doing@page@targets%
Fred Drake9b8afde1999-03-24 14:16:17 +000067 {\pdfdest name{#1} xyz}%
Fred Drakea2c2a831998-04-15 17:50:01 +000068 \fi%
69 }
Fred Drake24340ea1998-04-28 18:30:34 +000070 \let\py@OldLabel=\label
Fred Drake6659c301998-03-03 22:02:19 +000071 \renewcommand{\label}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +000072 \py@OldLabel{#1}%
Fred Drakea2c2a831998-04-15 17:50:01 +000073 \py@target{label-#1}%
Fred Drake6659c301998-03-03 22:02:19 +000074 }
Fred Drakeba1700c1998-05-11 20:42:54 +000075 % This stuff adds a page# destination to every PDF page, where # is three
76 % digits wide, padded with leading zeros. This doesn't really help with
77 % the frontmatter, but does fine with the body.
Fred Drake6659c301998-03-03 22:02:19 +000078 %
79 % This is *heavily* based on the hyperref package.
80 %
Fred Drake1c8d0e01998-03-07 05:29:15 +000081 \def\@begindvi{%
82 \unvbox \@begindvibox
83 \@hyperfixhead
Fred Drake6659c301998-03-03 22:02:19 +000084 }
Fred Drake1c8d0e01998-03-07 05:29:15 +000085 \def\@hyperfixhead{%
86 \let\H@old@thehead\@thehead
Fred Drakea2c2a831998-04-15 17:50:01 +000087 \global\def\@foo{\py@target{page\py@pageno}}%
Fred Drake1c8d0e01998-03-07 05:29:15 +000088 \expandafter\ifx\expandafter\@empty\H@old@thehead
89 \def\H@old@thehead{\hfil}\fi
90 \def\@thehead{\@foo\relax\H@old@thehead}%
Fred Drake6659c301998-03-03 22:02:19 +000091 }
Fred Drakec0b2e451998-03-25 14:53:43 +000092\fi\fi
Fred Drake6659c301998-03-03 22:02:19 +000093
94% Increase printable page size (copied from fullpage.sty)
95\topmargin 0pt
96\advance \topmargin by -\headheight
97\advance \topmargin by -\headsep
98
99% attempt to work a little better for A4 users
Fred Drake9466b9a1999-03-18 16:18:27 +0000100\textheight \paperheight
101\advance\textheight by -2in
Fred Drake6659c301998-03-03 22:02:19 +0000102
103\oddsidemargin 0pt
Fred Drake9466b9a1999-03-18 16:18:27 +0000104\evensidemargin 0pt
105%\evensidemargin -.25in % for ``manual size'' documents
Fred Drake6659c301998-03-03 22:02:19 +0000106\marginparwidth 0.5in
107
Fred Drake9466b9a1999-03-18 16:18:27 +0000108\textwidth \paperwidth
109\advance\textwidth by -2in
Fred Drake6659c301998-03-03 22:02:19 +0000110
111
112% Style parameters and macros used by most documents here
113\raggedbottom
114\sloppy
115\parindent = 0mm
Fred Drake24340ea1998-04-28 18:30:34 +0000116\parskip = 2mm
Fred Drake6659c301998-03-03 22:02:19 +0000117\hbadness = 5000 % don't print trivial gripes
118
119\pagestyle{empty} % start this way; change for
120\pagenumbering{roman} % ToC & chapters
121\setcounter{secnumdepth}{1}
122
123% Use this to set the font family for headers and other decor:
Fred Drake24340ea1998-04-28 18:30:34 +0000124\newcommand{\py@HeaderFamily}{\sffamily}
Fred Drake6659c301998-03-03 22:02:19 +0000125
126% Redefine the 'normal' header/footer style when using "fancyhdr" package:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000127\@ifundefined{fancyhf}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000128 % Use \pagestyle{normal} as the primary pagestyle for text.
129 \fancypagestyle{normal}{
130 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000131 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
132 \fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
133 \fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
Fred Drake6659c301998-03-03 22:02:19 +0000134 \renewcommand{\headrulewidth}{0pt}
135 \renewcommand{\footrulewidth}{0.4pt}
136 }
137 % Update the plain style so we get the page number & footer line,
138 % but not a chapter or section title. This is to keep the first
139 % page of a chapter and the blank page between chapters `clean.'
140 \fancypagestyle{plain}{
141 \fancyhf{}
Fred Drake24340ea1998-04-28 18:30:34 +0000142 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
Fred Drake6659c301998-03-03 22:02:19 +0000143 \renewcommand{\headrulewidth}{0pt}
144 \renewcommand{\footrulewidth}{0.4pt}
145 }
146 % Redefine \cleardoublepage so that the blank page between chapters
147 % gets the plain style and not the fancy style. This is described
148 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000149 \@ifundefined{chapter}{}{
Fred Drake28f13911998-03-04 21:47:59 +0000150 \renewcommand{\cleardoublepage}{
Fred Drake1c8d0e01998-03-07 05:29:15 +0000151 \clearpage\if@openright \ifodd\c@page\else
Fred Drake28f13911998-03-04 21:47:59 +0000152 \hbox{}
153 \thispagestyle{plain}
154 \newpage
Fred Drake1c8d0e01998-03-07 05:29:15 +0000155 \if@twocolumn\hbox{}\newpage\fi\fi\fi
Fred Drake28f13911998-03-04 21:47:59 +0000156 }
157 }
Fred Drake6659c301998-03-03 22:02:19 +0000158}
159
Fred Drake6659c301998-03-03 22:02:19 +0000160% This sets up the {verbatim} environment to be indented and a minipage,
161% and to have all the other mostly nice properties that we want for
162% code samples.
163
Fred Drake9466b9a1999-03-18 16:18:27 +0000164\let\py@OldVerbatim=\verbatim
165\let\py@OldEndVerbatim=\endverbatim
166\RequirePackage{verbatim}
167
Fred Drake6659c301998-03-03 22:02:19 +0000168% Variable used by begin code command
Fred Drake24340ea1998-04-28 18:30:34 +0000169\newlength{\py@codewidth}
Fred Drake6659c301998-03-03 22:02:19 +0000170
Fred Drake6659c301998-03-03 22:02:19 +0000171\renewcommand{\verbatim}{%
Fred Drake9466b9a1999-03-18 16:18:27 +0000172 \setlength{\parindent}{1cm}%
Fred Drake6659c301998-03-03 22:02:19 +0000173 % Calculate the text width for the minipage:
Fred Drake24340ea1998-04-28 18:30:34 +0000174 \setlength{\py@codewidth}{\linewidth}%
175 \addtolength{\py@codewidth}{-\parindent}%
Fred Drake6659c301998-03-03 22:02:19 +0000176 %
Fred Drake9466b9a1999-03-18 16:18:27 +0000177 \par\indent%
Fred Drake24340ea1998-04-28 18:30:34 +0000178 \begin{minipage}[t]{\py@codewidth}%
Fred Drake6659c301998-03-03 22:02:19 +0000179 \small%
Fred Drake24340ea1998-04-28 18:30:34 +0000180 \py@OldVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000181}
182\renewcommand{\endverbatim}{%
Fred Drake24340ea1998-04-28 18:30:34 +0000183 \py@OldEndVerbatim%
Fred Drake6659c301998-03-03 22:02:19 +0000184 \end{minipage}%
Fred Drake6659c301998-03-03 22:02:19 +0000185}
186
Fred Drake6cb71491998-03-27 05:22:53 +0000187
Fred Drakea488f301998-07-23 17:50:45 +0000188\newcommand{\py@modulebadkey}{{--just-some-junk--}}
Fred Drake6659c301998-03-03 22:02:19 +0000189
Fred Drake6659c301998-03-03 22:02:19 +0000190
191%% Lots of index-entry generation support.
192
193% Command to wrap around stuff that refers to function / module /
194% attribute names in the index. Default behavior: like \code{}. To
195% just keep the index entries in the roman font, uncomment the second
Fred Drakea488f301998-07-23 17:50:45 +0000196% definition; it matches O'Reilly style more.
Fred Drake6659c301998-03-03 22:02:19 +0000197%
Fred Drake24340ea1998-04-28 18:30:34 +0000198\newcommand{\py@idxcode}[1]{\texttt{#1}}
199%\renewcommand{\py@idxcode}[1]{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000200
201% Command to generate two index entries (using subentries)
202\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
203
204% And three entries (using only one level of subentries)
205\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
206
207% And four (again, using only one level of subentries)
208\newcommand{\indexiv}[4]{
209\index{#1!#2 #3 #4}
210\index{#2!#3 #4, #1}
211\index{#3!#4, #1 #2}
212\index{#4!#1 #2 #3}
213}
214
215% Command to generate a reference to a function, statement, keyword,
216% operator.
Fred Drake0cabff91998-05-06 19:36:01 +0000217\newcommand{\kwindex}[1]{\indexii{keyword}{#1@{\py@idxcode{#1}}}}
Fred Drake24340ea1998-04-28 18:30:34 +0000218\newcommand{\stindex}[1]{\indexii{statement}{#1@{\py@idxcode{#1}}}}
219\newcommand{\opindex}[1]{\indexii{operator}{#1@{\py@idxcode{#1}}}}
220\newcommand{\exindex}[1]{\indexii{exception}{#1@{\py@idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000221\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drake2351c801998-04-02 18:48:32 +0000222\newcommand{\bifuncindex}[1]{\withsubitem{(built-in function)}{\ttindex{#1()}}}
Fred Drake6659c301998-03-03 22:02:19 +0000223
224% Add an index entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000225\newcommand{\py@refmodule}[2]{\index{#1@{\py@idxcode{#1}} (#2module)}}
226\newcommand{\refmodindex}[1]{\py@refmodule{#1}{}}
227\newcommand{\refbimodindex}[1]{\py@refmodule{#1}{built-in }}
228\newcommand{\refexmodindex}[1]{\py@refmodule{#1}{extension }}
229\newcommand{\refstmodindex}[1]{\py@refmodule{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000230
Fred Drakeda943741999-01-13 17:09:06 +0000231% Refer to a module's documentation using a hyperlink of the module's
232% name, at least if we're building PDF:
233\@ifundefined{pdfannotlink}{%
234 \newcommand{\refmodule}[2][\py@modulebadkey]{\module{#2}}
Fred Drakeaa2aea01999-01-27 17:37:36 +0000235}{%
236 \newcommand{\refmodule}[2][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000237 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drakeaa2aea01999-01-27 17:37:36 +0000238 \py@linkToName{label-module-\py@modulekey}{\module{#2}}%
Fred Drakeda943741999-01-13 17:09:06 +0000239 }
240}
241
Fred Drake6659c301998-03-03 22:02:19 +0000242% support for the module index
Fred Drake24340ea1998-04-28 18:30:34 +0000243\newif\ifpy@UseModuleIndex
244\py@UseModuleIndexfalse
Fred Drakeb390daf1998-03-09 16:35:36 +0000245
Fred Drakeb390daf1998-03-09 16:35:36 +0000246\newcommand{\makemodindex}{
247 \newwrite\modindexfile
248 \openout\modindexfile=mod\jobname.idx
Fred Drake24340ea1998-04-28 18:30:34 +0000249 \py@UseModuleIndextrue
Fred Drakeb390daf1998-03-09 16:35:36 +0000250}
251
Fred Drake0ee9f721998-03-12 06:41:40 +0000252% Add the defining entry for a module
Fred Drake24340ea1998-04-28 18:30:34 +0000253\newcommand{\py@modindex}[2]{%
Fred Drakea488f301998-07-23 17:50:45 +0000254 \renewcommand{\py@thismodule}{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000255 \setindexsubitem{(in module #1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000256 \index{#1@{\py@idxcode{#1}} (#2module)|textbf}%
257 \ifpy@UseModuleIndex%
Fred Drake0c275fa1999-03-02 16:17:44 +0000258 \@ifundefined{py@modplat@\py@thismodulekey}{
259 \write\modindexfile{\protect\indexentry{#1@{\texttt{#1}}}{\thepage}}%
260 }{\write\modindexfile{\protect\indexentry{#1@{\texttt{#1} %
Fred Drake9466b9a1999-03-18 16:18:27 +0000261 \emph{(\py@platformof[\py@thismodulekey]{})}}}{\thepage}}%
Fred Drake0c275fa1999-03-02 16:17:44 +0000262 }
Fred Drake0ee9f721998-03-12 06:41:40 +0000263 \fi%
264}
265
Fred Drake9466b9a1999-03-18 16:18:27 +0000266% *** XXX *** THE NEXT FOUR MACROS ARE NOW OBSOLETE !!! ***
267
Fred Drake6659c301998-03-03 22:02:19 +0000268% built-in & Python modules in the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000269\newcommand{\bimodindex}[1]{\py@modindex{#1}{built-in }%
270 \typeout{*** MACRO bimodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
271\newcommand{\stmodindex}[1]{\py@modindex{#1}{standard }%
272 \typeout{*** MACRO stmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000273
274% Python & extension modules outside the main distribution
Fred Drake9466b9a1999-03-18 16:18:27 +0000275\newcommand{\modindex}[1]{\py@modindex{#1}{}%
276 \typeout{*** MACRO modindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
277\newcommand{\exmodindex}[1]{\py@modindex{#1}{extension }%
278 \typeout{*** MACRO exmodindex IS OBSOLETE -- USE declaremodule INSTEAD!}}
Fred Drake6659c301998-03-03 22:02:19 +0000279
280% Additional string for an index entry
Fred Drake1c8d0e01998-03-07 05:29:15 +0000281\newcommand{\index@subitem}{}
282\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000283\newcommand{\ttindex}[1]{\index{#1@{\py@idxcode{#1}} \index@subitem}}
Fred Drake6659c301998-03-03 22:02:19 +0000284
Fred Drake0ee9f721998-03-12 06:41:40 +0000285\newcommand{\withsubitem}[2]{%
286 \begingroup%
287 \def\index@subitem{#1}#2%
288 \endgroup%
289}
Fred Drake6659c301998-03-03 22:02:19 +0000290
Fred Drake53714971998-04-02 22:33:16 +0000291
Fred Drakea488f301998-07-23 17:50:45 +0000292% Module synopsis processing -----------------------------------------------
293%
Fred Drake0c275fa1999-03-02 16:17:44 +0000294\newcommand{\py@thisclass}{}
295\newcommand{\py@thismodule}{}
296\newcommand{\py@thismodulekey}{}
297\newcommand{\py@thismoduletype}{}
298
Fred Drake9466b9a1999-03-18 16:18:27 +0000299\newcommand{\py@standardIndexModule}[1]{\py@modindex{#1}{standard }}
300\newcommand{\py@builtinIndexModule}[1]{\py@modindex{#1}{built-in }}
301\newcommand{\py@extensionIndexModule}[1]{\py@modindex{#1}{extension }}
302\newcommand{\py@IndexModule}[1]{\py@modindex{#1}{}}
Fred Drakea488f301998-07-23 17:50:45 +0000303
Fred Drake0c275fa1999-03-02 16:17:44 +0000304\newif\ifpy@HaveModSynopsis \py@HaveModSynopsisfalse
305\newif\ifpy@ModSynopsisFileIsOpen \py@ModSynopsisFileIsOpenfalse
306\newif\ifpy@HaveModPlatform \py@HaveModPlatformfalse
Fred Drakea488f301998-07-23 17:50:45 +0000307
308% \declaremodule[key]{type}{name}
309\newcommand{\declaremodule}[3][\py@modulebadkey]{
310 \py@openModSynopsisFile
311 \renewcommand{\py@thismoduletype}{#2}
Fred Drakea488f301998-07-23 17:50:45 +0000312 \ifx\py@modulebadkey#1
313 \renewcommand{\py@thismodulekey}{#3}
314 \else
315 \renewcommand{\py@thismodulekey}{#1}
316 \fi
Fred Drake5bc8d991999-05-17 14:47:10 +0000317 \@ifundefined{py@#2IndexModule}{%
318 \typeout{*** MACRO declaremodule called with unknown module type: `#2'}
319 \py@ModuleIndex{#3}%
320 }{%
321 \csname py@#2IndexModule\endcsname{#3}%
322 }
Fred Drakea488f301998-07-23 17:50:45 +0000323 \label{module-\py@thismodulekey}
Fred Drakea488f301998-07-23 17:50:45 +0000324}
Fred Drake0c275fa1999-03-02 16:17:44 +0000325\newif\ifpy@ModPlatformFileIsOpen \py@ModPlatformFileIsOpenfalse
326\newcommand{\py@ModPlatformFilename}{\jobname.pla}
327\newcommand{\platform}[1]{
328 \ifpy@ModPlatformFileIsOpen\else
329 \newwrite\py@ModPlatformFile
330 \openout\py@ModPlatformFile=\py@ModPlatformFilename
331 \py@ModPlatformFileIsOpentrue
332 \fi
Fred Drake0c275fa1999-03-02 16:17:44 +0000333}
334\InputIfFileExists{\jobname.pla}{}{}
Fred Drake9466b9a1999-03-18 16:18:27 +0000335\newcommand{\py@platformof}[2][\py@modulebadkey]{%
Fred Drake0c275fa1999-03-02 16:17:44 +0000336 \ifx\py@modulebadkey#1 \def\py@key{#2}%
337 \else \def\py@key{#1}%
338 \fi%
339 \csname py@modplat@\py@key\endcsname%
340}
341\newcommand{\ignorePlatformAnnotation}[1]{}
Fred Drakea488f301998-07-23 17:50:45 +0000342
Fred Drakeb75c6151998-08-10 18:41:43 +0000343% \moduleauthor{name}{email}
344\newcommand{\moduleauthor}[2]{}
345
346% \sectionauthor{name}{email}
347\newcommand{\sectionauthor}[2]{}
348
Fred Drakea488f301998-07-23 17:50:45 +0000349
350\newcommand{\py@defsynopsis}{Module has no synopsis.}
351\newcommand{\py@modulesynopsis}{\py@defsynopsis}
352\newcommand{\modulesynopsis}[1]{
Fred Drake0c275fa1999-03-02 16:17:44 +0000353 \py@HaveModSynopsistrue
Fred Drakea488f301998-07-23 17:50:45 +0000354 \renewcommand{\py@modulesynopsis}{#1}
355}
356
357% define the file
358\newwrite\py@ModSynopsisFile
359
360% hacked from \addtocontents from latex.ltx:
361\long\def\py@writeModSynopsisFile#1{%
362 \protected@write\py@ModSynopsisFile%
363 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
364 {\string#1}%
365}
366\newcommand{\py@closeModSynopsisFile}{
367 \ifpy@ModSynopsisFileIsOpen
368 \closeout\py@ModSynopsisFile
369 \py@ModSynopsisFileIsOpenfalse
370 \fi
371}
372\newcommand{\py@openModSynopsisFile}{
373 \ifpy@ModSynopsisFileIsOpen\else
374 \openout\py@ModSynopsisFile=\py@ModSynopsisFilename
375 \py@ModSynopsisFileIsOpentrue
376 \fi
377}
378
379\newcommand{\py@ProcessModSynopsis}{
380 \ifpy@HaveModSynopsis
381 \py@writeModSynopsisFile{\modulesynopsis%
382 {\py@thismodulekey}{\py@thismodule}%
383 {\py@thismoduletype}{\py@modulesynopsis}}%
384 \py@HaveModSynopsisfalse
385 \fi
386 \renewcommand{\py@modulesynopsis}{\py@defsynopsis}
387}
388\AtEndDocument{\py@ProcessModSynopsis\py@closeModSynopsisFile}
389
Fred Drake0c275fa1999-03-02 16:17:44 +0000390
391\long\def\py@writeModPlatformFile#1{%
392 \protected@write\py@ModPlatformFile%
393 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
394 {\string#1}%
395}
396
397
Fred Drakea488f301998-07-23 17:50:45 +0000398\newcommand{\localmoduletable}{
399 \IfFileExists{\py@ModSynopsisFilename}{
400 \begin{synopsistable}
401 \input{\py@ModSynopsisFilename}
402 \end{synopsistable}
403 }{}
404}
405
406\@ifundefined{pdfoutput}{
407 \newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
408}{
Fred Drakeaa2aea01999-01-27 17:37:36 +0000409 \newcommand{\py@ModSynopsisSummary}[4]{%
410 \py@linkToName{label-module-#1}{\bfcode{#2}} & #4\\
411 }
Fred Drakea488f301998-07-23 17:50:45 +0000412}
413\newenvironment{synopsistable}{
414 % key, name, type, synopsis
415 \let\modulesynopsis=\py@ModSynopsisSummary
416 \begin{tabular}{ll}
417}{
418 \end{tabular}
419}
420%
421% --------------------------------------------------------------------------
422
423
Fred Drakea488f301998-07-23 17:50:45 +0000424\newcommand{\py@reset}{
425 \py@ProcessModSynopsis
426 \renewcommand{\py@thisclass}{}
427 \renewcommand{\py@thismodule}{}
428 \renewcommand{\py@thismodulekey}{}
429 \renewcommand{\py@thismoduletype}{}
430}
431
432% Augment the sectioning commands used to get our own font family in place,
433% and reset some internal data items:
434\renewcommand{\section}{\py@reset%
435 \@startsection{section}{1}{\z@}%
436 {-3.5ex \@plus -1ex \@minus -.2ex}%
437 {2.3ex \@plus.2ex}%
438 {\reset@font\Large\py@HeaderFamily}}
439\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
440 {-3.25ex\@plus -1ex \@minus -.2ex}%
441 {1.5ex \@plus .2ex}%
442 {\reset@font\large\py@HeaderFamily}}
443\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
444 {-3.25ex\@plus -1ex \@minus -.2ex}%
445 {1.5ex \@plus .2ex}%
446 {\reset@font\normalsize\py@HeaderFamily}}
447\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
448 {3.25ex \@plus1ex \@minus.2ex}%
449 {-1em}%
450 {\reset@font\normalsize\py@HeaderFamily}}
451\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
452 {3.25ex \@plus1ex \@minus .2ex}%
453 {-1em}%
454 {\reset@font\normalsize\py@HeaderFamily}}
455
456
Fred Drake5420f331998-07-23 21:41:02 +0000457% This gets the underscores closer to the right width; the only change
458% from standard LaTeX is the width specified.
459
460\DeclareTextCommandDefault{\textunderscore}{%
461 \leavevmode \kern.06em\vbox{\hrule\@width.55em}}
462
Fred Drakea488f301998-07-23 17:50:45 +0000463% Underscore hack (only act like subscript operator if in math mode)
464%
465% The following is due to Mark Wooding (the old version didn't work with
466% Latex 2e.
467
468\DeclareRobustCommand\hackscore{%
469 \ifmmode_\else\textunderscore\fi%
470}
471\begingroup
472\catcode`\_\active
473\def\next{%
474 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
475}
476\expandafter\endgroup\next
477
478
Fred Drake53714971998-04-02 22:33:16 +0000479% Now for a lot of semantically-loaded environments that do a ton of magical
480% things to get the right formatting and index entries for the stuff in
481% Python modules and C API.
482
483
Fred Drake6659c301998-03-03 22:02:19 +0000484% {fulllineitems} is used in one place in libregex.tex, but is really for
485% internal use in this file.
486%
Fred Drakef9acc591998-09-09 15:27:43 +0000487\newcommand{\py@itemnewline}[1]{%
488 \@tempdima\linewidth%
489 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
490}
491
Fred Drake6659c301998-03-03 22:02:19 +0000492\newenvironment{fulllineitems}{
493 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
494 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
495 \itemsep -\parsep
Fred Drakef9acc591998-09-09 15:27:43 +0000496 \let\makelabel=\py@itemnewline}
Fred Drake6659c301998-03-03 22:02:19 +0000497}{\end{list}}
498
Fred Drake6cb71491998-03-27 05:22:53 +0000499% \optional is mostly for use in the arguments parameters to the various
500% {*desc} environments defined below, but may be used elsewhere. Known to
501% be used in the debugger chapter.
Fred Drake24340ea1998-04-28 18:30:34 +0000502%
503% Typical usage:
504%
505% \begin{funcdesc}{myfunc}{reqparm\optional{, optparm}}
506% ^^^ ^^^
507% No space here No space here
508%
509% When a function has multiple optional parameters, \optional should be
510% nested, not chained. This is right:
511%
512% \begin{funcdesc}{myfunc}{\optional{parm1\optional{, parm2}}}
513%
Fred Drake6659c301998-03-03 22:02:19 +0000514\newcommand{\optional}[1]{%
515 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
516
Fred Drake6cb71491998-03-27 05:22:53 +0000517% C functions ------------------------------------------------------------
518% \begin{cfuncdesc}{type}{name}{arglist}
519\newenvironment{cfuncdesc}[3]{
520 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000521 \item[\code{#1 \bfcode{#2}(\py@varvars{#3})}\index{#2@{\py@idxcode{#2()}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000522}{\end{fulllineitems}}
523
524% C variables ------------------------------------------------------------
525% \begin{cvardesc}{type}{name}
526\newenvironment{cvardesc}[2]{
527 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000528 \item[\code{#1 \bfcode{#2}}\index{#2@{\py@idxcode{#2}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000529}{\end{fulllineitems}}
530
531% C data types -----------------------------------------------------------
532% \begin{ctypedesc}{typedef name}
533\newenvironment{ctypedesc}[1]{
534 \begin{fulllineitems}
535 \item[\bfcode{#1}\ttindex{#1}]
536}{\end{fulllineitems}}
537
538% simple functions (not methods) -----------------------------------------
539% \begin{funcdesc}{name}{args}
540\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
541\newenvironment{funcdesc}[2]{
542 \begin{fulllineitems}
543 \funcline{#1}{#2}
544}{\end{fulllineitems}}
545
Fred Drake6659c301998-03-03 22:02:19 +0000546% similar to {funcdesc}, but doesn't add to the index
Fred Drake300775d1998-04-17 02:17:00 +0000547\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\py@varvars{#2})}]}
Fred Drake6cb71491998-03-27 05:22:53 +0000548\newenvironment{funcdescni}[2]{
549 \begin{fulllineitems}
550 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000551}{\end{fulllineitems}}
552
Fred Drake6cb71491998-03-27 05:22:53 +0000553% classes ----------------------------------------------------------------
554% \begin{classdesc}{name}{constructor args}
555\newenvironment{classdesc}[2]{
Fred Drake1cbd1961998-11-25 17:13:28 +0000556 % Using \renewcommand doesn't work for this, for unknown reasons:
557 \global\def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000558 \begin{fulllineitems}
Fred Drake300775d1998-04-17 02:17:00 +0000559 \item[\code{\bfcode{#1}(\py@varvars{#2})}%
Fred Drake24340ea1998-04-28 18:30:34 +0000560 \withsubitem{(class in \py@thismodule)}{\ttindex{#1}}]
Fred Drake6659c301998-03-03 22:02:19 +0000561}{\end{fulllineitems}}
562
Fred Drake6cb71491998-03-27 05:22:53 +0000563
Fred Drake24340ea1998-04-28 18:30:34 +0000564\let\py@classbadkey=\@undefined
Fred Drake6cb71491998-03-27 05:22:53 +0000565
566% object method ----------------------------------------------------------
567% \begin{methoddesc}[classname]{methodname}{args}
Fred Drake24340ea1998-04-28 18:30:34 +0000568\newcommand{\methodline}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000569 \methodlineni{#2}{#3}
570 \ifx#1\@undefined
Fred Drake24340ea1998-04-28 18:30:34 +0000571 \withsubitem{(\py@thisclass\ method)}{\ttindex{#2()}}
Fred Drake6cb71491998-03-27 05:22:53 +0000572 \else
573 \withsubitem{(#1 method)}{\ttindex{#2()}}
574 \fi
575}
Fred Drake24340ea1998-04-28 18:30:34 +0000576\newenvironment{methoddesc}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000577 \begin{fulllineitems}
578 \ifx#1\@undefined
579 \methodline{#2}{#3}
580 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000581 \def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000582 \methodline[#1]{#2}{#3}
583 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000584}{\end{fulllineitems}}
585
Fred Drake6cb71491998-03-27 05:22:53 +0000586% similar to {methoddesc}, but doesn't add to the index
587% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000588\newcommand{\methodlineni}[3][\py@classbadkey]{%
Fred Drake300775d1998-04-17 02:17:00 +0000589 \item[\code{\bfcode{#2}(\py@varvars{#3})}]}
Fred Drake24340ea1998-04-28 18:30:34 +0000590\newenvironment{methoddescni}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000591 \begin{fulllineitems}
592 \methodlineni{#2}{#3}
593}{\end{fulllineitems}}
594
595% object data attribute --------------------------------------------------
596% \begin{memberdesc}[classname]{membername}
Fred Drake24340ea1998-04-28 18:30:34 +0000597\newcommand{\memberline}[2][\py@classbadkey]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000598 \ifx#1\@undefined
599 \memberlineni{#2}
Fred Drake24340ea1998-04-28 18:30:34 +0000600 \withsubitem{(\py@thisclass\ attribute)}{\ttindex{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000601 \else
602 \memberlineni{#2}
Fred Drake41565f61998-04-07 19:32:40 +0000603 \withsubitem{(#1 attribute)}{\ttindex{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000604 \fi
605}
Fred Drake24340ea1998-04-28 18:30:34 +0000606\newenvironment{memberdesc}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000607 \begin{fulllineitems}
608 \ifx#1\@undefined
609 \memberline{#2}
610 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000611 \def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000612 \memberline[#1]{#2}
613 \fi
614}{\end{fulllineitems}}
615
616% similar to {memberdesc}, but doesn't add to the index
617% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000618\newcommand{\memberlineni}[2][\py@classbadkey]{\item[\bfcode{#2}]}
619\newenvironment{memberdescni}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000620 \begin{fulllineitems}
621 \memberlineni{#2}
622}{\end{fulllineitems}}
623
624% For exceptions: --------------------------------------------------------
625% \begin{excdesc}{name}
626% -- need support for constructor; maybe use optional parameter?
627\newenvironment{excdesc}[1]{
628 \begin{fulllineitems}
629 \item[\bfcode{#1}\ttindex{#1}]
630}{\end{fulllineitems}}
631
632% Module data or constants: ----------------------------------------------
633% \begin{datadesc}{name}
Fred Drake6659c301998-03-03 22:02:19 +0000634\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drake6cb71491998-03-27 05:22:53 +0000635\newenvironment{datadesc}[1]{
636 \begin{fulllineitems}
637 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000638}{\end{fulllineitems}}
639
640% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000641\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
642\newenvironment{datadescni}[1]{
643 \begin{fulllineitems}
644 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000645}{\end{fulllineitems}}
646
Fred Drake6cb71491998-03-27 05:22:53 +0000647% bytecode instruction ---------------------------------------------------
648% \begin{opcodedesc}{name}{var}
649% -- {var} may be {}
650\newenvironment{opcodedesc}[2]{
651 \begin{fulllineitems}
652 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000653}{\end{fulllineitems}}
654
655
Fred Drake24340ea1998-04-28 18:30:34 +0000656\newcommand{\nodename}[1]{\label{#1}}
Fred Drake55730311998-03-25 15:41:23 +0000657
Fred Drake6659c301998-03-03 22:02:19 +0000658% For these commands, use \command{} to get the typography right, not
659% {\command}. This works better with the texinfo translation.
660\newcommand{\ABC}{{\sc abc}}
661\newcommand{\UNIX}{{\sc Unix}}
662\newcommand{\POSIX}{POSIX}
663\newcommand{\ASCII}{{\sc ascii}}
664\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
665\newcommand{\C}{C}
666\newcommand{\EOF}{{\sc eof}}
Fred Drake24340ea1998-04-28 18:30:34 +0000667\newcommand{\NULL}{\constant{NULL}}
Fred Drake6659c301998-03-03 22:02:19 +0000668
Fred Drake53714971998-04-02 22:33:16 +0000669% Also for consistency: spell Python "Python", not "python"!
670
Fred Drake6659c301998-03-03 22:02:19 +0000671% code is the most difficult one...
Fred Drake1c8d0e01998-03-07 05:29:15 +0000672\newcommand{\code}[1]{{\@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 +0000673\texttt{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000674
675\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Fred Drake8e54abe1998-07-01 14:49:25 +0000676\newcommand{\kbd}[1]{\code{#1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000677\newcommand{\samp}[1]{`\code{#1}'}
Fred Drake6659c301998-03-03 22:02:19 +0000678% This weird definition of \var{} allows it to always appear in roman
679% italics, and won't get funky in code fragments when we play around
Fred Drakefa1cceb1998-11-30 14:42:59 +0000680% with fonts. This also works directly in math mode.
681\newcommand{\var}[1]{%
682 \ifmmode%
683 \hbox{\normalsize\textrm{\textit{#1\/}}}%
684 \else%
685 \normalsize\textrm{\textit{#1\/}}%
686 \fi%
687}
Fred Drake24340ea1998-04-28 18:30:34 +0000688\renewcommand{\emph}[1]{{\em #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000689\newcommand{\dfn}[1]{\emph{#1}}
690\newcommand{\strong}[1]{{\bf #1}}
691% let's experiment with a new font:
Fred Drake0ee9f721998-03-12 06:41:40 +0000692\newcommand{\file}[1]{`{\small\textsf{#1}}'}
Fred Drake0a0fd591999-04-28 14:59:44 +0000693\newcommand{\filenq}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000694
695% Use this def/redef approach for \url{} since hyperref defined this already,
696% but only if we actually used hyperref:
Fred Drake6cb71491998-03-27 05:22:53 +0000697\@ifundefined{pdfannotlink}{
Fred Drakea2c2a831998-04-15 17:50:01 +0000698 \newcommand{\py@url}[1]{\mbox{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000699}{
Fred Drakea2c2a831998-04-15 17:50:01 +0000700 \newcommand{\py@url}[1]{{%
Fred Drake6659c301998-03-03 22:02:19 +0000701 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000702 \py@LinkColor% color of the link text
703 \mbox{\small\textsf{#1}}%
704 \py@NormalColor% Turn it back off; these are declarative
Fred Drake6659c301998-03-03 22:02:19 +0000705 \pdfendlink}% and don't appear bound to the current
706 }% formatting "box".
707}
Fred Drakea2c2a831998-04-15 17:50:01 +0000708\let\url=\py@url
Fred Drake0ee9f721998-03-12 06:41:40 +0000709\newcommand{\email}[1]{{\small\textsf{#1}}}
Fred Drake454a4fb1998-04-01 22:20:14 +0000710\newcommand{\newsgroup}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000711
Fred Drake300775d1998-04-17 02:17:00 +0000712\newcommand{\py@varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Fred Drake24340ea1998-04-28 18:30:34 +0000713% let's see if this breaks anything now; we may be able to simplify...
714\renewcommand{\py@varvars}[1]{\var{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000715
Fred Drake24340ea1998-04-28 18:30:34 +0000716% I'd really like to get rid of this!
Fred Drake6659c301998-03-03 22:02:19 +0000717\newif\iftexi\texifalse
Fred Drake6659c301998-03-03 22:02:19 +0000718
Fred Drake1e4973b1998-07-28 21:52:17 +0000719% This is used to get l2h to put the copyright and abstract on
720% a separate HTML page.
721\newif\ifhtml\htmlfalse
722
723
Fred Drake6659c301998-03-03 22:02:19 +0000724% These should be used for all references to identifiers which are
725% used to refer to instances of specific language constructs. See the
726% names for specific semantic assignments.
727%
728% For now, don't do anything really fancy with them; just use them as
729% logical markup. This might change in the future.
730%
Fred Drake24340ea1998-04-28 18:30:34 +0000731\newcommand{\module}[1]{\texttt{#1}}
732\newcommand{\keyword}[1]{\texttt{#1}}
733\newcommand{\exception}[1]{\texttt{#1}}
734\newcommand{\class}[1]{\texttt{#1}}
735\newcommand{\function}[1]{\texttt{#1}}
736\newcommand{\member}[1]{\texttt{#1}}
737\newcommand{\method}[1]{\texttt{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000738
Fred Drake53714971998-04-02 22:33:16 +0000739\newcommand{\pytype}[1]{#1} % built-in Python type
740
Fred Drake24340ea1998-04-28 18:30:34 +0000741\newcommand{\cfunction}[1]{\texttt{#1}}
742\newcommand{\ctype}[1]{\texttt{#1}} % C struct or typedef name
743\newcommand{\cdata}[1]{\texttt{#1}} % C variable, typically global
Fred Drake6659c301998-03-03 22:02:19 +0000744
Fred Drake0ee9f721998-03-12 06:41:40 +0000745\newcommand{\mimetype}[1]{{\small\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000746% The \! is a "negative thin space" in math mode.
747\newcommand{\regexp}[1]{%
748 {\tiny$^{^\lceil}\!\!$%
749 {\normalsize\code{#1}}%
Fred Drake47cfd031998-04-03 21:22:31 +0000750 $\!\rfloor\!$%
Fred Drake94fac131998-03-12 19:37:03 +0000751 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000752\newcommand{\envvar}[1]{%
Fred Drake94fac131998-03-12 19:37:03 +0000753 \$#1% $ <-- bow to font-lock 3 times!
754 \index{#1@{\$#1}}% $
755 \index{environment variables!{\$#1}}% $
Fred Drake0ee9f721998-03-12 06:41:40 +0000756}
Fred Drake24340ea1998-04-28 18:30:34 +0000757\newcommand{\makevar}[1]{#1} % variable in a Makefile
758\newcommand{\character}[1]{\samp{#1}}
Fred Drake0ee9f721998-03-12 06:41:40 +0000759
Fred Drake6659c301998-03-03 22:02:19 +0000760% constants defined in Python modules or C headers, not language constants:
Fred Drake24340ea1998-04-28 18:30:34 +0000761\newcommand{\constant}[1]{\code{#1}} % manifest constant, not syntactic
Fred Drake6659c301998-03-03 22:02:19 +0000762
763\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
764\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
765\newcommand{\program}[1]{\strong{#1}}
766
767
768% Deprecation stuff.
769% Should be extended to allow an index / list of deprecated stuff. But
770% there's a lot of stuff that needs to be done to make that automatable.
771%
772% First parameter is the release number that deprecates the feature, the
773% second is the action the should be taken by users of the feature.
774%
775% Example:
Fred Drake24340ea1998-04-28 18:30:34 +0000776% \deprecated{1.5.1}{Use \method{frobnicate()} instead.}
Fred Drake6659c301998-03-03 22:02:19 +0000777%
778\newcommand{\deprecated}[2]{%
779 \strong{Deprecated since release #1.} #2\par}
780
Fred Drakeaf958c71998-07-27 20:32:33 +0000781% New stuff.
782% This should be used to mark things which have been added to the
783% development tree but that aren't in the release, but are documented.
784% This allows release of documentation that already includes updated
Fred Drake2116d981999-02-02 18:02:48 +0000785% descriptions. Place at end of descriptor environment.
Fred Drakeaf958c71998-07-27 20:32:33 +0000786%
787% Example:
788% \versionadded{1.5.2}
789%
790\newcommand{\versionadded}[1]{%
Fred Drake2116d981999-02-02 18:02:48 +0000791 { New in version #1. }}
Fred Drakeaf958c71998-07-27 20:32:33 +0000792\newcommand{\versionchanged}[1]{%
Fred Drake2116d981999-02-02 18:02:48 +0000793 { Changed in version #1. }}
Fred Drake6659c301998-03-03 22:02:19 +0000794
Fred Drakeaf958c71998-07-27 20:32:33 +0000795
796% Tables.
797%
Fred Drake6659c301998-03-03 22:02:19 +0000798\newenvironment{tableii}[4]{%
799 \begin{center}%
800 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakeee601911998-04-11 20:53:03 +0000801 \begin{tabular}{#1}\strong{#3}&\strong{#4} \\ \hline%
Fred Drake6659c301998-03-03 22:02:19 +0000802}{%
Fred Drake6659c301998-03-03 22:02:19 +0000803 \end{tabular}%
804 \end{center}%
805}
806
807\newenvironment{tableiii}[5]{%
808 \begin{center}%
809 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
Fred Drakeee601911998-04-11 20:53:03 +0000810 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\ \hline%
Fred Drake6659c301998-03-03 22:02:19 +0000811}{%
Fred Drake6659c301998-03-03 22:02:19 +0000812 \end{tabular}%
813 \end{center}%
814}
815
Fred Drake30e52651998-07-24 22:11:29 +0000816\newenvironment{tableiv}[6]{%
817 \begin{center}%
818 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
819 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6} \\%
820 \hline%
821}{%
822 \end{tabular}%
823 \end{center}%
824}
825
Fred Drake24340ea1998-04-28 18:30:34 +0000826% Cross-referencing (AMK, new impl. FLD)
Fred Drake6659c301998-03-03 22:02:19 +0000827% Sample usage:
828% \begin{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +0000829% \seemodule{rand}{Uniform random number generator.}; % Module xref
830% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +0000831%
832% % A funky case: module name contains '_'; have to supply an optional key
Fred Drake84bd6f31999-05-11 15:42:51 +0000833% \seemodule[copyreg]{copy_reg}{Interface constructor registration for
834% \module{pickle}.}
Fred Drake6659c301998-03-03 22:02:19 +0000835% \end{seealso}
Fred Drake84bd6f31999-05-11 15:42:51 +0000836%
837% Note that the last parameter for \seemodule and \seetext should be complete
838% sentences and be terminated with the proper punctuation.
Fred Drake6659c301998-03-03 22:02:19 +0000839
Fred Drake1c8d0e01998-03-07 05:29:15 +0000840\@ifundefined{pdfannotlink}{%
Fred Drake24340ea1998-04-28 18:30:34 +0000841 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000842 \par%
Fred Drake24340ea1998-04-28 18:30:34 +0000843 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drake84bd6f31999-05-11 15:42:51 +0000844 \begin{fulllineitems}
845 \item[Module \module{#2} (section \ref{module-\py@modulekey}):]
846 #3
847 \end{fulllineitems}
Fred Drakeebcb6581998-03-06 21:25:17 +0000848 }
Fred Drake24340ea1998-04-28 18:30:34 +0000849}{\newcommand{\py@seemodule}[3][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000850 \par%
Fred Drake24340ea1998-04-28 18:30:34 +0000851 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
Fred Drake84bd6f31999-05-11 15:42:51 +0000852 \begin{fulllineitems}
853 \item[\py@linkToName{label-module-\py@modulekey}{Module \module{#2}}
854 (section \ref{module-\py@modulekey}):]
855 #3
856 \end{fulllineitems}
Fred Drakeebcb6581998-03-06 21:25:17 +0000857 }
858}
Fred Drake6659c301998-03-03 22:02:19 +0000859\newenvironment{seealso}[0]{
Fred Drake9466b9a1999-03-18 16:18:27 +0000860 \par
Fred Drake6659c301998-03-03 22:02:19 +0000861 \strong{See Also:}\par
Fred Drake6659c301998-03-03 22:02:19 +0000862 \def\seetext##1{\par{##1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000863 \let\seemodule=\py@seemodule
Fred Drake6659c301998-03-03 22:02:19 +0000864}{\par}
865
866
Fred Drakeaf958c71998-07-27 20:32:33 +0000867% Allow the Python release number to be specified independently of the
Fred Drake6659c301998-03-03 22:02:19 +0000868% \date{}. This allows the date to reflect the document's date and
869% release to specify the Python release that is documented.
870%
Fred Drake24340ea1998-04-28 18:30:34 +0000871\newcommand{\py@release}{}
Fred Drake6659c301998-03-03 22:02:19 +0000872\newcommand{\version}{}
873\newcommand{\releasename}{Release}
874\newcommand{\release}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +0000875 \renewcommand{\py@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +0000876 \renewcommand{\version}{#1}}
877
878% Allow specification of the author's address separately from the
879% author's name. This can be used to format them differently, which
880% is a good thing.
881%
Fred Drake24340ea1998-04-28 18:30:34 +0000882\newcommand{\py@authoraddress}{}
883\newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress}{#1}}
Fred Drake6df93ef1998-05-14 20:56:31 +0000884\let\developersaddress=\authoraddress
885\let\developer=\author
886\let\developers=\author
Fred Drake6659c301998-03-03 22:02:19 +0000887
Fred Drake6659c301998-03-03 22:02:19 +0000888% This sets up the fancy chapter headings that make the documents look
889% at least a little better than the usual LaTeX output.
890%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000891\@ifundefined{ChTitleVar}{}{
Fred Drake24340ea1998-04-28 18:30:34 +0000892 \ChNameVar{\raggedleft\normalsize\py@HeaderFamily}
893 \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily}
894 \ChTitleVar{\raggedleft \rm\Huge\py@HeaderFamily}
Fred Drake6659c301998-03-03 22:02:19 +0000895 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000896 \def\@makechapterhead#1{%
897 {\parindent \z@ \raggedright \normalfont
898 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +0000899 \DOCH
900 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +0000901 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +0000902 \DOTI{#1}
903 }
904 }
Fred Drake6659c301998-03-03 22:02:19 +0000905}
906
Fred Drake3bf78651998-05-20 17:42:17 +0000907
908% Definition lists; requested by AMK for HOWTO documents. Probably useful
909% elsewhere as well, so keep in in the general style support.
910%
911\newenvironment{definitions}{%
912 \begin{description}%
Fred Drakef9acc591998-09-09 15:27:43 +0000913 \def\term##1{\item[##1]\mbox{}\\*[0mm]}
Fred Drake3bf78651998-05-20 17:42:17 +0000914}{%
915 \end{description}%
916}
917
Fred Drake6659c301998-03-03 22:02:19 +0000918% Tell TeX about pathological hyphenation cases:
919\hyphenation{Base-HTTP-Re-quest-Hand-ler}