What is the correct way to insert and format non-executable code in Quarto?

490 views Asked by At

What is the correct way of integrating arbitrary code in Quarto? In my case, I have an Overpass API/Overpass QL example for extracting OpenStreetMap data.

Is there a way to integrate code cells as non-executable code chunks or are code cells generally reserved for executable code, meaning that another formatting has to be selected for non-executable code?

2

There are 2 answers

3
Quinton.Quagliano On

EDIT w/ Some Sugestions from @Fuhrmanator

If I am understanding correctly, you are looking for a way to have code inside the Quarto document that is not executed / not run. If that is correct, there is a fairly simple solution for this: using code chunk options allow you to customize the behavior of code in every chunk or at the document level. Or you can include code via a "default" language flag.

For an overview of this topic, see this part of the Quarto documentation.

At the beginning of each code chunk you are able to see options that effects that chunk visibility and execution. This is only applicable to the languages that Quarto can actually run. Take the below R chunk:

```r
#| eval: true # Do evaluate this chunk
#| echo: true # Do show this chunk in the final rendered document
#| output: true # Do show the output / results of this chunk in the rendered document

print("Dont run this code")
```

You can also include code in a stylized code block but it is not execute or ran, via normally markdown syntax. This can be helpful for code that cannot be executed in Quarto. Information on this can be found in this section of the above documentation. Format non-evaluated code blocks with "default" where the language name would normally go.

```default
This is pseduo code
  that is placed within a code block but not run {
    return test  
Arbitrary code that is styled like code but will not run
  }
```

See @Fuhrmanator's comment for a possible way to get syntax highlighting for your chosen language.

0
ncraig On

To show the code, but not execute, try the Fenced Echo.

enter image description here

Another approach to Unexectuted Blocks is the two curly braces around the language

enter image description here

Each will show the code block in the output document, but will not return the computation.