Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\p@<counter> and cleveref firstaid #1544

Open
muzimuzhi opened this issue Nov 8, 2024 · 2 comments
Open

\p@<counter> and cleveref firstaid #1544

muzimuzhi opened this issue Nov 8, 2024 · 2 comments

Comments

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Nov 8, 2024

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.

\newcommand\firstaid@cref@updatelabeldata[1]{%
\cref@constructprefix{#1}{\cref@result}%
\@ifundefined{cref@#1@alias}%
{\def\@tempa{#1}}%
{\def\@tempa{\csname cref@#1@alias\endcsname}}%
\protected@xdef\cref@gcurrentlabel@temp{%
[\@tempa][\arabic{#1}][\cref@result]%
\csname p@#1\endcsname\csname the#1\endcsname}%
\aftergroup\firstaid@cref@smugglelabel
}

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
Copy link
Member

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
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants