I want to use a notebook to perform calculations, and one or more markdown files to write a document where I am using figures and variables from the notebook. Matplotlib plots created in the notebook are embedded using the recipe in docs. However, I am not able to use the eval role to embed a variable from the notebook. Steps to reproduce the observed behaviour are shown below.
I am running on:
mystmd v1.3.11
windows
Description
Please find below three files that can be used to reproduce the observed behaviour: 1) requirements.txt, 2) calculations.ipynb, and 3) report.md.
requirements.txt
The Python environment can be created with the dependencies given in requirements.txt:
matplotlib
jupyter-server
ipykernel
calculations.ipynb
A notebook with the following cells. The first and last cells are markdown, the remaining cells are python.
---
title: Calculations
author: Name Nameson
exports:
- format: pdf
output: calculations.pdf
template: plain_latex
---
#| tags:
#| - remove-cell
import matplotlib.pyplot as plt
import numpy as np
The calculation result is {eval}`calculation_result`.
If I do a myst build calculations.ipynb --pdf --execute the variable is embedded as expected. ā
report.md
A markdown file with the following contents.
---
title: The report
author: Name Nameson
exports:
- format: pdf
output: report.pdf
template: plain_latex
kernelspec:
name: python3
display_name: venv
---
:::{figure} #fig-cos
:label: figure-from-nb
The `cos` function.
:::
The calculation result is {eval}`calculation_result`.
If I do a myst build report.md --pdf --execute the matplotlib figure from the notebook is embedded as expected, but the variable calculation_result cannot be embedded. š„
The following is printed in the terminal, possibly indicating that calculation_error cannot be found in the namespace available to report.md:
š¬ Performing exports:
report.md -> report.pdf
šæ Executing Notebook (report.md) [no execution cache found]
š¾ Adding Cached Notebook Outputs (calculations.ipynb)
š Built calculations.ipynb in 22 ms.
š Starting new Jupyter server
šŖ Jupyter server started
http://localhost:8888/?token=3ce1d702a24b5985ac5c53a9717a45c105d6b0eb03cfc90d
Starting WebSocket: ws://localhost:8888/api/kernels/d2db867b-6de2-4d70-9f6f-a91bb3566705
āļø report.md An exception occurred during expression evaluation, halting further execution:
NameError: name 'calculation_result' is not defined
š Built report.md in 3.15 s.
...
It would be extremely powerful to have the ability to embed variables like this in markdown files and not only notebooks š
I want to use a notebook to perform calculations, and one or more markdown files to write a document where I am using figures and variables from the notebook. Matplotlib plots created in the notebook are embedded using the recipe in docs. However, I am not able to use the
eval
role to embed a variable from the notebook. Steps to reproduce the observed behaviour are shown below.I am running on:
Description
Please find below three files that can be used to reproduce the observed behaviour: 1) requirements.txt, 2) calculations.ipynb, and 3) report.md.
requirements.txt
The Python environment can be created with the dependencies given in
requirements.txt
:calculations.ipynb
A notebook with the following cells. The first and last cells are markdown, the remaining cells are python.
If I do a
myst build calculations.ipynb --pdf --execute
the variable is embedded as expected. āreport.md
A markdown file with the following contents.
If I do a
myst build report.md --pdf --execute
the matplotlib figure from the notebook is embedded as expected, but the variablecalculation_result
cannot be embedded. š„The following is printed in the terminal, possibly indicating that
calculation_error
cannot be found in the namespace available toreport.md
:It would be extremely powerful to have the ability to embed variables like this in markdown files and not only notebooks š