blob: 4a02d927fdb934f008a77f340494c6ce0ccfaf58 [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
9
10\textheight 8.9in
11
12\oddsidemargin 0pt
13\evensidemargin \oddsidemargin
14\marginparwidth 0.5in
15
16\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
Guido van Rossum4c22cb21991-01-25 13:28:15 +000024% Variable used by begin code command
Guido van Rossum44000ed1991-01-24 16:54:29 +000025\newlength{\codewidth}
Guido van Rossum44000ed1991-01-24 16:54:29 +000026
Guido van Rossum5badc751992-03-06 10:55:46 +000027% Command to start a code block (follow this by \begin{verbatim})
Guido van Rossum4c22cb21991-01-25 13:28:15 +000028\newcommand{\bcode}{
29 % Calculate the text width for the minipage:
30 \setlength{\codewidth}{\linewidth}
31 \addtolength{\codewidth}{-\parindent}
32 %
Guido van Rossum4c22cb21991-01-25 13:28:15 +000033 \par
Guido van Rossum92fba021991-11-12 15:44:51 +000034 \vspace{3mm}
Guido van Rossum4c22cb21991-01-25 13:28:15 +000035 \indent
36 \begin{minipage}[t]{\codewidth}
37}
38
Guido van Rossum5badc751992-03-06 10:55:46 +000039% Command to end a code block (precede this by \end{verbatim})
Guido van Rossum4c22cb21991-01-25 13:28:15 +000040\newcommand{\ecode}{
41 \end{minipage}
42 \vspace{3mm}
43 \par
44 \noindent
45}
Guido van Rossum5badc751992-03-06 10:55:46 +000046
Guido van Rossumecae0b71996-06-26 19:03:20 +000047% Underscore hack (only act like subscript operator if in math mode)
48%
49% The following is due to Mark Wooding (the old version didn't work with
50% Latex 2e.
51
52\DeclareRobustCommand\hackscore{%
53 \ifmmode_\else\textunderscore\fi%
54}
55\begingroup
56\catcode`\_\active
57\def\next{%
58 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
59}
60\expandafter\endgroup\next
61
62%
63% This is the old hack, which didn't work with 2e.
64% If you're still using Latex 2.09, you can give it a try if the above fails.
65%
66%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
67%\catcode`\_=12
68%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
Guido van Rossum5badc751992-03-06 10:55:46 +000069
Guido van Rossum5badc751992-03-06 10:55:46 +000070% Define \itembreak: force the text after an item to start on a new line
71\newcommand{\itembreak}{
72\mbox{}
73\\*[0mm]
74}
75
76% Command to generate two index entries (using subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +000077\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +000078
79% And three entries (using only one level of subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +000080\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
Guido van Rossum5badc751992-03-06 10:55:46 +000081
82% And four (again, using only one level of subentries)
83\newcommand{\indexiv}[4]{
84\index{#1!#2 #3 #4}
85\index{#2!#3 #4, #1}
86\index{#3!#4, #1 #2}
87\index{#4!#1 #2 #3}
88}
89
90% Command to generate a reference to a function, statement, keyword, operator
91\newcommand{\stindex}[1]{\indexii{statement}{#1@{\tt#1}}}
92\newcommand{\kwindex}[1]{\indexii{keyword}{#1@{\tt#1}}}
93\newcommand{\opindex}[1]{\indexii{operator}{#1@{\tt#1}}}
Guido van Rossum6886c831992-04-03 14:44:27 +000094\newcommand{\exindex}[1]{\indexii{exception}{#1@{\tt#1}}}
95\newcommand{\obindex}[1]{\indexii{object}{#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +000096\newcommand{\bifuncindex}[1]{\index{#1@{\tt#1} (built-in function)}}
97
98% Add an index entry for a module
Fred Drake207e57b1997-12-15 21:37:45 +000099\newcommand{\refmodule}[2]{\index{#1@{\tt#1} (#2module)}}
Fred Drake4af18141997-12-15 22:08:14 +0000100\newcommand{\refmodindex}[1]{\refmodule{#1}{}}
Fred Drake207e57b1997-12-15 21:37:45 +0000101\newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }}
102\newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }}
103
Fred Drakeda941ef1998-01-02 02:57:41 +0000104% support for the module index
105\newwrite\modindexfile
106\openout\modindexfile=modules.idx
107
Fred Drake207e57b1997-12-15 21:37:45 +0000108% Add the defining entry for a module
Fred Drakeda941ef1998-01-02 02:57:41 +0000109\newcommand{\defmodindex}[2]{\index{#1@{\tt#1} (#2module)|textbf}%
110 \write\modindexfile{#1 \thepage}}
Fred Drake207e57b1997-12-15 21:37:45 +0000111\newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }}
112\newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }}
Guido van Rossum5badc751992-03-06 10:55:46 +0000113
114% Additional string for an index entry
115\newcommand{\indexsubitem}{}
116\newcommand{\ttindex}[1]{\index{#1@{\tt#1} \indexsubitem}}
117
118% Define \itemjoin: some negative vspace to join two items together
119\newcommand{\itemjoin}{
120\mbox{}
121\vspace{-\itemsep}
122\vspace{-\parsep}
123}
124
125% Define \funcitem{func}{args}: define a function item
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000126\newcommand{\funcitem}[2]{%
127\ttindex{#1}%
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000128\item[\code{#1(\varvars{#2})}]
Guido van Rossum5badc751992-03-06 10:55:46 +0000129\
130}
131
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000132
133% from user-level, fulllineitems should be called as an environment
134\def\fulllineitems{\list{}{\labelwidth \leftmargin \labelsep 0pt
135\rightmargin 0pt \topsep -\parskip \partopsep \parskip
136\itemsep -\parsep
137\let\makelabel\itemnewline}}
138\let\endfulllineitems\endlist
139
140
Guido van Rossum36f35021997-05-22 20:43:24 +0000141% cfuncdesc should be called as
142% \begin{cfuncdesc}{type}{name}{arglist}
143% ... description ...
144% \end{cfuncdesc}
Fred Drakeeb33c781996-10-29 15:55:08 +0000145\newcommand{\cfuncline}[3]{\item[\code{#1 #2(\varvars{#3})}]\ttindex{#2}}
146\newcommand{\cfuncdesc}[3]{\fulllineitems\cfuncline{#1}{#2}{#3}}
147\let\endcfuncdesc\endfulllineitems
148
Guido van Rossum36f35021997-05-22 20:43:24 +0000149\newcommand{\cvarline}[2]{\item[\code{#1 #2}]\ttindex{#2}}
150\newcommand{\cvardesc}[2]{\fulllineitems\cvarline{#1}{#2}}
151\let\endcvardesc\endfulllineitems
152
153\newcommand{\ctypeline}[1]{\item[\code{#1}]\ttindex{#1}}
154\newcommand{\ctypedesc}[1]{\fulllineitems\ctypeline{#1}}
155\let\endctypedesc\endfulllineitems
156
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000157% funcdesc should be called as an \begin{funcdesc} ... \end{funcdesc}
158\newcommand{\funcline}[2]{\item[\code{#1(\varvars{#2})}]\ttindex{#1}}
159\newcommand{\funcdesc}[2]{\fulllineitems\funcline{#1}{#2}}
160\let\endfuncdesc\endfulllineitems
Fred Drake6c886a81998-01-12 14:44:33 +0000161\newcommand{\optional}[1]{{\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}} }
Guido van Rossum16d6e711994-08-08 12:30:22 +0000162
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000163
164% same for excdesc
165\newcommand{\excline}[1]{\item[\code{#1}]\ttindex{#1}}
166\newcommand{\excdesc}[1]{\fulllineitems\excline{#1}}
167\let\endexcdesc\endfulllineitems
168
169% same for datadesc
170\newcommand{\dataline}[1]{\item[\code{#1}]\ttindex{#1}}
171\newcommand{\datadesc}[1]{\fulllineitems\dataline{#1}}
172\let\enddatadesc\endfulllineitems
173
174
Fred Drakea610f9f1997-12-03 03:42:39 +0000175% opcodedesc should be called as an \begin{opcodedesc} ... \end{opcodedesc}
176\newcommand{\opcodeline}[2]{\item[\code{#1\quad\varvars{#2}}]\ttindex{#1}}
177\newcommand{\opcodedesc}[2]{\fulllineitems\opcodeline{#1}{#2}}
178\let\endopcodedesc\endfulllineitems
179
180
Guido van Rossum5badc751992-03-06 10:55:46 +0000181% Define \dataitem{name}: define a data item
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000182\newcommand{\dataitem}[1]{%
183\ttindex{#1}%
Guido van Rossum5badc751992-03-06 10:55:46 +0000184\item[{\tt #1}]
185\
186}
187
188% Define \excitem{name}: define an exception item
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000189\newcommand{\excitem}[1]{%
190\ttindex{#1}%
Guido van Rossum5badc751992-03-06 10:55:46 +0000191\item[{\tt #1}]
192\itembreak
193}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000194
195\let\nodename=\label
196
Fred Drake30824241996-12-13 21:53:07 +0000197%% For these commands, use \command{} to get the typography right, not
198%% {\command}. This works better with the texinfo translation.
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000199\newcommand{\ABC}{{\sc abc}}
200\newcommand{\UNIX}{{\sc Unix}}
201\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000202\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000203\newcommand{\C}{C}
204\newcommand{\EOF}{{\sc eof}}
Guido van Rossum9231c8f1997-05-15 21:43:21 +0000205\newcommand{\NULL}{\code{NULL}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000206
207% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000208\newcommand{\code}[1]{{\@vobeyspaces\@noligs\def\{{\char`\{}\def\}{\char`\}}\def\~{\char`\~}\def\^{\char`\^}\def\e{\char`\\}\def\${\char`\$}\def\#{\char`\#}\def\&{\char`\&}\def\%{\char`\%}%
209\mbox{\tt #1}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000210
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000211\newcommand{\kbd}[1]{\mbox{\tt #1}}
212\newcommand{\key}[1]{\mbox{\tt #1}}
213\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
214\newcommand{\var}[1]{\mbox{\it#1\/}}
215\let\file=\samp
Guido van Rossum45416021995-03-30 16:00:58 +0000216\newcommand{\dfn}[1]{{\em #1\/}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000217\renewcommand{\emph}[1]{{\em #1\/}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000218\newcommand{\strong}[1]{{\bf #1}}
219
Fred Drake9b550d91996-11-11 20:43:46 +0000220\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000221
222\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000223\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000224
Guido van Rossume7af5a01994-08-01 12:39:35 +0000225\newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3&#4\\
226\hline}{\hline\end{tabular}\end{center}}
227
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000228\newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3&#4&#5\\
229\hline}{\hline\end{tabular}\end{center}}
230
231\newcommand{\itemnewline}[1]{\@tempdima\linewidth
232\advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}}
233
234\newcommand{\sectcode}[1]{{\tt #1}}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000235
236% Cross-referencing (AMK)
237% Sample usage:
238% \begin{seealso}
239% \seemodule{rand}{Uniform random number generator}; % Module xref
240% \seetext{{\em Encyclopedia Britannica}}. % Ref to a book
241% \end{seealso}
242
Fred Drake6c886a81998-01-12 14:44:33 +0000243\newenvironment{seealso}[0]{{\bf See Also:}\par}{\par}
Guido van Rossume3d5fc51997-07-17 18:27:53 +0000244\newcommand{\seemodule}[2]{\ref{module-#1}: {\tt #1} (#2)}
245\newcommand{\seetext}[1]{\par{#1}}
Fred Drakeda941ef1998-01-02 02:57:41 +0000246
247% Fix the theindex environment to add an entry to the Table of Contents;
248% this is much nicer than just having to jump to the end of the book and
249% flip around, especially with multiple indexes.
250%
251\let\OldTheindex=\theindex
252\def\theindex{%
253 \OldTheindex%
254 \addcontentsline{toc}{chapter}{\indexname}%
255}
Fred Drake031ad4b1998-01-09 05:34:23 +0000256
257% Use a similar trick to catch the end of the {abstract} environment,
258% but here make sure the abstract is followed by a blank page if the
259% 'openright' option is used.
260%
261\let\OldEndAbstract=\endabstract
262\def\endabstract{%
263 \if@openright%
264 \ifodd\value{page}%
265 \typeout{Adding blank page after the abstract.}%
266 \vfil\pagebreak%
267 \fi
268 \fi%
269 \OldEndAbstract%
270}
271
272% \mytableofcontents wraps the \tableofcontents macro with all the magic to
273% get the spacing right and have the right number of pages if the 'openright'
274% option has been used. This eliminates a fair amount of crud in the
275% individual document files.
276%
277\newcommand{\mytableofcontents}{%
278 \pagebreak%
279 \pagestyle{plain}%
280 {%
281 \parskip = 0mm%
282 \tableofcontents
283 \if@openright
284 \ifodd\value{page}%
285 \typeout{Adding blank page after the table of contents.}%
286 \pagebreak\hspace{0pt}%
287 \fi
288 \fi
289 }
290 \pagebreak%
291}
Fred Drake8362d001998-01-13 17:29:31 +0000292
293% Uncomment the following line to use a PostScript font instead of bitmaps:
294%\RequirePackage{times}\typeout{Using times fonts instead of Computer Modern.}