##// END OF EJS Templates
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
David P. Sanders -
Show More
@@ -2,7 +2,7 b''
2
2
3 The IPython Notebook
3 The IPython Notebook
4 ====================
4 ====================
5
5
6 The IPython Notebook is part of the IPython package, which aims to provide a powerful, interactive approach to scientific computation.
6 The IPython Notebook is part of the IPython package, which aims to provide a powerful, interactive approach to scientific computation.
7 The IPython Notebook extends the previous text-console-based approach, and the later Qt console, in a qualitatively new diretion, providing a web-based application suitable for capturing the whole scientific computation process.
7 The IPython Notebook extends the previous text-console-based approach, and the later Qt console, in a qualitatively new diretion, providing a web-based application suitable for capturing the whole scientific computation process.
8
8
@@ -17,7 +17,7 b' Basic structure'
17
17
18 The IPython Notebook combines two components:
18 The IPython Notebook combines two components:
19
19
20 * **The *IPython Notebook* web application**:
20 * **The IPython Notebook web application**:
21
21
22 The IPython Notebook web app is a browser-based tool for interactive authoring of literate computations, in which explanatory text, mathematics,computations and rich media output may be combined. Input and output are stored in persistent cells that may be edited in-place.
22 The IPython Notebook web app is a browser-based tool for interactive authoring of literate computations, in which explanatory text, mathematics,computations and rich media output may be combined. Input and output are stored in persistent cells that may be edited in-place.
23
23
@@ -28,7 +28,7 b' The IPython Notebook combines two components:'
28 Since the similarity in names can lead to some confusion, in the documentation we will use capitalization of the word "notebook" to distinguish the *N*otebook app and *n*otebook documents, thinking of the Notebook app as being a proper noun. We will also always refer to the "Notebook app" when we are referring to the browser-based interface, and usually to "notebook documents", instead of "notebooks", for added precision.
28 Since the similarity in names can lead to some confusion, in the documentation we will use capitalization of the word "notebook" to distinguish the *N*otebook app and *n*otebook documents, thinking of the Notebook app as being a proper noun. We will also always refer to the "Notebook app" when we are referring to the browser-based interface, and usually to "notebook documents", instead of "notebooks", for added precision.
29
29
30 We refer to the current state of the computational process taking place in the Notebook app, i.e. the (numbered) sequence of input and output cells, as the
30 We refer to the current state of the computational process taking place in the Notebook app, i.e. the (numbered) sequence of input and output cells, as the
31 *notebook space*. Notebook documents provide an *exact*, *one-to-one* record of all the content in the notebook space, as a plain text file in JSON format. The Notebook app automatically saves, at certain intervals, the contents of the notebook space to a notebook document stored on disk, with the same name as the title of the notebook space, and the file extension ".ipynb". For this reason, there is no confusion about using the same word "notebook" for both the notebook space and the corresonding notebook document, since they are really one and the same concept ("isomorphic").
31 *notebook space*. Notebook documents provide an *exact*, *one-to-one* record of all the content in the notebook space, as a plain text file in JSON format. The Notebook app automatically saves, at certain intervals, the contents of the notebook space to a notebook document stored on disk, with the same name as the title of the notebook space, and the file extension ``.ipynb`. For this reason, there is no confusion about using the same word "notebook" for both the notebook space and the corresonding notebook document, since they are really one and the same concept (we could say that they are "isomorphic").
32
32
33
33
34 Main features of the IPython Notebook web app
34 Main features of the IPython Notebook web app
@@ -36,7 +36,7 b' Main features of the IPython Notebook web app'
36
36
37 The main features of the IPython Notebook app include:
37 The main features of the IPython Notebook app include:
38
38
39 * In-browser editing for code, with automatic syntax highlighting, tab completion and autoindentation.
39 * In-browser editing for code, with automatic syntax highlighting and indentation and tab completion/introspection.
40 * Literate combination of code with rich text using the Markdown markup language.
40 * Literate combination of code with rich text using the Markdown markup language.
41 * Mathematics is easily included within the Markdown using LaTeX notation, and rendered natively by MathJax.
41 * Mathematics is easily included within the Markdown using LaTeX notation, and rendered natively by MathJax.
42 * Displays rich data representations (e.g. HTML / LaTeX / SVG) as the result of computations.
42 * Displays rich data representations (e.g. HTML / LaTeX / SVG) as the result of computations.
@@ -76,7 +76,7 b' how to install the notebook and its dependencies.'
76 Starting up the IPython Notebook web app
76 Starting up the IPython Notebook web app
77 ----------------------------------------
77 ----------------------------------------
78
78
79 The Notebook web app is started with the command::
79 You can start running the Notebook web app using the following command::
80
80
81 $ ipython notebook
81 $ ipython notebook
82
82
@@ -85,8 +85,8 b' You can create new notebooks from the dashboard with the ``New Notebook``'
85 button, or open existing ones by clicking on their name.
85 button, or open existing ones by clicking on their name.
86 You can also drag and drop ``.ipynb`` notebooks and standard ``.py`` Python source code files into the notebook list area.
86 You can also drag and drop ``.ipynb`` notebooks and standard ``.py`` Python source code files into the notebook list area.
87
87
88 ``.py`` files will be imported into the IPython Notebook as a notebook with the same name, but an ``.ipynb`` extension, located in the working directory. The notebook will consist of a single cell containing all the
88 ``.py`` files will be imported into the IPython Notebook as a notebook with the same name, but an ``.ipynb`` extension, located in the working directory. The notebook created will have just one cell, which will contain all the
89 code in the ``.py`` file, which you can later manually partition into individual cells.
89 code in the ``.py`` file. You can later manually partition this into individual cells using the ``Edit | Split Cell`` menu option, or the :kbd:`Ctrl-m -` keyboard shortcut.
90
90
91 .. Alternatively, prior to importing the ``.py``, you can manually add ``# <nbformat>2</nbformat>`` at the start of the file, and then add separators for text and code cells, to get a cleaner import with the file already broken into individual cells.
91 .. Alternatively, prior to importing the ``.py``, you can manually add ``# <nbformat>2</nbformat>`` at the start of the file, and then add separators for text and code cells, to get a cleaner import with the file already broken into individual cells.
92
92
@@ -122,35 +122,32 b' The tool bar gives a quick way of accessing the most-used operations within the '
122 Input cells
122 Input cells
123 -----------
123 -----------
124 Input cells are at the core of the functionality of the IPython Notebook.
124 Input cells are at the core of the functionality of the IPython Notebook.
125 They are regions in the document in which you can enter different types of text and commands. To *execute* or *run* the *current cell*, i.e. the cell under the cursor, you can use the:kbd:`Shift-Enter` key combination.
125 They are regions in the document in which you can enter different types of text and commands. To *execute* or *run* the *current cell*, i.e. the cell under the cursor, you can use the :kbd:`Shift-Enter` key combination.
126 This tells the Notebook app to perform the relevant operation for each type of cell (see below), and then to display the resulting output.
126 This tells the Notebook app to perform the relevant operation for each type of cell (see below), and then to display the resulting output.
127
127
128 The notebook consists of a sequence of input cells, labelled ``In[n]``, which may be executed in a non-linear way, and outpus ``Out[n]``, where ``n`` is a number which denotes the order in which the cells were executed over the history of the computational process. The content of these cells is accessible as Python variables with the same names.
128 The notebook consists of a sequence of input cells, labelled ``In[n]``, which may be executed in a non-linear way, and outputs ``Out[n]``, where ``n`` is a number which denotes the order in which the cells were executed over the history of the computational process. The contents of all of these cells are accessible as Python variables with the same names, forming a complete record of the history of the computation.
129
129
130
130
131 Basic workflow
131 Basic workflow
132 --------------
132 --------------
133 The normal workflow in a notebook is, then, quite similar to a standard IPython session, with the difference that you can edit cells in-place multiple
133 The normal workflow in a notebook is, then, quite similar to a standard IPython session, with the difference that you can edit cells in-place multiple
134 times until you obtain the desired results, rather than having to
134 times until you obtain the desired results, rather than having to
135 rerun separate scripts with the ``%run`` magic command. (Magic commands do, however, also work in the notebook; see below). Typically, you'll work on a problem in pieces,
135 rerun separate scripts with the ``%run`` magic command. (Magic commands do, however, also work in the notebook; see below).
136 organizing related pieces into cells and moving forward as previous
136
137 parts work correctly. This is much more convenient for interactive exploration than breaking up a computation into scripts that must be
137 Typically, you will work on a computational problem in pieces, organizing related ideas into cells and moving forward once previous parts work correctly. This is much more convenient for interactive exploration than breaking up a computation into scripts that must be executed together, as was previously necessary, especially if parts of them take a long time to run
138 executed together, especially if parts of them take a long time to run
138
139
139 The only significant limitation that the Notebook currently has, compared to the Qt console, is that it cannot run any code that expects input from the kernel (such as scripts that call :func:`raw_input`). Very importantly, this means that the ``%debug`` magic does *not* currently work in the notebook!
140 The only significant limitation that the notebook currently has, compared to the Qt console, is that it cannot run any code that
140
141 expects input from the kernel (such as scripts that call
141 This limitation will be overcome in the future, but in the meantime, there is a simple solution for debugging: you can attach a Qt console to your existing notebook kernel, and run ``%debug`` from the Qt console.
142 :func:`raw_input`). Very importantly, this means that the ``%debug``
142 If your notebook is running on a local computer (i.e. if you are accessing it via your localhost address at ``127.0.0.1``), then you can just type
143 magic does *not* currently work in the notebook! This limitation will
143 ``%qtconsole`` in the notebook and a Qt console will open up, connected to that same kernel.
144 be overcome in the future, but in the meantime, there is a way to debug problems in the notebook: you can attach a Qt console to your existing notebook kernel, and run ``%debug`` from the Qt console.
145 If your notebook is running on a local
146 computer (i.e. if you are accessing it via your localhost address at ``127.0.0.1``), you can just type ``%qtconsole`` in the notebook and a Qt console will open up, connected to that same kernel.
147
144
148 At certain moments, it may be necessary to interrupt a particularly long calculation, or even to kill the entire computational process. This may be achieved by interrupting or restarting the kernel, respectively.
145 At certain moments, it may be necessary to interrupt a particularly long calculation, or even to kill the entire computational process. This may be achieved by interrupting or restarting the kernel, respectively.
149 After a restart, all relevant cells must be re-evaluated
146 After a kernel restart, it as if the notebook were loaded afresh.
150
147
151
148
152 A notebook may be downloaded in either ``.ipynb`` or raw ``.py`` form from the menu option ``File | Download as``
149 A notebook may be downloaded in either ``.ipynb`` or raw ``.py`` form from the menu option ``File | Download as``.
153 Choosing the ``.py`` option removes all output and saves the text cells
150 Choosing the ``.py`` option downloads a Python ``.py`` script, in which all output has been removed and the content of Markdown cells
154 in comment areas. See ref:`below <notebook_format>` for more details on the
151 in comment areas. See ref:`below <notebook_format>` for more details on the
155 notebook format.
152 notebook format.
156
153
@@ -174,24 +171,24 b' All actions in the notebook can be achieved with the mouse, but'
174 keyboard shortcuts are also available for the most common ones, so that productive use of the notebook can be achieved with minimal mouse usage. The main shortcuts to remember are the following:
171 keyboard shortcuts are also available for the most common ones, so that productive use of the notebook can be achieved with minimal mouse usage. The main shortcuts to remember are the following:
175
172
176 * :kbd:`Shift-Enter`:
173 * :kbd:`Shift-Enter`:
177 Execute the current cell, show output (if any), and jump to the next cell below. If :kbd:`Shift-Enter` is invoked on the last input cell, a new code cell will also be created. Note that in the notebook, typing :kbd:`Enter` on its own *never* forces execution, but rather just inserts a new line in the current input cell. In the Notebook it is thus always necessary to use :kbd:`Shift-Enter` to execute the cell (or use the ``Cell | Run`` menu item).
174 Execute the current cell, show output (if any), and jump to the next cell below. If :kbd:`Shift-Enter` is invoked on the last input cell, a new code cell will also be created. Note that in the notebook, typing :kbd:`Enter` on its own *never* forces execution, but rather just inserts a new line in the current input cell. In the Notebook it is thus always necessary to use :kbd:`Shift-Enter` to execute the cell (or use the ``Cell | Run`` menu item).
178
175
179 * :kbd:`Ctrl-Enter`:
176 * :kbd:`Ctrl-Enter`:
180 Execute the current cell as if it were in "terminal mode", where any output is shown, but the cursor *remains* in the current cell. This is convenient for doing quick experiments in place, or for querying things like filesystem content, without needing to create additional cells that you may not want to be saved in the notebook.
177 Execute the current cell as if it were in "terminal mode", where any output is shown, but the cursor *remains* in the current cell. This is convenient for doing quick experiments in place, or for querying things like filesystem content, without needing to create additional cells that you may not want to be saved in the notebook.
181
178
182 * :kbd:`Alt-Enter`:
179 * :kbd:`Alt-Enter`:
183 Executes the current cell, shows the output, and inserts a *new* input cell between the current cell and the adjacent cell (if one exists). This is thus a shortcut for the sequence :kbd:`Shift-Enter`, :kbd:`Ctrl-m a`.
180 Executes the current cell, shows the output, and inserts a *new* input cell between the current cell and the adjacent cell (if one exists). This is thus a shortcut for the sequence :kbd:`Shift-Enter`, :kbd:`Ctrl-m a`.
181 (:kbd:`Ctrl-m a` adds a new cell below the current one.)
184
182
185
183
186
184
187 * :kbd:`Ctrl-m`:
185 * :kbd:`Ctrl-m`:
188 This is the prefix for all of the other shortcuts, which consist of an additional single letter or character. If you type :kbd:`Ctrl-m h` (that is, the sole letter :kbd:`h` after :kbd:`Ctrl-m`), IPython will show you all the available keyboard shortcuts.
186 This is the prefix for *all* other shortcuts, which consist of :kbd:`Ctrl-m` followed by a single letter or character. For example, if you type :kbd:`Ctrl-m h` (that is, the sole letter :kbd:`h` after :kbd:`Ctrl-m`), IPython will show you all the available keyboard shortcuts.
189
187
190
188
191 Cell types
189 Input cell types
192 ----------
190 ----------------
193 Each IPython input cell has a *cell type*.
191 Each IPython input cell has a *cell type*, of which there is a restricted number. The type of a cell may be set by using the cell type dropdown on the toolbar, or via the following keyboard shortcuts:
194 There is a restricted number of possible cell types, which may be set by using the cell type dropdown on the toolbar, or via the following keyboard shortcuts:
195
192
196 * **code**: :kbd:`Ctrl-m y`
193 * **code**: :kbd:`Ctrl-m y`
197 * **markdown**: :kbd:`Ctrl-m m`
194 * **markdown**: :kbd:`Ctrl-m m`
@@ -203,55 +200,53 b' Upon initial creation, each input cell is by default a code cell.'
203
200
204 Code cells
201 Code cells
205 ~~~~~~~~~~
202 ~~~~~~~~~~
206 A *code input cell* allows you to edit code inline within the cell, with full syntax highlighting and autocompletion/introspection. By default, the language of a code cell is Python, but other languages, such as ``julia`` and ``R``, are handled using magic commands (see below).
203 A *code input cell* allows you to edit code inline within the cell, with full syntax highlighting and autocompletion/introspection. By default, the language associated to a code cell is Python, but other languages, such as ``julia`` and ``R``, can be handled using magic commands (see below).
207
204
208 When a code cell is executed with :kbd:`Shift-Enter`, the code that it contains is transparently exported and run in that language
205 When a code cell is executed with :kbd:`Shift-Enter`, the code that it contains is transparently exported and run in that language
209 (with automatic compiling, etc., if necessary). The result that is returned from this computation is then displayed in the notebook space as the cell's
206 (with automatic compiling, etc., if necessary). The result that is returned from this computation is then displayed in the notebook space as the cell's
210 *output*. If this output is of a textual nature, then it is placed into a numbered *output cell*.
207 *output*. If this output is of a textual nature, then it is placed into a numbered *output cell*.
211 However, many other possible forms of output are allowed, for example,
208 However, many other possible forms of output are also possible, including
212 ``matplotlib`` figures and HTML tables (as used, for example, in the
209 ``matplotlib`` figures and HTML tables (as used, for example, in the
213 ``pandas`` data analyis package). This is known as IPython's *rich display* capability.
210 ``pandas`` data analyis package). This is known as IPython's *rich display* capability.
214
211
215
212
216 Rich text using Markdown
213 Rich text using Markdown
217 ~~~~~~~~~~~~~~~~~~~~~~~~
214 ~~~~~~~~~~~~~~~~~~~~~~~~
218 You can document the computational process in a literate way, alternating descriptive text with code, using *rich text*. In IPython this is accomplished by marking up text using the Markdown markup language, in *Markdown input cells*. The Markdown language is a simple way to specify that parts of the text should be emphasized (italics), bold, form lists, etc.
215 You can document the computational process in a literate way, alternating descriptive text with code, using *rich text*. In IPython this is accomplished by marking up text with the Markdown language. The corresponding cells are called *Markdown input cells*. The Markdown language provides a simple way to perform this text markup, that is, to specify which parts of the text should be emphasized (italics), bold, form lists, etc.
219
216
220 When a Markdown input cell is executed, the Markdown code is converted into the corresponding formatted rich text. This output then *replaces* the original Markdown input cell, leaving just the visually-significant marked up rich text. Markdown allows arbitrary HTML code for formatting.
217 When a Markdown input cell is executed, the Markdown code is converted into the corresponding formatted rich text. This output then *replaces* the original Markdown input cell, leaving just the visually-significant marked up rich text. Markdown allows arbitrary HTML code for formatting.
221
218
222 Within Markdown cells, you can also include *mathematics* in a straightforward way, using standar LaTeX notation: ``$...$`` for inline mathematics and ``$$...$$`` for displayed mathematics. Mathematics is rendered natively in the browser by MathJax. Standard LaTeX and AMS-math environments, such as
219 Within Markdown cells, you can also include *mathematics* in a straightforward way, using standard LaTeX notation: ``$...$`` for inline mathematics and ``$$...$$`` for displayed mathematics. Mathematics is rendered natively in the browser by MathJax. Standard LaTeX and AMS-math environments, such as
223 ``\begin{equation}...\end{equation}``, and ``\begin{align}...\end{align}`` also work, and new LaTeX macros may be defined using standard LaTeX methods, such as ``\newcommand``, by placing them anywhere in a Markdown cell.
220 ``\begin{equation}...\end{equation}``, and ``\begin{align}...\end{align}`` also work, and new LaTeX macros may be defined using standard LaTeX methods, such as ``\newcommand``, by placing them anywhere in a Markdown cell.
224
221
225 Raw cells
222 Raw input cells
226 ~~~~~~~~~
223 ~~~~~~~~~~~~~~~
227 Raw cells provide a place to put additional information which is not evaluated by the Notebook. This can be used, for example, for extra information you
224 *Raw* input cells provide a place in which you can put additional information which you do not want to evaluated by the Notebook. This can be used, for example, to include extra information that is needed when exporting to a certain format. The output after evaluating a raw cell is just a verbatim copy of the input.
228 require to be included when the notebook is exported to a certain format.
229
225
230 Heading cells
226 Heading cells
231 ˜˜˜˜˜˜˜˜˜˜˜˜˜
227 ~~~~~~~~~~~~~
232 You can provide a conceptual structure for your computational document using
228 You can provide a conceptual structure for your computational document as a whole using different levels of headings; there are 6 levels available, from level 1 (main title) down to level 6 (paragraph). These can be used later for constructing tables of contents, etc.
233 different levels of headings; there are 6 levels available, from level 1 (main
234 title) down to level 6 (paragraph). These can be used later for constructing
235 tables of contents, etc.
236
229
237 As with Markdown cells, a heading input cell is replaced by a rich text rendering of the heading when the cell is executed.
230 As with Markdown cells, a heading input cell is replaced by a rich text rendering of the heading when the cell is executed.
238
231
239
232
240 Magic commands
233 Magic commands
241 --------------
234 ~~~~~~~~~~~~~~
242 Magic commands, or *magics*, are commands for controlling IPython itself.
235 Magic commands, or *magics*, are commands for controlling IPython itself.
243 They all begin with ``%`` and are entered into code input cells. They are entered into standard code cells and executed as usual with :kbd:`Shift-Enter`.
236 They all begin with ``%`` and are entered into code input cells; the code cells are executed as usual with :kbd:`Shift-Enter`.
237
238 The magic commands call special functions defined by IPython which manipulate the computational state in certain ways.
244
239
245 There are two types of magics:
240 There are two types of magics:
246
241
247 **line magics**:
242 **line magics**:
248 These begin with a single ``%`` and take as arguments the rest of the *same line* of the code cell. Any other lines of the code cell are treated as a standard code cell.
243 These begin with a single ``%`` and take as arguments the rest of the *same line* of the code cell. Any other lines of the code cell are treated as if they were part of a standard code cell.
249
244
250 **cell magics**:
245 **cell magics**:
251 These begin with ``%%`` and operate on the *entire* remaining contents of the code cell.
246 These begin with ``%%`` and operate on the *entire* remaining contents of the code cell.
252
247
253 Line magics
248 Line magics
254 ˜˜˜˜˜˜˜˜˜˜˜
249 ~~~~~~~~~~~
255 Some of the available line magics are the following:
250 Some of the available line magics are the following:
256
251
257 * ``%load filename``:
252 * ``%load filename``:
@@ -263,30 +258,25 b' Some of the available line magics are the following:'
263 * ``%config``:
258 * ``%config``:
264 Configuration of the IPython Notebook
259 Configuration of the IPython Notebook
265
260
266 * ``%load_ext``:
267 Loads an *extension* of the IPython Notebook. Extensions provide extra functionality beyond that of the basic Notebook
268
269 * ``%lsmagic``:
261 * ``%lsmagic``:
270 Provides a list of all available magic commands
262 Provides a list of all available magic commands
271
263
272 Cell magics
264 Cell magics
273 ˜˜˜˜˜˜˜˜˜˜˜
265 ~~~~~~~~~~~
266
274 * ``%%latex``:
267 * ``%%latex``:
275 The entire contents of the cell is rendered in LaTeX, as in a Markdown cell but without needing LaTeX delimiters.
268 Renders the entire contents of the cell in LaTeX, without needing to use explicit LaTeX delimiters.
276
269
277 * ``%%bash``:
270 * ``%%bash``:
278 When the code cell is executed, its contents are sent to be executed by ``bash``.
271 The code cell is executed by sending it to be executed by ``bash``. The output of the ``bash`` commands is captured and displayed in the notebook.
279
272
280 * ``%%file filename``:
273 * ``%%file filename``:
281 Writes the contents of the cell to the file ``filename``.
274 Writes the contents of the cell to the file ``filename``.
282 **Caution**: The file is over-written!
275 **Caution**: The file is over-written without warning!
283
276
284 * ``%%R``:
277 * ``%%R``:
285 Execute the contents of the cell using the R language.
278 Execute the contents of the cell using the R language.
286
279
287 * ``%%cython``:
288 Execute the contents of the cell using ``Cython``.
289
290
280
291 Several of the cell magics provide functionality to manipulate the filesystem of a remote server to which you otherwise do not have access.
281 Several of the cell magics provide functionality to manipulate the filesystem of a remote server to which you otherwise do not have access.
292
282
@@ -307,9 +297,11 b' When the default ``%matplotlib`` or ``%pylab`` magics are used, the output of a '
307
297
308 %matplotlib inline
298 %matplotlib inline
309
299
310 or ``%pylab inline``.
300 or::
301
302 %pylab inline
311
303
312 These capture the output *inline* within the notebook format. This has the benefit that the resulting plots will also stored in the notebook document.
304 These instead capture the output of the plot and display it *inline* within the notebook format, below the input cell that produced it. The resulting plots will then also be stored in the notebook document.
313
305
314
306
315 Converting notebooks to other formats
307 Converting notebooks to other formats
@@ -320,9 +312,9 b' Currently, only a command line tool is provided; in the future, it will also be '
320
312
321 $ ipython nbconvert --format=FORMAT notebook.ipynb
313 $ ipython nbconvert --format=FORMAT notebook.ipynb
322
314
323 This will convert the IPython document file `notebook.ipynb` into the output format specified by the ``FORMAT`` string.
315 This will convert the IPython document file ``notebook.ipynb`` into the output format given by the ``FORMAT`` string.
324
316
325 The default output format is HTML, for which the `--format`` modifier is not required::
317 The default output format is HTML, for which the `--format`` modifier is not actually required::
326
318
327 $ ipython nbconvert notebook.ipynb
319 $ ipython nbconvert notebook.ipynb
328
320
@@ -348,7 +340,7 b' The currently supported export formats are the following:'
348 The format for Sphinx manuals; similar to a `book`` in LaTeX
340 The format for Sphinx manuals; similar to a `book`` in LaTeX
349
341
350 - ``latex``:
342 - ``latex``:
351 LaTeX article
343 An article formatted completely using LaTeX
352
344
353 * Markup:
345 * Markup:
354
346
@@ -362,9 +354,9 b' The currently supported export formats are the following:'
362
354
363 Comments out all the non-Python code to produce a standard Python ``.py`` script with just the code content.
355 Comments out all the non-Python code to produce a standard Python ``.py`` script with just the code content.
364
356
365 The files output by `nbconvert` are currently placed in a new subdirectory called ``nbconvert_build``.
357 The files output by ``nbconvert` are currently placed in a new subdirectory called ``nbconvert_build``.
366
358
367 The PDF options produce a root LaTeX ``.tex`` file with the same name as the notebook, as well as individual files for each figure, and `.text` files with textual output from running code cells; all of these files are located together in the ``nbconvert_build`` subdirectory.
359 Each of the options for PDF export produces as an intermediate step a root LaTeX ``.tex`` file with the same name as the notebook, as well as individual files for each figure, and ``.text` files with textual output from running code cells; all of these files are located together in the ``nbconvert_build`` subdirectory.
368
360
369 To actually produce the final PDF file, change into the ``nbconvert_build`` directory and run the following command::
361 To actually produce the final PDF file, change into the ``nbconvert_build`` directory and run the following command::
370
362
@@ -378,18 +370,19 b' Alternatively, the output may be piped to standard output, ``stdout``, with::'
378
370
379 $ ipython nbconvert mynotebook.ipynb --stdout
371 $ ipython nbconvert mynotebook.ipynb --stdout
380
372
381 Multiple notebooks can be specified at the command line::
373 Multiple notebooks can be specified from the command line::
382
374
383 $ ipython nbconvert notebook*.ipynb
375 $ ipython nbconvert notebook*.ipynb
384 $ ipython nbconvert notebook1.ipynb notebook2.ipynb
376 $ ipython nbconvert notebook1.ipynb notebook2.ipynb
385
377
386 or via a list in a configuration file, say ``mycfg.py``, containing the text::
378 or via a list in a configuration file, say ``mycfg.py``, containing the text::
387
379
380 c = get_config()
388 c.NbConvertApp.notebooks = ["notebook1.ipynb", "notebook2.ipynb"]
381 c.NbConvertApp.notebooks = ["notebook1.ipynb", "notebook2.ipynb"]
389
382
390 and using the command::
383 and using the command::
391
384
392 > ipython nbconvert --config mycfg.py
385 $ ipython nbconvert --config mycfg.py
393
386
394
387
395 Configuring the IPython Notebook
388 Configuring the IPython Notebook
@@ -415,19 +408,19 b' To create a new set of default configuration files, with lots of information on '
415
408
416 Extracting standard Python files from notebooks
409 Extracting standard Python files from notebooks
417 -----------------------------------------------
410 -----------------------------------------------
418 ``.ipynb`` notebook document files are plain text files which store a representation in JSON format of the contents of a notebook space. As such, it is not a valid ``.py`` Python script, and so can be neither ``import``ed in Python, nor executed as a standard Python script.
411 ``.ipynb`` notebook document files are plain text files which store a representation in JSON format of the contents of a notebook space. As such, it is not a valid ``.py`` Python script, and so can be neither imported with
412 ``import`` in Python, nor run as a standard Python script.
419
413
420 To extract just the Python code from within a notebook document, one option is to use ``ipython nbconvert``, as described above.
414 To extract just the Python code from within a notebook document, one option is to use ``ipython nbconvert``, as described above.
421
415 An alternative is to pass an argument to the IPython Notebook, from the moment when it is originally started, specifying that whenever it saves an ``.ipynb`` notebook document, it should, at the same time, save the corresponding standard ``.py`` script. To do so, you can execute the following command::
422 An alternative is to run the IPython Notebook, specifying that whenever it saves an ``.ipynb`` notebook document, at the same time it should save the corresponding standard ``.py`` script. To do so, you can execute the following command::
423
416
424 ipython notebook --script
417 ipython notebook --script
425
418
426 or you can set this option permanently in your configuration file with::
419 or you can set this option permanently in your configuration file with::
420 c = get_config()
421 c.NotebookManager.save_script=True
427
422
428 c.NotebookManager.save_script=True
423 The result is that standard ``.py`` files are also now generated, and so they can be ``%run``, imported from regular IPython sessions or other notebooks, or executed at the command line, as usual. Since the raw code you have typed is exported you must avoid using syntax such as IPython magics and other IPython-specific extensions to the language for the files to be able to be successfully imported.
429
430 The result is that standard ``.py`` files are also now generated, and so they can be ``%run``, imported from regular IPython sessions or other notebooks, or executed at the command line, as usual. Since we export the raw code you have typed, for these files to be importable from other code, you will have to avoid using syntax such as IPython magics and other IPython-specific extensions to the language.
431
424
432 In normal Python practice, the standard way to differentiate importable code in a Python script from the "executable" part of a script is to use the following idiom at the start of the executable part of the code::
425 In normal Python practice, the standard way to differentiate importable code in a Python script from the "executable" part of a script is to use the following idiom at the start of the executable part of the code::
433
426
@@ -474,6 +467,7 b' hashed password using the function :func:`IPython.lib.security.passwd`:'
474 You can then add this to your :file:`ipython_notebook_config.py`, e.g.::
467 You can then add this to your :file:`ipython_notebook_config.py`, e.g.::
475
468
476 # Password to use for web authentication
469 # Password to use for web authentication
470 c = get_config()
477 c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
471 c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
478
472
479 When using a password, it is a good idea to also use SSL, so that your password
473 When using a password, it is a good idea to also use SSL, so that your password
@@ -513,11 +507,11 b' how to connect to each kernel, with messages such as the following::'
513 This long string is the name of a JSON file that contains all the port and
507 This long string is the name of a JSON file that contains all the port and
514 validation information necessary to connect to the kernel. You can then, for example, manually start a Qt console connected to the *same* kernel with::
508 validation information necessary to connect to the kernel. You can then, for example, manually start a Qt console connected to the *same* kernel with::
515
509
516 ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
510 $ ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
517
511
518 If you have only a single kernel running, simply typing::
512 If you have only a single kernel running, simply typing::
519
513
520 ipython qtconsole --existing
514 $ ipython qtconsole --existing
521
515
522 will automatically find it. (It will always find the most recently
516 will automatically find it. (It will always find the most recently
523 started kernel if there is more than one.) You can also request this
517 started kernel if there is more than one.) You can also request this
@@ -531,9 +525,9 b' Running a public notebook server'
531 If you want to access your notebook server remotely via a web browser,
525 If you want to access your notebook server remotely via a web browser,
532 you can do the following.
526 you can do the following.
533
527
534 Start by creating a certificate file and a hashed password, as explained above. Then, create a custom profile for the notebook: at the command line, type::
528 Start by creating a certificate file and a hashed password, as explained above. Then create a custom profile for the notebook, with the following command line, type::
535
529
536 ipython profile create nbserver
530 $ ipython profile create nbserver
537
531
538 In the profile directory just created, edit the file ``ipython_notebook_config.py``. By default, the file has all fields commented; the minimum set you need to uncomment and edit is the following::
532 In the profile directory just created, edit the file ``ipython_notebook_config.py``. By default, the file has all fields commented; the minimum set you need to uncomment and edit is the following::
539
533
@@ -558,9 +552,8 b' Running with a different URL prefix'
558
552
559 The notebook dashboard (the landing page with an overview
553 The notebook dashboard (the landing page with an overview
560 of the notebooks in your working directory) typically lives at the URL
554 of the notebooks in your working directory) typically lives at the URL
561 ``http://localhost:8888/``. If you want to have it, and the rest of the
555 ``http://localhost:8888/``. If you prefer that it lives, together with the rest of the notebook, under a sub-directory,
562 notebook, live under a sub-directory,
556 e.g. ``http://localhost:8888/ipython/``, you can do so with
563 e.g. ``http://localhost:8888/ipython/``d, you can do so with
564 configuration options like the following (see above for instructions about
557 configuration options like the following (see above for instructions about
565 modifying ``ipython_notebook_config.py``)::
558 modifying ``ipython_notebook_config.py``)::
566
559
@@ -588,8 +581,8 b' your notebooks.'
588
581
589 .. _notebook_format:
582 .. _notebook_format:
590
583
591 JSON format of notebook document files
584 Notebook JSON file format
592 --------------------------------------
585 -------------------------
593 Notebook documents are JSON files with an ``.ipynb`` extension, formatted
586 Notebook documents are JSON files with an ``.ipynb`` extension, formatted
594 as legibly as possible with minimal extra indentation and cell content broken
587 as legibly as possible with minimal extra indentation and cell content broken
595 across lines to make them reasonably friendly to use in version-control
588 across lines to make them reasonably friendly to use in version-control
@@ -600,18 +593,18 b' file meant only to be edited by the IPython Notebook app itself, not for hand-ed'
600
593
601 .. note::
594 .. note::
602
595
603 Binary data such as figures are also saved directly in the JSON file. This provides convenient single-file portability, but means that the files can be large; ``diff``s of binary data also are not very meaningful. Since the binary blobs are encoded in a single line, they affect only one line of the ``diff`` output, but they are typically very long lines. You can use the ``Cell | All Output | Clear`` menu option to remove all output from a notebook prior to committing it to version control, if this is a concdern.
596 Binary data such as figures are also saved directly in the JSON file. This provides convenient single-file portability, but means that the files can be large; a ``diff`` of binary data is also not very meaningful. Since the binary blobs are encoded in a single line, they affect only one line of the ``diff`` output, but they are typically very long lines. You can use the ``Cell | All Output | Clear`` menu option to remove all output from a notebook prior to committing it to version control, if this is a concern.
604
597
605 The notebook server can also generate a pure Python version of your notebook,
598 The notebook server can also generate a pure Python version of your notebook,
606 using the ``File | Download as`` menu option. The resulting ``.py`` file will
599 using the ``File | Download as`` menu option. The resulting ``.py`` file will
607 contain all the code cells from your notebook verbatim, and all text cells
600 contain all the code cells from your notebook verbatim, and all Markdown cells
608 prepended with a comment marker. The separation between code and text
601 prepended with a comment marker. The separation between code and Markdown
609 cells is indicated with special comments and there is a header indicating the
602 cells is indicated with special comments and there is a header indicating the
610 format version. All output is removed when exporting to Python.
603 format version. All output is removed when exporting to Python.
611
604
612 As an example, consider a simple notebook called ``simple.ipynb`` which contains one Markdown cell, with the content ``The simplest notebook.``, one code input cell with the content ``print Hello, IPython!``, and the corresopnding output.
605 As an example, consider a simple notebook called ``simple.ipynb`` which contains one Markdown cell, with the content ``The simplest notebook.``, one code input cell with the content ``print "Hello, IPython!"``, and the corresponding output.
613
606
614 The contents of ``simple.ipynb`` is the following JSON container::
607 The contents of the notebook document ``simple.ipynb`` is the following JSON container::
615
608
616 {
609 {
617 "metadata": {
610 "metadata": {
@@ -662,6 +655,8 b' The corresponding Python script is::'
662
655
663 print "Hello, IPython"
656 print "Hello, IPython"
664
657
658 Note that indeed the output of the code cell, which is present in the JSON container, has been removed in the ``.py`` script.
659
665
660
666 Known issues
661 Known issues
667 ------------
662 ------------
General Comments 0
You need to be logged in to leave comments. Login now