Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 1 | % |
| 2 | % myformat.sty for the Python doc [updated to work with Latex2e] |
| 3 | % |
| 4 | |
Guido van Rossum | 643d932 | 1992-03-31 18:53:47 +0000 | [diff] [blame] | 5 | % Style parameters and macros used by most documents here |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 6 | \raggedbottom |
| 7 | \sloppy |
| 8 | \parindent = 0mm |
| 9 | \parskip = 2mm |
| 10 | |
Guido van Rossum | 4c22cb2 | 1991-01-25 13:28:15 +0000 | [diff] [blame] | 11 | % Variable used by begin code command |
Guido van Rossum | 44000ed | 1991-01-24 16:54:29 +0000 | [diff] [blame] | 12 | \newlength{\codewidth} |
Guido van Rossum | 44000ed | 1991-01-24 16:54:29 +0000 | [diff] [blame] | 13 | |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 14 | % Command to start a code block (follow this by \begin{verbatim}) |
Guido van Rossum | 4c22cb2 | 1991-01-25 13:28:15 +0000 | [diff] [blame] | 15 | \newcommand{\bcode}{ |
| 16 | % Calculate the text width for the minipage: |
| 17 | \setlength{\codewidth}{\linewidth} |
| 18 | \addtolength{\codewidth}{-\parindent} |
| 19 | % |
Guido van Rossum | 4c22cb2 | 1991-01-25 13:28:15 +0000 | [diff] [blame] | 20 | \par |
Guido van Rossum | 92fba02 | 1991-11-12 15:44:51 +0000 | [diff] [blame] | 21 | \vspace{3mm} |
Guido van Rossum | 4c22cb2 | 1991-01-25 13:28:15 +0000 | [diff] [blame] | 22 | \indent |
| 23 | \begin{minipage}[t]{\codewidth} |
| 24 | } |
| 25 | |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 26 | % Command to end a code block (precede this by \end{verbatim}) |
Guido van Rossum | 4c22cb2 | 1991-01-25 13:28:15 +0000 | [diff] [blame] | 27 | \newcommand{\ecode}{ |
| 28 | \end{minipage} |
| 29 | \vspace{3mm} |
| 30 | \par |
| 31 | \noindent |
| 32 | } |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 33 | |
Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 34 | % 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 Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 56 | |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 57 | % 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 Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 64 | \newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}} |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 65 | |
| 66 | % And three entries (using only one level of subentries) |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 67 | \newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}} |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 68 | |
| 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 Rossum | 6886c83 | 1992-04-03 14:44:27 +0000 | [diff] [blame] | 81 | \newcommand{\exindex}[1]{\indexii{exception}{#1@{\tt#1}}} |
| 82 | \newcommand{\obindex}[1]{\indexii{object}{#1}} |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 83 | \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 Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 102 | \newcommand{\funcitem}[2]{% |
| 103 | \ttindex{#1}% |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 104 | \item[\code{#1(\varvars{#2})}] |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 105 | \ |
| 106 | } |
| 107 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 108 | |
| 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 Rossum | 36f3502 | 1997-05-22 20:43:24 +0000 | [diff] [blame] | 117 | % cfuncdesc should be called as |
| 118 | % \begin{cfuncdesc}{type}{name}{arglist} |
| 119 | % ... description ... |
| 120 | % \end{cfuncdesc} |
Fred Drake | eb33c78 | 1996-10-29 15:55:08 +0000 | [diff] [blame] | 121 | \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 Rossum | 36f3502 | 1997-05-22 20:43:24 +0000 | [diff] [blame] | 125 | \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 Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 133 | % 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 Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 137 | \newcommand{\optional}[1]{{\ \Large[}{#1}\hspace{0.5mm}{\Large]}\ } |
| 138 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 139 | |
| 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 Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 151 | % Define \dataitem{name}: define a data item |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 152 | \newcommand{\dataitem}[1]{% |
| 153 | \ttindex{#1}% |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 154 | \item[{\tt #1}] |
| 155 | \ |
| 156 | } |
| 157 | |
| 158 | % Define \excitem{name}: define an exception item |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 159 | \newcommand{\excitem}[1]{% |
| 160 | \ttindex{#1}% |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 161 | \item[{\tt #1}] |
| 162 | \itembreak |
| 163 | } |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 164 | |
| 165 | \let\nodename=\label |
| 166 | |
Fred Drake | 3082424 | 1996-12-13 21:53:07 +0000 | [diff] [blame] | 167 | %% For these commands, use \command{} to get the typography right, not |
| 168 | %% {\command}. This works better with the texinfo translation. |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 169 | \newcommand{\ABC}{{\sc abc}} |
| 170 | \newcommand{\UNIX}{{\sc Unix}} |
| 171 | \newcommand{\ASCII}{{\sc ascii}} |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 172 | \newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 173 | \newcommand{\C}{C} |
| 174 | \newcommand{\EOF}{{\sc eof}} |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 175 | \newcommand{\NULL}{\code{NULL}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 176 | |
| 177 | % code is the most difficult one... |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 178 | \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 Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 180 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 181 | \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 Rossum | 4541602 | 1995-03-30 16:00:58 +0000 | [diff] [blame] | 186 | \newcommand{\dfn}[1]{{\em #1\/}} |
Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 187 | \renewcommand{\emph}[1]{{\em #1\/}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 188 | \newcommand{\strong}[1]{{\bf #1}} |
| 189 | |
Fred Drake | 9b550d9 | 1996-11-11 20:43:46 +0000 | [diff] [blame] | 190 | \newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 191 | |
| 192 | \newif\iftexi\texifalse |
Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 193 | \newif\iflatex\latextrue |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 194 | |
Guido van Rossum | e7af5a0 | 1994-08-01 12:39:35 +0000 | [diff] [blame] | 195 | \newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3\\ |
| 196 | \hline}{\hline\end{tabular}\end{center}} |
| 197 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 198 | \newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3\\ |
| 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}} |