patat
patat copied to clipboard
Decide what code blocks to execute
Hello there,
I was wondering if there is a way to decide what code blocks to execute. From time to time I just want to show again a piece of code that was presented (and executed) earlier in the presentation, so running it again is not really necessary.
Thank you, Ilio.
That's a great question @iliocatallo!
You can do this using Pandoc's fenced code blocks. These allow you to set more than one attribute on code blocks, so you can have the language (for highlighting) and an additional identifier (for evaluation).
Here is some more information about this syntax: https://pandoc.org/MANUAL.html#extension-fenced_code_attributes
And here is an example:
---
patat:
eval:
python_eval:
command: python
...
# Slide 1
This is evaluated:
~~~~~{.python .python_eval}
print("Hello, world")
~~~~~
# Slide 1
This is not evaluated:
~~~~~{.python}
print("Hello, world")
~~~~~
Hope this helps!
Hi @jaspervdj,
It works perfectly, thank you. On a similar note, would it be possible to have invisible code blocks that get executed together with the visible blocks on the slide? That might be useful when you are incrementally building some code and you get to a point where you want to just use some previous functions without showing their definitons every single time.
Thanks!
Invisible codeblocks are not currently supported (and I'm not sure if they ever will be, but maybe I can be convinced otherwise). If you want this, you can typically create some sort of "header file" and then include that in the command:
for eval
.