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