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.
Sample document and desired output:
---
output:
pdf_document:
keep_tex: yes
---
% [[BEGIN]]
Body of document
% [[END]]
Into .tex file:
\documentclass[]{article}
%Remainder of knitr/pandoc-produced preamble
\begin{document}
% [[BEGIN]]
Body of document
% [[END]]
\end{document}