问题
I'm hoping someone can point me to the internal setting that can fix my issue with compiling tex docs from R.
My issues is that texi2pdf
and knit2pdf
throw warnings and do not generate a pdf.
I can get Rnw files to compile using the "Compile pdf" button in RStudio, I can knit rnw files into text files, and I can get my tex files to compile into pdf using TeXnicCenter, but I can't get the texi2pdf
or knit2pdf
functions to work in R.
In Windows 7 on one machine with TexLive installed and on another machine with MikTex 2.9 installed, when I run the following:
library(knitr)
f = system.file("examples", "knitr-minimal.Rnw", package = "knitr")
knit(f) # compile to tex
texi2pdf(gsub('Rnw', 'tex', f))
the first part works (rnw->tex), but the texi2pdf (tex->pdf) results in:
Warning message:
running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texify.exe" --quiet --pdf
"C:/Program Files/R/R-3.3.3/library/knitr/examples/knitr-minimal.tex" --max-
iterations=20 -I "C:/PROGRA~1/R/R-33~1.3/share/texmf/tex/latex" -I
"C:/PROGRA~1/R/R-33~1.3/share/texmf/bibtex/bst"' had status 1
The same is true if I run knit2pdf(f)
, I get the same warning message + a pop up "pdflatex.EXE has stopped working".
One other thing I don't understand is that I have MikTex 2.9 in my path, but the warning message references MikTex 1.9, which is not installed on my machine and is not in the path.
回答1:
This isn't so much a fix as a work around...
library(knitr)
setwd(system.file("examples", package = "knitr"))
knit("knitr-minimal.Rnw") # compile to tex
system('pdflatex knitr-minimal.tex')
回答2:
This happened to me today, and it seems it was because MikTex 2.9 was installed under my User account. R is also installed under my User account. Here is what worked for me:
- Uninstall MikTex and reinstall it under Program files. Update MikTex from its console.
- Add "C:\Program Files\MiKTeX 2.9\miktex\bin\x64" to Windows PATH (delete the old MikTex path).
- Restart you computer
- Uninstall and reinstall the knitr package (that might not be necessary).
来源:https://stackoverflow.com/questions/44785961/compile-pdf-in-rstudio-works-but-knit2pdf-does-not-work-in-r-or-rstudio