0

I just have installed MacTex on my iMac and I have downloaded a template from my university. When I open a tex file from this template with TeXShop, there are german umlauts, but they are shown as "ö" instead of "ö" and so on. But when I set the PDF file they are shown correctly. Now my questions:

  1. Even if I set the coding from TeXShop to UTF-8 Unicode and reopen the file, the umlauts are not shown correctly. Must I replace all the wrong umlauts on my own?

  2. When I replace one of the wrong umlauts with its correct char, I'm getting the following error:

Package inputenc Error: Keyboard character used is undefined in inputencoding 'utf8'.

l.34 ...ü...

The main.tex of that template is from a class "Thesis" and in Thesis.cls are the following lines:

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

So how can I replace all the wrong values in the editor with the correct values and also make them work when I set the PDF file? I have already searched for it, but setting the coding from the editor to utf8 and using the packages like above was the only thing I have found.

  • 3
    You should use utf8 as an encoding. But it can get quite confusing to change existing files if you don't really understand encodings. I suggest that you create new files in some other folder with utf8 encoded. Add \usepackage[utf8]{inputenc} and test if the umlauts are fine and then copy and paste the old text to this files. – Ulrike Fischer Mar 26 '17 at 14:10
  • 6
    Welcome, word of advice: Get rid of that template and run away. If inputenc is used in a class file, troule is on its way. If the file is called Thesis.cls, you are in even more trouble. – Johannes_B Mar 26 '17 at 14:11
  • 3
    There are probably a zillion LaTeX document class files called Thesis.cls available on the Internet -- where did yours come from? – Mico Mar 26 '17 at 14:12
  • 2
    Welcome to TeX.SX! Your editor thinks for some reason that the file is latin1 (or some other encoding different from utf8). Therefore it interprets utf8 encoded umlauts the way you see it and inserts umlauts in some other encoding. Either your text editor is configured in the wrong way, or more likely, your file contains a mixture of latin1 and utf8 encoded characters which leads the editor to the guess that it is something different than utf8. – gernot Mar 26 '17 at 14:14
  • 1
    You can check visually for accented characters that look ok (these are in fact the characters not encoded correctly) and remove them, and hope that after reopening the file the editor guesses the right encoding. The editor probably looks only at the first few paragraphs to guess the encoding. There are also command-line tools like iconv that can be used for checking, – gernot Mar 26 '17 at 14:18
2

The file was probably generated using a UTF-8 encoding:

enter image description here

When you open/view it with a different encoding, e. g. ANSI or Latin 1 (aka ISO 8859-1) then it looks like this:

enter image description here

UTF-8 uses one to four bytes per character whereas ISO 8859-1 / ANSI always uses one byte.

The first 128 characters (US-ASCII) need one byte -- this are the basic "easy" ones. This is why they are displayed correctly even when you use the "wrong" encoding for displaying them.

This is the reason why the single umlauts are replaced by two characters when you display them in ISO 8859-1 or ANSI, see also https://en.wikipedia.org/wiki/UTF-8.

Setting your LaTeX editor to UTF-8 probably just means that newly generated files will be encoded using UTF-8 but it will not apply to already existing files.

I emulated your problem in Texmaker, which is also a famous LaTeX editor:

enter image description here

At least in Texmaker a pop-up is shown when you open a file Texmaker isn't sure about the encoding and you are asked to tell Texmaker the encoding the file was generated:

enter image description here

[It seems that this file cannot be correctly decoded with the default encoding setting (ISO-5589-1). Use this encoding: UTF-8]

enter image description here

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.