# suffix package, cannot redefine a suffixed macro

I have two local packages A and B. Package B is used occasionally to override macros defined in package A.

Package A defines a macro and, using the suffix package, also defines a starred version of the macro.

Package B overrides both macros (unstarred and starred) from A. The redefinition of the unstarred macro works, but the redefinition of the starred version is be ignored; the * is taken as text.

Here is an example:

\documentclass{article}
\usepackage{suffix}
\newcommand{\mymacro}[1]{Plain Hello #1}
\WithSuffix\newcommand\mymacro*[1]{Starred Hello #1}
\begin{document}

\mymacro{world}

\mymacro*{world}

\rule{\textwidth}{1pt}
\renewcommand{\mymacro}[1]{Plain New Hello #1}
\WithSuffix\renewcommand\mymacro*[1]{Starred New Hello #1}

\mymacro{world}

\mymacro*{world}
\end{document}


The result of the code is here. The last call to \mymacro*{world} sees the * as text and not the redefined macro. How can I redefine the starred version?

-
Perhaps, it’s worth asking the package author about this. Even if it’s not a bug it might be a lacking feature. –  mhp Jun 15 '12 at 7:43

A quick look suggests that on the first definition, \WithSuffix records the fact that \mymacro has been modified to take a suffix. So when you do the second \WithSuffix, it does not try to alter \mymacro. However, because you've redefined \mymacro, the necessary internal code has been removed and so things will not work.

I think the only sensible approach is to alter the macro that suffix has used to store \mymacro:

\documentclass{article}
\usepackage{suffix}
\newcommand{\mymacro}[1]{Plain Hello #1}
\WithSuffix\newcommand\mymacro*[1]{Starred Hello #1}
\begin{document}

\mymacro{world}

\mymacro*{world}

\rule{\textwidth}{1pt}
\expandafter\renewcommand\expandafter
{\csname\NoSuffixName\mymacro\endcsname}[1]{Plain New Hello #1}
\WithSuffix\renewcommand\mymacro*[1]{Starred New Hello #1}

\mymacro{world}

\mymacro*{world}
\end{document}

-
I looked at the suffix package code and I doubt I ever would have seen the solution. Your code is exactly what I needed. –  Tim A Jun 14 '12 at 17:54
Instead of \csname WSF:\string\mymacro\endcsname, you can also use \csname\NoSuffixName\mymacro\endcsname. This is more robust. –  mhp Jun 14 '12 at 17:55
@mhp Edited in: I just picked up the format from \tracingall :-) –  Joseph Wright Jun 14 '12 at 18:04