带有 R-Exams 的 Moodle 问题表的不同副本 [英] Different copies of question with table for Moodle with R-Exams

查看:54
本文介绍了带有 R-Exams 的 Moodle 问题表的不同副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用随机生成的数据生成问题的多个副本,以便上传到 Moodle 并进行测验.这个问题将包括一个取决于每次生成的数据的表格.如何才能做到这一点?我尝试使用 xtable 但它在上传到 Moodle 时生成了一个没有边距和格式的表格.我也尝试过 ggpubr,但无法包含表格.

I would like to generate several copies of a question with randomly generated data in order to upload to Moodle and make a quiz. This question would include a table which depends on the data generated each time. How can this be done? I tried using xtable but it generates a table with no margins and format when uploaded to Moodle. I also tried ggpubr but it was not possible to include the table.

我读到可以生成一个.png",例如,使用include_supplement"和\includegraphics for .Rnw 文件被导入到文件中.这在只生成一份副本时很有用,因为只有一个文件是导入的文件.但是,当必须一次创建具有不同数据的问题的多个副本时会发生什么?

I read that one can generate a '.png', for example, and using 'include_supplement' and \includegraphics for .Rnw the file is imported into the file. This is useful when only one copy is generated because only one file would be the one imported. But what happens when multiple copies of the question with different data have to be created at once?

任何帮助将不胜感激.谢谢.

Any help would be appreciated. Thank you.

推荐答案

概览

表格格式对于 Moodle 来说并不是那么简单,无论是从 R/LaTeX 格式(Rnw,就像你做的那样)或 R/Markdown 格式(Rmd)的练习开始.下面我展示了您可以做的一些变化,尽管我对所有这些都不是 100% 满意.在所有情况下,示例都是静态的,但可以在通常的"示例中变为动态的.方法是将随机数插入到相应的表中.如果您在使其中一个解决方案动态化时遇到问题,请告诉我.

Overview

Table formatting is not so straightforward for Moodle, both when starting from an exercise in R/LaTeX format (Rnw, as you do) or in R/Markdown format (Rmd). Below I'm showing a couple of variations of what you can do although I'm not 100% happy with all of them. In all cases the example is static but could be made dynamic in the "usual" way by inserting the random numbers into the respective tables. If you have problems with making one of the solutions dynamic, please let me know.

当您开始使用 Rnw 时,您通常会手动或通过诸如 xtableknitr::kable 之类的包生成一个 {tabular} 对象> 等.这些被转换为有效的 HTML 并导入到 Moodle 中,但不保留带有线条(水平和/或垂直)的格式.当从 Rmd 开始并使用简单的 Markdown 标记对表格进行编码时也是如此(再次手动或通过 knitr::kable 等).

When you are starting in Rnw you typically generate a {tabular} object either by hand or via packages like xtable or knitr::kable etc. These are converted to valid HTML and imported into Moodle but the formatting with lines (horizontal and/or vertical) is not preserved. The same is true when starting in Rmd and using plain Markdown markup to code the table (again by hand or via knitr::kable etc.).

示例:

Rnw:

\begin{question}
Consider the following table:

\begin{tabular}{lrr}
\hline
Name & Min & Max \\
\hline
Foo  & 0   & 1   \\
Bar  & 0   & 100 \\
\hline
\end{tabular}

What is the overall maximum?
\end{question}

\exname{Table}
\extype{num}
\exsolution{100}
\extol{0.01}

Rmd: 与上面类似,但简单的 Markdown 表格为:

Rmd: Would be similar to above but the table in plain Markdown as:

| Name | Min | Max |
|:-----|----:|----:|
| Foo  |   0 |   1 |
| Bar  |   0 | 100 |

其他一些学习管理系统(例如 OpenOLAT)在其 CSS 中提供了合适的表格类,以便我们可以将结果 HTML 中的

调整为
(其中 mytable" 类需要在 CSS 中提供).我在 Moodle 的问题编辑器中环顾了一下,但似乎不支持这种专用的 CSS 表格样式.如果有人对此有更多了解,我将不胜感激.

Some other learning management systems (like OpenOLAT for example) offer suitable table classes in their CSS so that we can tweak the <table> in the resulting HTML to <table class="mytable"> (where the "mytable" class would need to be provided in the CSS). I looked around a bit in Moodle's question editor but there doesn't seem to be support for such dedicated CSS table styles. If anyone knows more about this I would appreciate some pointers.

最好的替代方法可能是从 Rmd 开始,但您可以直接使用完整的 HTML,而不是在 Markdown 中编写表格.这为您手动设计单元格提供了广泛的可能性.还有各种软件包可以帮助您解决这个问题.下面我使用了 knitr::kablekableExtra::kable_styling 的组合.后者提供的选项比我在下面使用的选项多得多.

The best alternative to this is probably to start in Rmd but instead of writing the table in Markdown you can use full HTML directly. This gives you extensive possibilities for styling the cells by hand. There are also various packages that help you with this. Below I'm using a combination of knitr::kable and kableExtra::kable_styling. The latter offers many more options than those that I use below.

示例:

Rmd:

Question
========
Consider the following table:

```{r, echo = FALSE, results = "asis"}
d <- data.frame(
  Name = c("Foo", "Bar"),
  Min = c(0, 1),
  Max = c(0, 100)
)
kableExtra::kable_styling(
  knitr::kable(d, format = "html", booktabs = TRUE),
  bootstrap_options = "bordered", full_width = FALSE, position = "left")
```

What is the overall maximum?

Meta-information
================
exname: Table
extype: num
exsolution: 100
extol: 0.01

Rnw: 我想在 Rnw 练习中应该可以使用相同的技巧,即在 LaTeX 练习中包含 HTML,并在使用 pandoc 转换为 HTML 时保留它.但是,我没有设法找到合适的标志.所以这目前仅适用于 Rmd 练习.

Rnw: I guess the same trick should be possible in Rnw exercises, i.e., include HTML in the LaTeX exercise and preserve that when converting to HTML with pandoc. However, I didn't manage to find the right flag for that. So this currently works just from Rmd exercises.

您还可以使用 LaTeX 排版表格并使用 pdfLaTeX 进行渲染,然后将输出转换为 PNG 或 SVG.这由 exams 包中的 tex2image() 函数支持.这可以在 Rnw 和 Rmd 练习中使用,并且生成的图像必须包含在练习中.缺点是表格和主要问题之间的字体等不同(并且您必须在 tex2image() 中使用字体大小和分辨率).此外,这相对较慢,因为 pdfLaTeX 必须在每次使用这样的表格的练习上运行.

You can also typeset the table with LaTeX and use pdfLaTeX for rendering and then convert the output to PNG or SVG. This is supported by the tex2image() function in the exams package. This can be used in both Rnw and Rmd exercises and the resulting image has to be included in the exercise. The disadvantage is that the fonts etc. differ between the table and the main question (and you have to play with the fontsize and resolution in tex2image()). Moreover, this is relatively slow because pdfLaTeX has to be run on each exercise with such a table.

示例:

Rnw:

\begin{question}
Consider the following table:

<<echo=FALSE, results=hide>>=
tab <- '\\begin{tabular}{lrr}
\\hline
Name & Min & Max \\\\
\\hline
Foo  & 0   & 1   \\\\
Bar  & 0   & 100 \\\\
\\hline
\\end{tabular}'
tex2image(tab, name = "tab", dir = ".", pt = 8, resize = 250)
@
\includegraphics{tab.png}

What is the overall maximum?
\end{question}

\exname{Table}
\extype{num}
\exsolution{100}
\extol{0.01}

Rmd: 可以在 Rmd 中使用生成图像的相同代码块.只需将 \includegraphics 替换为相应的 ![]() Markdown.

Rmd: The same code chunk generating the image could be used in Rmd. Just the \includegraphics would need to be replace by the corresponding ![]() Markdown.

在 Moodle 中渲染表格的另一种选择是插入一个自定义样式表,其中包含要渲染的

的类.Kenji Sato 在他的博客中提供了一个工作示例:https://www.kenjisato.jp/en/post/2020/07/moodle-bordered-table/.我们计划将其与 exams2moodle() 中的几个典型类集成,以便不必在每个练习中手动插入 CSS.但是,我们还没有开始考虑这一点.

Yet another option to render the table in Moodle is to insert a custom stylesheet with a class for the <table class="..."> to be rendered. A worked example is provided by Kenji Sato in his blog at: https://www.kenjisato.jp/en/post/2020/07/moodle-bordered-table/. We plan to integrate this with a couple of typical classes in exams2moodle() so that the CSS does not have to be inserted in every exercise manually. However, we did not yet get round to impelement this.

这篇关于带有 R-Exams 的 Moodle 问题表的不同副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆