【问题标题】:rmarkdown::render() failed to generate pdf, but the rstudio 'knitr' buttons worksrmarkdown::render() 无法生成 pdf,但 rstudio 'knitr' 按钮有效
【发布时间】:2020-01-06 17:35:47
【问题描述】:

我使用 tineytex 包,当我单击 rStudio 中的 knit 按钮时,编织 pdf 没有问题。但是,当我使用相同的 .Rmd 文件作为输入调用 rmarkdown::render() 时,目标文件夹中只生成了一个中间的 .tex 文件。

下面是我的代码。

rmarkdown::render(input = "C:/Users/sqhuang/Pdf.Rmd",  
           output_format = "pdf_document",
           output_file = "test.pdf", 
            output_dir = ot_path)

以下是我收到的错误消息。

处理文件:Pdf.Rmd

|.........                                                        |  14%
  ordinary text without R code

  |...................                                              |  29%
label: setup (with options) 
List of 1
 $ echo: logi FALSE

  |............................                                     |  43%
  ordinary text without R code

  |.....................................                            |  57%
label: cars
  |..............................................                   |  71%
  ordinary text without R code

  |........................................................         |  86%
label: pressure (with options) 
List of 1
 $ echo: logi FALSE

  |.................................................................| 100%
  ordinary text without R code

输出文件:Pdf.knit.md

"C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS Pdf.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc15f027594a1c.tex --template "C:\PROGRA~1\R\R-36~1.1\library\RMARKD~1\rmd\latex\DEFAUL~3.TEX" --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" --variable "compact-title:yes" 这是 pdfTeX,版本 3.14159265-2.6-1.40.20 (TeX Live 2019/W32TeX) (预加载格式=pdflatex)限制\write18 启用。警告: kpathsea: //enterprise2/Users4$/Sqhuang_a/My Documents: Unrecognized 变量构造$/'. warning: kpathsea: //enterprise2/Users4$/Sqhuang_a/My Documents: Unrecognized variable construct$/'。警告:kpathsea://enterprise2/Users4$/Sqhuang_a/My 文档:无法识别的变量构造 $/'. warning: kpathsea: //enterprise2/Users4$/Sqhuang_a/My Documents/.TinyTeX/texmf-config/web2c/pdftex: Unrecognized variable construct$/'。警告:kpathsea://enterprise2/Users4$/Sqhuang_a/My Documents/.TinyTeX/texmf-var/web2c/pdftex:无法识别的变量 构造$/'. warning: kpathsea: //enterprise2/Users4$/Sqhuang_a/My Documents/.TinyTeX/texmf-home/web2c/pdftex: Unrecognized variable construct$/'。警告:kpathsea://enterprise2/Users4$/Sqhuang_a/My Documents/.TinyTeX/texmf-config/web2c:无法识别的变量构造 $/'. warning: kpathsea: //enterprise2/Users4$/Sqhuang_a/My Documents/.TinyTeX/texmf-var/web2c: Unrecognized variable construct $/'。警告:kpathsea://enterprise2/Users4$/Sqhuang_a/My Documents/.TinyTeX/texmf-home/web2c:无法识别的变量构造 `$/'。进入扩展模式错误:编译失败 \endeavor/apps_doc$/Applications/0_Support/GCS/Brett - 其他 职责/BAR/Steph/AL/Jul/test_report.tex。看 https://yihui.name/tinytex/r/#debugging 获取调试提示。

【问题讨论】:

  • 我在我的 .Rmd 文件代码主干中添加了以下内容:options(tinytex.verbose = TRUE)。但是,没有给出关于错误的太多细节。我也在互联网上搜索,发现有人在 Rstudio 论坛上发布了相同的问题,但问题没有解决。有没有人遇到这个问题并解决了这个问题?非常感谢任何获得有关该问题的更多信息的指针。
  • 在呈现同一报表的 HTML 版本时,render() 也失败了。但是,这次我获得了有关该错误的更多信息。 render() 函数有问题的是合作共享驱动器:它无法正确解释包含$ 的共享驱动器路径。一旦我将输出目录更改为 C 驱动器,报告的 pdf 和 html 版本都会被渲染。
  • (仅作记录)在这里提出了类似的问题:github.com/yihui/tinytex/issues/150 但我没有解决方案。

标签: r-markdown render tinytex


【解决方案1】:

我认为我已经解决了问题(不幸的是,我似乎遇到了further issue,但我想我已经解决了这个问题)。

基本上,kpathsea 会在您的系统中到处搜索所需的软件包。这意味着它正在尝试在它无法正确读取的目录中搜索(因为$ 等符号)。解决方案是找到看起来像这样的texmf.cnf 文件:

% (Public domain.)
% This texmf.cnf file should contain only your personal changes from the
% original texmf.cnf (for example, as chosen in the installer).
%
% That is, if you need to make changes to texmf.cnf, put your custom
% settings in this file, which is .../texlive/YYYY/texmf.cnf, rather than
% the distributed file (which is .../texlive/YYYY/texmf-dist/web2c/texmf.cnf).
% And include *only* your changed values, not a copy of the whole thing!
%
TEXMFLOCAL = $SELFAUTOPARENT/texmf-local
TEXMFHOME = $HOME/.TinyTeX/texmf-home
TEXMFVAR = $HOME/.TinyTeX/texmf-var
TEXMFCONFIG = $HOME/.TinyTeX/texmf-config
OSFONTDIR = $SystemRoot/fonts//
ASYMPTOTE_HOME = $TEXMFCONFIG/asymptote

% Prefer external Perl for third-party TeXLive Perl scripts
% Was set to 1 if at install time a sufficiently recent Perl was detected.
TEXLIVE_WINDOWS_TRY_EXTERNAL_PERL = 0
TEXMFAUXTREES = C:/PROGRA~1/R/R-36~1.3/share/texmf,

搜索时,kpathsea 将$HOME 替换为包含$ 的目录,例如,对我而言,$HOME 被我的默认 Documents 文件夹(位于共享网络驱动器上)替换。

我用./TinyTeX 替换了任何有$HOME/.TinyTeX 的地方,这将使kpathsea 在我实际安装TinyTex 的目录中搜索(更具体地说,在默认情况下不 搜索目录。)

希望这对遇到此问题的任何人有所帮助,并为开发人员提供一些帮助,帮助他们在未来如何阻止此问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-14
    • 2018-07-26
    • 2017-04-05
    • 1970-01-01
    • 2014-03-30
    • 2015-12-04
    • 2017-01-24
    • 1970-01-01
    相关资源
    最近更新 更多