10

I have been trying to get pdflatex to use the correct version of miktex and have not been successful.

I have set the R Path to have the correct location of Miktex 2.9, and verified that it worked with:

Sys.getenv("PATH")
"C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\pdflatex;..." 

However when i look at the version of miktex that pdflatex is using:

Sys.which("pdflatex")
"C:\\PROGRA~1\\MIKTEX~1.9\\miktex\\bin\\x64\\pdflatex.exe"

This 1.9 path is to an old version of miktex that no longer even exists.

Running in the command prompt which pdflatex returns the correct path, so the problem is just in R. How can I get R to use the correct path to pdflatex?

clairekelley
  • 427
  • 2
  • 4
  • 11
  • I know this is an old thread, but the path in your `PATH` environment includes an extra 'pdflatex' that might be causing this problem – Will Bryant May 05 '20 at 05:32

1 Answers1

3

There are couple solutions you can try:

  1. Disable the "Enable shell escape commands" in Tools > Global Options > Sweave

  2. Set the path manually per this answer. You will have to run this every time you restart RStudio.

     Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:/Program Files/MiKTeX 2.9/miktex/bin/x64", sep=.Platform$path.sep))
    
  3. Put the following line in Renviron.site in the folder R_HOME/etc where R_HOME is the path returned by Sys.getenv("R_HOME"). Ref

     PATH=C:/Program Files/MiKTeX 2.9/miktex/bin/x64:"${PATH}"
    
  4. Install tinytex package. Note that you should use either MiKTeX or tinytex, but not both. If you have both installed, Yihui recommended that you remove MiKTeX in this case. Ref

You might have to restart R/RStudio or even your PC/laptop after each change to see if it works or not

Tung
  • 26,371
  • 7
  • 91
  • 115
  • Thank you for your detailed answer! Sadly none of these solutions work. I restarted R and my computer between each test. If i set the path (either manually or by Renviron.site) then in the command prompt (ie outside R) the correct path to miktex is found but with in R Sys.which("pdflatex") still refers to the old non existent path. I also cant uninstall MikTex because i need it for other project. – clairekelley Aug 13 '18 at 13:02
  • @clairekelley: you can use both `tinytex` and MiKTeX. I'm using both of them on my Windows PC too – Tung Aug 13 '18 at 13:06
  • If nothing works then you should probably consider uninstall/reinstall R, RStudio & MikTeX – Tung Aug 13 '18 at 13:12
  • I did everything(including reinstall). Still didn't work unfortunately. R still points to a non existent 1.9. – NelsonGon Feb 28 '20 at 13:26
  • 4
    @clairekelley Did you ever solve this?! if(solved) how did you do so? – NelsonGon Feb 28 '20 at 14:40