Export a notebook with no codeΒΆ


Sometimes, you just want to remove all codes from your report. You can just reasd the json of a notebook and remove all codes by yourself or you can add an extra preprocessor which removes all the code in a notebook. We do something similar to this example. First we create a preprocessor:

from nbconvert.preprocessors import Preprocessor

class LatexNoCodePreprocessor(Preprocessor):
    def preprocess_cell(self, cell, resources, cell_index):
        if cell.cell_type == 'code':
            if isinstance(cell.code, list):
                cell.source = []
                cell.source = ""
        return cell, resources

And then a configuration file config.py for nbconvert:

c = get_config()
c.Exporter.preprocessors = [

And finally the command line:

nbconvert --config config.py --to latex --template article <notebook.ipynb> --output <notebook.tex>

To avoid import issues, the command line must be run from the folder which contains config.py and custom_nbconvert_preprocessor.py.