Skip to content

Add inline short-hand for glue:any role #186

@choldgraf

Description

@choldgraf

Description

In RMarkdown, they have a short-hand for inserting the values of r code inline into the document: `r somevariable`. Right now, we'd accomplish the same thing with {glue:}`somekey` (after glueing it into the notebook).

I wonder if it would be helpful to think up a similar short-hand for variable insertion with MyST-NB. Some random ideas:

  • {{ somekey }}
  • `j somekey` (j for jupyter)
  • `g somekey` (g for glue)
  • {g}`somekey`

Benefit

This is an extremely commonly-requested feature in the Jupyter ecosystem, so it seems there is a large community of people that want this, particularly for scientific writing. For example, see these posts on SO, shared by @matthew-brett:

and this long-standing IPython issue where it is discussed:

ipython/ipython#2958

Implementation

I think we can split this into three different questions, and each could be tackled separately:

  1. Given the current Glue infrastructure, define a shorthand for glue:any. I think this could be resolved relatively quickly using MyST substitutions, as described here
  2. Allow for substitutions that didn't require a glue function to be called first - this would require collecting variables when the notebooks are run somehow, and would probably be a bigger amount of work.
  3. More broadly, how to substitute variables at run-time from within the kernel. This would be a much more significant re-write of how the execution logic works, and would also break from how Jupyter does execution.

cc @stefanv who mentioned this earlier

Metadata

Metadata

Assignees

No one assigned

    Labels

    🏷️ glueRelated to storing/pasting variables via glueenhancementNew feature or requestlong-termAn issue which will not be closed any time soon

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions