25

cleveref is one of my favorite packages, and indeed, many of my own packages (cleveref-forward, crefthe, create-theorem) and classes (minimalist, colorist) depend in a fundamental way on cleveref.

However, it was last updated more than 5 years ago, and since then a lot have happened in the world of LaTeX. And I remember having seen patches to cleveref in many different places (but unfortunately I didn't take note on them; one could see some of these by viewing at those questions with tag "cleveref"). As a package maintainer, I am concerned about this situation (when I started to write my first package in 2021, this didn't seem to be quite a problem, but now one has to face the possibility that cleveref may no longer be maintained). For example, just recently I have added to one package a patch given by Ulrike Fischer in this answer.

Is there thus, to your knowledge, a collected list of known issues (and hopefully also recommended solutions) and known improvements to cleveref as for now? And for those newly coming users, is it still okay to use cleveref in their daily documents? And in case not, is there perhaps any alternative choice as for now?

11
  • Ulrike Fischer is probably the best placed person to answer this. If I recall correctly, she was able to contact Toby Cubitt in the not too distant past. My direct experience in trying to report a problem and a fix for it (at tex.stackexchange.com/q/603514/105447) was "no answer and no fix". I have been keeping tabs on things that show up here on the site, but not for long, so probably incomplete, but I'm not sure how useful it would be in this context. Commented Feb 24, 2024 at 20:23
  • 2
    @gusbrs yes good luck with that, compare the note on page one of texdoc afterpage with the number of times users expect that package to do something vaguely useful. Commented Feb 24, 2024 at 22:50
  • 4
    Only the maintainer can give a definite answer about the status and some time frame, so you will have to write him directly. Currently my doubts outweigh hope, but who knows ... Commented Mar 6, 2024 at 14:38
  • 2
    Thanks for putting effort into the topic, +1. Commented Mar 7, 2024 at 23:22
  • 1
    @UlrikeFischer I wrote him more than once. The result has been equivalent to >>/dev/null so far :-). Commented Jun 18, 2024 at 0:04

4 Answers 4

5

Below are some known fixes to cleveref. Currently these fixes have been included in the package cleveref-forward, hopefully one day they can make their way into the original package cleveref.

% Fix for cleveref in order to work with long range of pages
% See https://tex.stackexchange.com/a/620066
\providecommand*{\@setcpagerefrange}[3]{%
    \@@setcpagerefrange{#1}{#2}{cref}{#3}}
\providecommand*{\@setCpagerefrange}[3]{%
    \@@setcpagerefrange{#1}{#2}{Cref}{#3}}
\providecommand*{\@setlabelcpagerefrange}[3]{%
    \@@setcpagerefrange{#1}{#2}{labelcref}{#3}}
% Fix for cleveref in order to work with xr-hyper
% See https://tex.stackexchange.com/a/708445
\def\cref@getref#1#2{%
  \expandafter\let\expandafter#2\csname r@#1@cref\endcsname%
  \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#2%
    \expandafter\expandafter\expandafter{%
      \expandafter\@firstoffive#2}}% <-------- five
\def\cpageref@getref#1#2{%
  \expandafter\let\expandafter#2\csname r@#1@cref\endcsname%
  \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#2%
    \expandafter\expandafter\expandafter{%
      \expandafter\@secondoffive#2}}% <----------- five
\AtBeginDocument{%
  \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}%
  \def\label@optarg[#1]#2{%
    \cref@old@label{#2}%
    \@bsphack%
    \edef\@tempa{{page}{\the\c@page}}%
    \setcounter{page}{1}%
    \edef\@tempb{\thepage}%
    \expandafter\setcounter\@tempa%
    \cref@constructprefix{page}{\cref@result}%
    \protected@edef\cref@currentlabel{%
      \expandafter\cref@override@label@type%
        \cref@currentlabel\@nil{#1}}%
    \protected@write\@auxout{}%
      {\string\newlabel{#2@cref}{{\cref@currentlabel}%
      {[\@tempb][\arabic{page}][\cref@result]\thepage}{}{}{}}}% <------- five
    \@esphack}%
}
2
  • Concerning cleveref-foward, consider inserting the code of cleveref into your package rather than using cleveref. This would allow you to actually replace the wrong code at the places it should be replaced rather than calling the wrong code and patching it subsequently (which wastes some running time whenever a document uses cleveref-forward). Commented Jun 19, 2024 at 21:00
  • If users load cleveref after cleveref-forward, they are themselves to blame. In my opinion, nobody should use the unpatched official cleveref any longer, and failing on loading it is the right thing to do. Although the additional compilation may negligible for one person compiling once, these times sum up to tons of CO₂, and they also sum up noticeably if you compile many documents in a batch over and over again in the course of the years. Commented Jun 20, 2024 at 15:46
5

The package zref-clever is a good alternative — a modern, actively maintained package providing much of the functionality of cleveref.

(Thanks to samcarter_is_at_top_answers.xyz for pointing me to zref-cleveref in the comments here.)

2

Trying to combine Jiwen's patches with https://github.com/latex3/latex2e/issues/1382, I arrived at

--- /home/username/tex/cleveref_0.21.5/cleveref.sty 2018-10-18 18:36:21.000000000 +0200
+++ cleveref.sty    2024-06-19 01:04:26.050825233 +0200
@@ -9,10 +9,11 @@
 %% LaTeX package for intelligent cross-referencing.
 %% 
 %% Copyright (C) 2006--2016  Toby Cubitt
+%% Improved/hacked by ................, 2024.
 %% See the files README and COPYING.
 %% 
-\def\packagedate{2018/10/18}
-\def\packageversion{0.21.5}
+\def\packagedate{2024/06/19}
+\def\packageversion{0.21.5.3}
 %% This file may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.2
 %% of this license or (at your option) any later version.
@@ -72,19 +73,19 @@
     \@bsphack%
     \edef\@tempa{{page}{\the\c@page}}%
     \setcounter{page}{1}%
-    \edef\@tempb{\thepage}%
+    \protected@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}}}%
+      {[\@tempb][\arabic{page}][\cref@result]\thepage}{}{}{}}}%
     \@esphack}%
   \def\label@optarg[#1]#2{%
     \cref@old@label{#2}%
     \@bsphack%
     \edef\@tempa{{page}{\the\c@page}}%
     \setcounter{page}{1}%
-    \edef\@tempb{\thepage}%
+    \protected@edef\@tempb{\thepage}%
     \expandafter\setcounter\@tempa%
     \cref@constructprefix{page}{\cref@result}%
     \protected@edef\cref@currentlabel{%
@@ -92,7 +93,7 @@
         \cref@currentlabel\@nil{#1}}%
     \protected@write\@auxout{}%
       {\string\newlabel{#2@cref}{{\cref@currentlabel}%
-      {[\@tempb][\arabic{page}][\cref@result]\thepage}}}%
+      {[\@tempb][\arabic{page}][\cref@result]\thepage}{}{}{}}}%
     \@esphack}%
 }% end of AtBeginDocument
 \let\cref@old@makefntext\@makefntext%
@@ -310,7 +311,7 @@
   \expandafter\expandafter\expandafter\def%
     \expandafter\expandafter\expandafter#2%
     \expandafter\expandafter\expandafter{%
-      \expandafter\@firstoftwo#2}}%
+      \expandafter\@firstoffive#2}}%
 \def\cref@getlabel#1#2{%
   \cref@getref{#1}{\@tempa}%
   \expandafter\@cref@getlabel\@tempa\@nil#2}%
@@ -340,7 +341,7 @@
   \expandafter\expandafter\expandafter\def%
     \expandafter\expandafter\expandafter#2%
     \expandafter\expandafter\expandafter{%
-      \expandafter\@secondoftwo#2}}%
+      \expandafter\@secondoffive#2}}%
 \def\cpageref@getlabel#1#2{%
   \cpageref@getref{#1}{\@tempa}%
   \expandafter\@cpageref@getlabel\@tempa\@nil#2}%
@@ -4119,7 +4120,11 @@
     \crefname@preamble{page}{Seite}{Seiten}%
     \crefname@preamble{part}{Teil}{Teile}%
     \crefname@preamble{chapter}{Kapitel}{Kapitel}%
-    \crefname@preamble{section}{Abschnitt}{Abschnitte}%
+    \if@cref@abbrev%
+      \crefname@preamble{section}{Abschn.}{Abschn.}%
+    \else%
+      \crefname@preamble{section}{Abschnitt}{Abschnitte}%
+    \fi%
     \crefname@preamble{appendix}{Anhang}{Anh\"ange}%
     \crefname@preamble{enumi}{Punkt}{Punkte}%
     \crefname@preamble{footnote}{Fu\ss note}{Fu\ss noten}%
@@ -4196,9 +4201,15 @@
   \crefname{page}{Seite}{Seiten}%
   \crefname{part}{Teil}{Teile}%
   \crefname{chapter}{Kapitel}{Kapitel}%
-  \crefname{section}{Abschnitt}{Abschnitte}%
-  \crefname{subsection}{Abschnitt}{Abschnitte}%
-  \crefname{subsubsection}{Abschnitt}{Abschnitte}%
+  \if@cref@abbrev%
+    \crefname{section}{Abschn.}{Abschn.}%
+    \crefname{subsection}{Abschn.}{Abschn.}%
+    \crefname{subsubsection}{Abschn.}{Abschn.}%
+  \else%
+    \crefname{section}{Abschnitt}{Abschnitte}%
+    \crefname{subsection}{Abschnitt}{Abschnitte}%
+    \crefname{subsubsection}{Abschnitt}{Abschnitte}%
+  \fi%
   \crefname{appendix}{Anhang}{Anh\"ange}%
   \crefname{subappendix}{Anhang}{Anh\"ange}%
   \crefname{subsubappendix}{Anhang}{Anh\"ange}%
@@ -4283,9 +4294,15 @@
   \crefname{page}{Seite}{Seiten}%
   \crefname{part}{Teil}{Teile}%
   \crefname{chapter}{Kapitel}{Kapitel}%
-  \crefname{section}{Abschnitt}{Abschnitte}%
-  \crefname{subsection}{Abschnitt}{Abschnitte}%
-  \crefname{subsubsection}{Abschnitt}{Abschnitte}%
+  \if@cref@abbrev%
+    \crefname{section}{Abschn.}{Abschn.}%
+    \crefname{subsection}{Abschn.}{Abschn.}%
+    \crefname{subsubsection}{Abschn.}{Abschn.}%
+  \else%
+    \crefname{section}{Abschnitt}{Abschnitte}%
+    \crefname{subsection}{Abschnitt}{Abschnitte}%
+    \crefname{subsubsection}{Abschnitt}{Abschnitte}%
+  \fi%
   \crefname{appendix}{Anhang}{Anh\"ange}%
   \crefname{subappendix}{Anhang}{Anh\"ange}%
   \crefname{subsubappendix}{Anhang}{Anh\"ange}%
@@ -8049,6 +8066,14 @@
   %
   \let\cref@language\relax%
 }%  end of \AtBeginDocument
+
+\providecommand*{\@setcpagerefrange}[3]{%
+    \@@setcpagerefrange{#1}{#2}{cref}{#3}}
+\providecommand*{\@setCpagerefrange}[3]{%
+    \@@setcpagerefrange{#1}{#2}{Cref}{#3}}
+\providecommand*{\@setlabelcpagerefrange}[3]{%
+  \@@setcpagerefrange{#1}{#2}{labelcref}{#3}}
+
 \InputIfFileExists{cleveref.cfg}%
   {\PackageInfo{cleveref}{reading definitions from cleveref.cfg}}{}%
 \endinput

To apply, run patch cleveref.sty patchfile on the latest cleveref.sty 0.21.5 from the author's Web page.

We bother abbreviating “Abschnitt” and “Abschnitte” into “Abschn.” only for ngerman, and not for german, since we assume that the pre-1996 German is nowadays used mostly to recompile old documents, and, if you go for the old German, our assumption is that you probably wish to preserve also other historical aspects.

Testing is appreciated.

0
0

I am writing a fix that can correctly deal with (and add more) resetby-information. For example, enumii is reseted by enumi, and so on. With the following code, cleveref knows that thmenumii is reseted by thmenumi, and thmenumi is reseted by theorem: then the sorting will be performed correctly.

I sent the author an e-mail at 2024/01/14, but I have not received any reply yet. I wonder if you can merge it, or maintain a new cleveref package? Thanks.

% \deal@currentlabel and \cref@resetby@list allow redefined by user. Explanation is in the following code.
\def\cref@resetby@list{thmenumii,thmenumi;thmenumi,theorem;} % the second item is the parent environment of the first item

% this is the hack to make cref work with enumitem
\let\cref@old@resetby\cref@resetby
\def\cref@resetby#1#2{%
    \let#2\relax%
    \def\@eatall##1\relax{}%
    \def\@tmpcode##1,##2;{%
        \let\qcy@next\@eatall% \@next is defined by other packages, so we use \qcy@next instead, where qcy is my name
        \ifx,##1,\else
            \ifnum\pdfstrcmp{#1}{##1}=\z@
                % \message{Enter @tmpcode, input=##1,##2; command=#1^^J}% only for debugging
                \def#2{##2}%
            \else
                \let\qcy@next\@tmpcode
            \fi
        \fi
        \qcy@next
    }%
    \expandafter\@tmpcode\cref@resetby@list,;\relax
    \ifx#2\relax%
        \cref@old@resetby{#1}{#2}%
    \fi
}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.