Forum: support

Monitor Forum | Start New Thread Start New Thread
RE: Equations in moodle [ reply ]
By: Achim Zeileis on 2017-03-23 11:05
Justin, if you install the devel version of "exams" from R-Forge then you should be able to use \url{file.csv} also with converter = "pandoc-mathjax". I have tweaked the pandoc conversion so that internally \href{file.csv}{\texttt{file.csv}} is used instead of \url{file.csv}.

RE: Equations in moodle [ reply ]
By: Justin Wishart on 2017-02-23 11:39
Hi Achim,

That resolves the issue. The amended file compiles flawlessly. Thanks again.

RE: Equations in moodle [ reply ]
By: Achim Zeileis on 2017-02-23 10:12

forum.Rnw (1) downloads
OK, I think I got it now. The results=tex wasn't the only thing I had changed in your forum.Rnw exercise but hadn't realized it. I also replaced \texttt{\url{tmp.csv}} with just \url{tmp.csv} because I thought that was sufficient. However, while the tth/ttm converter interprets \url{} as hyperlink+typewriter, pandoc does not. For reasons that I explain in more detail below (if you're interested), the better workaround for pandoc is \href{tmp.csv}{\texttt{tmp.csv}}. See also the attached updated forum.Rnw. Could you please check whether this resolves the problem on your end? (Alternatively, you could also accept that \url{tmp.csv} does not add typewriter markup when using pandoc, of course.)

I've also added a fix in exams2moodle() that avoids the error in case of \texttt{\url{...}}. However, while this yields a valid .xml file, this does not embed the .csv file. The reason is the following:

In tth/ttm \url{tmp.csv} is transformed to <a href="tmp.csv"><tt>tmp.csv</tt></a>, thus there is hyperlinking _and_ typewriter markup. In pandoc, however, the <tt> markup is omitted for some reason.

Switching to \texttt{\url{tmp.csv}} yields in tth/ttm <tt><a href="tmp.csv"><tt>tmp.csv</tt></a></tt>, i.e., has the <tt> markup twice which is unnecessary but still leads to the desired output. In pandoc, however, this gets transformed to <code>tmp.csv</code>, i.e., loses the hyperlink!

Only \href{tmp.csv}{\texttt{tmp.csv}} leads to the same desired output in both tth/ttm and pandoc.

The error in exams2moodle() occured because it saw that there was tmp.csv (without quotes) and then tried to replace "tmp.csv" (with quotes) which didn't exist. This has been unified now.

Or in other words, tth/ttm treat \url{...} like \href{...}{\texttt{...}} while pandoc only uses \href{...}{...}. But what is even worse: if you use \texttt{\url{...}}

RE: Equations in moodle [ reply ]
By: Justin Wishart on 2017-02-23 06:58
I still get the error with results = tex or results = verbatim in the Rnw file. The sessionInfo() is the same as before and using the development version of exams package from R-forge repository. The error disappears if I comment out the line creating the hyperlink to the csv file.

I have migrated to Rmd which compiles flawlessly with no errors but thought I should mention.

Thanks for providing the solution of the converter = "pandoc-mathjax" regardless :)

RE: Equations in moodle [ reply ]
By: Achim Zeileis on 2017-02-21 07:31
OK, thanks for the report. The issue seems to be that you used "results=verbatim" rather than "results=tex" for the code chunk that creates the answerlist. This still creates the answerlist but also an empty verbatim code chunk that some systems do not like. While the ttm and plain pandoc converters can deal with it both pandoc-mathjax but also exams2pdf choke on it. Simply setting "results=tex" appears to work for all of them.

RE: Equations in moodle [ reply ]
By: Justin Wishart on 2017-02-21 02:49

forum.Rnw (3) downloads
Hi Achim,

I was able to compile the fourfold and boxhist examples and they work great.

I've been able to further isolate the issue. It seems to occur for the cloze type of questions (no error using a Rnw file for schoice question type).

On both the latest CRAN and development R Forge exams package I get the error when using converter = "pandoc-mathjax" on an Rnw file that uses a cloze question with an embedded data file.

Attached is a minimal reproducible example.

> exams2moodle("forum.Rnw")

compiles without error.

> exams2moodle("forum.Rnw", converter = "pandoc-mathjax")

produces the same error as before with the append issue.

My sessionInfo is as follows.

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] exams_2.2-1

loaded via a namespace (and not attached):
[1] backports_1.0.5 magrittr_1.5 rprojroot_1.2 htmltools_0.3.5 tools_3.3.2 base64enc_0.1-3
[7] Rcpp_0.12.9 stringi_1.1.2 rmarkdown_1.3 tth_4.3-2-1 knitr_1.15.1 stringr_1.1.0
[13] digest_0.6.12 evaluate_0.10

RE: Equations in moodle [ reply ]
By: Achim Zeileis on 2017-02-16 22:47
Justin, thanks for digging into this. However, I couldn't reproduce the problem you indicated. This may either be due to your myfile.Rnw or the exams version you are using, I guess. Could you please try to install the latest devel version here from R-Forge:

install.packages("exams", repos = "")

If the problems persist after that, please post your myfile.Rnw here in the forum by attaching it to your message. Also, in that case, please also include the output of sessionInfo() on your machine.

Also, I looked up what needs to be done for the ##ANSWER1## placeholders in Markdown: You simply have to escape the hashtags, i.e., use \#\#ANSWER1\#\#. Then everything works as intended.

I have just added two examples for this to the devel version of the package here on CRAN. If you have installed it (see above), you can do

exams2moodle(c("fourfold2.Rmd", "boxhist2.Rmd"))

I have also tried adding converter="pandoc-mathjax" which for me worked without problem and also the import into Moodle looked very nice.

RE: Equations in moodle [ reply ]
By: Justin Wishart on 2017-02-16 02:44
I tried using the pandoc-mathjax convertor on the Rnw file and it throws an error. It seems to fail during one of the append statements in the code.

e.g. using

> exams2moodle("myfile.Rnw")

compiles flawlessly.

However, using the pandoc convertor.

> exams2moodle("myfile.Rnw", converter = "pandoc-mathjax")

throws this error.

Error in if (!after) c(values, x) else if (after >= lengx) c(x, values) else c(x[1L:after], :
argument is of length zero

The same error occurs on "pandoc-jsmath" and "pandoc" too. After doing a traceback, there seems to be an error when using pandoc when the source file has a pluginfile (embedded csv in my case). If it helps, it seems idx isnt properly initialised (set to integer(0)) which causes problems to embed the pluginfile to question_xml. This is in the code chunk around line 122 of the exams2moodle source.

I'm not familiar with R-forge but I could put in a bug report with a reproduceable example if it helps.

Thanks again for your help.

RE: Equations in moodle [ reply ]
By: Achim Zeileis on 2017-02-15 11:31
The pandoc converter can be used with either .Rnw or .Rmd files. It's just that ttm is the default for .Rnw and pandoc is the default (and only) option for .Rmd. So you shouldn't have to switch from .Rnw to use the pandoc-mathjax feature, try

exams2html("tstat.Rnw", converter = "pandoc-mathjax", mathjax = TRUE)

As for the ##ANSWER1## problem: This is a good point and needs to be fixed. I'll try to have a look in due course.

RE: Equations in moodle [ reply ]
By: Justin Wishart on 2017-02-15 11:21
Thanks for the prompt reply. Using the modified converter = "pandoc-mathjax" seems to have done the trick very well.

This requires an rmarkdown source when before I was using the Sweave .Rnw so I could do a custom placement of the answers with the ##ANSWER1## syntax. However, this syntax seems to no longer be possible with the Rmd structure since it converts it to a html header. Is there an equivalent of ##ANSWERx## for the Rmd structure?

RE: Equations in moodle [ reply ]
By: Achim Zeileis on 2017-02-15 09:12
Yes, Chrome is notorious for not supporting MathML. Other major browsers do support it - notably Firefox, Safari, and Internet Explorer (with the MathPlayer plugin).

First, I thought that MathJax ought to be able to render the MathML as well. I.e., rather than letting the browser render the MathML you can ask the server to render it through the MathJax plugin. For illustration see:

exams2html("tstat", mathjax = TRUE)

The only difference between the HTML files (apart from our random number generation) is that the latter output HTML also loads the MathJax plugin. But both rely on MathML. However, my reading of the Moodle documentation is that this option is not supported in Moodle? This seems to be weird though and I guess it should work.

Alternatively, one can use a different converter, namely "pandoc" with conversion for "mathjax":

exams2html("tstat", converter = "pandoc-mathjax")

As you see this also works in plain HTML but I haven't tried whether Moodle's MathJax filter covers this situation.

RE: Equations in moodle [ reply ]
By: Justin Wishart on 2017-02-15 03:05
Sorry for digging up an old thread. I am a new user and have been creating some quizzes to implement on moodle. The exams2moodle function has been great and a great credit to all the authors. To make the quizzes better, I'd like the quizzes to have mathematical symbols embedded in the question and answers.

Since the MathML rendering is device dependent (works on Firefox but not chrome as discussed earlier), I investigated suggestion of using of Mathjax on moodle. The moodle server can render the mathjax server side by using tags as shown here,

However any calls using the exams2moodle automatically convert any tex code into HTML. I was wondering if there is anyway to protect the mathematical tex code and prevent it from being converted to HTML so the moodle server can render the tex code itself with mathjax.

e.g. In the source file I have,

"[tex]\mu[/tex] or [tex]\\mu[/tex]"

After a call using exams2moodle this gets converted to

"[tex] [/tex] or [tex]<br /> mu[/tex]"

Or more spefically, line 167 of the xexams package. (driver$transform) is the point where the unintended conversion occurs.

Thanks again for creating this great package.

RE: Equations in moodle [ reply ]
By: Achim Zeileis on 2014-10-24 06:40
Yes, Chrome had briefly enabled support for MathML but then abandoned it again due to instabilities.

In principle it should be possible to install MathJax on the Moodle server so that the MathML rendering is done by the server rather than the browser of the client. But I never tried this...

RE: Equations in moodle [ reply ]
By: samara kiihl on 2014-10-24 01:27
Firefox it looks great, thanks! Chrome has issues.

RE: Equations in moodle [ reply ]
By: Achim Zeileis on 2014-10-23 07:23
Hmm, the MathML formulas should be at least as pretty as images if viewed with the right browser. Did you use Firefox for accessing Moodle?

A very nice browser test is available at It shows images produced by LaTeX+MikTeX and MathML+Firefox (which both look very much alike) and the MathML rendering of your browser.

Firefox and Safari have support for MathML while Chrome does not, see The Internet Explorer can be enhanced using the MathPlayer plugin

Equations in moodle [ reply ]
By: samara kiihl on 2014-10-22 22:59
Is there a way to make the equations using LateX prettier when uploaded to Moodle? Maybe saving as figures? Any tips are greatly appreciated.

Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge