Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 1 | % |
Fred Drake | 6663b22 | 1998-03-06 22:33:06 +0000 | [diff] [blame] | 2 | % python.sty for the Python docummentation [works only with with Latex2e] |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 3 | % |
| 4 | |
| 5 | \NeedsTeXFormat{LaTeX2e}[1995/12/01] |
| 6 | \ProvidesPackage{python} |
| 7 | [1998/01/11 LaTeX package (Python manual markup)] |
| 8 | |
| 9 | % The "fncychap" package is used to get the nice chapter headers. The |
| 10 | % .sty file is distributed with Python, so you should not need to disable |
| 11 | % it. You'd also end up with a mixed page style; uglier than stock LaTeX! |
| 12 | % |
Fred Drake | 28f1391 | 1998-03-04 21:47:59 +0000 | [diff] [blame] | 13 | \RequirePackage[Bjarne]{fncychap}\typeout{Using fancy chapter headings.} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 14 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 15 | % for PDF output, use maximal compression |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 16 | \@ifundefined{pdfannotlink}{ |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 17 | \let\LinkColor=\relax |
| 18 | \let\NormalColor=\relax |
| 19 | }{% |
| 20 | \input{pdfcolor} |
| 21 | \let\LinkColor=\NavyBlue |
| 22 | \let\NormalColor=\Black |
| 23 | \pdfcompresslevel=9 |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 24 | % |
| 25 | % This definition allows the entries in the page-view of the ToC to be |
| 26 | % active links. Some work, some don't. |
| 27 | % |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 28 | \let\OldContentsline=\contentsline |
| 29 | \renewcommand{\contentsline}[3]{% |
| 30 | \OldContentsline{#1}{% |
| 31 | \pdfannotlink attr{/Border [0 0 0]} goto name{page.#3}% |
| 32 | \LinkColor#2\NormalColor% |
| 33 | \pdfendlink% |
| 34 | }{#3}% |
| 35 | } |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 36 | \renewcommand{\thepage}{\roman{page}} |
| 37 | % |
| 38 | % This is supposed to build the "outline" view of the document; it seems |
| 39 | % quite fragile. The breakages are the same as in the ToC. |
| 40 | % |
| 41 | \AtEndDocument{ |
| 42 | \InputIfFileExists{\jobname.bkm}{\pdfcatalog pagemode{/UseOutlines}}{} |
| 43 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 44 | \let\OldLabel=\label |
| 45 | \renewcommand{\label}[1]{% |
| 46 | \OldLabel{#1}% |
| 47 | {\pdfdest name{label.#1} fit}% |
| 48 | } |
| 49 | % This stuff adds a page.# destination to every PDF page, where # has |
| 50 | % the same formatting as the displayed page number. This doesn't really |
| 51 | % help with the frontmatter, but does fine with the body. |
| 52 | % |
| 53 | % This is *heavily* based on the hyperref package. |
| 54 | % |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 55 | \def\@begindvi{% |
| 56 | \unvbox \@begindvibox |
| 57 | \@hyperfixhead |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 58 | } |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 59 | \def\hyperpageanchor{\pdfdest name{page.\thepage}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 60 | \let\HYPERPAGEANCHOR\hyperpageanchor |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 61 | \def\@hyperfixhead{% |
| 62 | \let\H@old@thehead\@thehead |
| 63 | \gdef\@foo{\pdfdest name{page.\thepage} fit}% |
| 64 | \expandafter\ifx\expandafter\@empty\H@old@thehead |
| 65 | \def\H@old@thehead{\hfil}\fi |
| 66 | \def\@thehead{\@foo\relax\H@old@thehead}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | % Increase printable page size (copied from fullpage.sty) |
| 71 | \topmargin 0pt |
| 72 | \advance \topmargin by -\headheight |
| 73 | \advance \topmargin by -\headsep |
| 74 | |
| 75 | % attempt to work a little better for A4 users |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 76 | \@ifundefined{paperheight}{ |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 77 | \textheight 9in |
| 78 | }{ |
| 79 | \textheight \paperheight |
| 80 | \advance\textheight by -2in |
| 81 | } |
| 82 | |
| 83 | \oddsidemargin 0pt |
| 84 | \evensidemargin \oddsidemargin |
| 85 | \marginparwidth 0.5in |
| 86 | |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 87 | \@ifundefined{paperwidth}{ |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 88 | \textwidth 6.5in |
| 89 | }{ |
| 90 | \textwidth \paperwidth |
| 91 | \advance\textwidth by -2in |
| 92 | } |
| 93 | |
| 94 | |
| 95 | % Style parameters and macros used by most documents here |
| 96 | \raggedbottom |
| 97 | \sloppy |
| 98 | \parindent = 0mm |
| 99 | \parskip = 2mm |
| 100 | \hbadness = 5000 % don't print trivial gripes |
| 101 | |
| 102 | \pagestyle{empty} % start this way; change for |
| 103 | \pagenumbering{roman} % ToC & chapters |
| 104 | \setcounter{secnumdepth}{1} |
| 105 | |
| 106 | % Use this to set the font family for headers and other decor: |
| 107 | \newcommand{\HeaderFamily}{\sffamily} |
| 108 | |
| 109 | % Redefine the 'normal' header/footer style when using "fancyhdr" package: |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 110 | \@ifundefined{fancyhf}{}{ |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 111 | % Use \pagestyle{normal} as the primary pagestyle for text. |
| 112 | \fancypagestyle{normal}{ |
| 113 | \fancyhf{} |
| 114 | \fancyfoot[LE,RO]{{\HeaderFamily\thepage}} |
| 115 | \fancyfoot[LO]{{\HeaderFamily\nouppercase{\rightmark}}} |
| 116 | \fancyfoot[RE]{{\HeaderFamily\nouppercase{\leftmark}}} |
| 117 | \renewcommand{\headrulewidth}{0pt} |
| 118 | \renewcommand{\footrulewidth}{0.4pt} |
| 119 | } |
| 120 | % Update the plain style so we get the page number & footer line, |
| 121 | % but not a chapter or section title. This is to keep the first |
| 122 | % page of a chapter and the blank page between chapters `clean.' |
| 123 | \fancypagestyle{plain}{ |
| 124 | \fancyhf{} |
| 125 | \fancyfoot[LE,RO]{{\HeaderFamily\thepage}} |
| 126 | \renewcommand{\headrulewidth}{0pt} |
| 127 | \renewcommand{\footrulewidth}{0.4pt} |
| 128 | } |
| 129 | % Redefine \cleardoublepage so that the blank page between chapters |
| 130 | % gets the plain style and not the fancy style. This is described |
| 131 | % in the documentation for the fancyhdr package by Piet von Oostrum. |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 132 | \@ifundefined{chapter}{}{ |
Fred Drake | 28f1391 | 1998-03-04 21:47:59 +0000 | [diff] [blame] | 133 | \renewcommand{\cleardoublepage}{ |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 134 | \clearpage\if@openright \ifodd\c@page\else |
Fred Drake | 28f1391 | 1998-03-04 21:47:59 +0000 | [diff] [blame] | 135 | \hbox{} |
| 136 | \thispagestyle{plain} |
| 137 | \newpage |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 138 | \if@twocolumn\hbox{}\newpage\fi\fi\fi |
Fred Drake | 28f1391 | 1998-03-04 21:47:59 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | % old code font selections: |
| 144 | \let\codefont=\tt |
| 145 | \let\sectcodefont=\tt |
| 146 | |
| 147 | % (Haven't found a new one that gets <, >, and _ right without being |
| 148 | % monospaced.) |
| 149 | |
| 150 | |
| 151 | % This sets up the {verbatim} environment to be indented and a minipage, |
| 152 | % and to have all the other mostly nice properties that we want for |
| 153 | % code samples. |
| 154 | |
| 155 | % Variable used by begin code command |
| 156 | \newlength{\codewidth} |
| 157 | |
| 158 | \newcommand{\examplevspace}{2mm} |
| 159 | \newcommand{\exampleindent}{1cm} |
| 160 | |
| 161 | \let\OldVerbatim=\verbatim |
| 162 | \let\OldEndVerbatim=\endverbatim |
| 163 | \renewcommand{\verbatim}{% |
| 164 | \begingroup% |
| 165 | \setlength{\parindent}\exampleindent% |
| 166 | % Calculate the text width for the minipage: |
| 167 | \setlength{\codewidth}{\linewidth}% |
| 168 | \addtolength{\codewidth}{-\parindent}% |
| 169 | % |
| 170 | \par% |
| 171 | \vspace\examplevspace% |
| 172 | \indent% |
| 173 | \begin{minipage}[t]{\codewidth}% |
| 174 | \small% |
| 175 | \OldVerbatim% |
| 176 | } |
| 177 | \renewcommand{\endverbatim}{% |
| 178 | \OldEndVerbatim% |
| 179 | \end{minipage}% |
| 180 | \endgroup% |
| 181 | } |
| 182 | |
| 183 | % Augment the sectioning commands used to get our own font family in place: |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 184 | \renewcommand{\section}{\@startsection {section}{1}{\z@}% |
| 185 | {-3.5ex \@plus -1ex \@minus -.2ex}% |
| 186 | {2.3ex \@plus.2ex}% |
| 187 | {\reset@font\Large\HeaderFamily}} |
| 188 | \renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}% |
| 189 | {-3.25ex\@plus -1ex \@minus -.2ex}% |
| 190 | {1.5ex \@plus .2ex}% |
| 191 | {\reset@font\large\HeaderFamily}} |
| 192 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}% |
| 193 | {-3.25ex\@plus -1ex \@minus -.2ex}% |
| 194 | {1.5ex \@plus .2ex}% |
| 195 | {\reset@font\normalsize\HeaderFamily}} |
| 196 | \renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}% |
| 197 | {3.25ex \@plus1ex \@minus.2ex}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 198 | {-1em}% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 199 | {\reset@font\normalsize\HeaderFamily}} |
| 200 | \renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}% |
| 201 | {3.25ex \@plus1ex \@minus .2ex}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 202 | {-1em}% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 203 | {\reset@font\normalsize\HeaderFamily}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 204 | |
| 205 | |
| 206 | % Underscore hack (only act like subscript operator if in math mode) |
| 207 | % |
| 208 | % The following is due to Mark Wooding (the old version didn't work with |
| 209 | % Latex 2e. |
| 210 | |
| 211 | \DeclareRobustCommand\hackscore{% |
| 212 | \ifmmode_\else\textunderscore\fi% |
| 213 | } |
| 214 | \begingroup |
| 215 | \catcode`\_\active |
| 216 | \def\next{% |
| 217 | \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}% |
| 218 | } |
| 219 | \expandafter\endgroup\next |
| 220 | |
| 221 | % |
| 222 | % This is the old hack, which didn't work with 2e. |
| 223 | % You should not need this since the rest of the documentation is now |
| 224 | % LaTeX2e-only. |
| 225 | % |
| 226 | %\def\_{\ifnum\fam=\ttfamily \char'137\else{\tt\char'137}\fi} |
| 227 | %\catcode`\_=12 |
| 228 | %\catcode`\_=\active\def_{\ifnum\fam=\ttfamily \char'137 \else{\tt\char'137}\fi} |
| 229 | |
| 230 | |
| 231 | |
| 232 | %% Lots of index-entry generation support. |
| 233 | |
| 234 | % Command to wrap around stuff that refers to function / module / |
| 235 | % attribute names in the index. Default behavior: like \code{}. To |
| 236 | % just keep the index entries in the roman font, uncomment the second |
| 237 | % definition to use instead; it matches O'Reilly style more. |
| 238 | % |
| 239 | \newcommand{\idxcode}[1]{\codefont{#1}} |
| 240 | %\renewcommand{\idxcode}[1]{#1} |
| 241 | |
| 242 | % Command to generate two index entries (using subentries) |
| 243 | \newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}} |
| 244 | |
| 245 | % And three entries (using only one level of subentries) |
| 246 | \newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}} |
| 247 | |
| 248 | % And four (again, using only one level of subentries) |
| 249 | \newcommand{\indexiv}[4]{ |
| 250 | \index{#1!#2 #3 #4} |
| 251 | \index{#2!#3 #4, #1} |
| 252 | \index{#3!#4, #1 #2} |
| 253 | \index{#4!#1 #2 #3} |
| 254 | } |
| 255 | |
| 256 | % Command to generate a reference to a function, statement, keyword, |
| 257 | % operator. |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 258 | \newcommand{\stindex}[1]{\indexii{statement}{#1@{\idxcode{#1}}}} |
| 259 | \newcommand{\opindex}[1]{\indexii{operator}{#1@{\idxcode{#1}}}} |
| 260 | \newcommand{\exindex}[1]{\indexii{exception}{#1@{\idxcode{#1}}}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 261 | \newcommand{\obindex}[1]{\indexii{object}{#1}} |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 262 | \newcommand{\bifuncindex}[1]{\index{#1@{\idxcode{#1()}} (built-in function)}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 263 | |
| 264 | % Add an index entry for a module |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 265 | \newcommand{\refmodule}[2]{\index{#1@{\idxcode{#1}} (#2module)}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 266 | \newcommand{\refmodindex}[1]{\refmodule{#1}{}} |
| 267 | \newcommand{\refbimodindex}[1]{\refmodule{#1}{built-in }} |
| 268 | \newcommand{\refexmodindex}[1]{\refmodule{#1}{extension }} |
| 269 | \newcommand{\refstmodindex}[1]{\refmodule{#1}{standard }} |
| 270 | |
| 271 | % support for the module index |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 272 | \if@usemoduleindex |
Fred Drake | 3455edc | 1998-03-04 21:56:42 +0000 | [diff] [blame] | 273 | \newwrite\modindexfile |
| 274 | \openout\modindexfile=mod\jobname.idx |
| 275 | \fi |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 276 | |
| 277 | % Add the defining entry for a module |
| 278 | \newcommand{\defmodindex}[2]{% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 279 | \index{#1@{\idxcode{#1}} (#2module)|textbf}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 280 | \setindexsubitem{(in module #1)}% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 281 | \if@usemoduleindex% |
Fred Drake | 3455edc | 1998-03-04 21:56:42 +0000 | [diff] [blame] | 282 | \write\modindexfile{#1 \thepage}% |
| 283 | \fi} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 284 | |
| 285 | % built-in & Python modules in the main distribution |
| 286 | \newcommand{\bimodindex}[1]{\defmodindex{#1}{built-in }} |
| 287 | \newcommand{\stmodindex}[1]{\defmodindex{#1}{standard }} |
| 288 | |
| 289 | % Python & extension modules outside the main distribution |
| 290 | \newcommand{\modindex}[1]{\defmodindex{#1}{}} |
| 291 | \newcommand{\exmodindex}[1]{\defmodindex{#1}{extension }} |
| 292 | |
| 293 | % Additional string for an index entry |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 294 | \newcommand{\index@subitem}{} |
| 295 | \newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}} |
| 296 | \newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 297 | |
| 298 | |
| 299 | % {fulllineitems} is used in one place in libregex.tex, but is really for |
| 300 | % internal use in this file. |
| 301 | % |
| 302 | \newenvironment{fulllineitems}{ |
| 303 | \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt |
| 304 | \rightmargin 0pt \topsep -\parskip \partopsep \parskip |
| 305 | \itemsep -\parsep |
| 306 | \let\makelabel=\itemnewline} |
| 307 | }{\end{list}} |
| 308 | |
| 309 | |
| 310 | % cfuncdesc should be called as |
| 311 | % \begin{cfuncdesc}{type}{name}{arglist} |
| 312 | % ... description ... |
| 313 | % \end{cfuncdesc} |
| 314 | \newenvironment{cfuncdesc}[3]{% |
| 315 | \begin{fulllineitems}% |
| 316 | \item[\code{#1 \bfcode{#2}(\varvars{#3})}]% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 317 | \index{#2@{\idxcode{#2()}}}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 318 | }{\end{fulllineitems}} |
| 319 | |
| 320 | \newenvironment{cvardesc}[2]{% |
| 321 | \begin{fulllineitems}% |
| 322 | \item[\code{#1 \bfcode{#2}}]% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 323 | \index{#2@{\idxcode{#2}}}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 324 | }{\end{fulllineitems}} |
| 325 | |
| 326 | \newenvironment{ctypedesc}[1]{% |
| 327 | \begin{fulllineitems}% |
| 328 | \item[\bfcode{#1}]\ttindex{#1} |
| 329 | }{\end{fulllineitems}} |
| 330 | |
| 331 | \newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}} |
| 332 | \newenvironment{funcdesc}[2]{% |
| 333 | \begin{fulllineitems}% |
| 334 | \funcline{#1}{#2}% |
| 335 | }{\end{fulllineitems}} |
| 336 | |
| 337 | \newcommand{\optional}[1]{% |
| 338 | {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}} |
| 339 | |
| 340 | % similar to {funcdesc}, but doesn't add to the index |
| 341 | \newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]} |
| 342 | \newenvironment{funcdescni}[2]{% |
| 343 | \begin{fulllineitems}% |
| 344 | \funclineni{#1}{#2}% |
| 345 | }{\end{fulllineitems}} |
| 346 | |
| 347 | \newenvironment{classdesc}[2]{% |
| 348 | \begin{fulllineitems}% |
| 349 | \item[\code{\bfcode{#1}(\varvars{#2})}]% |
| 350 | \ttindex{#1}% |
| 351 | \def\baseclasses##1{}% |
| 352 | }{\end{fulllineitems}} |
| 353 | |
| 354 | \newenvironment{excdesc}[1]{% |
| 355 | \begin{fulllineitems}% |
| 356 | \item[\bfcode{#1}]\ttindex{#1}% |
| 357 | }{\end{fulllineitems}} |
| 358 | |
| 359 | \newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}} |
| 360 | \newenvironment{datadesc}[1]{% |
| 361 | \begin{fulllineitems}% |
| 362 | \dataline{#1}% |
| 363 | }{\end{fulllineitems}} |
| 364 | |
| 365 | % similar to {datadesc}, but doesn't add to the index |
| 366 | \newcommand{\datalineni}[1]{\item[\bfcode{#1}]} |
| 367 | \newenvironment{datadescni}[1]{% |
| 368 | \begin{fulllineitems}% |
| 369 | \datalineni{#1}% |
| 370 | }{\end{fulllineitems}} |
| 371 | |
| 372 | \newenvironment{opcodedesc}[2]{% |
| 373 | \begin{fulllineitems}% |
| 374 | \item[\bfcode{#1}\quad\var{#2}]% |
| 375 | }{\end{fulllineitems}} |
| 376 | |
| 377 | |
| 378 | \let\nodename=\label |
| 379 | |
| 380 | % For these commands, use \command{} to get the typography right, not |
| 381 | % {\command}. This works better with the texinfo translation. |
| 382 | \newcommand{\ABC}{{\sc abc}} |
| 383 | \newcommand{\UNIX}{{\sc Unix}} |
| 384 | \newcommand{\POSIX}{POSIX} |
| 385 | \newcommand{\ASCII}{{\sc ascii}} |
| 386 | \newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}} |
| 387 | \newcommand{\C}{C} |
| 388 | \newcommand{\EOF}{{\sc eof}} |
| 389 | \newcommand{\NULL}{\code{NULL}} |
| 390 | |
| 391 | % code is the most difficult one... |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 392 | \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 | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 393 | \mbox{\codefont{#1}}}} |
| 394 | |
| 395 | \newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font |
| 396 | \newcommand{\kbd}[1]{\mbox{\tt #1}} |
| 397 | \newcommand{\key}[1]{\mbox{\tt #1}} |
| 398 | \newcommand{\samp}[1]{\mbox{`\code{#1}'}} |
| 399 | % This weird definition of \var{} allows it to always appear in roman |
| 400 | % italics, and won't get funky in code fragments when we play around |
| 401 | % with fonts. |
| 402 | \newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}} |
| 403 | \renewcommand{\emph}[1]{{\em #1\/}} |
| 404 | \newcommand{\dfn}[1]{\emph{#1}} |
| 405 | \newcommand{\strong}[1]{{\bf #1}} |
| 406 | % let's experiment with a new font: |
| 407 | \newcommand{\file}[1]{\mbox{`\small\textsf{#1}'}} |
| 408 | |
| 409 | % Use this def/redef approach for \url{} since hyperref defined this already, |
| 410 | % but only if we actually used hyperref: |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 411 | \@ifundefined{pdfannotlink}{% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 412 | \newcommand{\pythonurl}[1]{\mbox{\small\textsf{#1}}}% |
| 413 | }{ |
| 414 | \newcommand{\pythonurl}[1]{{% |
| 415 | \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}% |
| 416 | \LinkColor% color of the link text |
| 417 | \mbox{\small\textsf{#1}}% |
| 418 | \NormalColor% Turn it back off; these are declarative |
| 419 | \pdfendlink}% and don't appear bound to the current |
| 420 | }% formatting "box". |
| 421 | } |
| 422 | \let\url=\pythonurl |
| 423 | \newcommand{\email}[1]{\mbox{\small\textsf{#1}}} |
| 424 | |
| 425 | \newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}} |
| 426 | |
| 427 | \newif\iftexi\texifalse |
| 428 | \newif\iflatex\latextrue |
| 429 | |
| 430 | % These should be used for all references to identifiers which are |
| 431 | % used to refer to instances of specific language constructs. See the |
| 432 | % names for specific semantic assignments. |
| 433 | % |
| 434 | % For now, don't do anything really fancy with them; just use them as |
| 435 | % logical markup. This might change in the future. |
| 436 | % |
| 437 | \let\module=\code |
| 438 | \let\keyword=\code |
| 439 | \let\exception=\code |
| 440 | \let\class=\code |
| 441 | \let\function=\code |
| 442 | \let\member=\code |
| 443 | \let\method=\code |
| 444 | |
| 445 | \let\cfunction=\code |
| 446 | \let\ctype=\code |
| 447 | \let\cdata=\code |
| 448 | |
| 449 | % constants defined in Python modules or C headers, not language constants: |
| 450 | \let\constant=\code |
| 451 | |
| 452 | \newcommand{\manpage}[2]{{\emph{#1}(#2)}} |
| 453 | \newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}} |
| 454 | \newcommand{\program}[1]{\strong{#1}} |
| 455 | |
| 456 | |
| 457 | % Deprecation stuff. |
| 458 | % Should be extended to allow an index / list of deprecated stuff. But |
| 459 | % there's a lot of stuff that needs to be done to make that automatable. |
| 460 | % |
| 461 | % First parameter is the release number that deprecates the feature, the |
| 462 | % second is the action the should be taken by users of the feature. |
| 463 | % |
| 464 | % Example: |
| 465 | % |
| 466 | % \deprecated {1.5.1} |
| 467 | % {Use \method{frobnicate()} instead.} |
| 468 | % |
| 469 | \newcommand{\deprecated}[2]{% |
| 470 | \strong{Deprecated since release #1.} #2\par} |
| 471 | |
| 472 | |
| 473 | \newenvironment{tableii}[4]{% |
| 474 | \begin{center}% |
| 475 | \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}% |
| 476 | \begin{tabular}{#1}\hline \strong{#3}&\strong{#4} \\ \hline% |
| 477 | }{% |
| 478 | \hline% |
| 479 | \end{tabular}% |
| 480 | \end{center}% |
| 481 | } |
| 482 | |
| 483 | \newenvironment{tableiii}[5]{% |
| 484 | \begin{center}% |
| 485 | \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}% |
| 486 | \begin{tabular}{#1}\hline \strong{#3}&\strong{#4}&\strong{#5} \\ \hline% |
| 487 | }{% |
| 488 | \hline% |
| 489 | \end{tabular}% |
| 490 | \end{center}% |
| 491 | } |
| 492 | |
| 493 | \newcommand{\itemnewline}[1]{% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 494 | \@tempdima\linewidth% |
| 495 | \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | \newcommand{\sectcode}[1]{{\sectcodefont{#1}}} |
| 499 | |
| 500 | % Cross-referencing (AMK) |
| 501 | % Sample usage: |
| 502 | % \begin{seealso} |
| 503 | % \seemodule{rand}{Uniform random number generator}; % Module xref |
| 504 | % \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 505 | % |
| 506 | % % A funky case: module name contains '_'; have to supply an optional key |
| 507 | % \seemodule[copyreg]{copy_reg}{pickle interface constructor registration} |
| 508 | % |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 509 | % \end{seealso} |
| 510 | |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 511 | \newif\if@keyedmodule\@keyedmodulefalse |
| 512 | \newcommand{\@modulebadkey}{{--just-some-junk--}} |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 513 | |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 514 | \@ifundefined{pdfannotlink}{% |
| 515 | \newcommand{\seemodule}[3][\@modulebadkey]{% |
| 516 | \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi% |
| 517 | \ref{module-\@modulekey}:\quad % |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 518 | Module \module{#2}% |
| 519 | \quad (#3)% |
| 520 | } |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 521 | }{\newcommand{\seemodule}[3][\@modulebadkey]{% |
| 522 | \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi% |
| 523 | \ref{module-\@modulekey}:\quad % |
| 524 | {\pdfannotlink attr{/Border [0 0 0]} goto name{label.module-\@modulekey}% |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 525 | \LinkColor Module \module{#2} \NormalColor% |
| 526 | \pdfendlink% |
| 527 | }% |
| 528 | \quad (#3)% |
| 529 | } |
| 530 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 531 | \newenvironment{seealso}[0]{ |
| 532 | \strong{See Also:}\par |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 533 | \def\seetext##1{\par{##1}} |
| 534 | }{\par} |
| 535 | |
| 536 | |
| 537 | % Fix the theindex environment to add an entry to the Table of |
| 538 | % Contents; this is much nicer than just having to jump to the end of |
| 539 | % the book and flip around, especially with multiple indexes. |
| 540 | % |
| 541 | \let\OldTheindex=\theindex |
| 542 | \renewcommand{\theindex}{ |
| 543 | \cleardoublepage |
| 544 | \OldTheindex |
| 545 | \addcontentsline{toc}{chapter}{\indexname} |
| 546 | } |
| 547 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 548 | % Allow the release number to be specified independently of the |
| 549 | % \date{}. This allows the date to reflect the document's date and |
| 550 | % release to specify the Python release that is documented. |
| 551 | % |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 552 | \newcommand{\@release}{} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 553 | \newcommand{\version}{} |
| 554 | \newcommand{\releasename}{Release} |
| 555 | \newcommand{\release}[1]{% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 556 | \renewcommand{\@release}{\releasename\space\version}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 557 | \renewcommand{\version}{#1}} |
| 558 | |
| 559 | % Allow specification of the author's address separately from the |
| 560 | % author's name. This can be used to format them differently, which |
| 561 | % is a good thing. |
| 562 | % |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 563 | \newcommand{\@authoraddress}{} |
| 564 | \newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 565 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 566 | % This sets up the fancy chapter headings that make the documents look |
| 567 | % at least a little better than the usual LaTeX output. |
| 568 | % |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 569 | \@ifundefined{ChTitleVar}{}{ |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 570 | \ChNameVar{\raggedleft\normalsize\HeaderFamily} |
| 571 | \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily} |
| 572 | \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily} |
| 573 | % This creates chapter heads without the leading \vspace*{}: |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 574 | \def\@makechapterhead#1{% |
| 575 | {\parindent \z@ \raggedright \normalfont |
| 576 | \ifnum \c@secnumdepth >\m@ne |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 577 | \DOCH |
| 578 | \fi |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame^] | 579 | \interlinepenalty\@M |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 580 | \DOTI{#1} |
| 581 | } |
| 582 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | % Tell TeX about pathological hyphenation cases: |
| 586 | \hyphenation{Base-HTTP-Re-quest-Hand-ler} |