Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change font in ipython notebook

I am fairly new to python and have no html experience. The question has been asked and either not answered at all or not answered in enough detail for me to set the default font within iPython (not change to browser). Specifically, what has to be put in the css file and which css file should be used? I am on a Windows system.

For reference, these are in answer to the linked SO questions below:

  • in #1: an unnamed file in /usr/lib/python2.6/.../css/
  • in comment to #1: change monospace font in browser - worked but font is italic
  • in #2: custom.css in profile subdirectory /static/custom/custom.css

Related questions:

  1. Change ipython notebook font type
  2. Change font & background color in ipython notebook
  3. Changing (back to default) font in ipython notebook (unanswered) -

Edit: Changing the monospace font in my browser worked, as suggested in an answer comment of #1. However the font is italic, which is not what is intended.

like image 343
cb4 Avatar asked Mar 13 '14 17:03

cb4


People also ask

How do I change the font in JupyterLab?

JupyterLab Extensions To change your default fonts, from the main menu, select Settings ▶ Fonts ▶ Code ▶ Font (or Size or Line Height) and the value you'd like.

How do I write text in IPython notebook?

Simply Enter Esc and type m it will convert to text cell.

How do I make my font bold in Jupyter Notebook?

Use the following code to emphasize text: Bold text: __string__ or **string** Italic text: _string_ or *string*


2 Answers

You can hover to .ipython folder (i.e. you can type $ ipython locate in your terminal/bash OR CMD.exe Prompt from your Anaconda Navigator to see where is your ipython is located)

Then, in .ipython, you will see profile_default directory which is the default one. This directory will have static/custom/custom.css file located.

You can now apply change to this custom.css file. There are a lot of styles in the custom.css file that you can use or search for. For example, you can see this link (which is my own customize custom.css file)

Basically, this custom.css file apply changes to your browser. You can use inspect elements in your ipython notebook to see which elements you want to change. Then, you can changes to the custom.css file. For example, you can add these chunk to change font in .CodeMirror pre to type Monaco

.CodeMirror pre {font-family: Monaco; font-size: 9pt;} 

Note that now for Jupyter notebook version >= 4.1, the custom css file is moved to ~/.jupyter/custom/custom.css instead.

like image 99
titipata Avatar answered Sep 17 '22 14:09

titipata


I would also suggest that you explore the options offered by the jupyter themer. For more modest interface changes you may be satisfied with running the syntax:

jupyter-themer [-c COLOR, --color COLOR]                       [-l LAYOUT, --layout LAYOUT]                       [-t TYPOGRAPHY, --typography TYPOGRAPHY] 

where the options offered by themer would provide you with a less onerous way of making some changes in to the look of Jupyter Notebook. Naturally, you may still to prefer edit the .css files if the changes you want to apply are elaborate.

like image 23
Konrad Avatar answered Sep 19 '22 14:09

Konrad