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

code for #1632 #1637

Merged
merged 13 commits into from
Jan 26, 2025
6 changes: 6 additions & 0 deletions base/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>

* 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 <[email protected]>

* ltcmd.dtx:
Expand Down
8 changes: 8 additions & 0 deletions base/doc/ltnews41.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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
the argument \texttt{*} to denote the current counter (as used by
\cs{label}). This is compatible with the package \pkg{enumitem} use of
\verb|\alph*| in item labels but is generally available.
%
\githubissue{1632}

\section{Code improvements}

\subsection{Refinement of \cs{MakeTitlecase}}
Expand Down
27 changes: 21 additions & 6 deletions base/ltcounts.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -56,14 +56,17 @@
%</driver>
% \fi
%
% \providecommand\env[1]{\texttt{#1}}
%
% \changes{v1.0c}{1994/03/29}
% {Create file from parts of ltmiscen and ltherest.}
% \changes{v1.1a}{1994/05/19}{Extracted file from ltcntlen.}
% \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 defines the following commands. In each case \marg{counter} may be
% |*| denoting the current counter as set by a previous |\refstepcounter|.
%
% \DescribeMacro{\newcounter}
% To define a new counter.
Expand All @@ -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 the \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}
Expand Down Expand Up @@ -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
% 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}
Expand Down
14 changes: 11 additions & 3 deletions base/ltxref.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
%<latexrelease>\IncludeInRelease{2022/06/01}%
%<latexrelease> {\Ref}{Add starred version}%
Expand Down Expand Up @@ -462,10 +463,14 @@
% \end{macrocode}
% \end{plugdecl}
% \begin{macrocode}
\def\ltx@star@counter{*}
\def\refstepcounter#1{%
\UseSocket{refstepcounter}{%
\stepcounter{#1}%
\edef\@currentcounter{#1}%
\edef\reserved@a{#1}%
\ifx\reserved@a\ltx@star@counter\else
\let\@currentcounter\reserved@a
\fi
\protected@edef\@currentlabel
% \end{macrocode}
% By generating the second csname first the |\p@...| command can
Expand Down Expand Up @@ -501,7 +506,10 @@
\def\@kernel@refstepcounter#1{%
\UseSocket{refstepcounter}{%
\stepcounter{#1}%
\edef\@currentcounter{#1}%
\edef\reserved@a{#1}%
\ifx\reserved@a\ltx@star@counter\else
\let\@currentcounter\reserved@a
\fi
\protected@edef\@currentlabel
{\csname p@#1\expandafter\endcsname\csname the#1\endcsname}}}%
% \end{macrocode}
Expand Down
Loading