Search code examples
r-exams

How to scale SVG in R/Exams


I am struggling to scale an SVG file with R Exams using RStudio on Windows. I would appreciate any help. Here is the SVG file I am using:

https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/atom.svg

Here is a complete code:

<<echo=FALSE, results=hide>>=
include_supplement("atom.svg", recursive = TRUE)
@

\begin{question}
What is 2 + 1?

\includegraphics[scale = 0.1]{atom.svg}

\begin{answerlist}
\item 1
\item 2
\item 3
\end{answerlist}
\end{question}

\extype{schoice}
\exsolution{001}
\exshuffle{3}

Solution

  • As far as I can tell the scale=0.1 attribute is not supported by converter = "ttm" (the default for .Rnw exercises) nor by converter = "pandoc" or "pandoc-mathjax". However, the latter supports the width= attribute. So both of the following work correctly with pandoc:

    \includegraphics[width=0.5\textwidth]{atom.svg}
    

    or

    \includegraphics[width=4in]{atom.svg}
    

    For example, with the latter we get:

    exams2html("atom.Rnw", converter = "pandoc")
    

    Screenshot of the atom.Rnw exercise as rendered by exams2html with pandoc converter.