Include external snipset into JupyterLab Desktop

How can an external Marktdown .md or LaTex .tex file be included/embeded and made visible into a notebook of JupyterLab Desktop, so not to compose some snipsets again (but just “call” these)?

If it is only one direction once, then this post basically covers how.

Example steps assuming you have your markdown stored in markdown_file.md:

  1. Run %load markdown_file.md.
  2. Delete the first line that will now be commented and change the cell type from code to markdown.

You could make your own custom magic command to modify that process further or automate it better.

If you want to be able to update as the included markdown template may change and could act on saved notebooks externally, you could incorporate cell tags in the metadata of the markdown to be replaced, and then automate the appropriate replacements with nbformat. Since the tags would stay in the metadata, you could then run the code again to place the new version of the markdown text. Here was using nbformat to make notebooks for a completely different reason, however, the code may give you ideas on how to script this for yourself.

Other ideas: