quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.76k stars 308 forks source link

.content-visible when-profile= ignored in version 1.3.115 #4006

Closed PeterReiter closed 1 year ago

PeterReiter commented 1 year ago

When rendering a file that includes conditional content e.g.:

---
title: "exerc"
---

::: {.content-visible when-profile="solutions"}
This content will only appear in the advanced version.
:::

The conditional content is not included in the output when rendered using quarto version 1.3.115. In version 1.2.313 everything works as expected.

quarto render exerc.qmd --profile solutions

System: Windows 10

cscheid commented 1 year ago

Thanks for the feedback! I can't seem to reproduce this on macOS:

image

@cderv can you test this on windows?

cderv commented 1 year ago

It works for me too on Windows using 1.3.115 and dev version.

cscheid commented 1 year ago

@PeterReiter We can't seem to reproduce your report. Is it possible that you have multiple versions of quarto installed, and you're inadvertently running an older version? In the generated HTML, there's a <meta generator ...></meta> tag. For example, in https://quarto.org, you'll see this in the source code:

<meta name="generator" content="quarto-1.3.115">

Can you confirm your output was generated with the quarto version you're expecting?

PeterReiter commented 1 year ago

@cscheid, @cderv Issue doesn't occur anymore, could have been an outdated version of deno?

cscheid commented 1 year ago

No, we bundle our own version of deno on each install and that wouldn't control the execution of the conditional content. I'm going to go ahead and close this. If it resurfaces reproducibly for you, please feel free to reopen!

giabaio commented 1 year ago

Can I quickly add a question to this? Can you use a profile to conditionally include a qmd file - something like

:::{.content-visible when-profile="solutions"}
{{< include _solutions.qmd >}}
:::

Would that work? Or is the profile only for written text (rather than macros or filters)?

cscheid commented 1 year ago

It works in the sense that the content will not be visible in profiles other than solutions. It doesn't work in the sense that if your _solutions.qmd includes executable code, that's still run by the engine.

To be more precise, the way .content-visible works is through a Lua filter which removes it from the document. But Lua filters run inside Pandoc, which happens after Knitr (or jupyter)

giabaio commented 1 year ago

Ah --- thanks.


Gianluca Baio Professor of Statistics and Health Economics | Head of Department

Department of Statistical Science | University College London 1-19 Torrington Place, London, WC1E 6BT, UK Twitter: @stats_uclhttps://twitter.com/stats_UCL | Instagram: @stats_UCLhttps://instagram.com/ucl.stats/

Telephone: +44(0)20 7679 1248 (internal: 41248) Website: http://www.homepages.ucl.ac.uk/~ucakgba Blog: https://gianluca.statistica.it/blog/ Book a meeting with me: https://book.morgen.so/gianlucabaio/book-me

@.***> [https://www.svgrepo.com/show/157815/twitter.svg] https://twitter.com/gianlubaio [https://www.svgrepo.com/show/138936/linkedin.svg] https://www.linkedin.com/in/gianluca-baio-b893879/ [https://www.svgrepo.com/show/341847/github.svg] https://github.com/giabaio [https://www.geol.umd.edu/styles/academicons-192/svg/arxiv.svg] https://arxiv.org/a/baio_g_1.html [https://www.geol.umd.edu/styles/academicons-192/svg/orcid.svg] https://orcid.org/0000-0003-4314-2570 [https://www.svgrepo.com/show/40973/soundcloud.svg] https://soundcloud.com/uclsound/sets/sample-space


For Head of Department correspondence, please use @.**@.>

[https://s1g.s3.amazonaws.com/3f32ef1962be41fb8943ee58d28cf3aa.png]

This email may reach you outside of your working hours. If that’s the case, please do not feel pressure to reply immediately.

On January 18, 2023 at 21:46 GMT, Carlos Scheidegger @.**@.>> wrote:

⚠ Caution: External sender

It works in the sense that the content will not be visible in profiles other than solutions. It doesn't work in the sense that if your _solutions.qmd includes executable code, that's still run by the engine.

To be more precise, the way .content-visible works is through a Lua filter which removes it from the document. But Lua filters run inside Pandoc, which happens after Knitr (or jupyter)

— Reply to this email directly, view it on GitHubhttps://github.com/quarto-dev/quarto-cli/issues/4006#issuecomment-1396128179, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACCRVSJNEZURKSNPJFFIBXTWTBP6HANCNFSM6AAAAAAT7HQUIE. You are receiving this because you commented.Message ID: @.***>

[https://bolt.im/t/?73vyZ6ksu_a6QrNLFB7T5oMH8tcQVSob8oT9MfoGFXxeP7zAs4uPIxgxs3wXaRW2qnFkrEGj7o-LzzZzbO3zbA]

giabaio commented 1 year ago

I think the solution I was looking for is something like

```{r child="_solutions1.qmd",eval=rmarkdown::metadata$params$solutions}
cscheid commented 1 year ago

That's neat, but unfortunately that is an RMarkdown-specific technique that's knitr-specific as well as a result.

cderv commented 1 year ago

@giabaio you don't need to rely on rmarkdown::metadata when using params. Quarto supports it: https://quarto.org/docs/computations/parameters.html

So such chunks should work

```{r}
#| eval: !expr params$solutions
#| child: _solutions.qmd

`params` could probably be define in your profile solutions YAML probably. (if we support parmas globally - IDR)

However, this indeed **knitr** specific because of `child` mainly. Python has support for params but we have currently no way to pass a value to `eval` chunk option in Quarto. 

@cscheid I feel this is a kind of usage that will be pretty common when working on teaching related document (like questions / solutions).  

Maybe we could think of ways of making `profiles` information supported for `eval` field - like 

| eval: {{ when-profile solutions }}

...


It would mean something like shortcode would need to be processed / replace in document with `true` or `false` before computation. 

Also this 
> To be more precise, the way .content-visible works is through a Lua filter which removes it from the document. But Lua filters run inside Pandoc, which happens after Knitr (or jupyter)

I wonder how safe it would be to use Lua filters to pre-process the document before computation for example. Like a `md -> md` conversion that would remove part of the document for example. 

Anyway, just take the opportunity to share LT ideas - This needs thinking and I don't know what are our plans on all this. I know we are working on passing informations between from / to Quarto to improve integration with computations code. 
giabaio commented 1 year ago

Thank you --- I knew, but completely forgot about this! And yes, I've tried and it just works to simply use the code you suggest (and actually is easier to then render with params...). I understand that the solution is not fit for all purposes (as you may not use R and only work with quarto or with other platforms) --- it just works beautifully for me, though (as I do use R...) :wink:

And yes, it is useful to be able to do so --- for instance, I prepare a single document in which I add the option to show or hide solutions (so when I'm passing variables to create my exam question is all propagated through) and with a single re-rendering I have the version to keep secret with all the worked out solution and the one I can share with students etc...

Thanks!

PeterReiter commented 1 year ago

I have quite the same usecase for, exams, assignments,....

For now my solutions is as follows:

Document:


title: "exerc"

::: {#exr-3}

Test

:::

::: {.content-visible when-profile="solutions"}

::: {.solution} The solution. :::

:::

::: {.content-visible when-profile="solutions"}

R

#| eval: false

ggplot(mpg, aes(x = hwy, y = cty, color = cyl)) +
  geom_point(alpha = 0.5, size = 2) +
  scale_color_viridis_c() +
  theme_minimal()

:::

::: {.content-visible when-profile="solutions"}

Python

#| eval: false

import numpy as np
a = np.arange(15).reshape(3, 5)
a

:::

and rendered using two different profiles.