使用Rmarkdown生成pdf报错的问题

如题,在使用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报错的解决方法即可解决中文输出问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值