[Tex/LaTex] RStudio Can’t Find pdflatex On Windows 7


I'm running RStudio (0.98.1091) and Texworks MiKTeX (2.9 64 bit) on Windows 7.

My PATH environment variable is set and includes the complete path to the MiKTeX directory where pdflatex lives: "F:\Tools\MiKTeX 2.9\miktex\bin\x64". If I open a command shell I can see the PATH is set; I can also invoke pdflatex simply by typing in the command shell.

I can see my PATH variable with the correct path to the MiKTeX /bin folder if I open RStudio and type Sys.getenv("PATH") in the console.

However, when I run Rmarkdown in Rstudio it complains that there's no pdflatex available.

No TeX installation detected (TeX is required to create PDF output). You should install a recommended TeX distribution for your platform:

  Windows: MiKTeX (Complete) - http://miktex.org/2.9/setup
  (NOTE: Be sure to download the Complete rather than Basic installation)

Google searches bring back several questions like mine, except for MacOS, like this:


Is there any way for me to tell RStudio where MiKTeX is installed so I can generate PDFs?

Best Answer

Ulrike Fischer's comment is correct. In RStudio for Windows, I can do this:

Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\\RMathew\\PortableApps\\MikTeX\\miktex\\bin", sep=.Platform$path.sep))

which will let me use pdfLaTeX for that session. If you want RStudio to remember this command each time you start RStudio, you have to add the command to your .Rprofile file.

Note the use of the double backslash for each folder.