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 | b390daf | 1998-03-09 16:35:36 +0000 | [diff] [blame] | 272 | \newif\if@UseModuleIndex |
| 273 | \@UseModuleIndexfalse |
| 274 | |
Fred Drake | b390daf | 1998-03-09 16:35:36 +0000 | [diff] [blame] | 275 | % Fix the theindex environment to add an entry to the Table of |
| 276 | % Contents; this is much nicer than just having to jump to the end of |
| 277 | % the book and flip around, especially with multiple indexes. |
| 278 | % |
| 279 | \let\OldTheindex=\theindex |
| 280 | \renewcommand{\theindex}{ |
| 281 | \cleardoublepage |
| 282 | \OldTheindex |
| 283 | \addcontentsline{toc}{chapter}{\indexname} |
Fred Drake | b390daf | 1998-03-09 16:35:36 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 286 | % these should dump an error or warning to the transcript |
Fred Drake | b390daf | 1998-03-09 16:35:36 +0000 | [diff] [blame] | 287 | \newcommand{\@thismodule}{$<<$ ERROR - NO CURRENT MODULE $>>$} |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 288 | \newcommand{\@thisclass}{$<<$ ERROR - NO CURRENT CLASS $>>$} |
Fred Drake | b390daf | 1998-03-09 16:35:36 +0000 | [diff] [blame] | 289 | |
| 290 | \newcommand{\makemodindex}{ |
| 291 | \newwrite\modindexfile |
| 292 | \openout\modindexfile=mod\jobname.idx |
| 293 | \@UseModuleIndextrue |
| 294 | } |
| 295 | |
| 296 | \newcommand{\inputindex}[1]{ |
| 297 | \IfFileExists{#1}{\input{#1}}{\begin{theindex}\end{theindex}} |
| 298 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 299 | |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 300 | % Add the defining entry for a module |
| 301 | \newcommand{\@modindex}[2]{% |
| 302 | \renewcommand{\@thismodule}{#1} |
| 303 | \setindexsubitem{(in module \@thismodule)}% |
| 304 | \index{#1@{\idxcode{#1}} (#2module)|textbf}% |
| 305 | \if@UseModuleIndex% |
| 306 | \write\modindexfile{\protect\indexentry{#1@{\tt #1}}{\thepage}}% |
| 307 | \fi% |
| 308 | } |
| 309 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 310 | % built-in & Python modules in the main distribution |
Fred Drake | b390daf | 1998-03-09 16:35:36 +0000 | [diff] [blame] | 311 | \newcommand{\bimodindex}[1]{\@modindex{#1}{built-in }} |
| 312 | \newcommand{\stmodindex}[1]{\@modindex{#1}{standard }} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 313 | |
| 314 | % Python & extension modules outside the main distribution |
Fred Drake | b390daf | 1998-03-09 16:35:36 +0000 | [diff] [blame] | 315 | \newcommand{\modindex}[1]{\@modindex{#1}{}} |
| 316 | \newcommand{\exmodindex}[1]{\@modindex{#1}{extension }} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 317 | |
| 318 | % Additional string for an index entry |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 319 | \newcommand{\index@subitem}{} |
| 320 | \newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}} |
| 321 | \newcommand{\ttindex}[1]{\index{#1@{\idxcode{#1}} \index@subitem}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 322 | |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 323 | \newcommand{\withsubitem}[2]{% |
| 324 | \begingroup% |
| 325 | \def\index@subitem{#1}#2% |
| 326 | \endgroup% |
| 327 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 328 | |
| 329 | % {fulllineitems} is used in one place in libregex.tex, but is really for |
| 330 | % internal use in this file. |
| 331 | % |
| 332 | \newenvironment{fulllineitems}{ |
| 333 | \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt |
| 334 | \rightmargin 0pt \topsep -\parskip \partopsep \parskip |
| 335 | \itemsep -\parsep |
| 336 | \let\makelabel=\itemnewline} |
| 337 | }{\end{list}} |
| 338 | |
| 339 | |
| 340 | % cfuncdesc should be called as |
| 341 | % \begin{cfuncdesc}{type}{name}{arglist} |
| 342 | % ... description ... |
| 343 | % \end{cfuncdesc} |
| 344 | \newenvironment{cfuncdesc}[3]{% |
| 345 | \begin{fulllineitems}% |
| 346 | \item[\code{#1 \bfcode{#2}(\varvars{#3})}]% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 347 | \index{#2@{\idxcode{#2()}}}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 348 | }{\end{fulllineitems}} |
| 349 | |
| 350 | \newenvironment{cvardesc}[2]{% |
| 351 | \begin{fulllineitems}% |
| 352 | \item[\code{#1 \bfcode{#2}}]% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 353 | \index{#2@{\idxcode{#2}}}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 354 | }{\end{fulllineitems}} |
| 355 | |
| 356 | \newenvironment{ctypedesc}[1]{% |
| 357 | \begin{fulllineitems}% |
| 358 | \item[\bfcode{#1}]\ttindex{#1} |
| 359 | }{\end{fulllineitems}} |
| 360 | |
| 361 | \newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}} |
| 362 | \newenvironment{funcdesc}[2]{% |
| 363 | \begin{fulllineitems}% |
| 364 | \funcline{#1}{#2}% |
| 365 | }{\end{fulllineitems}} |
| 366 | |
| 367 | \newcommand{\optional}[1]{% |
| 368 | {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}} |
| 369 | |
| 370 | % similar to {funcdesc}, but doesn't add to the index |
| 371 | \newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\varvars{#2})}]} |
| 372 | \newenvironment{funcdescni}[2]{% |
| 373 | \begin{fulllineitems}% |
| 374 | \funclineni{#1}{#2}% |
| 375 | }{\end{fulllineitems}} |
| 376 | |
| 377 | \newenvironment{classdesc}[2]{% |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 378 | \renewcommand{\@thisclass}{#1}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 379 | \begin{fulllineitems}% |
| 380 | \item[\code{\bfcode{#1}(\varvars{#2})}]% |
Fred Drake | ae25be2 | 1998-03-16 05:26:10 +0000 | [diff] [blame] | 381 | \withsubitem{(class in \@thismodule)}{\ttindex{#1}}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 382 | \def\baseclasses##1{}% |
| 383 | }{\end{fulllineitems}} |
| 384 | |
| 385 | \newenvironment{excdesc}[1]{% |
| 386 | \begin{fulllineitems}% |
| 387 | \item[\bfcode{#1}]\ttindex{#1}% |
| 388 | }{\end{fulllineitems}} |
| 389 | |
| 390 | \newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}} |
| 391 | \newenvironment{datadesc}[1]{% |
| 392 | \begin{fulllineitems}% |
| 393 | \dataline{#1}% |
| 394 | }{\end{fulllineitems}} |
| 395 | |
| 396 | % similar to {datadesc}, but doesn't add to the index |
| 397 | \newcommand{\datalineni}[1]{\item[\bfcode{#1}]} |
| 398 | \newenvironment{datadescni}[1]{% |
| 399 | \begin{fulllineitems}% |
| 400 | \datalineni{#1}% |
| 401 | }{\end{fulllineitems}} |
| 402 | |
| 403 | \newenvironment{opcodedesc}[2]{% |
| 404 | \begin{fulllineitems}% |
| 405 | \item[\bfcode{#1}\quad\var{#2}]% |
| 406 | }{\end{fulllineitems}} |
| 407 | |
| 408 | |
| 409 | \let\nodename=\label |
| 410 | |
| 411 | % For these commands, use \command{} to get the typography right, not |
| 412 | % {\command}. This works better with the texinfo translation. |
| 413 | \newcommand{\ABC}{{\sc abc}} |
| 414 | \newcommand{\UNIX}{{\sc Unix}} |
| 415 | \newcommand{\POSIX}{POSIX} |
| 416 | \newcommand{\ASCII}{{\sc ascii}} |
| 417 | \newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}} |
| 418 | \newcommand{\C}{C} |
| 419 | \newcommand{\EOF}{{\sc eof}} |
| 420 | \newcommand{\NULL}{\code{NULL}} |
| 421 | |
| 422 | % code is the most difficult one... |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 423 | \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] | 424 | \mbox{\codefont{#1}}}} |
| 425 | |
| 426 | \newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font |
| 427 | \newcommand{\kbd}[1]{\mbox{\tt #1}} |
| 428 | \newcommand{\key}[1]{\mbox{\tt #1}} |
| 429 | \newcommand{\samp}[1]{\mbox{`\code{#1}'}} |
| 430 | % This weird definition of \var{} allows it to always appear in roman |
| 431 | % italics, and won't get funky in code fragments when we play around |
| 432 | % with fonts. |
| 433 | \newcommand{\var}[1]{\mbox{\normalsize\textrm{\textit{#1\/}}}} |
| 434 | \renewcommand{\emph}[1]{{\em #1\/}} |
| 435 | \newcommand{\dfn}[1]{\emph{#1}} |
| 436 | \newcommand{\strong}[1]{{\bf #1}} |
| 437 | % let's experiment with a new font: |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 438 | \newcommand{\file}[1]{`{\small\textsf{#1}}'} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 439 | |
| 440 | % Use this def/redef approach for \url{} since hyperref defined this already, |
| 441 | % but only if we actually used hyperref: |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 442 | \@ifundefined{pdfannotlink}{% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 443 | \newcommand{\pythonurl}[1]{\mbox{\small\textsf{#1}}}% |
| 444 | }{ |
| 445 | \newcommand{\pythonurl}[1]{{% |
| 446 | \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}% |
| 447 | \LinkColor% color of the link text |
| 448 | \mbox{\small\textsf{#1}}% |
| 449 | \NormalColor% Turn it back off; these are declarative |
| 450 | \pdfendlink}% and don't appear bound to the current |
| 451 | }% formatting "box". |
| 452 | } |
| 453 | \let\url=\pythonurl |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 454 | \newcommand{\email}[1]{{\small\textsf{#1}}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 455 | |
| 456 | \newcommand{\varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}} |
| 457 | |
| 458 | \newif\iftexi\texifalse |
| 459 | \newif\iflatex\latextrue |
| 460 | |
| 461 | % These should be used for all references to identifiers which are |
| 462 | % used to refer to instances of specific language constructs. See the |
| 463 | % names for specific semantic assignments. |
| 464 | % |
| 465 | % For now, don't do anything really fancy with them; just use them as |
| 466 | % logical markup. This might change in the future. |
| 467 | % |
| 468 | \let\module=\code |
| 469 | \let\keyword=\code |
| 470 | \let\exception=\code |
| 471 | \let\class=\code |
| 472 | \let\function=\code |
| 473 | \let\member=\code |
| 474 | \let\method=\code |
| 475 | |
| 476 | \let\cfunction=\code |
| 477 | \let\ctype=\code |
| 478 | \let\cdata=\code |
| 479 | |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 480 | \newcommand{\mimetype}[1]{{\small\textsf{#1}}} |
Fred Drake | 94fac13 | 1998-03-12 19:37:03 +0000 | [diff] [blame] | 481 | % The \! is a "negative thin space" in math mode. |
| 482 | \newcommand{\regexp}[1]{% |
| 483 | {\tiny$^{^\lceil}\!\!$% |
| 484 | {\normalsize\code{#1}}% |
| 485 | $\!\!\rfloor\!$% |
| 486 | }} |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 487 | \newcommand{\envvar}[1]{% |
Fred Drake | 94fac13 | 1998-03-12 19:37:03 +0000 | [diff] [blame] | 488 | \$#1% $ <-- bow to font-lock 3 times! |
| 489 | \index{#1@{\$#1}}% $ |
| 490 | \index{environment variables!{\$#1}}% $ |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 491 | } |
| 492 | \let\character=\samp |
| 493 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 494 | % constants defined in Python modules or C headers, not language constants: |
| 495 | \let\constant=\code |
| 496 | |
| 497 | \newcommand{\manpage}[2]{{\emph{#1}(#2)}} |
| 498 | \newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}} |
| 499 | \newcommand{\program}[1]{\strong{#1}} |
| 500 | |
| 501 | |
| 502 | % Deprecation stuff. |
| 503 | % Should be extended to allow an index / list of deprecated stuff. But |
| 504 | % there's a lot of stuff that needs to be done to make that automatable. |
| 505 | % |
| 506 | % First parameter is the release number that deprecates the feature, the |
| 507 | % second is the action the should be taken by users of the feature. |
| 508 | % |
| 509 | % Example: |
| 510 | % |
| 511 | % \deprecated {1.5.1} |
| 512 | % {Use \method{frobnicate()} instead.} |
| 513 | % |
| 514 | \newcommand{\deprecated}[2]{% |
| 515 | \strong{Deprecated since release #1.} #2\par} |
| 516 | |
| 517 | |
| 518 | \newenvironment{tableii}[4]{% |
| 519 | \begin{center}% |
| 520 | \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}% |
| 521 | \begin{tabular}{#1}\hline \strong{#3}&\strong{#4} \\ \hline% |
| 522 | }{% |
| 523 | \hline% |
| 524 | \end{tabular}% |
| 525 | \end{center}% |
| 526 | } |
| 527 | |
| 528 | \newenvironment{tableiii}[5]{% |
| 529 | \begin{center}% |
| 530 | \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}% |
| 531 | \begin{tabular}{#1}\hline \strong{#3}&\strong{#4}&\strong{#5} \\ \hline% |
| 532 | }{% |
| 533 | \hline% |
| 534 | \end{tabular}% |
| 535 | \end{center}% |
| 536 | } |
| 537 | |
| 538 | \newcommand{\itemnewline}[1]{% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 539 | \@tempdima\linewidth% |
| 540 | \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | \newcommand{\sectcode}[1]{{\sectcodefont{#1}}} |
| 544 | |
| 545 | % Cross-referencing (AMK) |
| 546 | % Sample usage: |
| 547 | % \begin{seealso} |
| 548 | % \seemodule{rand}{Uniform random number generator}; % Module xref |
| 549 | % \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 550 | % |
| 551 | % % A funky case: module name contains '_'; have to supply an optional key |
| 552 | % \seemodule[copyreg]{copy_reg}{pickle interface constructor registration} |
| 553 | % |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 554 | % \end{seealso} |
| 555 | |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 556 | \newif\if@keyedmodule\@keyedmodulefalse |
| 557 | \newcommand{\@modulebadkey}{{--just-some-junk--}} |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 558 | |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 559 | \@ifundefined{pdfannotlink}{% |
| 560 | \newcommand{\seemodule}[3][\@modulebadkey]{% |
| 561 | \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi% |
| 562 | \ref{module-\@modulekey}:\quad % |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 563 | Module \module{#2}% |
| 564 | \quad (#3)% |
| 565 | } |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 566 | }{\newcommand{\seemodule}[3][\@modulebadkey]{% |
| 567 | \ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi% |
| 568 | \ref{module-\@modulekey}:\quad % |
| 569 | {\pdfannotlink attr{/Border [0 0 0]} goto name{label.module-\@modulekey}% |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 570 | \LinkColor Module \module{#2} \NormalColor% |
| 571 | \pdfendlink% |
| 572 | }% |
| 573 | \quad (#3)% |
| 574 | } |
| 575 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 576 | \newenvironment{seealso}[0]{ |
| 577 | \strong{See Also:}\par |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 578 | \def\seetext##1{\par{##1}} |
| 579 | }{\par} |
| 580 | |
| 581 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 582 | % Allow the release number to be specified independently of the |
| 583 | % \date{}. This allows the date to reflect the document's date and |
| 584 | % release to specify the Python release that is documented. |
| 585 | % |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 586 | \newcommand{\@release}{} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 587 | \newcommand{\version}{} |
| 588 | \newcommand{\releasename}{Release} |
| 589 | \newcommand{\release}[1]{% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 590 | \renewcommand{\@release}{\releasename\space\version}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 591 | \renewcommand{\version}{#1}} |
| 592 | |
| 593 | % Allow specification of the author's address separately from the |
| 594 | % author's name. This can be used to format them differently, which |
| 595 | % is a good thing. |
| 596 | % |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 597 | \newcommand{\@authoraddress}{} |
| 598 | \newcommand{\authoraddress}[1]{\renewcommand{\@authoraddress}{#1}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 599 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 600 | % This sets up the fancy chapter headings that make the documents look |
| 601 | % at least a little better than the usual LaTeX output. |
| 602 | % |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 603 | \@ifundefined{ChTitleVar}{}{ |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 604 | \ChNameVar{\raggedleft\normalsize\HeaderFamily} |
| 605 | \ChNumVar{\raggedleft \bfseries\Large\HeaderFamily} |
| 606 | \ChTitleVar{\raggedleft \rm\Huge\HeaderFamily} |
| 607 | % This creates chapter heads without the leading \vspace*{}: |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 608 | \def\@makechapterhead#1{% |
| 609 | {\parindent \z@ \raggedright \normalfont |
| 610 | \ifnum \c@secnumdepth >\m@ne |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 611 | \DOCH |
| 612 | \fi |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 613 | \interlinepenalty\@M |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 614 | \DOTI{#1} |
| 615 | } |
| 616 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | % Tell TeX about pathological hyphenation cases: |
| 620 | \hyphenation{Base-HTTP-Re-quest-Hand-ler} |