# \renewcommand with exact same definition results in weird error [duplicate]

I'm using the dramatist package to typeset a drama script. Characters are created using the \GCharacter-command. I want to customize that command to have it execute \NewPerson for each new Character created.

To do so, I've looked up the installed dramatist.sty on my system and copied the definition of \GCharacter into my preamble like that:

\renewcommand\GCharacter[3]{
\stepcounter{g\Roman{character}}
\global\@namedef{#3}{{\namefont #2}\xspace}
\global\n@me@ppend@nddef{#3}{\@ppendname}{%
\if@drverse
\else
\item[#2\speaksdel]
\fi}
\global\n@me@ppend@nddef{gpersona@\Roman{character}}{%
@\Roman{g\Roman{character}}}{\castfont #1}
}


This is the exact definition from the dramatist.sty-file. However, LaTeX complains: ! You can't use \spacefactor in vertical mode. on the first line I use \GCharacter in. How could this be, as I've changed nothing in comparison to the original definition?

In the following MWE, the error occurs in line 19:

\documentclass[a4paper]{scrartcl}
\usepackage{dramatist}
\usepackage{lipsum}

\renewcommand\GCharacter[3]{
\stepcounter{g\Roman{character}}
\global\@namedef{#3}{{\namefont #2}\xspace}
\global\n@me@ppend@nddef{#3}{\@ppendname}{%
\if@drverse
\else
\item[#2\speaksdel]
\fi}
\global\n@me@ppend@nddef{gpersona@\Roman{character}}{%
@\Roman{g\Roman{character}}}{\castfont #1}
%\NewPerson
}

\begin{CharacterGroup}{TeX.SX}
\GCharacter{A Character}{A Character}{character}
\end{CharacterGroup}

\begin{document}
\DramPer

\lipsum[1] % Compilation fails with only \DramPer in document
\end{document}


Without the \renewcommand, everything works fine:

Any clues on how to fix that error?

## marked as duplicate by gernot, GuM, Marco Daniel, egreg macros StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Mar 9 '17 at 20:41

• you could just have used the search box for that error tex.stackexchange.com/… – David Carlisle Mar 9 '17 at 20:10
• You should consider \patchcmd instead of \renewcommand (but that does not prevent the \makeatletter...\makeatother pair) – user31729 Mar 9 '17 at 20:13
• I did a lot of search regarding customizing macros from packages and so on, but I didn't stumble upon the @-thing. Sorry about that. @Christian Hupfer: What are the advantages of \patchcmd? – LukeLR Mar 9 '17 at 20:15

It should be:

\documentclass[a4paper]{scrartcl}
\usepackage{dramatist}
\usepackage{lipsum}

\makeatletter % here
\renewcommand\GCharacter[3]{
\stepcounter{g\Roman{character}}
\global\@namedef{#3}{{\namefont #2}\xspace}
\global\n@me@ppend@nddef{#3}{\@ppendname}{%
\if@drverse
\else
\item[#2\speaksdel]
\fi}
\global\n@me@ppend@nddef{gpersona@\Roman{character}}{%
@\Roman{g\Roman{character}}}{\castfont #1}
%\NewPerson
}
\makeatother

\begin{CharacterGroup}{TeX.SX}
\GCharacter{A Character}{A Character}{character}
\end{CharacterGroup}

\begin{document}
\DramPer

\lipsum[1] % Compilation fails with only \DramPer in document
\end{document}


Inside *.sty files @'s are letters, in an ordinary *.tex file are not, hence local switch of their meaning.