blob: ad3e4a76aae5a5a098dc1b9ccf156951052effa4 [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
231%
232% This is the old hack, which didn't work with 2e.
233% You should not need this since the rest of the documentation is now
234% LaTeX2e-only.
235%
236%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
237%\catcode`\_=12
238%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
239
240
241
242%% Lots of index-entry generation support.
243
244% Command to wrap around stuff that refers to function / module /
245% attribute names in the index. Default behavior: like \code{}. To
246% just keep the index entries in the roman font, uncomment the second
247% definition to use instead; it matches O'Reilly style more.
248%
249\newcommand{\idxcode}[1]{\codefont{#1}}
250%\renewcommand{\idxcode}[1]{#1}
251
252% Command to generate two index entries (using subentries)
253\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
254
255% And three entries (using only one level of subentries)
256\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
257
258% And four (again, using only one level of subentries)
259\newcommand{\indexiv}[4]{
260\index{#1!#2 #3 #4}
261\index{#2!#3 #4, #1}
262\index{#3!#4, #1 #2}
263\index{#4!#1 #2 #3}
264}
265
266% Command to generate a reference to a function, statement, keyword,
267% operator.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000268\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
269\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
270\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000271\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drake2351c801998-04-02 18:48:32 +0000272\newcommand{\bifuncindex}[1]{\withsubitem{(built-in function)}{\ttindex{#1()}}}
Fred Drake6659c301998-03-03 22:02:19 +0000273
274% Add an index entry for a module
Fred Drake1c8d0e01998-03-07 05:29:15 +0000275\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake6659c301998-03-03 22:02:19 +0000276\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
277\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
278\newcommand{\refexmodindex}[1]{\refmodule{#1}{extension }}
279\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
280
281% support for the module index
Fred Drakeb390daf1998-03-09 16:35:36 +0000282\newif\if@UseModuleIndex
283\@UseModuleIndexfalse
284
Fred Drakeb390daf1998-03-09 16:35:36 +0000285% Fix the theindex environment to add an entry to the Table of
286% Contents; this is much nicer than just having to jump to the end of
287% the book and flip around, especially with multiple indexes.
288%
289\let\OldTheindex=\theindex
290\renewcommand{\theindex}{
291 \cleardoublepage
292 \OldTheindex
293 \addcontentsline{toc}{chapter}{\indexname}
Fred Drakeb390daf1998-03-09 16:35:36 +0000294}
295
Fred Drakeb390daf1998-03-09 16:35:36 +0000296\newcommand{\makemodindex}{
297 \newwrite\modindexfile
298 \openout\modindexfile=mod\jobname.idx
299 \@UseModuleIndextrue
300}
301
Fred Drake0ee9f721998-03-12 06:41:40 +0000302% Add the defining entry for a module
303\newcommand{\@modindex}[2]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000304 \global\def\@thismodule{#1}
305 \setindexsubitem{(in module #1)}%
Fred Drake0ee9f721998-03-12 06:41:40 +0000306 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
307 \if@UseModuleIndex%
308 \write\modindexfile{\protect\indexentry{#1@{\tt #1}}{\thepage}}%
309 \fi%
310}
311
Fred Drake6659c301998-03-03 22:02:19 +0000312% built-in & Python modules in the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000313\newcommand{\bimodindex}[1]{\@modindex{#1}{built-in }}
314\newcommand{\stmodindex}[1]{\@modindex{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000315
316% Python & extension modules outside the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000317\newcommand{\modindex}[1]{\@modindex{#1}{}}
318\newcommand{\exmodindex}[1]{\@modindex{#1}{extension }}
Fred Drake6659c301998-03-03 22:02:19 +0000319
320% Additional string for an index entry
Fred Drake1c8d0e01998-03-07 05:29:15 +0000321\newcommand{\index@subitem}{}
322\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
323\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Fred Drake6659c301998-03-03 22:02:19 +0000324
Fred Drake0ee9f721998-03-12 06:41:40 +0000325\newcommand{\withsubitem}[2]{%
326 \begingroup%
327 \def\index@subitem{#1}#2%
328 \endgroup%
329}
Fred Drake6659c301998-03-03 22:02:19 +0000330
331% {fulllineitems} is used in one place in libregex.tex, but is really for
332% internal use in this file.
333%
334\newenvironment{fulllineitems}{
335 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
336 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
337 \itemsep -\parsep
338 \let\makelabel=\itemnewline}
339}{\end{list}}
340
Fred Drake6cb71491998-03-27 05:22:53 +0000341% \optional is mostly for use in the arguments parameters to the various
342% {*desc} environments defined below, but may be used elsewhere. Known to
343% be used in the debugger chapter.
Fred Drake6659c301998-03-03 22:02:19 +0000344\newcommand{\optional}[1]{%
345 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
346
Fred Drake6cb71491998-03-27 05:22:53 +0000347% C functions ------------------------------------------------------------
348% \begin{cfuncdesc}{type}{name}{arglist}
349\newenvironment{cfuncdesc}[3]{
350 \begin{fulllineitems}
351 \item[\code{#1 \bfcode{#2}(\varvars{#3})}\index{#2@{\idxcode{#2()}}}]
352}{\end{fulllineitems}}
353
354% C variables ------------------------------------------------------------
355% \begin{cvardesc}{type}{name}
356\newenvironment{cvardesc}[2]{
357 \begin{fulllineitems}
358 \item[\code{#1 \bfcode{#2}}\index{#2@{\idxcode{#2}}}]
359}{\end{fulllineitems}}
360
361% C data types -----------------------------------------------------------
362% \begin{ctypedesc}{typedef name}
363\newenvironment{ctypedesc}[1]{
364 \begin{fulllineitems}
365 \item[\bfcode{#1}\ttindex{#1}]
366}{\end{fulllineitems}}
367
368% simple functions (not methods) -----------------------------------------
369% \begin{funcdesc}{name}{args}
370\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
371\newenvironment{funcdesc}[2]{
372 \begin{fulllineitems}
373 \funcline{#1}{#2}
374}{\end{fulllineitems}}
375
Fred Drake6659c301998-03-03 22:02:19 +0000376% similar to {funcdesc}, but doesn't add to the index
377\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
Fred Drake6cb71491998-03-27 05:22:53 +0000378\newenvironment{funcdescni}[2]{
379 \begin{fulllineitems}
380 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000381}{\end{fulllineitems}}
382
Fred Drake6cb71491998-03-27 05:22:53 +0000383% classes ----------------------------------------------------------------
384% \begin{classdesc}{name}{constructor args}
385\newenvironment{classdesc}[2]{
386 \global\def\@thisclass{#1}
387 \begin{fulllineitems}
388 \item[\code{\bfcode{#1}(\varvars{#2})}%
389 \withsubitem{(class in \@thismodule)}{\ttindex{#1}}]
390 \def\baseclasses##1{}
Fred Drake6659c301998-03-03 22:02:19 +0000391}{\end{fulllineitems}}
392
Fred Drake6cb71491998-03-27 05:22:53 +0000393
394\newcommand{\@classbadkey}{--bad current class--}
395\let\@classbadkey=\@undefined
396
397% object method ----------------------------------------------------------
398% \begin{methoddesc}[classname]{methodname}{args}
399\newcommand{\methodline}[3][\@classbadkey]{
400 \methodlineni{#2}{#3}
401 \ifx#1\@undefined
402 \withsubitem{(\@thisclass\ method)}{\ttindex{#2()}}
403 \else
404 \withsubitem{(#1 method)}{\ttindex{#2()}}
405 \fi
406}
407\newenvironment{methoddesc}[3][\@classbadkey]{
408 \begin{fulllineitems}
409 \ifx#1\@undefined
410 \methodline{#2}{#3}
411 \else
412 \def\@thisclass{#1}
413 \methodline[#1]{#2}{#3}
414 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000415}{\end{fulllineitems}}
416
Fred Drake6cb71491998-03-27 05:22:53 +0000417% similar to {methoddesc}, but doesn't add to the index
418% (never actually uses the optional argument)
419\newcommand{\methodlineni}[3][\@classbadkey]{%
420 \item[\code{\bfcode{#2}(\varvars{#3})}]}
421\newenvironment{methoddescni}[3][\@classbadkey]{
422 \begin{fulllineitems}
423 \methodlineni{#2}{#3}
424}{\end{fulllineitems}}
425
426% object data attribute --------------------------------------------------
427% \begin{memberdesc}[classname]{membername}
428\newcommand{\memberline}[2][\@classbadkey]{%
429 \ifx#1\@undefined
430 \memberlineni{#2}
431 \withsubitem{(\@thisclass\ attribute)}{\ttindex{#2()}}
432 \else
433 \memberlineni{#2}
434 \withsubitem{(#1 attribute)}{\ttindex{#2()}}
435 \fi
436}
437\newenvironment{memberdesc}[2][\@classbadkey]{
438 \begin{fulllineitems}
439 \ifx#1\@undefined
440 \memberline{#2}
441 \else
442 \def\@thisclass{#1}
443 \memberline[#1]{#2}
444 \fi
445}{\end{fulllineitems}}
446
447% similar to {memberdesc}, but doesn't add to the index
448% (never actually uses the optional argument)
449\newcommand{\memberlineni}[2][\@classbadkey]{\item[\bfcode{#2}]}
450\newenvironment{memberdescni}[2][\@classbadkey]{
451 \begin{fulllineitems}
452 \memberlineni{#2}
453}{\end{fulllineitems}}
454
455% For exceptions: --------------------------------------------------------
456% \begin{excdesc}{name}
457% -- need support for constructor; maybe use optional parameter?
458\newenvironment{excdesc}[1]{
459 \begin{fulllineitems}
460 \item[\bfcode{#1}\ttindex{#1}]
461}{\end{fulllineitems}}
462
463% Module data or constants: ----------------------------------------------
464% \begin{datadesc}{name}
Fred Drake6659c301998-03-03 22:02:19 +0000465\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drake6cb71491998-03-27 05:22:53 +0000466\newenvironment{datadesc}[1]{
467 \begin{fulllineitems}
468 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000469}{\end{fulllineitems}}
470
471% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000472\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
473\newenvironment{datadescni}[1]{
474 \begin{fulllineitems}
475 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000476}{\end{fulllineitems}}
477
Fred Drake6cb71491998-03-27 05:22:53 +0000478% bytecode instruction ---------------------------------------------------
479% \begin{opcodedesc}{name}{var}
480% -- {var} may be {}
481\newenvironment{opcodedesc}[2]{
482 \begin{fulllineitems}
483 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000484}{\end{fulllineitems}}
485
486
487\let\nodename=\label
488
Fred Drake55730311998-03-25 15:41:23 +0000489\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
490
Fred Drake6659c301998-03-03 22:02:19 +0000491% For these commands, use \command{} to get the typography right, not
492% {\command}. This works better with the texinfo translation.
493\newcommand{\ABC}{{\sc abc}}
494\newcommand{\UNIX}{{\sc Unix}}
495\newcommand{\POSIX}{POSIX}
496\newcommand{\ASCII}{{\sc ascii}}
497\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
498\newcommand{\C}{C}
499\newcommand{\EOF}{{\sc eof}}
Fred Drake55730311998-03-25 15:41:23 +0000500\newcommand{\NULL}{\sectcode{NULL}}
Fred Drake6659c301998-03-03 22:02:19 +0000501
502% code is the most difficult one...
Fred Drake1c8d0e01998-03-07 05:29:15 +0000503\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 +0000504\mbox{\codefont{#1}}}}
505
506\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
507\newcommand{\kbd}[1]{\mbox{\tt #1}}
508\newcommand{\key}[1]{\mbox{\tt #1}}
509\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
510% This weird definition of \var{} allows it to always appear in roman
511% italics, and won't get funky in code fragments when we play around
512% with fonts.
513\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
514\renewcommand{\emph}[1]{{\em #1\/}}
515\newcommand{\dfn}[1]{\emph{#1}}
516\newcommand{\strong}[1]{{\bf #1}}
517% let's experiment with a new font:
Fred Drake0ee9f721998-03-12 06:41:40 +0000518\newcommand{\file}[1]{`{\small\textsf{#1}}'}
Fred Drake6659c301998-03-03 22:02:19 +0000519
520% Use this def/redef approach for \url{} since hyperref defined this already,
521% but only if we actually used hyperref:
Fred Drake6cb71491998-03-27 05:22:53 +0000522\@ifundefined{pdfannotlink}{
523 \newcommand{\pythonurl}[1]{\mbox{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000524}{
525 \newcommand{\pythonurl}[1]{{%
526 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
527 \LinkColor% color of the link text
Fred Drake6cb71491998-03-27 05:22:53 +0000528 {\small\textsf{#1}}%
Fred Drake6659c301998-03-03 22:02:19 +0000529 \NormalColor% Turn it back off; these are declarative
530 \pdfendlink}% and don't appear bound to the current
531 }% formatting "box".
532}
533\let\url=\pythonurl
Fred Drake0ee9f721998-03-12 06:41:40 +0000534\newcommand{\email}[1]{{\small\textsf{#1}}}
Fred Drake454a4fb1998-04-01 22:20:14 +0000535\newcommand{\newsgroup}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000536
537\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
538
539\newif\iftexi\texifalse
540\newif\iflatex\latextrue
541
542% These should be used for all references to identifiers which are
543% used to refer to instances of specific language constructs. See the
544% names for specific semantic assignments.
545%
546% For now, don't do anything really fancy with them; just use them as
547% logical markup. This might change in the future.
548%
Fred Drake55730311998-03-25 15:41:23 +0000549\let\module=\sectcode
550\let\keyword=\sectcode
551\let\exception=\sectcode
552\let\class=\sectcode
553\let\function=\sectcode
554\let\member=\sectcode
555\let\method=\sectcode
Fred Drake6659c301998-03-03 22:02:19 +0000556
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}}%
566 $\!\!\rfloor\!$%
567 }}
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}