# LaTeX: UTF8 and algorithm2e clash

I have this input file in utf8 encoding:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{algorithm2e}
\begin{document}

\begin{procedure}
foo
\caption{ö()}
\end{procedure}
\end{document}


but this gives me an error:

) (./test.aux)
! Missing \endcsname inserted.
\unhbox
l.8 \caption{ö()}


somehow the \caption command doesn't like the ö character. Is there any way to use ö in utf8 encoding and the algorithm package?

 *File List*
article.cls    2007/10/19 v1.4h Standard LaTeX document class
size10.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
inputenc.sty    2008/03/30 v1.1d Input encoding file
utf8.def    2008/04/05 v1.1m UTF-8 support for inputenc
t1enc.dfu    2008/04/05 v1.1m UTF-8 support for inputenc
ot1enc.dfu    2008/04/05 v1.1m UTF-8 support for inputenc
omsenc.dfu    2008/04/05 v1.1m UTF-8 support for inputenc
algorithm2e.sty    2008/00/00 v3.10 algorithms environments
ifthen.sty    2001/05/26 v1.1c Standard LaTeX ifthen package (DPC)
xspace.sty    2006/05/08 v1.12 Space after command names (DPC,MH)
relsize.sty    2003/07/04 ver 3.1

-
Are you using pdflatex? – Charles Stewart Nov 30 '10 at 20:25
Yes, and I cannot change easily (well, it's not me that has the problem but a friend, and he's a few days before a deadline and I don't want to tell him "update your TeX installation and do this and that). – topskip Nov 30 '10 at 20:33

Algorithm2e tries to define a command \csname ö\endcsname in your example. The problem is that the "ö" is already a command and - as you are using OT1 font encoding - it contains commands which can't be used in \csname. You can use \usepackage[T1]{fontenc}. This will solve the problem with the ö. But on the whole I do find it rather problematic how algorithm2e defines commands without checking. I would suggest the nokwfunc option.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage%[nokwfunc] % enable it to see the difference
{algorithm2e}
\usepackage[T1]{fontenc}
\begin{document}
\section{A}

\begin{procedure}
foo \caption{ö()}
\end{procedure}

\begin{procedure}
foo \caption{section()}
\end{procedure}

\section{B}
\end{document}

-
I changed to T1 fontenc now anyway but also added the nokwfunc option to the package. Thanks a lot! – topskip Dec 1 '10 at 10:59

I don't believe it is possible to define a macro name with an umlaut and that is what is happening here. Your \caption{ö()} will create a command \ö using csname. This for example works perfectly.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{algorithm2e}
\begin{document}
\begin{procedure}
\caption{test(disjöint decomposition)}
\end{procedure}
\end{document}


The problem is not utf-08 or the umlaut, you just cannot use the umlaut as a macro name.

-
Things do work if you switch to a UTF-8 engine (XeLaTeX or LuaLaTeX), and load appropriate font support. In the LuaLaTeX case there are some errors due to bad UTF-8 character codes for the 'french' option stuff in algorithm2e.sty, but the example file still works. – Joseph Wright Nov 30 '10 at 20:18
Normally I can create a command name with an ö for example. But with \usepackage[utf8]{inputenc} (and utf8 input) the ö is a command which probably gets expanded and then fails. In latin 1 this is not a problem as far as I can see. – topskip Dec 1 '10 at 18:43