[latex3-commits] [git/LaTeX3-latex3-latex2e] gh239: Enforce \escapechar=`\\ when copying commands (3c919272)

PhelypeOleinik tex.phelype at gmail.com
Sun May 10 03:18:18 CEST 2020


Repository : https://github.com/latex3/latex2e
On branch  : gh239
Link       : https://github.com/latex3/latex2e/commit/3c9192726c737d5aa3d50d619596feb5a75899dc

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

commit 3c9192726c737d5aa3d50d619596feb5a75899dc
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date:   Sat May 9 22:18:18 2020 -0300

    Enforce \escapechar=`\\ when copying commands
    
    Even though \newcommand doesn't


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

3c9192726c737d5aa3d50d619596feb5a75899dc
 base/ltdefns.dtx                | 23 ++++++++++++++++-------
 base/testfiles/github-0239b.lvt |  2 --
 base/testfiles/github-0239c.lvt | 30 ++++++++++++++++++++++++++++++
 base/testfiles/github-0239c.tlg |  8 ++++++++
 4 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/base/ltdefns.dtx b/base/ltdefns.dtx
index d7c5729b..4ce6e94d 100644
--- a/base/ltdefns.dtx
+++ b/base/ltdefns.dtx
@@ -1467,6 +1467,7 @@
 %    \begin{macrocode}
 \def\CopyKernelRobustCommand#1#2{%
   \begingroup
+    \escapechar=`\\
     \edef\reserved at a{\string#1}%
     \def\reserved at b{#1}%
     \edef\reserved at b{\expandafter\strip at prefix\meaning\reserved at b}%
@@ -1499,11 +1500,15 @@
 %   accordingly.
 %    \begin{macrocode}
 \def\IfKernelCmdWithOptArg#1{%
-  \edef\reserved at a{%
+  \begingroup
+    \escapechar`\\
+    \edef\reserved at a{%
+  \endgroup
+  \def\noexpand\reserved at a{%
     \noexpand\@protected at testopt
     \noexpand#1%
-    \expandafter\noexpand\csname\string#1\endcsname
-  }%
+    \expandafter\noexpand\csname\string#1\endcsname}}%
+  \reserved at a
   \edef\reserved at b{%
     \unexpanded\expandafter\expandafter\expandafter
       {\expandafter\@carcube#1{}{}{}\@nil}}%
@@ -1519,15 +1524,19 @@
 %   \verb=\@protected at testopt\foo\\foo{<opt>}=.
 %    \begin{macrocode}
 \def\CopyKernelCmdWithOptArg#1#2{%
-  \edef#1{%
+  \begingroup
+    \escapechar=`\\
+    \edef\reserved at a{%
+  \endgroup
+  \def\noexpand#1{%
     \noexpand\@protected at testopt
     \noexpand#1%
     \expandafter\noexpand\csname\string#1\endcsname
     \unexpanded\expandafter\expandafter\expandafter
       {\expandafter\@gobblethree#2}}%
-  \expandafter\let
-    \csname\string#1\expandafter\endcsname
-    \csname\string#2\endcsname}
+  \let\expandafter\noexpand\csname\string#1\endcsname
+      \expandafter\noexpand\csname\string#2\endcsname
+  }\reserved at a}
 %    \end{macrocode}
 %
 %   Now the rollback code.
diff --git a/base/testfiles/github-0239b.lvt b/base/testfiles/github-0239b.lvt
index 4876c9e0..046d568d 100644
--- a/base/testfiles/github-0239b.lvt
+++ b/base/testfiles/github-0239b.lvt
@@ -18,10 +18,8 @@
 \def\exists{exists}
 \def\another{another}
 
-% \tracingall
 \expect{\tmpa =macro:->another|}
 \test\NewCommandCopy\tmpa\another
-% \tracingnone
 
 \expect{\exists =macro:->exists| (and an error)}
 \test\NewCommandCopy\exists\another
diff --git a/base/testfiles/github-0239c.lvt b/base/testfiles/github-0239c.lvt
new file mode 100644
index 00000000..1db68575
--- /dev/null
+++ b/base/testfiles/github-0239c.lvt
@@ -0,0 +1,30 @@
+
+\documentclass{article}
+\input{test2e}
+
+\showoutput
+
+\begin{document}
+
+\START
+
+\newcommand\testa[2][opt]{hey}
+\DeclareRobustCommand\testb[2][opt]{hey}
+\DeclareRobustCommand\$[2][opt]{hey}
+
+\escapechar-1
+
+\NewCommandCopy\tmpa\testa
+\NewCommandCopy\tmpb\testb
+\NewCommandCopy\tmpc\$
+\RenewCommandCopy\%\testb
+
+\escapechar92
+
+\typeout{\expandafter\meaning\csname\string\tmpa\endcsname}
+\typeout{\expandafter\meaning\csname\string\tmpb\space\endcsname}
+\typeout{\expandafter\meaning\csname\string\tmpc\space\endcsname}
+\typeout{\expandafter\meaning\csname\string\%\space\endcsname}
+
+\end{document}
+
diff --git a/base/testfiles/github-0239c.tlg b/base/testfiles/github-0239c.tlg
new file mode 100644
index 00000000..34df038f
--- /dev/null
+++ b/base/testfiles/github-0239c.tlg
@@ -0,0 +1,8 @@
+This is a generated file for the LaTeX2e validation system.
+Don't change this file in any respect.
+LaTeX Info: Redefining \$ on input line ....
+\long macro:[#1]#2->hey
+\long macro:[#1]#2->hey
+\long macro:[#1]#2->hey
+\long macro:[#1]#2->hey
+(github-0239c.aux)





More information about the latex3-commits mailing list.