From 8bd9ffe4fcafba5fde0f7552e13033336827a474 Mon Sep 17 00:00:00 2001 From: David Carlisle Date: Wed, 22 Jan 2025 22:21:23 +0000 Subject: [PATCH] code for #1632 --- base/changes.txt | 6 ++++++ base/doc/ltnews41.tex | 8 ++++++++ base/ltcounts.dtx | 27 +++++++++++++++++++++------ base/ltxref.dtx | 5 +++-- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/base/changes.txt b/base/changes.txt index c8b2ad578..80fd69e6c 100644 --- a/base/changes.txt +++ b/base/changes.txt @@ -6,6 +6,12 @@ to completeness or accuracy and it contains some references to files that are not part of the distribution. ================================================================================ +2025-01-22 David Carlisle + + * ltcounts.dtx, ltxref.dtx: + Allow * to denote the current counter (as used by \label) in counter + related commands, \alph* \stepcounter* etc. gh/1632 + 2025-01-21 Joseph Wright * ltcmd.dtx: diff --git a/base/doc/ltnews41.tex b/base/doc/ltnews41.tex index a5002a9d5..0eb4a2b99 100644 --- a/base/doc/ltnews41.tex +++ b/base/doc/ltnews41.tex @@ -244,6 +244,14 @@ \subsection{Socket and plug conditionals} % \githubissue{1577} +\subsection{Accessing the current counter} +Counter commands such as \cs{alph}, \cs{stepcounter}, may now have +argument \texttt{*} to denote the current counter (as used by +\cs{label}). This is compatible with the \pkg{enumitem} use of +\verb|\alph*| in item labels but is generally available. +% +\githubissue{1632} + \section{Code improvements} \subsection{Refinement of \cs{MakeTitlecase}} diff --git a/base/ltcounts.dtx b/base/ltcounts.dtx index 498d5d6db..8a3107deb 100644 --- a/base/ltcounts.dtx +++ b/base/ltcounts.dtx @@ -33,7 +33,7 @@ %<*driver> % \fi \ProvidesFile{ltcounts.dtx} - [2024/10/26 v1.1p LaTeX Kernel (Counters)] + [2025/01/22 v1.2a LaTeX Kernel (Counters)] % \iffalse \documentclass{ltxdoc} \GetFileInfo{ltcounts.dtx} @@ -56,6 +56,7 @@ % % \fi % +% \providecommand\env[1]{\texttt{#1}} % % \changes{v1.0c}{1994/03/29} % {Create file from parts of ltmiscen and ltherest.} @@ -63,7 +64,9 @@ % \changes{v1.1d}{1996/04/23}{Documentation improvements} % % \section{Counters and Lengths} -% Commands for defining and using counters. This file defines: +% Commands for defining and using counters. +% This file definef the following commands. In each case \marg{counter} may be +% |*| denoting the current counter as set by a previous |\refstepcouter|. % % \DescribeMacro{\newcounter} % To define a new counter. @@ -72,13 +75,13 @@ % To set the value of counters. % % \DescribeMacro{\addtocounter} -% Increase the counter |#1| by the number |#2|. +% Increase the \marg{counter} |#1| by the number |#2|. % % \DescribeMacro{\stepcounter} -% Increase a counter by one. +% Increase th \marg{counter} by one. % % \DescribeMacro{\refstepcounter} -% Increase a counter by one, also setting the value used by |\label|. +% Increase the \marg{counter} by one, also setting the value used by |\label|. % % % \DescribeMacro{\value} @@ -246,7 +249,19 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}{\@newctr} +% \begin{macro}{\c@*} +% \changes{v1.2a}{2025/01/22}{\cs{c@*} added gh/1632} +% Make the current counter available as a \LaTeX\ counter +% with name |*|, so `\alph*` returns the current list +% counter as a letter, |\stepcounter{*}| increments the current +% counter, etc. +% \begin{macrocode} +\protected\expandafter + \def\csname c@*\endcsname{\value\@currentcounter} +% \end{macrocode} +% \end{macro} + +%\begin{macro}{\@newctr} % \changes{v1.0d}{1994/04/09} % {\cs{@nocnterr} now has counter name argument} % \changes{v1.0e}{1994/04/17} diff --git a/base/ltxref.dtx b/base/ltxref.dtx index 7acd6250b..5f4cfad3c 100644 --- a/base/ltxref.dtx +++ b/base/ltxref.dtx @@ -33,7 +33,7 @@ %<*driver> % \fi \ProvidesFile{ltxref.dtx} - [2024/12/10 v1.1s LaTeX Kernel (Cross Referencing)] + [2025/01/22 v1.1t LaTeX Kernel (Cross Referencing)] % \iffalse \documentclass{ltxdoc} \GetFileInfo{ltxref.dtx} @@ -424,6 +424,7 @@ % \changes{v1.1r}{2024/09/20}{set also \@currentHref} % \changes{v1.1r}{2024/09/20}{provide a kernel copy \@kernel@refstepcounter} % \changes{v1.1r}{2024/09/20}{add sockets} +% \changes{v1.1t}{2025/01/22}{Guard * from causing infinite loop} % \begin{macrocode} %\IncludeInRelease{2022/06/01}% % {\Ref}{Add starred version}% @@ -465,7 +466,7 @@ \def\refstepcounter#1{% \UseSocket{refstepcounter}{% \stepcounter{#1}% - \edef\@currentcounter{#1}% + \edef\@currentcounter{\ifx*#1\@currentcounter\else#1\fi}% \protected@edef\@currentlabel % \end{macrocode} % By generating the second csname first the |\p@...| command can