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:





Where test.tikz is just:

    \draw (-1,0) -- (1,0);

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?

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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.