Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make new cells in ipython notebook markdown by default?

Currently, whenever you create a new cell in an iPython notebook, it defaults to a opening up a cell for Python code. I can then change it to markdown by hitting the keyboard shortcut ctrl m m

Is there any method or any setting I can tweak so that new cells default to being in "markdown mode"?

I did find this question which appears to ask the same thing, but it was erroneously flagged as a duplicate and wasn't answered.

like image 769
Michael0x2a Avatar asked Oct 09 '13 00:10

Michael0x2a


People also ask

How do you create a markdown cell in Jupyter Notebook?

Create New Cells You can change the cell type of any cell in Jupyter Notebook using the Toolbar. The default cell type is Code. To use the Keyboard Shortcuts, hit the esc key. After that, you can change a cell to Markdown by hitting the m key, or you can change a cell to Code by hitting the y key.

How do you write a new line in markdown in a Jupyter Notebook?

Just add <br> where you would like to make the new line.

How do I set autofill in Jupyter Notebook?

Enable autocomplete feature To enable code autocomplete in Jupyter Notebook or JupyterLab, you just need to hit the Tab key while writing code. Jupyter will suggest a few completion options. Navigate to the one you want with the arrow keys, and hit Enter to choose the suggestion.


1 Answers

I was just reading the IPython notebook js code, and found the insert_cell_below method at https://github.com/ipython/ipython/blob/master/IPython/html/static/notebook/js/notebook.js#L849 .

If you want to do this programatically, it would simply be a case of doing something like:

from IPython.display import display, Javascript

def markdown_below():
    display(Javascript("""
    IPython.notebook.insert_cell_below('markdown')
    """));

markdown_below()

This would be fairly early to turn into a button on the toolbar in a similar way to the gist button in https://github.com/minrk/ipython_extensions.

HTH

like image 142
pelson Avatar answered Sep 27 '22 21:09

pelson