3

The package xspace allows for the definition of abbreviations like \NOM:

\newcommand{\NOM}{\textsc{nom}\xspace}

\xspace makes it possible to use \NOMin 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}

enter image description here

\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}
David Carlisle
  • 757,742
Stefan Müller
  • 6,901
  • 3
  • 29
  • 61
  • 2
    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. – Alan Munn May 28 '20 at 14:13
  • 1
    I added the xspace tag and I'll add a link to by far the highest voted answer in that tag https://tex.stackexchange.com/a/86620/1090 If xspace is convenient in simple cases, perhaps use it but if it is complicated to add then not using it is probably the best idea – David Carlisle May 28 '20 at 14:19
  • 1
    as @AlanMunn says this isn't really feasible, xspace doesn't work by expansion, so no amount of \expandafter will get it to add a space character before you need one for \getwords – David Carlisle May 28 '20 at 14:22
  • Thanks! Too bad ... – Stefan Müller May 28 '20 at 15:05

1 Answers1

1

A regular expression can convert .nom to .NOM:

Using regex

It means wrapping the gll/glt/etc in a command so the regex can get at it, though.

MWE

\documentclass{article}
\usepackage{langsci-gb4e}
\usepackage{xparse}
\usepackage{xcolor}
\usepackage{fontspec}
\setmainfont{Noto Serif}
\setsansfont{Noto Sans}
\setmonofont{Noto Sans Mono}
%--------------------
\ExplSyntaxOn

\NewDocumentCommand { \glsm } { +m } {

    \tl_set:Nn \l_tmpa_tl { #1 }

% .text > .{{\posformat text}} \regex_replace_all:nnN { (.)(\w+) } { \1 \cB{\cB{ \c{posformat} \2 \cE}\cE} } \l_tmpa_tl

    \tl_use:N \l_tmpa_tl

}

\NewDocumentCommand { \glsmm } { +m } {

    \tl_set:Nn \l_tmpa_tl { #1 }

% x.text > x.{{\posformat text}} \regex_replace_all:nnN { (.)(\w+) } { \1 \cB{\cB{ \c{posformat} \2 \cE}\cE} } \l_tmpa_tl

% [space].text > [space]text \regex_replace_all:nnN { (\s.)(.) } { \ \2 } \l_tmpa_tl

    \tl_use:N \l_tmpa_tl

}

%-------------------- \NewDocumentCommand { \posformat } { } { \scshape } %-------------------- \NewDocumentCommand { \setposformat } { m } { \renewcommand{\posformat}{#1} }

\ExplSyntaxOff

\begin{document} Original: \ea \gll der Mann\ the.nom man\ \z

\bigskip Small caps: \ea \glsm{% \gll der Mann\ the.nom man\ } \z

\bigskip SC, blue, bold, sans \setposformat{\scshape\bfseries\color{blue}\sffamily} \ea \glsm{% \gll der Mann\ the.nom man\ } \z \bigskip \ea \glsm{% \gll kma t'-əlčqu-(ɣ)in\ .1sg .1sg.sub-see-.2sg.obj\ \glt `I saw you.' (S1:71) } \z

\bigskip No initial dot \ea \glsmm{% \gll kma t'-əlčqu-(ɣ)in\ .1sg .1sg.sub-see-.2sg.obj\ \glt `I saw you.' (S1:71) } \z

\end{document}

Cicada
  • 10,129