mystmd icon indicating copy to clipboard operation
mystmd copied to clipboard

Include variables inline

Open rmnldwg opened this issue 1 year ago • 4 comments

Proposal

It would be great if one could include computational output - stored either in a Jupyter notebook or a separate file - inline and formatted just as normal text.

Additional notes

It is already really great to be able to include figures from a notebook in a scientific article when using MyST. However, what's missing for me is to include results or variables inline with normal text.

E.g., when I write a manuscript like this

## Methods

We included ![](#num-patients) patients in our study. Their mean age was ![](#mean-age) years.

an I have the corresponding notebook cells, then I see this:

image

But I would like to include these numbers like so:

image

I have seen that there is the substitutions syntax in the MyST parser. Could this be used here as well to include data stored e.g. in a variables.yaml file?

Another solution would be to allow inline references of just the output of a cell, rendered as if it were normal text.

Thanks for looking into this!

rmnldwg avatar Dec 06 '23 10:12 rmnldwg

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] avatar Dec 06 '23 10:12 welcome[bot]

In the MyST ecosystem we have a couple of mechanisms for this; the substitutions syntax, which is not implemented in our myst-spec (that governs "official" features), and the eval syntax. The eval role (although not referenced anywhere on mystmd.org yet) will evaluate the embedded code fragment in the active kernel, and embed the result.

To use eval roles, you need to execute the notebook with jupyterlab-myst, and save the notebook. In future, we'll have tooling to do this as part of a myst build.

In an executable notebook, you can use the eval role as follows:


The sum of 1 and 2 is {eval}`1 + 2`.

c.f. https://mystmd.org/guide/quickstart-jupyter-lab-myst#inline-expressions

agoose77 avatar Jan 10 '24 14:01 agoose77

Thanks for your comment!

I am happy to hear that the myst-cli will include tooling to execute code cells in the future.

The eval role in executable notebooks is really neat and I have used that in the past. But since code cells in jupyter notebooks cannot be hidden at the moment, I can either have code and output in my paper or neither, right?

So, to rephrase my problem slightly: I would love to have a way of rendering computational output (inline) without rendering the code that generated the output (either because it's hidden or because it lives somewhere else).

Though, if I understand this roadmap correctly, that will come soon in the form of code-cells that can be hidden (a.k.a. toggle).

Anyways, sounds like this will be implemented in some form or another 👍🏻

rmnldwg avatar Jan 16 '24 10:01 rmnldwg

I looked through this issue and think it's actually a combination of several enhancement requests that could be tackled independently of one another, so I've opened up an issue for each:

  • https://github.com/executablebooks/mystmd/issues/1109
  • https://github.com/executablebooks/mystmd/issues/1107
  • https://github.com/executablebooks/mystmd/issues/1108

Dos that sound correct to others? If so, could we close this issue in favor of those more precise follow-up issues?

choldgraf avatar Apr 16 '24 19:04 choldgraf