View on GitHub

how-to-customize-title-of-jupyter-notebook

:tada: How to customize the web page title of all pages created with Jupyter Notebook :notebook:

“How to customize Jupyter notebooks document titles ?”

New tutorial :sparkles:

By using the latest features from Jupyter Notebook, you can use this script custom.js to perform this hack easily:

// custom.js script for Jupyter Notebook
// (C) Lilian Besson, 2018
// See https://github.com/Naereen/how-to-customize-title-of-jupyter-notebook/issues/1
// MIT License, https://lbesson.mit-license.org/

// Fourth solution, using deprecated __defineSetter__ method... simple and pretty!
document.__defineSetter__('title', function(val) {
    // document.title = val + " — Jupyter Notebook";   // WARNING Would be recursive!
    console.log("Setting window's title to:", val);
    document.querySelector('title').childNodes[0].nodeValue = val + " — Jupyter Notebook";
});

You can download this raw custom.js file and save it to ~/.jupyter/custom/custom.js (create the folder if needed):

mkdir -p ~/.jupyter/custom/
cd ~/.jupyter/custom/
wget https://github.com/Naereen/how-to-customize-title-of-jupyter-notebook/raw/master/custom.js
cat custom.js  # just check the content by yourself, never trust a stranger from Internet!
# relaunch Jupyter notebook!
See the difference (before, without “Jupyter Notebook” display in the window’s title after, with “Jupyter Notebook” in the title):

latest_demo.png


Previous tutorial

This small document is here to quickly and clearly explain how to do the following tweak for every page that the Jupyter application displays in your browser :

« How to ensure that the title of the web page (document.title in the DOM) finishes with " - Jupyter Notebook" ? »

These explanations were up-to date on May 12th of 2017, with Jupyter Notebook package at version 5.0.0.


The following explanations assume you have a local installation of Jupyter Notebook. If this is not the case, follow this tutorial.

Typically, this Python package will be installed in /usr/local/lib/python3.5/dist-packages/notebook/ on a Debian/Ubuntu machine, and probably on a similar location for Mac OS X, and you can figure it out on Windows. Let call that path PATH/.

First modification : HTML templates

Of course, if the line number don’t match, just search for the pattern, and edit on the first line that contains it !

Second modification : Javascript files

Cautious!

These changes have to be done again if you update (pip install --upgrade) Jupyter Notebook…


Demos ?

Here are some screenshots showing that these small modifications worked:

Editing a notebook : before and after

Editing a notebook : before and after

Home view : before and after

Home view : before and after


You can also see the useless PDF version of this webpage… If you want!

Questions

Bonus question : why would you want to do that ?

Interesting question : why writing a tutorial and not a Jupyter Notebook extension (nbextension) ?


:scroll: License ? GitHub license

MIT Licensed (file LICENSE). © Lilian Besson, 2017-18.

Maintenance Ask Me Anything ! Analytics

ForTheBadge built-with-swag

ForTheBadge uses-badges ForTheBadge uses-git