如题,在使用Rstudio创建markdown出现报错
processing file: test.Rmd

“D:/Rstudio/resources/app/bin/quarto/bin/tools/pandoc” +RTS -K512m -RTS test.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.tex --lua-filter “D:\R\R-4.3.3\library\rmarkdown\rmarkdown\lua\pagebreak.lua” --lua-filter “D:\R\R-4.3.3\library\rmarkdown\rmarkdown\lua\latex-div.lua” --embed-resources --standalone --highlight-style tango --pdf-engine pdflatex --variable graphics --variable “geometry:margin=1in”
output file: test.knit.md

错误: LaTeX failed to compile test.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.
此外: Warning message:
In system2(…, stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :
‘“pdflatex”’ not found
停止执行

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

MacTeX on macOS - https://tug.org/mactex/
(NOTE: Download with Safari rather than Chrome strongly recommended)

Linux: Use system package manager

经翻译,发现是没有安装latex
解决步骤:

  1. 安装 TinyTeX
    TinyTeX 是一个轻量级、跨平台且易于维护的 LaTeX 发行版,可以直接从 R 中安装。你可以在 R 控制台中运行以下命令来安装 TinyTeX:

    install.packages("tinytex")
    tinytex::install_tinytex()
    

    安装完成后,你可以运行以下命令来验证是否安装成功:

    tinytex::is_tinytex()
    

    TinyTeX 对于 R 用户来说是非常适合的,因为它是专门为 R Markdown 和 RStudio 设计的。

  2. 替代方案:安装 MiKTeX(Windows)
    如果你需要一个更全面的 LaTeX 发行版,可以安装 MiKTeX。访问 MiKTeX 的官方网站,下载安装程序并按照说明进行安装。

  3. 替代方案:安装 MacTeX(macOS)
    macOS 用户推荐使用 MacTeX。你可以从 tug.org/mactex 下载。注意建议使用 Safari 浏览器下载。

  4. 替代方案:Linux 用户
    在 Linux 系统中,可以使用系统的包管理器安装 TeX Live。例如,在 Ubuntu 上,可以运行以下命令:

    sudo apt-get install texlive-full
    
  5. 验证安装
    在安装 LaTeX 发行版后,确保 LaTeX 的可执行文件在系统的 PATH 中。你可以在系统命令行(而不是 R 中)运行 pdflatex --version 来测试是否显示版本信息。

安装完成后,重新在 RStudio 中 knit 你的 R Markdown 文件,这样应该可以解决错误并生成 PDF 文件。

经过一段时间安装后,运行 tinytex::is_tinytex(),出现TRUE时,代表latex已成功安装
此时在点击Knit,即可生成PDF文件。

经过测试,发现只能输出英文,文档中含有中文时会报错
具体解决方案可参考这篇Rmarkdown输出中文PDF报错的解决方法即可解决中文输出问题。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐