[Tikzdevice-bugs] getMetrics error

Charlie Sharpsteen chuck at sharpsteen.net
Tue Aug 2 17:47:29 CEST 2011


On Tuesday, August 2, 2011 12:48:25 AM UTC-7, Berner Larsen wrote:

(some editing to remove email link noise)

I got the same getMetrics error as is described in the message from Anh 
> Nguyen:


    https://groups.google.com/d/topic/tikzdevice/iNPWtQVAcuA/discussion 

>  I do not think that the problem is the use of pdflatex instead of xelatex 
> or the Zapfino font as is described in the answer.
>
 

> I think the problem is the string "%\n" in line 364 in the source file 
> latexStrWidth.R of tikzDevice. In the file error-output.txt we see the 
> result of these two characters in latexStrWidth.R as "%" at the end of line 
> 35 and a line break. The % character starts a Latex comment and the end of 
> line character finishes a Latex comment. However, the line break character 
> \n is not (at least in this case)  recognized in Windows as the end of line 
> character which imply that the next } is interpreted as a part of the 
> comment, so the Latex run is aborted due to a missing }. The character \n is 
> the end of line character in the UNIX world, but in Windows \r\n is the end 
> of line character. Windows 7 seems to interpret \n as end of line more often 
> than Windows XP, as the getMetrics error occurs more often on my home PC 
> with Windows XP than on my office PC with Windows 7. E.g. on my office PC, 
>  plot(1:15,main="{-1.5%\vab}") gives a getMetrics error when pgfSweave is 
> run, while plot(1:15,main="{-1.5%\rab}") gives the title "-1.5ab" as 
> expected.
>
>  
>
> As a check of my hypothesis,  I downloaded the source code of version 0.6.1 
> of the tikzDevice package from CRAN, deleted the character string "%\n" from 
> line 364 in latexStrWidth.R and installed this modified version of the 
> tikzDevice package, and afterwards  I did not get the getMetrics error 
>  described in the file error-output.txt when I ran pgfSweave on my home PC 
> with Windows XP.
>
>  
>
> Naturally, a getMetrics error may occur due to another reason than the bug 
> described above. There are at least two another reasons why a getMetrics 
> error may occur:
>
> 1.      When MiKTeX 2.9 is installed the default MiKTeX option of "Install 
> missing packages on-the fly" is "Ask me first". A better choice is probably 
> "Yes". This is due to the fact that when tikzDevice computes the Latex 
> string width it calls Latex and uses the Latex package "preview" which is 
> not part of the basic MiKTeX installation. (I think few persons install the 
> complete MiKTeX system as this is very time and disc consuming.) The 
> pdflatex run is aborted if the preview package is not present and a 
> getMetrics error occurs.
>
> 2.      A TeX string with a syntax error, e.g. a missing } or $ or an 
> undefined control sequence, will also cause a getMetrics error.
>

Hmmm, that is some interesting information. Thanks for taking the time to 
report it!

I always thought that R replaced "\n" with whatever platform-specific 
newline sequence was required but it appears that this may not be the case. 
 Commenting the line end is commonly done in LaTeX macros to prevent 
unwanted whitespace. However, looking back at this line of code, it doesn't 
really seem necessary, so I will probably just pull it out if it is causing 
a problem.

-Charlie


More information about the Tikzdevice-bugs mailing list