latex3 / latex2e

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

`cleveref` needs another firstaid to work with LaTeX 2024-11-01 plus `hyperref` #1524

Closed muzimuzhi closed 3 weeks ago

muzimuzhi commented 3 weeks ago

Brief outline of the bug

Loading hyperref and cleveref in LaTeX 2024-11-01, the use of \refstepcounter{<counter>} won't update \cref@currentlabel thus a corresponding \cref{<counter>} will typeset "??".

This may be related to the changes in hyperref: when used with LaTeX 2024-11-01, it doesn't redefine \refstepcounter anymore.

Found when running l3build check --dev from ctex directory, https://github.com/CTeX-org/ctex-kit repository.

Minimal example showing the bug

% needs latex(-dev) 2024-11-01
% \RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}
\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}
\section{title}\label{key}

\makeatletter
\show\cref@currentlabel % still empty
\makeatother

\cref{key} % typesets "??"

\end{document}

In .aux

% with hyperref, bad
\newlabel{key}{{1}{1}{title}{section.1}{}}
\newlabel{key@cref}{{}{[1][1][]1}{}{}{}}

% without hyperref, good
\newlabel{key}{{1}{1}{}{section.1}{}}
\newlabel{key@cref}{{[section][1][]1}{[1][1][]1}{}{}{}}

Log file (required) and possibly PDF file

cleveref-refstepcounter.log

u-fischer commented 3 weeks ago

It works ok for me. You must ensure that the format has been built with the newest firstaid version. You can check that by looking into the hook label:

\documentclass{article}
\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}
\ShowHook{label}
\section{title}\label{key}

\cref{key} % typesets "??"

\end{document}

it should show the cleveref hook:

-> The hook 'label' (1 argument):
> Code chunks:
>     nameref -> \def \label@name {#1}\label@hook 
>     firstaid/cleveref -> \ifx \@currentcounter \@empty \else \firstaid@cref@updatelabeldata {\@currentcounter } \fi 
> Document-level (top-level) code (executed last):
>     ---
> Extra code for next invocation:
>     ---
> Rules:
>     ---
> Execution order:
>     nameref, firstaid/cleveref.
<recently read> }
muzimuzhi commented 3 weeks ago

It works ok for me.

You're right. The problem disappears if I use the format built from this repo, on tag release-2024-11-01. Perhaps some changes taken place between the last pre-release and the stable release of 2024-11-01 help.

I'll close this issue once double checked using LaTeX 2024-11-01 updated from tlmgr.

muzimuzhi commented 3 weeks ago

Perhaps some changes taken place between the last pre-release and the stable release of 2024-11-01 help.

It's 3d8c18544 (firstaid for gh1393 and tagging-project733 (#1494), 2024-10-21).

I'll close this issue once double checked using LaTeX 2024-11-01 updated from tlmgr.

Confirm fixed, thank you again.