problems with commands let to a char.
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 205
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
hyperref has problems with commands which have been let to a char.
With pdflatex one gets e.g. wrong bookmarks:
\documentclass{article}
\usepackage{hyperref}
\let\mychar!
\begin{document}
\tableofcontents
\section{\mychar}
\section{!}
\end{document}

With unicode engines and pdfencoding=auto the problem is more serious
\documentclass{article}
\usepackage[pdfencoding=auto]{hyperref}
\let\mychar!
\begin{document}
\tableofcontents
\section{\mychar}
\section{!}
\end{document}
gives the error
! Improper alphabetic constant.
<to be read again>
\mychar
l.21 \section{\mychar}
The problem is this definition which is used for the unicode engines.
\def\HyPsd@Char#1{%
\ifnum`#1<128 %
\@backslashchar 000#1%
\else
\ifnum`#1<65536 %
\expandafter\HyPsd@CharTwoByte\number`#1!%
\else
\expandafter\expandafter\expandafter\HyPsd@CharSurrogate
\intcalcSub{`#1}{65536}!%
\fi
\fi
}%
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 replace 000#1).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the shown \HyPsd@Char definition and reproduce the issue using the minimal pdflatex and unicode-engine examples. Done means commands let to characters produce correct bookmarks without the reported unicode-engine error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- latex
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100