knitr: echo chunk does not work when using a seperate boilerplate / setup file

StackOverflow https://stackoverflow.com/questions/23364563

  •  11-07-2023
  •  | 
  •  

I have identified an issue with knitr where the use of a central file to hold setup stuff like

\documentclass{article}
\usepackage[T1]{fontenc}

and defined styles, margins etc will cause errors when a knitr chunk has echo=TRUE set.

I've produced a MWE on github as it requires at least two files. https://github.com/stephlocke/knitrhighlighting

I've raised a request on the knitr github to accomodate \input commands but I'm hoping that someone can suggest the correct combination of code to be added to the setup file that would allow the code highlighting to go ahead in the interim.

I have tried adding

\usepackage{framed}
\usepackage{alltt}

but still get the following error

! LaTeX Error: Environment kframe undefined.
有帮助吗?

解决方案

Thanks to Yihui (https://github.com/yihui/knitr/issues/765), moving the \documentclass{} into the .Rnw file instead of the boilerplate document is sufficient to ensure this works.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top