texlive[72088] Master/texmf-dist: zref-clever (23aug24)

commits+karl at tug.org commits+karl at tug.org
Fri Aug 23 22:57:58 CEST 2024


Revision: 72088
          https://tug.org/svn/texlive?view=revision&revision=72088
Author:   karl
Date:     2024-08-23 22:57:58 +0200 (Fri, 23 Aug 2024)
Log Message:
-----------
zref-clever (23aug24)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/zref-clever/CHANGELOG.md
    trunk/Master/texmf-dist/doc/latex/zref-clever/zref-clever-code.pdf
    trunk/Master/texmf-dist/doc/latex/zref-clever/zref-clever-doc.pdf
    trunk/Master/texmf-dist/doc/latex/zref-clever/zref-clever-doc.tex
    trunk/Master/texmf-dist/source/latex/zref-clever/zref-clever.dtx
    trunk/Master/texmf-dist/tex/latex/zref-clever/zref-clever.sty

Modified: trunk/Master/texmf-dist/doc/latex/zref-clever/CHANGELOG.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/zref-clever/CHANGELOG.md	2024-08-23 12:27:21 UTC (rev 72087)
+++ trunk/Master/texmf-dist/doc/latex/zref-clever/CHANGELOG.md	2024-08-23 20:57:58 UTC (rev 72088)
@@ -1,7 +1,17 @@
 # Changelog
 
-## [Unreleased](https://github.com/gusbrs/zref-clever/compare/v0.4.5...HEAD)
+## [Unreleased](https://github.com/gusbrs/zref-clever/compare/v0.4.6...HEAD)
 
+## [v0.4.6](https://github.com/gusbrs/zref-clever/compare/v0.4.5...v0.4.6) (2024-08-23)
+
+### Fixed
+- Fix sorting of appendix references.
+
+### Changed
+- The `counterresetters` option now receives a full comma separated list of
+  counters as value, instead of working by incrementally adding values to the
+  list.
+
 ## [v0.4.5](https://github.com/gusbrs/zref-clever/compare/v0.4.4...v0.4.5) (2024-05-20)
 
 ### Added

Modified: trunk/Master/texmf-dist/doc/latex/zref-clever/zref-clever-code.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/zref-clever/zref-clever-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/zref-clever/zref-clever-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/zref-clever/zref-clever-doc.tex	2024-08-23 12:27:21 UTC (rev 72087)
+++ trunk/Master/texmf-dist/doc/latex/zref-clever/zref-clever-doc.tex	2024-08-23 20:57:58 UTC (rev 72088)
@@ -245,20 +245,23 @@
 
 But the plethora of existing features, packages and document classes which, in
 one way or another, extends this basic functionality is a clear indication of
-a demand for more automation.  Just to name the most popular: \pkg{cleveref},
-\pkg{hyperref}, \pkg{titleref}, \pkg{nameref}, \pkg{varioref}, \pkg{fancyref},
+a demand for more automation.  Just to name the some of the most popular:
+\pkg{cleveref}, \pkg{nameref}, \pkg{titleref}, \pkg{varioref}, \pkg{fancyref},
 and the kernel's \cs{labelformat}.
 
-However, the standard cross-referencing system stores two, and only two,
-properties with the label: the printed representation of the counter last
-incremented with \cs{refstepcounter} and the page.  Of course, out of the
-mentioned desire to automate more, the need arose to store more information
-about the label to support this: the title or caption of the referenced
-object; its counter or, even better, its ``type'', that is, whether it is a
-section, chapter, figure, etc.; its hyperlink anchor, and so on.  Thus those
-two property ``fields'' of the standard label became quite a disputed real
-state.  And the packages in this area of functionality were bound to step on
-each other's toes as a result.
+However, the standard cross-referencing system traditionally stored two, and
+only two, properties with the label: the printed representation of the counter
+last incremented with \cs{refstepcounter} and the page.\footnote{Nowadays, it
+  stores 5, so that \pkg{hyperref} and \pkg{nameref} no longer need to
+  redefine \cs{label}.}  Of course, out of the mentioned desire to automate
+more, the need arose to store more information about the label to support
+this: the title or caption of the referenced object; its counter or, even
+better, its ``type'', that is, whether it is a section, chapter, figure, etc.;
+its hyperlink anchor, and so on.  Thus those two property ``fields'' of the
+standard label became quite a disputed real state.  And the packages in this
+area of functionality, or which somehow depended on extending the
+cross-referencing mechanism, were bound to step on each other's toes as a
+result.
 
 Out of this conundrum, Heiko Oberdiek eventually developed \pkg{zref}, which
 implements an extensible referencing system, making the labels store a
@@ -890,30 +893,31 @@
 any counter whose stepping may trigger its resetting, or its ``enclosing
 counters''.  This information is not easily retrievable from the counter
 itself but is (normally) stored with the counter that does the resetting.  The
-\opt{counterresetters} option adds counter names, received as a comma
-separated list, to the list of counters \pkg{zref-clever} uses to search for
-``enclosing counters'' of the counter for which a label is being set.
-Unfortunately, not every counter gets reset through the standard machinery for
-this, including some \LaTeX{} kernel ones (e.g. the \texttt{enumerate}
-environment counters).  For those, there is really no way to retrieve this
-information directly, so we have to just tell \pkg{zref-clever} about them.
-And that's what the \opt{counterresetby} option is made for.  It receives a
-comma separated list of \texttt{key=value} pairs, in which \texttt{key} is the
-counter, and \texttt{value} is its ``enclosing counter'', that is, the counter
-whose stepping results in its resetting.  This is not really an ``option'' in
-the sense of ``user choice'', it is more of a way to inform \pkg{zref-clever}
-of something it cannot know or automatically find in general.  One cannot
-place arbitrary information there, or \pkg{zref-clever} can be thoroughly
-confused.  The setting must correspond to the actual resetting behavior of the
-involved counters.  \opt{counterresetby} has precedence over the search done
-in the \opt{counterresetters} list.  The default value of
-\opt{counterresetters} includes the counters for sectioning commands of the
-standard classes which, in most cases, should be the relevant ones for
-cross-referencing purposes.  The default value of \opt{counterresetby}
-includes the \texttt{enumerate} environment counters.  So, hopefully, you
-don't need to ever bother with either of these options.  But, if you do, they
-are here.  Use them with caution though.  Since these options only affect how
-labels are set, they are not available in \cs{zcref}.
+\opt{counterresetters} option receives a full comma separated list of counter
+names, which \pkg{zref-clever} uses to search for ``enclosing counters'' of
+the counter for which a label is being set.  The order matters (see code
+documentation for details), and you should also take care to start from the
+initial value set by the package.  Unfortunately, not every counter gets reset
+through the standard machinery for this, including some \LaTeX{} kernel ones
+(e.g. the \texttt{enumerate} environment counters).  For those, there is
+really no way to retrieve this information directly, so we have to just tell
+\pkg{zref-clever} about them.  And that's what the \opt{counterresetby} option
+is made for.  It receives a comma separated list of \texttt{key=value} pairs,
+in which \texttt{key} is the counter, and \texttt{value} is its ``enclosing
+counter'', that is, the counter whose stepping results in its resetting.  This
+is not really an ``option'' in the sense of ``user choice'', it is more of a
+way to inform \pkg{zref-clever} of something it cannot know or automatically
+find in general.  One cannot place arbitrary information there, or
+\pkg{zref-clever} can be thoroughly confused.  The setting must correspond to
+the actual resetting behavior of the involved counters.  \opt{counterresetby}
+has precedence over the search done in the \opt{counterresetters} list.  The
+default value of \opt{counterresetters} includes the counters for sectioning
+commands of the standard classes which, in most cases, should be the relevant
+ones for cross-referencing purposes.  The default value of
+\opt{counterresetby} includes the \texttt{enumerate} environment counters.
+So, hopefully, you don't need to ever bother with either of these options.
+But, if you do, they are here.  Use them with caution though.  Since these
+options only affect how labels are set, they are not available in \cs{zcref}.
 
 \DescribeOption{\raisebox{.4em}{\dbend}\ currentcounter} %
 \LaTeX{}'s \cs{refstepcounter} sets two variables which potentially affect the
@@ -2242,12 +2246,12 @@
 \section{Limitations}
 \zlabel{sec:limitations}
 
-Being based on \pkg{zref} entails one quite sizable advantage for
+Being based on \pkg{zref} entails one significant advantage for
 \pkg{zref-clever}: the extensible referencing system of the former allows
 \pkg{zref-clever} to store and retrieve the information it needs to work
-without having to redefine some core \LaTeX{} commands.  This alone makes for
-reduced compatibility problems and less load order issues than the average
-package in this functionality area.  On the other hand, being based on
+without having to redefine some core \LaTeX{} commands.  Which leads to less
+compatibility problems and load order issues than some traditional
+cross-reference related packages.  On the other hand, being based on
 \pkg{zref} also does impair the supported scope of \pkg{zref-clever}.  Not
 because of any particular limitation of either, but because any class or
 package which implements some special handling for reference labels
@@ -2347,9 +2351,12 @@
 refer to the appendix sectioning commands as ``appendices'' rather than
 ``chapters'' or ``sections''.  Since the sectioning commands are the same as
 before \cs{appendix}, and so are their underlying counters, we must configure
-the counter type of the sectioning counters to \texttt{appendix}.  And this is
-what this compatibility module does, and it uses a \pkg{ltcmdhooks} hook on
-\cs{appendix} for the purpose.  Hence, this module applies to any document
+the counter type of the sectioning counters to \texttt{appendix}.  Also, the
+sorting of appendix labels relative to those in the rest of the document
+requires attention, which is done by setting the main sectioning level counter
+as being reset by an internal counter with the \opt{counterresetby} option.
+And this is what this compatibility module does, using a \pkg{ltcmdhooks} hook
+on \cs{appendix} for the purpose.  Hence, this module applies to any document
 class or package which provides that command.
 
 \DescribeOption{appendices} %
@@ -2356,9 +2363,9 @@
 This module implements support for the \env{appendices} and
 \env{subappendices} environments provided by the \pkg{appendix} package, and
 also by \cls{memoir}.  The task is the same as for the \texttt{appendix}
-module: set proper counter types for the sectioning counters.  This module
-employs environment hooks to \env{appendices} and \env{subappendices} and a
-command hook to \cs{appendix} for the purpose.
+module: set proper counter types for the sectioning counters and ensuring
+proper sorting of labels.  This module employs environment hooks to
+\env{appendices} and \env{subappendices}.
 
 \DescribeOption{memoir} %
 This compatibility module provides support for some of \cls{memoir}'s
@@ -2641,6 +2648,7 @@
   % 2023-11-09: https://github.com/gusbrs/zref-clever/issues/20
   % 2024-01-20: https://github.com/gusbrs/zref-clever/pull/25
   % 2024-05-04: https://github.com/gusbrs/zref-clever/pull/27
+  % 2024-07-19: https://github.com/gusbrs/zref-clever/pull/32
   and Lars Madsen.
   % 2023-07-24: https://chat.stackexchange.com/transcript/message/64039717#64039717
   %             and following discussion.

Modified: trunk/Master/texmf-dist/source/latex/zref-clever/zref-clever.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/zref-clever/zref-clever.dtx	2024-08-23 12:27:21 UTC (rev 72087)
+++ trunk/Master/texmf-dist/source/latex/zref-clever/zref-clever.dtx	2024-08-23 20:57:58 UTC (rev 72088)
@@ -171,7 +171,7 @@
 %
 % Identify the package.
 %    \begin{macrocode}
-\ProvidesExplPackage {zref-clever} {2024-05-20} {0.4.5}
+\ProvidesExplPackage {zref-clever} {2024-08-23} {0.4.6}
   {Clever LaTeX cross-references based on zref}
 %    \end{macrocode}
 %
@@ -374,19 +374,34 @@
 % there is no possible verification mechanism for this.
 %
 %
-% \begin{macro}[EXP]{\@@_get_enclosing_counters_value:n}
-%   Recursively generate a \emph{sequence} of ``enclosing counters'' values,
-%   for a given \meta{counter} and leave it in the input stream.  This
-%   function must be expandable, since it gets called from \cs{zref at newprop}
-%   and is the one responsible for generating the desired information when
-%   the label is being set.  Note that the order in which we are getting this
-%   information is reversed, since we are navigating the counter reset chain
-%   bottom-up.  But it is very hard to do otherwise here where we need
-%   expandable functions, and easy to handle at the reading side.
+% \begin{macro}[EXP]
+%   {
+%     \@@_get_enclosing_counters:n ,
+%     \@@_get_enclosing_counters_value:n ,
+%   }
+%   Recursively generate a \emph{sequence} of ``enclosing counters'' and
+%   values, for a given \meta{counter} and leave it in the input stream.
+%   These functions must be expandable, since they get called from
+%   \cs{zref at newprop} and are the ones responsible for generating the desired
+%   information when the label is being set.  Note that the order in which we
+%   are getting this information is reversed, since we are navigating the
+%   counter reset chain bottom-up.  But it is very hard to do otherwise here
+%   where we need expandable functions, and easy to handle at the reading
+%   side.
 %     \begin{syntax}
+%       \cs{@@_get_enclosing_counters:n} \Arg{counter}
 %       \cs{@@_get_enclosing_counters_value:n} \Arg{counter}
 %     \end{syntax}
 %    \begin{macrocode}
+\cs_new:Npn \@@_get_enclosing_counters:n #1
+  {
+    \cs_if_exist:cT { c@ \@@_counter_reset_by:n {#1} }
+      {
+        { \@@_counter_reset_by:n {#1} }
+        \@@_get_enclosing_counters:e
+          { \@@_counter_reset_by:n {#1} }
+      }
+  }
 \cs_new:Npn \@@_get_enclosing_counters_value:n #1
   {
     \cs_if_exist:cT { c@ \@@_counter_reset_by:n {#1} }
@@ -406,6 +421,7 @@
 % Gregorio}, aka `egreg' at
 % \url{https://tex.stackexchange.com/q/611370/#comment1529282_611385}).
 %    \begin{macrocode}
+\cs_generate_variant:Nn \@@_get_enclosing_counters:n { e }
 \cs_generate_variant:Nn \@@_get_enclosing_counters_value:n { e }
 %    \end{macrocode}
 % \end{macro}
@@ -412,10 +428,11 @@
 %
 %
 % \begin{macro}[EXP]{\@@_counter_reset_by:n}
-%   Auxiliary function for \cs{@@_get_enclosing_counters_value:n}, and useful
-%   on its own standing.  It is broken in parts to be able to use the
-%   expandable mapping functions.  \cs{@@_counter_reset_by:n} leaves in the
-%   stream the ``enclosing counter'' which resets \meta{counter}.
+%   Auxiliary function for \cs{@@_get_enclosing_counters:n} and
+%   \cs{@@_get_enclosing_counters_value:n}, and useful on its own standing.
+%   It is broken in parts to be able to use the expandable mapping functions.
+%   \cs{@@_counter_reset_by:n} leaves in the stream the ``enclosing counter''
+%   which resets \meta{counter}.
 %   \begin{syntax}
 %     \cs{@@_counter_reset_by:n} \Arg{counter}
 %   \end{syntax}
@@ -461,7 +478,15 @@
 \zref at addprop \ZREF at mainlist { zc at enclval }
 %    \end{macrocode}
 %
+% The \texttt{zc at enclcnt} property is provided for the purpose of easing the
+% debugging of counter reset chains, thus it is not added \texttt{main}
+% property list by default.
+%    \begin{macrocode}
+\zref at newprop { zc at enclcnt }
+  { \@@_get_enclosing_counters:e \l_@@_current_counter_tl }
+%    \end{macrocode}
 %
+%
 % Another piece of information we need is the page numbering format being used
 % by \cs{thepage}, so that we know when we can (or not) group a set of page
 % references in a range.  Unfortunately, \texttt{page} is not a typical
@@ -3883,37 +3908,70 @@
 %
 % \cs{l_@@_counter_resetters_seq} is used by \cs{@@_counter_reset_by:n} to
 % populate the \texttt{zc at enclval} property, and stores the list of counters
-% which are potential ``enclosing counters'' for other counters.  This option
-% is constructed such that users can only \emph{add} items to the variable.
-% There would be little gain and some risk in allowing removal, and the syntax
-% of the option would become unnecessarily more complicated.  Besides, users
-% can already override, for any particular counter, the search done from the
-% set in \cs{l_@@_counter_resetters_seq} with the \opt{counterresetby} option.
+% which are potential ``enclosing counters'' for other counters.
 %
+% Note that, as far as \LaTeX{} is concerned, a given counter can be reset by
+% \emph{any number of counters}.  \cs{counterwithin} just adds a new
+% ``within-counter'' for ``counter'' without removing any other existing ones.
+% However, the data structure of \pkg{zref-clever} can only account for
+% \emph{one} enclosing counter.  In a way, this is hard to circumvent, because
+% the underlying counter reset behavior works ``top-down'', but when looking
+% to a label built from a given counter we need to infer the enclosing
+% counters ``bottom-up''.  As a result, the reset chain we find is path
+% dependent or, more formally, what \cs{@@_counter_reset_by:n} returns depends
+% on the order in which it searches the list of
+% \cs{l_@@_counter_resetters_seq}, since it stops on the first match.  This
+% representation mismatch should not be a problem in most cases.  But one
+% should be aware of the limits it imposes.
+%
+% Consider the following case: the \cls{book} class sets, by default
+% \texttt{figure} and \texttt{table} counters to be reset every
+% \texttt{chapter}, \texttt{section} is also reset every \texttt{chapter}, of
+% course.  Suppose now we say
+% \cs{counterwithin}\texttt{\{figure\}\{section\}}.  Technically,
+% \texttt{figure} is being reset every \texttt{section} and every
+% \texttt{chapter}, but since \texttt{section} is also reset every
+% \texttt{chapter}, the original ``\texttt{chapter} resets \texttt{figure}''
+% behavior is now redundant.  Innocuous, but is still there.  Now, suppose we
+% want to find which counter is resetting \texttt{figure} using
+% \cs{@@_counter_reset_by:n}.  If \texttt{chapter} comes before
+% \texttt{section} in \cs{l_@@_counter_resetters_seq}, \texttt{chapter} will
+% be returned, and that's not what we want.  That's the reason
+% \opt{counterresetters} initial value goes bottom-up in the sectioning level,
+% since we'd expect the nesting of the reset chain to \emph{typically} work
+% top-down.
+%
+% If, despite all this, unexpected results still ensue, users can take care to
+% ``clean'' redundant resetting settings with \cs{counterwithout}.  Besides,
+% users can already override, for any particular counter, the search done from
+% the set in \cs{l_@@_counter_resetters_seq} with the \opt{counterresetby}
+% option.
+%
+% For the above reasons, since order matters, the \opt{counterresetters}
+% option can only be set by the full list of counters.  In other words, users
+% wanting to change this should take the initial value as their starting base.
+%
+% The \texttt{zc at enclcnt} \pkg{zref} property, not included by default in the
+% \texttt{main} property list, is provided for the purpose of easing the
+% debugging of counter reset chains.  So, by adding
+% \cs{zref at addprop}\texttt{\{main\}\{zc at enclcnt\}} you can inspect what the
+% values in the \texttt{zc at enclval} property correspond to.
+%
 %    \begin{macrocode}
 \seq_new:N \l_@@_counter_resetters_seq
 \keys_define:nn { zref-clever/label }
   {
     counterresetters .code:n =
-      {
-        \clist_map_inline:nn {#1}
-          {
-            \seq_if_in:NnF \l_@@_counter_resetters_seq {##1}
-              {
-                \seq_put_right:Nn
-                  \l_@@_counter_resetters_seq {##1}
-              }
-          }
-      } ,
+      { \seq_set_from_clist:Nn \l_@@_counter_resetters_seq {#1} } ,
     counterresetters .initial:n =
       {
+        subparagraph ,
+        paragraph ,
+        subsubsection ,
+        subsection ,
+        section ,
+        chapter ,
         part ,
-        chapter ,
-        section ,
-        subsection ,
-        subsubsection ,
-        paragraph ,
-        subparagraph ,
       },
     counterresetters .value_required:n = true ,
   }
@@ -7754,11 +7812,45 @@
 % appendix to ``end'', but in this case, of course, we can hook into the
 % environment instead.
 %
+% For the record, \url{https://tex.stackexchange.com/a/724742} is of
+% interest.
+%
 %    \begin{macrocode}
 \@@_compat_module:nn { appendix }
   {
+    \newcounter { zc at appendix }
+    \cs_if_exist:cTF { chapter }
+      {
+        \@@_zcsetup:e
+          {
+            counterresetby =
+              {
+%    \end{macrocode}
+% In case someone did something like
+% \texttt{\textbackslash{}counterwithin\{chapter\}\{part\}}.  Harmless
+% otherwise.
+%    \begin{macrocode}
+                zc at appendix = \@@_counter_reset_by:n { chapter } ,
+                chapter = zc at appendix ,
+              } ,
+          }
+      }
+      {
+        \cs_if_exist:cT { section }
+          {
+            \@@_zcsetup:e
+              {
+                counterresetby =
+                  {
+                    zc at appendix = \@@_counter_reset_by:n { section } ,
+                    section = zc at appendix ,
+                  } ,
+              }
+          }
+      }
     \AddToHook { cmd / appendix / before }
       {
+        \setcounter { zc at appendix } { 1 }
         \@@_zcsetup:n
           {
             countertype =
@@ -7797,26 +7889,28 @@
   {
     \@@_if_package_loaded:nT { appendix }
       {
-        \newcounter { zc at appendix }
-        \newcounter { zc at save@appendix }
-        \setcounter { zc at appendix } { 0 }
-        \setcounter { zc at save@appendix } { 0 }
-        \cs_if_exist:cTF { chapter }
-          {
-            \@@_zcsetup:n
-              { counterresetby = { chapter = zc at appendix } }
-          }
-          {
-            \cs_if_exist:cT { section }
-              {
-                \@@_zcsetup:n
-                  { counterresetby = { section = zc at appendix } }
-              }
-          }
         \AddToHook { env / appendices / begin }
           {
-            \stepcounter { zc at save@appendix }
-            \setcounter { zc at appendix } { \value { zc at save@appendix } }
+%    \end{macrocode}
+% Technically, the \env{appendices} environment can be called multiple times.
+% By default, successive calls keep track of numbering and start where the
+% previous one left off.  Which means just setting the \texttt{zc at appendix}
+% counter to 1 is enough for things to work, since the distinction between the
+% calls and the sorting of their respective references will depend on the
+% underlying sectioning.  \pkg{appendix}'s documentation however, provides a
+% way to restart from A at each call (by redefining \cs{restoreapp} to do
+% nothing).  In this case, the references inside different calls to
+% \env{appendices} get to be identical in every way, including printed form,
+% counter value, enclosing counters, etc., despite being different.  We could
+% keep track of different calls to \env{appendices} by having the
+% \texttt{zc at appendix} counter be ``stepped'' at each call.  Doing so would
+% mean though that \cs{zcref} would distingish things which are typeset
+% identically, granting some arguably weird results.  True, the user
+% \emph{can} change the printed form for each \env{appendices} call,
+% e.g. redefining \cs{thechapter}, but in this case, they are responsible for
+% keeping track of this.
+%    \begin{macrocode}
+            \setcounter { zc at appendix } { 1 }
             \@@_zcsetup:n
               {
                 countertype =
@@ -7832,13 +7926,36 @@
           }
         \AddToHook { env / appendices / end }
           { \setcounter { zc at appendix } { 0 } }
-        \AddToHook { cmd / appendix / before }
+        \newcounter { zc at subappendix }
+        \cs_if_exist:cTF { chapter }
           {
-            \stepcounter { zc at save@appendix }
-            \setcounter { zc at appendix } { \value { zc at save@appendix } }
+            \@@_zcsetup:e
+              {
+                counterresetby =
+                  {
+                    zc at subappendix = \@@_counter_reset_by:n { section } ,
+                    section = zc at subappendix ,
+                  } ,
+              }
           }
+          {
+            \@@_zcsetup:e
+              {
+                counterresetby =
+                  {
+                    zc at subappendix = \@@_counter_reset_by:n { subsection } ,
+                    subsection = zc at subappendix ,
+                  } ,
+              }
+          }
         \AddToHook { env / subappendices / begin }
           {
+%    \end{macrocode}
+% The \env{subappendices} environment, on the other hand, appears not to
+% support multiple calls inside the same chapter/section (the counter is reset
+% by default).  Either way, the same reasoning applies.
+%    \begin{macrocode}
+            \setcounter { zc at subappendix } { 1 }
             \@@_zcsetup:n
               {
                 countertype =
@@ -7851,6 +7968,8 @@
                   } ,
               }
           }
+        \AddToHook { env / subappendices / end }
+          { \setcounter { zc at subappendix } { 0 } }
         \msg_info:nnn { zref-clever } { compat-package } { appendix }
       }
   }
@@ -7977,10 +8096,13 @@
           }
 %    \end{macrocode}
 % \pkg{amsmath} does use \cs{refstepcounter} for the \texttt{equation} counter
-% throughout and does set \cs{@currentcounter} for \cs{tag}s.  But we still
-% have to manually reset \opt{currentcounter} to default because, since we had
-% to manually set \opt{currentcounter} to \texttt{parentequation} in
-% \env{subequations}, we also have to manually set it to \env{equation} in
+% throughout and supposedly sets \cs{@currentcounter} for \cs{tag}s (I'm not
+% sure if it works in all environments, though.  Once I tried to remove the
+% explicit \opt{currentcounter} setting and several labels to \cs{tag}s ended
+% up with type \texttt{section}.  But I didn't investigate this further).  But
+% we still have to manually reset \opt{currentcounter} to default because,
+% since we had to manually set \opt{currentcounter} to \texttt{parentequation}
+% in \env{subequations}, we also have to manually set it to \env{equation} in
 % environments which may be used within it.  The \env{xxalignat} environment
 % is not included, because it is ``starred'' by default (i.e.\ unnumbered),
 % and does not display or accepts labels or tags anyway.  The \env{-ed}
@@ -8041,6 +8163,18 @@
 % doing special handling inside \cs{zcref}, but the feature is very cool, so
 % it's worth it.
 %
+% Note that this support comes at a little cost.  \opt{showonlyrefs} works by
+% setting a special \cs{MT at newlabel} for each label referenced with
+% \cs{eqref}.  Now, \cs{eqref} is a specialized reference command, only used
+% to refer to equations, so it sets \cs{MT at newlabel} unconditionally on the
+% first run.  \cs{zcref}, on the other hand, is a general purpose reference
+% command, used to reference labels of any type.  But we wouldn't want to set
+% \cs{MT at newlabel} indiscriminately for all referenced labels in the document,
+% so we need to test for its type.  Alas, the label must exist before its type
+% can be tested, thus we cannot set \cs{MT at newlabel} on the first run, only on
+% the second.  In sum, since \cs{eqref} requires 3 runs to work, \cs{zcref}
+% needs 4.
+%
 %    \begin{macrocode}
 \bool_new:N \l_@@_mathtools_loaded_bool
 \@@_compat_module:nn { mathtools }

Modified: trunk/Master/texmf-dist/tex/latex/zref-clever/zref-clever.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/zref-clever/zref-clever.sty	2024-08-23 12:27:21 UTC (rev 72087)
+++ trunk/Master/texmf-dist/tex/latex/zref-clever/zref-clever.sty	2024-08-23 20:57:58 UTC (rev 72088)
@@ -52,7 +52,7 @@
         'zref-clever' requires a LaTeX kernel \zrefclever at required@kernel\space or newer.%
       }%
   }%
-\ProvidesExplPackage {zref-clever} {2024-05-20} {0.4.5}
+\ProvidesExplPackage {zref-clever} {2024-08-23} {0.4.6}
   {Clever LaTeX cross-references based on zref}
 \RequirePackage { zref-base }
 \RequirePackage { zref-user }
@@ -102,6 +102,15 @@
 \zref at addprop \ZREF at mainlist { zc at cntval }
 \zref at newprop* { zc at pgval } [0] { \int_use:c { c at page } }
 \zref at addprop \ZREF at mainlist { zc at pgval }
+\cs_new:Npn \__zrefclever_get_enclosing_counters:n #1
+  {
+    \cs_if_exist:cT { c@ \__zrefclever_counter_reset_by:n {#1} }
+      {
+        { \__zrefclever_counter_reset_by:n {#1} }
+        \__zrefclever_get_enclosing_counters:e
+          { \__zrefclever_counter_reset_by:n {#1} }
+      }
+  }
 \cs_new:Npn \__zrefclever_get_enclosing_counters_value:n #1
   {
     \cs_if_exist:cT { c@ \__zrefclever_counter_reset_by:n {#1} }
@@ -111,6 +120,7 @@
           { \__zrefclever_counter_reset_by:n {#1} }
       }
   }
+\cs_generate_variant:Nn \__zrefclever_get_enclosing_counters:n { e }
 \cs_generate_variant:Nn \__zrefclever_get_enclosing_counters_value:n { e }
 \cs_new:Npn \__zrefclever_counter_reset_by:n #1
   {
@@ -144,6 +154,8 @@
       \l__zrefclever_current_counter_tl
   }
 \zref at addprop \ZREF at mainlist { zc at enclval }
+\zref at newprop { zc at enclcnt }
+  { \__zrefclever_get_enclosing_counters:e \l__zrefclever_current_counter_tl }
 \int_new:N \g__zrefclever_page_format_int
 \tl_new:N \g__zrefclever_prev_page_format_tl
 \AddToHook { shipout / before }
@@ -2418,25 +2430,16 @@
 \keys_define:nn { zref-clever/label }
   {
     counterresetters .code:n =
-      {
-        \clist_map_inline:nn {#1}
-          {
-            \seq_if_in:NnF \l__zrefclever_counter_resetters_seq {##1}
-              {
-                \seq_put_right:Nn
-                  \l__zrefclever_counter_resetters_seq {##1}
-              }
-          }
-      } ,
+      { \seq_set_from_clist:Nn \l__zrefclever_counter_resetters_seq {#1} } ,
     counterresetters .initial:n =
       {
+        subparagraph ,
+        paragraph ,
+        subsubsection ,
+        subsection ,
+        section ,
+        chapter ,
         part ,
-        chapter ,
-        section ,
-        subsection ,
-        subsubsection ,
-        paragraph ,
-        subparagraph ,
       },
     counterresetters .value_required:n = true ,
   }
@@ -5389,8 +5392,34 @@
 \cs_generate_variant:Nn \__zrefclever_get_rf_opt_bool:nnnnN { nneeN }
 \__zrefclever_compat_module:nn { appendix }
   {
+    \newcounter { zc at appendix }
+    \cs_if_exist:cTF { chapter }
+      {
+        \__zrefclever_zcsetup:e
+          {
+            counterresetby =
+              {
+                zc at appendix = \__zrefclever_counter_reset_by:n { chapter } ,
+                chapter = zc at appendix ,
+              } ,
+          }
+      }
+      {
+        \cs_if_exist:cT { section }
+          {
+            \__zrefclever_zcsetup:e
+              {
+                counterresetby =
+                  {
+                    zc at appendix = \__zrefclever_counter_reset_by:n { section } ,
+                    section = zc at appendix ,
+                  } ,
+              }
+          }
+      }
     \AddToHook { cmd / appendix / before }
       {
+        \setcounter { zc at appendix } { 1 }
         \__zrefclever_zcsetup:n
           {
             countertype =
@@ -5409,26 +5438,9 @@
   {
     \__zrefclever_if_package_loaded:nT { appendix }
       {
-        \newcounter { zc at appendix }
-        \newcounter { zc at save@appendix }
-        \setcounter { zc at appendix } { 0 }
-        \setcounter { zc at save@appendix } { 0 }
-        \cs_if_exist:cTF { chapter }
-          {
-            \__zrefclever_zcsetup:n
-              { counterresetby = { chapter = zc at appendix } }
-          }
-          {
-            \cs_if_exist:cT { section }
-              {
-                \__zrefclever_zcsetup:n
-                  { counterresetby = { section = zc at appendix } }
-              }
-          }
         \AddToHook { env / appendices / begin }
           {
-            \stepcounter { zc at save@appendix }
-            \setcounter { zc at appendix } { \value { zc at save@appendix } }
+            \setcounter { zc at appendix } { 1 }
             \__zrefclever_zcsetup:n
               {
                 countertype =
@@ -5444,13 +5456,31 @@
           }
         \AddToHook { env / appendices / end }
           { \setcounter { zc at appendix } { 0 } }
-        \AddToHook { cmd / appendix / before }
+        \newcounter { zc at subappendix }
+        \cs_if_exist:cTF { chapter }
           {
-            \stepcounter { zc at save@appendix }
-            \setcounter { zc at appendix } { \value { zc at save@appendix } }
+            \__zrefclever_zcsetup:e
+              {
+                counterresetby =
+                  {
+                    zc at subappendix = \__zrefclever_counter_reset_by:n { section } ,
+                    section = zc at subappendix ,
+                  } ,
+              }
           }
+          {
+            \__zrefclever_zcsetup:e
+              {
+                counterresetby =
+                  {
+                    zc at subappendix = \__zrefclever_counter_reset_by:n { subsection } ,
+                    subsection = zc at subappendix ,
+                  } ,
+              }
+          }
         \AddToHook { env / subappendices / begin }
           {
+            \setcounter { zc at subappendix } { 1 }
             \__zrefclever_zcsetup:n
               {
                 countertype =
@@ -5463,6 +5493,8 @@
                   } ,
               }
           }
+        \AddToHook { env / subappendices / end }
+          { \setcounter { zc at subappendix } { 0 } }
         \msg_info:nnn { zref-clever } { compat-package } { appendix }
       }
   }



More information about the tex-live-commits mailing list.