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
:
- Run
%load markdown_file.md
. - Delete the first line that will now be commented and change the cell type from
code
tomarkdown
.
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:
- My answer to ’ How do I paste raw text into Jupyter Notebook and have it automatically detect markdown cells, and code cells?’
- pidgy involved markdown and templates and so may provide a way to do this?
- See about preprocessors mentioned here.
- ‘How to programmatically generate markdown output in Jupyter notebooks’ is more about how to mix code and markdown; however, the things there may give you an idea. For, myst is mentioned and there is MyST-NB that has a lot of abilities for making notebooks.