【发布时间】:2020-06-12 18:44:03
【问题描述】:
我已经阅读了下面列出的几个问题:
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
上面的列表并没有穷尽我尝试过的所有内容,其中还包括重新安装 RStudio、R 和 MikTex。
然后我认为我可以编辑路径以删除 R 一直调用但不知道该怎么做的 MikTeX 1.9。
我找到了this function,这表明我实际上已经为 MikTex 设置了正确的路径,但 R 一直在调用 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)
}
Sys.which 和 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"
我怎样才能最好地解决这个问题?
我的想法是以某种方式找到 R 在哪里找到这个 MikTeX 1.9 并替换它,但我在我的系统上找不到它,也不知道 Sys.which 在幕后做什么。
编辑
尝试定位 1.9 的位置:
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
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\C lient 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\我的名字\AppData \Local\Programs\Python\Python38\Scripts\;C:\Users\我的名字\AppData\Local\Programs\Python\Python38\;C:\Users\我的名字\AppData\Local\Programs\Python\Python36\Scripts \;C:\Users\我的名字\AppData\Local\Programs\Python\Python36\;C:\Users\我的名字\Desktop\wget-1.20.3-win64;C:\Users\我的名字\AppData\Local \Programs\Python\Python37\Scripts\;C:\Users\我的名字\AppData\Local\Programs\Python\Python37\;C:\Users\我的名字\AppData\Local\Microsoft\WindowsApps;C:\Users\我的名字\AppData\Local\Programs\Python\Python37-32;E:\jdk-12_windows-x64_bin;C:\Users\我的名字\AppData\Local\Microsoft\WindowsApps;C:\Users\我的名字\Desktop\ adb+-+平台+工具+v28.0.1"
【问题讨论】:
-
C:\\PROGRA~1\\MIKTEX~1.9\\miktex\\bin\\x64可能在您的 Windows PATH 变量中。在这种情况下,您必须将其删除。 -
@StéphaneLaurent 谢谢,我查看了 PATH(上面编辑)但找不到它。我怎样才能最好地找到它?
-
PATH 变量包含一些文件夹,而不是一些文件。在您的 R 命令中将
"latex"更改为"miktex",您应该会找到它。要删除它,请转到 Windows 的开始菜单并搜索“路径”。您应该找到类似“编辑环境变量”的内容。在 Windows 10 中,这是非常干净的。然后你必须从 PATH 变量中删除这个文件夹。 -
嗯...也许 R PATH 变量在 Renviron 文件中被修改了?转到包含 R 安装的文件夹,然后搜索 Renviron 文件(我认为它在 etc 文件夹中)。打开它(这是一个文本文件),然后检查。
-
您能否在帖子中包含
Sys.getenv("PATH")的输出。
标签: r r-markdown knitr pdflatex miktex