Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable line wrapping in ipython notebook

I have been trying to enable line wrapping in ipython notebook. I googled it with no results and i typed ipython notebook --help in a terminal. This gives me a ton of configuration commands for a config file, but no line wrapping. Does anyone know if ipnotebook has this feature and if so how to enable it? Your help would be greatly appreciated. Thank you.

like image 904
dr3311 Avatar asked Dec 19 '13 02:12

dr3311


People also ask

How do I enable line numbers in Jupyter Notebook?

Enable row numbers via hotkeys You can enable row numbers in all code cells by pressing Shift + L while no cell is active. If you cannot remember these hotkeys, open the command palette by pressing Control + Shift + P and search for 'line numbers'.

How do you show lines in Jupyter lab?

In a code cell in the Jupyter notebook, line numbers may be turned on by typing ESC-L.

How do you insert a horizontal line in a Jupyter Notebook?

If you would like to display some code or text in an indented block, all you have to do is to start the line with a > followed by a space and then the text. The text is indented and has a gray horizontal line to the left until the next carriage return is detected.

What is %% capture in Jupyter Notebook?

IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. from __future__ import print_function import sys. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.


1 Answers

As @Matt pointed out you have to configure CodeMirror to enable wrapping.

However, this can be achieved by simply adding the following line to your custom.js:

 IPython.Cell.options_default.cm_config.lineWrapping = true;

So there is no need to loop through all the cells. In a similar fashion you can enable line numbers, set the indentation depth and so on (see the link posted by @Matt for other options). The location of your custom.js depends on your OS (on my Ubuntu machine it is ~/.ipython/profile_default/static/custom).

Update:

In IPython 3 the plain call does not work any more, thus it is required to place the setting within an appropriate event handler. A possible solution could look like:

define([
    'base/js/namespace',
    'base/js/events'
    ],
    function(IPython, events) {
        events.on("app_initialized.NotebookApp",
            function () {
                IPython.Cell.options_default.cm_config.lineWrapping = true;
            }
        );
    }
);
like image 180
Jakob Avatar answered Sep 20 '22 06:09

Jakob