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