Control code cell visibility and behavior with tags and metadata
choldgraf opened this issue · comments
Currently, all code cells that are parsed by MyST will include their input and outputs together.
Outputs can be inserted into the page via the {embed}
directive, which allows you to remove the input, output, or include both.
However it's not possible to modify the behavior of the code cell itself, which makes it clunky if you want the code cell to exist on the same page where you want to embed its output.
It would be helpful if there were a way to control the visibility of the cell input and cell output from within a code cell.
How MyST-NB handles this
MyST NB accomplishes this by using Cell Metadata tags, with tags like the following:
remove-cell
remove-input
remove-output
hide-input
(hides behind a toggle)hide-output
skip-execution
raises-exception
(to prevent errors from stopping the build process)
References
There was an initial PR on this in the theme over here:
- executablebooks/myst-theme#129
- Related issue: executablebooks/myst-theme#50
This was partially implemented here:
But I believe is undocumented on our side. I think at this stage, only the remove-cell/input/output
is respected (no toggles). The tags are listed here:
https://github.com/executablebooks/mystmd/blob/main/packages/myst-common/src/types.ts#L34
There was an initial PR on this in the theme over here:
- executablebooks/myst-theme#129
- Related issue: executablebooks/myst-theme#50
We got the first part merged, but not the theme as there were changes to thebe that we needed to consider.
Ah nice - I've added a PR to document some of this here:
Agreed that there's still functionality that needs to be added, so we can use this to flesh out the behavior. I've added your links to the top comment so that it's easier to track the progress
Sorry to bother you, but it seems remove-cell/input/output
tags are not respected for PDF output for native jupyter code cells. From looking at #407 it seems like it should work just as it does in Jupyter Book. It seems like #407 was merged at 1.0.2. I'm on 1.2.0. I'm not sure why its not working.
Edit: adding to this. I see your documentation on notebook cell visibility. I see no indication that this works. Or maybe I'm using it wrong. Could you please advise?
I am running into a similar issue (v1.2.3
), where remove-input
works, but hide-input
does not. Not sure if this is not implemented yet, but interestingly, it throws a warning when you pass both tags.