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