[latex3-commits] [git/LaTeX3-latex3-latex2e] gh239: Use \cs_to_str:N rather than \escapechar tricks (f7e978e5)

PhelypeOleinik tex.phelype at gmail.com
Mon May 11 00:29:07 CEST 2020


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

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

commit f7e978e527176b6f9f059ef0f95fd4fc785d23fa
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date:   Sun May 10 19:29:07 2020 -0300

    Use \cs_to_str:N rather than \escapechar tricks


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

f7e978e527176b6f9f059ef0f95fd4fc785d23fa
 base/ltdefns.dtx | 62 +++++++++++++++++++++++++-------------------------------
 1 file changed, 28 insertions(+), 34 deletions(-)

diff --git a/base/ltdefns.dtx b/base/ltdefns.dtx
index 090c9635..1a013bca 100644
--- a/base/ltdefns.dtx
+++ b/base/ltdefns.dtx
@@ -1336,12 +1336,8 @@
 %   command being copied.
 %    \begin{macrocode}
 \def\declare at commandcopy#1#2#3#4{%
-  \begingroup
-    \escapechar=\m at ne
-    \edef\reserved at a{\endgroup
-      \def\noexpand\reserved at a{\string#3}%
-      \noexpand\@ifundefined\noexpand\reserved at a}%
-  \reserved at a{#1}{#2}%
+  \edef\reserved at a{\@expl at cs@to at str@@N#3}%
+  \@ifundefined\reserved at a{#1}{#2}%
     {\declare at command@copy#3#4}}
 %    \end{macrocode}
 %
@@ -1437,18 +1433,17 @@
 %
 %    \begin{macrocode}
 \def\@if at DeclareRobustCommand#1{%
-  \edef\reserved at a{\string#1}%
-  \def\reserved at b{#1}%
-  \edef\reserved at b{\expandafter\strip at prefix\meaning\reserved at b}%
   \begingroup
-    \escapechar\m at ne
+    \escapechar=`\\
+    \edef\reserved at a{\string#1}%
+    \edef\reserved at b{\detokenize{#1}}%
     \xdef\@gtempa{%
       \ifx\reserved at a\reserved at b
          \noexpand\x at protect
          \noexpand#1%
       \fi
       \noexpand\protect
-      \expandafter\noexpand\csname\string#1 \endcsname}%
+      \expandafter\noexpand\csname\@expl at cs@to at str@@N#1 \endcsname}%
   \endgroup
   \ifx\@gtempa#1\relax
     \expandafter\@firstoftwo
@@ -1472,9 +1467,7 @@
   \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}%
-    \escapechar=\m at ne
+    \edef\reserved at b{\detokenize{#1}}%
     \edef\reserved at a{%
   \endgroup
   \def\noexpand#1{%
@@ -1483,10 +1476,10 @@
        \noexpand#1%
     \fi
     \noexpand\protect
-    \expandafter\noexpand\csname\string#1 \endcsname}%
+    \expandafter\noexpand\csname\@expl at cs@to at str@@N#1 \endcsname}%
   \noexpand\copy at kernel@robust at command
-    \expandafter\noexpand\csname\string#1 \endcsname
-    \expandafter\noexpand\csname\string#2 \endcsname}%
+    \expandafter\noexpand\csname\@expl at cs@to at str@@N#1 \endcsname
+    \expandafter\noexpand\csname\@expl at cs@to at str@@N#2 \endcsname}%
   \reserved at a}
 \def\copy at kernel@robust at command#1#2{%
   \@if at newcommand#2%
@@ -1503,15 +1496,10 @@
 %   accordingly.
 %    \begin{macrocode}
 \def\@if at newcommand#1{%
-  \begingroup
-    \escapechar`\\
-    \edef\reserved at a{%
-  \endgroup
-  \def\noexpand\reserved at a{%
+  \edef\reserved at a{%
     \noexpand\@protected at testopt
     \noexpand#1%
-    \expandafter\noexpand\csname\string#1\endcsname}}%
-  \reserved at a
+    \expandafter\noexpand\csname\@backslashchar\@expl at cs@to at str@@N#1\endcsname}%
   \edef\reserved at b{%
     \unexpanded\expandafter\expandafter\expandafter
       {\expandafter\@carcube#1{}{}{}\@nil}}%
@@ -1527,19 +1515,25 @@
 %   \verb=\@protected at testopt\foo\\foo{<opt>}=.
 %    \begin{macrocode}
 \def\@copy at newcommand#1#2{%
-  \begingroup
-    \escapechar=`\\
-    \edef\reserved at a{%
-  \endgroup
-  \def\noexpand#1{%
-    \noexpand\@protected at testopt
+  \edef#1{\noexpand\@protected at testopt
     \noexpand#1%
-    \expandafter\noexpand\csname\string#1\endcsname
+    \expandafter\noexpand\csname\@backslashchar\@expl at cs@to at str@@N#1\endcsname
     \unexpanded\expandafter\expandafter\expandafter
       {\expandafter\@gobblethree#2}}%
-  \let\expandafter\noexpand\csname\string#1\endcsname
-      \expandafter\noexpand\csname\string#2\endcsname
-  }\reserved at a}
+  \expandafter
+  \let\csname\@backslashchar\@expl at cs@to at str@@N#1\expandafter\endcsname
+      \csname\@backslashchar\@expl at cs@to at str@@N#2\endcsname}
+%    \end{macrocode}
+%
+%   Steal the definition of \textsf{expl3}'s \cs{cs_to_str:N} for a while.  This
+%   should disappear as soon as this macro is defined in \texttt{ltexpl.dtx} as
+%   a copy of \cs{cs_to_str:N}.
+%    \begin{macrocode}
+\def\@expl at cs@to at str@@N{%
+  \romannumeral\if\string\ \@@expl at cs@to at str@@w\fi
+  \expandafter\@@expl at cs@to at str@@N\string}
+\def\@@expl at cs@to at str@@N#1{\z@}
+\def\@@expl at cs@to at str@@w#1\@@expl at cs@to at str@@N{-\number\fi\expandafter\z@}
 %    \end{macrocode}
 %
 %   Now the rollback code.





More information about the latex3-commits mailing list.