diff --git a/docs/source/interactive/htmlnotebook.txt b/docs/source/interactive/htmlnotebook.txt index 501d3a7..9652076 100644 --- a/docs/source/interactive/htmlnotebook.txt +++ b/docs/source/interactive/htmlnotebook.txt @@ -1,8 +1,8 @@ .. _htmlnotebook: -========================= -An HTML Notebook IPython -========================= +==================== +The IPython Notebook +==================== .. seealso:: @@ -10,37 +10,50 @@ An HTML Notebook IPython The IPython Notebook consists of two related components: -* An JSON based Notebook document format for recording and distributing - Python code and rich text. -* A web-based user interface for authoring and running notebook documents. +* A web application for interactive authoring of literate computations, combining explanatory text, mathematics, computations and rich media output. Input and output are stored in persistent cells that may be edited in-place. + +* Notebook documents for recording and distributing + the results. + + +Features of the IPython Notebook web app +---------------------------------------- + +Some of the main +features of the IPython Notebook app include: + +* Display rich data representations (e.g. HTML / LaTeX / SVG) in the browser as a result of computations. +* Compose text cells using Markdown and HTML. +* Include mathematical equations, rendered directly in the browser by MathJax. +* Import standard Python scripts +* In-browser editing, syntax highlighting, tab completion and autoindentation. +* Inline figures rendered by the ``matplotlib`` library with publication quality, in a range of formats (SVG / PDF / PNG). + +If you have ever used the Mathematica or SAGE notebooks (the latter is also +web-based__) you should feel right at home. If you have not, you will be +able to learn how to use it in just a few minutes. + +.. __: http://sagenb.org + -The Notebook can be used by starting the Notebook server with the -command:: - $ ipython notebook -Note that by default, the notebook doesn't load pylab, it's just a normal -IPython session like any other. If you want pylab support, you must use:: - - $ ipython notebook --pylab -which will behave similar to the terminal and Qt console versions, using your -default matplotlib backend and providing floating interactive plot windows. If -you want inline figures, you must manually select the ``inline`` backend:: +Notebook documents +------------------ - $ ipython notebook --pylab inline +Notebook documents, or *notebooks*, are files which record all computations carried out and the results obtained in a literate way, including inputs, outputs, toegether with descriptive text and mathematics. -This server uses the same ZeroMQ-based two process kernel architecture as -the QT Console as well Tornado for serving HTTP/S requests. Some of the main -features of the Notebook include: +They are plain text files, which are thus easy to share with colleagues and place under version control. But, by using the +JSON format, they can record all aspects of the computation, including embedding rich media output. +The standard file extension for notebook documents is ``.ipynb``. + +Notebooks may easily be exported to a range of static formats, including HTML (for example, for blog posts), PDF and slide shows. +Furthermore, any publicly +available notebook may be shared via the `IPython Notebook Viewer +`_ service, which will provide it as a static web +page. The results may thus be shared without having to install anything. -* Display rich data (png/html/latex/svg) in the browser as a result of - computations. -* Compose text cells using HTML and Markdown. -* Import and export notebook documents in range of formats (.ipynb, .py). -* In browser syntax highlighting, tab completion and autoindentation. -* Inline matplotlib plots that can be stored in Notebook documents and opened - later. See :ref:`our installation documentation ` for directions on how to install the notebook and its dependencies. @@ -49,93 +62,74 @@ how to install the notebook and its dependencies. You can start more than one notebook server at the same time, if you want to work on notebooks in different directories. By default the first notebook - server starts in port 8888, later notebooks search for random ports near + server starts on port 8888, and later notebook servers search for ports near that one. You can also manually specify the port with the ``--port`` option. -Basic Usage -=========== +Starting the IPython Notebook web app +===================================== -The landing page of the notebook server application, which we call the IPython -Notebook *dashboard*, shows the notebooks currently available in the directory -in which the application was started, and allows you to create new notebooks. +The Notebook web app can be started with the command:: -A notebook is a combination of two things: + $ ipython notebook -1. An interactive session connected to an IPython kernel, controlled by a web - application that can send input to the console and display many types of - output (text, graphics, mathematics and more). This is the same kernel used - by the :ref:`Qt console `, but in this case the web console sends - input in persistent cells that you can edit in-place instead of the - vertically scrolling terminal style used by the Qt console. +The landing page of the notebook server application, the *dashboard*, shows the notebooks currently available in the working directory (the directory from which the notebook was started). +You can create new notebooks from the dashboard with the ``New Notebook`` +button, or open existing ones by clicking on their name. -2. A document that can save the inputs and outputs of the session as well as - additional text that accompanies the code but is not meant for execution. - In this way, notebook files serve as a complete computational record of a - session including explanatory text and mathematics, code and resulting - figures. These documents are internally JSON files and are saved with the - ``.ipynb`` extension. -If you have ever used the Mathematica or Sage notebooks (the latter is also -web-based__) you should feel right at home. If you have not, you should be -able to learn how to use it in just a few minutes. +You can also drag and drop into the area listing files any ``.py`` +file: it will be imported into a notebook with the same name (but +``.ipynb`` extension), located in the working directory. This notebook will consist of a single cell with all the code in the file, which you can later manually partition into individual cells for gradual execution, and add text +and graphics, etc. +Alternatively, +prior to import, you can manually add ``# 2`` +markers at the start and then add separators for text/code cells, to get a cleaner import with the file already broken into individual cells. -.. __: http://sagenb.org +The IPython Notebook web app is based on a server-client structure. +This server uses a two-process kernel architecture based on ZeroMQ, as well as Tornado for serving HTTP requests. Other clients may connect to the same underlying IPython kernel. -Creating and editing notebooks ------------------------------- -You can create new notebooks from the dashboard with the ``New Notebook`` -button or open existing ones by clicking on their name. Once in a notebook, -your browser tab will reflect the name of that notebook (prefixed with "IPy:"). -The URL for that notebook is not meant to be human-readable and is *not* -persistent across invocations of the notebook server. -You can also drag and drop into the area listing files any python file: it -will be imported into a notebook with the same name (but ``.ipynb`` extension) -located in the directory where the notebook server was started. This notebook -will consist of a single cell with all the code in the file, which you can -later manually partition into individual cells for gradual execution, add text -and graphics, etc. +Basic workflow +------------------------ -Workflow and limitations ------------------------- +Once in a notebook, your browser tab will reflect the name of that notebook (prefixed with "IPy"). +The URL for that notebook is currently not meant to be human-readable and is not persistent across invocations of the notebook server; however, this will change soon. + +The normal workflow in a notebook is quite similar to a normal IPython +session, with the difference that you can edit a cell in-place multiple +times until you obtain the desired resultsj, rather than having to +rerun separate scripts with the ``%run`` magic (though magics also work +in the notebook). Typically you'll work on a problem in pieces, +organizing related pieces into cells and moving forward as previous +parts work correctly. This is much more convenient for interactive exploration than breaking up a computation into scripts that must be +executed together, especially if parts of them take a long time to run + +The only significant limitation that the notebook currently has, compared to the qt console, is that it can not 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! This limitation will +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. +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``), you can just type ``%qtconsole`` in the notebook and a Qt console will open up, connected to that same kernel. + + +Connecting to an existing kernel +--------------------------------- -The normal workflow in a notebook is quite similar to a normal IPython session, -with the difference that you can edit a cell in-place multiple times until you -obtain the desired results rather than having to rerun separate scripts with -the ``%run`` magic (though magics also work in the notebook). Typically -you'll work on a problem in pieces, organizing related pieces into cells and -moving forward as previous parts work correctly. This is much more convenient -for interactive exploration than breaking up a computation into scripts that -must be executed together, especially if parts of them take a long time to run -(In the traditional terminal-based IPython, you can use tricks with namespaces -and ``%run -i`` to achieve this capability, but we think the notebook is a more -natural solution for that kind of problem). - -The only significant limitation the notebook currently has, compared to the qt -console, is that it can not 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* work in the notebook! We intend to -correct this limitation, 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. 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), you can just type ``%qtconsole`` in the notebook and a Qt console -will open up connected to that same kernel. - -In general, the notebook server prints the full details of how to connect to -each kernel at the terminal, with lines like:: +The notebook server always prints to the terminal the full details of +how to connect to each kernel, with lines like:: [IPKernelApp] To connect another client to this kernel, use: [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json -This is the name of a JSON file that contains all the port and validation -information necessary to connect to the kernel. You can manually start a -qt console with:: +This is the name of a JSON file that contains all the port and +validation information necessary to connect to the kernel. You can +manually start a Qt console with:: ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json @@ -143,10 +137,10 @@ and if you only have a single kernel running, simply typing:: ipython qtconsole --existing -will automatically find it (it will always find the most recently started -kernel if there is more than one). You can also request this connection data -by typing ``%connect_info``; this will print the same file information as well -as the content of the JSON data structure it contains. +will automatically find it (it will always find the most recently +started kernel if there is more than one). You can also request this +connection data by typing ``%connect_info``; this will print the same +file information as well as the content of the JSON data structure it contains. Text input @@ -181,12 +175,6 @@ in the `Download` drop list. This removes all output and saves the text cells in comment areas. See ref:`below ` for more details on the notebook format. -The notebook can also *import* ``.py`` files as notebooks, by dragging and -dropping the file into the notebook dashboard file list area. By default, the -entire contents of the file will be loaded into a single code cell. But if -prior to import, you manually add the ``# 2`` marker at -the start and then add separators for text/code cells, you can get a cleaner -import with the file broken into individual cells. .. warning::