Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在rmarkdown/knitr文档(或pandoc->;TeX输出)中包含TeX注释_R_Latex_Knitr_R Markdown_Pandoc - Fatal编程技术网

在rmarkdown/knitr文档(或pandoc->;TeX输出)中包含TeX注释

在rmarkdown/knitr文档(或pandoc->;TeX输出)中包含TeX注释,r,latex,knitr,r-markdown,pandoc,R,Latex,Knitr,R Markdown,Pandoc,我想在我的.Rmd文件中包含一条注释,该注释将包含在源.tex中。最终目标是在.tex源代码中创建“锚定”/“标记”,我可以稍后使用grep获取这些锚定”/“标记”,以分割输出的块以包含在其他文档中 建议使用HTML样式的注释看起来很有希望,但我认为pandoc在转换为TeX之前会删除该注释,因为包含此类注释的源文件是不变的。上面提到的spin的使用看起来很有希望,但我对spin不太熟悉,而且我似乎必须将我的整个文档翻转才能使这种方法起作用(?)。或者至少用spin而不是knit开始编译(不理想

我想在我的
.Rmd
文件中包含一条注释,该注释将包含在源
.tex
中。最终目标是在.tex源代码中创建“锚定”/“标记”,我可以稍后使用
grep
获取这些锚定”/“标记”,以分割输出的块以包含在其他文档中

建议使用HTML样式的注释
看起来很有希望,但我认为
pandoc
在转换为
TeX
之前会删除该注释,因为包含此类注释的源文件是不变的。上面提到的
spin
的使用看起来很有希望,但我对
spin
不太熟悉,而且我似乎必须将我的整个文档翻转才能使这种方法起作用(?)。或者至少用
spin
而不是
knit
开始编译(不理想)。如其他地方所述(例如),仅包含带有
%
的文本将被消毒

示例文档和所需输出:

---
output:
  pdf_document:
    keep_tex: yes
---

% [[BEGIN]]

Body of document

% [[END]]
进入
.tex
文件:

\documentclass[]{article}
%Remainder of knitr/pandoc-produced preamble
\begin{document}

% [[BEGIN]]

Body of document

% [[END]]


\end{document}

只是在这里胡闹。您必须对
.tex
文件进行一些后处理,以除去
%
之前的额外
\
(在
粘贴
版本中)或移除
逐字标记(在逐字版本中)。还在想

这是rmarkdown文件:

---
output:
  pdf_document:
    keep_tex: yes
header-includes:
  - \usepackage{verbatim}
---

\begin{verbatim}
% Comment inside verbatim environment
\end{verbatim}

\verbatim{% Comment inside verbatim}

`r paste("% Commment inside paste")`

Body of document  

% [[END]]
\begin{document}

\begin{verbatim}
% Comment inside verbatim environment
\end{verbatim}

\verbatim{% Comment inside verbatim}

\% Commment inside paste

Body of document

\% {[}{[}END{]}{]}


\end{document}
这是
tex
输出文件:

---
output:
  pdf_document:
    keep_tex: yes
header-includes:
  - \usepackage{verbatim}
---

\begin{verbatim}
% Comment inside verbatim environment
\end{verbatim}

\verbatim{% Comment inside verbatim}

`r paste("% Commment inside paste")`

Body of document  

% [[END]]
\begin{document}

\begin{verbatim}
% Comment inside verbatim environment
\end{verbatim}

\verbatim{% Comment inside verbatim}

\% Commment inside paste

Body of document

\% {[}{[}END{]}{]}


\end{document}
回应您的评论:如果您只需要能够搜索特定文本(“标签”),那么下面的内容如何:

---
output:
  pdf_document:
    keep_tex: yes
---

\phantom{BB} This is the first line of the body. Then there's a whole bunch of 
stuff, like the text in an SO question: I'd like to include a comment in my .Rmd
 file that will be included in the source .tex. The ultimate goal is to create 
"anchors"/"tags" in the .tex source that I can pick up with grep later to split 
off chunks of the output for inclusion in other documents.

The suggestion here to use HTML-style comments <!-- Comment --> looked 
promising, but I think pandoc removes this before converting to TeX since the 
source file is unchanged by including such comments. The use of spin mentioned 
here looks promising, but I'm not too familiar with spin, and it looks like I'd 
have to upend my whole document for this approach to work (?). Or at least start 
compiling with spin instead of knit (not ideal). As noted elsewhere (e.g., 
here), simply including text with % will be sanitized. Then, finally, we get to 
the very last line of the body.\phantom{EE}
---
输出:
pdf\U文件:
泰克斯:是的
---
\幻影{BB}这是身体的第一行。然后有一大堆
内容,比如SO问题中的文本:我想在我的.Rmd中包含一条注释
将包含在source.tex中的文件。最终目标是创造
.tex源中的“锚”/“标记”,我可以稍后使用grep进行拆分
删除输出的块以包含在其他文档中。
这里建议使用HTML样式的注释
很有希望,但我认为pandoc在转换为TeX之前删除了它,因为
源文件通过包含此类注释而保持不变。提到了自旋的使用
这里看起来很有希望,但我对旋转不太熟悉,而且看起来我
为了使这种方法起作用,我必须把我的整个文档都翻过来(?)。或者至少开始吧
使用spin而不是knit进行编译(不理想)。如其他地方所述(例如。,
此处),仅包含带有%的文本将被清除。然后,最后,我们到达
正文的最后一行。\phantom{EE}
借用, 我们可以定义一个新命令,该命令不向文档设置任何打印内容,但允许您将任何内容放置在命令的大括号内。这似乎很顺利

---
output:
  pdf_document:
    keep_tex: yes
header-includes:
  - \usepackage{verbatim}
  - \newcommand{\comm}[1]{}
---

La la la

\comm{START OF BLOCK 1}

Here is the text that goes inside of the first block

\comm{END OF BLOCK 1}

Here is some text that is not between "comment" blocks.

可能将
cat(“%[[BEGIN]]”)放入一个
结果为'asis'
的块中?(未经测试)@Benjamin我不相信这会起作用——这就是
xtable
注释块的基本情况,如下所述:现在我在电脑前,我明白我为什么这么想了。
%
表格
环境中调用一条注释,这是我最常遇到它的地方。哦,这实际上是一个灵感。关键是在.tex源代码中不可见地显示某些内容。我刚刚尝试了几种使用
\phantom{BEGIN}
的方法;问题是1)它仍然“出现”,因为它会留下空白(因此它不能在自己的行上),2)我无法在标题中编译它:
\TEST$\phantom{TEST}$
给出了一个错误。有什么相关的想法吗?见我答案的附录。是的,我想可以。。。不理想(如果这是knitr pdf输出的优先事项,可能会产生样式问题,最好使用具有有意义名称的标记来匹配,而不是缩写)。。。坚持为nowAFK提供更“正式”的方法,因此无法再进行测试。。。在这些地方加上一个没有参考的标签怎么样?太好了。只需将我的
grep
更改为查找
\comm{BEGIN}
(实际上我将使用
\TAG
)而不是
%BEGIN