[latex3-commits] [git/latex2e] master: adjust \@ifundefined to avoid implict definition to \relax (15acc99)

David Carlisle d.p.carlisle at gmail.com
Sat Jan 6 23:40:58 CET 2018


Repository : https://github.com/latex3/latex2e
On branch  : master
Link       : https://github.com/latex3/latex2e/commit/15acc9948db073edb812c5a5f6d78747f71322da

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

commit 15acc9948db073edb812c5a5f6d78747f71322da
Author: David Carlisle <d.p.carlisle at gmail.com>
Date:   Sat Jan 6 22:40:58 2018 +0000

    adjust \@ifundefined to avoid implict definition to \relax


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

15acc9948db073edb812c5a5f6d78747f71322da
 base/changes.txt                        |    6 ++++
 base/ltdefns.dtx                        |   58 +++++++++++++++++++++++++++++++
 base/ltvers.dtx                         |    4 +--
 base/testfiles/tlb-ifundefined-2017.lvt |   17 +++++++++
 base/testfiles/tlb-ifundefined-2017.tlg |    7 ++++
 base/testfiles/tlb-ifundefined.lvt      |   17 +++++++++
 base/testfiles/tlb-ifundefined.tlg      |    7 ++++
 7 files changed, 114 insertions(+), 2 deletions(-)

diff --git a/base/changes.txt b/base/changes.txt
index 71484cb..dc8f5b3 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -4,6 +4,12 @@ completeness or accuracy and it contains some references to files that
 are not part of the distribution.
 =======================================================================
 
+2018-01-06  David Carlisle  <latex-bugs at latex-project.org>
+
+	* ltvers.dtx: possible 2018-02-01 release
+
+* ltdefns.dtx: new \@ifundefined definitions to avoit setting csname to \relax
+
 2017-12-17  Frank Mittelbach  <frank.mittelbach at latex-project.org>
 
 	 * latexrelease.dtx: Add \latexreleaseversion info
diff --git a/base/ltdefns.dtx b/base/ltdefns.dtx
index fa669c4..730fefc 100644
--- a/base/ltdefns.dtx
+++ b/base/ltdefns.dtx
@@ -1219,6 +1219,34 @@
 % \changes{LaTeX2e}{1993/11/23}{Redefined to remove a trailing \cs{fi}}
 %    Check if first arg is undefined or \cs{relax} and execute second or
 %    third arg depending,
+% \changes{LaTeX2e}{2018/01/06}{Avoid defining undefined commands to \cs{relax}}
+%    \begin{macrocode}
+%</2ekernel>
+%<latexrelease>\IncludeInRelease{2018/02/01}{\@ifundefined}
+%<latexrelease>{Leave commands undefined in \@ifundefined}%
+%<*2ekernel|latexrelease>
+%    \end{macrocode}
+% Version using |\ifcsname| to avoid defining undefined tokens to |\relax|.
+% Defined here to simplify using unmatched |\fi|.
+%    \begin{macrocode}
+\def\@ifundefined#1{%
+  \ifcsname#1\endcsname\@ifundefin at d@i\else\@ifundefin at d@ii\fi{#1}}
+%    \end{macrocode}
+%    \begin{macrocode}
+\long\def\@ifundefin at d@i#1\fi#2{\fi
+  \expandafter\ifx\csname #2\endcsname\relax
+    \@ifundefin at d@ii
+  \fi
+  \@secondoftwo}
+%    \end{macrocode}
+%    \begin{macrocode}
+\long\def\@ifundefin at d@ii\fi#1#2#3{\fi #2}
+%    \end{macrocode}
+% Now test of engine.
+%    \begin{macrocode}
+\ifx\numexpr\@undefined
+%    \end{macrocode}
+% Classic version (should not be needed as etex is assumed).
 %    \begin{macrocode}
 \def\@ifundefined#1{%
   \expandafter\ifx\csname#1\endcsname\relax
@@ -1226,6 +1254,36 @@
   \else
     \expandafter\@secondoftwo
   \fi}
+\else\ifx\directlua\@undefined
+%    \end{macrocode}
+% Use the |\ifcsname| defined above.
+%    \begin{macrocode}
+\else
+%    \end{macrocode}
+% Optimised version for Lua\TeX, using |\lastnamedcs|
+%    \begin{macrocode}
+\def\@ifundefined#1{%
+  \ifcsname#1\endcsname
+  \expandafter\ifx\lastnamedcs\relax\else
+  \expandafter\expandafter\expandafter\@thirdofthree
+  \fi
+  \fi
+  \@firstoftwo}
+%    \end{macrocode}
+%    \begin{macrocode}
+\fi
+\fi
+%</2ekernel|latexrelease>
+%<latexrelease>\EndIncludeInRelease
+%<latexrelease>\IncludeInRelease{0000/00/00}{\@ifundefined}
+%<latexrelease>{Leave commands undefined in \@ifundefined}%
+%<latexrelease>\def\@ifundefined#1{%
+%<latexrelease>  \expandafter\ifx\csname#1\endcsname\relax
+%<latexrelease>    \expandafter\@firstoftwo
+%<latexrelease>  \else
+%<latexrelease>    \expandafter\@secondoftwo
+%<latexrelease>  \fi}
+%<*2ekernel>
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/base/ltvers.dtx b/base/ltvers.dtx
index 4694c63..295dc8f 100644
--- a/base/ltvers.dtx
+++ b/base/ltvers.dtx
@@ -92,10 +92,10 @@
 %</2ekernel>
 %<latexrelease>\edef\latexreleaseversion
 %<*2ekernel|latexrelease>
-   {2017-04-15}
+   {2018-02-01}
 %</2ekernel|latexrelease>
 %<*2ekernel>
-\def\patch at level{1}
+\def\patch at level{-1}
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
diff --git a/base/testfiles/tlb-ifundefined-2017.lvt b/base/testfiles/tlb-ifundefined-2017.lvt
new file mode 100644
index 0000000..c49606a
--- /dev/null
+++ b/base/testfiles/tlb-ifundefined-2017.lvt
@@ -0,0 +1,17 @@
+\RequirePackage[2017-04-15]{latexrelease}
+\input{test2e}
+
+% testing \@ifthenelse with defined and undefinined commands
+% including unmatched \if
+% finally test whether undefined command gets set to \relax
+% or (from 2018 on) left undefined
+
+\START
+
+\wlog{test 1 \@ifundefined{\expandafter\@gobble\string\if}{Y}{N}}
+\wlog{test 2 \@ifundefined{\string\if}{Y}{N}}
+\wlog{test 3 \@ifundefined{hbox}{Y}{N}}
+\wlog{test 4 \@ifundefined{wibble}{Y}{N}}
+\wlog{test 5 \meaning\wibble}
+
+\END
\ No newline at end of file
diff --git a/base/testfiles/tlb-ifundefined-2017.tlg b/base/testfiles/tlb-ifundefined-2017.tlg
new file mode 100644
index 0000000..dfe9307
--- /dev/null
+++ b/base/testfiles/tlb-ifundefined-2017.tlg
@@ -0,0 +1,7 @@
+This is a generated file for the LaTeX2e validation system.
+Don't change this file in any respect.
+test 1 N
+test 2 Y
+test 3 N
+test 4 Y
+test 5 \relax
diff --git a/base/testfiles/tlb-ifundefined.lvt b/base/testfiles/tlb-ifundefined.lvt
new file mode 100644
index 0000000..ec19265
--- /dev/null
+++ b/base/testfiles/tlb-ifundefined.lvt
@@ -0,0 +1,17 @@
+
+\input{test2e}
+
+% testing \@ifthenelse with defined and undefinined commands
+% including unmatched \if
+% finally test whether undefined command gets set to \relax
+% or (from 2018 on) left undefined
+
+\START
+
+\wlog{test 1 \@ifundefined{\expandafter\@gobble\string\if}{Y}{N}}
+\wlog{test 2 \@ifundefined{\string\if}{Y}{N}}
+\wlog{test 3 \@ifundefined{hbox}{Y}{N}}
+\wlog{test 4 \@ifundefined{wibble}{Y}{N}}
+\wlog{test 5 \meaning\wibble}
+
+\END
\ No newline at end of file
diff --git a/base/testfiles/tlb-ifundefined.tlg b/base/testfiles/tlb-ifundefined.tlg
new file mode 100644
index 0000000..2c5412b
--- /dev/null
+++ b/base/testfiles/tlb-ifundefined.tlg
@@ -0,0 +1,7 @@
+This is a generated file for the LaTeX2e validation system.
+Don't change this file in any respect.
+test 1 N
+test 2 Y
+test 3 N
+test 4 Y
+test 5 undefined





More information about the latex3-commits mailing list