0

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?

LukeLR
  • 641
  • 1
    Add \makeatletter before the \renewcommand and \makeatother after the \renewcommand... such that it reads \makeatletter\renewcommand\GCharacter[3]{...}\makeatother – gernot Mar 09 '17 at 20:09
  • 1
    you could just have used the search box for that error http://tex.stackexchange.com/search?q=%21+You+can%27t+use+%5Cspacefactor+in+vertical+mode – David Carlisle Mar 09 '17 at 20:10
  • You should consider \patchcmd instead of \renewcommand (but that does not prevent the \makeatletter...\makeatother pair) –  Mar 09 '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 09 '17 at 20:15

1 Answers1

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.