I'm using a custom macros as suggested by Christian Hupfer here to create characters for typesetting a drama script:
\makeatletter
\NewDocumentCommand{\NewPerson}{m}{%
\expandafter\NewDocumentCommand\csname #1x\endcsname{+m}{%
#1: \textbf{##1}\par%
}
\expandafter\NewDocumentCommand\csname #1h\endcsname{}{%
\textsc{#1}%
}
}
\makeatother
When called like this:
\NewPerson{thomas}
everything works fine, the macros \thomash and \thomasx are available in the entire document. But when called from within a group, like this:
{
\NewPerson{thomas}
}
both macros are only accessible from within the group. How can I define those macros in such a manner that they may be used outside the group? I've read about prepending \global to the command definitions inside \NewPerson, but that didn't fix the issue. A MWE could be:
\documentclass{minimal}
\usepackage{xparse}
\makeatletter
\NewDocumentCommand{\NewPerson}{m}{%
\expandafter\NewDocumentCommand\csname #1x\endcsname{+m}{%
#1: \textbf{##1}\par%
}
\expandafter\NewDocumentCommand\csname #1h\endcsname{}{%
\textsc{#1}%
}
}
\makeatother
\begin{document}
\NewPerson{thomas}
\thomasx{asdf}
\thomash
{
\NewPerson{elvis}
\elvisx{asdf}
\elvish
}
\elvisx{asdf}
\elvish
\end{document}
Here, using \elvisx and \elvish outside the group doesn't work. Any ideas on how to fix that are very appreciated!



\makeatletter...\makeatotherhere... – Mar 10 '17 at 19:46xparse: The xparse package provides a high-level interface for producing document-level commands -- So just use\gdefor somthing similar inside your definition. – Marco Daniel Mar 10 '17 at 19:47\makeatcommands. But there is no reason to needxparseor\NewDocumentCommandfor what you are trying to do. – Mar 10 '17 at 19:50\NewPersonmacro was never intended to be used in a group. – Mar 10 '17 at 19:55\NewDocumentCommandis intended for commands with document scope (there is a clue in the name) – David Carlisle Mar 10 '17 at 20:05