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 | |
Fred Drake | eb33c78 | 1996-10-29 15:55:08 +0000 | [diff] [blame] | 117 | % 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 Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 122 | % 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 Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 126 | \newcommand{\optional}[1]{{\ \Large[}{#1}\hspace{0.5mm}{\Large]}\ } |
| 127 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 128 | |
| 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 Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 140 | % Define \dataitem{name}: define a data item |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 141 | \newcommand{\dataitem}[1]{% |
| 142 | \ttindex{#1}% |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 143 | \item[{\tt #1}] |
| 144 | \ |
| 145 | } |
| 146 | |
| 147 | % Define \excitem{name}: define an exception item |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 148 | \newcommand{\excitem}[1]{% |
| 149 | \ttindex{#1}% |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 150 | \item[{\tt #1}] |
| 151 | \itembreak |
| 152 | } |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 153 | |
| 154 | \let\nodename=\label |
| 155 | |
| 156 | \newcommand{\ABC}{{\sc abc}} |
| 157 | \newcommand{\UNIX}{{\sc Unix}} |
| 158 | \newcommand{\ASCII}{{\sc ascii}} |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 159 | \newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 160 | \newcommand{\C}{C} |
| 161 | \newcommand{\EOF}{{\sc eof}} |
| 162 | |
| 163 | % code is the most difficult one... |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 164 | \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 Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 166 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 167 | \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 Rossum | 4541602 | 1995-03-30 16:00:58 +0000 | [diff] [blame] | 172 | \newcommand{\dfn}[1]{{\em #1\/}} |
Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 173 | \renewcommand{\emph}[1]{{\em #1\/}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 174 | \newcommand{\strong}[1]{{\bf #1}} |
| 175 | |
Fred Drake | 9b550d9 | 1996-11-11 20:43:46 +0000 | [diff] [blame] | 176 | \newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 177 | |
| 178 | \newif\iftexi\texifalse |
Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 179 | \newif\iflatex\latextrue |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 180 | |
Guido van Rossum | e7af5a0 | 1994-08-01 12:39:35 +0000 | [diff] [blame] | 181 | \newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3\\ |
| 182 | \hline}{\hline\end{tabular}\end{center}} |
| 183 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 184 | \newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3\\ |
| 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}} |