# Problem with special characters in .toc files

I have an odd problem with special characters (in this case the Swedish åäö), that pops up in my .toc file. If I remove the .toc file everything works OK except I get an empty table of contents. When I re-run pdflatex, I get errors on every line in the .toc file that has either of åäö in it (which, as it happens, is every line...).

I've tried to produce a MWE example of this, but I'm unable to reproduce the problem with other files. However, I've noticed that for other files, åäö in the .toc file are replaced as follows:

å -> \IeC {\r a}
ä -> \IeC {\"a}
ö -> \IeC {\"o}


In the .toc file for the failing document, only å is replaced. Why could this be? What can I do about it?

Clarification: As I said, I have tried but been unable to reproduce this error in a MWE. (The full version is a pretty advanced structure with templates, frame and content files compiled by a python script calling pdflatex via os.system(), so I can't really just "scale off" one piece after another...) However, I can give the following information:

• All files are saved in utf-8.
• I'm using \usepackage[utf8]{inputenc} and \usepackage[swedish]{babel}.
• The python file starts with #coding: utf8
-
Perhaps post a minimal code example that produces this problem. Until now, we don't know the encoding you're using neither we know if you're using babel or not. –  Stefan Kottwitz Nov 1 '10 at 23:11
What error message do you get? –  Caramdir Nov 2 '10 at 0:47
@Caramdir: I get lots of variations of ! Package inputenc Error: Unicode char \u8:Â„ not set up for use with LaTeX. in the log file, along with things like Missing character: There is no Â in font cmcsc10!. –  Tomas Lycken Nov 2 '10 at 1:02
In addititon, there are problems with rendering these letters in some headings, particularly within \textsc{}. –  Tomas Lycken Nov 2 '10 at 1:04

When the non-ascii-chars like ä or ö get in the toc, this means that they are not active. Perhaps you are storing some of your titles in commands before inputenc has been loaded:

\documentclass{article}
\def\test{ÅÄÖ}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}
\tableofcontents

\section{\test}

\end{document}


My example doesn't give an error, but its possible that your python code insert an utf8 char tex can't handle.

-
This is very likely the cause - I'll do some testing and get back... –  Tomas Lycken Nov 2 '10 at 13:51
Thanks! I had to rewrite quite a lot of my code to handle this, but when I include inputenc before setting up all the titles etc, everything works as expected =) –  Tomas Lycken Nov 12 '10 at 19:52

From the inputenc documentation:

1.3.3 Unicode char <charcode> is not set up for use with LaTeX

This is the dreaded error message that one will receive if the document contains an UTF-8 character that isn't known to LATEX. It is quite possible that the character looks very unsuspicious and is rendered perfectly in the editor.

...

However, even if LATEX can type that character in question it may not have been set up in which case you would need to do that yourself via \DeclareUnicodeCharacter.

So, something like \DeclareUnicodeCharacter{00E4}{\"a} might work. You'd probably need to see which Unicode glyph is the one you're trying to use (this example straight from the manual, section 1.2).

Hope this helps.

-
OK. I'm unable to find what numbers and glyphs I should use for the other five characters. Any clues? –  Tomas Lycken Nov 2 '10 at 8:53
See this: utf8-chartable.de . Does it work otherwise? –  Martin Tapankov Nov 2 '10 at 8:57
I added \DeclareUnicodeCharacter{00E4}{\"a} as well as one command for each of the other (ÅÄÖåö) troubling characters, but with no positive results - I still have warnings in my log file about undefined characters (\u8:Å, among others) and I still get an exit code that suggests failure. –  Tomas Lycken Nov 2 '10 at 9:13

Use a meaningful encoding such as

\usepackage[utf8]{inputenc}


but also take care that your editor uses the same encoding and that the file itself has this encoding too. For instance, one may download a latin1 encoded file but edit it with utf8 option and the other way round.

-