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

Use \protected@edef to expand \thepage at cleveref firstaid #1613

Open
Sophanatprime opened this issue Jan 7, 2025 · 3 comments
Open

Use \protected@edef to expand \thepage at cleveref firstaid #1613

Sophanatprime opened this issue Jan 7, 2025 · 3 comments

Comments

@Sophanatprime
Copy link

Brief Outline of the Enhancement

If the user redefines \thepage with a \protect macro, an issue arises with \label. Below is a minimal example that demonstrates the problem:

\RequirePackage{latexbug}
\documentclass{book}
\usepackage{cleveref}

\renewcommand{\thepage}{\textbf{\arabic{page}}}

\begin{document}

Text\label{error}.

\end{document}

The LaTeX team has already patched \label@noarg and \label@optarg. Would it be possible to use \protected@edef to expand \thepage instead of \edef? This change could potentially resolve the issue.

Related issue: #1382

Relevant lines of code:

\AddToHook{begindocument}[cleveref]{%
\def\label@noarg#1{%
\cref@old@label{#1}%
\@bsphack%
\edef\@tempa{{page}{\the\c@page}}%
\setcounter{page}{1}%
\edef\@tempb{\thepage}%
\expandafter\setcounter\@tempa%
\cref@constructprefix{page}{\cref@result}%
\protected@write\@auxout{}%
{\string\newlabel{#1@cref}{{\cref@currentlabel}%
{[\@tempb][\arabic{page}][\cref@result]\thepage}{}{}{}}}% <----- five
\@esphack}%

@FrankMittelbach
Copy link
Member

This change could potentially resolve the issue.

could or does? Anyway, I agree with you that the firstaid should be a bit more careful as it is not known what is inside \thepage

@u-fischer
Copy link
Member

The example errors already e.g. in texlive 2018 and the \edef is in the original code and this bug been reported more than once. I'm not quite sure if we should start package maintenance through the firstaid.

@FrankMittelbach
Copy link
Member

We should not in general, but if we do some firstaid anyway, we might well do it in a way that it is less broken :-) after all, if somebody tried to fix that bug in his or her preamble our firstaid would overwrite that again, wouldn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

3 participants