[Tex/LaTex] utf8, newcommand and umlaut

macrosunicode

In my document, which is encoded as utf8 throughout (hopefully), umlaute etc. in the document body are put out correctly, but those defined in a \newcommand are not. I have tried some alternatives to writing the unlaute plain, and \symbol works, while the international accent does not, and I'd rather not use it since it is a little cumbersome.

See the following example:

\newcommand{\myPlace}{Örtlichkeit}
\newcommand{\myWhat}{\"{O}rtlichkeit}
\newcommand{\myHmm}{Stra\symbol{255}e}

\documentclass{scrlttr2} 

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

\begin{document}

\myPlace

\myWhat

\myHmm

ÖÄÜäöüß
\end{document}

Thanks for any input!

Best Answer

If you move the three \newcommand instructions to a point after the \usepackage[utf8]{inputenc} instruction, you won't experience the problems you're reporting.

Addendum -- A comment provided by @egreg -- If you wanted to leave the definitions at the top, you should use the LaTeX internal character representation (LICR) of the characters: \newcommand{\myPlace}{\"{O}rtlichkeit} and \newcommand{\myHmmm}{Stra\ss e}. It's the inputenc package that assigns the desired meaning to the non-ASCII characters, and using them before loading the package is what leads to puzzling results.

Related Question