source: fact/tools/pyscripts/doc/_build/latex/sphinx.sty@ 13151

Last change on this file since 13151 was 13151, checked in by lusterma, 13 years ago
added doc; this is just an example, nothing ready, to be adapted to work at ISDC, I just made this some time ago on my Laptop
File size: 14.1 KB
Line 
1%
2% sphinx.sty
3%
4% Adapted from the old python.sty, mostly written by Fred Drake,
5% by Georg Brandl.
6%
7
8\NeedsTeXFormat{LaTeX2e}[1995/12/01]
9\ProvidesPackage{sphinx}[2010/01/15 LaTeX package (Sphinx markup)]
10
11\RequirePackage{textcomp}
12\RequirePackage{fancyhdr}
13\RequirePackage{fancybox}
14\RequirePackage{titlesec}
15\RequirePackage{tabulary}
16\RequirePackage{amsmath} % for \text
17\RequirePackage{makeidx}
18\RequirePackage{framed}
19\RequirePackage{color}
20% For highlighted code.
21\RequirePackage{fancyvrb}
22% For table captions.
23\RequirePackage{threeparttable}
24% Handle footnotes in tables.
25\RequirePackage{footnote}
26\makesavenoteenv{tabulary}
27% For floating figures in the text.
28\RequirePackage{wrapfig}
29% Separate paragraphs by space by default.
30\RequirePackage{parskip}
31
32% Redefine these colors to your liking in the preamble.
33\definecolor{TitleColor}{rgb}{0.126,0.263,0.361}
34\definecolor{InnerLinkColor}{rgb}{0.208,0.374,0.486}
35\definecolor{OuterLinkColor}{rgb}{0.216,0.439,0.388}
36% Redefine these colors to something not white if you want to have colored
37% background and border for code examples.
38\definecolor{VerbatimColor}{rgb}{1,1,1}
39\definecolor{VerbatimBorderColor}{rgb}{1,1,1}
40
41% Uncomment these two lines to ignore the paper size and make the page
42% size more like a typical published manual.
43%\renewcommand{\paperheight}{9in}
44%\renewcommand{\paperwidth}{8.5in} % typical squarish manual
45%\renewcommand{\paperwidth}{7in} % O'Reilly ``Programmming Python''
46
47% For graphicx, check if we are compiling under latex or pdflatex.
48\ifx\pdftexversion\undefined
49 \usepackage{graphicx}
50\else
51 \usepackage[pdftex]{graphicx}
52\fi
53
54% for PDF output, use colors and maximal compression
55\newif\ifsphinxpdfoutput\sphinxpdfoutputfalse
56\ifx\pdfoutput\undefined\else\ifcase\pdfoutput
57 \let\py@NormalColor\relax
58 \let\py@TitleColor\relax
59\else
60 \sphinxpdfoutputtrue
61 \input{pdfcolor}
62 \def\py@NormalColor{\color[rgb]{0.0,0.0,0.0}}
63 \def\py@TitleColor{\color{TitleColor}}
64 \pdfcompresslevel=9
65\fi\fi
66
67% XeLaTeX can do colors, too
68\ifx\XeTeXrevision\undefined\else
69 \def\py@NormalColor{\color[rgb]{0.0,0.0,0.0}}
70 \def\py@TitleColor{\color{TitleColor}}
71\fi
72
73% Increase printable page size (copied from fullpage.sty)
74\topmargin 0pt
75\advance \topmargin by -\headheight
76\advance \topmargin by -\headsep
77
78% attempt to work a little better for A4 users
79\textheight \paperheight
80\advance\textheight by -2in
81
82\oddsidemargin 0pt
83\evensidemargin 0pt
84%\evensidemargin -.25in % for ``manual size'' documents
85\marginparwidth 0.5in
86
87\textwidth \paperwidth
88\advance\textwidth by -2in
89
90
91% Style parameters and macros used by most documents here
92\raggedbottom
93\sloppy
94\hbadness = 5000 % don't print trivial gripes
95
96\pagestyle{empty} % start this way; change for
97\pagenumbering{roman} % ToC & chapters
98
99% Use this to set the font family for headers and other decor:
100\newcommand{\py@HeaderFamily}{\sffamily\bfseries}
101
102% Redefine the 'normal' header/footer style when using "fancyhdr" package:
103\@ifundefined{fancyhf}{}{
104 % Use \pagestyle{normal} as the primary pagestyle for text.
105 \fancypagestyle{normal}{
106 \fancyhf{}
107 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
108 \fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
109 \fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
110 \fancyhead[LE,RO]{{\py@HeaderFamily \@title, \py@release}}
111 \renewcommand{\headrulewidth}{0.4pt}
112 \renewcommand{\footrulewidth}{0.4pt}
113 }
114 % Update the plain style so we get the page number & footer line,
115 % but not a chapter or section title. This is to keep the first
116 % page of a chapter and the blank page between chapters `clean.'
117 \fancypagestyle{plain}{
118 \fancyhf{}
119 \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
120 \renewcommand{\headrulewidth}{0pt}
121 \renewcommand{\footrulewidth}{0.4pt}
122 }
123}
124
125% Some custom font markup commands.
126%
127\newcommand{\strong}[1]{{\bf #1}}
128\newcommand{\code}[1]{\texttt{#1}}
129\newcommand{\bfcode}[1]{\code{\bfseries#1}}
130\newcommand{\samp}[1]{`\code{#1}'}
131\newcommand{\email}[1]{\textsf{#1}}
132
133% Redefine the Verbatim environment to allow border and background colors.
134% The original environment is still used for verbatims within tables.
135\let\OriginalVerbatim=\Verbatim
136\let\endOriginalVerbatim=\endVerbatim
137
138% Play with vspace to be able to keep the indentation.
139\newlength\distancetoright
140\newlength\leftsidespace
141\def\mycolorbox#1{%
142 \setlength\leftsidespace{\@totalleftmargin}%
143 \setlength\distancetoright{\linewidth}%
144 \advance\distancetoright -\@totalleftmargin %
145 \noindent\hspace*{\@totalleftmargin}%
146 \fcolorbox{VerbatimBorderColor}{VerbatimColor}{%
147 \begin{minipage}{\distancetoright}%
148 \noindent\hspace*{-\leftsidespace}%
149 #1
150 \end{minipage}%
151 }%
152}
153\def\FrameCommand{\mycolorbox}
154
155\renewcommand{\Verbatim}[1][1]{%
156 % list starts new par, but we don't want it to be set apart vertically
157 \bgroup\parskip=0pt%
158 \smallskip%
159 % The list environement is needed to control perfectly the vertical
160 % space.
161 \list{}{%
162 \setlength\parskip{0pt}%
163 \setlength\itemsep{0ex}%
164 \setlength\topsep{0ex}%
165 \setlength\partopsep{0pt}%
166 \setlength\leftmargin{0pt}%
167 }%
168 \item\MakeFramed {\FrameRestore}%
169 \small%
170 \OriginalVerbatim[#1]%
171}
172\renewcommand{\endVerbatim}{%
173 \endOriginalVerbatim%
174 \endMakeFramed%
175 \endlist%
176 % close group to restore \parskip
177 \egroup%
178}
179
180
181% Index-entry generation support.
182%
183
184% Command to generate two index entries (using subentries)
185\newcommand{\indexii}[2]{\index{#1!#2}\index{#2!#1}}
186
187% And three entries (using only one level of subentries)
188\newcommand{\indexiii}[3]{\index{#1!#2 #3}\index{#2!#3, #1}\index{#3!#1 #2}}
189
190% And four (again, using only one level of subentries)
191\newcommand{\indexiv}[4]{
192\index{#1!#2 #3 #4}
193\index{#2!#3 #4, #1}
194\index{#3!#4, #1 #2}
195\index{#4!#1 #2 #3}
196}
197
198% \moduleauthor{name}{email}
199\newcommand{\moduleauthor}[2]{}
200
201% \sectionauthor{name}{email}
202\newcommand{\sectionauthor}[2]{}
203
204% Augment the sectioning commands used to get our own font family in place,
205% and reset some internal data items:
206\titleformat{\section}{\Large\py@HeaderFamily}%
207 {\py@TitleColor\thesection}{0.5em}{\py@TitleColor}{\py@NormalColor}
208\titleformat{\subsection}{\large\py@HeaderFamily}%
209 {\py@TitleColor\thesubsection}{0.5em}{\py@TitleColor}{\py@NormalColor}
210\titleformat{\subsubsection}{\py@HeaderFamily}%
211 {\py@TitleColor\thesubsubsection}{0.5em}{\py@TitleColor}{\py@NormalColor}
212\titleformat{\paragraph}{\large\py@HeaderFamily}%
213 {\py@TitleColor}{0em}{\py@TitleColor}{\py@NormalColor}
214
215% {fulllineitems} is the main environment for object descriptions.
216%
217\newcommand{\py@itemnewline}[1]{%
218 \@tempdima\linewidth%
219 \advance\@tempdima \leftmargin\makebox[\@tempdima][l]{#1}%
220}
221
222\newenvironment{fulllineitems}{
223 \begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
224 \rightmargin 0pt \topsep -\parskip \partopsep \parskip
225 \itemsep -\parsep
226 \let\makelabel=\py@itemnewline}
227}{\end{list}}
228
229% \optional is used for ``[, arg]``, i.e. desc_optional nodes.
230\newcommand{\optional}[1]{%
231 {\textnormal{\Large[}}{#1}\hspace{0.5mm}{\textnormal{\Large]}}}
232
233\newlength{\py@argswidth}
234\newcommand{\py@sigparams}[2]{%
235 \parbox[t]{\py@argswidth}{#1\code{)}#2}}
236\newcommand{\pysigline}[1]{\item[#1]\nopagebreak}
237\newcommand{\pysiglinewithargsret}[3]{%
238 \settowidth{\py@argswidth}{#1\code{(}}%
239 \addtolength{\py@argswidth}{-2\py@argswidth}%
240 \addtolength{\py@argswidth}{\linewidth}%
241 \item[#1\code{(}\py@sigparams{#2}{#3}]}
242
243% This version is being checked in for the historical record; it shows
244% how I've managed to get some aspects of this to work. It will not
245% be used in practice, so a subsequent revision will change things
246% again. This version has problems, but shows how to do something
247% that proved more tedious than I'd expected, so I don't want to lose
248% the example completely.
249%
250\newcommand{\grammartoken}[1]{\texttt{#1}}
251\newenvironment{productionlist}[1][\@undefined]{
252 \def\optional##1{{\Large[}##1{\Large]}}
253 \def\production##1##2{\hypertarget{grammar-token-##1}{}%
254 \code{##1}&::=&\code{##2}\\}
255 \def\productioncont##1{& &\code{##1}\\}
256 \def\token##1{##1}
257 \let\grammartoken=\token
258 \parindent=2em
259 \indent
260 \begin{tabular}{lcl}
261}{%
262 \end{tabular}
263}
264
265% Notices / Admonitions
266%
267\newlength{\py@noticelength}
268
269\newcommand{\py@heavybox}{
270 \setlength{\fboxrule}{1pt}
271 \setlength{\fboxsep}{7pt}
272 \setlength{\py@noticelength}{\linewidth}
273 \addtolength{\py@noticelength}{-2\fboxsep}
274 \addtolength{\py@noticelength}{-2\fboxrule}
275 \setlength{\shadowsize}{3pt}
276 \Sbox
277 \minipage{\py@noticelength}
278}
279\newcommand{\py@endheavybox}{
280 \endminipage
281 \endSbox
282 \fbox{\TheSbox}
283}
284
285% Some are quite plain:
286\newcommand{\py@noticestart@note}{}
287\newcommand{\py@noticeend@note}{}
288\newcommand{\py@noticestart@hint}{}
289\newcommand{\py@noticeend@hint}{}
290\newcommand{\py@noticestart@important}{}
291\newcommand{\py@noticeend@important}{}
292\newcommand{\py@noticestart@tip}{}
293\newcommand{\py@noticeend@tip}{}
294
295% Others gets more visible distinction:
296\newcommand{\py@noticestart@warning}{\py@heavybox}
297\newcommand{\py@noticeend@warning}{\py@endheavybox}
298\newcommand{\py@noticestart@caution}{\py@heavybox}
299\newcommand{\py@noticeend@caution}{\py@endheavybox}
300\newcommand{\py@noticestart@attention}{\py@heavybox}
301\newcommand{\py@noticeend@attention}{\py@endheavybox}
302\newcommand{\py@noticestart@danger}{\py@heavybox}
303\newcommand{\py@noticeend@danger}{\py@endheavybox}
304\newcommand{\py@noticestart@error}{\py@heavybox}
305\newcommand{\py@noticeend@error}{\py@endheavybox}
306
307\newenvironment{notice}[2]{
308 \def\py@noticetype{#1}
309 \csname py@noticestart@#1\endcsname
310 \par\strong{#2}
311}{\csname py@noticeend@\py@noticetype\endcsname}
312
313% Allow the release number to be specified independently of the
314% \date{}. This allows the date to reflect the document's date and
315% release to specify the release that is documented.
316%
317\newcommand{\py@release}{}
318\newcommand{\version}{}
319\newcommand{\shortversion}{}
320\newcommand{\releaseinfo}{}
321\newcommand{\releasename}{Release}
322\newcommand{\release}[1]{%
323 \renewcommand{\py@release}{\releasename\space\version}%
324 \renewcommand{\version}{#1}}
325\newcommand{\setshortversion}[1]{%
326 \renewcommand{\shortversion}{#1}}
327\newcommand{\setreleaseinfo}[1]{%
328 \renewcommand{\releaseinfo}{#1}}
329
330% Allow specification of the author's address separately from the
331% author's name. This can be used to format them differently, which
332% is a good thing.
333%
334\newcommand{\py@authoraddress}{}
335\newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress}{#1}}
336
337% This sets up the fancy chapter headings that make the documents look
338% at least a little better than the usual LaTeX output.
339%
340\@ifundefined{ChTitleVar}{}{
341 \ChNameVar{\raggedleft\normalsize\py@HeaderFamily}
342 \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily}
343 \ChTitleVar{\raggedleft \rm\Huge\py@HeaderFamily}
344 % This creates chapter heads without the leading \vspace*{}:
345 \def\@makechapterhead#1{%
346 {\parindent \z@ \raggedright \normalfont
347 \ifnum \c@secnumdepth >\m@ne
348 \DOCH
349 \fi
350 \interlinepenalty\@M
351 \DOTI{#1}
352 }
353 }
354}
355
356% Redefine description environment so that it is usable inside fulllineitems.
357%
358\renewcommand{\description}{%
359 \list{}{\labelwidth\z@%
360 \itemindent-\leftmargin%
361 \labelsep5pt%
362 \let\makelabel=\descriptionlabel}}
363
364% Definition lists; requested by AMK for HOWTO documents. Probably useful
365% elsewhere as well, so keep in in the general style support.
366%
367\newenvironment{definitions}{%
368 \begin{description}%
369 \def\term##1{\item[##1]\mbox{}\\*[0mm]}
370}{%
371 \end{description}%
372}
373
374% Tell TeX about pathological hyphenation cases:
375\hyphenation{Base-HTTP-Re-quest-Hand-ler}
376
377
378% The following is stuff copied from docutils' latex writer.
379%
380\newcommand{\optionlistlabel}[1]{\bf #1 \hfill}
381\newenvironment{optionlist}[1]
382{\begin{list}{}
383 {\setlength{\labelwidth}{#1}
384 \setlength{\rightmargin}{1cm}
385 \setlength{\leftmargin}{\rightmargin}
386 \addtolength{\leftmargin}{\labelwidth}
387 \addtolength{\leftmargin}{\labelsep}
388 \renewcommand{\makelabel}{\optionlistlabel}}
389}{\end{list}}
390
391\newlength{\lineblockindentation}
392\setlength{\lineblockindentation}{2.5em}
393\newenvironment{lineblock}[1]
394{\begin{list}{}
395 {\setlength{\partopsep}{\parskip}
396 \addtolength{\partopsep}{\baselineskip}
397 \topsep0pt\itemsep0.15\baselineskip\parsep0pt
398 \leftmargin#1}
399 \raggedright}
400{\end{list}}
401
402% Redefine includgraphics for avoiding images larger than the screen size
403% If the size is not specified.
404\let\py@Oldincludegraphics\includegraphics
405
406\newbox\image@box%
407\newdimen\image@width%
408\renewcommand\includegraphics[2][\@empty]{%
409 \ifx#1\@empty%
410 \setbox\image@box=\hbox{\py@Oldincludegraphics{#2}}%
411 \image@width\wd\image@box%
412 \ifdim \image@width>\linewidth%
413 \setbox\image@box=\hbox{\py@Oldincludegraphics[width=\linewidth]{#2}}%
414 \box\image@box%
415 \else%
416 \py@Oldincludegraphics{#2}%
417 \fi%
418 \else%
419 \py@Oldincludegraphics[#1]{#2}%
420 \fi%
421}
422
423
424% Fix the index and bibliography environments to add an entry to the Table of
425% Contents; this is much nicer than just having to jump to the end of the book
426% and flip around, especially with multiple indexes.
427%
428\let\py@OldTheindex=\theindex
429\renewcommand{\theindex}{
430 \cleardoublepage
431 \phantomsection
432 \py@OldTheindex
433 \addcontentsline{toc}{chapter}{\indexname}
434}
435
436\let\py@OldThebibliography=\thebibliography
437\renewcommand{\thebibliography}[1]{
438 \cleardoublepage
439 \phantomsection
440 \py@OldThebibliography{1}
441 \addcontentsline{toc}{chapter}{\bibname}
442}
443
444% Include hyperref last.
445\RequirePackage[colorlinks,breaklinks,
446 linkcolor=InnerLinkColor,filecolor=OuterLinkColor,
447 menucolor=OuterLinkColor,urlcolor=OuterLinkColor,
448 citecolor=InnerLinkColor]{hyperref}
449% Fix anchor placement for figures with captions.
450% (Note: we don't use a package option here; instead, we give an explicit
451% \capstart for figures that actually have a caption.)
452\RequirePackage{hypcap}
453
454% From docutils.writers.latex2e
455\providecommand{\DUspan}[2]{%
456 {% group ("span") to limit the scope of styling commands
457 \@for\node@class@name:=#1\do{%
458 \ifcsname docutilsrole\node@class@name\endcsname%
459 \csname docutilsrole\node@class@name\endcsname%
460 \fi%
461 }%
462 {#2}% node content
463 }% close "span"
464}
Note: See TracBrowser for help on using the repository browser.