Search code examples
latexr-markdownr-exams

Tables in R-markdown not shown in Moodle - exams2moodle


I have a serious problem with rendering tables in Moodle once I upload the Moodle XML file generated by R-exams package to Moodle. I am using exercise files in .Rmd format handed to me from a previous professor's assistant. These .Rmd files contain lots of tables using Latex language. Once I upload the Moodle XML file, all of these tables are simply missing. I have tried to look up a solution, but could not find anything helpful on this.

Interestingly, these tables are rendered properly into PDF when using "exams2pdf" command in R-studio. However, when using "exams2moodle", these tables are simply not shown in Moodle.

I am showing an example of the table in one of these .Rmd files below:

enter image description here

I would appreciate if anyone could provide any guidance, as I got really stuck with this issue.


Solution

  • TL;DR: The problem is that you mix an exercise in Markdown format with LaTeX content. This only works if the rendering goes via LaTeX (see below for details). Instead you could convert your question from R/Markdown (.Rmd) to R/LaTeX (.Rnw) - or convert the formatting of the table from LaTeX to Markdown. Both would be feasible in this case. If you need help with this, please share (a link to) the code for the exercise and not just a screenshot of parts of it.

    Hint: If you're using at least version 2.4-0 of exams, exams2moodle() gained an argument table where you can set a class for formatting the table a bit more nicely, e.g., table = "table_shade" or "table_rule" or "table_grid".

    Details: You have a question in R/Markdown format which contains a table in LaTeX format. When you use exams2pdf() this works because rendering works in the following steps:

    1. knit R/Markdown to Markdown (preserving the LaTeX table).
    2. Convert Markdown to LaTeX via pandoc (preserving the LaTeX table).
    3. Render LaTeX (including the table) to PDF using texi2pdf or latexmk.

    Thus, it is crucial that you do a rendering step from LaTeX to the output format. This is not the case though for exams2moodle() or other engines based on HTML output. The steps are just:

    1. knit R/Markdown to Markdown (preserving the LaTeX table).
    2. Convert Markdown to HTML via pandoc (which does not know how to render the LaTeX table and hence drops it).
    3. Embed HTML in XML for Moodle.

    Thus, the problem is that there is no rendering or transformation step from LaTeX in this case. The same would be true if you had R/Markdown exercises with HTML content. These could be rendered with exams2moodle() because the HTML would just need to be preserved - but not with exams2pdf() because the HTML would not be converted to LaTeX.