2

I'm working on a knitr document and trying to place knitr output inside of a new environment defined using the environ package.

The example below illustrates the problem. With a traditional LaTeX environment definition, the resulting LaTeX output is as expected and the document compiles with no problems. (I want to use environ for other reasons.) But using the environ package, the resulting LaTeX is identical (except for the relevant lines indicated below) but the document won't compile, throwing multiple errors.

\documentclass{article}

% This works
\newenvironment{newenv}{}{}

% This doesn't
\usepackage{environ}
\NewEnviron{newenv}{\BODY}{}

\begin{document}

\begin{newenv}
<<test>>=
l <- list(a=1)
print(l$a)
@ 
\end{newenv}
\end{document}

The situation is similar to that described in this earlier question but in this case, the inner environment is actually four nested knitr environments. To my reading, this means that both of the solutions offered on that question (the accepted one and the newenviron package) are probably impossible here or at least very ugly. Any suggestions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.