0

This question already has an answer here:

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
            {\speakstab\speaksfont #2\speaksdel\par\nobreak\addvspace{-\parskip}}
        \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
            {\speakstab\speaksfont #2\speaksdel\par\nobreak\addvspace{-\parskip}}
        \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: My MWE

Any clues on how to fix that error?

marked as duplicate by gernot, GuM, Marco Daniel, egreg macros Mar 9 '17 at 20:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Add \makeatletter before the \renewcommand and \makeatother after the \renewcommand... such that it reads \makeatletter\renewcommand\GCharacter[3]{...}\makeatother – gernot Mar 9 '17 at 20:09
  • 1
    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
1

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
            {\speakstab\speaksfont #2\speaksdel\par\nobreak\addvspace{-\parskip}}
        \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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.