4 % Adapted from the old python.sty, mostly written by Fred Drake,
8 \NeedsTeXFormat{LaTeX2e
}[1995/
12/
01]
9 \ProvidesPackage{sphinx
}[2010/
01/
15 LaTeX package (Sphinx markup)
]
11 \@ifclassloaded
{memoir
}{}{\RequirePackage{fancyhdr
}}
13 \RequirePackage{textcomp
}
14 \RequirePackage{fancybox
}
15 \RequirePackage{titlesec
}
16 \RequirePackage{tabulary
}
17 \RequirePackage{amsmath
} % for \text
18 \RequirePackage{makeidx
}
19 \RequirePackage{framed
}
20 \RequirePackage{ifthen
}
21 \RequirePackage{color}
22 % For highlighted code.
23 \RequirePackage{fancyvrb
}
25 \RequirePackage{threeparttable
}
26 % Handle footnotes in tables.
27 \RequirePackage{footnote
}
28 \makesavenoteenv{tabulary
}
29 % For floating figures in the text.
30 \RequirePackage{wrapfig
}
31 % Separate paragraphs by space by default.
32 \RequirePackage{parskip
}
33 \RequirePackage{lastpage
}
34 % Redefine these colors to your liking in the preamble.
35 \definecolor{TitleColor
}{rgb
}{0.126,
0.263,
0.361}
36 \definecolor{InnerLinkColor
}{rgb
}{0.208,
0.374,
0.486}
37 \definecolor{OuterLinkColor
}{rgb
}{0.216,
0.439,
0.388}
39 % Required to preserve indentation settings in minipage constructs
40 % (otherwise parskip is set to 0 by default. minipagerestore is called
41 % each time we enter a minipage environment)
42 \newcommand{\@minipagerestore
}{\setlength{\parskip}{\medskipamount}}
44 % Redefine these colors to something not white if you want to have colored
45 % background and border for code examples.
46 \definecolor{VerbatimColor
}{rgb
}{1,
1,
1}
47 \definecolor{VerbatimBorderColor
}{rgb
}{1,
1,
1}
49 % Uncomment these two lines to ignore the paper size and make the page
50 % size more like a typical published manual.
51 %\renewcommand{\paperheight}{9in}
52 %\renewcommand{\paperwidth}{8.5in} % typical squarish manual
53 %\renewcommand{\paperwidth}{7in} % O'Reilly ``Programmming Python''
55 % use pdfoutput for pTeX and dvipdfmx
56 \ifx\kanjiskip\undefined\else
57 \ifx\Gin@driver
{dvipdfmx.def
}\undefined\else
58 \newcount\pdfoutput\pdfoutput=
0
62 % For graphicx, check if we are compiling under latex or pdflatex.
63 \ifx\pdftexversion\undefined
66 \usepackage[pdftex
]{graphicx}
69 % for PDF output, use colors and maximal compression
70 \newif\ifsphinxpdfoutput\sphinxpdfoutputfalse
71 \ifx\pdfoutput\undefined\else\ifcase\pdfoutput
72 \let\py@NormalColor
\relax
73 \let\py@TitleColor
\relax
77 \def\py@NormalColor
{\color[rgb
]{0.0,
0.0,
0.0}}
78 \def\py@TitleColor
{\color{TitleColor
}}
82 % XeLaTeX can do colors, too
83 \ifx\XeTeXrevision\undefined\else
84 \def\py@NormalColor
{\color[rgb
]{0.0,
0.0,
0.0}}
85 \def\py@TitleColor
{\color{TitleColor
}}
88 % Increase printable page size (copied from fullpage.sty)
90 \advance \topmargin by -
\headheight
91 \advance \topmargin by -
\headsep
93 % attempt to work a little better for A4 users
94 \textheight \paperheight
95 \advance\textheight by -
2in
99 %\evensidemargin -.25in % for ``manual size'' documents
100 \marginparwidth 0.5in
102 \textwidth \paperwidth
103 \advance\textwidth by -
2in
106 % Style parameters and macros used by most documents here
109 \hbadness =
5000 % don't print trivial gripes
111 \pagestyle{empty
} % start this way
113 \renewcommand{\maketitle}{%
115 \let\footnotesize\small
116 \let\footnoterule\relax
117 \rule{\textwidth}{1pt
}%
120 % These \defs are required to deal with multi-line authors; it
121 % changes \\ to ', ' (comma-space), making it pass muster for
122 % generating document info in the PDF file.
133 {\rm\Huge \@title
\par}%
134 {\em\LARGE\py@HeaderFamily
\py@release
\releaseinfo \par}
136 {\LARGE\py@HeaderFamily
142 \py@authoraddress
\par
144 \end{flushright
}%\par
148 \setcounter{footnote
}{0}%
149 \let\thanks\relax\let\maketitle\relax
153 % Use this to set the font family for headers and other decor:
154 \newcommand{\py@HeaderFamily
}{\sffamily\bfseries}
156 % Redefine the 'normal' header/footer style when using "fancyhdr" package:
157 \@ifundefined
{fancyhf
}{}{
158 % Use \pagestyle{normal} as the primary pagestyle for text.
159 \fancypagestyle{normal
}{
161 \fancyfoot[LE,RO
]{{\py@HeaderFamily
\thepage\ of
\pageref*
{LastPage
}}}
162 \fancyfoot[LO
]{{\py@HeaderFamily
\nouppercase{\rightmark}}}
163 \fancyfoot[RE
]{{\py@HeaderFamily
\nouppercase{\leftmark}}}
164 \fancyhead[LE,RO
]{{\py@HeaderFamily \@title,
\py@release
}}
165 \renewcommand{\headrulewidth}{0.4pt
}
166 \renewcommand{\footrulewidth}{0.4pt
}
167 % define chaptermark with \@chappos when \@chappos is available for Japanese
168 \ifx\@chappos
\undefined\else
169 \def\chaptermark#
#1{\markboth{\@chapapp
\space\thechapter\space\@chappos
\space #
#1}{}}
172 % Update the plain style so we get the page number & footer line,
173 % but not a chapter or section title. This is to keep the first
174 % page of a chapter and the blank page between chapters `clean.'
175 \fancypagestyle{plain
}{
177 \fancyfoot[LE,RO
]{{\py@HeaderFamily
\thepage\ of
\pageref*
{LastPage
}}}
178 \fancyfoot[LO,RE
]{{\py@HeaderFamily
\GNATFullDocumentName}}
179 \fancyhead[LE,RO
]{{\py@HeaderFamily \@title\
\GNATVersion}}
180 \renewcommand{\headrulewidth}{0.0pt
}
181 \renewcommand{\footrulewidth}{0.4pt
}
185 % Some custom font markup commands.
187 \newcommand{\strong}[1]{{\textbf{#1}}}
188 \newcommand{\code}[1]{\texttt{#1}}
189 \newcommand{\bfcode}[1]{\code{\bfseries#1}}
190 \newcommand{\email}[1]{\textsf{#1}}
192 % Redefine the Verbatim environment to allow border and background colors.
193 % The original environment is still used for verbatims within tables.
194 \let\OriginalVerbatim=
\Verbatim
195 \let\endOriginalVerbatim=
\endVerbatim
197 % Play with vspace to be able to keep the indentation.
198 \newlength\distancetoright
200 \setlength\distancetoright{\linewidth}%
201 \advance\distancetoright -\@totalleftmargin
%
202 \fcolorbox{VerbatimBorderColor
}{VerbatimColor
}{%
203 \begin{minipage
}{\distancetoright}%
208 \def\FrameCommand{\mycolorbox}
210 \renewcommand{\Verbatim}[1][1]{%
211 % list starts new par, but we don't want it to be set apart vertically
214 % The list environement is needed to control perfectly the vertical
217 \setlength\parskip{0pt
}%
218 \setlength\itemsep{0ex
}%
219 \setlength\topsep{0ex
}%
220 \setlength\partopsep{0pt
}%
221 \setlength\leftmargin{0pt
}%
223 \item\MakeFramed {\FrameRestore}%
225 \OriginalVerbatim[#1]%
227 \renewcommand{\endVerbatim}{%
228 \endOriginalVerbatim%
231 % close group to restore \parskip
236 % \moduleauthor{name}{email}
237 \newcommand{\moduleauthor}[2]{}
239 % \sectionauthor{name}{email}
240 \newcommand{\sectionauthor}[2]{}
242 % Augment the sectioning commands used to get our own font family in place,
243 % and reset some internal data items:
244 \titleformat{\section}{\Large\py@HeaderFamily
}%
245 {\py@TitleColor
\thesection}{0.5em
}{\py@TitleColor
}{\py@NormalColor
}
246 \titleformat{\subsection}{\large\py@HeaderFamily
}%
247 {\py@TitleColor
\thesubsection}{0.5em
}{\py@TitleColor
}{\py@NormalColor
}
248 \titleformat{\subsubsection}{\py@HeaderFamily
}%
249 {\py@TitleColor
\thesubsubsection}{0.5em
}{\py@TitleColor
}{\py@NormalColor
}
250 \titleformat{\paragraph}{\small\py@HeaderFamily
}%
251 {\py@TitleColor
}{0em
}{\py@TitleColor
}{\py@NormalColor
}
253 % {fulllineitems} is the main environment for object descriptions.
255 \newcommand{\py@itemnewline
}[1]{%
256 \@tempdima
\linewidth%
257 \advance\@tempdima
\leftmargin\makebox[\@tempdima
][l
]{#1}%
260 \newenvironment{fulllineitems
}{
261 \begin{list
}{}{\labelwidth \leftmargin \labelsep 0pt
262 \rightmargin 0pt
\topsep -
\parskip \partopsep \parskip
264 \let\makelabel=
\py@itemnewline
}
267 % \optional is used for ``[, arg]``, i.e. desc_optional nodes.
268 \newcommand{\optional}[1]{%
269 {\textnormal{\Large[}}{#1}\hspace{0.5mm
}{\textnormal{\Large]}}}
271 \newlength{\py@argswidth
}
272 \newcommand{\py@sigparams
}[2]{%
273 \parbox[t
]{\py@argswidth
}{#1\code{)
}#2}}
274 \newcommand{\pysigline}[1]{\item[#1]\nopagebreak}
275 \newcommand{\pysiglinewithargsret}[3]{%
276 \settowidth{\py@argswidth
}{#1\code{(
}}%
277 \addtolength{\py@argswidth
}{-
2\py@argswidth
}%
278 \addtolength{\py@argswidth
}{\linewidth}%
279 \item[#1\code{(
}\py@sigparams
{#2}{#3}]}
283 \newenvironment{productionlist
}{
284 % \def\optional##1{{\Large[}##1{\Large]}}
285 \def\production#
#1#
#2{\\
\code{#
#1}&::=&
\code{#
#2}}
286 \def\productioncont#
#1{\\& &
\code{#
#1}}
294 % Notices / Admonitions
296 \newlength{\py@noticelength
}
298 \newcommand{\py@heavybox
}{
299 \setlength{\fboxrule}{1pt
}
300 \setlength{\fboxsep}{6pt
}
301 \setlength{\py@noticelength
}{\linewidth}
302 \addtolength{\py@noticelength
}{-
2\fboxsep}
303 \addtolength{\py@noticelength
}{-
2\fboxrule}
304 %\setlength{\shadowsize}{3pt}
306 \minipage{\py@noticelength
}
308 \newcommand{\py@endheavybox
}{
314 \newcommand{\py@lightbox
}{{%
315 \setlength\parskip{0pt
}\par
316 \noindent\rule[0ex
]{\linewidth}{0.5pt
}%
317 \par\noindent\vspace{-
0.5ex
}%
319 \newcommand{\py@endlightbox
}{{%
320 \setlength{\parskip}{0pt
}%
321 \par\noindent\rule[0.5ex
]{\linewidth}{0.5pt
}%
327 % Some are quite plain:
328 \newcommand{\py@noticestart@note
}{\py@lightbox
}
329 \newcommand{\py@noticeend@note
}{\py@endlightbox
}
330 \newcommand{\py@noticestart@hint
}{\py@lightbox
}
331 \newcommand{\py@noticeend@hint
}{\py@endlightbox
}
332 \newcommand{\py@noticestart@important
}{\py@lightbox
}
333 \newcommand{\py@noticeend@important
}{\py@endlightbox
}
334 \newcommand{\py@noticestart@tip
}{\py@lightbox
}
335 \newcommand{\py@noticeend@tip
}{\py@endlightbox
}
337 % Others gets more visible distinction:
338 \newcommand{\py@noticestart@warning
}{\py@heavybox
}
339 \newcommand{\py@noticeend@warning
}{\py@endheavybox
}
340 \newcommand{\py@noticestart@caution
}{\py@heavybox
}
341 \newcommand{\py@noticeend@caution
}{\py@endheavybox
}
342 \newcommand{\py@noticestart@attention
}{\py@heavybox
}
343 \newcommand{\py@noticeend@attention
}{\py@endheavybox
}
344 \newcommand{\py@noticestart@danger
}{\py@heavybox
}
345 \newcommand{\py@noticeend@danger
}{\py@endheavybox
}
346 \newcommand{\py@noticestart@error
}{\py@heavybox
}
347 \newcommand{\py@noticeend@error
}{\py@endheavybox
}
349 \newenvironment{notice
}[2]{
350 \def\py@noticetype
{#1}
351 \csname py@noticestart@
#1\endcsname
353 }{\csname py@noticeend@
\py@noticetype
\endcsname}
355 % Allow the release number to be specified independently of the
356 % \date{}. This allows the date to reflect the document's date and
357 % release to specify the release that is documented.
359 \newcommand{\py@release
}{}
360 \newcommand{\version}{}
361 \newcommand{\shortversion}{}
362 \newcommand{\releaseinfo}{}
363 \newcommand{\releasename}{GNAT
}
364 \newcommand{\release}[1]{%
365 \renewcommand{\py@release
}{\releasename\space\version}%
366 \renewcommand{\version}{#1}}
367 \newcommand{\setshortversion}[1]{%
368 \renewcommand{\shortversion}{#1}}
369 \newcommand{\setreleaseinfo}[1]{%
370 \renewcommand{\releaseinfo}{#1}}
372 % Allow specification of the author's address separately from the
373 % author's name. This can be used to format them differently, which
376 \newcommand{\py@authoraddress
}{}
377 \newcommand{\authoraddress}[1]{\renewcommand{\py@authoraddress
}{#1}}
379 % This sets up the fancy chapter headings that make the documents look
380 % at least a little better than the usual LaTeX output.
382 \@ifundefined
{ChTitleVar
}{}{
383 \ChNameVar{\raggedleft\normalsize\py@HeaderFamily
}
384 \ChNumVar{\raggedleft \bfseries\Large\py@HeaderFamily
}
385 \ChTitleVar{\raggedleft \textrm{\Huge\py@HeaderFamily
}}
386 % This creates chapter heads without the leading \vspace*{}:
387 \def\@makechapterhead
#1{%
388 {\parindent \z@
\raggedright \normalfont
389 \ifnum \c@secnumdepth >
\m@ne
398 % Redefine description environment so that it is usable inside fulllineitems.
400 \renewcommand{\description}{%
401 \list{}{\labelwidth\z@
%
402 \itemindent-
\leftmargin%
404 \let\makelabel=
\descriptionlabel}}
406 % Definition lists; requested by AMK for HOWTO documents. Probably useful
407 % elsewhere as well, so keep in in the general style support.
409 \newenvironment{definitions
}{%
411 \def\term#
#1{\item[#
#1]\mbox{}\\*
[0mm
]}
416 % Tell TeX about pathological hyphenation cases:
417 \hyphenation{Base-HTTP-Re-quest-Hand-ler
}
420 % The following is stuff copied from docutils' latex writer.
422 \newcommand{\optionlistlabel}[1]{\bf #1 \hfill}
423 \newenvironment{optionlist
}[1]
425 {\setlength{\labelwidth}{#1}
426 \setlength{\rightmargin}{1cm
}
427 \setlength{\leftmargin}{\rightmargin}
428 \addtolength{\leftmargin}{\labelwidth}
429 \addtolength{\leftmargin}{\labelsep}
430 \renewcommand{\makelabel}{\optionlistlabel}}
433 \newlength{\lineblockindentation}
434 \setlength{\lineblockindentation}{2.5em
}
435 \newenvironment{lineblock
}[1]
437 {\setlength{\partopsep}{\parskip}
438 \addtolength{\partopsep}{\baselineskip}
439 \topsep0pt\itemsep0.15
\baselineskip\parsep0pt
444 % Redefine includgraphics for avoiding images larger than the screen size
445 % If the size is not specified.
446 \let\py@Oldincludegraphics
\includegraphics
449 \newdimen\image@width
%
450 \renewcommand\includegraphics[2][\@empty
]{%
452 \setbox\image@box=
\hbox{\py@Oldincludegraphics
{#2}}%
453 \image@width
\wd\image@box
%
454 \ifdim \image@width>
\linewidth%
455 \setbox\image@box=
\hbox{\py@Oldincludegraphics
[width=
\linewidth]{#2}}%
458 \py@Oldincludegraphics
{#2}%
461 \py@Oldincludegraphics
[#1]{#2}%
465 % to make pdf with correct encoded bookmarks in Japanese
466 % this should precede the hyperref package
467 \ifx\kanjiskip\undefined\else
468 \usepackage{atbegshi
}
470 \ifnum 42146=
\euc"A4A2
471 \AtBeginShipoutFirst{\special{pdf:tounicode EUC-UCS2
}}
473 \AtBeginShipoutFirst{\special{pdf:tounicode
90ms-RKSJ-UCS2
}}
476 \AtBeginShipoutFirst{\special{pdf:tounicode UTF8-UCS2
}}
480 % Include hyperref last.
481 \RequirePackage[colorlinks,breaklinks,destlabel,
482 linkcolor=InnerLinkColor,filecolor=OuterLinkColor,
483 menucolor=OuterLinkColor,urlcolor=OuterLinkColor,
484 citecolor=InnerLinkColor
]{hyperref
}
485 % Fix anchor placement for figures with captions.
486 % (Note: we don't use a package option here; instead, we give an explicit
487 % \capstart for figures that actually have a caption.)
488 \RequirePackage{hypcap
}
490 % From docutils.writers.latex2e
491 \providecommand{\DUspan}[2]{%
492 {% group ("span") to limit the scope of styling commands
493 \@for
\node@class@name:=
#1\do{%
494 \ifcsname docutilsrole
\node@class@name
\endcsname%
495 \csname docutilsrole
\node@class@name
\endcsname%
502 \providecommand*
{\DUprovidelength}[2]{
503 \ifthenelse{\isundefined{#1}}{\newlength{#1}\setlength{#1}{#2}}{}
506 \DUprovidelength{\DUlineblockindent}{2.5em
}
507 \ifthenelse{\isundefined{\DUlineblock}}{
508 \newenvironment{DUlineblock
}[1]{%
509 \list{}{\setlength{\partopsep}{\parskip}
510 \addtolength{\partopsep}{\baselineskip}
511 \setlength{\topsep}{0pt
}
512 \setlength{\itemsep}{0.15\baselineskip}
513 \setlength{\parsep}{0pt
}
514 \setlength{\leftmargin}{#1}}
521 % From footmisc.sty: allows footnotes in titles
522 \let\FN@sf@@footnote
\footnote
523 \def\footnote{\ifx\protect\@typeset@protect
524 \expandafter\FN@sf@@footnote
526 \expandafter\FN@sf@gobble@opt
529 \edef\FN@sf@gobble@opt
{\noexpand\protect
530 \expandafter\noexpand\csname FN@sf@gobble@opt
\endcsname}
531 \expandafter\def\csname FN@sf@gobble@opt
\endcsname{%
533 \FN@sf@gobble@twobracket
536 \def\FN@sf@gobble@twobracket
[#1]#2{}
538 % adjust the margins for footer,
539 % this works with the jsclasses only (Japanese standard document classes)
540 \ifx\@jsc@uplatextrue
\undefined\else
541 \hypersetup{setpagesize=false
}
542 \setlength\footskip{2\baselineskip}
543 \addtolength{\textheight}{-
2\baselineskip}
546 % fix the double index and bibliography on the table of contents
547 % in jsclasses (Japanese standard document classes)
548 \ifx\@jsc@uplatextrue
\undefined\else
549 \renewcommand{\theindex}{
554 \renewcommand{\thebibliography}[1]{
557 \py@OldThebibliography
{1}
561 % do not use \@chappos in Appendix in pTeX
562 \ifx\kanjiskip\undefined\else
563 \renewcommand{\appendix}{\par
564 \setcounter{chapter
}{0}
565 \setcounter{section
}{0}
566 \gdef\@chapapp
{\appendixname}
568 \gdef\thechapter{\@Alph
\c@chapter
}