|
|
|
|
@ -122,8 +122,6 @@ and using the command::
|
|
|
|
|
$ ipython nbconvert --config mycfg.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _notebook_format:
|
|
|
|
|
|
|
|
|
|
LaTeX citations
|
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
|
@ -139,92 +137,3 @@ the nbconvert-examples_ repository.
|
|
|
|
|
|
|
|
|
|
.. _nbconvert-examples: https://github.com/ipython/nbconvert-examples
|
|
|
|
|
|
|
|
|
|
Notebook JSON file format
|
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
|
Notebook documents are JSON files with an ``.ipynb`` extension, formatted
|
|
|
|
|
as legibly as possible with minimal extra indentation and cell content broken
|
|
|
|
|
across lines to make them reasonably friendly to use in version-control
|
|
|
|
|
workflows. You should be very careful if you ever manually edit this JSON
|
|
|
|
|
data, as it is extremely easy to corrupt its internal structure and make the
|
|
|
|
|
file impossible to load. In general, you should consider the notebook as a
|
|
|
|
|
file meant only to be edited by the IPython Notebook app itself, not for
|
|
|
|
|
hand-editing.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
The notebook server can also generate a pure Python version of your notebook,
|
|
|
|
|
using the ``File | Download as`` menu option. The resulting ``.py`` file will
|
|
|
|
|
contain all the code cells from your notebook verbatim, and all Markdown cells
|
|
|
|
|
prepended with a comment marker. The separation between code and Markdown
|
|
|
|
|
cells is indicated with special comments and there is a header indicating the
|
|
|
|
|
format version. All output is removed when exporting to Python.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
The contents of the notebook document ``simple.ipynb`` is the following JSON
|
|
|
|
|
container::
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"metadata": {
|
|
|
|
|
"name": "simple"
|
|
|
|
|
},
|
|
|
|
|
"nbformat": 3,
|
|
|
|
|
"nbformat_minor": 0,
|
|
|
|
|
"worksheets": [
|
|
|
|
|
{
|
|
|
|
|
"cells": [
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"source": "The simplest notebook."
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"collapsed": false,
|
|
|
|
|
"input": "print \"Hello, IPython\"",
|
|
|
|
|
"language": "python",
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"stream": "stdout",
|
|
|
|
|
"text": "Hello, IPython\n"
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"prompt_number": 1
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"metadata": {}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The corresponding Python script is::
|
|
|
|
|
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
# <nbformat>3.0</nbformat>
|
|
|
|
|
|
|
|
|
|
# <markdowncell>
|
|
|
|
|
|
|
|
|
|
# The simplest notebook.
|
|
|
|
|
|
|
|
|
|
# <codecell>
|
|
|
|
|
|
|
|
|
|
print "Hello, IPython"
|
|
|
|
|
|
|
|
|
|
Note that indeed the output of the code cell, which is present in the JSON
|
|
|
|
|
container, has been removed in the ``.py`` script.
|
|
|
|
|
|