创建两个版本的文档

huangapple go评论49阅读模式
英文:

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(&#39;answer&#39;) then
       return pandoc.Null()
     else 
       return el
     end
   end
  }
end


function Pandoc(doc)
  local meta = doc.meta
  local hide = meta[&#39;hide-answer&#39;]
  if hide  then
    return doc:walk(answer())
  end
end
~~~

output when `hide-answer: true`,

[![output without answer][1]][1]

&lt;hr&gt;

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>



huangapple
  • 本文由 发表于 2023年2月14日 06:57:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75441964.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定