Python notebook tricks (Jupyter, nbconvert, Slideshow)

Tip #1: To generate slides (“Slideshow”) from your notebook:

  • View => Slideshow, then decide which cell is which Slide / Sub-slide (arrow down to see it) / Fragment (Enter to reveal; i.e. fragment of a Slide) / Skip
  • Then from command line: jupyter nbconvert my_slides.ipynb --to slides --post serve will generate an html file + serve it from local webserver (that also has reveal.js etc.).
  • There’s a ~bug with the zoom

    There’s a ~bug with the zoom. reveal.js takes control of the zoom, so you cannot e.g. adjust font size during Slideshow, whose default is too small.

    For anyone interested in a temporary fix to both issues (nicer initial font size + browser zoom functionality to affect the slides): You can hack the CSS of the `.slides` element in the page by adding the following code (=essentially one line of JS) to some(*) Markdown cell in your Slideshow notebook: <script> console.log("Hello. You'll see this printed in your browser's DevTools / Console. Feel free to delete this line."); document.querySelector('head').innerHTML += '<style>.slides { zoom: 1.0 !important; }</style>'; </script> (*)any cell which is not of type ‘Skip’; e.g. add it to some Markdown cell that you already intended to display in your Slideshow.

    Tip #2: Run notebook from command line using `nbconvert`

    C:\Temp>jupyter nbconvert --to notebook --execute C:\dev\python\JupyterLocal\MyStuff\Statistics.ipynb
    [NbConvertApp] Converting notebook C:\dev\python\JupyterLocal\MyStuff\Statistics.ipynb to notebook
    [NbConvertApp] Executing notebook with kernel: python2
    [NbConvertApp] Writing 4319 bytes to C:\dev\python\JupyterLocal\MyStuff\Statistics.nbconvert.ipynb

    Leave a Reply

    Your email address will not be published. Required fields are marked *