patat icon indicating copy to clipboard operation
patat copied to clipboard

Decide what code blocks to execute

Open iliocatallo opened this issue 3 years ago • 2 comments

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.

iliocatallo avatar Jul 02 '21 06:07 iliocatallo

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!

jaspervdj avatar Jul 02 '21 09:07 jaspervdj

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!

iliocatallo avatar Jul 03 '21 15:07 iliocatallo

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.

jaspervdj avatar Sep 25 '23 08:09 jaspervdj