feature: control conditional content with boolean metadata#5755
feature: control conditional content with boolean metadata#5755
Conversation
|
Exactly what I was looking for! But it doesn't seem to have been released? At least it doesn't work for me in 1.3.450. |
|
@allefeld This is a 1.4 feature - so you need 1.4.119 or above |
|
I'll wait for that to be released officially then. |
|
(I realize now that I forgot to add a 1.4 changelog entry for this. I apologize for the confusion) |
|
I use this feature to generate output for typesetting purposes for articles (where figures are omitted and replaced with messages like PLACE FIGURE 1 HERE). I found that omitting a figure using conditional formatting causes it to no longer work in cross-references (which is to be expected). However, I'm unable to define a second figure with the same ID for the reverse condition, since this leads to a "Duplicate chunk label". Any pointers as to what I could do? I'm fine with either behaviour, both having both at the same time is very confusing. Thanks! |
|
@AntheSevenants see about #5161 (comment) as it may help (defining the id once for difference content based on conditional) |
|
@cderv Thanks for your response! I played around with the syntax, and got it to work (somewhat). If I separate the figure ID and caption, the Figure label and caption appear separately: I can fix this by moving the figure caption into the div definition: However, now the caption still appears under "PLACE FIGURE 1 HERE", and ideally I'd have the caption not appear at all when meta- |
This could probably be possibly using only knitr and params for example. ( Disclaimer: Advanced usage only, and tied to knitr but still works - No quarto warranty whatsoever though. ---
title: "test"
format:
html: default
params:
manuscript: false
---
See this plot:
```{r}
#| eval: !expr params$manuscript
#| echo: false
#| label: fig-plot
#| fig-cap: Figure Caption
plot(cars)
```
```{asis, echo = !params$manuscript}
::: {#fig-plot}
**PLACE FIGURE 1 HERE**
:::
```
See @fig-plotIf you want the caption in both plot and placeholder, you may be looking for this syntax instead ---
title: "test"
format:
html: default
params:
manuscript: true
---
See this plot:
::: {#fig-plot}
```{r}
#| eval: !expr params$manuscript
#| echo: false
plot(cars)
```
```{asis, echo = !params$manuscript}
**PLACE FIGURE 1 HERE**
```
Figure Caption
:::
See @fig-plot
Some resources
Hope it helps as workaround until we try to improve pre-execution processing 🤔 |
This closes #5707.
cc @aronatkins, @dragonstyle, @jjallaire
Aron: the feature is intentionally quite narrow; we want to avoid things degenerating into a turing-complete expression language. This means each conditional block can only check the value of a single metadata entry, and only checks against
trueandfalsevalues.The included test document shows the syntax.
It's also worth noting that changing the metadata on a Lua filter currently will not work. This was on purpose, so that we can eventually do dependency analysis statically without having to run Pandoc.