[latex3-commits] [latex3/latex2e] develop: Gh823 (#1165) (ff81ece9)

github at latex-project.org github at latex-project.org
Wed Nov 8 17:49:18 CET 2023


Repository : https://github.com/latex3/latex2e
On branch  : develop
Link       : https://github.com/latex3/latex2e/commit/ff81ece9b2f8bffdb6a4c11d44fbcc3a18a49cb4

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

commit ff81ece9b2f8bffdb6a4c11d44fbcc3a18a49cb4
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date:   Wed Nov 8 17:49:18 2023 +0100

    Gh823 (#1165)
    
    * possible fix for #823
    
    * try again
    
    * move docu block
    
    * add news entry


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

ff81ece9b2f8bffdb6a4c11d44fbcc3a18a49cb4
 base/changes.txt               |  3 +++
 base/doc/ltnews39.tex          | 16 ++++++++++++++++
 base/ltcounts.dtx              | 19 ++++++++++++++++---
 base/testfiles/github-0823.lvt | 32 ++++++++++++++++++++++++++++++++
 base/testfiles/github-0823.tlg |  9 +++++++++
 5 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/base/changes.txt b/base/changes.txt
index f6aff0b9..29f0ad04 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -7,6 +7,9 @@ not part of the distribution.
 ================================================================================
 
 2023-11-07  Frank Mittelbach  <Frank.Mittelbach at latex-project.org>
+	* ltcounts.dtx (subsection{Environment Counter Macros}):
+	In \newcounter do not change \the... if already defined (gh/823)
+
 	* ltplain.dtx (section{Plain \TeX}):
 	Set \tracinglostchars to 2 in \tracingnone (gh/549)
 
diff --git a/base/doc/ltnews39.tex b/base/doc/ltnews39.tex
index 75d44ee9..2e037c6f 100644
--- a/base/doc/ltnews39.tex
+++ b/base/doc/ltnews39.tex
@@ -164,6 +164,22 @@ corrected.
 
 
 
+\section{Code improvements}
+
+\subsection{Warn if counter names are problematic}
+
+In the past it was possible to declare, for example,
+\verb/\newcounter{index}/ with the side-effect that this defines
+\cs{theindex}, even though \LaTeX{} has a \env{theindex} environment
+that then got clobbered by the declaration.
+%
+This has now been changed: if \cs{the}\meta{counter} is already
+defined it is not altered, but instead a warning message is displayed.
+%
+\githubissue{823}
+
+
+
 %\section{Bug fixes}
 
 %\section{Changes to packages in the \pkg{amsmath} category}
diff --git a/base/ltcounts.dtx b/base/ltcounts.dtx
index 69025fa4..d8d963f1 100644
--- a/base/ltcounts.dtx
+++ b/base/ltcounts.dtx
@@ -33,7 +33,7 @@
 %<*driver>
 % \fi
 \ProvidesFile{ltcounts.dtx}
-             [2021/07/08 v1.1m LaTeX Kernel (Counters)]
+             [2021/11/08 v1.1n LaTeX Kernel (Counters)]
 % \iffalse
 \documentclass{ltxdoc}
 \GetFileInfo{ltcounts.dtx}
@@ -305,6 +305,7 @@
 %  \begin{macro}{\@definecounter}
 %  \changes{v1.1b}{1995/05/20}{Streamlined code}
 %  \changes{v1.1c}{1995/05/20}{And do it right}
+%  \changes{v1.1n}{2023/11/07}{Do not change \cs{the...} if already defined (gh/823)}
 %
 %    \begin{macrocode}
 \def\@definecounter#1{\expandafter\newcount\csname c@#1\endcsname
@@ -312,9 +313,21 @@
      \global\expandafter\let\csname cl@#1\endcsname\@empty
      \@addtoreset{#1}{@ckpt}%
      \global\expandafter\let\csname p@#1\endcsname\@empty
+%    \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
+%    catch, for example, that somebody defines a counter named
+%    ``index'' conflicting with the \env{theindex} environment.
+%    \begin{macrocode}
      \expandafter
-     \gdef\csname the#1\expandafter\endcsname\expandafter
-          {\expandafter\@arabic\csname c@#1\endcsname}}
+     \ifx\csname the#1\endcsname\relax
+       \expandafter
+       \gdef\csname the#1\expandafter\endcsname\expandafter
+              {\expandafter\@arabic\csname c@#1\endcsname}%
+     \else
+       \@latex at warning{Command `\string\the#1' already
+                       defined -- not changed}%
+     \fi}
 %    \end{macrocode}
 %  \end{macro}
 %
diff --git a/base/testfiles/github-0823.lvt b/base/testfiles/github-0823.lvt
new file mode 100644
index 00000000..01a4806a
--- /dev/null
+++ b/base/testfiles/github-0823.lvt
@@ -0,0 +1,32 @@
+\documentclass{article}
+
+\input{test2e}
+
+\usepackage{makeidx}
+\makeindex
+
+\START
+
+% bad, but user is not warned
+\newcounter{index}
+\newcounter{bibliography}
+
+\OMIT
+\begin{document}
+\TIMO
+
+test % btw without it nothing goes to idx...
+\index{foobar}
+
+\cite{qqq}
+
+\begin{thebibliography}{99}
+\bibitem{qqq}hmm
+\end{thebibliography}
+
+% lonely \item error
+\printindex
+
+\newpage
+\OMIT
+\end{document}
diff --git a/base/testfiles/github-0823.tlg b/base/testfiles/github-0823.tlg
new file mode 100644
index 00000000..353b7cab
--- /dev/null
+++ b/base/testfiles/github-0823.tlg
@@ -0,0 +1,9 @@
+This is a generated file for the LaTeX2e validation system.
+Don't change this file in any respect.
+\c at index=\count...
+LaTeX Warning: Command `\theindex' already defined -- not changed on input line ....
+\c at bibliography=\count...
+LaTeX Warning: Command `\thebibliography' already defined -- not changed on input line ....
+No file github-0823.ind.
+[1
+]





More information about the latex3-commits mailing list.