jupyter-book
jupyter-book copied to clipboard
Target-dependent cell tags
Describe the enhancement you'd like
We can use cell tags (remove-input/output for example) to control which cells are included in the rendered site. I use this feature quite a bit to sweep over complex figure construction code that isn't in any way necessary for the understanding the text.
For the problem described below, I think it might be helpful to have this behavior also applied conditionally on the build target, eg, remove-output-html or remove-output-latexpdf would only remove the cell's output when targeting HTML or latexpdf, respectively.
Does this solve a specific problem?
I'm now trying to expand my project to latex and PDF builds, and am running into the problem that not all media is supported by all build targets. For example, animations or audio widgets make sense in the HTML output, but not PDF. This ends up leaving gaps in the output document where the media objects would be.
What would be helpful is to have a way to supply alternate cells, say with static images to replace animations, that could be included only when building for a specific target. This way, the same notebook would generate both animation and static images, and each would be used in their appropriate context. (And yes, I'm willing to contort my prose around this quantum superposition of media types.)
What alternatives exist?
It might be possible to work around this by some kind of conditional use of glue, but I don't see it immediately.
Otherwise, I see no way to achieve this short of maintaining separate document trees.
Additional context
No response
Possibly relevant, I just discovered the .. only:: directive in sphinx. It's complementary to what I propose above, but could be used to achieve the same effect. Would it be possible to route a cell tag into an only directive for this purpose?
Hmmm - isn't this what MIME types are supposed to solve for? Shouldn't the output format be able to choose the mime value that suits it best? That could be another fix
I could see that working if it was just the media type, but I think it would be more helpful to also be able to apply it to cells in general. This would let you select out alternative figure captions / glue code for the different build targets (in my example).
I need this behavior, too! I have both animations that cannot be sent to the pdf and interactive tools that can't be rendered in pdf.
I would also love to see this behaviour. Building a PDF version of the book can't contain stuff like animations and interactive elements. I don't see any way to achieve this other than adding my own tags and pre-processing the Markdown files before building.