I'm trying to compile a simple Rnw file in Rstudio using knitr
"compile pdf" functionality. But it gives me an error.
This is what I have in hello.Rnw
:
\documentclass{article}
\begin{document}
Hello World
\end{document}
Error:
Running pdflatex.exe on hello.tex...failed
Error running C:/PROGRA~1/MIKTEX~1.9/miktex/bin/x64/pdflatex.exe (exit code 1)
However if I typeset hello.tex
using TeXworks, it generates a pdf file without any error. I checked my Sys.getenv("PATH")
variable, and it shows the correct MiKTeX location. So I'm not sure why RStudio pdflatex is not working.
"C:\\Users\\zk0q8r5\\Documents\\R\\R-3.5.0\\bin\\x64;
C:\\ProgramData\\Oracle\\Java\\javapath;
C:\\WINDOWS\\system32;
C:\\WINDOWS;
C:\\WINDOWS\\System32\\Wbem;
C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;
C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;
C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;
C:\\Program Files\\1E\\NomadBranch\\;
C:\\Program Files (x86)\\Microsoft Application Virtualization Client;
C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;
C:\\Program Files (x86)\\WebEx\\Productivity Tools;
C:\\Program Files\\TortoiseSVN\\bin;
C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64;
C:\\MiKTeX\\miktex\\bin\\x64\\"
Best Answer
So I figured out the problem. There were two MikTeX installations on my machine. And the R PATH variable was pointing to the wrong one. I simply followed the instructions from the below link and it resolved the issue. Thank you! https://stackoverflow.com/questions/33650869/how-can-i-set-the-latex-path-for-sweave-in-r