blob: 1887953ddfb16579ca5d2ed4bd4529b8ad3bc855 [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 Rossum643d9321992-03-31 18:53:47 +00005% Style parameters and macros used by most documents here
Guido van Rossum5badc751992-03-06 10:55:46 +00006\raggedbottom
7\sloppy
8\parindent = 0mm
9\parskip = 2mm
10
Guido van Rossum4c22cb21991-01-25 13:28:15 +000011% Variable used by begin code command
Guido van Rossum44000ed1991-01-24 16:54:29 +000012\newlength{\codewidth}
Guido van Rossum44000ed1991-01-24 16:54:29 +000013
Guido van Rossum5badc751992-03-06 10:55:46 +000014% Command to start a code block (follow this by \begin{verbatim})
Guido van Rossum4c22cb21991-01-25 13:28:15 +000015\newcommand{\bcode}{
16 % Calculate the text width for the minipage:
17 \setlength{\codewidth}{\linewidth}
18 \addtolength{\codewidth}{-\parindent}
19 %
Guido van Rossum4c22cb21991-01-25 13:28:15 +000020 \par
Guido van Rossum92fba021991-11-12 15:44:51 +000021 \vspace{3mm}
Guido van Rossum4c22cb21991-01-25 13:28:15 +000022 \indent
23 \begin{minipage}[t]{\codewidth}
24}
25
Guido van Rossum5badc751992-03-06 10:55:46 +000026% Command to end a code block (precede this by \end{verbatim})
Guido van Rossum4c22cb21991-01-25 13:28:15 +000027\newcommand{\ecode}{
28 \end{minipage}
29 \vspace{3mm}
30 \par
31 \noindent
32}
Guido van Rossum5badc751992-03-06 10:55:46 +000033
Guido van Rossumecae0b71996-06-26 19:03:20 +000034% Underscore hack (only act like subscript operator if in math mode)
35%
36% The following is due to Mark Wooding (the old version didn't work with
37% Latex 2e.
38
39\DeclareRobustCommand\hackscore{%
40 \ifmmode_\else\textunderscore\fi%
41}
42\begingroup
43\catcode`\_\active
44\def\next{%
45 \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
46}
47\expandafter\endgroup\next
48
49%
50% This is the old hack, which didn't work with 2e.
51% If you're still using Latex 2.09, you can give it a try if the above fails.
52%
53%\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi}
54%\catcode`\_=12
55%\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi}
Guido van Rossum5badc751992-03-06 10:55:46 +000056
Guido van Rossum5badc751992-03-06 10:55:46 +000057% Define \itembreak: force the text after an item to start on a new line
58\newcommand{\itembreak}{
59\mbox{}
60\\*[0mm]
61}
62
63% Command to generate two index entries (using subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +000064\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +000065
66% And three entries (using only one level of subentries)
Guido van Rossum16d6e711994-08-08 12:30:22 +000067\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
Guido van Rossum5badc751992-03-06 10:55:46 +000068
69% And four (again, using only one level of subentries)
70\newcommand{\indexiv}[4]{
71\index{#1!#2 #3 #4}
72\index{#2!#3 #4, #1}
73\index{#3!#4, #1 #2}
74\index{#4!#1 #2 #3}
75}
76
77% Command to generate a reference to a function, statement, keyword, operator
78\newcommand{\stindex}[1]{\indexii{statement}{#1@{\tt#1}}}
79\newcommand{\kwindex}[1]{\indexii{keyword}{#1@{\tt#1}}}
80\newcommand{\opindex}[1]{\indexii{operator}{#1@{\tt#1}}}
Guido van Rossum6886c831992-04-03 14:44:27 +000081\newcommand{\exindex}[1]{\indexii{exception}{#1@{\tt#1}}}
82\newcommand{\obindex}[1]{\indexii{object}{#1}}
Guido van Rossum5badc751992-03-06 10:55:46 +000083\newcommand{\bifuncindex}[1]{\index{#1@{\tt#1} (built-in function)}}
84
85% Add an index entry for a module
86\newcommand{\modindex}[2]{\index{#1@{\tt#1} (#2module)}}
87\newcommand{\bimodindex}[1]{\modindex{#1}{built-in }}
88\newcommand{\stmodindex}[1]{\modindex{#1}{standard }}
89
90% Additional string for an index entry
91\newcommand{\indexsubitem}{}
92\newcommand{\ttindex}[1]{\index{#1@{\tt#1} \indexsubitem}}
93
94% Define \itemjoin: some negative vspace to join two items together
95\newcommand{\itemjoin}{
96\mbox{}
97\vspace{-\itemsep}
98\vspace{-\parsep}
99}
100
101% Define \funcitem{func}{args}: define a function item
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000102\newcommand{\funcitem}[2]{%
103\ttindex{#1}%
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000104\item[\code{#1(\varvars{#2})}]
Guido van Rossum5badc751992-03-06 10:55:46 +0000105\
106}
107
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000108
109% from user-level, fulllineitems should be called as an environment
110\def\fulllineitems{\list{}{\labelwidth \leftmargin \labelsep 0pt
111\rightmargin 0pt \topsep -\parskip \partopsep \parskip
112\itemsep -\parsep
113\let\makelabel\itemnewline}}
114\let\endfulllineitems\endlist
115
116
Fred Drakeeb33c781996-10-29 15:55:08 +0000117% cfuncdesc should be called as an \begin{cfuncdesc} ... \end{cfuncdesc}
118\newcommand{\cfuncline}[3]{\item[\code{#1 #2(\varvars{#3})}]\ttindex{#2}}
119\newcommand{\cfuncdesc}[3]{\fulllineitems\cfuncline{#1}{#2}{#3}}
120\let\endcfuncdesc\endfulllineitems
121
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000122% funcdesc should be called as an \begin{funcdesc} ... \end{funcdesc}
123\newcommand{\funcline}[2]{\item[\code{#1(\varvars{#2})}]\ttindex{#1}}
124\newcommand{\funcdesc}[2]{\fulllineitems\funcline{#1}{#2}}
125\let\endfuncdesc\endfulllineitems
Guido van Rossum16d6e711994-08-08 12:30:22 +0000126\newcommand{\optional}[1]{{\ \Large[}{#1}\hspace{0.5mm}{\Large]}\ }
127
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000128
129% same for excdesc
130\newcommand{\excline}[1]{\item[\code{#1}]\ttindex{#1}}
131\newcommand{\excdesc}[1]{\fulllineitems\excline{#1}}
132\let\endexcdesc\endfulllineitems
133
134% same for datadesc
135\newcommand{\dataline}[1]{\item[\code{#1}]\ttindex{#1}}
136\newcommand{\datadesc}[1]{\fulllineitems\dataline{#1}}
137\let\enddatadesc\endfulllineitems
138
139
Guido van Rossum5badc751992-03-06 10:55:46 +0000140% Define \dataitem{name}: define a data item
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000141\newcommand{\dataitem}[1]{%
142\ttindex{#1}%
Guido van Rossum5badc751992-03-06 10:55:46 +0000143\item[{\tt #1}]
144\
145}
146
147% Define \excitem{name}: define an exception item
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000148\newcommand{\excitem}[1]{%
149\ttindex{#1}%
Guido van Rossum5badc751992-03-06 10:55:46 +0000150\item[{\tt #1}]
151\itembreak
152}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000153
154\let\nodename=\label
155
156\newcommand{\ABC}{{\sc abc}}
157\newcommand{\UNIX}{{\sc Unix}}
158\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000159\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000160\newcommand{\C}{C}
161\newcommand{\EOF}{{\sc eof}}
162
163% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000164\newcommand{\code}[1]{{\@vobeyspaces\@noligs\def\{{\char`\{}\def\}{\char`\}}\def\~{\char`\~}\def\^{\char`\^}\def\e{\char`\\}\def\${\char`\$}\def\#{\char`\#}\def\&{\char`\&}\def\%{\char`\%}%
165\mbox{\tt #1}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000166
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000167\newcommand{\kbd}[1]{\mbox{\tt #1}}
168\newcommand{\key}[1]{\mbox{\tt #1}}
169\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
170\newcommand{\var}[1]{\mbox{\it#1\/}}
171\let\file=\samp
Guido van Rossum45416021995-03-30 16:00:58 +0000172\newcommand{\dfn}[1]{{\em #1\/}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000173\renewcommand{\emph}[1]{{\em #1\/}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000174\newcommand{\strong}[1]{{\bf #1}}
175
Fred Drake9b550d91996-11-11 20:43:46 +0000176\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000177
178\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000179\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000180
Guido van Rossume7af5a01994-08-01 12:39:35 +0000181\newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3&#4\\
182\hline}{\hline\end{tabular}\end{center}}
183
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000184\newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3&#4&#5\\
185\hline}{\hline\end{tabular}\end{center}}
186
187\newcommand{\itemnewline}[1]{\@tempdima\linewidth
188\advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}}
189
190\newcommand{\sectcode}[1]{{\tt #1}}