Skip to content

Add explanation on conditional code execution #1731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/authoring/conditional.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ You can also set conditions on non-executable code blocks:
```
````

When using the `knitr` engine, if you want to have a code chunk being excecuted/evaluated only when the output is being rendered to HTML or LaTeX you can use the `is_html_output()` and `is_latex_output()` respectively (see [this reply to quarto-cli issue 11724](https://github.com/quarto-dev/quarto-cli/issues/11724#issuecomment-2557635192)).

```` markdown
``` {r .content-visible when-format="html"}
#| eval = !expr knitr::is_html_output()
# code is shown AND evaluated only in HTML
2+2
```
````

To apply a condition only to a part of a paragraph, use a span (`[]{}`):

``` markdown
Expand Down