我有一个.Rnw
文件,Knitr
在我后端数据集发生变化之前,它编译得非常好。可能那时图表的大小也发生了变化。由于我不明白的原因,knitr
现在突然停止编译并LaTex
开始编译.tex
Knitr 生成的未完成文件。我猜这是发生了什么,因为我在活动监视器(ESS 缓冲区)中看到日志被knitr
替换为日志LaTex
。接下来我粘贴了日志的最后一部分,其中正常knitr
过程的最后几行,该过程加载了一个 R 脚本来生成 ggplot,被替换为LaTex
...
grid.arrange(gp2,gp1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##------ Thu Oct 10 18:39:42 2013 ------##
\documentclass[nohyper]{tufte-handout}
\nonstopmode
\usepackage{tikz}
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.26 \usepackage
{tikz}
Here is how much of TeX's memory you used:
15456 strings out of 493311
278701 string characters out of 6137850
379859 words of memory out of 5000000
18583 multiletter control sequences out of 15000+600000
4403 words of font info for 15 fonts, out of 8000000 for 9000
957 hyphenation exceptions out of 8191
56i,0n,92p,470b,151s stack positions out of 5000i,500n,10000p,200000b,80000s
! ==> Fatal error occurred, no output PDF file produced!
Quitting from lines 1-81 (my/path/time_series.R)
Quitting from lines 84-NA (my/path/time_series.R)
Error in getMetricsFromLatex(TeXMetrics) (from #91) :
TeX was unable to calculate metrics for the following string
or character:
Label
Common reasons for failure include:
* The string contains a character which is special to LaTeX unless
escaped properly, such as % or $.
* The string makes use of LaTeX commands provided by a package and
the tikzDevice was not told to load the package.
The contents of the LaTeX log of the aborted run have been printed above,
it may contain additional details as to why the metric calculation failed.
我无法弄清楚问题出在哪里,因为我在knitr
日志中没有看到任何线索。显然,阻止编译的.Rnw
是tikzDevice
用这些行生成的图表:
\begin{figure*}
\centering
<<child-time_series, child='figure/time_series.R',dev='tikz',fig.width=6,fig.height=3,out.width='.95\\textwidth',message=FALSE,echo=FALSE>>=
@
\label{fig:TimeSeries}
\end{figure*}
我猜关键是以下LaTex
错误(也在上面)
Error in getMetricsFromLatex(TeXMetrics) (from #91) :
TeX was unable to calculate metrics for the following string
or character:
Label
Label
是我的情节的标签。
答案1
对于名为 的块foo
,knitr
首先在图形设备为 时figure/foo.tikz
使用包生成。然后通过(或根据您的设置使用其他 LaTeX 引擎)将此文件编译为 PDF 。如果此过程中出现任何问题,您可以tikzDevice
tikz
knitr
.tikz
pdflatex
- 检查日志文件
figure/foo.log
中的错误消息 - 打开
figure/foo.tikz
(它应该是一个完整的 LaTeX 文档),看看是否能发现任何错误 cd figure/; pdflatex foo.tikz
在终端中尝试,看看pdflatex
说什么(你最好\nonstopmode
删除foo.tikz
)
从您发布的错误日志来看,中的 LaTeX 序言似乎有问题foo.tikz
。