2013-12-12 26 views
2

knitr編譯並生成pdf文件,但由knitr生成的tex文件不能編譯(使用livetex)使用texlive,爲什麼我可以將knitr Rnw文件編譯爲pdf而不是從編織R輸出到pdf

這裏是test.Rnw

\documentclass[letter]{article} 
\title{y} 
\author{z} 
\begin{document} 
\maketitle 
<<assignment, echo = TRUE>>= 
(X <- 10) 
@ 
\end{document} 

下產生pdf文件:texi2pdf(file = "test.tex", clean = TRUE)

由knitr產生的reamble有一個問題:

\usepackage{framed} 
\makeatletter 
\newenvironment{kframe}{% 
\def\[email protected]@[email protected]{}% 
\ifinner\ifhmode% 
    \def\[email protected]@[email protected]{\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\[email protected] \linewidth\hsize 
    \@setminipage}}% 
{\par\unskip\endMakeFramed% 
\[email protected]@[email protected]} 
\makeatother 

下面是錯誤:

\begin{minipage} does not have matching end; at least one unbalanced 
begin-end test.tex /tests-R line 39 Problem 

\end{minipage} found with no preceding \begin test.tex /tests-R line 38 

出於顯而易見的原因,至少有一個出版商希望TEX文件,而不是RNW文件

+0

無法在我的機器上重現此操作。什麼是livetex? – EDi

+0

無法在我的機器上重現。 Ubuntu 13.10 + TeXLive 2013. –

+0

同上Ubuntu 12.04 TeXLive 2009 –

回答

0

我還沒有收到一個錯誤。使用從RStudio「編譯PDF」按鈕,創建以下* .tex文件,我可以編譯使用TexMaker:

\documentclass[letter]{article} 
\usepackage[]{graphicx} 
\usepackage[]{color} 
%% maxwidth is the original width if it is less than linewidth 
%% otherwise use linewidth (to make sure the graphics do not exceed the margin) 
\makeatletter 
\def\maxwidth{ % 
\ifdim\[email protected]@width>\linewidth 
\linewidth 
\else 
\[email protected]@width 
\fi 
} 
\makeatother 

\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345} 
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}% 
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}% 
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}% 
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}% 
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}% 
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}% 
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}% 
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}% 
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}% 

\usepackage{framed} 
\makeatletter 
\newenvironment{kframe}{% 
\def\[email protected]@[email protected]{}% 
\ifinner\ifhmode% 
\def\[email protected]@[email protected]{\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\[email protected] \linewidth\hsize 
\@setminipage}}% 
{\par\unskip\endMakeFramed% 
\[email protected]@[email protected]} 
\makeatother 

\definecolor{shadecolor}{rgb}{.97, .97, .97} 
\definecolor{messagecolor}{rgb}{0, 0, 0} 
\definecolor{warningcolor}{rgb}{1, 0, 1} 
\definecolor{errorcolor}{rgb}{1, 0, 0} 
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX 

\usepackage{alltt} 
\title{y} 
\author{z} 
\IfFileExists{upquote.sty}{\usepackage{upquote}}{} 
\begin{document} 
\maketitle 
\begin{knitrout} 
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe} 
\begin{alltt} 
\hlstd{(X} \hlkwb{<-} \hlnum{10}\hlstd{)} 
\end{alltt} 
\begin{verbatim} 
## [1] 10 
\end{verbatim} 
\end{kframe} 
\end{knitrout} 

\end{document} 
1

我有這個問題太,但它似乎是一個路徑問題。如果yourfile.Rnw位於具有空格的路徑上,則knit2pdf將引發錯誤,並且您可以在texput.log而不是yourfile.log中看到錯誤消息。但是,如果您手動編譯yourfile.tex,則一切似乎都可以。

也許@Yihui可以說明爲什麼這可能是這種情況。

編輯這裏有一個日誌輸出:

knit2pdf("test.Rnw") 


processing file: test.Rnw 
    |......................           | 33% 
    ordinary text without R code 

    |...........................................      | 67% 
label: assignment (with options) 
List of 1 
$ echo: logi TRUE 

    |.................................................................| 100% 
    ordinary text without R code 


output file: test.tex 

Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, : 
    Running 'texi2dvi' on 'test.tex' failed. 
Messages: 
/usr/bin/texi2dvi: pdflatex exited with bad status, quitting. 
/usr/bin/texi2dvi: see test.log for errors. 

test.log不會在工作目錄中存在; texput.log確實包含此消息:

This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex 2014.7.13) 24 JUL 2014 10:04 
entering extended mode 
restricted \write18 enabled. 
file:line:error style messages enabled. 
%&-line parsing enabled. 
**\nonstopmode \input /Users/james/Documents/stack exchange/test.tex 

! Emergency stop. 
<*> ...opmode \input /Users/james/Documents/stack 
                exchange/test.tex 
*** (job aborted, file error in nonstop mode) 
+0

對不起,我無法用包含空格的目錄下的test.Rnw重現該問題。你使用Windows?你的LaTeX發行版也是TeXLive嗎? –

+0

這是在使用TeXLive(MacTeX)的Mac,R 3.1.0,knitr 1.6上。我使用輸出的日誌編輯了上面的響應。 – jkeirstead

+0

嗯......我認爲你是對的:文件路徑中的空間似乎是一個問題。謝謝! –

相關問題