2
votes

I am using R's knitr and LaTeX to create a pdf. Technic Center gives "!Undefined control sequence" for Build Output errors. Technic Center indicates that lines with \begin{kframe} and \end{kframe} are the problematic lines.

Removing the kframe environment resolves the errors from the Build Output, but the document does not display a shadecolor for code chunks even when the kframe environment is removed.

I updated my MikTex packages and knitr. The document's preamble includes \usepackage{framed}; \usepackage{xcolor} does not seem to influence the problem. Changing the knitr background option did not fix the problem.

Here is the preamble of my document in the Rnw file (knitr adds to this):

\documentclass{article}
\usepackage{Sweave}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage[margin = 0.5in]{geometry}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{marvosym}
\usepackage{paralist}
\usepackage{framed}
\usepackage{url}
\usepackage{xcolor}
\usepackage{array}

\renewcommand\qedsymbol{\Squarepipe}

\title{title changed for question}
\author{author changed for question}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}

\newenvironment{definition}[1][Definition]{\begin{trivlist}
    \item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}
\newenvironment{conjecture}[1][Conjecture]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}
\begin{document}

Thank you!

1

1 Answers

0
votes

The kframe environment should be defined in your latex preamble. It is defined for example in the example visible in help(knit)

 library(knitr)
 (f = system.file("examples", "knitr-minimal.Rnw", package = "knitr"))
 knit(f)  # compile to tex

Looking at the generated document knitr-minimal.tex you can see the definition of the kframe environment:

\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
 \def\at@end@of@kframe{}%
 \ifinner\ifhmode%
  \def\at@end@of@kframe{\end{minipage}}%
  \begin{minipage}{\columnwidth}%
 \fi\fi%
 \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
 \colorbox{shadecolor}{##1}\hskip-\fboxsep
     % There is no \\@totalrightmargin, so:
     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
 \MakeFramed {\advance\hsize-\width
   \@totalleftmargin\z@ \linewidth\hsize
   \@setminipage}}%
 {\par\unskip\endMakeFramed%
 \at@end@of@kframe}
\makeatother

Adding this to your latex preamble might solve the issue. This is of course taken care of when you generate complete pdf documents from knitr. It is only an issue when you use knitr to generate Latex fragments, later reused in larger Latex documents.