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