Skip to content

(Re-)consider allowing cells inside other directives and content. #143

@akhmerov

Description

@akhmerov

One of the project goals is to allow generation of notebooks, based on the input files. IIUC, this is the main reason why cell directives are only allowed at the highest level, and if they aren't, the doctree is manipulated by bringing the cells to the lowest doctree level. However, as the project matures, more and more content requires breaking this pattern. A simple example of that is displaying a cell inside an admonition:

```{warning} This cell was hidden with the toggle class
this will raise an error

```{code-cell}
raise RuntimeError
```

```

This pattern, however, is much more common. The most recent release recommends including execution outputs inside a tabbed directive by using glue. This, while partially achieving the goal, makes the source nonlocal (the code producing the output is located at a different place, and only referenced from where it is used), and also does not allow the user to show the input that generates the output, unlike the code-cell directive.


This brings me to glue.

glue aims to do two things:

  • Allow reusing outputs
  • Allow showing outputs where the notebook structure doesn't allow them to occur.

I have no opinion about the former, but the latter is once again forcing the same suboptimal pattern of separating input and output. Compare the myst and Rmarkdown examples of inserting a computed value in text.

```{code-cell}
:tags: [remove-cell]
from myst_nb import glue
glue("max_velocity", compute_max_velocity())
```

`<rest of the paragraph>`
Using these assumptions we compute the maximal airplane velocity as {glue:}`max_velocity`,
however this still requires that the approximations stay valid.
`<rest of the paragraph>`

versus

`<rest of the paragraph>`
Using the above assumptions we compute the maximal airplane velocity as `r max_velocity()`,
however this still requires that the approximations stay valid.
`<rest of the paragraph>`

Overall I think that, already as we discussed earlier, the constraint of 1-1 correspondence to a notebook format is limiting or inconveniencing the content creators, and I think the practice shows that this limitation does not go away as the content becomes more complex.

Hence my proposal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions