3

When using the expex package, is there an elegant way to apply the same formatting to both a morpheme and its gloss? Say, for example, that I'd like to bold each prefix in my data and its gloss, like so:

desired formatting

This can, of course, be done by bolding the prefix and its gloss separately, as in this MWE:

\documentclass{article}
\usepackage{expex}
\begin{document}

\ex \begingl[glstyle=nlevel]
\glpreamble Niwaapamaa kimaamaa.\endpreamble
\textbf{ni-}[\textbf{1-}] % prefix and gloss bolded separately
waapam[see]
-aa[-\textsc{dir}]
\nogloss{\quad}
\textbf{ki-}[\textbf{2-}] % prefix and gloss bolded separately
maamaa[mother]
\glft `I see your mother.'
\xe

\end{document}

But the repetition of duplicate formatting commands like \textbf{ni-}[\textbf{1-}] is inelegant. Fine for a one-off, but inefficient in a document with hundreds of glosses. Is there any way to take something like ni-[1-] and apply the same formatting to both elements in one shot? My naive attempt was the following, which would allow the first prefix in the example above to be entered as \glprefix{ni-}{1-}:

\newcommand{\glprefix}[2]{\textbf{#1}[\textbf{#2}]}

But it can't be that simple, because burying the two elements inside a single command prevents expex from glossing them properly. I'm wondering if there's some kind of trickery to get around this.

2
  • 2
    Welcome to TeX.se and thanks for including a minimal working document!
    – Alan Munn
    Commented Jul 27, 2019 at 18:31
  • Thanks for the welcome and the fantastic answer! Commented Jul 27, 2019 at 19:43

1 Answer 1

3

Here's a solution that works for the ngloss style input only. The idea is set a conditional inside the first gloss element and then have it persist in the second. The command to highlight is \HL and it must be inside the first element of the gloss pair, and the whole thing in {...}. Rather than hardcoding the formatting itself, I've made an \hlight macro which is defined to be \bfseries. This allows changing the formatting as needed.

The reason that your naive approach didn't work is that the macro that unpacks the pairs of elements in the ngloss style is a delimited macro, so you can't wrap it inside other macros in a simple way.

\documentclass{article}

\usepackage{expex}
\newif\ifhilight
\newcommand*{\hilight}{\bfseries}
\makeatletter
\newcommand*\HL{\hilight\global\hilighttrue}
\newcommand*\@hilight{\global\hilightfalse\hilight}
\def\gln@word #1[#2]#3 {%
   \def\@currentitem{\\{\ifhilight\hilight#1\else#1\fi}}%
   \def\@diacritic{#3}%
   \gln@ilg@f \ifhilight\@hilight#2\else#2\fi/\@nil
   \gln@ilg@a
}
\makeatother
\begin{document}

\ex \begingl[glstyle=nlevel]
\glpreamble Niwaapamaa kimaamaa.\endpreamble
{\HL ni-}[1-] % prefix and gloss bolded separately
waapam[see]
-aa[-\textsc{dir}]
\nogloss{\quad}
{\HL ki-}[2-] % prefix and gloss bolded separately
maamaa[mother]
\glft `I see your mother.'
\xe

\end{document}

output of code

You must log in to answer this question.

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