latex3 / latex3/hyperref

problems with commands let to a char.

Open
#63 1 comment 0 reactions 0 assignees View on GitHub

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}

image

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.