this is my first post to tex stack exchange so I apologise if the post is missing required information.

I'm using gb4e to produce linguistic examples for my dissertation, and I'm trying to find the most convenient way to include speaker labels as a part of example numbering. Some of the questions I've seen (eg. Interlinear glosses with overlaps, line numbers, and speaker labels) suggest that it might be easier to do this using a different package, but as I've already written a few hundred examples in gb4e it would save me time to stick with gb4e, given that only a minority that require speaker labels.

These are the basic considerations:

  • there are a maximum of three speakers to be distinguished for each example
  • speaker labels are simply A/B/C (or similar) identifiers, as I don't need to refer to full names of speakers
  • all sub-examples require full interlinear glosses

The current method is to put each utterance in an \xlist, and for each sub-example include the speaker label on the same line as the example number, removing some whitespace before the \gll:

\newcommand{\speakerlabel}[1]{Speaker #1\vspace*{-.5\baselineskip}}
    \ex \begin{xlist} 
        \ex \label{ex:my example} \speakerlabel{A}
        \gll my example\\
        my example\\
        \trans `My example'

\ref{ex:my example}

This is a reasonably tidy solution, but it wastes space for single character speaker identifiers, and speaker identifiers aren't preserved in example numbering for cross referencing (note text reference Example 171a, not 171a-A). It would be a useful to me if the identity of the speaker was clear from the example number, so as to avoid prose such as `Speaker A responds with 171a'.

enter image description here

Ideally what I'd like is something like a custom \xlist environment that adds the speaker identifier to the example number (171a-A, 171b-A, 171c-B). \exi{speaker label} does not work for this because (from what I've read so far) custom identifiers are not intended for use in cross-referencing due to the problems with including arbitrary characters in counters. But as mentioned, there are at most 3 unique speakers at a time, so perhaps a finite set of speaker characters might not be considered arbitrary.

I'm to suggestions for other ways to refer to speakers, and I really appreciate all responses. Thanks in advance!

The code below gives an idea of how I would like this to work. Is it possible to define myxlist and \exa, \exb, etc, so that this code snipped produces a formatted example that retains speaker identifiers in cross-references similar to the screenshot below?

(note that I would also change speaker identifiers to something other than A/B/C so as not to confuse with sub-example numbering, but this is sufficient for explanation)

\ex \label{ex:some dialogue} \begin{myxlist}
    \exa \gll first utterance\\
    first utterance\\
    \trans `First utterance'
    \exb \label{ex:B's reply} \gll second utterance\\
    second utterance\\
    \trans `Second utterance' 
    \exb \gll third utterance\\
    third utterance\\
    \trans `Third utterance'
\end{myxlist} \end{exe} 

Reference to \ref{ex:B's reply}.

enter image description here

  • Welcome to TeX.se. Is your problem just about cross referencing, or do you want the Speaker A, Speaker B labels etc. to be automatically generated?
    – Alan Munn
    Commented Feb 7, 2022 at 23:26
  • Thanks for your response. I think my writing 'Speaker A' in the \trans line may have confused things. I've edited the original post to include a text editor mock up of what I'm trying to achieve. Main ideas are (1) I don't need a separate line for the speaker label and can just include it in the sub-example number (2) I'd like that speaker label to be permanently attached to the example number for cross references. Do you know if this is possible? Thanks very much! Commented Feb 8, 2022 at 0:22

1 Answer 1


I'm not sure this is the best system to use since the speaker label is independent of the example reference and doesn't vary within it, but here's a simple system that will achieve what you want.

It redefines the existing \xlistA list in gb4e to be a regular alpha list with a speaker suffix. The speaker suffix is set using a \spkr macro. You should use fixed length speaker labels since the labels themselves are right aligned in the list, so having variable width speaker labels will create an odd looking list because the example letters won't line up at the left.

The list defaults to A as the first speaker; there's no need to use \spkr for each example if the speaker label doesn't change for subsequent examples.

% This redefines the xlistA list to use a speaker suffix
% The width of the label is determined by the [m-M.] part
% Since the label is right aligned, you need to make sure
% that the speaker labels are of uniform length.
\@ifnextchar [{\@xlist{\alph}}{\@xlist{\alph}[m-M.]}}

\ex\gll This is a glossed example\\
           These are the gloss words\\
       \glt `This is a translation' \label{LabelA}

\spkr{B}\ex \gll This is a glossed example\\
           These are the gloss words\\
       \glt `This is a translation' \label{LabelB}
\spkr{A}\ex\gll This is a glossed example\\
           These are the gloss words\\
       \glt `This is a translation'   

As we can see in (\ref{LabelA}) and (\ref{LabelB}) we get proper cross-referencing.

\ex\gll This is a glossed example\\
           These are the gloss words\\
       \glt `This is a translation' \label{LabelC}

\ex \gll This is a glossed example\\
           These are the gloss words\\
       \glt `This is a translation' \label{LabelD}
\ex\gll This is a glossed example\\
           These are the gloss words\\
       \glt `This is a translation'   

Regular lists are unaffected as in (\ref{LabelC}) and (\ref{LabelD}). 


output of code

  • This is brilliant, thanks very much! I see what you mean about the speaker label being invariant within the example reference. I will continue to think about this. Either way, your method for redefining xlistA will be very helpful. Thanks again! Also sorry for the delay in my reply, I had too many tabs open! Commented Feb 15, 2022 at 6:49

You must log in to answer this question.

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