##// END OF EJS Templates
Got both of the main template formats from sphinx rendering....
Jonathan Frederic -
Show More
@@ -1,33 +1,22 b''
1 ================================================================
1 ================================================================
2 nbconvert: conversion utilities for the IPython notebook format
2 nbconvert Sphinx-Latex Jinja2 templates
3 ================================================================
3 ================================================================
4
4
5 Overview
5 Overview
6 ========
6 ========
7
7
8 nbconvert provides command line utilities to convert to and from IPython
8 nbconvert provides command line utilities to convert to and from IPython
9 notebooks and standard formats:
9 notebooks and standard formats. However, the latex formatting leaves
10
10 something to be desired. This repository contains a port of the beautiful
11 - ReST
11 and popular Sphinx latex styles for nbconvert.
12 - Markdown
13 - HTML
14 - PDF
15 - Python script
16
17 As these tools mature, these utilities will be merged into IPython.
18
12
19 Requirements
13 Requirements
20 ============
14 ============
21
15
22 Sphinx-Latex:
16 Sphinx-Latex:
23
17
24 $ sudo apt-get install texlive-full
18 $ sudo apt-get install texlive-full
25
19
26 see http://jimmyg.org/blog/2009/sphinx-pdf-generation-with-latex.html
20 see http://jimmyg.org/blog/2009/sphinx-pdf-generation-with-latex.html
27
21
28 Running Tests
29 =============
30
31 Using nbconvert
32 ===============
33
22
@@ -1,214 +1,224 b''
1 ((*- extends 'display_priority.tplx' -*))
1 ((*- extends 'display_priority.tplx' -*))
2
2
3 ((* block in_prompt *))((* endblock in_prompt *))
3 ((* block in_prompt *))((* endblock in_prompt *))
4
4
5 ((* block output_prompt *))((* endblock output_prompt *))
5 ((* block output_prompt *))((* endblock output_prompt *))
6
6
7 ((* block codecell *))\begin{codecell}((( super() )))
7 ((* block codecell *))\begin{codecell}((( super() )))
8 \end{codecell}
8 \end{codecell}
9 ((* endblock *))
9 ((* endblock *))
10
10
11 ((* block input *))
11 ((* block input *))
12 \begin{codeinput}
12 \begin{codeinput}
13 \begin{lstlisting}
13 \begin{lstlisting}
14 ((( cell.input )))
14 ((( cell.input )))
15 \end{lstlisting}
15 \end{lstlisting}
16 \end{codeinput}
16 \end{codeinput}
17 ((* endblock input *))
17 ((* endblock input *))
18
18
19
19
20 ((= Those Two are for error displaying
20 ((= Those Two are for error displaying
21 even if the first one seem to do nothing,
21 even if the first one seem to do nothing,
22 it introduces a new line
22 it introduces a new line
23
23
24 =))
24 =))
25 ((* block pyerr *))((( super() )))
25 ((* block pyerr *))((( super() )))
26 ((* endblock pyerr *))
26 ((* endblock pyerr *))
27
27
28 ((* block traceback_line *))
28 ((* block traceback_line *))
29 ((( line |indent| rm_ansi )))((* endblock traceback_line *))
29 ((( line |indent| rm_ansi )))((* endblock traceback_line *))
30 ((= .... =))
30 ((= .... =))
31
31
32
32
33 ((*- block output_group -*))
33 ((*- block output_group -*))
34 \begin{codeoutput}
34 \begin{codeoutput}
35 ((( super() )))
35 ((( super() )))
36 \end{codeoutput}((* endblock *))
36 \end{codeoutput}((* endblock *))
37
37
38 ((*- block data_png -*))
38 ((*- block data_png -*))
39 \begin{center}
39 \begin{center}
40 \includegraphics[width=0.7\textwidth, height=0.9\textheight, keepaspectratio]{(((output.key_png)))}
40 \includegraphics[width=0.7\textwidth, height=0.9\textheight, keepaspectratio]{(((output.key_png)))}
41 \par
41 \par
42 \end{center}
42 \end{center}
43 ((*- endblock -*))
43 ((*- endblock -*))
44
44
45 ((*- block data_svg -*))
45 ((*- block data_svg -*))
46 \begin{center}
46 \begin{center}
47 \includegraphics[width=0.7\textwidth]{(((output.key_svg)))}
47 \includegraphics[width=0.7\textwidth]{(((output.key_svg)))}
48 \par
48 \par
49 \end{center}
49 \end{center}
50 ((*- endblock -*))
50 ((*- endblock -*))
51
51
52 ((* block pyout *))
52 ((* block pyout *))
53 ((( output.text)))
53 ((( output.text)))
54 ((* endblock pyout *))
54 ((* endblock pyout *))
55
55
56 ((* block data_text *))
56 ((* block data_text *))
57 \begin{verbatim}
57 \begin{verbatim}
58 ((( output.text )))
58 ((( output.text )))
59 \end{verbatim}
59 \end{verbatim}
60 ((* endblock *))
60 ((* endblock *))
61
61
62 ((* block stream *))
62 ((* block stream *))
63 \begin{verbatim}
63 \begin{verbatim}
64 ((( output.text)))
64 ((( output.text)))
65 \end{verbatim}
65 \end{verbatim}
66 ((* endblock stream *))
66 ((* endblock stream *))
67
67
68
68
69
69
70
70 ((=
71 %Doesn't work on my machine yet. TODO: Fix this.
71 ((* block markdowncell scoped *))((( cell.source | markdown2latex )))
72 ((* block markdowncell scoped *))((( cell.source | markdown2latex )))
72 ((* endblock markdowncell *))
73 ((* endblock markdowncell *))
74 =))
73
75
74 ((* block headingcell scoped *))
76 ((* block headingcell scoped *))
75 \section{((( cell.source)))}
77 \section{((( cell.source)))}
76 ((* endblock headingcell *))
78 ((* endblock headingcell *))
77
79
78 ((* block rawcell scoped *))
80 ((* block rawcell scoped *))
79 ((( cell.source | pycomment )))
81 ((( cell.source | pycomment )))
80 ((* endblock rawcell *))
82 ((* endblock rawcell *))
81
83
82 ((* block unknowncell scoped *))
84 ((* block unknowncell scoped *))
83 unknown type (((cell.type)))
85 unknown type (((cell.type)))
84 ((* endblock unknowncell *))
86 ((* endblock unknowncell *))
85
87
86
88
87
89
88 ((* block body *))\begin{document}
90 ((* block body *))
89 ((( super() )))
91
90 \end{document}
92 ((* block bodyBegin *))
91 ((* endblock*))
93 \begin{document}
94 ((* endblock bodyBegin *))
95
96 ((( super() )))
97
98 ((* block bodyEnd *))
99 \end{document}
100 ((* endblock bodyEnd *))
101 ((* endblock body *))
92
102
93 ((* block header *))
103 ((* block header *))
94 %% This file was auto-generated by IPython.
104 %% This file was auto-generated by IPython.
95 %% Conversion from the original notebook file:
105 %% Conversion from the original notebook file:
96 %% tests/ipynbref/Gun_Data.orig.ipynb
106 %% tests/ipynbref/Gun_Data.orig.ipynb
97 %%
107 %%
98 \documentclass[11pt,english]{article}
108 \documentclass[11pt,english]{article}
99
109
100 %% This is the automatic preamble used by IPython. Note that it does *not*
110 %% This is the automatic preamble used by IPython. Note that it does *not*
101 %% include a documentclass declaration, that is added at runtime to the overall
111 %% include a documentclass declaration, that is added at runtime to the overall
102 %% document.
112 %% document.
103
113
104 \usepackage{amsmath}
114 \usepackage{amsmath}
105 \usepackage{amssymb}
115 \usepackage{amssymb}
106 \usepackage{graphicx}
116 \usepackage{graphicx}
107 \usepackage{ucs}
117 \usepackage{ucs}
108 \usepackage[utf8x]{inputenc}
118 \usepackage[utf8x]{inputenc}
109
119
110 % needed for markdown enumerations to work
120 % needed for markdown enumerations to work
111 \usepackage{enumerate}
121 \usepackage{enumerate}
112
122
113 % Slightly bigger margins than the latex defaults
123 % Slightly bigger margins than the latex defaults
114 \usepackage{geometry}
124 \usepackage{geometry}
115 \geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=2.5cm,rmargin=2.5cm}
125 \geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=2.5cm,rmargin=2.5cm}
116
126
117 % Define a few colors for use in code, links and cell shading
127 % Define a few colors for use in code, links and cell shading
118 \usepackage{color}
128 \usepackage{color}
119 \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
129 \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
120 \definecolor{darkorange}{rgb}{.71,0.21,0.01}
130 \definecolor{darkorange}{rgb}{.71,0.21,0.01}
121 \definecolor{darkgreen}{rgb}{.12,.54,.11}
131 \definecolor{darkgreen}{rgb}{.12,.54,.11}
122 \definecolor{myteal}{rgb}{.26, .44, .56}
132 \definecolor{myteal}{rgb}{.26, .44, .56}
123 \definecolor{gray}{gray}{0.45}
133 \definecolor{gray}{gray}{0.45}
124 \definecolor{lightgray}{gray}{.95}
134 \definecolor{lightgray}{gray}{.95}
125 \definecolor{mediumgray}{gray}{.8}
135 \definecolor{mediumgray}{gray}{.8}
126 \definecolor{inputbackground}{rgb}{.95, .95, .85}
136 \definecolor{inputbackground}{rgb}{.95, .95, .85}
127 \definecolor{outputbackground}{rgb}{.95, .95, .95}
137 \definecolor{outputbackground}{rgb}{.95, .95, .95}
128 \definecolor{traceback}{rgb}{1, .95, .95}
138 \definecolor{traceback}{rgb}{1, .95, .95}
129
139
130 % Framed environments for code cells (inputs, outputs, errors, ...). The
140 % Framed environments for code cells (inputs, outputs, errors, ...). The
131 % various uses of \unskip (or not) at the end were fine-tuned by hand, so don't
141 % various uses of \unskip (or not) at the end were fine-tuned by hand, so don't
132 % randomly change them unless you're sure of the effect it will have.
142 % randomly change them unless you're sure of the effect it will have.
133 \usepackage{framed}
143 \usepackage{framed}
134
144
135 % remove extraneous vertical space in boxes
145 % remove extraneous vertical space in boxes
136 \setlength\fboxsep{0pt}
146 \setlength\fboxsep{0pt}
137
147
138 % codecell is the whole input+output set of blocks that a Code cell can
148 % codecell is the whole input+output set of blocks that a Code cell can
139 % generate.
149 % generate.
140
150
141 % TODO: unfortunately, it seems that using a framed codecell environment breaks
151 % TODO: unfortunately, it seems that using a framed codecell environment breaks
142 % the ability of the frames inside of it to be broken across pages. This
152 % the ability of the frames inside of it to be broken across pages. This
143 % causes at least the problem of having lots of empty space at the bottom of
153 % causes at least the problem of having lots of empty space at the bottom of
144 % pages as new frames are moved to the next page, and if a single frame is too
154 % pages as new frames are moved to the next page, and if a single frame is too
145 % long to fit on a page, will completely stop latex from compiling the
155 % long to fit on a page, will completely stop latex from compiling the
146 % document. So unless we figure out a solution to this, we'll have to instead
156 % document. So unless we figure out a solution to this, we'll have to instead
147 % leave the codecell env. as empty. I'm keeping the original codecell
157 % leave the codecell env. as empty. I'm keeping the original codecell
148 % definition here (a thin vertical bar) for reference, in case we find a
158 % definition here (a thin vertical bar) for reference, in case we find a
149 % solution to the page break issue.
159 % solution to the page break issue.
150
160
151 %% \newenvironment{codecell}{%
161 %% \newenvironment{codecell}{%
152 %% \def\FrameCommand{\color{mediumgray} \vrule width 1pt \hspace{5pt}}%
162 %% \def\FrameCommand{\color{mediumgray} \vrule width 1pt \hspace{5pt}}%
153 %% \MakeFramed{\vspace{-0.5em}}}
163 %% \MakeFramed{\vspace{-0.5em}}}
154 %% {\unskip\endMakeFramed}
164 %% {\unskip\endMakeFramed}
155
165
156 % For now, make this a no-op...
166 % For now, make this a no-op...
157 \newenvironment{codecell}{}
167 \newenvironment{codecell}{}
158
168
159 \newenvironment{codeinput}{%
169 \newenvironment{codeinput}{%
160 \def\FrameCommand{\colorbox{inputbackground}}%
170 \def\FrameCommand{\colorbox{inputbackground}}%
161 \MakeFramed{\advance\hsize-\width \FrameRestore}}
171 \MakeFramed{\advance\hsize-\width \FrameRestore}}
162 {\unskip\endMakeFramed}
172 {\unskip\endMakeFramed}
163
173
164 \newenvironment{codeoutput}{%
174 \newenvironment{codeoutput}{%
165 \def\FrameCommand{\colorbox{outputbackground}}%
175 \def\FrameCommand{\colorbox{outputbackground}}%
166 \vspace{-1.4em}
176 \vspace{-1.4em}
167 \MakeFramed{\advance\hsize-\width \FrameRestore}}
177 \MakeFramed{\advance\hsize-\width \FrameRestore}}
168 {\unskip\medskip\endMakeFramed}
178 {\unskip\medskip\endMakeFramed}
169
179
170 \newenvironment{traceback}{%
180 \newenvironment{traceback}{%
171 \def\FrameCommand{\colorbox{traceback}}%
181 \def\FrameCommand{\colorbox{traceback}}%
172 \MakeFramed{\advance\hsize-\width \FrameRestore}}
182 \MakeFramed{\advance\hsize-\width \FrameRestore}}
173 {\endMakeFramed}
183 {\endMakeFramed}
174
184
175 % Use and configure listings package for nicely formatted code
185 % Use and configure listings package for nicely formatted code
176 \usepackage{listingsutf8}
186 \usepackage{listingsutf8}
177 \lstset{
187 \lstset{
178 language=python,
188 language=python,
179 inputencoding=utf8x,
189 inputencoding=utf8x,
180 extendedchars=\true,
190 extendedchars=\true,
181 aboveskip=\smallskipamount,
191 aboveskip=\smallskipamount,
182 belowskip=\smallskipamount,
192 belowskip=\smallskipamount,
183 xleftmargin=2mm,
193 xleftmargin=2mm,
184 breaklines=true,
194 breaklines=true,
185 basicstyle=\small \ttfamily,
195 basicstyle=\small \ttfamily,
186 showstringspaces=false,
196 showstringspaces=false,
187 keywordstyle=\color{blue}\bfseries,
197 keywordstyle=\color{blue}\bfseries,
188 commentstyle=\color{myteal},
198 commentstyle=\color{myteal},
189 stringstyle=\color{darkgreen},
199 stringstyle=\color{darkgreen},
190 identifierstyle=\color{darkorange},
200 identifierstyle=\color{darkorange},
191 columns=fullflexible, % tighter character kerning, like verb
201 columns=fullflexible, % tighter character kerning, like verb
192 }
202 }
193
203
194 % The hyperref package gives us a pdf with properly built
204 % The hyperref package gives us a pdf with properly built
195 % internal navigation ('pdf bookmarks' for the table of contents,
205 % internal navigation ('pdf bookmarks' for the table of contents,
196 % internal cross-reference links, web links for URLs, etc.)
206 % internal cross-reference links, web links for URLs, etc.)
197 \usepackage{hyperref}
207 \usepackage{hyperref}
198 \hypersetup{
208 \hypersetup{
199 breaklinks=true, % so long urls are correctly broken across lines
209 breaklinks=true, % so long urls are correctly broken across lines
200 colorlinks=true,
210 colorlinks=true,
201 urlcolor=blue,
211 urlcolor=blue,
202 linkcolor=darkorange,
212 linkcolor=darkorange,
203 citecolor=darkgreen,
213 citecolor=darkgreen,
204 }
214 }
205
215
206 % hardcode size of all verbatim environments to be a bit smaller
216 % hardcode size of all verbatim environments to be a bit smaller
207 \makeatletter
217 \makeatletter
208 \g@addto@macro\@verbatim\small\topsep=0.5em\partopsep=0pt
218 \g@addto@macro\@verbatim\small\topsep=0.5em\partopsep=0pt
209 \makeatother
219 \makeatother
210
220
211 % Prevent overflowing lines due to urls and other hard-to-break entities.
221 % Prevent overflowing lines due to urls and other hard-to-break entities.
212 \sloppy
222 \sloppy
213
223
214 ((* endblock *))
224 ((* endblock *))
@@ -1,60 +1,128 b''
1 ((============================================================================
1 ((============================================================================
2 NBConvert Sphinx-Latex Template
2 NBConvert Sphinx-Latex Template
3
3
4 Purpose: Allow export of PDF friendly Latex inspired by Sphinx. Most of the
4 Purpose: Allow export of PDF friendly Latex inspired by Sphinx. Most of the
5 template is derived directly from Sphinx source.
5 template is derived directly from Sphinx source.
6
6
7 Inheritance: null>display_priority>latex_base
7 Inheritance: null>display_priority>latex_base
8
8
9 ==========================================================================))
9 ==========================================================================))
10
10
11 ((*- extends 'latex_base.tplx' -*))
11 ((*- extends 'latex_base.tplx' -*))
12
12
13 ((============================================================================
13 % Header, overrides base
14 Header, overrides base
15 ==========================================================================))
16 ((* block header *))
14 ((* block header *))
15
16 % Make sure that the sphinx doc style knows who it inherits from.
17 \def\sphinxdocclass{(((parentdocumentclass)))}
18
19 % Declare the document class
20 \documentclass[letterpaper,10pt,english]{templates/tex/sphinx(((documentclass)))}
21
22 % Imports
23 \usepackage[utf8]{inputenc}
24 \DeclareUnicodeCharacter{00A0}{\\nobreakspace}
25 \usepackage[T1]{fontenc}
26 \usepackage{babel}
27 \usepackage{times}
28 \usepackage{import}
29 \usepackage[Bjarne]{templates/tex/fncychap}
30 \usepackage{longtable}
31 \usepackage{templates/tex/sphinx}
32 \usepackage{multirow}
33
34 % Document level variables
35 \title{((( nb.metadata.name )))}
36 \date{\today}
37 \release{}
38 \author{Unknown Author}
39 \newcommand{\sphinxlogo}{}
40 \renewcommand{\releasename}{Release}
41 \makeindex
42
43
44 ((* block sphinxheader *))((* endblock sphinxheader *))
17
45
18 %\newcommand{\sphinxlogo}{}
19
20 %% Generated by Sphinx (not really.)
21 \def\sphinxdocclass{((* block documentclass *))sphinxmanual((* endblock documentclass *))}
22 \documentclass[letterpaper,10pt,english]{report}
23 \usepackage[utf8]{inputenc} %(inputenc)s
24 \DeclareUnicodeCharacter{00A0}{\\nobreakspace} %(utf8extra)s
25 \usepackage[T1]{fontenc} %(fontenc)s
26 \usepackage{babel} %(babel)s
27 \usepackage{times} %(fontpkg)s
28 \usepackage{import}
29 \usepackage[Bjarne]{templates/tex/fncychap}
30 %\usepackage[Bjarne]{} %(fncychap)s
31 \usepackage{longtable} %(longtable)s
32 \usepackage{templates/tex/sphinx}
33 \usepackage{multirow}
34
35 %"" (preamble)s
36
37 \title{((( nb.metadata.name )))} %(title)s}
38 \date{} %(date)s}
39 \release{} %(release)s}
40 \author{} %(author)s}
41 \newcommand{\sphinxlogo}{} %(logo)s}
42 \renewcommand{\releasename}{Release} %(releasename)s}
43 \makeindex %(makeindex)s
44
45 ((* block sphinxstyle *))((* endblock sphinxstyle *))
46 ((* endblock header *))
46 ((* endblock header *))
47
47
48 ((* block body *))
48 % Body
49 \begin{document}
49 ((* block bodyBegin *))
50 %(shorthandoff)s
51 \maketitle
52 \tableofcontents %(tableofcontents)s
53
50
54 \renewcommand{\indexname}{%(indexname)s}
51 % Start of the document
55 \printindex %(printindex)s
52 \begin{document}
56 \end{document}
53 \maketitle
57 ((* endblock body *))
54 \tableofcontents
55 ((* endblock bodyBegin *))
56 ((* block bodyEnd *))
58
57
58
59 \renewcommand{\indexname}{Index}
60 \printindex
61 \end{document}
62 ((* endblock bodyEnd *))
63
64 % Footer
59 ((* block footer *))
65 ((* block footer *))
60 ((* endblock footer *))
66 ((* endblock footer *))
67
68 ((*- block any_cell scoped -*))
69 ((( cell.source)))
70 ((*- if cell.type in ['code'] -*))
71
72 ((*- block codecell scoped -*))
73 ((*- block input_group -*))
74 ((*- block in_prompt -*))((*- endblock in_prompt -*))
75 ((*- block input -*))((*- endblock input -*))
76 ((*- endblock input_group -*))
77 ((*- if cell.outputs -*))
78 ((*- block output_group -*))
79 ((*- block output_prompt -*))((*- endblock output_prompt -*))
80 ((*- block outputs -*))
81 ((*- for output in cell.outputs -*))
82 ((*- if output.output_type in ['pyout'] -*))
83 ((*- block pyout scoped -*))((*- endblock pyout -*))
84 ((*- elif output.output_type in ['stream'] -*))
85 ((*- block stream scoped -*))
86 ((*- if output.stream in ['stdout'] -*))
87 ((*- block stream_stdout scoped -*))
88 ((*- endblock stream_stdout -*))
89 ((*- elif output.stream in ['stderr'] -*))
90 ((*- block stream_stderr scoped -*))
91 ((*- endblock stream_stderr -*))
92 ((*- endif -*))
93 ((*- endblock stream -*))
94 ((*- elif output.output_type in ['display_data'] -*))
95 ((*- block display_data scoped -*))
96 ((*- block data_priority scoped -*))
97 ((*- endblock data_priority -*))
98 ((*- endblock display_data -*))
99 ((*- elif output.output_type in ['pyerr'] -*))
100 ((*- block pyerr scoped -*))
101 ((*- for line in output.traceback -*))
102 ((*- block traceback_line scoped -*))((*- endblock traceback_line -*))
103 ((*- endfor -*))
104 ((*- endblock pyerr -*))
105 ((*- endif -*))
106 ((*- endfor -*))
107 ((*- endblock outputs -*))
108 ((*- endblock output_group -*))
109 ((*- endif -*))
110 ((*- endblock codecell -*))
111 ((*- elif cell.type in ['markdown'] -*))
112
113 ((*- block markdowncell scoped-*))
114 ((*- endblock markdowncell -*))
115 ((*- elif cell.type in ['heading'] -*))
116
117 ((*- block headingcell scoped-*))
118 ((*- endblock headingcell -*))
119 ((*- elif cell.type in ['raw'] -*))
120
121 ((*- block rawcell scoped-*))
122 ((*- endblock rawcell -*))
123 ((*- else -*))
124
125 ((*- block unknowncell scoped-*))
126 ((*- endblock unknowncell -*))
127 ((*- endif -*))
128 ((*- endblock any_cell -*))
@@ -1,16 +1,16 b''
1 ((============================================================================
1 ((============================================================================
2 NBConvert Sphinx-Latex HowTo Template
2 NBConvert Sphinx-Latex HowTo Template
3
3
4 Purpose: Allow export of PDF friendly Latex inspired by Sphinx HowTo
4 Purpose: Allow export of PDF friendly Latex inspired by Sphinx HowTo
5 document style. Most of the is derived directly from Sphinx source.
5 document style. Most of the is derived directly from Sphinx source.
6
6
7 Inheritance: null>display_priority>latex_base->latex_sphinx_base
7 Inheritance: null>display_priority>latex_base->latex_sphinx_base
8
8
9 ==========================================================================))
9 ==========================================================================))
10
10
11 ((*- extends 'latex_sphinx_base.tplx' -*))
11 ((*- extends 'latex_sphinx_base.tplx' -*))
12
12
13 ((* block documentclass *))sphinxhowto((* endblock documentclass *))
13 ((* set parentdocumentclass = 'article' *))
14 ((* block sphinxstyle *))((* include 'sphinxhowto.cls' *))((* endblock sphinxstyle *))
14 ((* set documentclass = 'howto' *))
15
15
16
16
@@ -1,14 +1,14 b''
1 ((============================================================================
1 ((============================================================================
2 NBConvert Sphinx-Latex Manual Template
2 NBConvert Sphinx-Latex Manual Template
3
3
4 Purpose: Allow export of PDF friendly Latex inspired by Sphinx Manual
4 Purpose: Allow export of PDF friendly Latex inspired by Sphinx Manual
5 document style. Most of the is derived directly from Sphinx source.
5 document style. Most of the is derived directly from Sphinx source.
6
6
7 Inheritance: null>display_priority>latex_base->latex_sphinx_base
7 Inheritance: null>display_priority>latex_base->latex_sphinx_base
8
8
9 ==========================================================================))
9 ==========================================================================))
10
10
11 ((*- extends 'latex_sphinx_base.tplx' -*))
11 ((*- extends 'latex_sphinx_base.tplx' -*))
12
12
13 ((* block documentclass *))sphinxmanual((* endblock documentclass *))
13 ((* set parentdocumentclass = 'report' *))
14 ((* block sphinxstyle *))((* include 'sphinxmanual.cls' *))((* endblock sphinxstyle *))
14 ((* set documentclass = 'manual' *))
@@ -1,133 +1,133 b''
1 %
1 %
2 % sphinxmanual.cls for Sphinx (http://sphinx-doc.org/)
2 % sphinxmanual.cls for Sphinx (http://sphinx-doc.org/)
3 %
3 %
4
4
5 \NeedsTeXFormat{LaTeX2e}[1995/12/01]
5 \NeedsTeXFormat{LaTeX2e}[1995/12/01]
6 \ProvidesClass{sphinxmanual}[2009/06/02 Document class (Sphinx manual)]
6 \ProvidesClass{sphinxmanual}[2009/06/02 Document class (Sphinx manual)]
7
7
8 % chapters starting at odd pages (overridden by 'openany' document option)
8 % chapters starting at odd pages (overridden by 'openany' document option)
9 \PassOptionsToClass{openright}{\sphinxdocclass}
9 \PassOptionsToClass{openright}{\sphinxdocclass}
10
10
11 % 'oneside' option overriding the 'twoside' default
11 % 'oneside' option overriding the 'twoside' default
12 \newif\if@oneside
12 \newif\if@oneside
13 \DeclareOption{oneside}{\@onesidetrue}
13 \DeclareOption{oneside}{\@onesidetrue}
14 % Pass remaining document options to the parent class.
14 % Pass remaining document options to the parent class.
15 \DeclareOption*{\PassOptionsToClass{\CurrentOption}{\sphinxdocclass}}
15 \DeclareOption*{\PassOptionsToClass{\CurrentOption}{\sphinxdocclass}}
16 \ProcessOptions\relax
16 \ProcessOptions\relax
17
17
18 % Defaults two-side document
18 % Defaults two-side document
19 \if@oneside
19 \if@oneside
20 % nothing to do (oneside is the default)
20 % nothing to do (oneside is the default)
21 \else
21 \else
22 \PassOptionsToClass{twoside}{\sphinxdocclass}
22 \PassOptionsToClass{twoside}{\sphinxdocclass}
23 \fi
23 \fi
24
24
25 \LoadClass{\sphinxdocclass}
25 \LoadClass{\sphinxdocclass}
26
26
27 % Set some sane defaults for section numbering depth and TOC depth. You can
27 % Set some sane defaults for section numbering depth and TOC depth. You can
28 % reset these counters in your preamble.
28 % reset these counters in your preamble.
29 %
29 %
30 \setcounter{secnumdepth}{2}
30 \setcounter{secnumdepth}{2}
31 \setcounter{tocdepth}{1}
31 \setcounter{tocdepth}{1}
32
32
33 % Change the title page to look a bit better, and fit in with the fncychap
33 % Change the title page to look a bit better, and fit in with the fncychap
34 % ``Bjarne'' style a bit better.
34 % ``Bjarne'' style a bit better.
35 %
35 %
36 \renewcommand{\maketitle}{%
36 \renewcommand{\maketitle}{%
37 \begin{titlepage}%
37 \begin{titlepage}%
38 \let\footnotesize\small
38 \let\footnotesize\small
39 \let\footnoterule\relax
39 \let\footnoterule\relax
40 \rule{\textwidth}{1pt}%
40 \rule{\textwidth}{1pt}%
41 \ifsphinxpdfoutput
41 \ifsphinxpdfoutput
42 \begingroup
42 \begingroup
43 % These \defs are required to deal with multi-line authors; it
43 % These \defs are required to deal with multi-line authors; it
44 % changes \\ to ', ' (comma-space), making it pass muster for
44 % changes \\ to ', ' (comma-space), making it pass muster for
45 % generating document info in the PDF file.
45 % generating document info in the PDF file.
46 \def\\{, }
46 \def\\{, }
47 \def\and{and }
47 \def\and{and }
48 \pdfinfo{
48 \pdfinfo{
49 /Author (\@author)
49 /Author (\@author)
50 /Title (\@title)
50 /Title (\@title)
51 }
51 }
52 \endgroup
52 \endgroup
53 \fi
53 \fi
54 \begin{flushright}%
54 \begin{flushright}%
55 \sphinxlogo%
55 \sphinxlogo%
56 {\rm\Huge\py@HeaderFamily \@title \par}%
56 {\rm\Huge\py@HeaderFamily \@title \par}%
57 {\em\LARGE\py@HeaderFamily \py@release\releaseinfo \par}
57 {\em\LARGE\py@HeaderFamily \py@release\releaseinfo \par}
58 \vfill
58 \vfill
59 {\LARGE\py@HeaderFamily
59 {\LARGE\py@HeaderFamily
60 \begin{tabular}[t]{c}
60 \begin{tabular}[t]{c}
61 \@author
61 \@author
62 \end{tabular}
62 \end{tabular}
63 \par}
63 \par}
64 \vfill\vfill
64 \vfill\vfill
65 {\large
65 {\large
66 \@date \par
66 \@date \par
67 \vfill
67 \vfill
68 \py@authoraddress \par
68 \py@authoraddress \par
69 }%
69 }%
70 \end{flushright}%\par
70 \end{flushright}%\par
71 \@thanks
71 \@thanks
72 \end{titlepage}%
72 \end{titlepage}%
73 \cleardoublepage%
73 \cleardoublepage%
74 \setcounter{footnote}{0}%
74 \setcounter{footnote}{0}%
75 \let\thanks\relax\let\maketitle\relax
75 \let\thanks\relax\let\maketitle\relax
76 %\gdef\@thanks{}\gdef\@author{}\gdef\@title{}
76 %\gdef\@thanks{}\gdef\@author{}\gdef\@title{}
77 }
77 }
78
78
79
79
80 % Catch the end of the {abstract} environment, but here make sure the abstract
80 % Catch the end of the {abstract} environment, but here make sure the abstract
81 % is followed by a blank page if the 'openright' option is used.
81 % is followed by a blank page if the 'openright' option is used.
82
82 %
83 \let\py@OldEndAbstract=\endabstract
83 \let\py@OldEndAbstract=\endabstract
84 \renewcommand{\endabstract}{
84 \renewcommand{\endabstract}{
85 \if@openright
85 \if@openright
86 \ifodd\value{page}
86 \ifodd\value{page}
87 \typeout{Adding blank page after the abstract.}
87 \typeout{Adding blank page after the abstract.}
88 \vfil\pagebreak
88 \vfil\pagebreak
89 \fi
89 \fi
90 \fi
90 \fi
91 \py@OldEndAbstract
91 \py@OldEndAbstract
92 }
92 }
93
93
94 % This wraps the \tableofcontents macro with all the magic to get the spacing
94 % This wraps the \tableofcontents macro with all the magic to get the spacing
95 % right and have the right number of pages if the 'openright' option has been
95 % right and have the right number of pages if the 'openright' option has been
96 % used. This eliminates a fair amount of crud in the individual document files.
96 % used. This eliminates a fair amount of crud in the individual document files.
97 %
97 %
98 \let\py@OldTableofcontents=\tableofcontents
98 \let\py@OldTableofcontents=\tableofcontents
99 \renewcommand{\tableofcontents}{%
99 \renewcommand{\tableofcontents}{%
100 \setcounter{page}{1}%
100 \setcounter{page}{1}%
101 \pagebreak%
101 \pagebreak%
102 \pagestyle{plain}%
102 \pagestyle{plain}%
103 {%
103 {%
104 \parskip = 0mm%
104 \parskip = 0mm%
105 \py@OldTableofcontents%
105 \py@OldTableofcontents%
106 \if@openright%
106 \if@openright%
107 \ifodd\value{page}%
107 \ifodd\value{page}%
108 \typeout{Adding blank page after the table of contents.}%
108 \typeout{Adding blank page after the table of contents.}%
109 \pagebreak\hspace{0pt}%
109 \pagebreak\hspace{0pt}%
110 \fi%
110 \fi%
111 \fi%
111 \fi%
112 \cleardoublepage%
112 \cleardoublepage%
113 }%
113 }%
114 \pagenumbering{arabic}%
114 \pagenumbering{arabic}%
115 \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
115 \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
116 }
116 }
117
117
118 % This is needed to get the width of the section # area wide enough in the
118 % This is needed to get the width of the section # area wide enough in the
119 % library reference. Doing it here keeps it the same for all the manuals.
119 % library reference. Doing it here keeps it the same for all the manuals.
120
120 %
121 \renewcommand*\l@section{\@dottedtocline{1}{1.5em}{2.6em}}
121 \renewcommand*\l@section{\@dottedtocline{1}{1.5em}{2.6em}}
122 \renewcommand*\l@subsection{\@dottedtocline{2}{4.1em}{3.5em}}
122 \renewcommand*\l@subsection{\@dottedtocline{2}{4.1em}{3.5em}}
123
123
124 % Fix the bibliography environment to add an entry to the Table of
124 % Fix the bibliography environment to add an entry to the Table of
125 % Contents.
125 % Contents.
126 % For a report document class this environment is a chapter.
126 % For a report document class this environment is a chapter.
127 \let\py@OldThebibliography=\thebibliography
127 \let\py@OldThebibliography=\thebibliography
128 \renewcommand{\thebibliography}[1]{
128 \renewcommand{\thebibliography}[1]{
129 \cleardoublepage
129 \cleardoublepage
130 \phantomsection
130 \phantomsection
131 \py@OldThebibliography{1}
131 \py@OldThebibliography{1}
132 \addcontentsline{toc}{chapter}{\bibname}
132 \addcontentsline{toc}{chapter}{\bibname}
133 }
133 }
General Comments 0
You need to be logged in to leave comments. Login now