9

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?

3
  • Interestingly it works for me if I use ASCII-only labels, i.e. \newglossaryentry{jazik}{...} & \newglossaryentry{komputer}{...}
    – moewe
    Jan 22 '19 at 13:53
  • @moewe Yes, with ASCII-only labels it works for me too. But I need Cyrillic labels Jan 22 '19 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 '19 at 14:06
8

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}
5
  • 1
    I will have to check if this always gives a valid pdf string. But if yes, this should probably be implemented. Jan 22 '19 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. Jan 22 '19 at 18:02
  • @MarcelKrüger, this is not quite right, because if there is any character higher then 255 then all the characters must be converted to pdf UTF16-BE BOM string prefixed with \376\377. Eg. \pdf@escapestring{1ч} you'll get 1\321\207 but should be \376\377\0001\004\107. This string will be shown in pdf correctly.
    – Linuxss
    Feb 3 at 9:29
  • @Linuxss That's mostly right when you care about the name of the links, but here the only real requirement is that they are unique identifiers. This approach gives unique identifiers, even though decoding them gives a random set of symbols instead of a useful string. But since you normally never see them in the first place, that's not an issue. Feb 3 at 9:41
  • if so, I agree.
    – Linuxss
    Feb 3 at 9:43
10

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}

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.