blob: 93957a644dc68be1bb1b830eecbd4cdc7a3d64ff [file] [log] [blame]
Fred Drake6659c301998-03-03 22:02:19 +00001%
2% myformat.sty for the Python docummentation [works only with with Latex2e]
3%
4
5\NeedsTeXFormat{LaTeX2e}[1995/12/01]
6\ProvidesPackage{python}
7 [1998/01/11 LaTeX package (Python manual markup)]
8
9% The "fncychap" package is used to get the nice chapter headers. The
10% .sty file is distributed with Python, so you should not need to disable
11% it. You'd also end up with a mixed page style; uglier than stock LaTeX!
12%
Fred Drake28f13911998-03-04 21:47:59 +000013\RequirePackage[Bjarne]{fncychap}\typeout{Using fancy chapter headings.}
Fred Drake6659c301998-03-03 22:02:19 +000014
15
16% for PDF output, use maximal compression
17\@ifundefined{pdfannotlink}{
18 \let\LinkColor=\relax
19 \let\NormalColor=\relax
20}{%
21 \input{pdfcolor}
22 \let\LinkColor=\NavyBlue
23 \let\NormalColor=\Black
24 \pdfcompresslevel=9
25 \let\OldContentsline=\contentsline
26 \renewcommand{\contentsline}[3]{%
27 \OldContentsline{#1}{%
28 \pdfannotlink attr{/Border [0 0 0]} goto name{page.#3}%
29 \LinkColor#2\NormalColor%
30 \pdfendlink%
31 }{#3}%
32 }
33 \let\OldLabel=\label
34 \renewcommand{\label}[1]{%
35 \OldLabel{#1}%
36 {\pdfdest name{label.#1} fit}%
37 }
38 % This stuff adds a page.# destination to every PDF page, where # has
39 % the same formatting as the displayed page number. This doesn't really
40 % help with the frontmatter, but does fine with the body.
41 %
42 % This is *heavily* based on the hyperref package.
43 %
44 \def\@begindvi{%
45 \unvbox \@begindvibox
46 \@hyperfixhead
47 \global\let \@begindvi \@hyperfixhead
48 }
49 \def\hyperpageanchor{%
50 \hyper@anchorstart{page.\thepage}\hyper@anchorend
51 }
52 \let\HYPERPAGEANCHOR\hyperpageanchor
53 \def\@hyperfixhead{%
54 \let\H@old@thehead\@thehead
55 \gdef\@foo{\pdfdest name{page.\thepage} fit}%
56 \expandafter\ifx\expandafter\@empty\H@old@thehead
57 \def\H@old@thehead{\hfil}\fi
58 \def\@thehead{\@foo\relax\H@old@thehead}%
59 }
60}
61
62% Increase printable page size (copied from fullpage.sty)
63\topmargin 0pt
64\advance \topmargin by -\headheight
65\advance \topmargin by -\headsep
66
67% attempt to work a little better for A4 users
68\@ifundefined{paperheight}{
69 \textheight 9in
70}{
71 \textheight \paperheight
72 \advance\textheight by -2in
73}
74
75\oddsidemargin 0pt
76\evensidemargin \oddsidemargin
77\marginparwidth 0.5in
78
79\@ifundefined{paperwidth}{
80 \textwidth 6.5in
81}{
82 \textwidth \paperwidth
83 \advance\textwidth by -2in
84}
85
86
87% Style parameters and macros used by most documents here
88\raggedbottom
89\sloppy
90\parindent = 0mm
91\parskip = 2mm
92\hbadness = 5000 % don't print trivial gripes
93
94\pagestyle{empty} % start this way; change for
95\pagenumbering{roman} % ToC & chapters
96\setcounter{secnumdepth}{1}
97
98% Use this to set the font family for headers and other decor:
99\newcommand{\HeaderFamily}{\sffamily}
100
101% Redefine the 'normal' header/footer style when using "fancyhdr" package:
102\@ifundefined{fancyhf}{}{
103 % Use \pagestyle{normal} as the primary pagestyle for text.
104 \fancypagestyle{normal}{
105 \fancyhf{}
106 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
107 \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}
108 \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}
109 \renewcommand{\headrulewidth}{0pt}
110 \renewcommand{\footrulewidth}{0.4pt}
111 }
112 % Update the plain style so we get the page number & footer line,
113 % but not a chapter or section title. This is to keep the first
114 % page of a chapter and the blank page between chapters `clean.'
115 \fancypagestyle{plain}{
116 \fancyhf{}
117 \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}
118 \renewcommand{\headrulewidth}{0pt}
119 \renewcommand{\footrulewidth}{0.4pt}
120 }
121 % Redefine \cleardoublepage so that the blank page between chapters
122 % gets the plain style and not the fancy style. This is described
123 % in the documentation for the fancyhdr package by Piet von Oostrum.
Fred Drake28f13911998-03-04 21:47:59 +0000124 \@ifundefined{chapter}{}{
125 \renewcommand{\cleardoublepage}{
126 \clearpage\if@openright \ifodd\c@page\else
127 \hbox{}
128 \thispagestyle{plain}
129 \newpage
130 \if@twocolumn\hbox{}\newpage\fi\fi\fi
131 }
132 }
Fred Drake6659c301998-03-03 22:02:19 +0000133}
134
135% old code font selections:
136\let\codefont=\tt
137\let\sectcodefont=\tt
138
139% (Haven't found a new one that gets <, >, and _ right without being
140% monospaced.)
141
142
143% This sets up the {verbatim} environment to be indented and a minipage,
144% and to have all the other mostly nice properties that we want for
145% code samples.
146
147% Variable used by begin code command
148\newlength{\codewidth}
149
150\newcommand{\examplevspace}{2mm}
151\newcommand{\exampleindent}{1cm}
152
153\let\OldVerbatim=\verbatim
154\let\OldEndVerbatim=\endverbatim
155\renewcommand{\verbatim}{%
156 \begingroup%
157 \setlength{\parindent}\exampleindent%
158 % Calculate the text width for the minipage:
159 \setlength{\codewidth}{\linewidth}%
160 \addtolength{\codewidth}{-\parindent}%
161 %
162 \par%
163 \vspace\examplevspace%
164 \indent%
165 \begin{minipage}[t]{\codewidth}%
166 \small%
167 \OldVerbatim%
168}
169\renewcommand{\endverbatim}{%
170 \OldEndVerbatim%
171 \end{minipage}%
172 \endgroup%
173}
174
175% Augment the sectioning commands used to get our own font family in place:
176\renewcommand{\section}{\@startsection {section}{1}{\z@}%
177 {-3.5ex \@plus -1ex \@minus -.2ex}%
178 {2.3ex \@plus.2ex}%
179 {\reset@font\Large\HeaderFamily}}
180\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
181 {-3.25ex\@plus -1ex \@minus -.2ex}%
182 {1.5ex \@plus .2ex}%
183 {\reset@font\large\HeaderFamily}}
184\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
185 {-3.25ex\@plus -1ex \@minus -.2ex}%
186 {1.5ex \@plus .2ex}%
187 {\reset@font\normalsize\HeaderFamily}}
188\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
189 {3.25ex \@plus1ex \@minus.2ex}%
190 {-1em}%
191 {\reset@font\normalsize\HeaderFamily}}
192\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
193 {3.25ex \@plus1ex \@minus .2ex}%
194 {-1em}%
195 {\reset@font\normalsize\HeaderFamily}}
196
197
198% Underscore hack (only act like subscript operator if in math mode)
199%
200% The following is due to Mark Wooding (the old version didn't work with
201% Latex 2e.
202
203\DeclareRobustCommand\hackscore{%
204 \ifmmode_\else\textunderscore\fi%
205}
206\begingroup
207\catcode`\_\active
208\def\next{%
209 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
210}
211\expandafter\endgroup\next
212
213%
214% This is the old hack, which didn't work with 2e.
215% You should not need this since the rest of the documentation is now
216% LaTeX2e-only.
217%
218%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
219%\catcode`\_=12
220%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
221
222
223
224%% Lots of index-entry generation support.
225
226% Command to wrap around stuff that refers to function / module /
227% attribute names in the index. Default behavior: like \code{}. To
228% just keep the index entries in the roman font, uncomment the second
229% definition to use instead; it matches O'Reilly style more.
230%
231\newcommand{\idxcode}[1]{\codefont{#1}}
232%\renewcommand{\idxcode}[1]{#1}
233
234% Command to generate two index entries (using subentries)
235\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
236
237% And three entries (using only one level of subentries)
238\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
239
240% And four (again, using only one level of subentries)
241\newcommand{\indexiv}[4]{
242\index{#1!#2 #3 #4}
243\index{#2!#3 #4, #1}
244\index{#3!#4, #1 #2}
245\index{#4!#1 #2 #3}
246}
247
248% Command to generate a reference to a function, statement, keyword,
249% operator.
250\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
251\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
252\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
253\newcommand{\obindex}[1]{\indexii{object}{#1}}
254\newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1()}} (built-in function)}}
255
256% Add an index entry for a module
257\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
258\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
259\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
260\newcommand{\refexmodindex}[1]{\refmodule{#1}{extension }}
261\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
262
263% support for the module index
264\newwrite\modindexfile
265\openout\modindexfile=mod\jobname.idx
266
267% Add the defining entry for a module
268\newcommand{\defmodindex}[2]{%
269 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
270 \setindexsubitem{(in module #1)}%
271 \write\modindexfile{#1 \thepage}}
272
273% built-in & Python modules in the main distribution
274\newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }}
275\newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }}
276
277% Python & extension modules outside the main distribution
278\newcommand{\modindex}[1]{\defmodindex{#1}{}}
279\newcommand{\exmodindex}[1]{\defmodindex{#1}{extension }}
280
281% Additional string for an index entry
282\newcommand{\index@subitem}{}
283\newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}}
284\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}}
285
286
287% {fulllineitems} is used in one place in libregex.tex, but is really for
288% internal use in this file.
289%
290\newenvironment{fulllineitems}{
291 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
292 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
293 \itemsep -\parsep
294 \let\makelabel=\itemnewline}
295}{\end{list}}
296
297
298% cfuncdesc should be called as
299% \begin{cfuncdesc}{type}{name}{arglist}
300% ... description ...
301% \end{cfuncdesc}
302\newenvironment{cfuncdesc}[3]{%
303 \begin{fulllineitems}%
304 \item[\code{#1 \bfcode{#2}(\varvars{#3})}]%
305 \index{#2@{\idxcode{#2()}}}%
306}{\end{fulllineitems}}
307
308\newenvironment{cvardesc}[2]{%
309 \begin{fulllineitems}%
310 \item[\code{#1 \bfcode{#2}}]%
311 \index{#2@{\idxcode{#2}}}%
312}{\end{fulllineitems}}
313
314\newenvironment{ctypedesc}[1]{%
315 \begin{fulllineitems}%
316 \item[\bfcode{#1}]\ttindex{#1}
317}{\end{fulllineitems}}
318
319\newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}}
320\newenvironment{funcdesc}[2]{%
321 \begin{fulllineitems}%
322 \funcline{#1}{#2}%
323}{\end{fulllineitems}}
324
325\newcommand{\optional}[1]{%
326 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
327
328% similar to {funcdesc}, but doesn't add to the index
329\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]}
330\newenvironment{funcdescni}[2]{%
331 \begin{fulllineitems}%
332 \funclineni{#1}{#2}%
333}{\end{fulllineitems}}
334
335\newenvironment{classdesc}[2]{%
336 \begin{fulllineitems}%
337 \item[\code{\bfcode{#1}(\varvars{#2})}]%
338 \ttindex{#1}%
339 \def\baseclasses##1{}%
340}{\end{fulllineitems}}
341
342\newenvironment{excdesc}[1]{%
343 \begin{fulllineitems}%
344 \item[\bfcode{#1}]\ttindex{#1}%
345}{\end{fulllineitems}}
346
347\newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}}
348\newenvironment{datadesc}[1]{%
349 \begin{fulllineitems}%
350 \dataline{#1}%
351}{\end{fulllineitems}}
352
353% similar to {datadesc}, but doesn't add to the index
354\newcommand{\datalineni}[1]{\item[\bfcode{#1}]}
355\newenvironment{datadescni}[1]{%
356 \begin{fulllineitems}%
357 \datalineni{#1}%
358}{\end{fulllineitems}}
359
360\newenvironment{opcodedesc}[2]{%
361 \begin{fulllineitems}%
362 \item[\bfcode{#1}\quad\var{#2}]%
363}{\end{fulllineitems}}
364
365
366\let\nodename=\label
367
368% For these commands, use \command{} to get the typography right, not
369% {\command}. This works better with the texinfo translation.
370\newcommand{\ABC}{{\sc abc}}
371\newcommand{\UNIX}{{\sc Unix}}
372\newcommand{\POSIX}{POSIX}
373\newcommand{\ASCII}{{\sc ascii}}
374\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
375\newcommand{\C}{C}
376\newcommand{\EOF}{{\sc eof}}
377\newcommand{\NULL}{\code{NULL}}
378
379% code is the most difficult one...
380\newcommand{\code}[1]{{\@vobeyspaces\@noligs\def\{{\char`\{}\def\}{\char`\}}\def\~{\char`\~}\def\^{\char`\^}\def\e{\char`\\}\def\${\char`\$}\def\#{\char`\#}\def\&{\char`\&}\def\%{\char`\%}%
381\mbox{\codefont{#1}}}}
382
383\newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font
384\newcommand{\kbd}[1]{\mbox{\tt #1}}
385\newcommand{\key}[1]{\mbox{\tt #1}}
386\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
387% This weird definition of \var{} allows it to always appear in roman
388% italics, and won't get funky in code fragments when we play around
389% with fonts.
390\newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}}
391\renewcommand{\emph}[1]{{\em #1\/}}
392\newcommand{\dfn}[1]{\emph{#1}}
393\newcommand{\strong}[1]{{\bf #1}}
394% let's experiment with a new font:
395\newcommand{\file}[1]{\mbox{`\small\textsf{#1}'}}
396
397% Use this def/redef approach for \url{} since hyperref defined this already,
398% but only if we actually used hyperref:
399\@ifundefined{pdfannotlink}{%
400 \newcommand{\pythonurl}[1]{\mbox{\small\textsf{#1}}}%
401}{
402 \newcommand{\pythonurl}[1]{{%
403 \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
404 \LinkColor% color of the link text
405 \mbox{\small\textsf{#1}}%
406 \NormalColor% Turn it back off; these are declarative
407 \pdfendlink}% and don't appear bound to the current
408 }% formatting "box".
409}
410\let\url=\pythonurl
411\newcommand{\email}[1]{\mbox{\small\textsf{#1}}}
412
413\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
414
415\newif\iftexi\texifalse
416\newif\iflatex\latextrue
417
418% These should be used for all references to identifiers which are
419% used to refer to instances of specific language constructs. See the
420% names for specific semantic assignments.
421%
422% For now, don't do anything really fancy with them; just use them as
423% logical markup. This might change in the future.
424%
425\let\module=\code
426\let\keyword=\code
427\let\exception=\code
428\let\class=\code
429\let\function=\code
430\let\member=\code
431\let\method=\code
432
433\let\cfunction=\code
434\let\ctype=\code
435\let\cdata=\code
436
437% constants defined in Python modules or C headers, not language constants:
438\let\constant=\code
439
440\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
441\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
442\newcommand{\program}[1]{\strong{#1}}
443
444
445% Deprecation stuff.
446% Should be extended to allow an index / list of deprecated stuff. But
447% there's a lot of stuff that needs to be done to make that automatable.
448%
449% First parameter is the release number that deprecates the feature, the
450% second is the action the should be taken by users of the feature.
451%
452% Example:
453%
454% \deprecated {1.5.1}
455% {Use \method{frobnicate()} instead.}
456%
457\newcommand{\deprecated}[2]{%
458 \strong{Deprecated since release #1.} #2\par}
459
460
461\newenvironment{tableii}[4]{%
462 \begin{center}%
463 \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
464 \begin{tabular}{#1}\hline \strong{#3}&\strong{#4} \\ \hline%
465}{%
466 \hline%
467 \end{tabular}%
468 \end{center}%
469}
470
471\newenvironment{tableiii}[5]{%
472 \begin{center}%
473 \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
474 \begin{tabular}{#1}\hline \strong{#3}&\strong{#4}&\strong{#5} \\ \hline%
475}{%
476 \hline%
477 \end{tabular}%
478 \end{center}%
479}
480
481\newcommand{\itemnewline}[1]{%
482 \@tempdima\linewidth%
483 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
484}
485
486\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
487
488% Cross-referencing (AMK)
489% Sample usage:
490% \begin{seealso}
491% \seemodule{rand}{Uniform random number generator}; % Module xref
492% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
493% \end{seealso}
494
495\newenvironment{seealso}[0]{
496 \strong{See Also:}\par
497 % These should only be defined within the {seealso} environment:
498 \def\seemodule##1##2{\ref{module-##1}:\quad Module \module{##1}\quad (##2)}
499 \def\seetext##1{\par{##1}}
500}{\par}
501
502
503% Fix the theindex environment to add an entry to the Table of
504% Contents; this is much nicer than just having to jump to the end of
505% the book and flip around, especially with multiple indexes.
506%
507\let\OldTheindex=\theindex
508\renewcommand{\theindex}{
509 \cleardoublepage
510 \OldTheindex
511 \addcontentsline{toc}{chapter}{\indexname}
512}
513
514% Use a similar trick to catch the end of the {abstract} environment,
515% but here make sure the abstract is followed by a blank page if the
516% 'openright' option is used.
517%
518\let\OldEndAbstract=\endabstract
519\renewcommand{\endabstract}{
520 \if@openright
521 \ifodd\value{page}
522 \typeout{Adding blank page after the abstract.}
523 \vfil\pagebreak
524 \fi
525 \fi
526 \OldEndAbstract
527}
528
Fred Drake6659c301998-03-03 22:02:19 +0000529% Allow the release number to be specified independently of the
530% \date{}. This allows the date to reflect the document's date and
531% release to specify the Python release that is documented.
532%
533\newcommand{\@release}{}
534\newcommand{\version}{}
535\newcommand{\releasename}{Release}
536\newcommand{\release}[1]{%
537 \renewcommand{\@release}{\releasename\space\version}%
538 \renewcommand{\version}{#1}}
539
540% Allow specification of the author's address separately from the
541% author's name. This can be used to format them differently, which
542% is a good thing.
543%
544\newcommand{\@authoraddress}{}
545\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
546
Fred Drake6659c301998-03-03 22:02:19 +0000547% This sets up the fancy chapter headings that make the documents look
548% at least a little better than the usual LaTeX output.
549%
550\@ifundefined{ChTitleVar}{}{
551 \ChNameVar{\raggedleft\normalsize\HeaderFamily}
552 \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily}
553 \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily}
554 % This creates chapter heads without the leading \vspace*{}:
555 \def\@makechapterhead#1{%
556 {\parindent \z@ \raggedright \normalfont
557 \ifnum \c@secnumdepth >\m@ne
558 \DOCH
559 \fi
560 \interlinepenalty\@M
561 \DOTI{#1}
562 }
563 }
Fred Drake6659c301998-03-03 22:02:19 +0000564}
565
566% Tell TeX about pathological hyphenation cases:
567\hyphenation{Base-HTTP-Re-quest-Hand-ler}