##// END OF EJS Templates
Update info about latex/pdf conversion
onesandzeroes -
Show More
@@ -1,165 +1,169
1 .. _nbconvert:
1 .. _nbconvert:
2
2
3 Converting notebooks to other formats
3 Converting notebooks to other formats
4 =====================================
4 =====================================
5
5
6 Newly added in the 1.0 release of IPython is the ``nbconvert`` tool, which
6 Newly added in the 1.0 release of IPython is the ``nbconvert`` tool, which
7 allows you to convert an ``.ipynb`` notebook document file into various static
7 allows you to convert an ``.ipynb`` notebook document file into various static
8 formats.
8 formats.
9
9
10 Currently, ``nbconvert`` is provided as a command line tool, run as a script
10 Currently, ``nbconvert`` is provided as a command line tool, run as a script
11 using IPython. A direct export capability from within the
11 using IPython. A direct export capability from within the
12 IPython Notebook web app is planned.
12 IPython Notebook web app is planned.
13
13
14 The command-line syntax to run the ``nbconvert`` script is::
14 The command-line syntax to run the ``nbconvert`` script is::
15
15
16 $ ipython nbconvert --to FORMAT notebook.ipynb
16 $ ipython nbconvert --to FORMAT notebook.ipynb
17
17
18 This will convert the IPython document file ``notebook.ipynb`` into the output
18 This will convert the IPython document file ``notebook.ipynb`` into the output
19 format given by the ``FORMAT`` string.
19 format given by the ``FORMAT`` string.
20
20
21 The default output format is html, for which the ``--to`` argument may be
21 The default output format is html, for which the ``--to`` argument may be
22 omitted::
22 omitted::
23
23
24 $ ipython nbconvert notebook.ipynb
24 $ ipython nbconvert notebook.ipynb
25
25
26 IPython provides a few templates for some output formats, and these can be
26 IPython provides a few templates for some output formats, and these can be
27 specified via an additional ``--template`` argument.
27 specified via an additional ``--template`` argument.
28
28
29 The currently supported export formats are:
29 The currently supported export formats are:
30
30
31 * ``--to html``
31 * ``--to html``
32
32
33 - ``--template full`` (default)
33 - ``--template full`` (default)
34
34
35 A full static HTML render of the notebook.
35 A full static HTML render of the notebook.
36 This looks very similar to the interactive view.
36 This looks very similar to the interactive view.
37
37
38 - ``--template basic``
38 - ``--template basic``
39
39
40 Simplified HTML, useful for embedding in webpages, blogs, etc.
40 Simplified HTML, useful for embedding in webpages, blogs, etc.
41 This excludes HTML headers.
41 This excludes HTML headers.
42
42
43 * ``--to latex``
43 * ``--to latex``
44
44
45 Latex export. This generates ``NOTEBOOK_NAME.tex`` file,
45 Latex export. This generates ``NOTEBOOK_NAME.tex`` file,
46 ready for export. You can automatically run latex on it to generate a PDF
46 ready for export.
47 by adding ``--post PDF``.
48
47
49 - ``--template article`` (default)
48 - ``--template article`` (default)
50
49
51 Latex article, derived from Sphinx's howto template.
50 Latex article, derived from Sphinx's howto template.
52
51
53 - ``--template book``
52 - ``--template report``
54
53
55 Latex book, derived from Sphinx's manual template.
54 Latex report, providing a table of contents and chapters.
56
55
57 - ``--template basic``
56 - ``--template basic``
58
57
59 Very basic latex output - mainly meant as a starting point for custom templates.
58 Very basic latex output - mainly meant as a starting point for custom templates.
60
59
60 * ``--to pdf``
61
62 Generates a PDF via latex. Replaces ``--to latex --post PDF``, which is deprecated.
63 Supports the same templates as ``--to latex``.
64
61 * ``--to slides``
65 * ``--to slides``
62
66
63 This generates a Reveal.js HTML slideshow.
67 This generates a Reveal.js HTML slideshow.
64 It must be served by an HTTP server. The easiest way to do this is adding
68 It must be served by an HTTP server. The easiest way to do this is adding
65 ``--post serve`` on the command-line. The ``serve`` post-processor proxies
69 ``--post serve`` on the command-line. The ``serve`` post-processor proxies
66 Reveal.js requests to a CDN if no local Reveal.js library is present.
70 Reveal.js requests to a CDN if no local Reveal.js library is present.
67 To make slides that don't require an internet connection, just place the
71 To make slides that don't require an internet connection, just place the
68 Reveal.js library in the same directory where your_talk.slides.html is located,
72 Reveal.js library in the same directory where your_talk.slides.html is located,
69 or point to another directory using the ``--reveal-prefix`` alias.
73 or point to another directory using the ``--reveal-prefix`` alias.
70
74
71 * ``--to markdown``
75 * ``--to markdown``
72
76
73 Simple markdown output. Markdown cells are unaffected,
77 Simple markdown output. Markdown cells are unaffected,
74 and code cells indented 4 spaces.
78 and code cells indented 4 spaces.
75
79
76 * ``--to rst``
80 * ``--to rst``
77
81
78 Basic reStructuredText output. Useful as a starting point for embedding notebooks
82 Basic reStructuredText output. Useful as a starting point for embedding notebooks
79 in Sphinx docs.
83 in Sphinx docs.
80
84
81 * ``--to script``
85 * ``--to script``
82
86
83 Convert a notebook to an executable script.
87 Convert a notebook to an executable script.
84 This is the simplest way to get a Python (or other language, depending on the kernel) script out of a notebook.
88 This is the simplest way to get a Python (or other language, depending on the kernel) script out of a notebook.
85 If there were any magics in an IPython notebook, this may only be executable from
89 If there were any magics in an IPython notebook, this may only be executable from
86 an IPython session.
90 an IPython session.
87
91
88 * ``--to notebook``
92 * ``--to notebook``
89
93
90 .. versionadded:: 3.0
94 .. versionadded:: 3.0
91
95
92 This doesn't convert a notebook to a different format *per se*,
96 This doesn't convert a notebook to a different format *per se*,
93 instead it allows the running of nbconvert preprocessors on a notebook,
97 instead it allows the running of nbconvert preprocessors on a notebook,
94 and/or conversion to other notebook formats. For example::
98 and/or conversion to other notebook formats. For example::
95
99
96 ipython nbconvert --to notebook --execute mynotebook.ipynb
100 ipython nbconvert --to notebook --execute mynotebook.ipynb
97
101
98 will open the notebook, execute it, capture new output, and save the result in
102 will open the notebook, execute it, capture new output, and save the result in
99 :file:`mynotebook.nbconvert.ipynb`.
103 :file:`mynotebook.nbconvert.ipynb`.
100
104
101 ::
105 ::
102
106
103 ipython nbconvert --to notebook --nbformat 3 mynotebook
107 ipython nbconvert --to notebook --nbformat 3 mynotebook
104
108
105 will create a copy of :file:`mynotebook.ipynb` in :file:`mynotebook.v3.ipynb`
109 will create a copy of :file:`mynotebook.ipynb` in :file:`mynotebook.v3.ipynb`
106 in version 3 of the :ref:`notebook format <nbformat>`.
110 in version 3 of the :ref:`notebook format <nbformat>`.
107
111
108 If you want to convert a notebook in-place,
112 If you want to convert a notebook in-place,
109 you can specify the ouptut file to be the same as the input file::
113 you can specify the ouptut file to be the same as the input file::
110
114
111 ipython nbconvert --to notebook mynb --output mynb
115 ipython nbconvert --to notebook mynb --output mynb
112
116
113 Be careful with that, since it will replace the input file.
117 Be careful with that, since it will replace the input file.
114
118
115 .. note::
119 .. note::
116
120
117 nbconvert uses pandoc_ to convert between various markup languages,
121 nbconvert uses pandoc_ to convert between various markup languages,
118 so pandoc is a dependency when converting to latex or reStructuredText.
122 so pandoc is a dependency when converting to latex or reStructuredText.
119
123
120 .. _pandoc: http://johnmacfarlane.net/pandoc/
124 .. _pandoc: http://johnmacfarlane.net/pandoc/
121
125
122 The output file created by ``nbconvert`` will have the same base name as
126 The output file created by ``nbconvert`` will have the same base name as
123 the notebook and will be placed in the current working directory. Any
127 the notebook and will be placed in the current working directory. Any
124 supporting files (graphics, etc) will be placed in a new directory with the
128 supporting files (graphics, etc) will be placed in a new directory with the
125 same base name as the notebook, suffixed with ``_files``::
129 same base name as the notebook, suffixed with ``_files``::
126
130
127 $ ipython nbconvert notebook.ipynb
131 $ ipython nbconvert notebook.ipynb
128 $ ls
132 $ ls
129 notebook.ipynb notebook.html notebook_files/
133 notebook.ipynb notebook.html notebook_files/
130
134
131 For simple single-file output, such as html, markdown, etc.,
135 For simple single-file output, such as html, markdown, etc.,
132 the output may be sent to standard output with::
136 the output may be sent to standard output with::
133
137
134 $ ipython nbconvert --to markdown notebook.ipynb --stdout
138 $ ipython nbconvert --to markdown notebook.ipynb --stdout
135
139
136 Multiple notebooks can be specified from the command line::
140 Multiple notebooks can be specified from the command line::
137
141
138 $ ipython nbconvert notebook*.ipynb
142 $ ipython nbconvert notebook*.ipynb
139 $ ipython nbconvert notebook1.ipynb notebook2.ipynb
143 $ ipython nbconvert notebook1.ipynb notebook2.ipynb
140
144
141 or via a list in a configuration file, say ``mycfg.py``, containing the text::
145 or via a list in a configuration file, say ``mycfg.py``, containing the text::
142
146
143 c = get_config()
147 c = get_config()
144 c.NbConvertApp.notebooks = ["notebook1.ipynb", "notebook2.ipynb"]
148 c.NbConvertApp.notebooks = ["notebook1.ipynb", "notebook2.ipynb"]
145
149
146 and using the command::
150 and using the command::
147
151
148 $ ipython nbconvert --config mycfg.py
152 $ ipython nbconvert --config mycfg.py
149
153
150
154
151 LaTeX citations
155 LaTeX citations
152 ---------------
156 ---------------
153
157
154 ``nbconvert`` now has support for LaTeX citations. With this capability you
158 ``nbconvert`` now has support for LaTeX citations. With this capability you
155 can:
159 can:
156
160
157 * Manage citations using BibTeX.
161 * Manage citations using BibTeX.
158 * Cite those citations in Markdown cells using HTML data attributes.
162 * Cite those citations in Markdown cells using HTML data attributes.
159 * Have ``nbconvert`` generate proper LaTeX citations and run BibTeX.
163 * Have ``nbconvert`` generate proper LaTeX citations and run BibTeX.
160
164
161 For an example of how this works, please see the citations example in
165 For an example of how this works, please see the citations example in
162 the nbconvert-examples_ repository.
166 the nbconvert-examples_ repository.
163
167
164 .. _nbconvert-examples: https://github.com/ipython/nbconvert-examples
168 .. _nbconvert-examples: https://github.com/ipython/nbconvert-examples
165
169
General Comments 0
You need to be logged in to leave comments. Login now