【问题标题】:LaTeX errors when creating PDF version. This typically indicates Rd problems. LaTeX errors found: ! Undefined control sequence创建 PDF 版本时出现 LaTeX 错误。这通常表示 Rd 问题。发现 LaTeX 错误:!未定义的控制序列
【发布时间】:2016-09-12 08:41:37
【问题描述】:

我是乳胶新手。我正确安装了 MikTeX 2.9、GhostScript、GSView、TeXnicCenter,并正确进行了设置。

我的包裹(名为“mypackage”)通过包裹检查
通过
从 R 控制台:devtools::check("C:/Users/User/Documents/Revolution/mypackage")
从 DOS 命令提示符:R CMD check mypackage
没有任何问题,我最终自动获得了 mypackage.PDF 文件。

我决定生成数学表达式,例如,

在生成的 .PDF 文件中。因此,我在 .R 文件的行中添加了以下乳胶表达式:

#' @param max selected ...The default is Schwert's approximation: \eqn{\lfloor 12(length(t) \over 100)^{\sfrac{1}{4}} \rfloor}

我再次激活并触发了上述包检查。这次,在包检查中,我收到以下错误(在命令提示符中):

* checking PDF version of manual ...Warning: running command '"C:/Revolution/R-Enterprise-7.3/R-3.1.1/bin/x64/Rcmd.exe" Rd2pdf  --batch --no-preview --build-dir
="C:/Users/User/AppData/Local/Temp/RtmpysnRGn/Rd2pdf1b3050f426ea" --no-clean -o mypackage-manual.pdf  

"C:/Users/User/Documents/Revolution/mypackage.Rcheck/mypackage"' had status 1
 WARNING LaTeX errors when creating PDF version. This typically indicates Rd problems. LaTeX errors found: ! Undefined control sequence.
<argument> ...oor 12(length(t) \over 100)^{\sfrac
    {1}{4}} \rfloor
l.67 ...th(t) \over 100)^{\sfrac{1}{4}} \rfloor}{}

checking PDF version of manual without hyperrefs or index ...Warning: running command '"C:/Revolution/R-Enterprise-7.3/R-3.1.1/bin/x64/Rcmd.exe" Rd2pdf  --bat
ch --no-preview --build-dir="C:/Users/User/AppData/Local/Temp/RtmpysnRGn/Rd2pdf1b3069b07b94" --no-clean --no-index -o  mypackage-manual.pdf  

C:/Users/User/Documents/Revolution/mypackage.Rcheck/mypackage' had status 1 ERROR

我做了什么:我分析了 SOF 中的类似错误,但无法弄清楚出了什么问题。我不确定错误发生在哪里:我的乳胶语法或 R 中的东西。

如果有任何帮助,我将不胜感激。

编辑(根据 Werner 的评论完成序言;在实施以下解决方案之后):

#' adfcs
#'
#' Augmented Dickey-Fuller test that uses common (sub-)sample for all of the lags when a selected max order is given to find optimal minimal lag order of the autoregressive process.
#'
#' Augmented Dickey-Fuller test (for unit root testing) that uses common (sub-)sample for all of the lags when a selected max order is given to find optimal minimal lag order of the autoregressive process. 
#' The test is based on J.G. McKinnons' numerical distribution functions. 
#' MacKinnon, J.G. (1996); Numerical distribution functions for unit root and cointegration tests, J of Applied Econometrics 11, p. 601 618.
#' The default value of max is Schwert's approximation (Schwert, G.W. (1989). Tests for Unit-Roots: A Monte Carlo investigation. Journal of Business and Economic Statistics 7, 147-159.) 
#' Usage: adfcs(t, max = floor(12*(length(t)/100)^(1/4)), type = c("c")). I thank Fabian Scheipl, Dept. of Statistics, LMU Munich for his helpful suggestions during the construction of adfcs. 
#' When data frame is supplied for the parameter t, specify the column of the variable for which the ADF test is wanted .
#'
#' @param t a numeric vector or time series object whose stationarity is examined
#' @param max selected max lag order to find optimal minimal lag order for the autoregressive process in ADF test. The default is Schwert's approximation: \eqn{\left\|12\left(\frac{length(t)}{100}\right)^{1/4}\right\|}
#' @param type a character string describing the type of the unit root  regression. Valid choices are "nc" for a regression  with no intercept (constant) nor time trend, and "c"  for a regression with an intercept (constant) but no time  trend, "ct" for a regression with an intercept  (constant) and a time trend. The default is "c".
#' @return Augmented Dickey-Fuller test that uses common sample for all of the lags.
#' @author Erdogan Cevher erdogancevher@@gmail.com
#' @seealso \code{\link{VARomlop}}
#' @examples
#' ## ADF test for the 1st variable in granger.df, max length is that of Schwert's approximation (default).
#' # adfcs(granger.df[,1])
#' ## ADF test for the 3rd variable in granger.df, max length is 10.
#' # adfcs(granger.df[,3], 10)
#' @importFrom fUnitRoots unitrootTest
#' @export
adfcs <- function(...

【问题讨论】:

  • 您可能应该在序言中包含xfrac package,以便使用\sfrac。但是,我建议只使用1/4
  • @Werner 要将包添加到序言中,我从 link 得到了提示。我在 .R 文件中添加了#' header-includes: #' - \usepackage{xfrac} 以包含 xfrac 包以使用 \sfrac。我触发了R CMD check mypackage。出现错误:* checking whether package 'mypackage' can be installed ... WARNING Found the following significant warnings: Warning: C:/Users/User/Documents/Revolution/mypackage/man/adfcs.Rd:31: unknown macro '\usepackage'。看来我无法实现如何将 TeX 包包含到 R 的序言中。
  • 那么您正在使用 Rmarkdown 并编译为 PDF?您真的应该向社区提供您的代码的完整示例,而不仅仅是零碎的 sn-ps。
  • @Werner,我添加了 .R 文件的完整序言。 AFAIK,我不使用 Rmarkdown。我使用 roxygen2 包。 #' 标签是 roxygen2 包的必需标签。 roxygen2 自动从 .R 文件生成 .Rd 文件(在roxygenize("mypackage") 上)。从那里,从命令提示符,通过R CMD check mypackge,我自动获取 .PDF 文件(我安装了 MikTex 和 TexNicCenter;GScript;GSview 以及所有正确设置)。

标签: r pdf latex


【解决方案1】:

1.我找到了一个免费的在线/实时/所见即所得的乳胶转换器:https://www.codecogs.com/latex/eqneditor.php

在本网站;通过反复试验,我发现了 Schwertz 公式的乳胶语法:

\left\|12\left(\frac{length(t)}{100}\right)^{1/4}\right\|

(我建议通过空格(单击上面的数学符号时)将乳胶标签彼此分开,以进一步发现/了解乳胶标签的工作。)删除标签之间的所有空格不会影响结果数学表达。

2.然后,我将上面的codecogs的乳胶代码替换为\eqn{...}标签:

#' @param max selected ...The default is Schwert's approximation: \eqn{\left\|12\left(\frac{length(t)}{100}\right)^{1/4}\right\|}

我没有在 .R 文件的序言中添加任何内容。

3. 然后,我从 DOS 命令提示符重新触发了R CMD check mypackage

这一次,包裹检查没有任何问题。我获得了 .PDF 文件,其中上述 .jpg 的内容比照显示。

(如果我能执行 Werner 的解决方案,我也会把它放在这里)

【讨论】:

  • 这基本上是维尔纳对您问题的评论的建议:使用1/4 而不是\sfrac{1}{4}
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-26
  • 2020-04-02
  • 1970-01-01
相关资源
最近更新 更多