Open u-fischer opened 6 years ago
Probably not solvable easily in hyperref for all engines. For luatex something like this could work:
\documentclass{article}
\usepackage{luacode}
\usepackage[pdfencoding=unicode]{hyperref}
\begin{luacode}
function getcharactercode ()
local t=token.get_next()
tex.print(t.mode)
end
\end{luacode}
\makeatletter
\def\HyPsd@Char#1{%
\ifnum\directlua{getcharactercode ()}#1<128 %
\@backslashchar 000\Uchar\directlua{getcharactercode ()}#1%
\else
\ifnum\directlua{getcharactercode ()}#1<65536 %
\expandafter\HyPsd@CharTwoByte\directlua{getcharactercode ()}#1!%
\else
\expandafter\expandafter\expandafter\HyPsd@CharSurrogate
\intcalcSub{\directlua{getcharactercode ()}#1}{65536}!%
\fi
\fi
}%
\makeatother
\begin{document}
\let\mychar!
\tableofcontents
\section{\mychar äüö€ ɑН}
\end{document}
hyperref has problems with commands which have been let to a char.
With pdflatex one gets e.g. wrong bookmarks:
With unicode engines and
pdfencoding=auto
the problem is more seriousgives the error
The problem is this definition which is used for the unicode engines.
It is called with
\mychar
as argument and so basically does\ifnum`\mychar < 128
.The error can be avoided by adding
\pdfstringdefDisableCommands{\def\mychar{!}}
but as e.g. unicode-math lets a lot commands to chars (e.g. \euro (https://github.com/wspr/unicode-math/issues/402) and \omega) some better solution is imho needed.(I tried to replace the
`#1
with a counter along this answer https://tex.stackexchange.com/a/148307/2388, but it looks as if\HyPsd@Char
should be expandable and also I'm not sure how to replace000#1
).