2

在孩子中编译 R 代码时,出现以下错误。

Error 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.

该文件完美无缺,直到我更改了一个我无法回忆的小细节。tikzDictionary 位于第一个包含 R 代码的子目录中。我删除了 tikZDictionary 无济于事。创建的文件为空(0 字节)。获取代码并将其编译到具有适当标题的文件中可以正常工作。我尝试将整篇论文的内容复制到一个新文件夹并在那里重新编译,但那里也出现了同样的问题。

> sessionInfo()
> R version 3.4.0 (2017-04-21) Platform: x86_64-apple-darwin16.5.0 (64-bit) Running under: macOS Sierra 10.12.4
> 
> Matrix products: default BLAS:
> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
> LAPACK:
> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib
> 
> locale: [1]
> en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> 
> attached base packages: [1] stats     graphics  grDevices utils    
> datasets  methods   base     
> 
> other attached packages: [1] tikzDevice_0.10-1 plyr_1.8.4       
> xtable_1.8-2      knitr_1.15.1     
> 
> loaded via a namespace (and not attached):  [1] compiler_3.4.0  
> magrittr_1.5     tools_3.4.0      Rcpp_0.12.10      [5]
> codetools_0.2-15 filehash_2.4-1   stringi_1.1.5    highr_0.6        
> [9] grid_3.4.0       digest_0.6.12    stringr_1.2.0    evaluate_0.10

将所有相关文件复制到新目录并尝试编译它会引发相同的错误。

1)可以尝试强制 tikZdevice 重新计算指标吗?!

2)我可以从其他地方获得正确的指标吗?

非常感谢你的帮助。


总共大约 6 个小时后,我让它开始工作。我把所有的 R 代码放在主文件中,它编译完美。“main-tikzDirectory”与“main”在同一目录中。

但是,它大约有 1000 行 R 代码(我们正在谈论我整个论文的结果方......),我宁愿将其放在单独的文件中。


一旦我将任何东西放在孩子身上,我就会得到同样的错误。此外,虽然之前在“R”控制台中引发了错误并且没有生成 tex 文件,但是当使用下面的最小示例时,错误消息被写入 tex 文件。

我提供了一个最小的例子:

\documentclass[10pt,a4paper]{book}


\usepackage{geometry} % Titelseite braucht eigene Margins.

%\usepackage[ngerman]{babel} % Trennungsregeln, Datumsangabe etc. in Deutsch

\usepackage[T1]{fontenc}    % europäischer Zeichensatz (Sonderzeichen, etc.)
%\usepackage[bitstream-charter]{mathdesign} % Moderne, serifenbetonte und sachliche Schriftart
\usepackage[utf8]{inputenc} % utf8 Eingabezeichensatz

\usepackage{xstring}        % Testen/Vergleichen von (Sub)Strings

\usepackage{totcount}       % Zähle Seitenzahlen, Abbildungen etc.

\usepackage{siunitx}        % SI Einheiten
    \DeclareSIUnit{\molar}{M}
%\usepackage{natbib}         % Naturwissenschaftliche Zitierungen
\usepackage[sorting=none, citestyle=nature, maxnames=99, minnames=99, backend=biber]{biblatex}
\addbibresource{bibliography/bibliography.bib}
\renewcommand*{\bibfont}{\small}

\usepackage[version=3]{mhchem} % chemische Summen- und Strukturformeln

\usepackage{eurosym}        % Euro-Zeichen

\usepackage{hyperref}                  %
\usepackage[xindy,acronym,nonumberlist,nomain]{glossaries} % Abkürzung + Abkürzungsverzeichnis
\makeglossaries      %
\usepackage{multicol}

% Grafiken
\usepackage{tikz}
\usepackage{epsfig}
\usepackage{graphics}
\usepackage{graphicx}

% Tabellen
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{tabu}
\usepackage{array}
\usepackage{rotating}
\usepackage{bigdelim}
\usepackage{multirow}
\usepackage{float}
\usepackage{colortbl}
\usepackage{xcolor}


\def\TReg{\textsuperscript{\textregistered}}
\def\TCop{\textsuperscript{\textcopyright}}
\def\TTra{\textsuperscript{\texttrademark}}

%% Nummerierung
\setcounter{secnumdepth}{4}

%% Eigene Makros
\input{config/config}
\input{macros/InOderAm}
\input{macros/HideIfZero}
\input{macros/citenumCounter}
\input{macros/totalfiguresCounter}
\input{macros/totalappendixCounter}

%% Floats erst ab 80% auf eigene Seite
\renewcommand{\floatpagefraction}{.8}%

%% Dokument

\begin{document}

%% Knitr-optionen
<<setup, echo = FALSE, results= 'hide', message = FALSE>>=
library(xtable)
library(plyr)
opts_chunk$set(fig.path='figure/graphics-', cache.path='cache/graphics-', fig.align='center', dev='tikz', external=TRUE, fig.width=5, fig.height=5, fig.show='hold', cache=TRUE, global.par=FALSE)
knit_hooks$set(par=function(before, options, envir){
if (before && options$fig.show!='none') par(mar=c(4,4,.1,.1),cex=1,cex.lab=.9,cex.axis=.9,mgp=c(2,.7,0),tcl=-.3)
}, crop=hook_pdfcrop)
@
<<results, child="content/main/results/results2.Rnw">>=
@

\end{document}

孩子位于下面的一些文件夹中。

<<corruption>>=
plot(runif(100,0,1)^2)
@
4

0 回答 0