blob: 3b415d0e5bf4ee0307b9b46f65249cd5652619eb [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
Guido van Rossum36f35021997-05-22 20:43:24 +0000117% cfuncdesc should be called as
118% \begin{cfuncdesc}{type}{name}{arglist}
119% ... description ...
120% \end{cfuncdesc}
Fred Drakeeb33c781996-10-29 15:55:08 +0000121\newcommand{\cfuncline}[3]{\item[\code{#1 #2(\varvars{#3})}]\ttindex{#2}}
122\newcommand{\cfuncdesc}[3]{\fulllineitems\cfuncline{#1}{#2}{#3}}
123\let\endcfuncdesc\endfulllineitems
124
Guido van Rossum36f35021997-05-22 20:43:24 +0000125\newcommand{\cvarline}[2]{\item[\code{#1 #2}]\ttindex{#2}}
126\newcommand{\cvardesc}[2]{\fulllineitems\cvarline{#1}{#2}}
127\let\endcvardesc\endfulllineitems
128
129\newcommand{\ctypeline}[1]{\item[\code{#1}]\ttindex{#1}}
130\newcommand{\ctypedesc}[1]{\fulllineitems\ctypeline{#1}}
131\let\endctypedesc\endfulllineitems
132
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000133% funcdesc should be called as an \begin{funcdesc} ... \end{funcdesc}
134\newcommand{\funcline}[2]{\item[\code{#1(\varvars{#2})}]\ttindex{#1}}
135\newcommand{\funcdesc}[2]{\fulllineitems\funcline{#1}{#2}}
136\let\endfuncdesc\endfulllineitems
Guido van Rossum16d6e711994-08-08 12:30:22 +0000137\newcommand{\optional}[1]{{\ \Large[}{#1}\hspace{0.5mm}{\Large]}\ }
138
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000139
140% same for excdesc
141\newcommand{\excline}[1]{\item[\code{#1}]\ttindex{#1}}
142\newcommand{\excdesc}[1]{\fulllineitems\excline{#1}}
143\let\endexcdesc\endfulllineitems
144
145% same for datadesc
146\newcommand{\dataline}[1]{\item[\code{#1}]\ttindex{#1}}
147\newcommand{\datadesc}[1]{\fulllineitems\dataline{#1}}
148\let\enddatadesc\endfulllineitems
149
150
Guido van Rossum5badc751992-03-06 10:55:46 +0000151% Define \dataitem{name}: define a data item
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000152\newcommand{\dataitem}[1]{%
153\ttindex{#1}%
Guido van Rossum5badc751992-03-06 10:55:46 +0000154\item[{\tt #1}]
155\
156}
157
158% Define \excitem{name}: define an exception item
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000159\newcommand{\excitem}[1]{%
160\ttindex{#1}%
Guido van Rossum5badc751992-03-06 10:55:46 +0000161\item[{\tt #1}]
162\itembreak
163}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000164
165\let\nodename=\label
166
Fred Drake30824241996-12-13 21:53:07 +0000167%% For these commands, use \command{} to get the typography right, not
168%% {\command}. This works better with the texinfo translation.
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000169\newcommand{\ABC}{{\sc abc}}
170\newcommand{\UNIX}{{\sc Unix}}
171\newcommand{\ASCII}{{\sc ascii}}
Guido van Rossum16d6e711994-08-08 12:30:22 +0000172\newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000173\newcommand{\C}{C}
174\newcommand{\EOF}{{\sc eof}}
Guido van Rossum9231c8f1997-05-15 21:43:21 +0000175\newcommand{\NULL}{\code{NULL}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000176
177% code is the most difficult one...
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000178\newcommand{\code}[1]{{\@vobeyspaces\@noligs\def\{{\char`\{}\def\}{\char`\}}\def\~{\char`\~}\def\^{\char`\^}\def\e{\char`\\}\def\${\char`\$}\def\#{\char`\#}\def\&{\char`\&}\def\%{\char`\%}%
179\mbox{\tt #1}}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000180
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000181\newcommand{\kbd}[1]{\mbox{\tt #1}}
182\newcommand{\key}[1]{\mbox{\tt #1}}
183\newcommand{\samp}[1]{\mbox{`\code{#1}'}}
184\newcommand{\var}[1]{\mbox{\it#1\/}}
185\let\file=\samp
Guido van Rossum45416021995-03-30 16:00:58 +0000186\newcommand{\dfn}[1]{{\em #1\/}}
Guido van Rossumecae0b71996-06-26 19:03:20 +0000187\renewcommand{\emph}[1]{{\em #1\/}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000188\newcommand{\strong}[1]{{\bf #1}}
189
Fred Drake9b550d91996-11-11 20:43:46 +0000190\newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}}
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000191
192\newif\iftexi\texifalse
Guido van Rossumecae0b71996-06-26 19:03:20 +0000193\newif\iflatex\latextrue
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000194
Guido van Rossume7af5a01994-08-01 12:39:35 +0000195\newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3&#4\\
196\hline}{\hline\end{tabular}\end{center}}
197
Guido van Rossum95cd2ef1992-12-08 14:37:55 +0000198\newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3&#4&#5\\
199\hline}{\hline\end{tabular}\end{center}}
200
201\newcommand{\itemnewline}[1]{\@tempdima\linewidth
202\advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}}
203
204\newcommand{\sectcode}[1]{{\tt #1}}