Leftriver
Leftriver

Reputation: 97

How to change the font in Markdown cells when they are in Edit Mode?

I want to change the font type in Markdown cells when I am editing them. How Can I do that?

I can edit the file .jupyter/custom/custom.css and change the font when they are "run":

div.text_cell_render {
    font-family: 'Linux Libertine O';
    font-size: 12pt;
}

As shown in the figure, the upper half is a Markdown cell in edit mode, and that is the place where I want to change the font. example

Upvotes: 1

Views: 6472

Answers (1)

gboffi
gboffi

Reputation: 25023

A simple possibility is

from IPython.display import HTML, display
display(HTML('<style>.CodeMirror{font-family:whatever}</style>')

but beware that the code above changes also the fonts used for

  1. editing cells of code
  2. rendered code cells

Also note, that my simple proposal works on a notebook by notebook base, you have to add the lines to every notebook you want to modify. On the contrary, if you have a custom.css file where it can be accessed by jupiter during startup you can add the font-family:whatever to it, to make the customization hold for every notebook that you are using.

For an example of permanent customization please have a look at this question from Joel Ostblom — in a nutshell, edit ~/.jupyter/custom/custom.css and put in it

.CodeMirror pre {
    font-family: "Ubuntu Mono", monospace;
    font-size: 14pt;
    ...
}

Upvotes: 2

Related Questions