使用 R/exams exams2pdf() 生成 PDF 文档
Use R/exams exams2pdf() to produce a PDF document
我是 R/exams 包的新手,我尝试从开发人员提供的模板之一生成 pdf 文档。 (http://www.R-exams.org/templates/confint3/)
我可以使用以下命令将 Rnw 文件编译成 HTML 文档
library("exams")
exams2html("confint3.Rnw")
调用函数时
exams2pdf("confint3.Rnw")
它给出了错误信息
! LaTeX Error: File `Sweave.sty' not found.
我安装了Latex,一般使用没有问题。我不明白:
- 我需要告诉
exams2pdf()
Latex 安装的位置吗?
- 我需要先定义一个模板(如
plain.tex
)吗?它应该是什么样子?
- 有什么不明白的?
我查看了 exams 包的文档,安装并调用 library("tinytex")
后我也尝试了 exams2pdf()
。
非常感谢您提供有关查看位置或操作的任何帮助。谢谢!
最小示例:
install.packages("exams")
install.packages("tth")
library("exams")
set.seed(1090)
exams2html("confint3.Rnw")
set.seed(1090)
exams2pdf("confint3.Rnw")
很难诊断所提供的信息到底出了什么问题。在任何情况下,当 运行ning pdfLaTeX 通过 utils::texi2dvi()
(未安装 R 包 tinytex
时的默认设置)或通过 tinytex::latexmk()
(R 包 tinytex
时的默认设置 tinytex
已安装)没有找到 R 基本系统提供的 Sweave.sty
文件。我不清楚哪个 LaTeX 引擎在后台 运行ning:MikTeX on Windows?
有几种策略可以解决这个问题:
- 告诉您的 LaTeX 安装有关 R 基础系统提供的
texmf
目录,这样无论您在系统的哪个位置调用 pdfLaTeX,都可以找到它。
- 使用不同的 LaTeX 安装,例如,通过
tinytex
(R 包)安装 TinyTeX(LaTeX 发行版):tinytex::install_tinytex()
。如果您实际上不是 LaTeX 用户并且只是需要它来编译 PDF 考试,这可能会特别有吸引力。
- 避免在自定义模板文件中使用
Sweave.sty
文件,比如 myplain.tex
。 post. 末尾包含对此类文件的建议
更多详细信息在此线程中讨论:https://tex.stackexchange.com/questions/153193/latex-error-sweave-sty-not-found
关于你的三个问题:
- 如上所述:
exams2pdf()
利用 utils::texi2dvi()
或 tinytex::latexmk()
。所以这些需要了解 LaTeX 安装 - 但似乎是这样。他们只是找不到 base R. 提供的 texmf
- 您不应该必须执行此操作,但这肯定是您可以使用的选项。作为起点,运行
exams_skeleton(markup = "latex", writer = "exams2pdf")
。除其他事项外,这会创建一个 templates
文件夹,您可以在其中放置 myplain.tex
模板。
- 正如我上面所说,很难用所提供的信息来回答这个问题。希望此处提供的其中一条线索能让您向前迈出几步。
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}
我是 R/exams 包的新手,我尝试从开发人员提供的模板之一生成 pdf 文档。 (http://www.R-exams.org/templates/confint3/)
我可以使用以下命令将 Rnw 文件编译成 HTML 文档
library("exams")
exams2html("confint3.Rnw")
调用函数时
exams2pdf("confint3.Rnw")
它给出了错误信息
! LaTeX Error: File `Sweave.sty' not found.
我安装了Latex,一般使用没有问题。我不明白:
- 我需要告诉
exams2pdf()
Latex 安装的位置吗? - 我需要先定义一个模板(如
plain.tex
)吗?它应该是什么样子? - 有什么不明白的?
我查看了 exams 包的文档,安装并调用 library("tinytex")
后我也尝试了 exams2pdf()
。
非常感谢您提供有关查看位置或操作的任何帮助。谢谢!
最小示例:
install.packages("exams")
install.packages("tth")
library("exams")
set.seed(1090)
exams2html("confint3.Rnw")
set.seed(1090)
exams2pdf("confint3.Rnw")
很难诊断所提供的信息到底出了什么问题。在任何情况下,当 运行ning pdfLaTeX 通过 utils::texi2dvi()
(未安装 R 包 tinytex
时的默认设置)或通过 tinytex::latexmk()
(R 包 tinytex
时的默认设置 tinytex
已安装)没有找到 R 基本系统提供的 Sweave.sty
文件。我不清楚哪个 LaTeX 引擎在后台 运行ning:MikTeX on Windows?
有几种策略可以解决这个问题:
- 告诉您的 LaTeX 安装有关 R 基础系统提供的
texmf
目录,这样无论您在系统的哪个位置调用 pdfLaTeX,都可以找到它。 - 使用不同的 LaTeX 安装,例如,通过
tinytex
(R 包)安装 TinyTeX(LaTeX 发行版):tinytex::install_tinytex()
。如果您实际上不是 LaTeX 用户并且只是需要它来编译 PDF 考试,这可能会特别有吸引力。 - 避免在自定义模板文件中使用
Sweave.sty
文件,比如myplain.tex
。 post. 末尾包含对此类文件的建议
更多详细信息在此线程中讨论:https://tex.stackexchange.com/questions/153193/latex-error-sweave-sty-not-found
关于你的三个问题:
- 如上所述:
exams2pdf()
利用utils::texi2dvi()
或tinytex::latexmk()
。所以这些需要了解 LaTeX 安装 - 但似乎是这样。他们只是找不到 base R. 提供的 - 您不应该必须执行此操作,但这肯定是您可以使用的选项。作为起点,运行
exams_skeleton(markup = "latex", writer = "exams2pdf")
。除其他事项外,这会创建一个templates
文件夹,您可以在其中放置myplain.tex
模板。 - 正如我上面所说,很难用所提供的信息来回答这个问题。希望此处提供的其中一条线索能让您向前迈出几步。
texmf
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}