# Glossaries links with non-latin labels in LuaLaTeX refer to wrong place

I want to make a glossary with glossaries-extra package and use Cyrillic characters as entries labels. Everything works fine with XeLaTeX. Clickable links refer to exact glossary entry. But in LuaLaTeX links doesn't work properly. They refer to wrong place. Entries with Latin link works fine in every case. MWE:

\documentclass{article}
\usepackage{polyglossia}
\setmainfont{Liberation Serif}

\usepackage{hyperref}

\usepackage[nonumberlist]{glossaries-extra}

\newglossaryentry{язык}{ name={язык},
sort=\lowercase{язык},
description={Система общения людей.}}

\newglossaryentry{компьютер}{ name={компьютер},
sort=\lowercase{компьютер},
description={Вычислительная машина.}}

\makeglossaries[main]

\begin{document}

\section*{Словарь}

\printglossary[style=list,title={}]

\forallglossaries{\thistype}{\section{Glossary \thistype'}
\forglsentries[\thistype]{\thislabel}{\gls{\thislabel}. }}

\end{document}


Is there a way to get right links in pdf with LuaLaTeX?

• Interestingly it works for me if I use ASCII-only labels, i.e. \newglossaryentry{jazik}{...} & \newglossaryentry{komputer}{...} – moewe Jan 22 at 13:53
• @moewe Yes, with ASCII-only labels it works for me too. But I need Cyrillic labels – Shalom Alecheim Jan 22 at 14:03
• Ah bummer, since the labels are only used as internal identifiers and never exposed in the document, I thought you could be OK with using ASCII-only labels. That said, since LuaLaTeX is supposed to be a Unicode engine I would expect things to work with Cyrillic as well. – moewe Jan 22 at 14:06

As Ulrike Fischer described the problem is that non-ASCII characters are dropped by \pdf@escapestring. To avoid this, you can change \pdf@escapestring to encode Unicode characters in UTF-8:

\documentclass{article}
\usepackage{polyglossia}
\setmainfont{Liberation Serif}

\usepackage{hyperref}

\usepackage[nonumberlist]{glossaries-extra}

\newglossaryentry{язык}{ name={язык},
sort=\lowercase{язык},
description={Система общения людей.}}

\newglossaryentry{компьютер}{ name={компьютер},
sort=\lowercase{компьютер},
description={Вычислительная машина.}}

\makeglossaries[main]

\makeatletter
\long\def\pdf@escapestring#1{%
\directlua0{%
oberdiek.pdftexcmds.escapestring("\luaescapestring{#1}")% Almost like the original one, just omit "byte" to keep all characters.
}%
}
\makeatother

\begin{document}

\section*{Словарь}

\printglossary[style=list,title={}]

\forallglossaries{\thistype}{\section{Glossary \thistype'}
\forglsentries[\thistype]{\thislabel}{\gls{\thislabel}. }}

\end{document}

• I will have to check if this always gives a valid pdf string. But if yes, this should probably be implemented. – Ulrike Fischer Jan 22 at 17:15
• @UlrikeFischer I am quite sure that it always gives a valid PDF string. (It corresponds to a valid PDFDocEncoding string, at least if U+7F=Delete is not used, because 0x7f is undefined for PDFDocEncoding) But it does not generate a valid encoding of the passed string, because PDF only accepts PDFDocEncodung and UTF-16, not UTF-8. – Marcel Krüger Jan 22 at 18:02

Not a solution but an explanation. The problem is hyperref. hyperref uses with lualatex \pdf@escapestring to convert the name to something that can be safely used as a destination in the pdf. But the current implementation of \pdf@escapestring handles only ascii, everything else is simply dropped. And this means that glossaries creates for the two entries the same destination glo: On the terminal you can see the warning

 warning  (pdf backend): ignoring duplicate destination with the name 'glo:'


when trying this document:

\documentclass{article}

\usepackage{hyperref}

\begin{document}

\makeatletter
\pdf@escapestring {glo:компьютер}

\pdf@escapestring {glo:язык}

\hypertarget{glo:компьютер}{blub}

\hypertarget{glo:язык}{bla}

\end{document}