The package xspace
allows for the definition of abbreviations like \NOM
:
\newcommand{\NOM}{\textsc{nom}\xspace}
\xspace
makes it possible to use \NOM
in the text without a {}
following the \NOM
. Otherwise the \NOM
would eat the white space following the command.
I would like to have this behavior in glosses set with the langsci-gb4e
package and wonder if this is possible. Somehow the \xspace
seems to cause strange effects here. It seems to be interpreted as one word with the following word.
\documentclass{article}
\usepackage{langsci-gb4e,xspace}
\newcommand{\NOM}{\textsc{nom}\xspace}
\begin{document}
\ea
\gll der Mann\\
the.\NOM man\\
\z
\ea
\gll der Mann\\
the.\NOM{} man\\
\z
\end{document}
\gll
the glossing command calls \twosent
, which does some magic that I do not understand ... The code is originally coming from cgloss4e
.
\gdef\twosent#1\\ #2\\{% #1 = first line, #2 = second line
\getwords(\lineone,\eachwordone)#1 \\%
\getwords(\linetwo,\eachwordtwo)#2 \\%
\loop\lastword{\eachwordone}{\lineone}{\wordone}%
\lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
\global\setbox\gline=\hbox{\unhbox\gline
\hskip\glossglue
\vtop{\box\wordone % vtop was vbox
\nointerlineskip
\box\wordtwo
}%
}%
\testdone
\ifnotdone
\repeat
\egroup % matches \bgroup in \gloss
\gl@stop}
xspace
inserts a space into the output, using\space
which is simply another macro and gobbles the following space. But the glossing macros depend on spaces in the input and so you must always either put braces around gloss words that contain macros or add{}
. There's no way around this.\expandafter
will get it to add a space character before you need one for\getwords