blob: 2190f25a4a6e366030ed7beadb7fc4ff451c7641 [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 Drake0c275fa1999-03-02 16:17:44 +0000317 \csname py@#2IndexModule\endcsname{#3}
Fred Drakea488f301998-07-23 17:50:45 +0000318 \label{module-\py@thismodulekey}
Fred Drakea488f301998-07-23 17:50:45 +0000319}
Fred Drake0c275fa1999-03-02 16:17:44 +0000320\newif\ifpy@ModPlatformFileIsOpen \py@ModPlatformFileIsOpenfalse
321\newcommand{\py@ModPlatformFilename}{\jobname.pla}
322\newcommand{\platform}[1]{
323 \ifpy@ModPlatformFileIsOpen\else
324 \newwrite\py@ModPlatformFile
325 \openout\py@ModPlatformFile=\py@ModPlatformFilename
326 \py@ModPlatformFileIsOpentrue
327 \fi
Fred Drake0c275fa1999-03-02 16:17:44 +0000328}
329\InputIfFileExists{\jobname.pla}{}{}
Fred Drake9466b9a1999-03-18 16:18:27 +0000330\newcommand{\py@platformof}[2][\py@modulebadkey]{%
Fred Drake0c275fa1999-03-02 16:17:44 +0000331 \ifx\py@modulebadkey#1 \def\py@key{#2}%
332 \else \def\py@key{#1}%
333 \fi%
334 \csname py@modplat@\py@key\endcsname%
335}
336\newcommand{\ignorePlatformAnnotation}[1]{}
Fred Drakea488f301998-07-23 17:50:45 +0000337
Fred Drakeb75c6151998-08-10 18:41:43 +0000338% \moduleauthor{name}{email}
339\newcommand{\moduleauthor}[2]{}
340
341% \sectionauthor{name}{email}
342\newcommand{\sectionauthor}[2]{}
343
Fred Drakea488f301998-07-23 17:50:45 +0000344
345\newcommand{\py@defsynopsis}{Module has no synopsis.}
346\newcommand{\py@modulesynopsis}{\py@defsynopsis}
347\newcommand{\modulesynopsis}[1]{
Fred Drake0c275fa1999-03-02 16:17:44 +0000348 \py@HaveModSynopsistrue
Fred Drakea488f301998-07-23 17:50:45 +0000349 \renewcommand{\py@modulesynopsis}{#1}
350}
351
352% define the file
353\newwrite\py@ModSynopsisFile
354
355% hacked from \addtocontents from latex.ltx:
356\long\def\py@writeModSynopsisFile#1{%
357 \protected@write\py@ModSynopsisFile%
358 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
359 {\string#1}%
360}
361\newcommand{\py@closeModSynopsisFile}{
362 \ifpy@ModSynopsisFileIsOpen
363 \closeout\py@ModSynopsisFile
364 \py@ModSynopsisFileIsOpenfalse
365 \fi
366}
367\newcommand{\py@openModSynopsisFile}{
368 \ifpy@ModSynopsisFileIsOpen\else
369 \openout\py@ModSynopsisFile=\py@ModSynopsisFilename
370 \py@ModSynopsisFileIsOpentrue
371 \fi
372}
373
374\newcommand{\py@ProcessModSynopsis}{
375 \ifpy@HaveModSynopsis
376 \py@writeModSynopsisFile{\modulesynopsis%
377 {\py@thismodulekey}{\py@thismodule}%
378 {\py@thismoduletype}{\py@modulesynopsis}}%
379 \py@HaveModSynopsisfalse
380 \fi
381 \renewcommand{\py@modulesynopsis}{\py@defsynopsis}
382}
383\AtEndDocument{\py@ProcessModSynopsis\py@closeModSynopsisFile}
384
Fred Drake0c275fa1999-03-02 16:17:44 +0000385
386\long\def\py@writeModPlatformFile#1{%
387 \protected@write\py@ModPlatformFile%
388 {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
389 {\string#1}%
390}
391
392
Fred Drakea488f301998-07-23 17:50:45 +0000393\newcommand{\localmoduletable}{
394 \IfFileExists{\py@ModSynopsisFilename}{
395 \begin{synopsistable}
396 \input{\py@ModSynopsisFilename}
397 \end{synopsistable}
398 }{}
399}
400
401\@ifundefined{pdfoutput}{
402 \newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
403}{
Fred Drakeaa2aea01999-01-27 17:37:36 +0000404 \newcommand{\py@ModSynopsisSummary}[4]{%
405 \py@linkToName{label-module-#1}{\bfcode{#2}} & #4\\
406 }
Fred Drakea488f301998-07-23 17:50:45 +0000407}
408\newenvironment{synopsistable}{
409 % key, name, type, synopsis
410 \let\modulesynopsis=\py@ModSynopsisSummary
411 \begin{tabular}{ll}
412}{
413 \end{tabular}
414}
415%
416% --------------------------------------------------------------------------
417
418
Fred Drakea488f301998-07-23 17:50:45 +0000419\newcommand{\py@reset}{
420 \py@ProcessModSynopsis
421 \renewcommand{\py@thisclass}{}
422 \renewcommand{\py@thismodule}{}
423 \renewcommand{\py@thismodulekey}{}
424 \renewcommand{\py@thismoduletype}{}
425}
426
427% Augment the sectioning commands used to get our own font family in place,
428% and reset some internal data items:
429\renewcommand{\section}{\py@reset%
430 \@startsection{section}{1}{\z@}%
431 {-3.5ex \@plus -1ex \@minus -.2ex}%
432 {2.3ex \@plus.2ex}%
433 {\reset@font\Large\py@HeaderFamily}}
434\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
435 {-3.25ex\@plus -1ex \@minus -.2ex}%
436 {1.5ex \@plus .2ex}%
437 {\reset@font\large\py@HeaderFamily}}
438\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
439 {-3.25ex\@plus -1ex \@minus -.2ex}%
440 {1.5ex \@plus .2ex}%
441 {\reset@font\normalsize\py@HeaderFamily}}
442\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
443 {3.25ex \@plus1ex \@minus.2ex}%
444 {-1em}%
445 {\reset@font\normalsize\py@HeaderFamily}}
446\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
447 {3.25ex \@plus1ex \@minus .2ex}%
448 {-1em}%
449 {\reset@font\normalsize\py@HeaderFamily}}
450
451
Fred Drake5420f331998-07-23 21:41:02 +0000452% This gets the underscores closer to the right width; the only change
453% from standard LaTeX is the width specified.
454
455\DeclareTextCommandDefault{\textunderscore}{%
456 \leavevmode \kern.06em\vbox{\hrule\@width.55em}}
457
Fred Drakea488f301998-07-23 17:50:45 +0000458% Underscore hack (only act like subscript operator if in math mode)
459%
460% The following is due to Mark Wooding (the old version didn't work with
461% Latex 2e.
462
463\DeclareRobustCommand\hackscore{%
464 \ifmmode_\else\textunderscore\fi%
465}
466\begingroup
467\catcode`\_\active
468\def\next{%
469 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
470}
471\expandafter\endgroup\next
472
473
Fred Drake53714971998-04-02 22:33:16 +0000474% Now for a lot of semantically-loaded environments that do a ton of magical
475% things to get the right formatting and index entries for the stuff in
476% Python modules and C API.
477
478
Fred Drake6659c301998-03-03 22:02:19 +0000479% {fulllineitems} is used in one place in libregex.tex, but is really for
480% internal use in this file.
481%
Fred Drakef9acc591998-09-09 15:27:43 +0000482\newcommand{\py@itemnewline}[1]{%
483 \@tempdima\linewidth%
484 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
485}
486
Fred Drake6659c301998-03-03 22:02:19 +0000487\newenvironment{fulllineitems}{
488 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
489 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
490 \itemsep -\parsep
Fred Drakef9acc591998-09-09 15:27:43 +0000491 \let\makelabel=\py@itemnewline}
Fred Drake6659c301998-03-03 22:02:19 +0000492}{\end{list}}
493
Fred Drake6cb71491998-03-27 05:22:53 +0000494% \optional is mostly for use in the arguments parameters to the various
495% {*desc} environments defined below, but may be used elsewhere. Known to
496% be used in the debugger chapter.
Fred Drake24340ea1998-04-28 18:30:34 +0000497%
498% Typical usage:
499%
500% \begin{funcdesc}{myfunc}{reqparm\optional{, optparm}}
501% ^^^ ^^^
502% No space here No space here
503%
504% When a function has multiple optional parameters, \optional should be
505% nested, not chained. This is right:
506%
507% \begin{funcdesc}{myfunc}{\optional{parm1\optional{, parm2}}}
508%
Fred Drake6659c301998-03-03 22:02:19 +0000509\newcommand{\optional}[1]{%
510 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
511
Fred Drake6cb71491998-03-27 05:22:53 +0000512% C functions ------------------------------------------------------------
513% \begin{cfuncdesc}{type}{name}{arglist}
514\newenvironment{cfuncdesc}[3]{
515 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000516 \item[\code{#1 \bfcode{#2}(\py@varvars{#3})}\index{#2@{\py@idxcode{#2()}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000517}{\end{fulllineitems}}
518
519% C variables ------------------------------------------------------------
520% \begin{cvardesc}{type}{name}
521\newenvironment{cvardesc}[2]{
522 \begin{fulllineitems}
Fred Drake24340ea1998-04-28 18:30:34 +0000523 \item[\code{#1 \bfcode{#2}}\index{#2@{\py@idxcode{#2}}}]
Fred Drake6cb71491998-03-27 05:22:53 +0000524}{\end{fulllineitems}}
525
526% C data types -----------------------------------------------------------
527% \begin{ctypedesc}{typedef name}
528\newenvironment{ctypedesc}[1]{
529 \begin{fulllineitems}
530 \item[\bfcode{#1}\ttindex{#1}]
531}{\end{fulllineitems}}
532
533% simple functions (not methods) -----------------------------------------
534% \begin{funcdesc}{name}{args}
535\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
536\newenvironment{funcdesc}[2]{
537 \begin{fulllineitems}
538 \funcline{#1}{#2}
539}{\end{fulllineitems}}
540
Fred Drake6659c301998-03-03 22:02:19 +0000541% similar to {funcdesc}, but doesn't add to the index
Fred Drake300775d1998-04-17 02:17:00 +0000542\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\py@varvars{#2})}]}
Fred Drake6cb71491998-03-27 05:22:53 +0000543\newenvironment{funcdescni}[2]{
544 \begin{fulllineitems}
545 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000546}{\end{fulllineitems}}
547
Fred Drake6cb71491998-03-27 05:22:53 +0000548% classes ----------------------------------------------------------------
549% \begin{classdesc}{name}{constructor args}
550\newenvironment{classdesc}[2]{
Fred Drake1cbd1961998-11-25 17:13:28 +0000551 % Using \renewcommand doesn't work for this, for unknown reasons:
552 \global\def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000553 \begin{fulllineitems}
Fred Drake300775d1998-04-17 02:17:00 +0000554 \item[\code{\bfcode{#1}(\py@varvars{#2})}%
Fred Drake24340ea1998-04-28 18:30:34 +0000555 \withsubitem{(class in \py@thismodule)}{\ttindex{#1}}]
Fred Drake6659c301998-03-03 22:02:19 +0000556}{\end{fulllineitems}}
557
Fred Drake6cb71491998-03-27 05:22:53 +0000558
Fred Drake24340ea1998-04-28 18:30:34 +0000559\let\py@classbadkey=\@undefined
Fred Drake6cb71491998-03-27 05:22:53 +0000560
561% object method ----------------------------------------------------------
562% \begin{methoddesc}[classname]{methodname}{args}
Fred Drake24340ea1998-04-28 18:30:34 +0000563\newcommand{\methodline}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000564 \methodlineni{#2}{#3}
565 \ifx#1\@undefined
Fred Drake24340ea1998-04-28 18:30:34 +0000566 \withsubitem{(\py@thisclass\ method)}{\ttindex{#2()}}
Fred Drake6cb71491998-03-27 05:22:53 +0000567 \else
568 \withsubitem{(#1 method)}{\ttindex{#2()}}
569 \fi
570}
Fred Drake24340ea1998-04-28 18:30:34 +0000571\newenvironment{methoddesc}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000572 \begin{fulllineitems}
573 \ifx#1\@undefined
574 \methodline{#2}{#3}
575 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000576 \def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000577 \methodline[#1]{#2}{#3}
578 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000579}{\end{fulllineitems}}
580
Fred Drake6cb71491998-03-27 05:22:53 +0000581% similar to {methoddesc}, but doesn't add to the index
582% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000583\newcommand{\methodlineni}[3][\py@classbadkey]{%
Fred Drake300775d1998-04-17 02:17:00 +0000584 \item[\code{\bfcode{#2}(\py@varvars{#3})}]}
Fred Drake24340ea1998-04-28 18:30:34 +0000585\newenvironment{methoddescni}[3][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000586 \begin{fulllineitems}
587 \methodlineni{#2}{#3}
588}{\end{fulllineitems}}
589
590% object data attribute --------------------------------------------------
591% \begin{memberdesc}[classname]{membername}
Fred Drake24340ea1998-04-28 18:30:34 +0000592\newcommand{\memberline}[2][\py@classbadkey]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000593 \ifx#1\@undefined
594 \memberlineni{#2}
Fred Drake24340ea1998-04-28 18:30:34 +0000595 \withsubitem{(\py@thisclass\ attribute)}{\ttindex{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000596 \else
597 \memberlineni{#2}
Fred Drake41565f61998-04-07 19:32:40 +0000598 \withsubitem{(#1 attribute)}{\ttindex{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000599 \fi
600}
Fred Drake24340ea1998-04-28 18:30:34 +0000601\newenvironment{memberdesc}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000602 \begin{fulllineitems}
603 \ifx#1\@undefined
604 \memberline{#2}
605 \else
Fred Drake24340ea1998-04-28 18:30:34 +0000606 \def\py@thisclass{#1}
Fred Drake6cb71491998-03-27 05:22:53 +0000607 \memberline[#1]{#2}
608 \fi
609}{\end{fulllineitems}}
610
611% similar to {memberdesc}, but doesn't add to the index
612% (never actually uses the optional argument)
Fred Drake24340ea1998-04-28 18:30:34 +0000613\newcommand{\memberlineni}[2][\py@classbadkey]{\item[\bfcode{#2}]}
614\newenvironment{memberdescni}[2][\py@classbadkey]{
Fred Drake6cb71491998-03-27 05:22:53 +0000615 \begin{fulllineitems}
616 \memberlineni{#2}
617}{\end{fulllineitems}}
618
619% For exceptions: --------------------------------------------------------
620% \begin{excdesc}{name}
621% -- need support for constructor; maybe use optional parameter?
622\newenvironment{excdesc}[1]{
623 \begin{fulllineitems}
624 \item[\bfcode{#1}\ttindex{#1}]
625}{\end{fulllineitems}}
626
627% Module data or constants: ----------------------------------------------
628% \begin{datadesc}{name}
Fred Drake6659c301998-03-03 22:02:19 +0000629\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drake6cb71491998-03-27 05:22:53 +0000630\newenvironment{datadesc}[1]{
631 \begin{fulllineitems}
632 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000633}{\end{fulllineitems}}
634
635% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000636\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
637\newenvironment{datadescni}[1]{
638 \begin{fulllineitems}
639 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000640}{\end{fulllineitems}}
641
Fred Drake6cb71491998-03-27 05:22:53 +0000642% bytecode instruction ---------------------------------------------------
643% \begin{opcodedesc}{name}{var}
644% -- {var} may be {}
645\newenvironment{opcodedesc}[2]{
646 \begin{fulllineitems}
647 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000648}{\end{fulllineitems}}
649
650
Fred Drake24340ea1998-04-28 18:30:34 +0000651\newcommand{\nodename}[1]{\label{#1}}
Fred Drake55730311998-03-25 15:41:23 +0000652
Fred Drake6659c301998-03-03 22:02:19 +0000653% For these commands, use \command{} to get the typography right, not
654% {\command}. This works better with the texinfo translation.
655\newcommand{\ABC}{{\sc abc}}
656\newcommand{\UNIX}{{\sc Unix}}
657\newcommand{\POSIX}{POSIX}
658\newcommand{\ASCII}{{\sc ascii}}
659\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
660\newcommand{\C}{C}
661\newcommand{\EOF}{{\sc eof}}
Fred Drake24340ea1998-04-28 18:30:34 +0000662\newcommand{\NULL}{\constant{NULL}}
Fred Drake6659c301998-03-03 22:02:19 +0000663
Fred Drake53714971998-04-02 22:33:16 +0000664% Also for consistency: spell Python "Python", not "python"!
665
Fred Drake6659c301998-03-03 22:02:19 +0000666% code is the most difficult one...
Fred Drake1c8d0e01998-03-07 05:29:15 +0000667\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 +0000668\texttt{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000669
670\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
Fred Drake8e54abe1998-07-01 14:49:25 +0000671\newcommand{\kbd}[1]{\code{#1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000672\newcommand{\samp}[1]{`\code{#1}'}
Fred Drake6659c301998-03-03 22:02:19 +0000673% This weird definition of \var{} allows it to always appear in roman
674% italics, and won't get funky in code fragments when we play around
Fred Drakefa1cceb1998-11-30 14:42:59 +0000675% with fonts. This also works directly in math mode.
676\newcommand{\var}[1]{%
677 \ifmmode%
678 \hbox{\normalsize\textrm{\textit{#1\/}}}%
679 \else%
680 \normalsize\textrm{\textit{#1\/}}%
681 \fi%
682}
Fred Drake24340ea1998-04-28 18:30:34 +0000683\renewcommand{\emph}[1]{{\em #1}}
Fred Drake6659c301998-03-03 22:02:19 +0000684\newcommand{\dfn}[1]{\emph{#1}}
685\newcommand{\strong}[1]{{\bf #1}}
686% let's experiment with a new font:
Fred Drake0ee9f721998-03-12 06:41:40 +0000687\newcommand{\file}[1]{`{\small\textsf{#1}}'}
Fred Drake6659c301998-03-03 22:02:19 +0000688
689% Use this def/redef approach for \url{} since hyperref defined this already,
690% but only if we actually used hyperref:
Fred Drake6cb71491998-03-27 05:22:53 +0000691\@ifundefined{pdfannotlink}{
Fred Drakea2c2a831998-04-15 17:50:01 +0000692 \newcommand{\py@url}[1]{\mbox{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000693}{
Fred Drakea2c2a831998-04-15 17:50:01 +0000694 \newcommand{\py@url}[1]{{%
Fred Drake6659c301998-03-03 22:02:19 +0000695 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
Fred Drake24340ea1998-04-28 18:30:34 +0000696 \py@LinkColor% color of the link text
697 \mbox{\small\textsf{#1}}%
698 \py@NormalColor% Turn it back off; these are declarative
Fred Drake6659c301998-03-03 22:02:19 +0000699 \pdfendlink}% and don't appear bound to the current
700 }% formatting "box".
701}
Fred Drakea2c2a831998-04-15 17:50:01 +0000702\let\url=\py@url
Fred Drake0ee9f721998-03-12 06:41:40 +0000703\newcommand{\email}[1]{{\small\textsf{#1}}}
Fred Drake454a4fb1998-04-01 22:20:14 +0000704\newcommand{\newsgroup}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000705
Fred Drake300775d1998-04-17 02:17:00 +0000706\newcommand{\py@varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Fred Drake24340ea1998-04-28 18:30:34 +0000707% let's see if this breaks anything now; we may be able to simplify...
708\renewcommand{\py@varvars}[1]{\var{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000709
Fred Drake24340ea1998-04-28 18:30:34 +0000710% I'd really like to get rid of this!
Fred Drake6659c301998-03-03 22:02:19 +0000711\newif\iftexi\texifalse
Fred Drake6659c301998-03-03 22:02:19 +0000712
Fred Drake1e4973b1998-07-28 21:52:17 +0000713% This is used to get l2h to put the copyright and abstract on
714% a separate HTML page.
715\newif\ifhtml\htmlfalse
716
717
Fred Drake6659c301998-03-03 22:02:19 +0000718% These should be used for all references to identifiers which are
719% used to refer to instances of specific language constructs. See the
720% names for specific semantic assignments.
721%
722% For now, don't do anything really fancy with them; just use them as
723% logical markup. This might change in the future.
724%
Fred Drake24340ea1998-04-28 18:30:34 +0000725\newcommand{\module}[1]{\texttt{#1}}
726\newcommand{\keyword}[1]{\texttt{#1}}
727\newcommand{\exception}[1]{\texttt{#1}}
728\newcommand{\class}[1]{\texttt{#1}}
729\newcommand{\function}[1]{\texttt{#1}}
730\newcommand{\member}[1]{\texttt{#1}}
731\newcommand{\method}[1]{\texttt{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000732
Fred Drake53714971998-04-02 22:33:16 +0000733\newcommand{\pytype}[1]{#1} % built-in Python type
734
Fred Drake24340ea1998-04-28 18:30:34 +0000735\newcommand{\cfunction}[1]{\texttt{#1}}
736\newcommand{\ctype}[1]{\texttt{#1}} % C struct or typedef name
737\newcommand{\cdata}[1]{\texttt{#1}} % C variable, typically global
Fred Drake6659c301998-03-03 22:02:19 +0000738
Fred Drake0ee9f721998-03-12 06:41:40 +0000739\newcommand{\mimetype}[1]{{\small\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000740% The \! is a "negative thin space" in math mode.
741\newcommand{\regexp}[1]{%
742 {\tiny$^{^\lceil}\!\!$%
743 {\normalsize\code{#1}}%
Fred Drake47cfd031998-04-03 21:22:31 +0000744 $\!\rfloor\!$%
Fred Drake94fac131998-03-12 19:37:03 +0000745 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000746\newcommand{\envvar}[1]{%
Fred Drake94fac131998-03-12 19:37:03 +0000747 \$#1% $ <-- bow to font-lock 3 times!
748 \index{#1@{\$#1}}% $
749 \index{environment variables!{\$#1}}% $
Fred Drake0ee9f721998-03-12 06:41:40 +0000750}
Fred Drake24340ea1998-04-28 18:30:34 +0000751\newcommand{\makevar}[1]{#1} % variable in a Makefile
752\newcommand{\character}[1]{\samp{#1}}
Fred Drake0ee9f721998-03-12 06:41:40 +0000753
Fred Drake6659c301998-03-03 22:02:19 +0000754% constants defined in Python modules or C headers, not language constants:
Fred Drake24340ea1998-04-28 18:30:34 +0000755\newcommand{\constant}[1]{\code{#1}} % manifest constant, not syntactic
Fred Drake6659c301998-03-03 22:02:19 +0000756
757\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
758\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
759\newcommand{\program}[1]{\strong{#1}}
760
761
762% Deprecation stuff.
763% Should be extended to allow an index / list of deprecated stuff. But
764% there's a lot of stuff that needs to be done to make that automatable.
765%
766% First parameter is the release number that deprecates the feature, the
767% second is the action the should be taken by users of the feature.
768%
769% Example:
Fred Drake24340ea1998-04-28 18:30:34 +0000770% \deprecated{1.5.1}{Use \method{frobnicate()} instead.}
Fred Drake6659c301998-03-03 22:02:19 +0000771%
772\newcommand{\deprecated}[2]{%
773 \strong{Deprecated since release #1.} #2\par}
774
Fred Drakeaf958c71998-07-27 20:32:33 +0000775% New stuff.
776% This should be used to mark things which have been added to the
777% development tree but that aren't in the release, but are documented.
778% This allows release of documentation that already includes updated
Fred Drake2116d981999-02-02 18:02:48 +0000779% descriptions. Place at end of descriptor environment.
Fred Drakeaf958c71998-07-27 20:32:33 +0000780%
781% Example:
782% \versionadded{1.5.2}
783%
784\newcommand{\versionadded}[1]{%
Fred Drake2116d981999-02-02 18:02:48 +0000785 { New in version #1. }}
Fred Drakeaf958c71998-07-27 20:32:33 +0000786\newcommand{\versionchanged}[1]{%
Fred Drake2116d981999-02-02 18:02:48 +0000787 { Changed in version #1. }}
Fred Drake6659c301998-03-03 22:02:19 +0000788
Fred Drakeaf958c71998-07-27 20:32:33 +0000789
790% Tables.
791%
Fred Drake6659c301998-03-03 22:02:19 +0000792\newenvironment{tableii}[4]{%
793 \begin{center}%
794 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
Fred Drakeee601911998-04-11 20:53:03 +0000795 \begin{tabular}{#1}\strong{#3}&\strong{#4} \\ \hline%
Fred Drake6659c301998-03-03 22:02:19 +0000796}{%
Fred Drake6659c301998-03-03 22:02:19 +0000797 \end{tabular}%
798 \end{center}%
799}
800
801\newenvironment{tableiii}[5]{%
802 \begin{center}%
803 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
Fred Drakeee601911998-04-11 20:53:03 +0000804 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\ \hline%
Fred Drake6659c301998-03-03 22:02:19 +0000805}{%
Fred Drake6659c301998-03-03 22:02:19 +0000806 \end{tabular}%
807 \end{center}%
808}
809
Fred Drake30e52651998-07-24 22:11:29 +0000810\newenvironment{tableiv}[6]{%
811 \begin{center}%
812 \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
813 \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6} \\%
814 \hline%
815}{%
816 \end{tabular}%
817 \end{center}%
818}
819
Fred Drake24340ea1998-04-28 18:30:34 +0000820% Cross-referencing (AMK, new impl. FLD)
Fred Drake6659c301998-03-03 22:02:19 +0000821% Sample usage:
822% \begin{seealso}
823% \seemodule{rand}{Uniform random number generator}; % Module xref
824% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +0000825%
826% % A funky case: module name contains '_'; have to supply an optional key
827% \seemodule[copyreg]{copy_reg}{pickle interface constructor registration}
828%
Fred Drake6659c301998-03-03 22:02:19 +0000829% \end{seealso}
830
Fred Drake1c8d0e01998-03-07 05:29:15 +0000831\@ifundefined{pdfannotlink}{%
Fred Drake24340ea1998-04-28 18:30:34 +0000832 \newcommand{\py@seemodule}[3][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000833 \par%
Fred Drake24340ea1998-04-28 18:30:34 +0000834 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
835 \ref{module-\py@modulekey}:\quad %
Fred Drakeebcb6581998-03-06 21:25:17 +0000836 Module \module{#2}%
837 \quad (#3)%
838 }
Fred Drake24340ea1998-04-28 18:30:34 +0000839}{\newcommand{\py@seemodule}[3][\py@modulebadkey]{%
Fred Drakeda943741999-01-13 17:09:06 +0000840 \par%
Fred Drake24340ea1998-04-28 18:30:34 +0000841 \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
842 \ref{module-\py@modulekey}:\quad %
Fred Drakeaa2aea01999-01-27 17:37:36 +0000843 \py@linkToName{label-module-\py@modulekey}{ Module \module{#2} }
Fred Drakeebcb6581998-03-06 21:25:17 +0000844 \quad (#3)%
845 }
846}
Fred Drake6659c301998-03-03 22:02:19 +0000847\newenvironment{seealso}[0]{
Fred Drake9466b9a1999-03-18 16:18:27 +0000848 \par
Fred Drake6659c301998-03-03 22:02:19 +0000849 \strong{See Also:}\par
Fred Drake6659c301998-03-03 22:02:19 +0000850 \def\seetext##1{\par{##1}}
Fred Drake24340ea1998-04-28 18:30:34 +0000851 \let\seemodule=\py@seemodule
Fred Drake6659c301998-03-03 22:02:19 +0000852}{\par}
853
854
Fred Drakeaf958c71998-07-27 20:32:33 +0000855% Allow the Python release number to be specified independently of the
Fred Drake6659c301998-03-03 22:02:19 +0000856% \date{}. This allows the date to reflect the document's date and
857% release to specify the Python release that is documented.
858%
Fred Drake24340ea1998-04-28 18:30:34 +0000859\newcommand{\py@release}{}
Fred Drake6659c301998-03-03 22:02:19 +0000860\newcommand{\version}{}
861\newcommand{\releasename}{Release}
862\newcommand{\release}[1]{%
Fred Drake24340ea1998-04-28 18:30:34 +0000863 \renewcommand{\py@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +0000864 \renewcommand{\version}{#1}}
865
866% Allow specification of the author's address separately from the
867% author's name. This can be used to format them differently, which
868% is a good thing.
869%
Fred Drake24340ea1998-04-28 18:30:34 +0000870\newcommand{\py@authoraddress}{}
871\newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress}{#1}}
Fred Drake6df93ef1998-05-14 20:56:31 +0000872\let\developersaddress=\authoraddress
873\let\developer=\author
874\let\developers=\author
Fred Drake6659c301998-03-03 22:02:19 +0000875
Fred Drake6659c301998-03-03 22:02:19 +0000876% This sets up the fancy chapter headings that make the documents look
877% at least a little better than the usual LaTeX output.
878%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000879\@ifundefined{ChTitleVar}{}{
Fred Drake24340ea1998-04-28 18:30:34 +0000880 \ChNameVar{\raggedleft\normalsize\py@HeaderFamily}
881 \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily}
882 \ChTitleVar{\raggedleft \rm\Huge\py@HeaderFamily}
Fred Drake6659c301998-03-03 22:02:19 +0000883 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000884 \def\@makechapterhead#1{%
885 {\parindent \z@ \raggedright \normalfont
886 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +0000887 \DOCH
888 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +0000889 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +0000890 \DOTI{#1}
891 }
892 }
Fred Drake6659c301998-03-03 22:02:19 +0000893}
894
Fred Drake3bf78651998-05-20 17:42:17 +0000895
896% Definition lists; requested by AMK for HOWTO documents. Probably useful
897% elsewhere as well, so keep in in the general style support.
898%
899\newenvironment{definitions}{%
900 \begin{description}%
Fred Drakef9acc591998-09-09 15:27:43 +0000901 \def\term##1{\item[##1]\mbox{}\\*[0mm]}
Fred Drake3bf78651998-05-20 17:42:17 +0000902}{%
903 \end{description}%
904}
905
Fred Drake6659c301998-03-03 22:02:19 +0000906% Tell TeX about pathological hyphenation cases:
907\hyphenation{Base-HTTP-Re-quest-Hand-ler}