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"