1

I want to load and use isotope package in my .Rnw file:

\exname{foo}
\extype{schoice}
\exsolution{0001}
\usepackage{isotope}
\begin{question}
  Foo \isotope[A][Z]{H}\ bar
  \begin{answerlist}
    \item a
    \item b
    \item c
    \item d
  \end{answerlist}
\end{question}

But when I render it into Moodle's XML (exams2moodle) the \isotope disappear and appears only Foo bar. I'm using MathML rendering.

How can I load and use correctly?

uzsolt
  • 5,832
  • 2
  • 20
  • 32

1 Answers1

1

This short answer is: There is no way (that I know of) of rendering the \isotope command using either MathML or MathJax. See also this discussion: How to use a LaTeX package with R/exams?

There are two possible workarounds:

Option 1

Compile the \isotope command using pdfLaTeX as usual, extract the image (e.g., in a SVG vector graphic), and embed it into the exercise is. All this can be done conveniently with the tex2image() function.

The advantage is that you can use the isotope package that you are used to. However, there is a number of disadvantages: The rendering is rather slow, especially if you need many such images.The scaling of the graphic might not match the scaling of the text, especially when zooming into the HTML. The kind of graphic you need will depend on the kind of output (HTML vs. PDF) etc.

Option 2

Rather than using a specialized package, mimic the output using standard LaTeX commands. In this case using the \sideset command from amsmath would be one option because the amsmath package is supported by MathJax (but not in the MathML converters). Disadvantage: The LaTeX code is slightly more cumbersome. Advantages: Very fast, can be scaled in the HTML, works also in PDF. Hence, I would recommend Option 2.

Example

Below is the adapted code of your foo.Rnw file. This can be rendered into HTML via:

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

This is the same converter that current versions of R/exams use in exams2moodle() as well.

<<echo=FALSE, results=hide>>=
tex2image("\\isotope[A][Z]{H}", packages = "isotope",
  name = "iso_AZH", format = "svg", dir = ".")
@

\begin{question}
Option 1: \includegraphics{iso_AZH.svg}

Option 2: $\sideset{_Z^A}{}H$
\begin{answerlist}
  \item a
  \item b
  \item c
  \item d
\end{answerlist}
\end{question}

\exname{foo}
\extype{schoice}
\exsolution{0001}
Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49
  • Oh, understand. And as I understand it's impossible to use almost every package directly. Do I think right? – uzsolt May 13 '20 at 20:05
  • Correct. At least there is no standard or simple way to do so with TtM or pandoc that I would be aware of. With sufficient determination you might be able to extend pandoc's capabilities by adding custom scripts but I wouldn't recommend going there. – Achim Zeileis May 13 '20 at 21:30
  • Thanks. I think in many cases the `option 1` would be the solution (create image). In this case `option 2`. – uzsolt May 14 '20 at 05:46
  • 1
    We included `tex2image()` in the package as the "last resort" when other options are not applicable. The most prominent case probably is including TikZ images for which a convenience interface `include_tikz()` is available (calling `tex2image()` in the background). Examples are available in the "logic" and "automaton" exercises in R/exams. – Achim Zeileis May 14 '20 at 07:59