josephwright / etoolbox

Tool-box for LaTeX programmers using e-TeX
LaTeX Project Public License v1.3c
41 stars 7 forks source link

\DeclareCommandCopy and parameterless macro containing \par #35

Closed mrpiggi closed 3 years ago

mrpiggi commented 3 years ago

With 2020-10-01 LaTeX2e provides \DeclareCommandCopy as superior alternative to a simple assignment with \let. However, etoolbox seems to have some problems with copying macros not defined as long but holding \par although I am not sure how and when etoolbox participates at all.

\documentclass{minimal}
\usepackage{etoolbox}
\begin{document}

% ok
\newcommand*\fooarg[1]{\par}
\DeclareCommandCopy\foobar\fooarg

% error
\newcommand*\fooplain{\par}
\DeclareCommandCopy\foobar\fooplain

%% ok
%\newrobustcmd*\fooarg[1]{\par}
%\DeclareCommandCopy\foobar\fooarg
%
%% error
%\newrobustcmd*\fooplain{\par}
%\DeclareCommandCopy\foobar\fooplain

\end{document}
muzimuzhi commented 3 years ago

A quick attempt

diff --git a/etoolbox.sty b/etoolbox.sty
index 4c07cea..c4c5b37 100644
--- a/etoolbox.sty
+++ b/etoolbox.sty
@@ -880,7 +880,7 @@

 \ifdef\NewCommandCopy
   {%
-    \def\etb@carsquare#1#2#3\@nil{#1#2}
+    \long\def\etb@carsquare#1#2#3\@nil{#1#2}
     %
     % {<cstoken>}{<true>}{<false>}
     %

Equivalently, you can try

\documentclass{minimal}
\usepackage{etoolbox}

\makeatletter
\long\def\etb@carsquare#1#2#3\@nil{#1#2}
\makeatother

\begin{document}

% ok
\newcommand*\fooarg[1]{\par}
\DeclareCommandCopy\foobar\fooarg

% error
\newcommand*\fooplain{\par}
\DeclareCommandCopy\foobar\fooplain

%% ok
%\newrobustcmd*\fooarg[1]{\par}
%\DeclareCommandCopy\foobar\fooarg
%
%% error
%\newrobustcmd*\fooplain{\par}
%\DeclareCommandCopy\foobar\fooplain

\end{document}
mrpiggi commented 3 years ago

I should really have had a look into etoolbox.sty but was a little lazy last night. Thanks for the suggested fix.