[Tikzdevice-bugs] getMetrics error

547 views
Skip to first unread message

Berner Larsen

unread,
Aug 2, 2011, 3:48:25 AM8/2/11
to tikzdev...@r-forge.wu-wien.ac.at
I got the same getMetrics error as is described in the message from Anh Nguyen eatabanana at gmail.com <mailto:tikzdevice-bugs%40lists.r-forge.r-project.org?Subject=Re%3A%20%5BTikzdevice-bugs%5D%20getMetrics%20error&In-Reply-To=%3CAANLkTik5uuZhyPcuWt7B2X9q%2B6%3DrEfFw8e3Qp9zMD7W7%40mail.gmail.com%3E>

Mon Mar 7 22:47:10 CET 2011. 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 from Sharpie chuck at sharpsteen.net <mailto:tikzdevice-bugs%40lists.r-forge.r-project.org?Subject=Re%3A%20%5BTikzdevice-bugs%5D%20getMetrics%20error&In-Reply-To=%3C1260540.3450.1299563468356.JavaMail.geo-discussion-forums%40prgz35%3E> Tue Mar 8 06:51:08 CET 2011.

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.

Berner Larsen

Tel: +47 75517282 / +47 48121112

Berner...@uin.no <mailto:navn.n...@uin.no>

http://www.uin.no <http://www.uin.no/>


Bodø Graduate School of Business

error-output.txt

Charlie Sharpsteen

unread,
Aug 2, 2011, 11:47:29 AM8/2/11
to tikzd...@googlegroups.com, tikzdev...@r-forge.wu-wien.ac.at
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.
>

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

Shaun Siau

unread,
Sep 15, 2011, 7:07:07 AM9/15/11
to tikzd...@googlegroups.com, tikzdev...@r-forge.wu-wien.ac.at


On Tuesday, 2 August 2011 17:48:25 UTC+10, Berner Larsen wrote:

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.


I think this is worth emphasizing. I spent an hour figuring out what's wrong with my MiKTeX installation (since the pgf package has already been installed).
But yeah, the preview package is also necessary for proper functioning.

Maybe a brief notice to MiKTeX users would be useful here?

Regards,
Shaun
Reply all
Reply to author
Forward
0 new messages