Skip to content

Commit

Permalink
Fully expand counter name in \theH<counter> commands (#1509)
Browse files Browse the repository at this point in the history
* Fully expand counter name in `\theH<counter>` commands (#1508)

* Move tests to tlb-theHcounter-001

* minor [ci skip]
  • Loading branch information
muzimuzhi authored Oct 27, 2024
1 parent 69f76c1 commit d84e75d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions base/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ to completeness or accuracy and it contains some references to files that are
not part of the distribution.
================================================================================

2024-10-26 Yukai Chou <muzimuzhi@gmail.com>
* ltcounts.dtx (subsection{Environment Counter Macros}):
Fully expand counter name in \theH<counter> commands (gh/1508)

2024-10-23 Frank Mittelbach <Frank.Mittelbach@latex-project.org>
* doc.dtx:
A rollback comment leaked into the documentation (gh1418)
Expand Down
11 changes: 8 additions & 3 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/09/20 v1.1o LaTeX Kernel (Counters)]
[2024/10/26 v1.1p LaTeX Kernel (Counters)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltcounts.dtx}
Expand Down Expand Up @@ -310,6 +310,7 @@
% \changes{v1.1n}{2023/11/07}{Do not change \cs{the...} if already defined (gh/823)}
% \changes{v1.1o}{2024/09/20}{define theHfoo (used for internal links)}
% \begin{macrocode}
% \changes{v1.1p}{2024/10/26}{Fully expand counter name in theHfoo commands (gh/1508)}
%</2ekernel>
%<latexrelease>\IncludeInRelease{2024/11/01}{\@definecounter}
%<latexrelease> {provide theHfoo commands}%
Expand All @@ -319,7 +320,8 @@
\global\expandafter\let\csname cl@#1\endcsname\@empty
\@addtoreset{#1}{@ckpt}%
\global\expandafter\let\csname p@#1\endcsname\@empty
\expandafter\gdef\csname theH#1\endcsname{\the\value{#1}}%
\expandafter\xdef\csname theH#1\endcsname{%
\noexpand\the\noexpand\value{#1}}%
% \end{macrocode}
% If \cs{the\#1} is undefined or \cs{relax} we define it with the
% standard definition for counters, otherwise we warn. This will
Expand Down Expand Up @@ -360,6 +362,7 @@
%
% \begin{macro}{\@addtoreset}
% \changes{v1.1o}{2024/09/20}{add the parent theHfoo if a counter is reset}
% \changes{v1.1p}{2024/10/26}{Fully expand counter name in theHfoo commands (gh/1508)}
% If a counter is reset when a parent counter changes it no longer has an unique value
% across the document. As |\theH<counter>| should be unique
% this representation is changed to include also the
Expand All @@ -371,7 +374,9 @@
%<latexrelease> {provide theHfoo commands}%
%<*2ekernel|latexrelease>
\def\@addtoreset#1#2{\expandafter\@cons\csname cl@#2\endcsname {{#1}}%
\expandafter\gdef\csname theH#1\endcsname{\csname theH#2\endcsname.\the\value{#1}}%
\expandafter\xdef\csname theH#1\endcsname{%
\expandafter\noexpand\csname theH#2\endcsname.%
\noexpand\the\noexpand\value{#1}}%
}
%<latexrelease>\EndIncludeInRelease
%</2ekernel|latexrelease>
Expand Down
8 changes: 8 additions & 0 deletions base/testfiles/tlb-theHcounter-001.lvt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@
\refstepcounter{foo}
\show\@currentHref

% Tests for gh/1508
\def\fooname{foox}
\newcounter{\fooname}
\show\theHfoox

\newcounter{\fooname x}[section]
\show\theHfooxx

\END

12 changes: 10 additions & 2 deletions base/testfiles/tlb-theHcounter-001.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@ l. ...\show\theHfoo
->\the \value {baz}.
l. ...\show\theHbaz
> \theHfoo=macro:
->\csname theHbaz\endcsname .\the \value {foo}.
->\theHbaz .\the \value {foo}.
l. ...\show\theHfoo
> \theHbaz=macro:
->\the \value {baz}.
l. ...\show\theHbaz
> \theHfoo=macro:
->\csname theHbaz\endcsname .\the \value {foo}.
->\theHbaz .\the \value {foo}.
l. ...\show\theHfoo
> \theHbaz=macro:
->\the \value {baz}.
l. ...\show\theHbaz
> \@currentHref=macro:
->foo.0.1.
l. ...\show\@currentHref
\c@foox=\count...
> \theHfoox=macro:
->\the \value {foox}.
l. ...\show\theHfoox
\c@fooxx=\count...
> \theHfooxx=macro:
->\theHsection .\the \value {fooxx}.
l. ...\show\theHfooxx

0 comments on commit d84e75d

Please sign in to comment.