5

I'm having problems inputting a TikZ picture in a document that is encoded with UTF-8. The TikZ picture was generated with matlab2tikz.

When I try to open the foo.tikz file with my editor (Texmaker), it says:

The file cannot be read correctly with the default enconding (UTF-8).
Use the following codification: ISO-8859-1

My preamble is the following:

\documentclass[a4paper,12pt]{article}
\usepackage[catalan]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
blà blà blà
blà blà blà
\begin{figure}[ht!]
  \centering
  \newlength\figureheight
  \newlength\figurewidth
  \setlength\figureheight{6cm}
  \setlength\figurewidth{6cm}
  \input{foo.tikz}
\end{figure}
\end{document}

When I input the foo.tikz file in my document, an error happens because some of the characters included are undefined in input-encoding 'utf8'.

The problem is that I have to use UTF-8 encoding because I'm not writing in English and I have to use a lot of accents and other characters.

What can I do in order to input this picture in my document? I thought about using multiple encodings in the document, but I don't know if this can be done. Or converting the TikZ file to utf8 encoding, but I don't know how I could do this, if possible.

6
  • 1
    Is your TikZ file saved as UTF8? Check with some editor. We cant help here, as we do not see the problematic TikZ code. Please add it to your OP. If you have really fancy stuff in you image, you could compile it separately and insert the resulting PDF to your document.
    – LaRiFaRi
    May 13, 2015 at 9:30
  • I forgot: Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – LaRiFaRi
    May 13, 2015 at 9:30
  • @LaRiFaRi Thanks! And that is a good idea since the plot is too dense. I will try to compile it separately and inserting the PDF to my document. So that, I don't have to deal with encoding problems.
    – Airman01
    May 13, 2015 at 9:43
  • 1
    From your description seems like matlab2tikz file is encoded in ISO-8859-1 while TeXMaker tries to read it with utf8 encoding. You can change TeXmaker encoding under Options+Editor. Although it's better to use it, you don't need to use utf8 for accents, latin1 is enough.
    – Ignasi
    May 13, 2015 at 10:03
  • 1
    Ah! i benvingut! Ja som més.
    – Ignasi
    May 13, 2015 at 10:03

1 Answer 1

4

You can tell LaTeX to use another input encoding locally:

\documentclass[a4paper,12pt]{article}
\usepackage[catalan]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
blà blà blà
blà blà blà
\begin{figure}[ht!]
  \centering
  \newlength\figureheight
  \newlength\figurewidth
  \setlength\figureheight{6cm}
  \setlength\figurewidth{6cm}
  \begingroup
  \inputencoding{latin1} % or whatever
  \input{foo.tikz}
  \endgroup
\end{figure}
\end{document}

In this case it should work without problem, but I wouldn't recommend it in all cases: If auxiliary files are involved (glossaries, index, etc) mixing encodings can get confusing.

1
  • Thank you very much! It worked fine without having to compile the picture separately.
    – Airman01
    May 13, 2015 at 12:06

You must log in to answer this question.

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