[latex3-commits] [git/LaTeX3-latex3-latex2e] counterwithin: new implementation (92f8d4e6)

Frank Mittelbach frank.mittelbach at latex-project.org
Thu Jul 8 20:08:05 CEST 2021


Repository : https://github.com/latex3/latex2e
On branch  : counterwithin
Link       : https://github.com/latex3/latex2e/commit/92f8d4e6a8018c091c714499710dfbe45d0941d4

>---------------------------------------------------------------

commit 92f8d4e6a8018c091c714499710dfbe45d0941d4
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date:   Thu Jul 8 20:08:05 2021 +0200

    new implementation


>---------------------------------------------------------------

92f8d4e6a8018c091c714499710dfbe45d0941d4
 base/ltcounts.dtx                   |  30 +++++-
 base/testfiles/tlb-remreset-002.tlg |  12 +--
 base/testfiles/tlb-remreset-004.lvt |   8 +-
 base/testfiles/tlb-remreset-004.tlg | 203 +++++-------------------------------
 4 files changed, 65 insertions(+), 188 deletions(-)

diff --git a/base/ltcounts.dtx b/base/ltcounts.dtx
index 445cac2f..7e3f9ae4 100644
--- a/base/ltcounts.dtx
+++ b/base/ltcounts.dtx
@@ -106,20 +106,22 @@
 %
 %
 % \DescribeMacro\counterwithin
-% |\counterwithin|\marg{counter}\marg{within-counter}:
+% |\counterwithin|\oarg{format}\marg{counter}\marg{within-counter}:
 % Resets \meta{counter} whenever
 % \meta{within-counter} is stepped. Also
 % redefines |\the|\meta{counter} command to produce
-% |\the|\meta{within-counter}|.\arabic|\marg{counter}.
+% |\the|\meta{within-counter}|.\Arg{format}|\marg{counter} with \cs{arabic} as
+% the default for \Arg{format}.
 % Star form omits redefining the print representation.
 
 %
 % \DescribeMacro\counterwithout
-% |\counterwithout|\marg{counter}\marg{within-counter}:
+% |\counterwithout|\oarg{format}\marg{counter}\marg{within-counter}:
 % Removes \meta{counter} from the reset list of \meta{within-counter}.
 % Also
 % redefines |\the|\meta{counter} command to produce
-% |\arabic|\marg{counter}.
+% \arg{format}|\marg{counter} with \cs{arabic} as
+% the default for \Arg{format}.
 % Star form omits redefining the print representation.
 %
 % \StopEventually{}
@@ -424,6 +426,26 @@
 %  \end{macro}
 
 
+\RenewDocumentCommand\counterwithout{sO{\arabic}mm}{%
+  \@ifbothcounters{#3}{#4}{%
+    \@removefromreset{#3}{#4}%
+    \IfBooleanF #1%
+        {\expandafter
+         \gdef\csname the#3\endcsname {#2{#3}}}%
+  }%
+}
+
+
+\RenewDocumentCommand\counterwithin{sO{\arabic}mm}{%
+  \@ifbothcounters{#3}{#4}{%
+    \@addtoreset{#3}{#4}%
+    \IfBooleanF #1%
+       {\expandafter
+         \gdef\csname the#3\expandafter\endcsname
+         \expandafter
+             {\csname the#4\endcsname .#2{#3}}}%
+  }%
+}
 %
 %    \begin{macrocode}
 %</2ekernel|latexrelease>
diff --git a/base/testfiles/tlb-remreset-002.tlg b/base/testfiles/tlb-remreset-002.tlg
index 72b47c94..1281578f 100644
--- a/base/testfiles/tlb-remreset-002.tlg
+++ b/base/testfiles/tlb-remreset-002.tlg
@@ -75,7 +75,7 @@ l. ...\show\cl at subsection
 l. ...\show\thesection
                          % \arabic{section}
 > \thesection=macro:
-->\@arabic \c at section .
+->\arabic {section}.
 l. ...\show\thesection
                          % unchanged as it wasn't on before
 > \cl at subsection=macro:
@@ -91,7 +91,7 @@ l. ...\show\cl at section
 l. ...\show\thesubsection
                          % \thesubsection . \arabic{subsubsection}
 > \thesubsection=macro:
-->\@arabic \c at subsection .
+->\arabic {subsection}.
 l. ...\show\thesubsection
                          % changed to \arabic{subsection}
 > \cl at subsection=macro:
@@ -103,7 +103,7 @@ l. ...\show\cl at subsection
 l. ...\show\cl at section
                          % now empty
 > \thefootnote=macro:
-->\thesubsection .\@arabic \c at footnote .
+->\thesubsection .\arabic {footnote}.
 l. ...\show\thefootnote
                          % \thesubsection.\arabic{footnote}
 > \cl at subsection=macro:
@@ -111,7 +111,7 @@ l. ...\show\thefootnote
 l. ...\show\cl at subsection
                          % footnote added
 > \thefootnote=macro:
-->\@arabic \c at footnote .
+->\arabic {footnote}.
 l. ...\show\thefootnote
                          % back to \arabic{footnote}
 > \cl at subsection=macro:
@@ -149,7 +149,7 @@ l. ...\show\thefootnot
 l. ...\show\cl at subsection
                          % unchanged
 > \thefootnote=macro:
-->\thesubsection .\@arabic \c at footnote .
+->\thesubsection .\arabic {footnote}.
 l. ...\show\thefootnote
                          % \thesubsection.\arabic{footnote}
 > \cl at subsection=macro:
@@ -157,7 +157,7 @@ l. ...\show\thefootnote
 l. ...\show\cl at subsection
                          % 3 footnote resets?
 > \thefootnote=macro:
-->\@arabic \c at footnote .
+->\arabic {footnote}.
 l. ...\show\thefootnote
                          % \arabic{footnote}
 > \cl at subsection=macro:
diff --git a/base/testfiles/tlb-remreset-004.lvt b/base/testfiles/tlb-remreset-004.lvt
index 68797de5..5e9b62b1 100644
--- a/base/testfiles/tlb-remreset-004.lvt
+++ b/base/testfiles/tlb-remreset-004.lvt
@@ -25,7 +25,7 @@
 
 \counterwithout[\roman]{footnote}{baz}
 
-\show\thefootnote  % \arabic{footnote}
+\show\thefootnote  % \arabic{footnote}  -- unchanged
 \show\cl at baz       % undefined
 \show\cl at footnote  % empty
 
@@ -40,13 +40,15 @@
 
 \show\thesection    % \arabic{section}
 
+\typeout{Next case is weird, perhaps a check after all?}
+
 \counterwithout[\roman]{section}{subsection}
 
-\show\thesection    % unchanged as it wasn't on before
+\show\thesection    % \roman --- even though there is nothing else happening
 \show\cl at subsection % unchanged
 \show\cl at section    % unchanged
 
-\show\thesubsection % \thesubsection . \roman{subsubsection}
+\show\thesubsection % \thesubsection . \arabic{subsubsection}
 
 \counterwithout[\roman]{subsection}{section}
 
diff --git a/base/testfiles/tlb-remreset-004.tlg b/base/testfiles/tlb-remreset-004.tlg
index cad17b19..738004eb 100644
--- a/base/testfiles/tlb-remreset-004.tlg
+++ b/base/testfiles/tlb-remreset-004.tlg
@@ -12,23 +12,14 @@ l. ...\show\cl at chapter
 > \cl at section=macro:
 ->\@elt {subsection}.
 l. ...\show\cl at section
-! LaTeX Error: No counter '[' defined.
+! LaTeX Error: No counter 'foo' defined.
 See the LaTeX manual or LaTeX Companion for explanation.
 Type  H <return>  for immediate help.
  ...                                              
-l. ...\counterwithout[\roman
-                           ]{foo}{baz}
+l. ...\counterwithout[\roman]{foo}{baz}
 Your command was ignored.
 Type  I <command> <return>  to replace it with another command,
 or  <return>  to continue without it.
-! LaTeX Error: Missing \begin{document}.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman]
-                            {foo}{baz}
-You're in trouble here.  Try typing  <return>  to proceed.
-If that doesn't work, type  X <return>  to quit.
 > \thefoo=undefined.
 l. ...\show\thefoo
                    % undefined
@@ -38,27 +29,18 @@ l. ...\show\cl at foo
 > \cl at baz=undefined.
 l. ...\show\cl at baz
                    % undefined
-! LaTeX Error: No counter '[' defined.
+! LaTeX Error: No counter 'baz' defined.
 See the LaTeX manual or LaTeX Companion for explanation.
 Type  H <return>  for immediate help.
  ...                                              
-l. ...\counterwithout[\roman
-                           ]{footnote}{baz}
+l. ...\counterwithout[\roman]{footnote}{baz}
 Your command was ignored.
 Type  I <command> <return>  to replace it with another command,
 or  <return>  to continue without it.
-! LaTeX Error: Missing \begin{document}.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman]
-                            {footnote}{baz}
-You're in trouble here.  Try typing  <return>  to proceed.
-If that doesn't work, type  X <return>  to quit.
 > \thefootnote=macro:
 ->\@arabic \c at footnote .
 l. ...\show\thefootnote
-                        % \arabic{footnote}
+                        % \arabic{footnote}  -- unchanged
 > \cl at baz=undefined.
 l. ...\show\cl at baz
                         % undefined
@@ -66,23 +48,14 @@ l. ...\show\cl at baz
 ->.
 l. ...\show\cl at footnote
                         % empty
-! LaTeX Error: No counter '[' defined.
+! LaTeX Error: No counter 'chapter' defined.
 See the LaTeX manual or LaTeX Companion for explanation.
 Type  H <return>  for immediate help.
  ...                                              
-l. ...\counterwithout[\roman
-                           ]{chapter}{section}
+l. ...\counterwithout[\roman]{chapter}{section}
 Your command was ignored.
 Type  I <command> <return>  to replace it with another command,
 or  <return>  to continue without it.
-! LaTeX Error: Missing \begin{document}.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman]
-                            {chapter}{section}
-You're in trouble here.  Try typing  <return>  to proceed.
-If that doesn't work, type  X <return>  to quit.
 > \thechapter=undefined.
 l. ...\show\thechapter
                         % undefined
@@ -101,27 +74,11 @@ l. ...\show\cl at subsection
 ->\@arabic \c at section .
 l. ...\show\thesection
                          % \arabic{section}
-! LaTeX Error: No counter '[' defined.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman
-                           ]{section}{subsection}
-Your command was ignored.
-Type  I <command> <return>  to replace it with another command,
-or  <return>  to continue without it.
-! LaTeX Error: Missing \begin{document}.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman]
-                            {section}{subsection}
-You're in trouble here.  Try typing  <return>  to proceed.
-If that doesn't work, type  X <return>  to quit.
-> \thesection=\long macro:
-->\@arabic \c at section .
+Next case is weird, perhaps a check after all?
+> \thesection=macro:
+->\roman {section}.
 l. ...\show\thesection
-                         % unchanged as it wasn't on before
+                         % \roman --- even though there is nothing else happ...
 > \cl at subsection=macro:
 ->\@elt {subsubsection}.
 l. ...\show\cl at subsection
@@ -133,26 +90,9 @@ l. ...\show\cl at section
 > \thesubsection=\long macro:
 ->\thesection .\@arabic \c at subsection .
 l. ...\show\thesubsection
-                         % \thesubsection . \roman{subsubsection}
-! LaTeX Error: No counter '[' defined.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman
-                           ]{subsection}{section}
-Your command was ignored.
-Type  I <command> <return>  to replace it with another command,
-or  <return>  to continue without it.
-! LaTeX Error: Missing \begin{document}.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman]
-                            {subsection}{section}
-You're in trouble here.  Try typing  <return>  to proceed.
-If that doesn't work, type  X <return>  to quit.
-> \thesubsection=\long macro:
-->\thesection .\@arabic \c at subsection .
+                         % \thesubsection . \arabic{subsubsection}
+> \thesubsection=macro:
+->\roman {subsection}.
 l. ...\show\thesubsection
                          % unchanged
 > \cl at subsection=macro:
@@ -160,155 +100,68 @@ l. ...\show\thesubsection
 l. ...\show\cl at subsection
                          % unchanged
 > \cl at section=macro:
-->\@elt {subsection}.
+->.
 l. ...\show\cl at section
                          % now empty
 > \thefootnote=macro:
-->\thesubsection .\@arabic \c at footnote .
+->\thesubsection .\arabic {footnote}.
 l. ...\show\thefootnote
                          % \arabic{footnote}
 > \cl at subsection=macro:
 ->\@elt {subsubsection}\@elt {footnote}.
 l. ...\show\cl at subsection
                          % footnote added
-! LaTeX Error: No counter '[' defined.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman
-                           ]{footnote}{subsection}
-Your command was ignored.
-Type  I <command> <return>  to replace it with another command,
-or  <return>  to continue without it.
-! LaTeX Error: Missing \begin{document}.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman]
-                            {footnote}{subsection}
-You're in trouble here.  Try typing  <return>  to proceed.
-If that doesn't work, type  X <return>  to quit.
 > \thefootnote=macro:
-->\thesubsection .\@arabic \c at footnote .
+->\roman {footnote}.
 l. ...\show\thefootnote
                          % \arabic{footnote}
 > \cl at subsection=macro:
-->\@elt {subsubsection}\@elt {footnote}.
+->\@elt {subsubsection}.
 l. ...\show\cl at subsection
                          % footnote removed
-! LaTeX Error: No counter '[' defined.
+! LaTeX Error: No counter 'footnot' defined.
 See the LaTeX manual or LaTeX Companion for explanation.
 Type  H <return>  for immediate help.
  ...                                              
-l. ...\counterwithin[\roman
-                          ]{footnot}{subsection}
+l. ...\counterwithin[\roman]{footnot}{subsection}
 Your command was ignored.
 Type  I <command> <return>  to replace it with another command,
 or  <return>  to continue without it.
-! LaTeX Error: Missing \begin{document}.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithin[\roman]
-                           {footnot}{subsection}
-You're in trouble here.  Try typing  <return>  to proceed.
-If that doesn't work, type  X <return>  to quit.
 > \thefootnot=undefined.
 l. ...\show\thefootnot
                          % undefined
 > \cl at subsection=macro:
-->\@elt {subsubsection}\@elt {footnote}.
+->\@elt {subsubsection}.
 l. ...\show\cl at subsection
                          % unchanged
-! LaTeX Error: No counter '[' defined.
+! LaTeX Error: No counter 'footnot' defined.
 See the LaTeX manual or LaTeX Companion for explanation.
 Type  H <return>  for immediate help.
  ...                                              
-l. ...\counterwithout[\roman
-                           ]{footnot}{subsection}
+l. ...\counterwithout[\roman]{footnot}{subsection}
 Your command was ignored.
 Type  I <command> <return>  to replace it with another command,
 or  <return>  to continue without it.
-! LaTeX Error: Missing \begin{document}.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman]
-                            {footnot}{subsection}
-You're in trouble here.  Try typing  <return>  to proceed.
-If that doesn't work, type  X <return>  to quit.
 > \thefootnot=undefined.
 l. ...\show\thefootnot
                          % undefined
 > \cl at subsection=macro:
-->\@elt {subsubsection}\@elt {footnote}.
+->\@elt {subsubsection}.
 l. ...\show\cl at subsection
                          % unchanged
-! LaTeX Error: No counter '[' defined.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithin[\roman
-                          ]{footnote}{subsection}
-Your command was ignored.
-Type  I <command> <return>  to replace it with another command,
-or  <return>  to continue without it.
-! LaTeX Error: Missing \begin{document}.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithin[\roman]
-                           {footnote}{subsection}
-You're in trouble here.  Try typing  <return>  to proceed.
-If that doesn't work, type  X <return>  to quit.
-! LaTeX Error: No counter '[' defined.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithin[\arabic
-                           ]{footnote}{subsection}
-Your command was ignored.
-Type  I <command> <return>  to replace it with another command,
-or  <return>  to continue without it.
-! LaTeX Error: No counter '[' defined.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithin[\Roman
-                          ]{footnote}{subsection}
-Your command was ignored.
-Type  I <command> <return>  to replace it with another command,
-or  <return>  to continue without it.
 > \thefootnote=macro:
-->\thesubsection .\@arabic \c at footnote .
+->\thesubsection .\Roman {footnote}.
 l. ...\show\thefootnote
                          % \Roman{footnote}
 > \cl at subsection=macro:
-->\@elt {subsubsection}\@elt {footnote}.
+->\@elt {subsubsection}\@elt {footnote}\@elt {footnote}\@elt {footnote}.
 l. ...\show\cl at subsection
                          % 3 footnote?
-! LaTeX Error: No counter '[' defined.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman
-                           ]{footnote}{subsection}
-Your command was ignored.
-Type  I <command> <return>  to replace it with another command,
-or  <return>  to continue without it.
-! LaTeX Error: Missing \begin{document}.
-See the LaTeX manual or LaTeX Companion for explanation.
-Type  H <return>  for immediate help.
- ...                                              
-l. ...\counterwithout[\roman]
-                            {footnote}{subsection}
-You're in trouble here.  Try typing  <return>  to proceed.
-If that doesn't work, type  X <return>  to quit.
 > \thefootnote=macro:
-->\thesubsection .\@arabic \c at footnote .
+->\roman {footnote}.
 l. ...\show\thefootnote
                          % \roman{footnote}
 > \cl at subsection=macro:
-->\@elt {subsubsection}\@elt {footnote}.
+->\@elt {subsubsection}.
 l. ...\show\cl at subsection
                          % all footnotes removed?





More information about the latex3-commits mailing list.