3

I use linguex together with own defined commands to get grammatical categories typeset in small-caps. For instance, I have \newcommand{\sg}{\textsc{sg}} to typeset the SG (=singular) gloss. This is also convenient if I want to change my glossing scheme. This creates however a slight inconvenience, since commands "gobble" the space after them. So in order to get the glosses correct I have to put {} after each such command, as shown in the following MWE:

\documentclass{article}
\usepackage{linguex}

\newcommand{\sg}{\textsc{sg}}

\begin{document}

I would like this to work, but it doesn't:

\exg. I am here! \\
1\sg be.1\sg here \\


Instead, I have to use this syntax:

\exg. I am here! \\
1\sg{} be.1\sg{} here \\


\end{document}

Using \xspace in the command definition doesn't help. Is there some other solution which can help me avoid using {} all the time?

5
  • Please give us a full MWE in order to start with your problem. Thanks.
    – LaRiFaRi
    Mar 2, 2015 at 14:16
  • 1
    This doesn't help with the {} issue, but you might be interested to know that there is a package leipzig that provides a lot of macros for gloss abbreviations, plus has functionality to work with glossaries and produce a list of the gloss abbreviations used throughout the document and their full forms. Mar 2, 2015 at 17:39
  • The problem is that \exg uses spaces for splitting the input into parts so as to be able to align them. But after \sg there is no space, because it is ignored at tokenization time and so it's not seen during the action of the macro expansion processor. David's trick requires special formatting, adding {} doesn't. Would you be satisfied if instead of \sg{} you had to type \sg*? Otherwise, I can offer a syntax where the different items are separated, say, by //
    – egreg
    Mar 2, 2015 at 18:22
  • @egreg, using * would not be good, since I already use the starred versions to get some other result (a full text). The basic problem is that sometimes I forget the {} and then I get misaligned examples. So changing the separator will probably not solve my problem.
    – Ariel
    Mar 3, 2015 at 17:09
  • @egreg, thinking more about it, a reasonable alternative would be if I could use a dot . after the command, which shouldn't be printed if it is followed by space, but otherwise it should appear. So `\sg.\masc.' could give SG.MASC
    – Ariel
    Mar 3, 2015 at 17:22

2 Answers 2

3

Not sure I'd recommend it but you could locally make a space not a normal space, so that it is not dropped after \foo then replace all the special spaces by normal spaces so the \exg macro sees them.

\documentclass{article}
\usepackage{linguex}

\newcommand{\sg}{\textsc{sg}}

\def\zztmp{\$}
{\obeyspaces\catcode`\~10\relax\makeatletter
\gdef\zz{\begingroup\obeyspaces\zzz}%
\gdef\zzz#1{\endgroup\zzzz{}#1 \$ }%
\gdef\zzzz#1#2 {%
\def\tmp{#2}\ifx\tmp\zztmp
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{#1}{\zzzz{#1#2~}}}}

\begin{document}

I would like this to work, but it doesn't:

\zz{
\exg. I am here! \\
1\sg be.1\sg here \\
}


Instead, I have to use this syntax:

\exg. I am here! \\
1\sg{} be.1\sg{} here \\


\end{document}
3
  • I've no clue how your code works, but it does seem to do the trick!
    – Ariel
    Mar 2, 2015 at 15:08
  • Trying this in my real document, however, it does not seem to work. In the real document I embed the \exg. within other commands, and so I tried to embed the \zz together with it, but for some reason it doesn't produce the same result. I load many different packages, so maybe one of them affects this...
    – Ariel
    Mar 3, 2015 at 17:20
  • 2
    @Ariel any command based on catcode changes is like \verb and can't be used in the argument of another command. You can almost certainly lift the space handling up to your top level document command, but to be honest I wouldn't it is a massively intrusive change for essentially at best cosmetic results, see tex.stackexchange.com/questions/86565/drawbacks-of-xspace/… for similar concerns. Just accept the answer as best that's possible but use {} in the document:-) Mar 3, 2015 at 17:36
3

The problem is that \exg uses spaces for splitting the input into parts so as to be able to align them. But after \sg there is no space, because it is ignored at tokenization time and so it's not seen during the action of the macro expansion processor. So a solution might be to follow these special commands with a period.

As requested, the period prints only if the next token is not a space. The disadvantage is that the period is mandatory after the abbreviations.

\documentclass{article}
\usepackage{linguex}

\makeatletter
\newcommand{\newabbreviation}[2]{%
  \@ifdefinable{#1}{\@newabbreviation{#1}{#2}}%
}
\newcommand\@newabbreviation[2]{%
  \def#1.{#2\@checkspace}%
}
\newcommand\@checkspace{%
  \futurelet\@let@token\@check@space
}
\newcommand\@check@space{%
  \ifx\@let@token\@sptoken\else.\fi
}
\makeatother

\newabbreviation{\sg}{\textsc{sg}}
\newabbreviation{\masc}{\textsc{masc}}

\begin{document}

This seems to work:

\exg. I am here! \\
1\sg. be.1\sg.\masc. here \\

\end{document}

I apologize for the linguistic blasphemy in the example. ;-)

enter image description here

2
  • Thanks, I see this is really a complicated problem which has to do with the very inner workings of TeX.... Is it not possible to make the . optional? Otherwise, I would have to rewrite all my previous examples.
    – Ariel
    Mar 5, 2015 at 16:01
  • @Ariel No, sorry; in my opinion it's an error of linguex using the space as the chunk delimiter to begin with. As ignoring spaces after control sequences is a rule of TeX, there's little you can do except trying the “envelope” method suggested by David.
    – egreg
    Mar 5, 2015 at 17:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .