You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法将Rmd文件编织为PDF,TinyTeX安装失败问题求助

R Markdown编织PDF时LaTeX环境安装失败解决方案

问题复现

编织PDF初始报错

将Rmd文件编织为PDF时首次报错内容如下:

Error: LaTeX failed to compile test.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.
In addition: Warning message:
In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :
  '"pdflatex"' not found
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

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

  Linux: Use system package manager

在线安装TinyTeX报错

运行tinytex::install_tinytex()安装时的报错:

trying URL 'https://yihui.org/tinytex/TinyTeX-1.zip'
Content type 'text/html' length 4305 bytes
downloaded 4305 bytes

Error in system2("tlmgr", args, ...) : '"tlmgr"' not found
In addition: Warning message:
In extract(pkg, exdir = path.expand(target)) :
  error 1 in extracting from zip file

后续运行tinytex::reinstall_tinytex()报错:

Error in system2("tlmgr", args, ...) : '"tlmgr"' not found

运行tinytex::uninstall_tinytex()报错:

Error in tinytex::uninstall_tinytex() : 
  TinyTeX does not seem to be installed.

运行环境信息

xfun::session_info()输出如下:

R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363), RStudio 2021.9.0.351

Locale:
  LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
  LC_NUMERIC=C                           LC_TIME=English_United States.1252    

Package version:
  base64enc_0.1.3 compiler_4.1.2  digest_0.6.28   evaluate_0.14   fastmap_1.1.0   glue_1.4.2      graphics_4.1.2  grDevices_4.1.2 highr_0.9      
  htmltools_0.5.2 jquerylib_0.1.4 jsonlite_1.7.2  knitr_1.36      magrittr_2.0.1  methods_4.1.2   rlang_0.4.12    rmarkdown_2.11  stats_4.1.2    
  stringi_1.7.5   stringr_1.4.0   tinytex_0.35    tools_4.1.2     utils_4.1.2     xfun_0.27       yaml_2.2.1   

根因说明

在线安装TinyTeX时网络请求异常,下载得到的4KB文件是错误提示页面而非正式安装包,解压失败导致没有完整的LaTeX运行环境,所有调用tlmgr、pdflatex的操作都会失败。

解决步骤

  1. 清理残留损坏文件
    在R控制台运行以下命令获取TinyTeX默认安装路径,手动删除该路径下的所有文件及文件夹:
file.path(Sys.getenv("APPDATA"), "TinyTeX")
  1. 离线安装TinyTeX
    下载TinyTeX的Windows离线安装包,保存到无中文、无空格的路径下(例如C:\soft\TinyTeX-1.zip),运行以下命令本地安装:
# 注意路径分隔符用正斜杠/或者双反斜杠\\
tinytex::install_tinytex("C:/soft/TinyTeX-1.zip")
  1. 验证安装
    运行以下命令,返回TRUE即为安装成功,重启RStudio后即可正常编织Rmd为PDF:
tinytex::is_tinytex()

备选方案

如果上述操作仍有问题,可直接安装Windows版MiKTeX,安装时勾选「添加到系统PATH」选项,安装完成后重启RStudio即可识别到LaTeX环境。

内容的提问来源于stack exchange,提问作者fkn_ez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 18:15:11