【问题标题】:knitr parses extra verbatim documentclassknitr 解析额外的逐字文档类
【发布时间】:2016-03-12 16:34:49
【问题描述】:

我想在使用 knitr 解析的 Rnw 文档中包含一个完整的 LaTeX 代码示例。

此处显示了我的 .Rnw 文件(我真的也想包含一堆 R 代码,但这个最小的示例显示了我的问题)

\documentclass{article}

\begin{document}    
Recursiveness, see     
\begin{verbatim}
\documentclass{article}
\begin{document}
Recursiveness
\end{document}
\end{verbatim}

\end{document}

当我运行knitr test.Rnw 时,我得到一个.tex 文件,其中第二个documentclass 被替换(见下文,其中显示了.tex 文件的顶部)。我很确定这是knitr,它用自己的宏替换了文字字符串\documentclass,并且它没有意识到在逐字环境中它不应该被解析。

\documentclass{article}
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document}

Recursiveness, see 

\begin{verbatim}
\documentclass{article}\usepackage[]{graphicx}\usepackage[]{color}
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
  \ifdim\Gin@nat@width>\linewidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother

是否有可能绕过这一点?我试图在documentclass 的中间插入一个零宽度的空格字符,但这让我在解析时很头疼。

【问题讨论】:

  • 抱歉,没有时间再回答了,但是添加一个带有 knitr::opts_knit$set(self.contained = FALSE) 的块是一种解决方法。

标签: r latex knitr


【解决方案1】:

这是一个错误,现在应该是当前development version of knitr (>= 1.12.22) 中的fixed

【讨论】:

    猜你喜欢
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多