blob: 9c262083e622c08a0aacc0cddf2b60cc9ff3837e [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 Drakec0b2e451998-03-25 14:53:43 +00009% for PDF output, use maximal compression & a lot of other stuff
10% (test for PDF recommended by Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov>)
11%
Fred Drake6cb71491998-03-27 05:22:53 +000012\newif\if@doing@page@targets
13\@doing@page@targetsfalse
14
Fred Drakec0b2e451998-03-25 14:53:43 +000015\ifx\pdfoutput\undefined\else\ifcase\pdfoutput
Fred Drake6659c301998-03-03 22:02:19 +000016 \let\LinkColor=\relax
17 \let\NormalColor=\relax
Fred Drakec0b2e451998-03-25 14:53:43 +000018\else
Fred Drake6659c301998-03-03 22:02:19 +000019 \input{pdfcolor}
20 \let\LinkColor=\NavyBlue
21 \let\NormalColor=\Black
22 \pdfcompresslevel=9
Fred Drakeebcb6581998-03-06 21:25:17 +000023 %
24 % This definition allows the entries in the page-view of the ToC to be
25 % active links. Some work, some don't.
26 %
Fred Drake6659c301998-03-03 22:02:19 +000027 \let\OldContentsline=\contentsline
28 \renewcommand{\contentsline}[3]{%
29 \OldContentsline{#1}{%
30 \pdfannotlink attr{/Border [0 0 0]} goto name{page.#3}%
31 \LinkColor#2\NormalColor%
32 \pdfendlink%
33 }{#3}%
34 }
Fred Drakeebcb6581998-03-06 21:25:17 +000035 %
36 % This is supposed to build the "outline" view of the document; it seems
37 % quite fragile. The breakages are the same as in the ToC.
38 %
39 \AtEndDocument{
Fred Drakec0b2e451998-03-25 14:53:43 +000040 \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
Fred Drakeebcb6581998-03-06 21:25:17 +000041 }
Fred Drake6659c301998-03-03 22:02:19 +000042 \let\OldLabel=\label
43 \renewcommand{\label}[1]{%
44 \OldLabel{#1}%
45 {\pdfdest name{label.#1} fit}%
46 }
47 % This stuff adds a page.# destination to every PDF page, where # has
48 % the same formatting as the displayed page number. This doesn't really
49 % help with the frontmatter, but does fine with the body.
50 %
51 % This is *heavily* based on the hyperref package.
52 %
Fred Drake1c8d0e01998-03-07 05:29:15 +000053 \def\@begindvi{%
54 \unvbox \@begindvibox
55 \@hyperfixhead
Fred Drake6659c301998-03-03 22:02:19 +000056 }
Fred Drake1c8d0e01998-03-07 05:29:15 +000057 \def\@hyperfixhead{%
58 \let\H@old@thehead\@thehead
Fred Drake6cb71491998-03-27 05:22:53 +000059 \gdef\@foo{\if@doing@page@targets\pdfdest name{page.\thepage} fit\fi}%
Fred Drake1c8d0e01998-03-07 05:29:15 +000060 \expandafter\ifx\expandafter\@empty\H@old@thehead
61 \def\H@old@thehead{\hfil}\fi
62 \def\@thehead{\@foo\relax\H@old@thehead}%
Fred Drake6659c301998-03-03 22:02:19 +000063 }
Fred Drakec0b2e451998-03-25 14:53:43 +000064\fi\fi
Fred Drake6659c301998-03-03 22:02:19 +000065
66% Increase printable page size (copied from fullpage.sty)
67\topmargin 0pt
68\advance \topmargin by -\headheight
69\advance \topmargin by -\headsep
70
71% attempt to work a little better for A4 users
Fred Drake1c8d0e01998-03-07 05:29:15 +000072\@ifundefined{paperheight}{
Fred Drake6659c301998-03-03 22:02:19 +000073 \textheight 9in
74}{
75 \textheight \paperheight
76 \advance\textheight by -2in
77}
78
79\oddsidemargin 0pt
80\evensidemargin \oddsidemargin
81\marginparwidth 0.5in
82
Fred Drake1c8d0e01998-03-07 05:29:15 +000083\@ifundefined{paperwidth}{
Fred Drake6659c301998-03-03 22:02:19 +000084 \textwidth 6.5in
85}{
86 \textwidth \paperwidth
87 \advance\textwidth by -2in
88}
89
90
91% Style parameters and macros used by most documents here
92\raggedbottom
93\sloppy
94\parindent = 0mm
95\parskip = 2mm
96\hbadness = 5000 % don't print trivial gripes
97
98\pagestyle{empty} % start this way; change for
99\pagenumbering{roman} % ToC & chapters
100\setcounter{secnumdepth}{1}
101
102% Use this to set the font family for headers and other decor:
103\newcommand{\HeaderFamily}{\sffamily}
104
105% Redefine the 'normal' header/footer style when using "fancyhdr" package:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000106\@ifundefined{fancyhf}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000107 % Use \pagestyle{normal} as the primary pagestyle for text.
108 \fancypagestyle{normal}{
109 \fancyhf{}
110 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
111 \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}
112 \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}
113 \renewcommand{\headrulewidth}{0pt}
114 \renewcommand{\footrulewidth}{0.4pt}
115 }
116 % Update the plain style so we get the page number & footer line,
117 % but not a chapter or section title. This is to keep the first
118 % page of a chapter and the blank page between chapters `clean.'
119 \fancypagestyle{plain}{
120 \fancyhf{}
121 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
122 \renewcommand{\headrulewidth}{0pt}
123 \renewcommand{\footrulewidth}{0.4pt}
124 }
125 % Redefine \cleardoublepage so that the blank page between chapters
126 % gets the plain style and not the fancy style. This is described
127 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000128 \@ifundefined{chapter}{}{
Fred Drake28f13911998-03-04 21:47:59 +0000129 \renewcommand{\cleardoublepage}{
Fred Drake1c8d0e01998-03-07 05:29:15 +0000130 \clearpage\if@openright \ifodd\c@page\else
Fred Drake28f13911998-03-04 21:47:59 +0000131 \hbox{}
132 \thispagestyle{plain}
133 \newpage
Fred Drake1c8d0e01998-03-07 05:29:15 +0000134 \if@twocolumn\hbox{}\newpage\fi\fi\fi
Fred Drake28f13911998-03-04 21:47:59 +0000135 }
136 }
Fred Drake6659c301998-03-03 22:02:19 +0000137}
138
139% old code font selections:
140\let\codefont=\tt
141\let\sectcodefont=\tt
142
143% (Haven't found a new one that gets <, >, and _ right without being
144% monospaced.)
145
146
147% This sets up the {verbatim} environment to be indented and a minipage,
148% and to have all the other mostly nice properties that we want for
149% code samples.
150
151% Variable used by begin code command
152\newlength{\codewidth}
153
154\newcommand{\examplevspace}{2mm}
155\newcommand{\exampleindent}{1cm}
156
157\let\OldVerbatim=\verbatim
158\let\OldEndVerbatim=\endverbatim
159\renewcommand{\verbatim}{%
160 \begingroup%
161 \setlength{\parindent}\exampleindent%
162 % Calculate the text width for the minipage:
163 \setlength{\codewidth}{\linewidth}%
164 \addtolength{\codewidth}{-\parindent}%
165 %
166 \par%
167 \vspace\examplevspace%
168 \indent%
169 \begin{minipage}[t]{\codewidth}%
170 \small%
171 \OldVerbatim%
172}
173\renewcommand{\endverbatim}{%
174 \OldEndVerbatim%
175 \end{minipage}%
176 \endgroup%
177}
178
Fred Drake6cb71491998-03-27 05:22:53 +0000179\newcommand{\reset@python}{
180 \global\let\@thisclass=\@undefined
181 \global\let\@thismodule=\@undefined
182}
183\reset@python
184
185% Augment the sectioning commands used to get our own font family in place,
186% and reset some internal data items:
187\renewcommand{\section}{\reset@python%
188 \@startsection {section}{1}{\z@}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000189 {-3.5ex \@plus -1ex \@minus -.2ex}%
190 {2.3ex \@plus.2ex}%
191 {\reset@font\Large\HeaderFamily}}
192\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
193 {-3.25ex\@plus -1ex \@minus -.2ex}%
194 {1.5ex \@plus .2ex}%
195 {\reset@font\large\HeaderFamily}}
196\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
197 {-3.25ex\@plus -1ex \@minus -.2ex}%
198 {1.5ex \@plus .2ex}%
199 {\reset@font\normalsize\HeaderFamily}}
200\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
201 {3.25ex \@plus1ex \@minus.2ex}%
Fred Drake6659c301998-03-03 22:02:19 +0000202 {-1em}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000203 {\reset@font\normalsize\HeaderFamily}}
204\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
205 {3.25ex \@plus1ex \@minus .2ex}%
Fred Drake6659c301998-03-03 22:02:19 +0000206 {-1em}%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000207 {\reset@font\normalsize\HeaderFamily}}
Fred Drake6659c301998-03-03 22:02:19 +0000208
209
210% Underscore hack (only act like subscript operator if in math mode)
211%
212% The following is due to Mark Wooding (the old version didn't work with
213% Latex 2e.
214
215\DeclareRobustCommand\hackscore{%
216 \ifmmode_\else\textunderscore\fi%
217}
218\begingroup
219\catcode`\_\active
220\def\next{%
221 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
222}
223\expandafter\endgroup\next
224
225%
226% This is the old hack, which didn't work with 2e.
227% You should not need this since the rest of the documentation is now
228% LaTeX2e-only.
229%
230%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
231%\catcode`\_=12
232%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
233
234
235
236%% Lots of index-entry generation support.
237
238% Command to wrap around stuff that refers to function / module /
239% attribute names in the index. Default behavior: like \code{}. To
240% just keep the index entries in the roman font, uncomment the second
241% definition to use instead; it matches O'Reilly style more.
242%
243\newcommand{\idxcode}[1]{\codefont{#1}}
244%\renewcommand{\idxcode}[1]{#1}
245
246% Command to generate two index entries (using subentries)
247\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
248
249% And three entries (using only one level of subentries)
250\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
251
252% And four (again, using only one level of subentries)
253\newcommand{\indexiv}[4]{
254\index{#1!#2 #3 #4}
255\index{#2!#3 #4, #1}
256\index{#3!#4, #1 #2}
257\index{#4!#1 #2 #3}
258}
259
260% Command to generate a reference to a function, statement, keyword,
261% operator.
Fred Drake1c8d0e01998-03-07 05:29:15 +0000262\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
263\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
264\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Fred Drake6659c301998-03-03 22:02:19 +0000265\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drake1c8d0e01998-03-07 05:29:15 +0000266\newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1()}} (built-in function)}}
Fred Drake6659c301998-03-03 22:02:19 +0000267
268% Add an index entry for a module
Fred Drake1c8d0e01998-03-07 05:29:15 +0000269\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake6659c301998-03-03 22:02:19 +0000270\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
271\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
272\newcommand{\refexmodindex}[1]{\refmodule{#1}{extension }}
273\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
274
275% support for the module index
Fred Drakeb390daf1998-03-09 16:35:36 +0000276\newif\if@UseModuleIndex
277\@UseModuleIndexfalse
278
Fred Drakeb390daf1998-03-09 16:35:36 +0000279% Fix the theindex environment to add an entry to the Table of
280% Contents; this is much nicer than just having to jump to the end of
281% the book and flip around, especially with multiple indexes.
282%
283\let\OldTheindex=\theindex
284\renewcommand{\theindex}{
285 \cleardoublepage
286 \OldTheindex
287 \addcontentsline{toc}{chapter}{\indexname}
Fred Drakeb390daf1998-03-09 16:35:36 +0000288}
289
Fred Drakeb390daf1998-03-09 16:35:36 +0000290\newcommand{\makemodindex}{
291 \newwrite\modindexfile
292 \openout\modindexfile=mod\jobname.idx
293 \@UseModuleIndextrue
294}
295
Fred Drake0ee9f721998-03-12 06:41:40 +0000296% Add the defining entry for a module
297\newcommand{\@modindex}[2]{%
Fred Drake6cb71491998-03-27 05:22:53 +0000298 \global\def\@thismodule{#1}
299 \setindexsubitem{(in module #1)}%
Fred Drake0ee9f721998-03-12 06:41:40 +0000300 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
301 \if@UseModuleIndex%
302 \write\modindexfile{\protect\indexentry{#1@{\tt #1}}{\thepage}}%
303 \fi%
304}
305
Fred Drake6659c301998-03-03 22:02:19 +0000306% built-in & Python modules in the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000307\newcommand{\bimodindex}[1]{\@modindex{#1}{built-in }}
308\newcommand{\stmodindex}[1]{\@modindex{#1}{standard }}
Fred Drake6659c301998-03-03 22:02:19 +0000309
310% Python & extension modules outside the main distribution
Fred Drakeb390daf1998-03-09 16:35:36 +0000311\newcommand{\modindex}[1]{\@modindex{#1}{}}
312\newcommand{\exmodindex}[1]{\@modindex{#1}{extension }}
Fred Drake6659c301998-03-03 22:02:19 +0000313
314% Additional string for an index entry
Fred Drake1c8d0e01998-03-07 05:29:15 +0000315\newcommand{\index@subitem}{}
316\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
317\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
Fred Drake6659c301998-03-03 22:02:19 +0000318
Fred Drake0ee9f721998-03-12 06:41:40 +0000319\newcommand{\withsubitem}[2]{%
320 \begingroup%
321 \def\index@subitem{#1}#2%
322 \endgroup%
323}
Fred Drake6659c301998-03-03 22:02:19 +0000324
325% {fulllineitems} is used in one place in libregex.tex, but is really for
326% internal use in this file.
327%
328\newenvironment{fulllineitems}{
329 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
330 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
331 \itemsep -\parsep
332 \let\makelabel=\itemnewline}
333}{\end{list}}
334
Fred Drake6cb71491998-03-27 05:22:53 +0000335% \optional is mostly for use in the arguments parameters to the various
336% {*desc} environments defined below, but may be used elsewhere. Known to
337% be used in the debugger chapter.
Fred Drake6659c301998-03-03 22:02:19 +0000338\newcommand{\optional}[1]{%
339 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
340
Fred Drake6cb71491998-03-27 05:22:53 +0000341% C functions ------------------------------------------------------------
342% \begin{cfuncdesc}{type}{name}{arglist}
343\newenvironment{cfuncdesc}[3]{
344 \begin{fulllineitems}
345 \item[\code{#1 \bfcode{#2}(\varvars{#3})}\index{#2@{\idxcode{#2()}}}]
346}{\end{fulllineitems}}
347
348% C variables ------------------------------------------------------------
349% \begin{cvardesc}{type}{name}
350\newenvironment{cvardesc}[2]{
351 \begin{fulllineitems}
352 \item[\code{#1 \bfcode{#2}}\index{#2@{\idxcode{#2}}}]
353}{\end{fulllineitems}}
354
355% C data types -----------------------------------------------------------
356% \begin{ctypedesc}{typedef name}
357\newenvironment{ctypedesc}[1]{
358 \begin{fulllineitems}
359 \item[\bfcode{#1}\ttindex{#1}]
360}{\end{fulllineitems}}
361
362% simple functions (not methods) -----------------------------------------
363% \begin{funcdesc}{name}{args}
364\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
365\newenvironment{funcdesc}[2]{
366 \begin{fulllineitems}
367 \funcline{#1}{#2}
368}{\end{fulllineitems}}
369
Fred Drake6659c301998-03-03 22:02:19 +0000370% similar to {funcdesc}, but doesn't add to the index
371\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
Fred Drake6cb71491998-03-27 05:22:53 +0000372\newenvironment{funcdescni}[2]{
373 \begin{fulllineitems}
374 \funclineni{#1}{#2}
Fred Drake6659c301998-03-03 22:02:19 +0000375}{\end{fulllineitems}}
376
Fred Drake6cb71491998-03-27 05:22:53 +0000377% classes ----------------------------------------------------------------
378% \begin{classdesc}{name}{constructor args}
379\newenvironment{classdesc}[2]{
380 \global\def\@thisclass{#1}
381 \begin{fulllineitems}
382 \item[\code{\bfcode{#1}(\varvars{#2})}%
383 \withsubitem{(class in \@thismodule)}{\ttindex{#1}}]
384 \def\baseclasses##1{}
Fred Drake6659c301998-03-03 22:02:19 +0000385}{\end{fulllineitems}}
386
Fred Drake6cb71491998-03-27 05:22:53 +0000387
388\newcommand{\@classbadkey}{--bad current class--}
389\let\@classbadkey=\@undefined
390
391% object method ----------------------------------------------------------
392% \begin{methoddesc}[classname]{methodname}{args}
393\newcommand{\methodline}[3][\@classbadkey]{
394 \methodlineni{#2}{#3}
395 \ifx#1\@undefined
396 \withsubitem{(\@thisclass\ method)}{\ttindex{#2()}}
397 \else
398 \withsubitem{(#1 method)}{\ttindex{#2()}}
399 \fi
400}
401\newenvironment{methoddesc}[3][\@classbadkey]{
402 \begin{fulllineitems}
403 \ifx#1\@undefined
404 \methodline{#2}{#3}
405 \else
406 \def\@thisclass{#1}
407 \methodline[#1]{#2}{#3}
408 \fi
Fred Drake6659c301998-03-03 22:02:19 +0000409}{\end{fulllineitems}}
410
Fred Drake6cb71491998-03-27 05:22:53 +0000411% similar to {methoddesc}, but doesn't add to the index
412% (never actually uses the optional argument)
413\newcommand{\methodlineni}[3][\@classbadkey]{%
414 \item[\code{\bfcode{#2}(\varvars{#3})}]}
415\newenvironment{methoddescni}[3][\@classbadkey]{
416 \begin{fulllineitems}
417 \methodlineni{#2}{#3}
418}{\end{fulllineitems}}
419
420% object data attribute --------------------------------------------------
421% \begin{memberdesc}[classname]{membername}
422\newcommand{\memberline}[2][\@classbadkey]{%
423 \ifx#1\@undefined
424 \memberlineni{#2}
425 \withsubitem{(\@thisclass\ attribute)}{\ttindex{#2()}}
426 \else
427 \memberlineni{#2}
428 \withsubitem{(#1 attribute)}{\ttindex{#2()}}
429 \fi
430}
431\newenvironment{memberdesc}[2][\@classbadkey]{
432 \begin{fulllineitems}
433 \ifx#1\@undefined
434 \memberline{#2}
435 \else
436 \def\@thisclass{#1}
437 \memberline[#1]{#2}
438 \fi
439}{\end{fulllineitems}}
440
441% similar to {memberdesc}, but doesn't add to the index
442% (never actually uses the optional argument)
443\newcommand{\memberlineni}[2][\@classbadkey]{\item[\bfcode{#2}]}
444\newenvironment{memberdescni}[2][\@classbadkey]{
445 \begin{fulllineitems}
446 \memberlineni{#2}
447}{\end{fulllineitems}}
448
449% For exceptions: --------------------------------------------------------
450% \begin{excdesc}{name}
451% -- need support for constructor; maybe use optional parameter?
452\newenvironment{excdesc}[1]{
453 \begin{fulllineitems}
454 \item[\bfcode{#1}\ttindex{#1}]
455}{\end{fulllineitems}}
456
457% Module data or constants: ----------------------------------------------
458% \begin{datadesc}{name}
Fred Drake6659c301998-03-03 22:02:19 +0000459\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
Fred Drake6cb71491998-03-27 05:22:53 +0000460\newenvironment{datadesc}[1]{
461 \begin{fulllineitems}
462 \dataline{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000463}{\end{fulllineitems}}
464
465% similar to {datadesc}, but doesn't add to the index
Fred Drake6cb71491998-03-27 05:22:53 +0000466\newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak}
467\newenvironment{datadescni}[1]{
468 \begin{fulllineitems}
469 \datalineni{#1}
Fred Drake6659c301998-03-03 22:02:19 +0000470}{\end{fulllineitems}}
471
Fred Drake6cb71491998-03-27 05:22:53 +0000472% bytecode instruction ---------------------------------------------------
473% \begin{opcodedesc}{name}{var}
474% -- {var} may be {}
475\newenvironment{opcodedesc}[2]{
476 \begin{fulllineitems}
477 \item[\bfcode{#1}\quad\var{#2}]
Fred Drake6659c301998-03-03 22:02:19 +0000478}{\end{fulllineitems}}
479
480
481\let\nodename=\label
482
Fred Drake55730311998-03-25 15:41:23 +0000483\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
484
Fred Drake6659c301998-03-03 22:02:19 +0000485% For these commands, use \command{} to get the typography right, not
486% {\command}. This works better with the texinfo translation.
487\newcommand{\ABC}{{\sc abc}}
488\newcommand{\UNIX}{{\sc Unix}}
489\newcommand{\POSIX}{POSIX}
490\newcommand{\ASCII}{{\sc ascii}}
491\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
492\newcommand{\C}{C}
493\newcommand{\EOF}{{\sc eof}}
Fred Drake55730311998-03-25 15:41:23 +0000494\newcommand{\NULL}{\sectcode{NULL}}
Fred Drake6659c301998-03-03 22:02:19 +0000495
496% code is the most difficult one...
Fred Drake1c8d0e01998-03-07 05:29:15 +0000497\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 +0000498\mbox{\codefont{#1}}}}
499
500\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
501\newcommand{\kbd}[1]{\mbox{\tt #1}}
502\newcommand{\key}[1]{\mbox{\tt #1}}
503\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
504% This weird definition of \var{} allows it to always appear in roman
505% italics, and won't get funky in code fragments when we play around
506% with fonts.
507\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
508\renewcommand{\emph}[1]{{\em #1\/}}
509\newcommand{\dfn}[1]{\emph{#1}}
510\newcommand{\strong}[1]{{\bf #1}}
511% let's experiment with a new font:
Fred Drake0ee9f721998-03-12 06:41:40 +0000512\newcommand{\file}[1]{`{\small\textsf{#1}}'}
Fred Drake6659c301998-03-03 22:02:19 +0000513
514% Use this def/redef approach for \url{} since hyperref defined this already,
515% but only if we actually used hyperref:
Fred Drake6cb71491998-03-27 05:22:53 +0000516\@ifundefined{pdfannotlink}{
517 \newcommand{\pythonurl}[1]{\mbox{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000518}{
519 \newcommand{\pythonurl}[1]{{%
520 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
521 \LinkColor% color of the link text
Fred Drake6cb71491998-03-27 05:22:53 +0000522 {\small\textsf{#1}}%
Fred Drake6659c301998-03-03 22:02:19 +0000523 \NormalColor% Turn it back off; these are declarative
524 \pdfendlink}% and don't appear bound to the current
525 }% formatting "box".
526}
527\let\url=\pythonurl
Fred Drake0ee9f721998-03-12 06:41:40 +0000528\newcommand{\email}[1]{{\small\textsf{#1}}}
Fred Drake6659c301998-03-03 22:02:19 +0000529
530\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
531
532\newif\iftexi\texifalse
533\newif\iflatex\latextrue
534
535% These should be used for all references to identifiers which are
536% used to refer to instances of specific language constructs. See the
537% names for specific semantic assignments.
538%
539% For now, don't do anything really fancy with them; just use them as
540% logical markup. This might change in the future.
541%
Fred Drake55730311998-03-25 15:41:23 +0000542\let\module=\sectcode
543\let\keyword=\sectcode
544\let\exception=\sectcode
545\let\class=\sectcode
546\let\function=\sectcode
547\let\member=\sectcode
548\let\method=\sectcode
Fred Drake6659c301998-03-03 22:02:19 +0000549
Fred Drake55730311998-03-25 15:41:23 +0000550\let\cfunction=\sectcode
551\let\ctype=\sectcode
552\let\cdata=\sectcode
Fred Drake6659c301998-03-03 22:02:19 +0000553
Fred Drake0ee9f721998-03-12 06:41:40 +0000554\newcommand{\mimetype}[1]{{\small\textsf{#1}}}
Fred Drake94fac131998-03-12 19:37:03 +0000555% The \! is a "negative thin space" in math mode.
556\newcommand{\regexp}[1]{%
557 {\tiny$^{^\lceil}\!\!$%
558 {\normalsize\code{#1}}%
559 $\!\!\rfloor\!$%
560 }}
Fred Drake0ee9f721998-03-12 06:41:40 +0000561\newcommand{\envvar}[1]{%
Fred Drake94fac131998-03-12 19:37:03 +0000562 \$#1% $ <-- bow to font-lock 3 times!
563 \index{#1@{\$#1}}% $
564 \index{environment variables!{\$#1}}% $
Fred Drake0ee9f721998-03-12 06:41:40 +0000565}
566\let\character=\samp
567
Fred Drake6659c301998-03-03 22:02:19 +0000568% constants defined in Python modules or C headers, not language constants:
569\let\constant=\code
570
571\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
572\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
573\newcommand{\program}[1]{\strong{#1}}
574
575
576% Deprecation stuff.
577% Should be extended to allow an index / list of deprecated stuff. But
578% there's a lot of stuff that needs to be done to make that automatable.
579%
580% First parameter is the release number that deprecates the feature, the
581% second is the action the should be taken by users of the feature.
582%
583% Example:
584%
585% \deprecated {1.5.1}
586% {Use \method{frobnicate()} instead.}
587%
588\newcommand{\deprecated}[2]{%
589 \strong{Deprecated since release #1.} #2\par}
590
591
592\newenvironment{tableii}[4]{%
593 \begin{center}%
594 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
595 \begin{tabular}{#1}\hline \strong{#3}&\strong{#4} \\ \hline%
596}{%
597 \hline%
598 \end{tabular}%
599 \end{center}%
600}
601
602\newenvironment{tableiii}[5]{%
603 \begin{center}%
604 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
605 \begin{tabular}{#1}\hline \strong{#3}&\strong{#4}&\strong{#5} \\ \hline%
606}{%
607 \hline%
608 \end{tabular}%
609 \end{center}%
610}
611
612\newcommand{\itemnewline}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000613 \@tempdima\linewidth%
614 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
Fred Drake6659c301998-03-03 22:02:19 +0000615}
616
Fred Drake6659c301998-03-03 22:02:19 +0000617% Cross-referencing (AMK)
618% Sample usage:
619% \begin{seealso}
620% \seemodule{rand}{Uniform random number generator}; % Module xref
621% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
Fred Drakeebcb6581998-03-06 21:25:17 +0000622%
623% % A funky case: module name contains '_'; have to supply an optional key
624% \seemodule[copyreg]{copy_reg}{pickle interface constructor registration}
625%
Fred Drake6659c301998-03-03 22:02:19 +0000626% \end{seealso}
627
Fred Drake1c8d0e01998-03-07 05:29:15 +0000628\newcommand{\@modulebadkey}{{--just-some-junk--}}
Fred Drakeebcb6581998-03-06 21:25:17 +0000629
Fred Drake1c8d0e01998-03-07 05:29:15 +0000630\@ifundefined{pdfannotlink}{%
631 \newcommand{\seemodule}[3][\@modulebadkey]{%
632 \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
633 \ref{module-\@modulekey}:\quad %
Fred Drakeebcb6581998-03-06 21:25:17 +0000634 Module \module{#2}%
635 \quad (#3)%
636 }
Fred Drake1c8d0e01998-03-07 05:29:15 +0000637}{\newcommand{\seemodule}[3][\@modulebadkey]{%
638 \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
639 \ref{module-\@modulekey}:\quad %
640 {\pdfannotlink attr{/Border [0 0 0]} goto name{label.module-\@modulekey}%
Fred Drakeebcb6581998-03-06 21:25:17 +0000641 \LinkColor Module \module{#2} \NormalColor%
642 \pdfendlink%
643 }%
644 \quad (#3)%
645 }
646}
Fred Drake6659c301998-03-03 22:02:19 +0000647\newenvironment{seealso}[0]{
648 \strong{See Also:}\par
Fred Drake6659c301998-03-03 22:02:19 +0000649 \def\seetext##1{\par{##1}}
650}{\par}
651
652
Fred Drake6659c301998-03-03 22:02:19 +0000653% Allow the release number to be specified independently of the
654% \date{}. This allows the date to reflect the document's date and
655% release to specify the Python release that is documented.
656%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000657\newcommand{\@release}{}
Fred Drake6659c301998-03-03 22:02:19 +0000658\newcommand{\version}{}
659\newcommand{\releasename}{Release}
660\newcommand{\release}[1]{%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000661 \renewcommand{\@release}{\releasename\space\version}%
Fred Drake6659c301998-03-03 22:02:19 +0000662 \renewcommand{\version}{#1}}
663
664% Allow specification of the author's address separately from the
665% author's name. This can be used to format them differently, which
666% is a good thing.
667%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000668\newcommand{\@authoraddress}{}
669\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
Fred Drake6659c301998-03-03 22:02:19 +0000670
Fred Drake6659c301998-03-03 22:02:19 +0000671% This sets up the fancy chapter headings that make the documents look
672% at least a little better than the usual LaTeX output.
673%
Fred Drake1c8d0e01998-03-07 05:29:15 +0000674\@ifundefined{ChTitleVar}{}{
Fred Drake6659c301998-03-03 22:02:19 +0000675 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
676 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
677 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
678 % This creates chapter heads without the leading \vspace*{}:
Fred Drake1c8d0e01998-03-07 05:29:15 +0000679 \def\@makechapterhead#1{%
680 {\parindent \z@ \raggedright \normalfont
681 \ifnum \c@secnumdepth >\m@ne
Fred Drake6659c301998-03-03 22:02:19 +0000682 \DOCH
683 \fi
Fred Drake1c8d0e01998-03-07 05:29:15 +0000684 \interlinepenalty\@M
Fred Drake6659c301998-03-03 22:02:19 +0000685 \DOTI{#1}
686 }
687 }
Fred Drake6659c301998-03-03 22:02:19 +0000688}
689
690% Tell TeX about pathological hyphenation cases:
691\hyphenation{Base-HTTP-Re-quest-Hand-ler}