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:
- Tell your LaTeX installation about the
texmf
directory provided by the R base system so that it is found no matter where on your system you call pdfLaTeX.
- Use a different LaTeX installation, e.g., by installing TinyTeX (the LaTeX distribution) through
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.
- Avoid using the
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:
- As already explained above:
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.
- You should not have to do this but it is certainly an option that you can use. As a starting point, run
exams_skeleton(markup = "latex", writer = "exams2pdf")
. Among other things this creates a templates
folder where you could put the myplain.tex
template below.
- As I said above, it's hard to answer that with the information provided. Hopefully, one of the clues provided here gets you a couple of steps forward.
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}