PDF Generation and Filtering

Otter includes a tool for generating PDFs of notebooks that optionally incorporates notebook filtering for generating PDFs for manual grading. There are two options for exporting PDFs:

  • PDF via LaTeX: this uses nbconvert, pandoc, and LaTeX to generate PDFs from TeX files

  • PDF via HTML: this uses wkhtmltopdf and the Python packages pdfkit and PyPDF2 to generate PDFs from HTML files

Otter Export is used by Otter Assign to generate Gradescope PDF templates and solutions, in the Gradescope autograder to generate the PDFs of notebooks, by otter.Notebook to generate PDFs. and in Otter Grade when PDFs are requested.

Cell Filtering

Otter Export uses HTML comments in Markdown cells to perform cell filtering. Filtering is the default behavior of most exporter implementations, but not of the exporter itself.

You can place HTML comments in Markdown cells to capture everything in between them in the output. To start a filtering group, place the comment <!-- BEGIN QUESTION --> whereever you want to start exporting and place <!-- END QUESTION --> at the end of the filtering group. Everything capture between these comments will be exported, and everything outside them removed. You can have multiple filtering groups in a notebook. When using Otter Export, you can also optionally add page breaks after an <!-- END QUESTION --> by setting pagebreaks=True in otter.export.export_notebook or using the corresponding flags/arguments in whichever utility is calling Otter Export.

Otter Export Reference

Exports a Jupyter Notebook to PDF with optional filtering

usage: otter export [-h] [--filtering] [--pagebreaks] [-s] [-e [{latex,html}]]
                    source [dest]

Positional Arguments


Notebook to export


Path to write PDF

Named Arguments


Whether the PDF should be filtered


Whether the PDF should have pagebreaks between questions

-s, --save

Save intermediate file(s) as well

-e, --exporter

Possible choices: latex, html

Type of PDF exporter to use


Export in debug mode