I'm very new to knitr. How do I write R code in knitr that composes LaTeX from scratch and injects it into the document at a particular point?
I'm thinking of something similar to what PHP or JSP does.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI'm very new to knitr. How do I write R code in knitr that composes LaTeX from scratch and injects it into the document at a particular point?
I'm thinking of something similar to what PHP or JSP does.
TeX is a text for knitr
, so you can use any text-generating function, e.g. cat()
. To include the text into the document, add echo=FALSE, results='asis'
to the chunk options, e.g.
<<echo=FALSE,results="asis">>=
title="Introduction"
cat(paste("\\section{",title,"}",sep=""))
@
which adds to your document \section{Introduction}