3

I have been using r/exams in some of my last exams and everything has worked fine. This semester, however, r/exams seems to generate the exams in Times New Roman instead of Helvetica, which messes with the character recognition in the scanning process.

Even the minimal example, produces this behavior:

library("exams")
myexam <- list("cholesky.Rnw")
set.seed(403)
ex1 <- exams2nops(myexam, n = 1,
              dir = "nops_pdf", name = "demo", date = "2015-07-29",
              points = c(1), showpoints = TRUE)

Does anyone have any idea what could have gone wrong? How do I see the intermediate steps? I get no error messages.

Thanks!

  • I don't know the package, but there are a lot of options in `?exams2nops`, have you pored over this? A quick glance shows: "Note that the font in the PDF must not be modified for the reading step to work reliably. (A sans-serif font is used and hence the \code{sfmath} LaTeX package is also used - if it is installed.)", perhaps your latex installation is missing `sfmath`? – MichaelChirico Mar 08 '19 at 09:56
  • 1
    Thanks for the hint. Something was missing in my TinyTex installation. It was not sfmath. I moved to MacTex and it works again! – André Calero Valdez Mar 08 '19 at 10:24

1 Answers1

3

Starting from R/exams version 2.3-2 (the current CRAN version at the time of writing) it is enforced that the digits that need to be scanned are always in Helvetica (\fontfamily{phv}) even if the font is switched for the rest of the document.

However, in a plain TinyTeX installation, i.e., after running just tinytex::install_tinytex() the Helvetica font is not installed yet. Just setting \fontfamily{phv} is not enough for TinyTeX to realize that an additional package needs to be installed (psnfss). Therefore, I have modified the devel version of exams on R-Forge to explicitly include \usepackage{helvet}. This will trigger the automatic installation of psnfss in TinyTeX. Installing version 2.3-5 should thus resolve the problem: install.packages("exams", repos = "http://R-Forge.R-project.org"). This will also be released to CRAN in the next days.

Moreover, just for future reference, I went through the source code of exams2nops() to check what packages we use. Partly for historical reasons there are quite a few. Possibly these could also be streamlined.

  • Basic tools: graphicx, color, amsmath, amssymb, latexsym.
  • For compatibility with Sweave: verbatim, url, fancyvrb, ae.
  • Layout etc.: multicol, a4wide, pdfpages, chngpage.
  • Fonts: helvet, sfmath.
  • For compatibility with LaTeX produced by pandoc from Markdown: booktabs, longtable, eurosym, textcomp.
Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49
  • 1
    Since **exams** uses `tools::texi2dvi()`, it cannot take full advantage of **tinytex** and TinyTeX. If you switch to `tinytex::latexmk()`, missing LaTeX packages will be automatically installed in TinyTeX. – Yihui Xie Mar 13 '19 at 19:57
  • @YihuiXie Thanks for pointing this out, I finally have time to work on this. I want to enable a switch between `tools::texi2dvi()` and `tinytex::latexmk()` in **exams**. Is `if(requireNamespace("tinytex"))` a good enough condition for deciding this? Shouldn't I test whether `tinytex` is really fully installed, i.e., check whether `tinytex::install_tinytex()` was actually run as well? Any hints appreciated! – Achim Zeileis Jul 17 '19 at 00:14
  • 1
    You don't need to detect if TinyTeX (the LaTeX distribution) is installed. `tinytex::latexmk()` doesn't require the LaTeX distribution to be TinyTeX: https://yihui.name/tinytex/r/#other-latex-distributions `tinytex::latexmk()` does most of the things that `tools::texi2dvi()` does, with one additional feature (i.e. automatically install missing LaTeX packages if possible). So `if (requireNamespace('tinytex'))` is enough. – Yihui Xie Jul 18 '19 at 16:49
  • 2
    Thanks, very much appreciated! I've committed this now to the devel version on R-Forge. Andre, if you want to give `tinytex` another try, you can get the devel version with `install.packages("exams", repos="http://R-Forge.R-project.org")`. If the "tinytex" package is installed, it wil be used automatically. Worked very smoothly for me! – Achim Zeileis Jul 19 '19 at 01:57
  • Damn... Reinstalled Tinytex. Now I have the same problem again. Installing MacTex and removing TinyTex solved the problem. Installing TinyTex again creates this problem. I have no idea how to debug this. Is there a way of seeing the "source.tex" ? – André Calero Valdez Feb 14 '20 at 18:12
  • In `exams2pdf()` and hence also `exams2nops()` you can set the `texdir=` argument to some directory where the tex files should be compiled. These can then be used for debugging afterwards. – Achim Zeileis Feb 15 '20 at 08:51
  • I just tried this on a completely fresh Windows machine and could replicate your problem. Apparently, I cannot assume that fontfamily `phv` is just available in TeXLive. But after running `tinytex::tlmgr_install("psnfss")` everything worked for me. Can you confirm that? If so, I only need to find out what I need to include in the .tex file so that `tinytex` resolves this dependency on its own. Probably `usepackage{helvet}`. – Achim Zeileis Mar 31 '20 at 10:40
  • I have updated my answer accordingly. It would be great if you could confirm (or disconfirm) whether this also works for you. – Achim Zeileis Mar 31 '20 at 15:52