【问题标题】:R package: Can't render pdf manual using mathjaxrR包:无法使用mathjaxr渲染pdf手册
【发布时间】:2020-12-25 11:47:04
【问题描述】:

我正在尝试使用mathjaxr 在 R 包的文档中包含一些 LaTeX 方程。我用的是\mjdeqn{latex}{ascii}mjeqn{latex}{ascii},例如:

 \mjdeqn{\operatorname{P} \left( \operatorname{H_0} | x \right) = \left( 1 + \frac{1 - \pi_0}{\pi_0} \, \frac {1}{\operatorname{B}_{01} \left( x \right) } \right) ^{-1}}{P(H_0 | x) = (1 + ((1 - pi_0) / pi_0) * (1 / B_01(x)))^(-1)}
  • html 文档完美呈现(带有?foo 以及包的pkgdown 网站)。
  • mathjaxr::preview_rd("foo", type = "html") 也可以渲染。
  • ascii 版本在 shell 上呈现没有问题。

但是当我尝试渲染 pdf 手册时出现错误:

mathjaxr::preview_rd("bfactor_to_prob", type = "pdf")

Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
  unable to run pdflatex on 'Rd2.tex'
LaTeX errors:
! Undefined control sequence.
<argument> \operatorname 
                         {P} \left ( \operatorname {H_0} | x \right ) = \lef...
l.36 ...}_{01} \left( x \right) } \right) ^{-1}}{}
                                                  
! Undefined control sequence.
<argument> ...ratorname {P} \left ( \operatorname 
                                                  {H_0} | x \right ) = \left...
l.36 ...}_{01} \left( x \right) } \right) ^{-1}}{}
                                                  
! Undefined control sequence.
<argument> \operatorname 
                         {B}_{01} \left ( x \right ) 
l.36 ...}_{01} \left( x \right) } \right) ^{-1}}{}
                                                  
! Undefined control sequence.
<argument>  \operatorname 
                          {B}_{01} \left ( x \right ) 
l.38 ...\operatorname{B}_{01} \left( x \right) }{}
                                                   is a Bayes factor if favo...
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
  unable to run pdflatex on 'Rd2.tex'
LaTeX errors:
! Undefined control sequence.
<argument> \operatorname 
                         {P} \left ( \operatorname {H_0} | x \right ) = \lef...
l.36 ...}_{01} \left( x \right) } \right) ^{-1}}{}
                                                  
! Undefined control sequence.
<argument> ...ratorname {P} \left ( \operatorname 
                                                  {H_0} | x \right ) = \left...
l.36 ...}_{01} \left( x \right) } \right) ^{-1}}{}
                                                  
! Undefined control sequence.
<argument> \operatorname 
                         {B}_{01} \left ( x \right ) 
l.36 ...}_{01} \left( x \right) } \right) ^{-1}}{}
                                                  
! Undefined control sequence.
<argument>  \operatorname 
                          {B}_{01} \left ( x \right ) 
l.38 ...\operatorname{B}_{01} \left( x \right) }{}
                                                   is a Bayes factor if favo...
Error in running tools::texi2pdf()
The file /var/folders/np/vk9nrhgx06zbfp3tqkrsn7km0000gn/T/RtmpKg4l2G/bfactor_to_prob.pdf does not exist.

devtools::build_manualR CMD build 也会给出同样的错误。 R CMD check 成功,R CMD check --as-cran gives 这个注释:

Package has help file(s) containing install/render-stage \Sexpr{} expressions but no prebuilt PDF manual.

mathjaxr documentation 中所列,我有:

  • 在说明文件的 imports 字段中包含 mathjaxr
  • 在说明文件的 RdMacros 字段中包含 mathjaxr
  • 使用mathjaxr 在每个函数的@description 部分中包含\loadmathjax
  • @import mathjaxr 添加到命名空间

【问题讨论】:

    标签: r latex mathjax r-package


    【解决方案1】:

    在渲染 PDF 时,您受限于 LaTeX 控制序列。似乎无法识别\operatorname。您可能希望将其替换为同时被 html 和 PDF 接受的格式,或者使用 \mjteqn\mjtdeqn 宏,您可以在其中为 PDF、html 和 ASCII 指定不同的公式。

    【讨论】:

      猜你喜欢
      • 2015-08-16
      • 1970-01-01
      • 2017-12-02
      • 2022-01-13
      • 1970-01-01
      • 2019-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多