设置RSTUDIO_PDFLATEX环境变量后,Rstudio找不到pdflatex



我已经安装了latex,并在RSTUDIO_PDFLATEX环境变量中指定了路径。但是它仍然找不到它,并且一直让我安装Miktex或tinytex,这是我不想安装的。有人知道为什么吗?

> Sys.getenv("RSTUDIO_PDFLATEX")
[1] "/home/victor/local/texlive/2020/bin/x86_64-linux/pdflatex"
/usr/lib/rstudio/bin/pandoc/pandoc +RTS -K512m -RTS ddd.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output ddd.tex --lua-filter /home/victor/R/x86_64-pc-linux-gnu-library/3.6/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/victor/R/x86_64-pc-linux-gnu-library/3.6/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable 'geometry:margin=1in' 
output file: ddd.knit.md
! sh: 1: pdflatex: not found
Error: LaTeX failed to compile ddd.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See ddd.log for more info.
In addition: Warning message:
In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :
  error in running command
Execution halted
No LaTeX installation detected (LaTeX is required to create PDF output). You should install a LaTeX distribution for your platform: https://www.latex-project.org/get/
  If you are not sure, you may install TinyTeX in R: tinytex::install_tinytex()
  Otherwise consider MiKTeX on Windows - http://miktex.org

在我的例子中,即使在WSL中将tex目录添加到Ubuntu-20.04的$PATH中,RStudio也没有检测到LATEX。我通过创建符号链接文件解决了这个问题:

$ sudo ln -s /usr/local/texlive/2021/bin/x86_64-linux/pdflatex /usr/bin/pdflatex
$ sudo ln -s /usr/local/texlive/2021/bin/x86_64-linux/xelatex
/usr/bin/xelatex
$ sudo ln -s /usr/local/texlive/2021/bin/x86_64-linux/lualatex /usr/bin/lualatex

我把texlive的添加目录放到系统环境变量PATH中,然后重启系统,Rstudio终于可以找到pdflatex了!

但是,如果有人知道如何使用RSTUDIO_PDFLATEX,欢迎留下评论!

最新更新