英文:
Create Two Versions of a Document
问题
I am using quarto to create a lesson with lots of mixed in tex. I want two version of this lesson -- one with answers and one without the answers -- in the same document to avoid trying to keep the two files consistent. What is the easiest way to do this?
I tried
Will only appear in HTML.
::: ```
but that only seems to be working if I want to change the document output format. I want it to toggle with just a TRUE or FALSE value. I also tried
``~```
```{r, eval = showText, echo = TRUE, output = "asis"} The probability that $n^2$ items happy is `dpois(n, 1)`.
~
However, this gives me the error
Error: unexpected symbol in "The probability"
Furthermore, it doesn't render the latex $n^2$
UPDATE: I tried the Lua filter approach without success.
---
title: "Conditional Content"
format: pdf
editor: visual
hide-answer: false
filters:
- hide-answer.lua
---
## Answer Test
- This is a list
- This $n^2$ works
- This is another element
- **Question:** What is my name?
``` ::: answer
- Why is this $n^2$ failing?
::: ```
- Continuation
英文:
I am using quarto to create a lesson with lots of mixed in tex. I want two version of this lesson -- one with answers and one without the answers -- in the same document to avoid trying to keep the two files consistent. What is the easiest way to do this?
I tried
::: {.content-visible XXX}
Will only appear in HTML.
:::
but that only seems to be working if I want to change the document output format. I want it to toggle with just a TRUE or FALSE value. I also tried
```{r, eval = showText, echo = TRUE, output = "asis"}
The probability that $n^2$ items happy is `dpois(n, 1)`.
```
However, this gives me the error
Error: unexpected symbol in "The probability"
Furthermore, it doesn't render the latex $n^2$
UPDATE: I tried the Lua filter approach without success.
---
title: "Conditional Content"
format: pdf
editor: visual
hide-answer: false
filters:
- hide-answer.lua
---
## Answer Test
- This is a list
- This $n^2$ works
- This is another element
- **Question:** What is my name?
::: answer
- Why is this $n^2$ failing?
:::
- Continuation
答案1
得分: 1
您可以使用Lua过滤器来创建一个选项,如果设置为true,将删除answer
div内的所有内容。
---
title: Conditional content
format: pdf
hide-answer: true
filters:
- hide-answer.lua
---
## Part 01
**Question 01: What is the probability that .... ?**
::: answer
The probability that $n^2$ items happy is `dpois(n, 1)`.
:::
hide-answer.lua
function answer()
return {
Div = function(el)
if el.classes:includes('answer') then
return pandoc.Null()
else
return el
end
end
}
end
function Pandoc(doc)
local meta = doc.meta
local hide = meta['hide-answer']
if hide then
return doc:walk(answer())
end
end
当hide-answer: true
时的输出如下:
当hide-answer: false
时的输出如下:
<details>
<summary>英文:</summary>
You can use [Lua filter](https://quarto.org/docs/extensions/lua.html) to create an option which if true, will remove all the contents within `answer` divs.
~~~
---
title: Conditional content
format: pdf
hide-answer: true
filters:
- hide-answer.lua
---
## Part 01
**Question 01: What is the probability that .... ?**
::: answer
The probability that $n^2$ items happy is `dpois(n, 1)`.
:::
~~~
**hide-answer.lua**
~~~
function answer()
return {
Div = function(el)
if el.classes:includes('answer') then
return pandoc.Null()
else
return el
end
end
}
end
function Pandoc(doc)
local meta = doc.meta
local hide = meta['hide-answer']
if hide then
return doc:walk(answer())
end
end
~~~
output when `hide-answer: true`,
[![output without answer][1]][1]
<hr>
output when `hide-answer: false`,
[![output with answer][2]][2]
[1]: https://i.stack.imgur.com/5K5DY.png
[2]: https://i.stack.imgur.com/wloNf.png
</details>
# 答案2
**得分**: 0
我目前正在尝试做同样的事情,正在探索使用配置文件的方法。 https://quarto.org/docs/projects/profiles.html
我很想提供更完整的答案,但只是想分享一下。我正在为学生(没有答案)和助教(有答案)创建一个配置文件。
如果有任何专家有进一步的建议,请随时提出!
最好的祝愿!
<details>
<summary>英文:</summary>
I’m trying to do the same at the moment and am exploring the use of profiles. https://quarto.org/docs/projects/profiles.html
I’d love to give a more complete answer, but just wanted to share that. I’m creating a profile for student (without answers) and TA (with answers).
If any experts have further advice, please feel free!
Best wishes!
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论