r-exams

exams2pdf breaks with url links?


In this RMD file ("q1.rmd"), I make a link using standard markdown syntax.

```{r data generation, echo = FALSE, results = "hide"}
knitr::opts_chunk$set(echo = FALSE)
options(scipen=100)
x = sample(1:6,10,TRUE)
```

Question
========

Find the [sample mean](https://en.wikipedia.org/wiki/Sample_mean_and_covariance#Definition_of_the_sample_mean).

`r x`


Solution
========

`r mean(x)`

Meta-information
========
extype: num
exsolution: `r mean(x)`
exname: find mean

I then run exams2pdf("q1.rmd") and I get the following error:

! Undefined control sequence. l.3 Find the \href {https://en.wikipedia.org/wiki/Sample_mean_and_covariance%5C%5C...

Error: LaTeX failed to compile plain1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See plain1.log for more info.

Is there potentially an easy solution to this? I have links in a lot of my questions, and this does not feel like it should break exams2pdf.


Solution

  • These kinds of hyperlinks need the LaTeX package {hyperref} which is not used in the default plain.tex LaTeX template used by exams2pdf(). Only the more lightweight {url} is included.

    So if you want to produce PDF output files you should set up your own LaTeX template which you also need for including header/footer and other styling of the document. You can start out by modifying the default plain.tex shipped with the package. Run exams_skeleton() or exams_skeleton(writer = "exams2pdf") to put copies of this (and other) files in your working directory.

    Then eventually you can use exams2pdf("q1.rmd", template = "my_template.tex") to produce the output you want, including the hyperlinks.

    See also Section 3 in vignette("exams", package = "exams") for more details. I should write an updated tutorial based on this old vignette but I hope it's still useful despite its age...