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 | |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 5 | \NeedsTeXFormat{LaTeX2e}[1995/12/01] |
| 6 | \ProvidesPackage{myformat} |
Fred Drake | 76183c0 | 1998-02-16 22:30:10 +0000 | [diff] [blame] | 7 | [1998/01/11 |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 8 | LaTeX package (Python manual markup)] |
| 9 | |
Fred Drake | 76183c0 | 1998-02-16 22:30:10 +0000 | [diff] [blame] | 10 | % Optional packages: |
| 11 | % |
| 12 | % If processing of these documents fails at your TeX installation, |
| 13 | % these may be commented out (independently) to make things work. |
| 14 | % These are both supplied with the current version of the teTeX |
| 15 | % distribution. |
| 16 | % |
| 17 | % The "fancyhdr" package makes nicer page footers reasonable to |
| 18 | % implement, and is used to put the chapter and section information in |
| 19 | % the footers. |
| 20 | % |
| 21 | % The "times" package makes the default font the PostScript Times |
| 22 | % font, which makes for smaller PostScript and a font that more people |
| 23 | % like. |
| 24 | % |
| 25 | \RequirePackage{fancyhdr}\typeout{Using fancier footers than usual....} |
| 26 | \RequirePackage{times}\typeout{Using times fonts instead of Computer Modern.} |
| 27 | |
| 28 | |
Fred Drake | 4186cd3 | 1998-02-18 17:21:09 +0000 | [diff] [blame^] | 29 | % for PDF output, use maximal compression, revise \label{} to support named |
| 30 | % targets for later linking operations. |
| 31 | \@ifundefined{pdfannotlink}{}{% |
| 32 | \pdfcompresslevel=9 |
| 33 | \let\OldLabel=\label |
| 34 | \renewcommand{\label}[1]{% |
| 35 | \OldLabel{#1}% |
| 36 | {\pdfdest name {#1} fit}% |
| 37 | } |
| 38 | } |
Fred Drake | 30d1782 | 1998-02-17 15:56:55 +0000 | [diff] [blame] | 39 | |
Guido van Rossum | daff175 | 1997-06-02 17:35:01 +0000 | [diff] [blame] | 40 | % Increase printable page size (copied from fullpage.sty) |
| 41 | \topmargin 0pt |
| 42 | \advance \topmargin by -\headheight |
| 43 | \advance \topmargin by -\headsep |
Fred Drake | 9e24309 | 1998-01-18 05:09:54 +0000 | [diff] [blame] | 44 | |
Fred Drake | 76183c0 | 1998-02-16 22:30:10 +0000 | [diff] [blame] | 45 | \textheight 8.7in |
Fred Drake | 9e24309 | 1998-01-18 05:09:54 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | daff175 | 1997-06-02 17:35:01 +0000 | [diff] [blame] | 47 | \oddsidemargin 0pt |
| 48 | \evensidemargin \oddsidemargin |
| 49 | \marginparwidth 0.5in |
Fred Drake | 9e24309 | 1998-01-18 05:09:54 +0000 | [diff] [blame] | 50 | |
Guido van Rossum | daff175 | 1997-06-02 17:35:01 +0000 | [diff] [blame] | 51 | \textwidth 6.5in |
| 52 | |
Guido van Rossum | 643d932 | 1992-03-31 18:53:47 +0000 | [diff] [blame] | 53 | % Style parameters and macros used by most documents here |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 54 | \raggedbottom |
| 55 | \sloppy |
| 56 | \parindent = 0mm |
| 57 | \parskip = 2mm |
| 58 | |
Fred Drake | 76183c0 | 1998-02-16 22:30:10 +0000 | [diff] [blame] | 59 | % uncomment the following line if you have the fancyhdr package available: |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 60 | \pagestyle{empty} % start this way; change for |
| 61 | \pagenumbering{roman} % ToC & chapters |
| 62 | \setcounter{secnumdepth}{1} |
| 63 | |
Fred Drake | 76183c0 | 1998-02-16 22:30:10 +0000 | [diff] [blame] | 64 | % Redefine the 'normal' header/footer style when using "fancyhdr" package: |
| 65 | \@ifundefined{fancyhf}{}{ |
| 66 | \fancypagestyle{normal}{% |
| 67 | \fancyhf{}% |
| 68 | \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}% |
| 69 | \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}}% |
| 70 | \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}}% |
| 71 | \renewcommand{\headrulewidth}{0pt}% |
| 72 | \renewcommand{\footrulewidth}{0.4pt}% |
| 73 | } |
| 74 | % Update the plain style so we get the page number & footer line, |
| 75 | % but not a chapter or section title. This is to keep the first |
| 76 | % page of a chapter and the blank page between chapters `clean.' |
| 77 | \fancypagestyle{plain}{% |
| 78 | \fancyhf{}% |
| 79 | \fancyfoot[LE,RO]{{\HeaderFamily\thepage}}% |
| 80 | \renewcommand{\headrulewidth}{0pt}% |
| 81 | \renewcommand{\footrulewidth}{0.4pt}% |
| 82 | } |
| 83 | % Redefine \cleardoublepage so that the blank page between chapters |
| 84 | % gets the plain style and not the fancy style. |
| 85 | \renewcommand{\cleardoublepage}{\clearpage\if@twoside \ifodd\c@page\else |
| 86 | \hbox{} |
| 87 | \thispagestyle{plain} |
| 88 | \newpage |
| 89 | \if@twocolumn\hbox{}\newpage\fi\fi\fi} |
| 90 | } |
| 91 | |
Fred Drake | 9e24309 | 1998-01-18 05:09:54 +0000 | [diff] [blame] | 92 | % old code font selections: |
| 93 | \let\codefont=\tt |
| 94 | \let\sectcodefont=\tt |
| 95 | |
| 96 | % (Haven't found a new one that gets <, >, and _ right without being |
| 97 | % monospaced.) |
| 98 | |
Guido van Rossum | 4c22cb2 | 1991-01-25 13:28:15 +0000 | [diff] [blame] | 99 | % Variable used by begin code command |
Guido van Rossum | 44000ed | 1991-01-24 16:54:29 +0000 | [diff] [blame] | 100 | \newlength{\codewidth} |
Guido van Rossum | 44000ed | 1991-01-24 16:54:29 +0000 | [diff] [blame] | 101 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 102 | \newcommand{\examplevspace}{2mm} |
| 103 | \newcommand{\exampleindent}{1cm} |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 104 | % Command to start a code block (follow this by \begin{verbatim}) |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 105 | \newcommand{\b@code}{% |
| 106 | \begingroup% |
| 107 | \setlength{\parindent}\exampleindent% |
| 108 | % Calculate the text width for the minipage: |
| 109 | \setlength{\codewidth}{\linewidth}% |
| 110 | \addtolength{\codewidth}{-\parindent}% |
| 111 | % |
| 112 | \par% |
| 113 | \vspace\examplevspace% |
| 114 | \indent% |
| 115 | \begin{minipage}[t]{\codewidth}% |
| 116 | \small% |
Guido van Rossum | 4c22cb2 | 1991-01-25 13:28:15 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 119 | % Command to end a code block (precede this by \end{verbatim}) |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 120 | \newcommand{\e@code}{% |
| 121 | \end{minipage}% |
| 122 | \endgroup% |
Guido van Rossum | 4c22cb2 | 1991-01-25 13:28:15 +0000 | [diff] [blame] | 123 | } |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 124 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 125 | \let\OldVerbatim=\verbatim |
| 126 | \let\OldEndVerbatim=\endverbatim |
| 127 | \renewcommand{\verbatim}{\b@code\OldVerbatim} |
| 128 | \renewcommand{\endverbatim}{\OldEndVerbatim\e@code} |
| 129 | |
| 130 | % Augment the sectioning commands used to get our own font family in |
| 131 | % place: |
| 132 | \newcommand{\HeaderFamily}{\sffamily} |
| 133 | \renewcommand{\section}{\@startsection {section}{1}{\z@}% |
| 134 | {-3.5ex \@plus -1ex \@minus -.2ex}% |
| 135 | {2.3ex \@plus.2ex}% |
| 136 | {\reset@font\Large\HeaderFamily}} |
| 137 | \renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}% |
| 138 | {-3.25ex\@plus -1ex \@minus -.2ex}% |
| 139 | {1.5ex \@plus .2ex}% |
| 140 | {\reset@font\large\HeaderFamily}} |
| 141 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}% |
| 142 | {-3.25ex\@plus -1ex \@minus -.2ex}% |
| 143 | {1.5ex \@plus .2ex}% |
| 144 | {\reset@font\normalsize\HeaderFamily}} |
| 145 | \renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}% |
| 146 | {3.25ex \@plus1ex \@minus.2ex}% |
| 147 | {-1em}% |
| 148 | {\reset@font\normalsize\HeaderFamily}} |
| 149 | \renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}% |
| 150 | {3.25ex \@plus1ex \@minus .2ex}% |
| 151 | {-1em}% |
| 152 | {\reset@font\normalsize\HeaderFamily}} |
| 153 | |
| 154 | |
Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 155 | % Underscore hack (only act like subscript operator if in math mode) |
| 156 | % |
| 157 | % The following is due to Mark Wooding (the old version didn't work with |
| 158 | % Latex 2e. |
| 159 | |
| 160 | \DeclareRobustCommand\hackscore{% |
| 161 | \ifmmode_\else\textunderscore\fi% |
| 162 | } |
| 163 | \begingroup |
| 164 | \catcode`\_\active |
| 165 | \def\next{% |
| 166 | \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}% |
| 167 | } |
| 168 | \expandafter\endgroup\next |
| 169 | |
| 170 | % |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 171 | % This is the old hack, which didn't work with 2e. |
| 172 | % You should not need this since the rest of the documentation is now |
| 173 | % LaTeX2e-only. |
Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 174 | % |
| 175 | %\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi} |
| 176 | %\catcode`\_=12 |
| 177 | %\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] | 178 | |
Fred Drake | b37a395 | 1998-02-06 22:52:52 +0000 | [diff] [blame] | 179 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 180 | |
Fred Drake | b37a395 | 1998-02-06 22:52:52 +0000 | [diff] [blame] | 181 | %% Lots of index-entry generation support. |
| 182 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 183 | % Command to wrap around stuff that refers to function / module / |
| 184 | % attribute names in the index. Default behavior: like \code{}. To |
| 185 | % just keep the index entries in the roman font, uncomment the second |
| 186 | % definition to use instead; it matches O'Reilly style more. |
| 187 | % |
Fred Drake | b37a395 | 1998-02-06 22:52:52 +0000 | [diff] [blame] | 188 | \newcommand{\idxcode}[1]{\codefont{#1}} |
| 189 | %\renewcommand{\idxcode}[1]{#1} |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 190 | |
| 191 | % Command to generate two index entries (using subentries) |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 192 | \newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}} |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 193 | |
| 194 | % And three entries (using only one level of subentries) |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 195 | \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] | 196 | |
| 197 | % And four (again, using only one level of subentries) |
| 198 | \newcommand{\indexiv}[4]{ |
| 199 | \index{#1!#2 #3 #4} |
| 200 | \index{#2!#3 #4, #1} |
| 201 | \index{#3!#4, #1 #2} |
| 202 | \index{#4!#1 #2 #3} |
| 203 | } |
| 204 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 205 | % Command to generate a reference to a function, statement, keyword, |
| 206 | % operator. |
Fred Drake | b37a395 | 1998-02-06 22:52:52 +0000 | [diff] [blame] | 207 | \newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}} |
| 208 | \newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}} |
| 209 | \newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}} |
Guido van Rossum | 6886c83 | 1992-04-03 14:44:27 +0000 | [diff] [blame] | 210 | \newcommand{\obindex}[1]{\indexii{object}{#1}} |
Fred Drake | b37a395 | 1998-02-06 22:52:52 +0000 | [diff] [blame] | 211 | \newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1}} (built-in function)}} |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 212 | |
| 213 | % Add an index entry for a module |
Fred Drake | b37a395 | 1998-02-06 22:52:52 +0000 | [diff] [blame] | 214 | \newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}} |
Fred Drake | 4af1814 | 1997-12-15 22:08:14 +0000 | [diff] [blame] | 215 | \newcommand{\refmodindex}[1]{\refmodule{#1}{}} |
Fred Drake | 207e57b | 1997-12-15 21:37:45 +0000 | [diff] [blame] | 216 | \newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }} |
| 217 | \newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }} |
| 218 | |
Fred Drake | da941ef | 1998-01-02 02:57:41 +0000 | [diff] [blame] | 219 | % support for the module index |
| 220 | \newwrite\modindexfile |
| 221 | \openout\modindexfile=modules.idx |
| 222 | |
Fred Drake | 207e57b | 1997-12-15 21:37:45 +0000 | [diff] [blame] | 223 | % Add the defining entry for a module |
Fred Drake | b37a395 | 1998-02-06 22:52:52 +0000 | [diff] [blame] | 224 | \newcommand{\defmodindex}[2]{% |
| 225 | \index{#1@{\idxcode{#1}} (#2module)|textbf}% |
Fred Drake | da941ef | 1998-01-02 02:57:41 +0000 | [diff] [blame] | 226 | \write\modindexfile{#1 \thepage}} |
Fred Drake | b192747 | 1998-02-04 14:43:36 +0000 | [diff] [blame] | 227 | \newcommand{\modindex}[1]{\defmodindex{#1}{}} |
Fred Drake | 207e57b | 1997-12-15 21:37:45 +0000 | [diff] [blame] | 228 | \newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }} |
| 229 | \newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }} |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 230 | |
| 231 | % Additional string for an index entry |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 232 | \newcommand{\index@subitem}{} |
| 233 | \newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}} |
| 234 | \newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}} |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 235 | |
Guido van Rossum | 5badc75 | 1992-03-06 10:55:46 +0000 | [diff] [blame] | 236 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 237 | % from user-level, fulllineitems should be called as an environment |
| 238 | \def\fulllineitems{\list{}{\labelwidth \leftmargin \labelsep 0pt |
| 239 | \rightmargin 0pt \topsep -\parskip \partopsep \parskip |
| 240 | \itemsep -\parsep |
| 241 | \let\makelabel\itemnewline}} |
| 242 | \let\endfulllineitems\endlist |
| 243 | |
| 244 | |
Guido van Rossum | 36f3502 | 1997-05-22 20:43:24 +0000 | [diff] [blame] | 245 | % cfuncdesc should be called as |
| 246 | % \begin{cfuncdesc}{type}{name}{arglist} |
| 247 | % ... description ... |
| 248 | % \end{cfuncdesc} |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 249 | \newcommand{\cfuncline}[3]{\item[\code{#1 \bfcode{#2}(\varvars{#3})}]\ttindex{#2}} |
Fred Drake | eb33c78 | 1996-10-29 15:55:08 +0000 | [diff] [blame] | 250 | \newcommand{\cfuncdesc}[3]{\fulllineitems\cfuncline{#1}{#2}{#3}} |
| 251 | \let\endcfuncdesc\endfulllineitems |
| 252 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 253 | \newcommand{\cvarline}[2]{\item[\code{#1 \bfcode{#2}}]\ttindex{#2}} |
Guido van Rossum | 36f3502 | 1997-05-22 20:43:24 +0000 | [diff] [blame] | 254 | \newcommand{\cvardesc}[2]{\fulllineitems\cvarline{#1}{#2}} |
| 255 | \let\endcvardesc\endfulllineitems |
| 256 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 257 | \newcommand{\ctypeline}[1]{\item[\bfcode{#1}]\ttindex{#1}} |
Guido van Rossum | 36f3502 | 1997-05-22 20:43:24 +0000 | [diff] [blame] | 258 | \newcommand{\ctypedesc}[1]{\fulllineitems\ctypeline{#1}} |
| 259 | \let\endctypedesc\endfulllineitems |
| 260 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 261 | % funcdesc should be called as an \begin{funcdesc} ... \end{funcdesc} |
Fred Drake | aebc6f3 | 1998-02-13 14:34:04 +0000 | [diff] [blame] | 262 | \newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 263 | \newcommand{\funcdesc}[2]{\fulllineitems\funcline{#1}{#2}} |
| 264 | \let\endfuncdesc\endfulllineitems |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 265 | \newcommand{\optional}[1]{{\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}} |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 266 | |
Fred Drake | aebc6f3 | 1998-02-13 14:34:04 +0000 | [diff] [blame] | 267 | % similar to {funcdesc}, but doesn't add to the index |
| 268 | \newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]} |
| 269 | \newcommand{\funcdescni}[2]{\fulllineitems\funclineni{#1}{#2}} |
| 270 | \let\endfuncdescni\endfulllineitems |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 271 | |
| 272 | % same for excdesc |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 273 | \newcommand{\excline}[1]{\item[\bfcode{#1}]\ttindex{#1}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 274 | \newcommand{\excdesc}[1]{\fulllineitems\excline{#1}} |
| 275 | \let\endexcdesc\endfulllineitems |
| 276 | |
| 277 | % same for datadesc |
Fred Drake | aebc6f3 | 1998-02-13 14:34:04 +0000 | [diff] [blame] | 278 | \newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 279 | \newcommand{\datadesc}[1]{\fulllineitems\dataline{#1}} |
| 280 | \let\enddatadesc\endfulllineitems |
| 281 | |
Fred Drake | aebc6f3 | 1998-02-13 14:34:04 +0000 | [diff] [blame] | 282 | % similar to {datadesc}, but doesn't add to the index |
| 283 | \newcommand{\datalineni}[1]{\item[\bfcode{#1}]} |
| 284 | \newcommand{\datadescni}[1]{\fulllineitems\datalineni{#1}} |
| 285 | \let\enddatadescni\endfulllineitems |
| 286 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 287 | |
Fred Drake | a610f9f | 1997-12-03 03:42:39 +0000 | [diff] [blame] | 288 | % opcodedesc should be called as an \begin{opcodedesc} ... \end{opcodedesc} |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 289 | \newcommand{\opcodeline}[2]{\item[\bfcode{#1}\quad\var{#2}]} |
Fred Drake | a610f9f | 1997-12-03 03:42:39 +0000 | [diff] [blame] | 290 | \newcommand{\opcodedesc}[2]{\fulllineitems\opcodeline{#1}{#2}} |
| 291 | \let\endopcodedesc\endfulllineitems |
| 292 | |
| 293 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 294 | \let\nodename=\label |
| 295 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 296 | % For these commands, use \command{} to get the typography right, not |
| 297 | % {\command}. This works better with the texinfo translation. |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 298 | \newcommand{\ABC}{{\sc abc}} |
| 299 | \newcommand{\UNIX}{{\sc Unix}} |
Fred Drake | 311c196 | 1998-01-20 05:07:19 +0000 | [diff] [blame] | 300 | \newcommand{\POSIX}{POSIX} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 301 | \newcommand{\ASCII}{{\sc ascii}} |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 302 | \newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 303 | \newcommand{\C}{C} |
| 304 | \newcommand{\EOF}{{\sc eof}} |
Guido van Rossum | 9231c8f | 1997-05-15 21:43:21 +0000 | [diff] [blame] | 305 | \newcommand{\NULL}{\code{NULL}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 306 | |
| 307 | % code is the most difficult one... |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 308 | \newcommand{\code}[1]{{\@vobeyspaces\@noligs\def\{{\char`\{}\def\}{\char`\}}\def\~{\char`\~}\def\^{\char`\^}\def\e{\char`\\}\def\${\char`\$}\def\#{\char`\#}\def\&{\char`\&}\def\%{\char`\%}% |
Fred Drake | 9e24309 | 1998-01-18 05:09:54 +0000 | [diff] [blame] | 309 | \mbox{\codefont{#1}}}} |
Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 310 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 311 | \newcommand{\bfcode}[1]{\code{\bfseries#1}} %bold-faced code font |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 312 | \newcommand{\kbd}[1]{\mbox{\tt #1}} |
| 313 | \newcommand{\key}[1]{\mbox{\tt #1}} |
| 314 | \newcommand{\samp}[1]{\mbox{`\code{#1}'}} |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 315 | % This weird definition of \var{} allows it to always appear in roman |
| 316 | % italics, and won't get funky in code fragments when we play around |
| 317 | % with fonts. |
| 318 | \newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}} |
Guido van Rossum | 4541602 | 1995-03-30 16:00:58 +0000 | [diff] [blame] | 319 | \newcommand{\dfn}[1]{{\em #1\/}} |
Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 320 | \renewcommand{\emph}[1]{{\em #1\/}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 321 | \newcommand{\strong}[1]{{\bf #1}} |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 322 | % let's experiment with a new font: |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 323 | \newcommand{\file}[1]{\mbox{`\small\textsf{#1}'}} |
Fred Drake | 0c17d66 | 1998-02-18 14:24:19 +0000 | [diff] [blame] | 324 | \@ifundefined{pdfannotlink}{% |
Fred Drake | 5374045 | 1998-02-17 15:13:01 +0000 | [diff] [blame] | 325 | \newcommand{\url}[1]{\mbox{\small\textsf{#1}}}% |
Fred Drake | 0c17d66 | 1998-02-18 14:24:19 +0000 | [diff] [blame] | 326 | }{ |
| 327 | \input{pdfcolor}% this really isn't a package |
| 328 | \newcommand{\url}[1]{{% |
| 329 | \pdfannotlink user{/C [1 1 1] /S /URI /URI (#1)}% |
| 330 | \NavyBlue% color of the link text |
| 331 | \mbox{\small\textsf{#1}}% |
| 332 | \Black% Turn it back off; these are declarative |
| 333 | \pdfendlink}}% and don't appear bound to the current |
| 334 | }% formatting "box". |
Fred Drake | 4186cd3 | 1998-02-18 17:21:09 +0000 | [diff] [blame^] | 335 | \newcommand{\email}[1]{\mbox{\small\textsf{#1}}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 336 | |
Fred Drake | 9b550d9 | 1996-11-11 20:43:46 +0000 | [diff] [blame] | 337 | \newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}} |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 338 | |
| 339 | \newif\iftexi\texifalse |
Guido van Rossum | ecae0b7 | 1996-06-26 19:03:20 +0000 | [diff] [blame] | 340 | \newif\iflatex\latextrue |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 341 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 342 | % These should be used for all references to identifiers which are |
| 343 | % used to refer to instances of specific language constructs. See the |
| 344 | % names for specific semantic assignments. |
Fred Drake | 311c196 | 1998-01-20 05:07:19 +0000 | [diff] [blame] | 345 | % |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 346 | % For now, don't do anything really fancy with them; just use them as |
| 347 | % logical markup. This might change in the future. |
Fred Drake | 311c196 | 1998-01-20 05:07:19 +0000 | [diff] [blame] | 348 | % |
| 349 | \let\module=\code |
Fred Drake | dd28d57 | 1998-01-22 15:55:21 +0000 | [diff] [blame] | 350 | \let\keyword=\code |
| 351 | \let\exception=\code |
Fred Drake | 311c196 | 1998-01-20 05:07:19 +0000 | [diff] [blame] | 352 | \let\class=\code |
Fred Drake | dd28d57 | 1998-01-22 15:55:21 +0000 | [diff] [blame] | 353 | \let\function=\code |
| 354 | \let\cfunction=\code |
| 355 | \let\method=\code |
| 356 | |
| 357 | % constants defined in Python modules, not language constants: |
| 358 | \let\constant=\code |
Fred Drake | 311c196 | 1998-01-20 05:07:19 +0000 | [diff] [blame] | 359 | |
| 360 | \newcommand{\manpage}[2]{{\emph{#1}(#2)}} |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 361 | \newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}} |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 362 | \newcommand{\program}[1]{\strong{#1}} |
Fred Drake | 311c196 | 1998-01-20 05:07:19 +0000 | [diff] [blame] | 363 | |
| 364 | |
Guido van Rossum | e7af5a0 | 1994-08-01 12:39:35 +0000 | [diff] [blame] | 365 | \newenvironment{tableii}[4]{\begin{center}\def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}\begin{tabular}{#1}\hline#3\\ |
| 366 | \hline}{\hline\end{tabular}\end{center}} |
| 367 | |
Guido van Rossum | 95cd2ef | 1992-12-08 14:37:55 +0000 | [diff] [blame] | 368 | \newenvironment{tableiii}[5]{\begin{center}\def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}\begin{tabular}{#1}\hline#3\\ |
| 369 | \hline}{\hline\end{tabular}\end{center}} |
| 370 | |
| 371 | \newcommand{\itemnewline}[1]{\@tempdima\linewidth |
| 372 | \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}} |
| 373 | |
Fred Drake | 9e24309 | 1998-01-18 05:09:54 +0000 | [diff] [blame] | 374 | \newcommand{\sectcode}[1]{{\sectcodefont{#1}}} |
Guido van Rossum | e3d5fc5 | 1997-07-17 18:27:53 +0000 | [diff] [blame] | 375 | |
| 376 | % Cross-referencing (AMK) |
| 377 | % Sample usage: |
| 378 | % \begin{seealso} |
| 379 | % \seemodule{rand}{Uniform random number generator}; % Module xref |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 380 | % \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book |
Guido van Rossum | e3d5fc5 | 1997-07-17 18:27:53 +0000 | [diff] [blame] | 381 | % \end{seealso} |
| 382 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 383 | \newenvironment{seealso}[0]{\strong{See Also:}\par}{\par} |
Fred Drake | aebc6f3 | 1998-02-13 14:34:04 +0000 | [diff] [blame] | 384 | \newcommand{\seemodule}[2]{\ref{module-#1}:% |
| 385 | \quad Module \module{#1}\quad(#2)} |
| 386 | \newcommand{\seebimodule}[2]{\ref{module-#1}:% |
| 387 | \quad Built-in Module \module{#1}\quad(#2)} |
| 388 | \newcommand{\seestmodule}[2]{\ref{module-#1}:% |
| 389 | \quad Standard Module \module{#1}\quad(#2)} |
Guido van Rossum | e3d5fc5 | 1997-07-17 18:27:53 +0000 | [diff] [blame] | 390 | \newcommand{\seetext}[1]{\par{#1}} |
Fred Drake | da941ef | 1998-01-02 02:57:41 +0000 | [diff] [blame] | 391 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 392 | % Fix the theindex environment to add an entry to the Table of |
| 393 | % Contents; this is much nicer than just having to jump to the end of |
| 394 | % the book and flip around, especially with multiple indexes. |
Fred Drake | da941ef | 1998-01-02 02:57:41 +0000 | [diff] [blame] | 395 | % |
| 396 | \let\OldTheindex=\theindex |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 397 | \renewcommand{\theindex}{% |
Fred Drake | f1a4150 | 1998-02-16 05:30:27 +0000 | [diff] [blame] | 398 | \cleardoublepage% |
Fred Drake | da941ef | 1998-01-02 02:57:41 +0000 | [diff] [blame] | 399 | \OldTheindex% |
| 400 | \addcontentsline{toc}{chapter}{\indexname}% |
| 401 | } |
Fred Drake | 031ad4b | 1998-01-09 05:34:23 +0000 | [diff] [blame] | 402 | |
| 403 | % Use a similar trick to catch the end of the {abstract} environment, |
| 404 | % but here make sure the abstract is followed by a blank page if the |
| 405 | % 'openright' option is used. |
| 406 | % |
| 407 | \let\OldEndAbstract=\endabstract |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 408 | \renewcommand{\endabstract}{ |
Fred Drake | 737e73e | 1998-01-13 22:40:08 +0000 | [diff] [blame] | 409 | \if@openright |
| 410 | \ifodd\value{page} |
| 411 | \typeout{Adding blank page after the abstract.} |
| 412 | \vfil\pagebreak |
Fred Drake | 031ad4b | 1998-01-09 05:34:23 +0000 | [diff] [blame] | 413 | \fi |
Fred Drake | 737e73e | 1998-01-13 22:40:08 +0000 | [diff] [blame] | 414 | \fi |
| 415 | \OldEndAbstract |
Fred Drake | 031ad4b | 1998-01-09 05:34:23 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 418 | % This wraps the \tableofcontents macro with all the magic to get the |
| 419 | % spacing right and have the right number of pages if the 'openright' |
Fred Drake | 031ad4b | 1998-01-09 05:34:23 +0000 | [diff] [blame] | 420 | % option has been used. This eliminates a fair amount of crud in the |
| 421 | % individual document files. |
| 422 | % |
Fred Drake | 737e73e | 1998-01-13 22:40:08 +0000 | [diff] [blame] | 423 | \let\OldTableofcontents=\tableofcontents |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 424 | \renewcommand{\tableofcontents}[0]{% |
| 425 | \setcounter{page}{1}% |
| 426 | \pagebreak% |
| 427 | \pagestyle{plain}% |
| 428 | {% |
| 429 | \parskip = 0mm% |
| 430 | \OldTableofcontents% |
| 431 | \if@openright% |
| 432 | \ifodd\value{page}% |
| 433 | \typeout{Adding blank page after the table of contents.}% |
| 434 | \pagebreak\hspace{0pt}% |
| 435 | \fi% |
| 436 | \fi% |
| 437 | }% |
Fred Drake | 4c68963 | 1998-02-13 16:58:49 +0000 | [diff] [blame] | 438 | \cleardoublepage% |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 439 | \pagenumbering{arabic}% |
Fred Drake | 76183c0 | 1998-02-16 22:30:10 +0000 | [diff] [blame] | 440 | \@ifundefined{fancyhf}{}{\pagestyle{normal}}% |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 443 | % Allow the release number to be specified independently of the |
| 444 | % \date{}. This allows the date to reflect the document's date and |
| 445 | % release to specify the Python release that is documented. |
| 446 | % |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 447 | \newcommand{\@release}{} |
| 448 | \newcommand{\version}{} |
| 449 | \newcommand{\releasename}{Release} |
| 450 | \newcommand{\release}[1]{% |
| 451 | \renewcommand{\@release}{\releasename\space\version}% |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 452 | \renewcommand{\version}{#1}} |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 453 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 454 | % Allow specification of the author's address separately from the |
| 455 | % author's name. This can be used to format them differently, which |
| 456 | % is a good thing. |
| 457 | % |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 458 | \newcommand{\@authoraddress}{} |
| 459 | \newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}} |
| 460 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 461 | % Change the title page to look a bit better, and fit in with the |
| 462 | % fncychap ``Bjarne'' style a bit better. |
| 463 | % |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 464 | \renewcommand{\maketitle}{\begin{titlepage}% |
| 465 | \let\footnotesize\small |
| 466 | \let\footnoterule\relax |
| 467 | \@ifundefined{ChTitleVar}{}{% |
| 468 | \mghrulefill{\RW}}% |
Fred Drake | 5374045 | 1998-02-17 15:13:01 +0000 | [diff] [blame] | 469 | \@ifundefined{pdfinfo}{}{ |
| 470 | \pdfinfo |
| 471 | author {\@author} |
| 472 | title {\@title} |
| 473 | } |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 474 | \begin{flushright}% |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 475 | {\rm\Huge\HeaderFamily \@title \par}% |
| 476 | {\em\LARGE\HeaderFamily \@release \par} |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 477 | \vfill |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 478 | {\LARGE\HeaderFamily \@author \par} |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 479 | \vfill\vfill |
| 480 | {\large |
| 481 | \@date \par |
| 482 | \vskip 3em |
| 483 | \@authoraddress \par |
| 484 | }% |
| 485 | \end{flushright}%\par |
| 486 | \@thanks |
| 487 | \end{titlepage}% |
| 488 | \setcounter{footnote}{0}% |
| 489 | \let\thanks\relax\let\maketitle\relax |
| 490 | \gdef\@thanks{}\gdef\@author{}\gdef\@title{} |
| 491 | } |
| 492 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 493 | % ``minitoc'' support; works fairly well but not all chapters do well |
| 494 | % with it. Has some weird side effects that I haven't tracked down; |
| 495 | % don't use it for real at this time. |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 496 | % |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 497 | % To enable, uncomment the following line only (don't do it!): |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 498 | %\RequirePackage{minitoc} |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 499 | % |
| 500 | % Maybe this should all be removed. But I think something like this |
| 501 | % would be really nice if it can be integrated with the ``list of |
| 502 | % modules'' at the top of module-documentation chapters. But it might |
| 503 | % require a completely new environment, perhaps based on {list}. |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 504 | |
| 505 | % Leave the rest as-is: |
| 506 | \newif\if@minitocprinted |
| 507 | \newcommand{\suppressminitoc}{\@minitocprintedtrue} |
| 508 | \@ifundefined{minitoc}{ |
| 509 | % allow \minitoc to be used even if the package hasn't been loaded. |
| 510 | \newcommand{\minitoc}{\@minitocprintedtrue} |
| 511 | }{ |
| 512 | \dominitoc |
| 513 | \newif\if@firstsection |
| 514 | \let\OldChapter=\chapter |
| 515 | \let\OldSection=\section |
| 516 | \let\OldMinitoc=\minitoc |
| 517 | % This will only include the minitoc once per chapter |
| 518 | \renewcommand{\minitoc}{% |
| 519 | \if@minitocprinted{}\else% |
| 520 | \OldMinitoc% |
| 521 | \@minitocprintedtrue% |
| 522 | \fi% |
Fred Drake | 031ad4b | 1998-01-09 05:34:23 +0000 | [diff] [blame] | 523 | } |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 524 | % This includes a minitoc before the first \section{}, if it hasn't |
| 525 | % already been printed using an explicit \minitoc call. |
| 526 | \newcommand{\NewSection}[1]{% |
| 527 | \if@firstsection% |
| 528 | \if@minitocprinted{}\else% |
| 529 | \vskip 15pt% |
| 530 | \minitoc% |
| 531 | \@firstsectionfalse% |
| 532 | \fi% |
| 533 | \fi% |
| 534 | \OldSection{#1}% |
| 535 | } |
| 536 | % Reset the flags for each chaper to let the automatic stuff work. |
| 537 | \newcommand{\NewChapter}[1]{% |
| 538 | \OldChapter{#1}% |
| 539 | \@firstsectiontrue% |
| 540 | \@minitocprintedfalse% |
| 541 | } |
| 542 | \let\chapter=\NewChapter |
| 543 | \let\section=\NewSection |
| 544 | \typeout{Including mini Tables of Contents in each chapter.} |
| 545 | } |
| 546 | |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 547 | % This sets up the fancy chapter headings that make the documents look |
| 548 | % at least a little better than the usual LaTeX output. |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 549 | % |
| 550 | \RequirePackage[Bjarne]{fncychap} |
| 551 | \@ifundefined{ChTitleVar}{}{ |
Fred Drake | dc8af0a | 1998-02-13 06:48:05 +0000 | [diff] [blame] | 552 | \ChNameVar{\raggedleft\normalsize\HeaderFamily} |
| 553 | \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily} |
| 554 | \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily} |
Fred Drake | 06f169b | 1998-02-11 23:08:20 +0000 | [diff] [blame] | 555 | % This creates chapter heads without the leading \vspace*{}: |
| 556 | \def\@makechapterhead#1{% |
| 557 | {\parindent \z@ \raggedright \normalfont |
| 558 | \ifnum \c@secnumdepth >\m@ne |
| 559 | \DOCH |
| 560 | \fi |
| 561 | \interlinepenalty\@M |
| 562 | \DOTI{#1} |
| 563 | } |
| 564 | } |
| 565 | \typeout{Using fancy chapter headings.} |
Fred Drake | 031ad4b | 1998-01-09 05:34:23 +0000 | [diff] [blame] | 566 | } |