# hypertarget with accents

with XeLaTeX (so native Unicode input), I would like to create a macro which, from a string, will create an hypertarget which anchor's name contain string.

\documentclass{article}

\usepackage{fontspec,hyperref}
\usepackage{polyglossia}
\setmainlanguage{french}

\begin{document}
\hypertarget{tête}{tête}

\hypertarget{toto}{toto}
\newpage

\end{document}


However, as this MWE illustrate, hypertarget anchor's name can't contain accents. So I suppose I should delete accent. So my question is : is there any way to provide a non-accentued version of the first argument? ideally the output should differ when coming from tête and from tété.

So maybe a command which provide a string contening all the unicode number of the sequence?

Typically, that is for cross-referencing inside index.

• You could investigate what the package does in the case of accents in \label{} \ref{} arguments because those work fine. – cfr Jan 21 '16 at 3:34
• you are right. I will. – Maïeul Jan 21 '16 at 8:42

We need to use \pdfstringdef

\documentclass{article}

\usepackage{fontspec,hyperref}
\usepackage{polyglossia}
\setmainlanguage{french}

\begin{document}

\pdfstringdef\toto{tête}

\hypertarget{\toto}{tête}

\newpage

\end{document}


Or better to patch some internal commands of hyperref:

\documentclass{article}

\usepackage{fontspec,hyperref}
\usepackage{polyglossia}
\setmainlanguage{french}

\begin{document}

\makeatletter

\long\def\hyper@@anchor#1#2{%
\pdfstringdef\@temp@anchorpdfstring{#1}%
\@hyper@@anchor\@temp@anchorpdfstring\relax#2\relax%
}
\pdfstringdef\@temp@anchorpdfstring{#1}%
}
\makeatother

\hypertarget{tête}{tête}

\newpage

The \pdfstringdef command is a very slow command, and maybe problematic with XeTeX. So make the patch only before the section you need accent in anchor name (for exemple only before indexing)