blob: c67b5d2083b2bab247d73b93fb43663bf404f28d [file] [log] [blame]
Guido van Rossumecae0b71996-06-26 19:03:20 +00001%
2% myformat.sty for the Python doc [updated to work with Latex2e]
3%
4
Fred Drake06f169b1998-02-11 23:08:20 +00005\NeedsTeXFormat{LaTeX2e}[1995/12/01]
6\ProvidesPackage{myformat}
7 [1998/01/11 $Revision$
8 LaTeX package (Python manual markup)]
9
Guido van Rossumdaff1751997-06-02 17:35:01 +000010% Increase printable page size (copied from fullpage.sty)
11\topmargin 0pt
12\advance \topmargin by -\headheight
13\advance \topmargin by -\headsep
Fred Drake9e243091998-01-18 05:09:54 +000014
Guido van Rossumdaff1751997-06-02 17:35:01 +000015\textheight 8.9in
Fred Drake9e243091998-01-18 05:09:54 +000016
Guido van Rossumdaff1751997-06-02 17:35:01 +000017\oddsidemargin 0pt
18\evensidemargin \oddsidemargin
19\marginparwidth 0.5in
Fred Drake9e243091998-01-18 05:09:54 +000020
Guido van Rossumdaff1751997-06-02 17:35:01 +000021\textwidth 6.5in
22
Guido van Rossum643d9321992-03-31 18:53:47 +000023% Style parameters and macros used by most documents here
Guido van Rossum5badc751992-03-06 10:55:46 +000024\raggedbottom
25\sloppy
26\parindent = 0mm
27\parskip = 2mm
28
Fred Drake9e243091998-01-18 05:09:54 +000029% old code font selections:
30\let\codefont=\tt
31\let\sectcodefont=\tt
32
33% (Haven't found a new one that gets <, >, and _ right without being
34% monospaced.)
35
Guido van Rossum4c22cb21991-01-25 13:28:15 +000036% Variable used by begin code command
Guido van Rossum44000ed1991-01-24 16:54:29 +000037\newlength{\codewidth}
Guido van Rossum44000ed1991-01-24 16:54:29 +000038
Guido van Rossum5badc751992-03-06 10:55:46 +000039% Command to start a code block (follow this by \begin{verbatim})
Guido van Rossum4c22cb21991-01-25 13:28:15 +000040\newcommand{\bcode}{
41 % Calculate the text width for the minipage:
42 \setlength{\codewidth}{\linewidth}
43 \addtolength{\codewidth}{-\parindent}
44 %
Guido van Rossum4c22cb21991-01-25 13:28:15 +000045 \par
Guido van Rossum92fba021991-11-12 15:44:51 +000046 \vspace{3mm}
Guido van Rossum4c22cb21991-01-25 13:28:15 +000047 \indent
48 \begin{minipage}[t]{\codewidth}
49}
50
Guido van Rossum5badc751992-03-06 10:55:46 +000051% Command to end a code block (precede this by \end{verbatim})
Guido van Rossum4c22cb21991-01-25 13:28:15 +000052\newcommand{\ecode}{
53 \end{minipage}
54 \vspace{3mm}
55 \par
56 \noindent
57}
Guido van Rossum5badc751992-03-06 10:55:46 +000058
Guido van Rossumecae0b71996-06-26 19:03:20 +000059% Underscore hack (only act like subscript operator if in math mode)
60%
61% The following is due to Mark Wooding (the old version didn't work with
62% Latex 2e.
63
64\DeclareRobustCommand\hackscore{%
65 \ifmmode_\else\textunderscore\fi%
66}
67\begingroup
68\catcode`\_\active
69\def\next{%
70 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
71}
72\expandafter\endgroup\next
73
74%
75% This is the old hack, which didn't work with 2e.
76% If you're still using Latex 2.09, you can give it a try if the above fails.
77%
78%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
79%\catcode`\_=12
80%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
Guido van Rossum5badc751992-03-06 10:55:46 +000081
Fred Drakeb37a3951998-02-06 22:52:52 +000082
83%% Lots of index-entry generation support.
84
85% Command to wrap around stuff that refers to function/module/attribute names
86% in the index. Default behavior: like \code{}. To just keep the index
87% entries in the roman font, uncomment the second definition to use instead;
88% it matches O'Reilly style more.
89\newcommand{\idxcode}[1]{\codefont{#1}}
90%\renewcommand{\idxcode}[1]{#1}
Guido van Rossum5badc751992-03-06 10:55:46 +000091
92% Command to generate two index entries (using subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +000093\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +000094
95% And three entries (using only one level of subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +000096\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
Guido van Rossum5badc751992-03-06 10:55:46 +000097
98% And four (again, using only one level of subentries)
99\newcommand{\indexiv}[4]{
100\index{#1!#2 #3 #4}
101\index{#2!#3 #4, #1}
102\index{#3!#4, #1 #2}
103\index{#4!#1 #2 #3}
104}
105
106% Command to generate a reference to a function, statement, keyword, operator
Fred Drakeb37a3951998-02-06 22:52:52 +0000107\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
108\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
109\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Guido van Rossum6886c831992-04-03 14:44:27 +0000110\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakeb37a3951998-02-06 22:52:52 +0000111\newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1}} (built-in function)}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000112
113% Add an index entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000114\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake4af18141997-12-15 22:08:14 +0000115\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000116\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
117\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
118
Fred Drakeda941ef1998-01-02 02:57:41 +0000119% support for the module index
120\newwrite\modindexfile
121\openout\modindexfile=modules.idx
122
Fred Drake207e57b1997-12-15 21:37:45 +0000123% Add the defining entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000124\newcommand{\defmodindex}[2]{%
125 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
Fred Drakeda941ef1998-01-02 02:57:41 +0000126 \write\modindexfile{#1 \thepage}}
Fred Drakeb1927471998-02-04 14:43:36 +0000127\newcommand{\modindex}[1]{\defmodindex{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000128\newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }}
129\newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }}
Guido van Rossum5badc751992-03-06 10:55:46 +0000130
131% Additional string for an index entry
132\newcommand{\indexsubitem}{}
Fred Drake06f169b1998-02-11 23:08:20 +0000133\newcommand{\setindexsubitem}[1]{\renewcommand{\indexsubitem}{#1}}
Fred Drakeb37a3951998-02-06 22:52:52 +0000134\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \indexsubitem}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000135
Guido van Rossum5badc751992-03-06 10:55:46 +0000136
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000137% from user-level, fulllineitems should be called as an environment
138\def\fulllineitems{\list{}{\labelwidth \leftmargin \labelsep 0pt
139\rightmargin 0pt \topsep -\parskip \partopsep \parskip
140\itemsep -\parsep
141\let\makelabel\itemnewline}}
142\let\endfulllineitems\endlist
143
144
Guido van Rossum36f35021997-05-22 20:43:24 +0000145% cfuncdesc should be called as
146% \begin{cfuncdesc}{type}{name}{arglist}
147% ... description ...
148% \end{cfuncdesc}
Fred Drakeeb33c781996-10-29 15:55:08 +0000149\newcommand{\cfuncline}[3]{\item[\code{#1 #2(\varvars{#3})}]\ttindex{#2}}
150\newcommand{\cfuncdesc}[3]{\fulllineitems\cfuncline{#1}{#2}{#3}}
151\let\endcfuncdesc\endfulllineitems
152
Guido van Rossum36f35021997-05-22 20:43:24 +0000153\newcommand{\cvarline}[2]{\item[\code{#1 #2}]\ttindex{#2}}
154\newcommand{\cvardesc}[2]{\fulllineitems\cvarline{#1}{#2}}
155\let\endcvardesc\endfulllineitems
156
157\newcommand{\ctypeline}[1]{\item[\code{#1}]\ttindex{#1}}
158\newcommand{\ctypedesc}[1]{\fulllineitems\ctypeline{#1}}
159\let\endctypedesc\endfulllineitems
160
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000161% funcdesc should be called as an \begin{funcdesc} ... \end{funcdesc}
162\newcommand{\funcline}[2]{\item[\code{#1(\varvars{#2})}]\ttindex{#1}}
163\newcommand{\funcdesc}[2]{\fulllineitems\funcline{#1}{#2}}
164\let\endfuncdesc\endfulllineitems
Fred Drake6c886a81998-01-12 14:44:33 +0000165\newcommand{\optional}[1]{{\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}} }
Guido van Rossum16d6e711994-08-08 12:30:22 +0000166
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000167
168% same for excdesc
169\newcommand{\excline}[1]{\item[\code{#1}]\ttindex{#1}}
170\newcommand{\excdesc}[1]{\fulllineitems\excline{#1}}
171\let\endexcdesc\endfulllineitems
172
173% same for datadesc
174\newcommand{\dataline}[1]{\item[\code{#1}]\ttindex{#1}}
175\newcommand{\datadesc}[1]{\fulllineitems\dataline{#1}}
176\let\enddatadesc\endfulllineitems
177
178
Fred Drakea610f9f1997-12-03 03:42:39 +0000179% opcodedesc should be called as an \begin{opcodedesc} ... \end{opcodedesc}
180\newcommand{\opcodeline}[2]{\item[\code{#1\quad\varvars{#2}}]\ttindex{#1}}
181\newcommand{\opcodedesc}[2]{\fulllineitems\opcodeline{#1}{#2}}
182\let\endopcodedesc\endfulllineitems
183
184
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000185\let\nodename=\label
186
Fred Drake30824241996-12-13 21:53:07 +0000187%% For these commands, use \command{} to get the typography right, not
188%% {\command}. This works better with the texinfo translation.
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000189\newcommand{\ABC}{{\sc abc}}
190\newcommand{\UNIX}{{\sc Unix}}
Fred Drake311c1961998-01-20 05:07:19 +0000191\newcommand{\POSIX}{POSIX}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000192\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000193\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000194\newcommand{\C}{C}
195\newcommand{\EOF}{{\sc eof}}
Guido van Rossum9231c8f1997-05-15 21:43:21 +0000196\newcommand{\NULL}{\code{NULL}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000197
198% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000199\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 Drake9e243091998-01-18 05:09:54 +0000200\mbox{\codefont{#1}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000201
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000202\newcommand{\kbd}[1]{\mbox{\tt #1}}
203\newcommand{\key}[1]{\mbox{\tt #1}}
204\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
Fred Drake9e243091998-01-18 05:09:54 +0000205% This weird definition of \var{} allows it to always appear in roman italics,
Fred Drake06f169b1998-02-11 23:08:20 +0000206% and won't get funky in code fragments when we play around with fonts.
Fred Drake9e243091998-01-18 05:09:54 +0000207\newcommand{\var}[1]{\mbox{\textrm{\textit{#1\/}}}}
Guido van Rossum45416021995-03-30 16:00:58 +0000208\newcommand{\dfn}[1]{{\em #1\/}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000209\renewcommand{\emph}[1]{{\em #1\/}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000210\newcommand{\strong}[1]{{\bf #1}}
Fred Drake06f169b1998-02-11 23:08:20 +0000211% let's experiment with a new font:
212\newcommand{\file}[1]{\mbox{`\textsf{#1}'}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000213
Fred Drake9b550d91996-11-11 20:43:46 +0000214\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000215
216\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000217\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000218
Fred Drake311c1961998-01-20 05:07:19 +0000219% Proposed new macros: These should be used for all references to identifiers
220% which are used to refer to instances of specific language constructs. See
221% the names for specific semantic assignments.
222%
Fred Drakedd28d571998-01-22 15:55:21 +0000223% For now, don't do anything really fancy with them; just use them as logical
224% markup. This might change in the future.
Fred Drake311c1961998-01-20 05:07:19 +0000225%
226\let\module=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000227\let\keyword=\code
228\let\exception=\code
Fred Drake311c1961998-01-20 05:07:19 +0000229\let\class=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000230\let\function=\code
231\let\cfunction=\code
232\let\method=\code
233
234% constants defined in Python modules, not language constants:
235\let\constant=\code
Fred Drake311c1961998-01-20 05:07:19 +0000236
237\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
Fred Drake06f169b1998-02-11 23:08:20 +0000238\newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}}
Fred Drake311c1961998-01-20 05:07:19 +0000239\let\email=\code
240\let\url=\code
241
242
Guido van Rossume7af5a01994-08-01 12:39:35 +0000243\newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3&#4\\
244\hline}{\hline\end{tabular}\end{center}}
245
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000246\newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3&#4&#5\\
247\hline}{\hline\end{tabular}\end{center}}
248
249\newcommand{\itemnewline}[1]{\@tempdima\linewidth
250\advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}}
251
Fred Drake9e243091998-01-18 05:09:54 +0000252\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000253
254% Cross-referencing (AMK)
255% Sample usage:
256% \begin{seealso}
257% \seemodule{rand}{Uniform random number generator}; % Module xref
258% \seetext{{\em Encyclopedia Britannica}}. % Ref to a book
259% \end{seealso}
260
Fred Drake6c886a81998-01-12 14:44:33 +0000261\newenvironment{seealso}[0]{{\bf See Also:}\par}{\par}
Fred Drake0f026281998-01-22 17:43:15 +0000262\newcommand{\seemodule}[2]{\ref{module-#1}: \module{#1}\quad(#2)}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000263\newcommand{\seetext}[1]{\par{#1}}
Fred Drakeda941ef1998-01-02 02:57:41 +0000264
265% Fix the theindex environment to add an entry to the Table of Contents;
266% this is much nicer than just having to jump to the end of the book and
267% flip around, especially with multiple indexes.
268%
269\let\OldTheindex=\theindex
Fred Drake06f169b1998-02-11 23:08:20 +0000270\renewcommand{\theindex}{%
Fred Drakeda941ef1998-01-02 02:57:41 +0000271 \OldTheindex%
272 \addcontentsline{toc}{chapter}{\indexname}%
273}
Fred Drake031ad4b1998-01-09 05:34:23 +0000274
275% Use a similar trick to catch the end of the {abstract} environment,
276% but here make sure the abstract is followed by a blank page if the
277% 'openright' option is used.
278%
279\let\OldEndAbstract=\endabstract
Fred Drake06f169b1998-02-11 23:08:20 +0000280\renewcommand{\endabstract}{
Fred Drake737e73e1998-01-13 22:40:08 +0000281 \if@openright
282 \ifodd\value{page}
283 \typeout{Adding blank page after the abstract.}
284 \vfil\pagebreak
Fred Drake031ad4b1998-01-09 05:34:23 +0000285 \fi
Fred Drake737e73e1998-01-13 22:40:08 +0000286 \fi
287 \OldEndAbstract
Fred Drake031ad4b1998-01-09 05:34:23 +0000288}
289
290% \mytableofcontents wraps the \tableofcontents macro with all the magic to
291% get the spacing right and have the right number of pages if the 'openright'
292% option has been used. This eliminates a fair amount of crud in the
293% individual document files.
294%
Fred Drake737e73e1998-01-13 22:40:08 +0000295\let\OldTableofcontents=\tableofcontents
Fred Drake06f169b1998-02-11 23:08:20 +0000296\renewcommand{\tableofcontents}[0]{%
297 \setcounter{page}{1}%
298 \pagebreak%
299 \pagestyle{plain}%
300 {%
301 \parskip = 0mm%
302 \OldTableofcontents%
303 \if@openright%
304 \ifodd\value{page}%
305 \typeout{Adding blank page after the table of contents.}%
306 \pagebreak\hspace{0pt}%
307 \fi%
308 \fi%
309 }%
310 \pagebreak%
311}
312
313% Allow the release number to be specified independently of the \date{}. This
314% allows the date to reflect the document's date and release to specify the
315% Python release that is documented.
316\newcommand{\@release}{}
317\newcommand{\version}{}
318\newcommand{\releasename}{Release}
319\newcommand{\release}[1]{%
320 \renewcommand{\@release}{\releasename\space\version}%
321 \renewcommand{\version}{#1}%
322}
323
324% Allow specification of the author's address separately from the author's
325% name. This can be used to format them differently, which is a good thing.
326\newcommand{\@authoraddress}{}
327\newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}}
328
329% Change the title page to look a bit better, and fit in with the fncychap
330% ``Bjarne'' style a bit better.
331\renewcommand{\maketitle}{\begin{titlepage}%
332 \let\footnotesize\small
333 \let\footnoterule\relax
334 \@ifundefined{ChTitleVar}{}{%
335 \mghrulefill{\RW}}%
336 \begin{flushright}%
337 {\huge \@title \par}%
338 {\em\LARGE \@release \par}
339 \vfill
340 {\LARGE \@author \par}
341 \vfill\vfill
342 {\large
343 \@date \par
344 \vskip 3em
345 \@authoraddress \par
346 }%
347 \end{flushright}%\par
348 \@thanks
349 \end{titlepage}%
350 \setcounter{footnote}{0}%
351 \let\thanks\relax\let\maketitle\relax
352 \gdef\@thanks{}\gdef\@author{}\gdef\@title{}
353}
354
355% ``minitoc'' support; works fairly well but not all chapters do well with it.
356% Has some weird side effects that I haven't tracked down; don't use it for
357% real at this time.
358%
359% To enable, uncomment the following line only:
360%\RequirePackage{minitoc}
361
362% Leave the rest as-is:
363\newif\if@minitocprinted
364\newcommand{\suppressminitoc}{\@minitocprintedtrue}
365\@ifundefined{minitoc}{
366 % allow \minitoc to be used even if the package hasn't been loaded.
367 \newcommand{\minitoc}{\@minitocprintedtrue}
368}{
369 \dominitoc
370 \newif\if@firstsection
371 \let\OldChapter=\chapter
372 \let\OldSection=\section
373 \let\OldMinitoc=\minitoc
374 % This will only include the minitoc once per chapter
375 \renewcommand{\minitoc}{%
376 \if@minitocprinted{}\else%
377 \OldMinitoc%
378 \@minitocprintedtrue%
379 \fi%
Fred Drake031ad4b1998-01-09 05:34:23 +0000380 }
Fred Drake06f169b1998-02-11 23:08:20 +0000381 % This includes a minitoc before the first \section{}, if it hasn't
382 % already been printed using an explicit \minitoc call.
383 \newcommand{\NewSection}[1]{%
384 \if@firstsection%
385 \if@minitocprinted{}\else%
386 \vskip 15pt%
387 \minitoc%
388 \@firstsectionfalse%
389 \fi%
390 \fi%
391 \OldSection{#1}%
392 }
393 % Reset the flags for each chaper to let the automatic stuff work.
394 \newcommand{\NewChapter}[1]{%
395 \OldChapter{#1}%
396 \@firstsectiontrue%
397 \@minitocprintedfalse%
398 }
399 \let\chapter=\NewChapter
400 \let\section=\NewSection
401 \typeout{Including mini Tables of Contents in each chapter.}
402}
403
404% This sets up the fancy chapter headings that make the documents look at
405% least a little better than the usual LaTeX output.
406%
407\RequirePackage[Bjarne]{fncychap}
408\@ifundefined{ChTitleVar}{}{
409 \ChTitleVar{\raggedleft \rm\Huge}
410 % This creates chapter heads without the leading \vspace*{}:
411 \def\@makechapterhead#1{%
412 {\parindent \z@ \raggedright \normalfont
413 \ifnum \c@secnumdepth >\m@ne
414 \DOCH
415 \fi
416 \interlinepenalty\@M
417 \DOTI{#1}
418 }
419 }
420 \typeout{Using fancy chapter headings.}
Fred Drake031ad4b1998-01-09 05:34:23 +0000421}
Fred Drake8362d001998-01-13 17:29:31 +0000422
423% Uncomment the following line to use a PostScript font instead of bitmaps:
Fred Drakeb16166e1998-02-09 19:14:54 +0000424\RequirePackage{times}\typeout{Using times fonts instead of Computer Modern.}