2

When compiling R code within a child, I get the following error.

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.

The file worked flawlessly until I changed one tiny detail that I cannot recall. The tikzDictionary is in the directory of the first child containing R-code. I removed the tikZDictionary to no avail. The file created is empty (0 Bytes). Taking the code and compiling it in a file with the appropriate headers works fine. I tried copying the contents of the whole thesis to a new folder and recompile it there, but the same problems occur there.

> 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

Copying all relevant files to a new directory and trying to compile it throws the same error.

1) Can one try to force the tikZdevice to recalculate the metrics?!

2) Can I get the correct metrics from elsewhere?

Thank you so much for your help.


I got it to work after a total of about 6 hours. I put all the R-Code in the main file, it compiles flawlessly. The ´main-tikzDirectory´ is in the same directory as the ´main´.

However, it is about 1000 lines of R code (we're talking about the results party of my whole thesis...), which I would rather have in a separate file.


As soon as I place anything in a child I get the same error. Also, while the error had been thrown in the ´R´ console before and no tex file is produced, when using the minimal example below the error message is written to the tex-file.

I provide a minimal example:

\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}

The child is located some folders below.

<<corruption>>=
plot(runif(100,0,1)^2)
@
isokinetic
  • 21
  • 2
  • Please add a minimum reproducible example. But my best guess is: You used LaTeX math syntax where not in math mode (e.g. outside `$...$`) (or some other LaTeX syntax error, but that's my personal favorite …). – CL. May 10 '17 at 08:09
  • I added an example above. – isokinetic May 10 '17 at 08:49
  • Not posting this as an answer, because … it's confusing. You say that pasting everything in your main document works fine, but having it in the child fails. To me, it looks like this plot always fails (no matter in which document), because `runif(100,0,1)^2` generates a y-label that is invalid LaTeX. Preventing this (e.g. `ylab=""`) solves the issue, no matter if in a child or in the main document. But honestly, for me the question is too convulted to find a better explanation. (Hint: a MWE should look more like [this](https://gist.github.com/anonymous/6c3bb5c66f876efe03acd49c7c3abec1).) – CL. May 10 '17 at 09:20

0 Answers0