Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it somehow possible to have utf8 characters (e.g. german umlauts) inside \edef ? The following example document behaves fine if the umlaut is given directly as argument like \convertTest{Müller}. The resulting output is "Mueller" after conversion. If "Müller" is given via a \edef like in \convertTest{\authorname}, the resulting output is not as expected ("M.ller"), although the message on \newcommand entry (before convert) is the same.

\documentclass{article}

\usepackage[ngerman]{babel} 

\usepackage[utf8]{inputenc}  
\usepackage[T1]{fontenc}  
\usepackage{stringstrings}


\newcommand{\convertTest}[1]{  
\message {before convert: #1}  
\convertword[q]{#1}{}{ue}  
\message {after convert: \thestring}  
\thestring \ 
}

\begin{document}  
\convertTest{Müller}  
\edef\authorname{Müller}
\convertTest{\authorname}  
\end{document}
share|improve this question

3 Answers 3

Martin is right when he says : an alternative might be to protect ...

You can to do this with

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


\newcommand{\convertTest}[1]{  
\message {before convert: #1}  
\convertword[q]{#1}{}{ue}  
\message {after convert: \thestring}  
\thestring \ 
}

\begin{document}  
\convertTest{Müller}
\makeatletter  
 \protected@edef\authorname{Müller}
 \makeatother   
 \authorname
\convertTest{\authorname}  
\end{document} 

You need to use an engine with etex but pfd(e)tex is very common actually

Alternativ : you can put the definition in your preamble :

\makeatletter   
\newcommand{\defauthorname}[1]{ 
 \protected@edef\authorname{#1}
 }
\makeatother 

and you can use this with

\defauthorname{Müller}  
 \authorname  
share|improve this answer
    
The \makeatletter \protected@edef ... \makeatother solution works fine and is actually very simple. It solves also other problems, for example it makes possible to use \authorname in a \addcontentsline statement. –  jbeh Jan 29 '11 at 11:47
    
\protected@edef seems the (general) way to go. Thanks! –  Raphael Oct 30 '12 at 10:57

The umlauts are usually defined as active characters, e.g. like ~. They are basically single-character macros which do not need the backslash in front of them.

Now, \edef expands all macros, and therefore also all active characters, until the resulting tokens cannot be expanded any further. This is whats causing the problem: after \edef the ü isn't a ü any longer:

\show ü
> ü=macro:
->\UTFviii@two@octets ü.

I ran into the same issue when adding group names to my svn-multi package, which should be used inside \csname ... \endcsname, which also expands like \edef (but causes an error if the result is not text-only).

Solution: You could redefine the ü locally prior to the \edef: If all what you want to do is to turn the ü into ue then do this:

\def ü{ue}
\edef\authorname{Müller}
\message{\authorname}%   Prints Mueller!

An alternative might be to protect the ü, e.g. make it robust. I tried the \robustify macro from etoolbox but it didn't work. But this might be an issue with my local encodings.

You might also try to use XeTeX, which has native unicode support. But I personally don't have any experience with it.

share|improve this answer
2  
^ and _ aren't active. –  TH. Jan 29 '11 at 10:25
    
Thanks, yes there are math super- and subscript characters (catcodes 7 and 8). My bad, I edited my post. –  Martin Scharrer Jan 29 '11 at 11:57
\documentclass{article}
\usepackage[T1]{fontenc}  
\usepackage[utf8]{inputenc}  
\usepackage[ngerman]{babel} 
\usepackage{xstring}

\newcommand\convertTest[1]{\StrSubstitute{#1}{ü}{ue}}

\begin{document}  
\convertTest{Müller}  
\edef\authorname{Müller}
\convertTest{\authorname}  
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.