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} |
Fred Drake | c0b2e45 | 1998-03-25 14:53:43 +0000 | [diff] [blame] | 7 | [1998/01/11 LaTeX package (Python markup)] |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 8 | |
Fred Drake | 454a4fb | 1998-04-01 22:20:14 +0000 | [diff] [blame] | 9 | % These packages can be used to add marginal annotations which indicate |
| 10 | % index entries and labels; useful for reviewing this messy documentation! |
| 11 | % |
| 12 | %\RequirePackage{showkeys} |
| 13 | %\RequirePackage{showidx} |
| 14 | |
Fred Drake | c0b2e45 | 1998-03-25 14:53:43 +0000 | [diff] [blame] | 15 | % for PDF output, use maximal compression & a lot of other stuff |
| 16 | % (test for PDF recommended by Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov>) |
| 17 | % |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 18 | \newif\ifpy@doing@page@targets |
| 19 | \py@doing@page@targetsfalse |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 20 | |
Fred Drake | c0b2e45 | 1998-03-25 14:53:43 +0000 | [diff] [blame] | 21 | \ifx\pdfoutput\undefined\else\ifcase\pdfoutput |
Fred Drake | c0b2e45 | 1998-03-25 14:53:43 +0000 | [diff] [blame] | 22 | \else |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 23 | \input{pdfcolor} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 24 | \let\py@LinkColor=\NavyBlue |
| 25 | \let\py@NormalColor=\Black |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 26 | \pdfcompresslevel=9 |
Fred Drake | ba1700c | 1998-05-11 20:42:54 +0000 | [diff] [blame] | 27 | \pdfpagewidth=\paperwidth % page width of PDF output |
| 28 | \pdfpageheight=\paperheight % page height of PDF output |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 29 | % |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 30 | % Pad the number with '0' to 3 digits wide so no page name is a prefix |
| 31 | % of any other. |
| 32 | % |
Fred Drake | a488f30 | 1998-07-23 17:50:45 +0000 | [diff] [blame] | 33 | \newcommand{\py@targetno}[1]{\ifnum#1<100 0\fi\ifnum#1<10 0\fi#1} |
| 34 | \newcommand{\py@pageno}{\py@targetno\thepage} |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 35 | % |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 36 | % This definition allows the entries in the page-view of the ToC to be |
| 37 | % active links. Some work, some don't. |
| 38 | % |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 39 | \let\py@OldContentsline=\contentsline |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 40 | % Compute the padded page number separately since we end up with a pair of |
| 41 | % \relax tokens; this gets the right string computed and works. |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 42 | \renewcommand{\contentsline}[3]{% |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 43 | \def\my@pageno{\py@targetno{#3}}% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 44 | \py@OldContentsline{#1}{% |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 45 | \pdfannotlink attr{/Border [0 0 0]} goto name{page\my@pageno}% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 46 | \py@LinkColor#2\py@NormalColor% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 47 | \pdfendlink% |
| 48 | }{#3}% |
| 49 | } |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 50 | \AtEndDocument{ |
Fred Drake | c0b2e45 | 1998-03-25 14:53:43 +0000 | [diff] [blame] | 51 | \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{} |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 52 | } |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 53 | \newcommand{\py@target}[1]{% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 54 | \ifpy@doing@page@targets% |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 55 | {\pdfdest name{#1} fit}% |
| 56 | \fi% |
| 57 | } |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 58 | \let\py@OldLabel=\label |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 59 | \renewcommand{\label}[1]{% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 60 | \py@OldLabel{#1}% |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 61 | \py@target{label-#1}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 62 | } |
Fred Drake | ba1700c | 1998-05-11 20:42:54 +0000 | [diff] [blame] | 63 | % This stuff adds a page# destination to every PDF page, where # is three |
| 64 | % digits wide, padded with leading zeros. This doesn't really help with |
| 65 | % the frontmatter, but does fine with the body. |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 66 | % |
| 67 | % This is *heavily* based on the hyperref package. |
| 68 | % |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 69 | \def\@begindvi{% |
| 70 | \unvbox \@begindvibox |
| 71 | \@hyperfixhead |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 72 | } |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 73 | \def\@hyperfixhead{% |
| 74 | \let\H@old@thehead\@thehead |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 75 | \global\def\@foo{\py@target{page\py@pageno}}% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 76 | \expandafter\ifx\expandafter\@empty\H@old@thehead |
| 77 | \def\H@old@thehead{\hfil}\fi |
| 78 | \def\@thehead{\@foo\relax\H@old@thehead}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 79 | } |
Fred Drake | c0b2e45 | 1998-03-25 14:53:43 +0000 | [diff] [blame] | 80 | \fi\fi |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 81 | |
| 82 | % Increase printable page size (copied from fullpage.sty) |
| 83 | \topmargin 0pt |
| 84 | \advance \topmargin by -\headheight |
| 85 | \advance \topmargin by -\headsep |
| 86 | |
| 87 | % attempt to work a little better for A4 users |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 88 | \@ifundefined{paperheight}{ |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 89 | \textheight 9in |
| 90 | }{ |
| 91 | \textheight \paperheight |
| 92 | \advance\textheight by -2in |
| 93 | } |
| 94 | |
| 95 | \oddsidemargin 0pt |
| 96 | \evensidemargin \oddsidemargin |
| 97 | \marginparwidth 0.5in |
| 98 | |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 99 | \@ifundefined{paperwidth}{ |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 100 | \textwidth 6.5in |
| 101 | }{ |
| 102 | \textwidth \paperwidth |
| 103 | \advance\textwidth by -2in |
| 104 | } |
| 105 | |
| 106 | |
| 107 | % Style parameters and macros used by most documents here |
| 108 | \raggedbottom |
| 109 | \sloppy |
| 110 | \parindent = 0mm |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 111 | \parskip = 2mm |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 112 | \hbadness = 5000 % don't print trivial gripes |
| 113 | |
| 114 | \pagestyle{empty} % start this way; change for |
| 115 | \pagenumbering{roman} % ToC & chapters |
| 116 | \setcounter{secnumdepth}{1} |
| 117 | |
| 118 | % Use this to set the font family for headers and other decor: |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 119 | \newcommand{\py@HeaderFamily}{\sffamily} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 120 | |
| 121 | % Redefine the 'normal' header/footer style when using "fancyhdr" package: |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 122 | \@ifundefined{fancyhf}{}{ |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 123 | % Use \pagestyle{normal} as the primary pagestyle for text. |
| 124 | \fancypagestyle{normal}{ |
| 125 | \fancyhf{} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 126 | \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}} |
| 127 | \fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}} |
| 128 | \fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 129 | \renewcommand{\headrulewidth}{0pt} |
| 130 | \renewcommand{\footrulewidth}{0.4pt} |
| 131 | } |
| 132 | % Update the plain style so we get the page number & footer line, |
| 133 | % but not a chapter or section title. This is to keep the first |
| 134 | % page of a chapter and the blank page between chapters `clean.' |
| 135 | \fancypagestyle{plain}{ |
| 136 | \fancyhf{} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 137 | \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 138 | \renewcommand{\headrulewidth}{0pt} |
| 139 | \renewcommand{\footrulewidth}{0.4pt} |
| 140 | } |
| 141 | % Redefine \cleardoublepage so that the blank page between chapters |
| 142 | % gets the plain style and not the fancy style. This is described |
| 143 | % in the documentation for the fancyhdr package by Piet von Oostrum. |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 144 | \@ifundefined{chapter}{}{ |
Fred Drake | 28f1391 | 1998-03-04 21:47:59 +0000 | [diff] [blame] | 145 | \renewcommand{\cleardoublepage}{ |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 146 | \clearpage\if@openright \ifodd\c@page\else |
Fred Drake | 28f1391 | 1998-03-04 21:47:59 +0000 | [diff] [blame] | 147 | \hbox{} |
| 148 | \thispagestyle{plain} |
| 149 | \newpage |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 150 | \if@twocolumn\hbox{}\newpage\fi\fi\fi |
Fred Drake | 28f1391 | 1998-03-04 21:47:59 +0000 | [diff] [blame] | 151 | } |
| 152 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 155 | % This sets up the {verbatim} environment to be indented and a minipage, |
| 156 | % and to have all the other mostly nice properties that we want for |
| 157 | % code samples. |
| 158 | |
| 159 | % Variable used by begin code command |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 160 | \newlength{\py@codewidth} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 161 | |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 162 | \newcommand{\py@examplevspace}{2mm} |
| 163 | \newcommand{\py@exampleindent}{1cm} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 164 | |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 165 | \let\py@OldVerbatim=\verbatim |
| 166 | \let\py@OldEndVerbatim=\endverbatim |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 167 | \renewcommand{\verbatim}{% |
| 168 | \begingroup% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 169 | \setlength{\parindent}\py@exampleindent% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 170 | % Calculate the text width for the minipage: |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 171 | \setlength{\py@codewidth}{\linewidth}% |
| 172 | \addtolength{\py@codewidth}{-\parindent}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 173 | % |
| 174 | \par% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 175 | \vspace\py@examplevspace% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 176 | \indent% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 177 | \begin{minipage}[t]{\py@codewidth}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 178 | \small% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 179 | \py@OldVerbatim% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 180 | } |
| 181 | \renewcommand{\endverbatim}{% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 182 | \py@OldEndVerbatim% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 183 | \end{minipage}% |
| 184 | \endgroup% |
| 185 | } |
| 186 | |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 187 | |
Fred Drake | a488f30 | 1998-07-23 17:50:45 +0000 | [diff] [blame] | 188 | \newcommand{\py@modulebadkey}{{--just-some-junk--}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 189 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 190 | |
| 191 | %% Lots of index-entry generation support. |
| 192 | |
| 193 | % Command to wrap around stuff that refers to function / module / |
| 194 | % attribute names in the index. Default behavior: like \code{}. To |
| 195 | % just keep the index entries in the roman font, uncomment the second |
Fred Drake | a488f30 | 1998-07-23 17:50:45 +0000 | [diff] [blame] | 196 | % definition; it matches O'Reilly style more. |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 197 | % |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 198 | \newcommand{\py@idxcode}[1]{\texttt{#1}} |
| 199 | %\renewcommand{\py@idxcode}[1]{#1} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 200 | |
| 201 | % Command to generate two index entries (using subentries) |
| 202 | \newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}} |
| 203 | |
| 204 | % And three entries (using only one level of subentries) |
| 205 | \newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}} |
| 206 | |
| 207 | % And four (again, using only one level of subentries) |
| 208 | \newcommand{\indexiv}[4]{ |
| 209 | \index{#1!#2 #3 #4} |
| 210 | \index{#2!#3 #4, #1} |
| 211 | \index{#3!#4, #1 #2} |
| 212 | \index{#4!#1 #2 #3} |
| 213 | } |
| 214 | |
| 215 | % Command to generate a reference to a function, statement, keyword, |
| 216 | % operator. |
Fred Drake | 0cabff9 | 1998-05-06 19:36:01 +0000 | [diff] [blame] | 217 | \newcommand{\kwindex}[1]{\indexii{keyword}{#1@{\py@idxcode{#1}}}} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 218 | \newcommand{\stindex}[1]{\indexii{statement}{#1@{\py@idxcode{#1}}}} |
| 219 | \newcommand{\opindex}[1]{\indexii{operator}{#1@{\py@idxcode{#1}}}} |
| 220 | \newcommand{\exindex}[1]{\indexii{exception}{#1@{\py@idxcode{#1}}}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 221 | \newcommand{\obindex}[1]{\indexii{object}{#1}} |
Fred Drake | 2351c80 | 1998-04-02 18:48:32 +0000 | [diff] [blame] | 222 | \newcommand{\bifuncindex}[1]{\withsubitem{(built-in function)}{\ttindex{#1()}}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 223 | |
| 224 | % Add an index entry for a module |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 225 | \newcommand{\py@refmodule}[2]{\index{#1@{\py@idxcode{#1}} (#2module)}} |
| 226 | \newcommand{\refmodindex}[1]{\py@refmodule{#1}{}} |
| 227 | \newcommand{\refbimodindex}[1]{\py@refmodule{#1}{built-in }} |
| 228 | \newcommand{\refexmodindex}[1]{\py@refmodule{#1}{extension }} |
| 229 | \newcommand{\refstmodindex}[1]{\py@refmodule{#1}{standard }} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 230 | |
| 231 | % support for the module index |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 232 | \newif\ifpy@UseModuleIndex |
| 233 | \py@UseModuleIndexfalse |
Fred Drake | b390daf | 1998-03-09 16:35:36 +0000 | [diff] [blame] | 234 | |
Fred Drake | b390daf | 1998-03-09 16:35:36 +0000 | [diff] [blame] | 235 | \newcommand{\makemodindex}{ |
| 236 | \newwrite\modindexfile |
| 237 | \openout\modindexfile=mod\jobname.idx |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 238 | \py@UseModuleIndextrue |
Fred Drake | b390daf | 1998-03-09 16:35:36 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 241 | % Add the defining entry for a module |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 242 | \newcommand{\py@modindex}[2]{% |
Fred Drake | a488f30 | 1998-07-23 17:50:45 +0000 | [diff] [blame] | 243 | \renewcommand{\py@thismodule}{#1} |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 244 | \setindexsubitem{(in module #1)}% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 245 | \index{#1@{\py@idxcode{#1}} (#2module)|textbf}% |
| 246 | \ifpy@UseModuleIndex% |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 247 | \write\modindexfile{\protect\indexentry{#1@{\tt #1}}{\thepage}}% |
| 248 | \fi% |
| 249 | } |
| 250 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 251 | % built-in & Python modules in the main distribution |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 252 | \newcommand{\bimodindex}[1]{\py@modindex{#1}{built-in }} |
| 253 | \newcommand{\stmodindex}[1]{\py@modindex{#1}{standard }} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 254 | |
| 255 | % Python & extension modules outside the main distribution |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 256 | \newcommand{\modindex}[1]{\py@modindex{#1}{}} |
| 257 | \newcommand{\exmodindex}[1]{\py@modindex{#1}{extension }} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 258 | |
| 259 | % Additional string for an index entry |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 260 | \newcommand{\index@subitem}{} |
| 261 | \newcommand{\setindexsubitem}[1]{\renewcommand{\index@subitem}{#1}} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 262 | \newcommand{\ttindex}[1]{\index{#1@{\py@idxcode{#1}} \index@subitem}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 263 | |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 264 | \newcommand{\withsubitem}[2]{% |
| 265 | \begingroup% |
| 266 | \def\index@subitem{#1}#2% |
| 267 | \endgroup% |
| 268 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 269 | |
Fred Drake | 5371497 | 1998-04-02 22:33:16 +0000 | [diff] [blame] | 270 | |
Fred Drake | a488f30 | 1998-07-23 17:50:45 +0000 | [diff] [blame] | 271 | % Module synopsis processing ----------------------------------------------- |
| 272 | % |
| 273 | \newcommand{\py@standardIndexModule}[1]{\stmodindex{#1}} |
| 274 | \newcommand{\py@builtinIndexModule}[1]{\bimodindex{#1}} |
| 275 | \newcommand{\py@extensionIndexModule}[1]{\exmodindex{#1}} |
| 276 | \newcommand{\py@IndexModule}[1]{\modindex{#1}} |
| 277 | |
| 278 | \newif\ifpy@HaveModSynopsis\py@HaveModSynopsisfalse |
| 279 | \newif\ifpy@ModSynopsisFileIsOpen\py@ModSynopsisFileIsOpenfalse |
| 280 | |
| 281 | % \declaremodule[key]{type}{name} |
| 282 | \newcommand{\declaremodule}[3][\py@modulebadkey]{ |
| 283 | \py@openModSynopsisFile |
| 284 | \renewcommand{\py@thismoduletype}{#2} |
| 285 | \csname py@#2IndexModule\endcsname{#3} |
| 286 | \ifx\py@modulebadkey#1 |
| 287 | \renewcommand{\py@thismodulekey}{#3} |
| 288 | \else |
| 289 | \renewcommand{\py@thismodulekey}{#1} |
| 290 | \fi |
| 291 | \label{module-\py@thismodulekey} |
| 292 | \py@HaveModSynopsistrue |
| 293 | } |
| 294 | |
Fred Drake | b75c615 | 1998-08-10 18:41:43 +0000 | [diff] [blame] | 295 | % \moduleauthor{name}{email} |
| 296 | \newcommand{\moduleauthor}[2]{} |
| 297 | |
| 298 | % \sectionauthor{name}{email} |
| 299 | \newcommand{\sectionauthor}[2]{} |
| 300 | |
Fred Drake | a488f30 | 1998-07-23 17:50:45 +0000 | [diff] [blame] | 301 | |
| 302 | \newcommand{\py@defsynopsis}{Module has no synopsis.} |
| 303 | \newcommand{\py@modulesynopsis}{\py@defsynopsis} |
| 304 | \newcommand{\modulesynopsis}[1]{ |
| 305 | \renewcommand{\py@modulesynopsis}{#1} |
| 306 | } |
| 307 | |
| 308 | % define the file |
| 309 | \newwrite\py@ModSynopsisFile |
| 310 | |
| 311 | % hacked from \addtocontents from latex.ltx: |
| 312 | \long\def\py@writeModSynopsisFile#1{% |
| 313 | \protected@write\py@ModSynopsisFile% |
| 314 | {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}% |
| 315 | {\string#1}% |
| 316 | } |
| 317 | \newcommand{\py@closeModSynopsisFile}{ |
| 318 | \ifpy@ModSynopsisFileIsOpen |
| 319 | \closeout\py@ModSynopsisFile |
| 320 | \py@ModSynopsisFileIsOpenfalse |
| 321 | \fi |
| 322 | } |
| 323 | \newcommand{\py@openModSynopsisFile}{ |
| 324 | \ifpy@ModSynopsisFileIsOpen\else |
| 325 | \openout\py@ModSynopsisFile=\py@ModSynopsisFilename |
| 326 | \py@ModSynopsisFileIsOpentrue |
| 327 | \fi |
| 328 | } |
| 329 | |
| 330 | \newcommand{\py@ProcessModSynopsis}{ |
| 331 | \ifpy@HaveModSynopsis |
| 332 | \py@writeModSynopsisFile{\modulesynopsis% |
| 333 | {\py@thismodulekey}{\py@thismodule}% |
| 334 | {\py@thismoduletype}{\py@modulesynopsis}}% |
| 335 | \py@HaveModSynopsisfalse |
| 336 | \fi |
| 337 | \renewcommand{\py@modulesynopsis}{\py@defsynopsis} |
| 338 | } |
| 339 | \AtEndDocument{\py@ProcessModSynopsis\py@closeModSynopsisFile} |
| 340 | |
| 341 | \newcommand{\localmoduletable}{ |
| 342 | \IfFileExists{\py@ModSynopsisFilename}{ |
| 343 | \begin{synopsistable} |
| 344 | \input{\py@ModSynopsisFilename} |
| 345 | \end{synopsistable} |
| 346 | }{} |
| 347 | } |
| 348 | |
| 349 | \@ifundefined{pdfoutput}{ |
| 350 | \newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\} |
| 351 | }{ |
| 352 | \newcommand{\py@ModSynopsisSummary}[4]{ |
| 353 | {\pdfannotlink attr{/Border [0 0 0]} goto name{label-module-#1} |
| 354 | \py@LinkColor \bfcode{#2} \py@NormalColor |
| 355 | \pdfendlink}& #4\\} |
| 356 | } |
| 357 | \newenvironment{synopsistable}{ |
| 358 | % key, name, type, synopsis |
| 359 | \let\modulesynopsis=\py@ModSynopsisSummary |
| 360 | \begin{tabular}{ll} |
| 361 | }{ |
| 362 | \end{tabular} |
| 363 | } |
| 364 | % |
| 365 | % -------------------------------------------------------------------------- |
| 366 | |
| 367 | |
| 368 | \newcommand{\py@thisclass}{} |
| 369 | \newcommand{\py@thismodule}{} |
| 370 | \newcommand{\py@thismodulekey}{} |
| 371 | \newcommand{\py@thismoduletype}{} |
| 372 | |
| 373 | \newcommand{\py@reset}{ |
| 374 | \py@ProcessModSynopsis |
| 375 | \renewcommand{\py@thisclass}{} |
| 376 | \renewcommand{\py@thismodule}{} |
| 377 | \renewcommand{\py@thismodulekey}{} |
| 378 | \renewcommand{\py@thismoduletype}{} |
| 379 | } |
| 380 | |
| 381 | % Augment the sectioning commands used to get our own font family in place, |
| 382 | % and reset some internal data items: |
| 383 | \renewcommand{\section}{\py@reset% |
| 384 | \@startsection{section}{1}{\z@}% |
| 385 | {-3.5ex \@plus -1ex \@minus -.2ex}% |
| 386 | {2.3ex \@plus.2ex}% |
| 387 | {\reset@font\Large\py@HeaderFamily}} |
| 388 | \renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}% |
| 389 | {-3.25ex\@plus -1ex \@minus -.2ex}% |
| 390 | {1.5ex \@plus .2ex}% |
| 391 | {\reset@font\large\py@HeaderFamily}} |
| 392 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}% |
| 393 | {-3.25ex\@plus -1ex \@minus -.2ex}% |
| 394 | {1.5ex \@plus .2ex}% |
| 395 | {\reset@font\normalsize\py@HeaderFamily}} |
| 396 | \renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}% |
| 397 | {3.25ex \@plus1ex \@minus.2ex}% |
| 398 | {-1em}% |
| 399 | {\reset@font\normalsize\py@HeaderFamily}} |
| 400 | \renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}% |
| 401 | {3.25ex \@plus1ex \@minus .2ex}% |
| 402 | {-1em}% |
| 403 | {\reset@font\normalsize\py@HeaderFamily}} |
| 404 | |
| 405 | |
Fred Drake | 5420f33 | 1998-07-23 21:41:02 +0000 | [diff] [blame] | 406 | % This gets the underscores closer to the right width; the only change |
| 407 | % from standard LaTeX is the width specified. |
| 408 | |
| 409 | \DeclareTextCommandDefault{\textunderscore}{% |
| 410 | \leavevmode \kern.06em\vbox{\hrule\@width.55em}} |
| 411 | |
Fred Drake | a488f30 | 1998-07-23 17:50:45 +0000 | [diff] [blame] | 412 | % Underscore hack (only act like subscript operator if in math mode) |
| 413 | % |
| 414 | % The following is due to Mark Wooding (the old version didn't work with |
| 415 | % Latex 2e. |
| 416 | |
| 417 | \DeclareRobustCommand\hackscore{% |
| 418 | \ifmmode_\else\textunderscore\fi% |
| 419 | } |
| 420 | \begingroup |
| 421 | \catcode`\_\active |
| 422 | \def\next{% |
| 423 | \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}% |
| 424 | } |
| 425 | \expandafter\endgroup\next |
| 426 | |
| 427 | |
Fred Drake | 5371497 | 1998-04-02 22:33:16 +0000 | [diff] [blame] | 428 | % Now for a lot of semantically-loaded environments that do a ton of magical |
| 429 | % things to get the right formatting and index entries for the stuff in |
| 430 | % Python modules and C API. |
| 431 | |
| 432 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 433 | % {fulllineitems} is used in one place in libregex.tex, but is really for |
| 434 | % internal use in this file. |
| 435 | % |
| 436 | \newenvironment{fulllineitems}{ |
| 437 | \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt |
| 438 | \rightmargin 0pt \topsep -\parskip \partopsep \parskip |
| 439 | \itemsep -\parsep |
| 440 | \let\makelabel=\itemnewline} |
| 441 | }{\end{list}} |
| 442 | |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 443 | % \optional is mostly for use in the arguments parameters to the various |
| 444 | % {*desc} environments defined below, but may be used elsewhere. Known to |
| 445 | % be used in the debugger chapter. |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 446 | % |
| 447 | % Typical usage: |
| 448 | % |
| 449 | % \begin{funcdesc}{myfunc}{reqparm\optional{, optparm}} |
| 450 | % ^^^ ^^^ |
| 451 | % No space here No space here |
| 452 | % |
| 453 | % When a function has multiple optional parameters, \optional should be |
| 454 | % nested, not chained. This is right: |
| 455 | % |
| 456 | % \begin{funcdesc}{myfunc}{\optional{parm1\optional{, parm2}}} |
| 457 | % |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 458 | \newcommand{\optional}[1]{% |
| 459 | {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}} |
| 460 | |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 461 | % C functions ------------------------------------------------------------ |
| 462 | % \begin{cfuncdesc}{type}{name}{arglist} |
| 463 | \newenvironment{cfuncdesc}[3]{ |
| 464 | \begin{fulllineitems} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 465 | \item[\code{#1 \bfcode{#2}(\py@varvars{#3})}\index{#2@{\py@idxcode{#2()}}}] |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 466 | }{\end{fulllineitems}} |
| 467 | |
| 468 | % C variables ------------------------------------------------------------ |
| 469 | % \begin{cvardesc}{type}{name} |
| 470 | \newenvironment{cvardesc}[2]{ |
| 471 | \begin{fulllineitems} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 472 | \item[\code{#1 \bfcode{#2}}\index{#2@{\py@idxcode{#2}}}] |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 473 | }{\end{fulllineitems}} |
| 474 | |
| 475 | % C data types ----------------------------------------------------------- |
| 476 | % \begin{ctypedesc}{typedef name} |
| 477 | \newenvironment{ctypedesc}[1]{ |
| 478 | \begin{fulllineitems} |
| 479 | \item[\bfcode{#1}\ttindex{#1}] |
| 480 | }{\end{fulllineitems}} |
| 481 | |
| 482 | % simple functions (not methods) ----------------------------------------- |
| 483 | % \begin{funcdesc}{name}{args} |
| 484 | \newcommand{\funcline}[2]{\funclineni{#1}{#2}\ttindex{#1()}} |
| 485 | \newenvironment{funcdesc}[2]{ |
| 486 | \begin{fulllineitems} |
| 487 | \funcline{#1}{#2} |
| 488 | }{\end{fulllineitems}} |
| 489 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 490 | % similar to {funcdesc}, but doesn't add to the index |
Fred Drake | 300775d | 1998-04-17 02:17:00 +0000 | [diff] [blame] | 491 | \newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\py@varvars{#2})}]} |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 492 | \newenvironment{funcdescni}[2]{ |
| 493 | \begin{fulllineitems} |
| 494 | \funclineni{#1}{#2} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 495 | }{\end{fulllineitems}} |
| 496 | |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 497 | % classes ---------------------------------------------------------------- |
| 498 | % \begin{classdesc}{name}{constructor args} |
| 499 | \newenvironment{classdesc}[2]{ |
Fred Drake | a488f30 | 1998-07-23 17:50:45 +0000 | [diff] [blame] | 500 | \renewcommand{\py@thisclass}{#1} |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 501 | \begin{fulllineitems} |
Fred Drake | 300775d | 1998-04-17 02:17:00 +0000 | [diff] [blame] | 502 | \item[\code{\bfcode{#1}(\py@varvars{#2})}% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 503 | \withsubitem{(class in \py@thismodule)}{\ttindex{#1}}] |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 504 | }{\end{fulllineitems}} |
| 505 | |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 506 | |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 507 | \let\py@classbadkey=\@undefined |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 508 | |
| 509 | % object method ---------------------------------------------------------- |
| 510 | % \begin{methoddesc}[classname]{methodname}{args} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 511 | \newcommand{\methodline}[3][\py@classbadkey]{ |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 512 | \methodlineni{#2}{#3} |
| 513 | \ifx#1\@undefined |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 514 | \withsubitem{(\py@thisclass\ method)}{\ttindex{#2()}} |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 515 | \else |
| 516 | \withsubitem{(#1 method)}{\ttindex{#2()}} |
| 517 | \fi |
| 518 | } |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 519 | \newenvironment{methoddesc}[3][\py@classbadkey]{ |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 520 | \begin{fulllineitems} |
| 521 | \ifx#1\@undefined |
| 522 | \methodline{#2}{#3} |
| 523 | \else |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 524 | \def\py@thisclass{#1} |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 525 | \methodline[#1]{#2}{#3} |
| 526 | \fi |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 527 | }{\end{fulllineitems}} |
| 528 | |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 529 | % similar to {methoddesc}, but doesn't add to the index |
| 530 | % (never actually uses the optional argument) |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 531 | \newcommand{\methodlineni}[3][\py@classbadkey]{% |
Fred Drake | 300775d | 1998-04-17 02:17:00 +0000 | [diff] [blame] | 532 | \item[\code{\bfcode{#2}(\py@varvars{#3})}]} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 533 | \newenvironment{methoddescni}[3][\py@classbadkey]{ |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 534 | \begin{fulllineitems} |
| 535 | \methodlineni{#2}{#3} |
| 536 | }{\end{fulllineitems}} |
| 537 | |
| 538 | % object data attribute -------------------------------------------------- |
| 539 | % \begin{memberdesc}[classname]{membername} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 540 | \newcommand{\memberline}[2][\py@classbadkey]{% |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 541 | \ifx#1\@undefined |
| 542 | \memberlineni{#2} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 543 | \withsubitem{(\py@thisclass\ attribute)}{\ttindex{#2}} |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 544 | \else |
| 545 | \memberlineni{#2} |
Fred Drake | 41565f6 | 1998-04-07 19:32:40 +0000 | [diff] [blame] | 546 | \withsubitem{(#1 attribute)}{\ttindex{#2}} |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 547 | \fi |
| 548 | } |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 549 | \newenvironment{memberdesc}[2][\py@classbadkey]{ |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 550 | \begin{fulllineitems} |
| 551 | \ifx#1\@undefined |
| 552 | \memberline{#2} |
| 553 | \else |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 554 | \def\py@thisclass{#1} |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 555 | \memberline[#1]{#2} |
| 556 | \fi |
| 557 | }{\end{fulllineitems}} |
| 558 | |
| 559 | % similar to {memberdesc}, but doesn't add to the index |
| 560 | % (never actually uses the optional argument) |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 561 | \newcommand{\memberlineni}[2][\py@classbadkey]{\item[\bfcode{#2}]} |
| 562 | \newenvironment{memberdescni}[2][\py@classbadkey]{ |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 563 | \begin{fulllineitems} |
| 564 | \memberlineni{#2} |
| 565 | }{\end{fulllineitems}} |
| 566 | |
| 567 | % For exceptions: -------------------------------------------------------- |
| 568 | % \begin{excdesc}{name} |
| 569 | % -- need support for constructor; maybe use optional parameter? |
| 570 | \newenvironment{excdesc}[1]{ |
| 571 | \begin{fulllineitems} |
| 572 | \item[\bfcode{#1}\ttindex{#1}] |
| 573 | }{\end{fulllineitems}} |
| 574 | |
| 575 | % Module data or constants: ---------------------------------------------- |
| 576 | % \begin{datadesc}{name} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 577 | \newcommand{\dataline}[1]{\datalineni{#1}\ttindex{#1}} |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 578 | \newenvironment{datadesc}[1]{ |
| 579 | \begin{fulllineitems} |
| 580 | \dataline{#1} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 581 | }{\end{fulllineitems}} |
| 582 | |
| 583 | % similar to {datadesc}, but doesn't add to the index |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 584 | \newcommand{\datalineni}[1]{\item[\bfcode{#1}]\nopagebreak} |
| 585 | \newenvironment{datadescni}[1]{ |
| 586 | \begin{fulllineitems} |
| 587 | \datalineni{#1} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 588 | }{\end{fulllineitems}} |
| 589 | |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 590 | % bytecode instruction --------------------------------------------------- |
| 591 | % \begin{opcodedesc}{name}{var} |
| 592 | % -- {var} may be {} |
| 593 | \newenvironment{opcodedesc}[2]{ |
| 594 | \begin{fulllineitems} |
| 595 | \item[\bfcode{#1}\quad\var{#2}] |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 596 | }{\end{fulllineitems}} |
| 597 | |
| 598 | |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 599 | \newcommand{\nodename}[1]{\label{#1}} |
Fred Drake | 5573031 | 1998-03-25 15:41:23 +0000 | [diff] [blame] | 600 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 601 | % For these commands, use \command{} to get the typography right, not |
| 602 | % {\command}. This works better with the texinfo translation. |
| 603 | \newcommand{\ABC}{{\sc abc}} |
| 604 | \newcommand{\UNIX}{{\sc Unix}} |
| 605 | \newcommand{\POSIX}{POSIX} |
| 606 | \newcommand{\ASCII}{{\sc ascii}} |
| 607 | \newcommand{\Cpp}{C\protect\raisebox{.18ex}{++}} |
| 608 | \newcommand{\C}{C} |
| 609 | \newcommand{\EOF}{{\sc eof}} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 610 | \newcommand{\NULL}{\constant{NULL}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 611 | |
Fred Drake | 5371497 | 1998-04-02 22:33:16 +0000 | [diff] [blame] | 612 | % Also for consistency: spell Python "Python", not "python"! |
| 613 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 614 | % code is the most difficult one... |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 615 | \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 | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 616 | \texttt{#1}}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 617 | |
| 618 | \newcommand{\bfcode}[1]{\code{\bfseries#1}} % bold-faced code font |
Fred Drake | 8e54abe | 1998-07-01 14:49:25 +0000 | [diff] [blame] | 619 | \newcommand{\kbd}[1]{\code{#1}} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 620 | \newcommand{\samp}[1]{`\code{#1}'} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 621 | % This weird definition of \var{} allows it to always appear in roman |
| 622 | % italics, and won't get funky in code fragments when we play around |
| 623 | % with fonts. |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 624 | \newcommand{\var}[1]{\normalsize\textrm{\textit{#1\/}}} |
| 625 | \renewcommand{\emph}[1]{{\em #1}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 626 | \newcommand{\dfn}[1]{\emph{#1}} |
| 627 | \newcommand{\strong}[1]{{\bf #1}} |
| 628 | % let's experiment with a new font: |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 629 | \newcommand{\file}[1]{`{\small\textsf{#1}}'} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 630 | |
| 631 | % Use this def/redef approach for \url{} since hyperref defined this already, |
| 632 | % but only if we actually used hyperref: |
Fred Drake | 6cb7149 | 1998-03-27 05:22:53 +0000 | [diff] [blame] | 633 | \@ifundefined{pdfannotlink}{ |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 634 | \newcommand{\py@url}[1]{\mbox{\small\textsf{#1}}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 635 | }{ |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 636 | \newcommand{\py@url}[1]{{% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 637 | \pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 638 | \py@LinkColor% color of the link text |
| 639 | \mbox{\small\textsf{#1}}% |
| 640 | \py@NormalColor% Turn it back off; these are declarative |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 641 | \pdfendlink}% and don't appear bound to the current |
| 642 | }% formatting "box". |
| 643 | } |
Fred Drake | a2c2a83 | 1998-04-15 17:50:01 +0000 | [diff] [blame] | 644 | \let\url=\py@url |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 645 | \newcommand{\email}[1]{{\small\textsf{#1}}} |
Fred Drake | 454a4fb | 1998-04-01 22:20:14 +0000 | [diff] [blame] | 646 | \newcommand{\newsgroup}[1]{{\small\textsf{#1}}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 647 | |
Fred Drake | 300775d | 1998-04-17 02:17:00 +0000 | [diff] [blame] | 648 | \newcommand{\py@varvars}[1]{{\def\,{\/{\char`\,}}\var{#1}}} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 649 | % let's see if this breaks anything now; we may be able to simplify... |
| 650 | \renewcommand{\py@varvars}[1]{\var{#1}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 651 | |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 652 | % I'd really like to get rid of this! |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 653 | \newif\iftexi\texifalse |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 654 | |
Fred Drake | 1e4973b | 1998-07-28 21:52:17 +0000 | [diff] [blame] | 655 | % This is used to get l2h to put the copyright and abstract on |
| 656 | % a separate HTML page. |
| 657 | \newif\ifhtml\htmlfalse |
| 658 | |
| 659 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 660 | % These should be used for all references to identifiers which are |
| 661 | % used to refer to instances of specific language constructs. See the |
| 662 | % names for specific semantic assignments. |
| 663 | % |
| 664 | % For now, don't do anything really fancy with them; just use them as |
| 665 | % logical markup. This might change in the future. |
| 666 | % |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 667 | \newcommand{\module}[1]{\texttt{#1}} |
| 668 | \newcommand{\keyword}[1]{\texttt{#1}} |
| 669 | \newcommand{\exception}[1]{\texttt{#1}} |
| 670 | \newcommand{\class}[1]{\texttt{#1}} |
| 671 | \newcommand{\function}[1]{\texttt{#1}} |
| 672 | \newcommand{\member}[1]{\texttt{#1}} |
| 673 | \newcommand{\method}[1]{\texttt{#1}} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 674 | |
Fred Drake | 5371497 | 1998-04-02 22:33:16 +0000 | [diff] [blame] | 675 | \newcommand{\pytype}[1]{#1} % built-in Python type |
| 676 | |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 677 | \newcommand{\cfunction}[1]{\texttt{#1}} |
| 678 | \newcommand{\ctype}[1]{\texttt{#1}} % C struct or typedef name |
| 679 | \newcommand{\cdata}[1]{\texttt{#1}} % C variable, typically global |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 680 | |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 681 | \newcommand{\mimetype}[1]{{\small\textsf{#1}}} |
Fred Drake | 94fac13 | 1998-03-12 19:37:03 +0000 | [diff] [blame] | 682 | % The \! is a "negative thin space" in math mode. |
| 683 | \newcommand{\regexp}[1]{% |
| 684 | {\tiny$^{^\lceil}\!\!$% |
| 685 | {\normalsize\code{#1}}% |
Fred Drake | 47cfd03 | 1998-04-03 21:22:31 +0000 | [diff] [blame] | 686 | $\!\rfloor\!$% |
Fred Drake | 94fac13 | 1998-03-12 19:37:03 +0000 | [diff] [blame] | 687 | }} |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 688 | \newcommand{\envvar}[1]{% |
Fred Drake | 94fac13 | 1998-03-12 19:37:03 +0000 | [diff] [blame] | 689 | \$#1% $ <-- bow to font-lock 3 times! |
| 690 | \index{#1@{\$#1}}% $ |
| 691 | \index{environment variables!{\$#1}}% $ |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 692 | } |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 693 | \newcommand{\makevar}[1]{#1} % variable in a Makefile |
| 694 | \newcommand{\character}[1]{\samp{#1}} |
Fred Drake | 0ee9f72 | 1998-03-12 06:41:40 +0000 | [diff] [blame] | 695 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 696 | % constants defined in Python modules or C headers, not language constants: |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 697 | \newcommand{\constant}[1]{\code{#1}} % manifest constant, not syntactic |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 698 | |
| 699 | \newcommand{\manpage}[2]{{\emph{#1}(#2)}} |
| 700 | \newcommand{\rfc}[1]{RFC #1\index{RFC!RFC #1}} |
| 701 | \newcommand{\program}[1]{\strong{#1}} |
| 702 | |
| 703 | |
| 704 | % Deprecation stuff. |
| 705 | % Should be extended to allow an index / list of deprecated stuff. But |
| 706 | % there's a lot of stuff that needs to be done to make that automatable. |
| 707 | % |
| 708 | % First parameter is the release number that deprecates the feature, the |
| 709 | % second is the action the should be taken by users of the feature. |
| 710 | % |
| 711 | % Example: |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 712 | % \deprecated{1.5.1}{Use \method{frobnicate()} instead.} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 713 | % |
| 714 | \newcommand{\deprecated}[2]{% |
| 715 | \strong{Deprecated since release #1.} #2\par} |
| 716 | |
Fred Drake | af958c7 | 1998-07-27 20:32:33 +0000 | [diff] [blame] | 717 | % New stuff. |
| 718 | % This should be used to mark things which have been added to the |
| 719 | % development tree but that aren't in the release, but are documented. |
| 720 | % This allows release of documentation that already includes updated |
| 721 | % descriptions. |
| 722 | % |
| 723 | % Example: |
| 724 | % \versionadded{1.5.2} |
| 725 | % |
| 726 | \newcommand{\versionadded}[1]{% |
| 727 | \strong{New in version #1.}\par} |
| 728 | \newcommand{\versionchanged}[1]{% |
| 729 | \strong{Changed in version #1.}\par} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 730 | |
Fred Drake | af958c7 | 1998-07-27 20:32:33 +0000 | [diff] [blame] | 731 | |
| 732 | % Tables. |
| 733 | % |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 734 | \newenvironment{tableii}[4]{% |
| 735 | \begin{center}% |
| 736 | \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}% |
Fred Drake | ee60191 | 1998-04-11 20:53:03 +0000 | [diff] [blame] | 737 | \begin{tabular}{#1}\strong{#3}&\strong{#4} \\ \hline% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 738 | }{% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 739 | \end{tabular}% |
| 740 | \end{center}% |
| 741 | } |
| 742 | |
| 743 | \newenvironment{tableiii}[5]{% |
| 744 | \begin{center}% |
| 745 | \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}% |
Fred Drake | ee60191 | 1998-04-11 20:53:03 +0000 | [diff] [blame] | 746 | \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\ \hline% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 747 | }{% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 748 | \end{tabular}% |
| 749 | \end{center}% |
| 750 | } |
| 751 | |
Fred Drake | 30e5265 | 1998-07-24 22:11:29 +0000 | [diff] [blame] | 752 | \newenvironment{tableiv}[6]{% |
| 753 | \begin{center}% |
| 754 | \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}% |
| 755 | \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6} \\% |
| 756 | \hline% |
| 757 | }{% |
| 758 | \end{tabular}% |
| 759 | \end{center}% |
| 760 | } |
| 761 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 762 | \newcommand{\itemnewline}[1]{% |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 763 | \@tempdima\linewidth% |
| 764 | \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Fred Drake | 0cabff9 | 1998-05-06 19:36:01 +0000 | [diff] [blame] | 767 | % Define \itembreak: force the text after an item to start on a new line |
| 768 | \newcommand{\itembreak}{% |
| 769 | \mbox{}% |
| 770 | \\*[0mm]% |
| 771 | } |
| 772 | |
| 773 | % Define \itemjoin: some negative vspace to join two items together |
| 774 | \newcommand{\itemjoin}{% |
| 775 | \mbox{}% |
| 776 | \vspace{-\itemsep}% |
| 777 | \vspace{-\parsep}% |
| 778 | } |
| 779 | |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 780 | % Cross-referencing (AMK, new impl. FLD) |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 781 | % Sample usage: |
| 782 | % \begin{seealso} |
| 783 | % \seemodule{rand}{Uniform random number generator}; % Module xref |
| 784 | % \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 785 | % |
| 786 | % % A funky case: module name contains '_'; have to supply an optional key |
| 787 | % \seemodule[copyreg]{copy_reg}{pickle interface constructor registration} |
| 788 | % |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 789 | % \end{seealso} |
| 790 | |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 791 | \@ifundefined{pdfannotlink}{% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 792 | \newcommand{\py@seemodule}[3][\py@modulebadkey]{% |
| 793 | \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi% |
| 794 | \ref{module-\py@modulekey}:\quad % |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 795 | Module \module{#2}% |
| 796 | \quad (#3)% |
| 797 | } |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 798 | }{\newcommand{\py@seemodule}[3][\py@modulebadkey]{% |
| 799 | \ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi% |
| 800 | \ref{module-\py@modulekey}:\quad % |
| 801 | {\pdfannotlink attr{/Border [0 0 0]} goto name{label-module-\py@modulekey}% |
| 802 | \py@LinkColor Module \module{#2} \py@NormalColor% |
Fred Drake | ebcb658 | 1998-03-06 21:25:17 +0000 | [diff] [blame] | 803 | \pdfendlink% |
| 804 | }% |
| 805 | \quad (#3)% |
| 806 | } |
| 807 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 808 | \newenvironment{seealso}[0]{ |
| 809 | \strong{See Also:}\par |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 810 | \def\seetext##1{\par{##1}} |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 811 | \let\seemodule=\py@seemodule |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 812 | }{\par} |
| 813 | |
| 814 | |
Fred Drake | af958c7 | 1998-07-27 20:32:33 +0000 | [diff] [blame] | 815 | % Allow the Python release number to be specified independently of the |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 816 | % \date{}. This allows the date to reflect the document's date and |
| 817 | % release to specify the Python release that is documented. |
| 818 | % |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 819 | \newcommand{\py@release}{} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 820 | \newcommand{\version}{} |
| 821 | \newcommand{\releasename}{Release} |
| 822 | \newcommand{\release}[1]{% |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 823 | \renewcommand{\py@release}{\releasename\space\version}% |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 824 | \renewcommand{\version}{#1}} |
| 825 | |
| 826 | % Allow specification of the author's address separately from the |
| 827 | % author's name. This can be used to format them differently, which |
| 828 | % is a good thing. |
| 829 | % |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 830 | \newcommand{\py@authoraddress}{} |
| 831 | \newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress}{#1}} |
Fred Drake | 6df93ef | 1998-05-14 20:56:31 +0000 | [diff] [blame] | 832 | \let\developersaddress=\authoraddress |
| 833 | \let\developer=\author |
| 834 | \let\developers=\author |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 835 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 836 | % This sets up the fancy chapter headings that make the documents look |
| 837 | % at least a little better than the usual LaTeX output. |
| 838 | % |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 839 | \@ifundefined{ChTitleVar}{}{ |
Fred Drake | 24340ea | 1998-04-28 18:30:34 +0000 | [diff] [blame] | 840 | \ChNameVar{\raggedleft\normalsize\py@HeaderFamily} |
| 841 | \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily} |
| 842 | \ChTitleVar{\raggedleft \rm\Huge\py@HeaderFamily} |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 843 | % This creates chapter heads without the leading \vspace*{}: |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 844 | \def\@makechapterhead#1{% |
| 845 | {\parindent \z@ \raggedright \normalfont |
| 846 | \ifnum \c@secnumdepth >\m@ne |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 847 | \DOCH |
| 848 | \fi |
Fred Drake | 1c8d0e0 | 1998-03-07 05:29:15 +0000 | [diff] [blame] | 849 | \interlinepenalty\@M |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 850 | \DOTI{#1} |
| 851 | } |
| 852 | } |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 853 | } |
| 854 | |
Fred Drake | 3bf7865 | 1998-05-20 17:42:17 +0000 | [diff] [blame] | 855 | |
| 856 | % Definition lists; requested by AMK for HOWTO documents. Probably useful |
| 857 | % elsewhere as well, so keep in in the general style support. |
| 858 | % |
| 859 | \newenvironment{definitions}{% |
| 860 | \begin{description}% |
| 861 | \def\term##1{\item[##1]\itembreak} |
| 862 | }{% |
| 863 | \end{description}% |
| 864 | } |
| 865 | |
Fred Drake | 6659c30 | 1998-03-03 22:02:19 +0000 | [diff] [blame] | 866 | % Tell TeX about pathological hyphenation cases: |
| 867 | \hyphenation{Base-HTTP-Re-quest-Hand-ler} |