Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
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
show 1 more comment

1 Answer

up vote 7 down vote accepted

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.

share|improve this answer
    
Thank you, that fixed it. Turns out, I had vim set to use BOM. –  mSSM May 30 '12 at 23:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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