I am new to the R/exams package and I try to produce a pdf document from one of the templates provided by the developers. (http://www.R-exams.org/templates/confint3/)
I am able to compile a Rnw file into a HTML document using the commands
library("exams")
exams2html("confint3.Rnw")
When calling the function
exams2pdf("confint3.Rnw")
it gives the error message
! LaTeX Error: File `Sweave.sty' not found.
I have Latex installed and there are no problems using it in general. I do not understand:
exams2pdf()
the location of the latex installation? plain.tex
) first? How should it look like?I looked at the documentation of the exams package, I also tried exams2pdf()
after installing and calling library("tinytex")
.
Any help where to look at or what to do is highly appreciated. Thank you!
Minimal example:
install.packages("exams")
install.packages("tth")
library("exams")
set.seed(1090)
exams2html("confint3.Rnw")
set.seed(1090)
exams2pdf("confint3.Rnw")
It is hard to diagnose what exactly goes wrong with the information provided. In any case, when running pdfLaTeX either through utils::texi2dvi()
(the default when the R package tinytex
is not installed) or through tinytex::latexmk()
(the default when the R package tinytex
is installed) does not find the Sweave.sty
file provided by the R base system. What is not clear to me which LaTeX engine is running in the background: MikTeX on Windows?
There are several strategies that could resolve this issue:
texmf
directory provided by the R base system so that it is found no matter where on your system you call pdfLaTeX.tinytex
(the R package): tinytex::install_tinytex()
. This might be particularly attractive if you are not actually a LaTeX user and just need it to compile PDF exams.Sweave.sty
file in a custom template file, say myplain.tex
. A suggestion for such a file is included at the end of this post.Further details are discussed in this thread: https://tex.stackexchange.com/questions/153193/latex-error-sweave-sty-not-found
As for your three questions:
exams2pdf()
leverages either utils::texi2dvi()
or tinytex::latexmk()
. So these need to know about the LaTeX installation - but this seems to be the case. They just don't find the texmf
provided by base R.exams_skeleton(markup = "latex", writer = "exams2pdf")
. Among other things this creates a templates
folder where you could put the myplain.tex
template below.Content of myplain.tex
:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{a4wide,graphicx,color,verbatim,url,fancyvrb,ae,amsmath,amssymb,booktabs,longtable,eurosym}
\newenvironment{question}{\item \textbf{Problem}\newline}{}
\newenvironment{solution}{\textbf{Solution}\newline}{}
\newenvironment{answerlist}{\renewcommand{\labelenumi}{(\alph{enumi})}\begin{enumerate}}{\end{enumerate}}
\providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setkeys{Gin}{keepaspectratio}
\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}
\newenvironment{Schunk}{}{}
\begin{document}
\begin{enumerate}
%% \exinput{exercises}
\end{enumerate}
\end{document}