8

I am getting random characters displayed in my TikZ images:

Random characters with TikZ

I have just noticed this recently. I am not sure what this might be caused by. I am using the latest TikZ build from TeXample.

I only observe this behaviour, when I create the image by using \input{} on my TikZ code, like so:

\documentclass{minimal}

\usepackage[T1]{fontenc}

\usepackage{tikz}

\begin{document}
    \input{test.tikz}
\end{document}

Where test.tikz is just:

\begin{tikzpicture}%
    \draw (-1,0) -- (1,0);
\end{tikzpicture}

If I were to directly insert the TikZ code (without inputing an external file), everything works nicely:

Normal TikZ

Also, removing \usepackage[T1]{fontenc} "fixes" the problem.

Any ideas what's going on there?

6
  • 1
    You probably have a BOM (byte ordering mark) in the input file.
    – egreg
    Commented May 30, 2012 at 22:52
  • @egreg: Great! :D What am I to do about that?
    – mSSM
    Commented May 30, 2012 at 23:02
  • It depends on what editor you're using. Find in its preferences something regarding BOM.
    – egreg
    Commented May 30, 2012 at 23:06
  • Also if it doesn't mention BOM anywhere obvious but does mention encodings save as ascii rather than utf-8. Commented May 30, 2012 at 23:07
  • Well, it is ascii: `❯ file -i test.tikz \n test.tikz: text/plain; charset=us-ascii
    – mSSM
    Commented May 30, 2012 at 23:10

1 Answer 1

9

Some editors declare at the beginning of the file which UTF encoding they are using, with the so called byte order mark (see http://en.wikipedia.org/wiki/Byte_order_mark).

In the case of UTF-8, the BOM is formed by the three bytes 0xEF 0xBB 0xBF, which, in the T1 encoding correspond exactly to

ïż£

This diagnosis is confirmed by the evidence you give: avoiding inputting the file doesn't show the characters. If you remove \usepackage[T1]{fontenc}, you'll be using OT1 encoded fonts that have nothing in those slots (and you'll get "Missing character" messages in the log file).

Find where your editor setup is writing the BOM and switch off that option.

1
  • Thank you, that fixed it. Turns out, I had vim set to use BOM.
    – mSSM
    Commented May 30, 2012 at 23:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .