简体   繁体   中英

R package: Can't render pdf manual using mathjaxr

I'm trying to use mathjaxr to include some LaTeX equations in the documentation of an R package. I'm using \\mjdeqn{latex}{ascii} and mjeqn{latex}{ascii} , for example:

 \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)}
  • The html documentation renders perfectly (with ?foo and also in the pkgdown website of the package).
  • mathjaxr::preview_rd("foo", type = "html") also renders ok.
  • The ascii version renders on the shell without problems.

But when I try to render the pdf manuals I get errors:

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_manual and R CMD build also give these same errors. R CMD check succeeds and R CMD check --as-cran gives this note:

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

As listed in the mathjaxr documentation I have:

  • Included mathjaxr in the imports field of the DESCRIPTION file
  • Included mathjaxr in the RdMacros field of the DESCRIPTION file
  • Included \\loadmathjax in the @description section of each function using mathjaxr
  • Added @import mathjaxr to the NAMESPACE

When rendering the PDF you are limited in the LaTeX control sequences. It seems that \\operatorname is not recognized. You may either want to replace it for one that is accepted by both html and PDF or to use the \\mjteqn and \\mjtdeqn macros where you can specify different equations for PDF, html and ASCII.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM