[Tex/LaTex] RStudio not detecting MikTeX

miktex2.9rstudio

I am having some trouble using MikTeX (v2.9) on windows 7 (64 bit) with RStudio (v1.1.447; R v 3.5.0). Despite the fact that I have installed the complete MikTeX, RStudio keeps telling me that no LaTex tool has been found when trying to knit any rmd document.

I’ve tried the answer given in a similar post (RStudio Can't Find pdflatex On Windows 7) by running

Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\\Users\\myname\\AppData\\Local\\Programs\\MikTex 2.9\\miktex\\bin", sep=.Platform$path.sep))

and it does not work.

It is funny because I have the same conficuration on another machine (though versions might differ) and it works smoothly. Any hints?

Best Answer

I seem to run into this problem every few months when deploying RStudio and MikTeX for co-workers. Here are some remedies:

  1. Uninstalling everything. Then reinstall MikTeX, R, and RStudio, in that order, by right-clicking the installation files and selecting "Run as Administrator".
  2. Carefully double check / VISIT the path in your

    Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\Users\myname\AppData\Local\Programs\MikTex 2.9\miktex\bin", sep=.Platform$path.sep)) 
    

    command. Sometimes there is an additional bin64 subfolder that contains the required files. (I don't know why this is. Perhaps it happens if the installer contained both versions.)

  3. When I don't have administrator privileges, I sometimes add the Sys.setenv command to the first line of the first chunk.

  4. Try using Yihui's TinyTeX software. It has a number of great features that integrate well with RStudio. To use it, simply install the package and run the command:

    tinytex::install_tinytex()
    
  5. Lastly, if you're working on a PC, I recommend installing the PERL programming language. It enables knitr to crop your .pdf images.

Related Question