1

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
\hyperlink{toto}{toto}
\hyperlink{tête}{tête}


\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
3

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
\hyperlink{\toto}{tête}

\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%
    }
    \def\hyperlink#1#2{%
       \pdfstringdef\@temp@anchorpdfstring{#1}%
       \hyper@@link{}{\@temp@anchorpdfstring}{#2}%
    }
\makeatother


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

\newpage
\hyperlink{tête}{tête}

\end{document}

I will suggest to Heiko Oberdiek to integrate directly this correction.

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)

thank @cfr

  • I found your solution interesting but in a math mode it generate some warning like : "\pdfstringdef invalid command in math mode" or "Token not allowed in a PDF string (PDFDocEncoding): removing `math shift' ". Is there a way to avoid this troubles ? – R. N Feb 16 '16 at 13:31
  • I don't know, I never do math… – Maïeul Feb 17 '16 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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