Closed 314a closed 2 months ago
Conditional content should not be mixed with cross-reference div. You have to nest the two.
---
title: "Conditional Solution Box"
solution: false
format: pdf
---
Show Solution: {{< meta solution >}}, see @exr-example and @sol-example.
::: {#exr-example}
Exercise to test conditional boxes using metadata variable `solution`.
:::
:::: {.content-visible when-meta="solution"}
::: {#sol-example}
Solution is visible if metadata element `solution: true`. (see @exr-example).
:::
::::
@mcanouil's suggestion should solve the problem. I'm going to go ahead and close this one.
While the nested approach works, it would be good that the behavior across cross references is consistent. Maybe this point is something to aid to the overhaul list for Crossref
Particularly, for exercise templates, it would be a nice feature to be able to conditionally turn solutions on/off with the reference to the exercise with cross-references. While this can be partly solved with custom .lua scripts, the appraoch with conditionals consistent in behaviour with the other crossref prefixes would be preferable.
Sorry, hard to understand what you are saying here. Are you saying, mixing conditional with some divs works? This might be a "lucky" result. Would you mind sharing code demonstrating the "inconsistency" you are mentioning?
Note that, as far as I know, there is nowhere in the documentation where conditional content is merged with other fenced divs.
Unfortunately, it's not because you have ::: {}
that you can merge those.
The structure matters.
::: {something}
::: {else}
whatever
:::
:::
is not and will not be equivalent to:
::: {something else}
whatever
:::
Even, if you found some cases where it works, you really should not consider this as the normal/default behaviour.
Particularly, for exercise templates, it would be a nice feature to be able to conditionally turn solutions on/off with the reference to the exercise with cross-references. While this can be partly solved with custom .lua scripts, the appraoch with conditionals consistent in behaviour with the other crossref prefixes would be preferable.
I suggest you go look in GitHub Discussions as this has already been discussed: https://github.com/quarto-dev/quarto-cli/discussions Also, you can look for existing extensions such as "assign": https://m.canouil.dev/quarto-extensions/
I tested it for all the reserved prefixes listed in Quarto Cross References. That's why I thought it was a feature, even if it's not explicitly documented.
It works for all the reserved prefixes if rendered to html. In the case of rendering to pdf, there's a nul pointer error for the prefixes #sol-
and #rem-
, the rest is rendered without any issue.
---
title: "Conditional Content Test"
solution: false
format: pdf
---
::: {#sol-example .content-visible when-meta="solution"}
Replacing #sol-example with #exm-example, #exr-example, #def-example, #thm-example .... works.
:::
I will look into the mentioned discussions.
Bug description
There seems to be a
main.lua
filter issue with conditional content for cross-ref#rem-
and#sol-
.Rendering a .qmd file with the following conditional (see below) and the metadata
solution: true
andsolution: false
works fine for html output. It fails withsolution: false
andformat: pdf
.My current workaround is splitting the divs into two, which way less elegant.
The problem only occurs for the prefix
#sol-
,#rem-
and not for any of the other reserved prefixes such as#exm
,#exr
,#rem
,#def
,#thm
.. (as listed in Quarto Cross References)Steps to reproduce
File: exercise.qmd Rendering the following file with
quarto render exercise.qmd
Expected behavior
A rendered pdf with a hidden
#sol-example
box.Actual behavior
Error message, when rendering the file to pdf:
Your environment
Quarto check output