latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.94k stars 267 forks source link

`\p@<counter>` and `cleveref` firstaid #1544

Open muzimuzhi opened 1 week ago

muzimuzhi commented 1 week ago

Brief outline of the enhancement

(First caught by a test in the ctex bundle, see log of its scheduled job.)

When \labelformat is introduced to the kernel in the 2019 Autumn release, the \p@<counter> is extended to accept one argument, usually \the<counter>. The uses of \p@<counter> in the kernel code is accordingly adapted, by adding an \expandafter:

% from
\csname p@#1\expandafter\endcsname\csname the#1\endcsname
% to
\csname p@#1\endcsname\csname the#1\endcsname

But the uses of \p@<counter> in cleveref.sty is never updated (due to lack of maintenance?), thus ctex patches uses of \p@<counter> in cleveref to insert the needed \expandafter.

Then in the most recent 2024-11-01 release, cleveref firstaid is extended with a pre-\labelformat use of \p@<counter> (see code line 736 below), which is missed by ctex's patches and causes problems when ctex is used with hyperref and cleveref.

https://github.com/latex3/latex2e/blob/716dec2c019175dda8efba108942b3f25c170aee/required/firstaid/latex2e-first-aid-for-external-files.dtx#L729-L738

What's the recommended way to continue here, update cleveref firstaid (which introduces inconsistent uses of \p@<counter>) or extend ctex patches for cleveref (which means to patch cleveref firstaid hmm)? Of course the best solution is to update cleveref.sty itself...

Minimal example showing the current behaviour

% \RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}
\usepackage[fontset=none, heading]{ctex}
\usepackage{hyperref,cleveref}

% \ShowHook{begindocument} % too long to be helpful

\begin{document}
\section{title}

\makeatletter
\show\cref@currentlabel
\makeatother
\end{document}

Expected

> \cref@currentlabel=macro:
->[section][1][]1.

Actual

> \cref@currentlabel=macro:
->[section][1][]1thesection\endcsname .
u-fischer commented 1 week ago

I added the missing \expandafter to the firstaid. But it will naturally not be released directly. Also I'm not sure if that catches everything -- we are not adapting \refstepcounter@optarg. So probably you will have to figure out some intermediate patches.

Of course the best solution is to update cleveref.sty itself...

Yes. Or to find someone who writes a compatible cleveref-new and then the firstaid could be restricted to load that instead of cleveref.

muzimuzhi commented 1 week ago

Linking to