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