blob: c58a55b2dff17566394350085e11626ed5736dd0 [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 Drake454a4fb1998-04-01 22:20:14 +00009% These packages can be used to add marginal annotations which indicate
10% index entries and labels; useful for reviewing this messy documentation!
11%
12%\RequirePackage{showkeys}
13%\RequirePackage{showidx}
14
Fred Drakec0b2e451998-03-25 14:53:43 +000015% for PDF output, use maximal compression & a lot of other stuff
16% (test for PDF recommended by Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov>)
17%
Fred Drake6cb71491998-03-27 05:22:53 +000018\newif\if@doing@page@targets
19\@doing@page@targetsfalse
20
Fred Drakec0b2e451998-03-25 14:53:43 +000021\ifx\pdfoutput\undefined\else\ifcase\pdfoutput
Fred Drake6659c301998-03-03 22:02:19 +000022 \let\LinkColor=\relax
23 \let\NormalColor=\relax
Fred Drakec0b2e451998-03-25 14:53:43 +000024\else
Fred Drake6659c301998-03-03 22:02:19 +000025 \input{pdfcolor}
26 \let\LinkColor=\NavyBlue
27 \let\NormalColor=\Black
28 \pdfcompresslevel=9
Fred Drakeebcb6581998-03-06 21:25:17 +000029 %
30 % This definition allows the entries in the page-view of the ToC to be
31 % active links. Some work, some don't.
32 %
Fred Drake6659c301998-03-03 22:02:19 +000033 \let\OldContentsline=\contentsline
34 \renewcommand{\contentsline}[3]{%
35 \OldContentsline{#1}{%
36 \pdfannotlink attr{/Border [0 0 0]} goto name{page.#3}%
37 \LinkColor#2\NormalColor%
38 \pdfendlink%
39 }{#3}%
40 }
Fred Drakeebcb6581998-03-06 21:25:17 +000041 %
42 % This is supposed to build the "outline" view of the document; it seems
43 % quite fragile. The breakages are the same as in the ToC.
44 %
45 \AtEndDocument{
Fred Drakec0b2e451998-03-25 14:53:43 +000046 \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
Fred Drakeebcb6581998-03-06 21:25:17 +000047 }
Fred Drake6659c301998-03-03 22:02:19 +000048 \let\OldLabel=\label
49 \renewcommand{\label}[1]{%
50 \OldLabel{#1}%
51 {\pdfdest name{label.#1} fit}%
52 }
53 % This stuff adds a page.# destination to every PDF page, where # has
54 % the same formatting as the displayed page number. This doesn't really
55 % help with the frontmatter, but does fine with the body.
56 %
57 % This is *heavily* based on the hyperref package.
58 %
Fred Drake1c8d0e01998-03-07 05:29:15 +000059 \def\@begindvi{%
60 \unvbox \@begindvibox
61 \@hyperfixhead
Fred Drake6659c301998-03-03 22:02:19 +000062 }
Fred Drake1c8d0e01998-03-07 05:29:15 +000063 \def\@hyperfixhead{%
64 \let\H@old@thehead\@thehead
Fred Drake6cb71491998-03-27 05:22:53 +000065 \gdef\@foo{\if@doing@page@targets\pdfdest name{page.\thepage} fit\fi}%
Fred Drake1c8d0e01998-03-07 05:29:15 +000066 \expandafter\ifx\expandafter\@empty\H@old@thehead
67 \def\H@old@thehead{\hfil}\fi
68 \def\@thehead{\@foo\relax\H@old@thehead}%
Fred Drake6659c301998-03-03 22:02:19 +000069 }
Fred Drakec0b2e451998-03-25 14:53:43 +000070\fi\fi
Fred Drake6659c301998-03-03 22:02:19 +000071
72% Increase printable page size (copied from fullpage.sty)
73\topmargin 0pt
74\advance \topmargin by -\headheight
75\advance \topmargin by -\headsep
76
77% attempt to work a little better for A4 users
Fred Drake1c8d0e01998-03-07 05:29:15 +000078\@ifundefined{paperheight}{
Fred Drake6659c301998-03-03 22:02:19 +000079 \textheight 9in
80}{
81 \textheight \paperheight
82 \advance\textheight by -2in
83}
84
85\oddsidemargin 0pt
86\evensidemargin \oddsidemargin
87\marginparwidth 0.5in
88
Fred Drake1c8d0e01998-03-07 05:29:15 +000089\@ifundefined{paperwidth}{
Fred Drake6659c301998-03-03 22:02:19 +000090 \textwidth 6.5in
91}{
92 \textwidth \paperwidth
93 \advance\textwidth by -2in
94}
95
96
97% Style parameters and macros used by most documents here
98\raggedbottom
99\sloppy
100\parindent = 0mm
101\parskip = 2mm
102\hbadness = 5000 % don't print trivial gripes
103
104\pagestyle{empty} % start this way; change for
105\pagenumbering{roman} % ToC & chapters
106\setcounter{secnumdepth}{1}
107
108% Use this to set the font family for headers and other decor:
109\newcommand{\HeaderFamily}{\sffamily}
110
111% Redefine the 'normal' header/footer style when using "fancyhdr" package:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000112\@ifundefined{fancyhf}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000113 % Use \pagestyle{normal} as the primary pagestyle for text.
114 \fancypagestyle{normal}{
115 \fancyhf{}
116 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
117 \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}
118 \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}
119 \renewcommand{\headrulewidth}{0pt}
120 \renewcommand{\footrulewidth}{0.4pt}
121 }
122 % Update the plain style so we get the page number & footer line,
123 % but not a chapter or section title. This is to keep the first
124 % page of a chapter and the blank page between chapters `clean.'
125 \fancypagestyle{plain}{
126 \fancyhf{}
127 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
128 \renewcommand{\headrulewidth}{0pt}
129 \renewcommand{\footrulewidth}{0.4pt}
130 }
131 % Redefine \cleardoublepage so that the blank page between chapters
132 % gets the plain style and not the fancy style. This is described
133 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000134 \@ifundefined{chapter}{}{
Fred Drake28f13911998-03-04 21:47:59 +0000135 \renewcommand{\cleardoublepage}{
Fred Drake1c8d0e01998-03-07 05:29:15 +0000136 \clearpage\if@openright \ifodd\c@page\else
Fred Drake28f13911998-03-04 21:47:59 +0000137 \hbox{}
138 \thispagestyle{plain}
139 \newpage
Fred Drake1c8d0e01998-03-07 05:29:15 +0000140 \if@twocolumn\hbox{}\newpage\fi\fi\fi
Fred Drake28f13911998-03-04 21:47:59 +0000141 }
142 }
Fred Drake6659c301998-03-03 22:02:19 +0000143}
144
145% old code font selections:
146\let\codefont=\tt
147\let\sectcodefont=\tt
148
149% (Haven't found a new one that gets <, >, and _ right without being
150% monospaced.)
151
152
153% This sets up the {verbatim} environment to be indented and a minipage,
154% and to have all the other mostly nice properties that we want for
155% code samples.
156
157% Variable used by begin code command
158\newlength{\codewidth}
159
160\newcommand{\examplevspace}{2mm}
161\newcommand{\exampleindent}{1cm}
162
163\let\OldVerbatim=\verbatim
164\let\OldEndVerbatim=\endverbatim
165\renewcommand{\verbatim}{%
166 \begingroup%
167 \setlength{\parindent}\exampleindent%
168 % Calculate the text width for the minipage:
169 \setlength{\codewidth}{\linewidth}%
170 \addtolength{\codewidth}{-\parindent}%
171 %
172 \par%
173 \vspace\examplevspace%
174 \indent%
175 \begin{minipage}[t]{\codewidth}%
176 \small%
177 \OldVerbatim%
178}
179\renewcommand{\endverbatim}{%
180 \OldEndVerbatim%
181 \end{minipage}%
182 \endgroup%
183}
184
Fred Drake6cb71491998-03-27 05:22:53 +0000185\newcommand{\reset@python}{
186 \global\let\@thisclass=\@undefined
187 \global\let\@thismodule=\@undefined
188}
189\reset@python
190
191% Augment the sectioning commands used to get our own font family in place,
192% and reset some internal data items:
193\renewcommand{\section}{\reset@python%
194 \@startsection {section}{1}{\z@}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000195 {-3.5ex \@plus -1ex \@minus -.2ex}%
196 {2.3ex \@plus.2ex}%
197 {\reset@font\Large\HeaderFamily}}
198\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
199 {-3.25ex\@plus -1ex \@minus -.2ex}%
200 {1.5ex \@plus .2ex}%
201 {\reset@font\large\HeaderFamily}}
202\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
203 {-3.25ex\@plus -1ex \@minus -.2ex}%
204 {1.5ex \@plus .2ex}%
205 {\reset@font\normalsize\HeaderFamily}}
206\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
207 {3.25ex \@plus1ex \@minus.2ex}%
Fred Drake6659c301998-03-03 22:02:19 +0000208 {-1em}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000209 {\reset@font\normalsize\HeaderFamily}}
210\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
211 {3.25ex \@plus1ex \@minus .2ex}%
Fred Drake6659c301998-03-03 22:02:19 +0000212 {-1em}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000213 {\reset@font\normalsize\HeaderFamily}}
Fred Drake6659c301998-03-03 22:02:19 +0000214
215
216% Underscore hack (only act like subscript operator if in math mode)
217%
218% The following is due to Mark Wooding (the old version didn't work with
219% Latex 2e.
220
221\DeclareRobustCommand\hackscore{%
222 \ifmmode_\else\textunderscore\fi%
223}
224\begingroup
225\catcode`\_\active
226\def\next{%
227 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
228}
229\expandafter\endgroup\next
230
Fred Drake6659c301998-03-03 22:02:19 +0000231
232%% Lots of index-entry generation support.
233
234% Command to wrap around stuff that refers to function / module /
235% attribute names in the index. Default behavior: like \code{}. To
236% just keep the index entries in the roman font, uncomment the second
237% definition to use instead; it matches O'Reilly style more.
238%
239\newcommand{\idxcode}[1]{\codefont{#1}}
240%\renewcommand{\idxcode}[1]{#1}
241
242% Command to generate two index entries (using subentries)
243\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
244
245% And three entries (using only one level of subentries)
246\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
247
248% And four (again, using only one level of subentries)
249\newcommand{\indexiv}[4]{
250\index{#1!#2 #3 #4}
251\index{#2!#3 #4, #1}
252\index{#3!#4, #1 #2}
253\index{#4!#1 #2 #3}
254}
255
256% Command to generate a reference to a function, statement, keyword,
257% operator.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000258\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
259\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
260\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000261\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drake2351c801998-04-02 18:48:32 +0000262\newcommand{\bifuncindex}[1]{\withsubitem{(built-in function)}{\ttindex{#1()}}}
Fred Drake6659c301998-03-03 22:02:19 +0000263
264% Add an index entry for a module
Fred Drake1c8d0e01998-03-07 05:29:15 +0000265\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake6659c301998-03-03 22:02:19 +0000266\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
267\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
268\newcommand{\refexmodindex}[1]{\refmodule{#1}{extension }}
269\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
270
271% support for the module index
Fred Drakeb390daf1998-03-09 16:35:36 +0000272\newif\if@UseModuleIndex
273\@UseModuleIndexfalse
274
Fred Drakeb390daf1998-03-09 16:35:36 +0000275% Fix the theindex environment to add an entry to the Table of
276% Contents; this is much nicer than just having to jump to the end of
277% the book and flip around, especially with multiple indexes.
278%
279\let\OldTheindex=\theindex
280\renewcommand{\theindex}{
281 \cleardoublepage
282 \OldTheindex
283 \addcontentsline{toc}{chapter}{\indexname}
Fred Drakeb390daf1998-03-09 16:35:36 +0000284}
285
Fred Drakeb390daf1998-03-09 16:35:36 +0000286\newcommand{\makemodindex}{
287 \newwrite\modindexfile
288 \openout\modindexfile=mod\jobname.idx
289 \@UseModuleIndextrue
290}
291
Fred Drake0ee9f721998-03-12 06:41:40 +0000292% Add the defining entry for a module
293\newcommand{\@modindex}[2]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000294 \global\def\@thismodule{#1}
295 \setindexsubitem{(in module #1)}%
Fred Drake0ee9f721998-03-12 06:41:40 +0000296 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
297 \if@UseModuleIndex%
298 \write\modindexfile{\protect\indexentry{#1@{\tt #1}}{\thepage}}%
299 \fi%
300}
301
Fred Drake6659c301998-03-03 22:02:19 +0000302% built-in & Python modules in the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000303\newcommand{\bimodindex}[1]{\@modindex{#1}{built-in }}
304\newcommand{\stmodindex}[1]{\@modindex{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000305
306% Python & extension modules outside the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000307\newcommand{\modindex}[1]{\@modindex{#1}{}}
308\newcommand{\exmodindex}[1]{\@modindex{#1}{extension }}
Fred Drake6659c301998-03-03 22:02:19 +0000309
310% Additional string for an index entry
Fred Drake1c8d0e01998-03-07 05:29:15 +0000311\newcommand{\index@subitem}{}
312\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
313\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Fred Drake6659c301998-03-03 22:02:19 +0000314
Fred Drake0ee9f721998-03-12 06:41:40 +0000315\newcommand{\withsubitem}[2]{%
316 \begingroup%
317 \def\index@subitem{#1}#2%
318 \endgroup%
319}
Fred Drake6659c301998-03-03 22:02:19 +0000320
Fred Drake53714971998-04-02 22:33:16 +0000321
322% Now for a lot of semantically-loaded environments that do a ton of magical
323% things to get the right formatting and index entries for the stuff in
324% Python modules and C API.
325
326
Fred Drake6659c301998-03-03 22:02:19 +0000327% {fulllineitems} is used in one place in libregex.tex, but is really for
328% internal use in this file.
329%
330\newenvironment{fulllineitems}{
331 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
332 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
333 \itemsep -\parsep
334 \let\makelabel=\itemnewline}
335}{\end{list}}
336
Fred Drake6cb71491998-03-27 05:22:53 +0000337% \optional is mostly for use in the arguments parameters to the various
338% {*desc} environments defined below, but may be used elsewhere. Known to
339% be used in the debugger chapter.
Fred Drake6659c301998-03-03 22:02:19 +0000340\newcommand{\optional}[1]{%
341 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
342
Fred Drake6cb71491998-03-27 05:22:53 +0000343% C functions ------------------------------------------------------------
344% \begin{cfuncdesc}{type}{name}{arglist}
345\newenvironment{cfuncdesc}[3]{
346 \begin{fulllineitems}
347 \item[\code{#1 \bfcode{#2}(\varvars{#3})}\index{#2@{\idxcode{#2()}}}]
348}{\end{fulllineitems}}
349
350% C variables ------------------------------------------------------------
351% \begin{cvardesc}{type}{name}
352\newenvironment{cvardesc}[2]{
353 \begin{fulllineitems}
354 \item[\code{#1 \bfcode{#2}}\index{#2@{\idxcode{#2}}}]
355}{\end{fulllineitems}}
356
357% C data types -----------------------------------------------------------
358% \begin{ctypedesc}{typedef name}
359\newenvironment{ctypedesc}[1]{
360 \begin{fulllineitems}
361 \item[\bfcode{#1}\ttindex{#1}]
362}{\end{fulllineitems}}
363
364% simple functions (not methods) -----------------------------------------
365% \begin{funcdesc}{name}{args}
366\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
367\newenvironment{funcdesc}[2]{
368 \begin{fulllineitems}
369 \funcline{#1}{#2}
370}{\end{fulllineitems}}
371
Fred Drake6659c301998-03-03 22:02:19 +0000372% similar to {funcdesc}, but doesn't add to the index
373\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
Fred Drake6cb71491998-03-27 05:22:53 +0000374\newenvironment{funcdescni}[2]{
375 \begin{fulllineitems}
376 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000377}{\end{fulllineitems}}
378
Fred Drake6cb71491998-03-27 05:22:53 +0000379% classes ----------------------------------------------------------------
380% \begin{classdesc}{name}{constructor args}
381\newenvironment{classdesc}[2]{
382 \global\def\@thisclass{#1}
383 \begin{fulllineitems}
384 \item[\code{\bfcode{#1}(\varvars{#2})}%
385 \withsubitem{(class in \@thismodule)}{\ttindex{#1}}]
386 \def\baseclasses##1{}
Fred Drake6659c301998-03-03 22:02:19 +0000387}{\end{fulllineitems}}
388
Fred Drake6cb71491998-03-27 05:22:53 +0000389
390\newcommand{\@classbadkey}{--bad current class--}
391\let\@classbadkey=\@undefined
392
393% object method ----------------------------------------------------------
394% \begin{methoddesc}[classname]{methodname}{args}
395\newcommand{\methodline}[3][\@classbadkey]{
396 \methodlineni{#2}{#3}
397 \ifx#1\@undefined
398 \withsubitem{(\@thisclass\ method)}{\ttindex{#2()}}
399 \else
400 \withsubitem{(#1 method)}{\ttindex{#2()}}
401 \fi
402}
403\newenvironment{methoddesc}[3][\@classbadkey]{
404 \begin{fulllineitems}
405 \ifx#1\@undefined
406 \methodline{#2}{#3}
407 \else
408 \def\@thisclass{#1}
409 \methodline[#1]{#2}{#3}
410 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000411}{\end{fulllineitems}}
412
Fred Drake6cb71491998-03-27 05:22:53 +0000413% similar to {methoddesc}, but doesn't add to the index
414% (never actually uses the optional argument)
415\newcommand{\methodlineni}[3][\@classbadkey]{%
416 \item[\code{\bfcode{#2}(\varvars{#3})}]}
417\newenvironment{methoddescni}[3][\@classbadkey]{
418 \begin{fulllineitems}
419 \methodlineni{#2}{#3}
420}{\end{fulllineitems}}
421
422% object data attribute --------------------------------------------------
423% \begin{memberdesc}[classname]{membername}
424\newcommand{\memberline}[2][\@classbadkey]{%
425 \ifx#1\@undefined
426 \memberlineni{#2}
Fred Drake41565f61998-04-07 19:32:40 +0000427 \withsubitem{(\@thisclass\ attribute)}{\ttindex{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000428 \else
429 \memberlineni{#2}
Fred Drake41565f61998-04-07 19:32:40 +0000430 \withsubitem{(#1 attribute)}{\ttindex{#2}}
Fred Drake6cb71491998-03-27 05:22:53 +0000431 \fi
432}
433\newenvironment{memberdesc}[2][\@classbadkey]{
434 \begin{fulllineitems}
435 \ifx#1\@undefined
436 \memberline{#2}
437 \else
438 \def\@thisclass{#1}
439 \memberline[#1]{#2}
440 \fi
441}{\end{fulllineitems}}
442
443% similar to {memberdesc}, but doesn't add to the index
444% (never actually uses the optional argument)
445\newcommand{\memberlineni}[2][\@classbadkey]{\item[\bfcode{#2}]}
446\newenvironment{memberdescni}[2][\@classbadkey]{
447 \begin{fulllineitems}
448 \memberlineni{#2}
449}{\end{fulllineitems}}
450
451% For exceptions: --------------------------------------------------------
452% \begin{excdesc}{name}
453% -- need support for constructor; maybe use optional parameter?
454\newenvironment{excdesc}[1]{
455 \begin{fulllineitems}
456 \item[\bfcode{#1}\ttindex{#1}]
457}{\end{fulllineitems}}
458
459% Module data or constants: ----------------------------------------------
460% \begin{datadesc}{name}
Fred Drake6659c301998-03-03 22:02:19 +0000461\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drake6cb71491998-03-27 05:22:53 +0000462\newenvironment{datadesc}[1]{
463 \begin{fulllineitems}
464 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000465}{\end{fulllineitems}}
466
467% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000468\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
469\newenvironment{datadescni}[1]{
470 \begin{fulllineitems}
471 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000472}{\end{fulllineitems}}
473
Fred Drake6cb71491998-03-27 05:22:53 +0000474% bytecode instruction ---------------------------------------------------
475% \begin{opcodedesc}{name}{var}
476% -- {var} may be {}
477\newenvironment{opcodedesc}[2]{
478 \begin{fulllineitems}
479 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000480}{\end{fulllineitems}}
481
482
483\let\nodename=\label
484
Fred Drake55730311998-03-25 15:41:23 +0000485\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
486
Fred Drake6659c301998-03-03 22:02:19 +0000487% For these commands, use \command{} to get the typography right, not
488% {\command}. This works better with the texinfo translation.
489\newcommand{\ABC}{{\sc abc}}
490\newcommand{\UNIX}{{\sc Unix}}
491\newcommand{\POSIX}{POSIX}
492\newcommand{\ASCII}{{\sc ascii}}
493\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
494\newcommand{\C}{C}
495\newcommand{\EOF}{{\sc eof}}
Fred Drake55730311998-03-25 15:41:23 +0000496\newcommand{\NULL}{\sectcode{NULL}}
Fred Drake6659c301998-03-03 22:02:19 +0000497
Fred Drake53714971998-04-02 22:33:16 +0000498% Also for consistency: spell Python "Python", not "python"!
499
Fred Drake6659c301998-03-03 22:02:19 +0000500% code is the most difficult one...
Fred Drake1c8d0e01998-03-07 05:29:15 +0000501\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 Drake6659c301998-03-03 22:02:19 +0000502\mbox{\codefont{#1}}}}
503
504\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
505\newcommand{\kbd}[1]{\mbox{\tt #1}}
506\newcommand{\key}[1]{\mbox{\tt #1}}
507\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
508% This weird definition of \var{} allows it to always appear in roman
509% italics, and won't get funky in code fragments when we play around
510% with fonts.
511\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
512\renewcommand{\emph}[1]{{\em #1\/}}
513\newcommand{\dfn}[1]{\emph{#1}}
514\newcommand{\strong}[1]{{\bf #1}}
515% let's experiment with a new font:
Fred Drake0ee9f721998-03-12 06:41:40 +0000516\newcommand{\file}[1]{`{\small\textsf{#1}}'}
Fred Drake6659c301998-03-03 22:02:19 +0000517
518% Use this def/redef approach for \url{} since hyperref defined this already,
519% but only if we actually used hyperref:
Fred Drake6cb71491998-03-27 05:22:53 +0000520\@ifundefined{pdfannotlink}{
521 \newcommand{\pythonurl}[1]{\mbox{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000522}{
523 \newcommand{\pythonurl}[1]{{%
524 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
525 \LinkColor% color of the link text
Fred Drake6cb71491998-03-27 05:22:53 +0000526 {\small\textsf{#1}}%
Fred Drake6659c301998-03-03 22:02:19 +0000527 \NormalColor% Turn it back off; these are declarative
528 \pdfendlink}% and don't appear bound to the current
529 }% formatting "box".
530}
531\let\url=\pythonurl
Fred Drake0ee9f721998-03-12 06:41:40 +0000532\newcommand{\email}[1]{{\small\textsf{#1}}}
Fred Drake454a4fb1998-04-01 22:20:14 +0000533\newcommand{\newsgroup}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000534
535\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
536
537\newif\iftexi\texifalse
538\newif\iflatex\latextrue
539
540% These should be used for all references to identifiers which are
541% used to refer to instances of specific language constructs. See the
542% names for specific semantic assignments.
543%
544% For now, don't do anything really fancy with them; just use them as
545% logical markup. This might change in the future.
546%
Fred Drake55730311998-03-25 15:41:23 +0000547\let\module=\sectcode
548\let\keyword=\sectcode
549\let\exception=\sectcode
550\let\class=\sectcode
551\let\function=\sectcode
552\let\member=\sectcode
553\let\method=\sectcode
Fred Drake6659c301998-03-03 22:02:19 +0000554
Fred Drake53714971998-04-02 22:33:16 +0000555\newcommand{\pytype}[1]{#1} % built-in Python type
556
Fred Drake55730311998-03-25 15:41:23 +0000557\let\cfunction=\sectcode
558\let\ctype=\sectcode
559\let\cdata=\sectcode
Fred Drake6659c301998-03-03 22:02:19 +0000560
Fred Drake0ee9f721998-03-12 06:41:40 +0000561\newcommand{\mimetype}[1]{{\small\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000562% The \! is a "negative thin space" in math mode.
563\newcommand{\regexp}[1]{%
564 {\tiny$^{^\lceil}\!\!$%
565 {\normalsize\code{#1}}%
Fred Drake47cfd031998-04-03 21:22:31 +0000566 $\!\rfloor\!$%
Fred Drake94fac131998-03-12 19:37:03 +0000567 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000568\newcommand{\envvar}[1]{%
Fred Drake94fac131998-03-12 19:37:03 +0000569 \$#1% $ <-- bow to font-lock 3 times!
570 \index{#1@{\$#1}}% $
571 \index{environment variables!{\$#1}}% $
Fred Drake0ee9f721998-03-12 06:41:40 +0000572}
Fred Drakef14e2f81998-04-02 16:09:02 +0000573\newcommand{\makevar}[1]{#1}
Fred Drake0ee9f721998-03-12 06:41:40 +0000574\let\character=\samp
575
Fred Drake6659c301998-03-03 22:02:19 +0000576% constants defined in Python modules or C headers, not language constants:
Fred Drakef14e2f81998-04-02 16:09:02 +0000577\let\constant=\sectcode
Fred Drake6659c301998-03-03 22:02:19 +0000578
579\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
580\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
581\newcommand{\program}[1]{\strong{#1}}
582
583
584% Deprecation stuff.
585% Should be extended to allow an index / list of deprecated stuff. But
586% there's a lot of stuff that needs to be done to make that automatable.
587%
588% First parameter is the release number that deprecates the feature, the
589% second is the action the should be taken by users of the feature.
590%
591% Example:
592%
593% \deprecated {1.5.1}
594% {Use \method{frobnicate()} instead.}
595%
596\newcommand{\deprecated}[2]{%
597 \strong{Deprecated since release #1.} #2\par}
598
599
600\newenvironment{tableii}[4]{%
601 \begin{center}%
602 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
603 \begin{tabular}{#1}\hline \strong{#3}&\strong{#4} \\ \hline%
604}{%
605 \hline%
606 \end{tabular}%
607 \end{center}%
608}
609
610\newenvironment{tableiii}[5]{%
611 \begin{center}%
612 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
613 \begin{tabular}{#1}\hline \strong{#3}&\strong{#4}&\strong{#5} \\ \hline%
614}{%
615 \hline%
616 \end{tabular}%
617 \end{center}%
618}
619
620\newcommand{\itemnewline}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000621 \@tempdima\linewidth%
622 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
Fred Drake6659c301998-03-03 22:02:19 +0000623}
624
Fred Drake6659c301998-03-03 22:02:19 +0000625% Cross-referencing (AMK)
626% Sample usage:
627% \begin{seealso}
628% \seemodule{rand}{Uniform random number generator}; % Module xref
629% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +0000630%
631% % A funky case: module name contains '_'; have to supply an optional key
632% \seemodule[copyreg]{copy_reg}{pickle interface constructor registration}
633%
Fred Drake6659c301998-03-03 22:02:19 +0000634% \end{seealso}
635
Fred Drake1c8d0e01998-03-07 05:29:15 +0000636\newcommand{\@modulebadkey}{{--just-some-junk--}}
Fred Drakeebcb6581998-03-06 21:25:17 +0000637
Fred Drake1c8d0e01998-03-07 05:29:15 +0000638\@ifundefined{pdfannotlink}{%
639 \newcommand{\seemodule}[3][\@modulebadkey]{%
640 \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
641 \ref{module-\@modulekey}:\quad %
Fred Drakeebcb6581998-03-06 21:25:17 +0000642 Module \module{#2}%
643 \quad (#3)%
644 }
Fred Drake1c8d0e01998-03-07 05:29:15 +0000645}{\newcommand{\seemodule}[3][\@modulebadkey]{%
646 \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
647 \ref{module-\@modulekey}:\quad %
648 {\pdfannotlink attr{/Border [0 0 0]} goto name{label.module-\@modulekey}%
Fred Drakeebcb6581998-03-06 21:25:17 +0000649 \LinkColor Module \module{#2} \NormalColor%
650 \pdfendlink%
651 }%
652 \quad (#3)%
653 }
654}
Fred Drake6659c301998-03-03 22:02:19 +0000655\newenvironment{seealso}[0]{
656 \strong{See Also:}\par
Fred Drake6659c301998-03-03 22:02:19 +0000657 \def\seetext##1{\par{##1}}
658}{\par}
659
660
Fred Drake6659c301998-03-03 22:02:19 +0000661% Allow the release number to be specified independently of the
662% \date{}. This allows the date to reflect the document's date and
663% release to specify the Python release that is documented.
664%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000665\newcommand{\@release}{}
Fred Drake6659c301998-03-03 22:02:19 +0000666\newcommand{\version}{}
667\newcommand{\releasename}{Release}
668\newcommand{\release}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000669 \renewcommand{\@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +0000670 \renewcommand{\version}{#1}}
671
672% Allow specification of the author's address separately from the
673% author's name. This can be used to format them differently, which
674% is a good thing.
675%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000676\newcommand{\@authoraddress}{}
677\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000678
Fred Drake6659c301998-03-03 22:02:19 +0000679% This sets up the fancy chapter headings that make the documents look
680% at least a little better than the usual LaTeX output.
681%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000682\@ifundefined{ChTitleVar}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000683 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
684 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
685 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
686 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000687 \def\@makechapterhead#1{%
688 {\parindent \z@ \raggedright \normalfont
689 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +0000690 \DOCH
691 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +0000692 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +0000693 \DOTI{#1}
694 }
695 }
Fred Drake6659c301998-03-03 22:02:19 +0000696}
697
698% Tell TeX about pathological hyphenation cases:
699\hyphenation{Base-HTTP-Re-quest-Hand-ler}