# nameref + fontenc causes umlauts in aux-File

I wrote a small new command that makes use of \@currentlabelname and \nameref. When I have Umlauts in the labelname (the argument of \@currentlabelname) everything works fine until I use the fontenc package. Then the umlauts are not correctly escaped/transformed into the .aux-File, which then causes an inputenc error.

Here is a minimal example. Run twice to get the error! Any ideas how to make this work with fontenc?

\documentclass{scrartcl}
\usepackage[T1]{fontenc} %causes Umlauts in -aux-file and therefore an inputenc-error on the second run
\usepackage[utf8]{inputenc}
\usepackage{hyperref}

\makeatletter
\newcommand\AP[1]{%
\subsubsection*{#1}%
\edef\@currentlabelname{#1}%
}
\makeatother
\begin{document}
\AP{endgültig}
\label{foo}
\nameref{foo}
\end{document}

• Welcome to TeX.SE! Have you checked out the posting Why characters UTF-8 encoded are ISO-8859-1 encoded when written in an external file? Read, in particular, @egreg's posting. Your issue and the one reported in the other posting could be related. – Mico Dec 13 '13 at 14:01
• Don't use this automation for labels: accented characters are not safe for a \label. – egreg Dec 13 '13 at 14:18
• – texenthusiast Dec 13 '13 at 14:24
• Thanks for the linked threads, @egreg explained the issue very well. Still, it does not provide a solution for pdflatex, right? But, it led me to the conclusion that it should work with lualatex and yes, it does (replace fontenc and inputenc with fontspec of course). Is that the best solution or do I oversee something? – JLo0815 Dec 13 '13 at 15:36

You can solve the issue by using \protected@edef instead of \edef:

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}

\makeatletter
\newcommand\AP[1]{%
\subsubsection*{#1}%
\protected@edef\@currentlabelname{#1}%
}
\makeatother
\begin{document}

\AP{endgültig}\label{foo}

\nameref{foo}

\end{document}