Package: jpconvert
JPConvertJPConvert is a preprocessor for Jupyter Notebooks. It may be used to split up Jupyter Notebooks based on macros,
automatically set options, embed images and remove unnecessary metadata.Quick StartInstall JPConvert:pipinstalljpconvertImagine two code cells inside your notebook:#jp-solutiona=a+1#jp-practicea=...If you call JPConvert with the--practiceoption, the first cell is removed and the second cell is kept:a=...If you call JPConvert with the--solutionoption, the first cell is kept and the second cell is removed:a=a+1SetupThe preferred way to use JPConvert is in a virtual environment:python-mvenvvenvsourcevenv/bin/activateUse pip to download and install JPConvert. JPConvert requiresrequestsandpython-magicto embed images via HTTP.
Both packages are installed automatically by pip.pipinstalljpconvertRun JPConvert as a Python module:python-mjpconvert<input>[<output>][<options>]Usage GuideMacros and Output TypesJPConvert provides several macros to mark cells for a specific task. Only code cells with the macro matching the output
options are kept.cli optiondescription--practice/-pkeep cells containing#jp-practice--teaching/-tkeep cells containing#jp-teaching--solution/-skeep cells containing#jp-solutionMultiple macros can be used per cell. Macros themselves are removed from the code cells.Instead of#you can also use--. The macros without any prefix can also be added as tags to individual cells.It is also possible to remove any cells without macros. Add--remove-without-macrosto the command line parameters
to activate this behavior.Empty Cells, Empty Lines, Trailing SpacesJPConvert automatically removestrailing spaces from lines,empty lines from the end of cells andempty cells.This behavior can be disabled using the command line parameters--no-strip-lines,--keep-trailingand--keep-empty.Readonly and UndeletableJPConvert automatically addsreadonlyandundeletableflags to any cells that do not contain#jp-practice. If you
want to protect the latter from writing as well, add#jp-readonlyor use#jp-practice-ro. Users may undo these
changes, but at least they cannot accidentally delete or modify cells.To disable this behavior, the command line parameters--no-force-readonlyand--no-set-undeletablecan be used.Table of ContentsA table of contents is automatically inserted into all cells that contain the macro#jp-toc. The entries are
automatically generated from headlines (lines starting with one or multiple#) in markdown cells. Each entry consists
of the title and a reference that leads directly to the anchor tag of the heading.Up to two conditionals can be added to control the table's depth. It uses the level of the heading (number of#) for
filtering. The following example shows how to create a table of contents from level 2 to 5.#jp-toc>=2<6Embedding ImagesImages can be embedded in markdown cells via the Jupyter user interface. JPConvert automatically embeds linked files
from both local disk and HTTP(S) sources, which simplifies notebook editing. Supported file types arepng,jpgandsvg.JPConvert also embeds files that are displayed using HTML tags. These provide the ability to scale graphics as desired,
while in markdown the size is determined only by the resolution.Add the command line parameter--no-embed-imagesto disable this behavior.Stripping Outputexecution_countis set toNoneandoutputis set to an empty array for each individual code cell. (Which is
basically the functionality ofnbstripout.)Add the command line parameter--keep-outputto disable this behavior.