1
votes

I have read several questions listed below:

Set path to miktex for pdflatex in R

How can I set the latex path for sweave in R?

https://tex.stackexchange.com/questions/267299/how-to-fix-the-sorry-but-c-miktex-pdftex-exe-did-not-succeed-error https://tex.stackexchange.com/questions/429706/rstudio-not-detecting-miktex https://tex.stackexchange.com/questions/231595/rstudio-cant-find-pdflatex-on-windows-7

The above list does not exhaust everything I have tried which also includes reinstalling RStudio, R and MikTex.

I then thought that I could edit the path to delete MikTeX 1.9 that R keeps calling but don't know how to do that.

I found this function which shows that I have infact set the correct path to MikTex but R keeps calling MikTeX 1.9:

Sys.which2 <- function(cmd) {
  stopifnot(length(cmd) == 1)
  if (.Platform$OS.type == "windows") {
    suppressWarnings({
      pathname <- shell(sprintf("where %s 2> NUL", cmd), intern=TRUE)[1]
    })
    if (!is.na(pathname)) return(setNames(pathname, cmd))
  }
  Sys.which(cmd)
}

Different output between Sys.which and Sys.which2:


Sys.which2("pdflatex")
                                                       pdflatex 
"C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\pdflatex.exe" 

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


How can I best solve this issue?

My idea was to somehow locate where R is finding this MikTeX 1.9 and replace it but I can't find it on my system and don't quite know what Sys.which is doing behind the scenes.

EDIT

An attempt at locating where 1.9 is:

stringr::str_detect(unlist(strsplit(Sys.getenv("PATH"),";")),"latex")
 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

Output of sys.getenv("PATH":

"C:/Program Files/MiKTeX 2.9/miktex/bin/x64:C:\Program Files\R\R-3.6.2\bin\x64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\copasi.org\COPASI 4.22.170\bin;C:\Program Files (x86)\Intel\TXE Components\iCLS\;C:\Program Files\Intel\TXE Components\iCLS\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Recovery\OEM\Backup\;C:\Program Files\Intel\TXE Components\DAL\;C:\Program Files (x86)\Intel\TXE Components\DAL\;C:\Program Files\Intel\TXE Components\IPT\;C:\Program Files (x86)\Intel\TXE Components\IPT\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;E:\MATLAB\runtime\win64;E:\MATLAB\bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\ProgramData\chocolatey\bin;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Users\my name\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\my name\AppData\Local\Programs\Python\Python38\;C:\Users\my name\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\my name\AppData\Local\Programs\Python\Python36\;C:\Users\my name\Desktop\wget-1.20.3-win64;C:\Users\my name\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\my name\AppData\Local\Programs\Python\Python37\;C:\Users\my name\AppData\Local\Microsoft\WindowsApps;C:\Users\my name\AppData\Local\Programs\Python\Python37-32;E:\jdk-12_windows-x64_bin;C:\Users\my name\AppData\Local\Microsoft\WindowsApps;C:\Users\my name\Desktop\adb+-+platform+tools+v28.0.1"

1
C:\\PROGRA~1\\MIKTEX~1.9\\miktex\\bin\\x64 is probably in your Windows PATH variable. In this case you have to remove it.Stéphane Laurent
@StéphaneLaurent Thanks, I looked at the PATH(edit above) but can't find it. How can I best locate it?NelsonGon
The PATH variable contains some folders, not some files. Change "latex" to "miktex" in your R command and you should find it. To remove it, go to the Start menu of Windows and search "path". You should find something like "Edit environmental variables". In windows 10 this is very clean. Then you have to remove this folder from the PATH variable.Stéphane Laurent
Hmm... maybe the R PATH variable is modified in the Renviron file ? Go to the folder containing you R installation, and search the Renviron file (I think it is in the etc folder). Open it (this is a text file), and check.Stéphane Laurent
Could you include the output of Sys.getenv("PATH") in your post.Stéphane Laurent

1 Answers

1
votes

C:\\PROGRA~1\\MIKTEX~1.9 doesn't mean literally MiKTeX v1.9. It is an 8.3 filename. Because the string MiKTeX 2 contains a "special character" (i.e. a space), it is converted to MIKTEX~1 (the .9 part still remains as the "extension", so MiKTeX 2.9 became MIKTEX~1.9, which is indeed confusing in this case).

I feel the problem you are actually trying to solve might be a different one. If that's the case, you may ask the actual question. There isn't anything wrong with your environment variables, as far as I can see.

If you really need the long name, you can call normalizePath() to convert the short 8.3 name to a long name.