tikzDevice 无法用于基本示例

问题描述 投票:0回答:2

考虑以下示例:

library(tikzDevice)
tikz("test.tex")
plot(1:10)
dev.off()

创建绘图后会产生错误,代码很多,但接近结束时出现错误:

("C:\ProgramError in getMetricsFromLatex(TeXMetrics, verbose = verbose) : 
TeX was unable to calculate metrics for the following string
or character:

    m

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.
In addition: Warning messages:
1: In readLines(texLog) :
  incomplete final line found on 'C:\Users\cgmil\AppData\Local\Temp\Rtmp6FouwP/tikzStringWidthCalc.log'
2: In readLines(texLog) :
  incomplete final line found on 'C:\Users\cgmil\AppData\Local\Temp\Rtmp6FouwP/tikzStringWidthCalc.log'

发生什么事了?

r plot latex tikz tikzdevice
2个回答
0
投票

有点晚了...

您应该有一个 .tex 文件,其中包含

C:\Users\cgmil\AppData\Local\Temp\Rtmp6FouwP/
中绘图的 tikz 代码。只需替换最后两行即可

\makeatletter
\@@end

\end{document}
\end{tikzpicture}

然后编译文档。将安装新软件包并且它应该可以工作。


0
投票

我迟到了 7 年,但也许其他人将来也会遇到这个问题。我是这样修复的:

  • 首先从
    https://ctan.org/pkg/preview?lang=en
    下载软件包preview
  • 在任何地方解压缩 zip,打开 powershell 或 git bash 并运行
    tex preview.ins
  • 获取生成的
    preview.sty
    并将其复制到文件夹
    C:\texlive\2024\texmf-dist\tex\latex\preview
    (您可能需要创建此文件夹
  • 在之前的 bash 中(或者任何地方),运行
    texhash
© www.soinside.com 2019 - 2024. All rights reserved.