blob: 0eadab8c0a3242d774bec7b1b779bb46df91f234 [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
Guido van Rossumdaff1751997-06-02 17:35:01 +00005% Increase printable page size (copied from fullpage.sty)
6\topmargin 0pt
7\advance \topmargin by -\headheight
8\advance \topmargin by -\headsep
Fred Drake9e243091998-01-18 05:09:54 +00009
Guido van Rossumdaff1751997-06-02 17:35:01 +000010\textheight 8.9in
Fred Drake9e243091998-01-18 05:09:54 +000011
Guido van Rossumdaff1751997-06-02 17:35:01 +000012\oddsidemargin 0pt
13\evensidemargin \oddsidemargin
14\marginparwidth 0.5in
Fred Drake9e243091998-01-18 05:09:54 +000015
Guido van Rossumdaff1751997-06-02 17:35:01 +000016\textwidth 6.5in
17
Guido van Rossum643d9321992-03-31 18:53:47 +000018% Style parameters and macros used by most documents here
Guido van Rossum5badc751992-03-06 10:55:46 +000019\raggedbottom
20\sloppy
21\parindent = 0mm
22\parskip = 2mm
23
Fred Drake9e243091998-01-18 05:09:54 +000024% old code font selections:
25\let\codefont=\tt
26\let\sectcodefont=\tt
27
28% (Haven't found a new one that gets <, >, and _ right without being
29% monospaced.)
30
Guido van Rossum4c22cb21991-01-25 13:28:15 +000031% Variable used by begin code command
Guido van Rossum44000ed1991-01-24 16:54:29 +000032\newlength{\codewidth}
Guido van Rossum44000ed1991-01-24 16:54:29 +000033
Guido van Rossum5badc751992-03-06 10:55:46 +000034% Command to start a code block (follow this by \begin{verbatim})
Guido van Rossum4c22cb21991-01-25 13:28:15 +000035\newcommand{\bcode}{
36 % Calculate the text width for the minipage:
37 \setlength{\codewidth}{\linewidth}
38 \addtolength{\codewidth}{-\parindent}
39 %
Guido van Rossum4c22cb21991-01-25 13:28:15 +000040 \par
Guido van Rossum92fba021991-11-12 15:44:51 +000041 \vspace{3mm}
Guido van Rossum4c22cb21991-01-25 13:28:15 +000042 \indent
43 \begin{minipage}[t]{\codewidth}
44}
45
Guido van Rossum5badc751992-03-06 10:55:46 +000046% Command to end a code block (precede this by \end{verbatim})
Guido van Rossum4c22cb21991-01-25 13:28:15 +000047\newcommand{\ecode}{
48 \end{minipage}
49 \vspace{3mm}
50 \par
51 \noindent
52}
Guido van Rossum5badc751992-03-06 10:55:46 +000053
Guido van Rossumecae0b71996-06-26 19:03:20 +000054% Underscore hack (only act like subscript operator if in math mode)
55%
56% The following is due to Mark Wooding (the old version didn't work with
57% Latex 2e.
58
59\DeclareRobustCommand\hackscore{%
60 \ifmmode_\else\textunderscore\fi%
61}
62\begingroup
63\catcode`\_\active
64\def\next{%
65 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
66}
67\expandafter\endgroup\next
68
69%
70% This is the old hack, which didn't work with 2e.
71% If you're still using Latex 2.09, you can give it a try if the above fails.
72%
73%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
74%\catcode`\_=12
75%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
Guido van Rossum5badc751992-03-06 10:55:46 +000076
Fred Drakeb37a3951998-02-06 22:52:52 +000077
78%% Lots of index-entry generation support.
79
80% Command to wrap around stuff that refers to function/module/attribute names
81% in the index. Default behavior: like \code{}. To just keep the index
82% entries in the roman font, uncomment the second definition to use instead;
83% it matches O'Reilly style more.
84\newcommand{\idxcode}[1]{\codefont{#1}}
85%\renewcommand{\idxcode}[1]{#1}
Guido van Rossum5badc751992-03-06 10:55:46 +000086
87% Command to generate two index entries (using subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +000088\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +000089
90% And three entries (using only one level of subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +000091\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
Guido van Rossum5badc751992-03-06 10:55:46 +000092
93% And four (again, using only one level of subentries)
94\newcommand{\indexiv}[4]{
95\index{#1!#2 #3 #4}
96\index{#2!#3 #4, #1}
97\index{#3!#4, #1 #2}
98\index{#4!#1 #2 #3}
99}
100
101% Command to generate a reference to a function, statement, keyword, operator
Fred Drakeb37a3951998-02-06 22:52:52 +0000102\newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}}
103\newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}}
104\newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}}
Guido van Rossum6886c831992-04-03 14:44:27 +0000105\newcommand{\obindex}[1]{\indexii{object}{#1}}
Fred Drakeb37a3951998-02-06 22:52:52 +0000106\newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1}} (built-in function)}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000107
108% Add an index entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000109\newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}}
Fred Drake4af18141997-12-15 22:08:14 +0000110\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000111\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
112\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
113
Fred Drakeda941ef1998-01-02 02:57:41 +0000114% support for the module index
115\newwrite\modindexfile
116\openout\modindexfile=modules.idx
117
Fred Drake207e57b1997-12-15 21:37:45 +0000118% Add the defining entry for a module
Fred Drakeb37a3951998-02-06 22:52:52 +0000119\newcommand{\defmodindex}[2]{%
120 \index{#1@{\idxcode{#1}} (#2module)|textbf}%
Fred Drakeda941ef1998-01-02 02:57:41 +0000121 \write\modindexfile{#1 \thepage}}
Fred Drakeb1927471998-02-04 14:43:36 +0000122\newcommand{\modindex}[1]{\defmodindex{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000123\newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }}
124\newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }}
Guido van Rossum5badc751992-03-06 10:55:46 +0000125
126% Additional string for an index entry
127\newcommand{\indexsubitem}{}
Fred Drakeb37a3951998-02-06 22:52:52 +0000128\newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \indexsubitem}}
Guido van Rossum5badc751992-03-06 10:55:46 +0000129
Guido van Rossum5badc751992-03-06 10:55:46 +0000130
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000131% from user-level, fulllineitems should be called as an environment
132\def\fulllineitems{\list{}{\labelwidth \leftmargin \labelsep 0pt
133\rightmargin 0pt \topsep -\parskip \partopsep \parskip
134\itemsep -\parsep
135\let\makelabel\itemnewline}}
136\let\endfulllineitems\endlist
137
138
Guido van Rossum36f35021997-05-22 20:43:24 +0000139% cfuncdesc should be called as
140% \begin{cfuncdesc}{type}{name}{arglist}
141% ... description ...
142% \end{cfuncdesc}
Fred Drakeeb33c781996-10-29 15:55:08 +0000143\newcommand{\cfuncline}[3]{\item[\code{#1 #2(\varvars{#3})}]\ttindex{#2}}
144\newcommand{\cfuncdesc}[3]{\fulllineitems\cfuncline{#1}{#2}{#3}}
145\let\endcfuncdesc\endfulllineitems
146
Guido van Rossum36f35021997-05-22 20:43:24 +0000147\newcommand{\cvarline}[2]{\item[\code{#1 #2}]\ttindex{#2}}
148\newcommand{\cvardesc}[2]{\fulllineitems\cvarline{#1}{#2}}
149\let\endcvardesc\endfulllineitems
150
151\newcommand{\ctypeline}[1]{\item[\code{#1}]\ttindex{#1}}
152\newcommand{\ctypedesc}[1]{\fulllineitems\ctypeline{#1}}
153\let\endctypedesc\endfulllineitems
154
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000155% funcdesc should be called as an \begin{funcdesc} ... \end{funcdesc}
156\newcommand{\funcline}[2]{\item[\code{#1(\varvars{#2})}]\ttindex{#1}}
157\newcommand{\funcdesc}[2]{\fulllineitems\funcline{#1}{#2}}
158\let\endfuncdesc\endfulllineitems
Fred Drake6c886a81998-01-12 14:44:33 +0000159\newcommand{\optional}[1]{{\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}} }
Guido van Rossum16d6e711994-08-08 12:30:22 +0000160
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000161
162% same for excdesc
163\newcommand{\excline}[1]{\item[\code{#1}]\ttindex{#1}}
164\newcommand{\excdesc}[1]{\fulllineitems\excline{#1}}
165\let\endexcdesc\endfulllineitems
166
167% same for datadesc
168\newcommand{\dataline}[1]{\item[\code{#1}]\ttindex{#1}}
169\newcommand{\datadesc}[1]{\fulllineitems\dataline{#1}}
170\let\enddatadesc\endfulllineitems
171
172
Fred Drakea610f9f1997-12-03 03:42:39 +0000173% opcodedesc should be called as an \begin{opcodedesc} ... \end{opcodedesc}
174\newcommand{\opcodeline}[2]{\item[\code{#1\quad\varvars{#2}}]\ttindex{#1}}
175\newcommand{\opcodedesc}[2]{\fulllineitems\opcodeline{#1}{#2}}
176\let\endopcodedesc\endfulllineitems
177
178
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000179\let\nodename=\label
180
Fred Drake30824241996-12-13 21:53:07 +0000181%% For these commands, use \command{} to get the typography right, not
182%% {\command}. This works better with the texinfo translation.
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000183\newcommand{\ABC}{{\sc abc}}
184\newcommand{\UNIX}{{\sc Unix}}
Fred Drake311c1961998-01-20 05:07:19 +0000185\newcommand{\POSIX}{POSIX}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000186\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000187\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000188\newcommand{\C}{C}
189\newcommand{\EOF}{{\sc eof}}
Guido van Rossum9231c8f1997-05-15 21:43:21 +0000190\newcommand{\NULL}{\code{NULL}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000191
192% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000193\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 +0000194\mbox{\codefont{#1}}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000195
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000196\newcommand{\kbd}[1]{\mbox{\tt #1}}
197\newcommand{\key}[1]{\mbox{\tt #1}}
198\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
Fred Drake9e243091998-01-18 05:09:54 +0000199% This weird definition of \var{} allows it to always appear in roman italics,
200% and won't be sans-serif in code fragments.
201\newcommand{\var}[1]{\mbox{\textrm{\textit{#1\/}}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000202\let\file=\samp
Guido van Rossum45416021995-03-30 16:00:58 +0000203\newcommand{\dfn}[1]{{\em #1\/}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000204\renewcommand{\emph}[1]{{\em #1\/}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000205\newcommand{\strong}[1]{{\bf #1}}
206
Fred Drake9b550d91996-11-11 20:43:46 +0000207\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000208
209\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000210\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000211
Fred Drake311c1961998-01-20 05:07:19 +0000212% Proposed new macros: These should be used for all references to identifiers
213% which are used to refer to instances of specific language constructs. See
214% the names for specific semantic assignments.
215%
Fred Drakedd28d571998-01-22 15:55:21 +0000216% For now, don't do anything really fancy with them; just use them as logical
217% markup. This might change in the future.
Fred Drake311c1961998-01-20 05:07:19 +0000218%
219\let\module=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000220\let\keyword=\code
221\let\exception=\code
Fred Drake311c1961998-01-20 05:07:19 +0000222\let\class=\code
Fred Drakedd28d571998-01-22 15:55:21 +0000223\let\function=\code
224\let\cfunction=\code
225\let\method=\code
226
227% constants defined in Python modules, not language constants:
228\let\constant=\code
Fred Drake311c1961998-01-20 05:07:19 +0000229
230\newcommand{\manpage}[2]{{\emph{#1}(#2)}}
231\let\email=\code
232\let\url=\code
233
234
Guido van Rossume7af5a01994-08-01 12:39:35 +0000235\newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3&#4\\
236\hline}{\hline\end{tabular}\end{center}}
237
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000238\newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3&#4&#5\\
239\hline}{\hline\end{tabular}\end{center}}
240
241\newcommand{\itemnewline}[1]{\@tempdima\linewidth
242\advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}}
243
Fred Drake9e243091998-01-18 05:09:54 +0000244\newcommand{\sectcode}[1]{{\sectcodefont{#1}}}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000245
246% Cross-referencing (AMK)
247% Sample usage:
248% \begin{seealso}
249% \seemodule{rand}{Uniform random number generator}; % Module xref
250% \seetext{{\em Encyclopedia Britannica}}. % Ref to a book
251% \end{seealso}
252
Fred Drake6c886a81998-01-12 14:44:33 +0000253\newenvironment{seealso}[0]{{\bf See Also:}\par}{\par}
Fred Drake0f026281998-01-22 17:43:15 +0000254\newcommand{\seemodule}[2]{\ref{module-#1}: \module{#1}\quad(#2)}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000255\newcommand{\seetext}[1]{\par{#1}}
Fred Drakeda941ef1998-01-02 02:57:41 +0000256
257% Fix the theindex environment to add an entry to the Table of Contents;
258% this is much nicer than just having to jump to the end of the book and
259% flip around, especially with multiple indexes.
260%
261\let\OldTheindex=\theindex
262\def\theindex{%
263 \OldTheindex%
264 \addcontentsline{toc}{chapter}{\indexname}%
265}
Fred Drake031ad4b1998-01-09 05:34:23 +0000266
267% Use a similar trick to catch the end of the {abstract} environment,
268% but here make sure the abstract is followed by a blank page if the
269% 'openright' option is used.
270%
271\let\OldEndAbstract=\endabstract
Fred Drake737e73e1998-01-13 22:40:08 +0000272\def\endabstract{
273 \if@openright
274 \ifodd\value{page}
275 \typeout{Adding blank page after the abstract.}
276 \vfil\pagebreak
Fred Drake031ad4b1998-01-09 05:34:23 +0000277 \fi
Fred Drake737e73e1998-01-13 22:40:08 +0000278 \fi
279 \OldEndAbstract
Fred Drake031ad4b1998-01-09 05:34:23 +0000280}
281
282% \mytableofcontents wraps the \tableofcontents macro with all the magic to
283% get the spacing right and have the right number of pages if the 'openright'
284% option has been used. This eliminates a fair amount of crud in the
285% individual document files.
286%
Fred Drake737e73e1998-01-13 22:40:08 +0000287\let\OldTableofcontents=\tableofcontents
288\def\tableofcontents{%
289 \pagebreak
290 \pagestyle{plain}
291 {
292 \parskip = 0mm
293 \OldTableofcontents
Fred Drake031ad4b1998-01-09 05:34:23 +0000294 \if@openright
Fred Drake737e73e1998-01-13 22:40:08 +0000295 \ifodd\value{page}
296 \typeout{Adding blank page after the table of contents.}
297 \pagebreak\hspace{0pt}
Fred Drake031ad4b1998-01-09 05:34:23 +0000298 \fi
299 \fi
300 }
Fred Drake737e73e1998-01-13 22:40:08 +0000301 \pagebreak
Fred Drake031ad4b1998-01-09 05:34:23 +0000302}
Fred Drake8362d001998-01-13 17:29:31 +0000303
304% Uncomment the following line to use a PostScript font instead of bitmaps:
305%\RequirePackage{times}\typeout{Using times fonts instead of Computer Modern.}