[Tex/LaTex] LaTeX: UTF8 and algorithm2e clash

algorithm2einput-encodingsunicode

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.
<to be read again> 
                   \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

Best Answer

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}