# Interlinear glosses with overlaps, line numbers, and speaker labels

I am trying to come up with a way to represent linguistic examples of naturally occurring dialog. I have not used LaTeX for linguistic glossing yet so I could need some help what package(s) would be most appropriate to start with.

I have looked at linguex, expex, and gb4e, and expex seems to be the most appropriate for my needs. However, there are a few things that I couldn't figure out even with expex. I'm providing a picture of how it should look in the end.

In my subfield (linguistic anthropology) we use Conversation Analysis conventions to represent naturally occurring dialogue but for non-English languages we also use interlinear glosses. Since I am looking at code-switching I have an extra line where each morpheme is identified by it's language, hence I need more than just two lines for the gloss (which is why my first choice would be expex).

Now, the main questions are: How can I achieve with expex (or some other package or combination of packages) to get (a) line numbers (12, 13, in the picture), (b) labels for each speaker, and then ideally (c) also a way to indent a line in order to represent overlapping speech?

If I could have someone help me achieve (a) and (b) I'd already be happy for a start, as I realize that (c) seems to be fairly complex. I know with just one line I can do it with the Tabbing package but with all the complexity of the interlinear glosses also aligned I have no idea how to start.

I know there is also conan a package specifically designed for Conversation Analysis but I couldn't get it to work for what I'm doing, and I couldn't find any documentation how to modify it (see my comment below).

EDIT: I came across this question, which is essentially the same problem that I have. That person had resolved it by manually inserting hspace for all indented lines, which could work for a few short examples, but (a) it's not precise and (b) it is quite cumbersome when formatting many pages of dialogue.

Anyone with some expertise on expex? ;) Or maybe someone knows a way to modify conan for my needs? Any other suggestions?

EDIT2: To give an illustration of what I'd like to achieve, here's how far I got (I know this doesn't work, probably because I can't use tabbing and expex together, but it illustrates how I would want it to work, aligning the second utterance with the second half of the word "sentence")

\documentclass{article}
\usepackage{expex}

\begin{document}
\begin{tabbing}

\ex[exno=Speaker A, exnoformat=X]
\begingl
\glpreamble An example test sen\=tence//
\gla An example test sentence//
\glb gl gl gl gl gl//
\glc A B C D E//
\glft Free translation//
\endgl
\xe

\ex[exno=Speaker B, exnoformat=X]
\begingl
\glpreamble \>A second example test sentence//
\gla A second example test sentence//
\glb gl gl gl gl gl//
\glc A B C D E//
\glft Free translation//
\endgl
\xe

\end{tabbing}
\end{document}


I'm not married to expex, it's just the one that I could figure out on my own with the manual how to at least get the basic structure.
Any help very much appreciated!

EDIT3: Per the suggestion below, this might be a way to achieve this with the conan package, but now I'm stuck with where to insert the \glll command?

\documentclass{article}
\usepackage[linenumbers,spacing=1,tt,singlebracket]{conan}
\usepackage{gb4e}
\usepackage{cgloss}
\begin{document}
\begin{exe}
\exi{A}{
\begin{conan*}
\simul{A}{A test sen[tence] with overlap.}
{B}{[Overlap]}
\end{conan*}}
\end{exe}
\end{document}

• If the conan style otherwise meets your needs, you should be able to combine it with just the \glll command from gb4e, or even better with the version in cgloss.sty, which further unwraps the interlinear glossing macros. They only support two lines of glosses, but the macro is quite easy to extend (and I saw recently that someone had done it and posted the code on the web). Google for clgoss.sty -- it's not on CTAN. Mar 16, 2016 at 15:30
• Thanks so much for your hints, Alexis. I've spent a few hours trying to figure out how to use conan but I couldn't get it to work. That is, it seems (I couldn't find good documentation anywhere) that in order to get the overlaps they need to be on the same line called \simul and that won't work for the data I'm trying to process (which is automatically generated by my transcription program, ELAN, and which has each speaker on a new line). I've also tried to use gb4e and expex within a tabbing section but that does not seem to work.
– jan
Mar 17, 2016 at 6:00
• I didn't recommend gb4e, I recommended its glossing macros because they can be used independently of the example environment. If you can't use conan, it's a moot point; choose whatever macros you can bend to your wishes first. Expex is more recent, powerful and flexible, but it's not modular in the same way, and its interface is a bit odd (the author doesn't use LaTeX, so the interface doesn't follow latex norms). I've never used expex, so I can't say more. Mar 17, 2016 at 11:47
• @alexis - "Google for clgoss.sty -- it's not on CTAN." Oops!. That would be cgloss.sty, then? ;) Mar 19, 2016 at 8:57
• Oops, yes indeed cgloss.sty. Ouch. Here's a direct link: cgloss.sty. Thanks @David. Mar 19, 2016 at 10:24

This is a kind of proof of concept using ExPex and the savepos module of the zref package. Thanks to David Carlisle for helping with the zref code in chat.

The basic idea is to set reference points of overlap and then pass those to the textoffset parameter of ExPex. This allows you to align multiple glossed examples with any previous one. The code defines one environment and 3 user macros:

• \begin{discourse} ... \end{discourse} An environment to group examples in a discourse. This is a simple environment that simply resets the line number counter, but could be made more complex if you need to label each discourse and want to list them in a contents list, for example. For this I would use the tocloft package.
• \spkr{} this macro sets the line number and generates a speaker name.
• \overmk{} this generates a label and keeps track of its position. The first example of a set (or in fact, the document, since labels are global) should contain an instance of this as its first element. Subsequent marks can be added anywhere in the gloss.
• \offset{}{} this takes two labels (created by \overmk) and sets an offset beginning at the second mark.

A fourth macro\deflargestlabel is used in the preamble. It takes one obligatory argument for the longest anticipated speaker name, and one optional argument for the largest anticipated line number (default is 99).

• \deflargestlabel[<longest line number>]{<longest speaker name>}

Here's a full example. Note that the zref package is writing labels to the .aux file, so you will need more than one compilation to make sure the references (and therefore the spacings) are correct.

\documentclass{article}
\usepackage[user,savepos]{zref}

\newcommand{\offset}[2]{%
\dimexpr\zposx{#2}sp-\zposx{#1}sp+1em\relax}
\newcommand{\overmk}[1]{\leavevmode\zsaveposx{#1}}
\usepackage{expex}
\newcounter{linenum}
\newlength{\largestspkr}
\newlength{\largestnum}
% Use this to define the size of the largest speaker number+name
% The main argument is the longest speaker name; optional argument
% is the largest line number. (default is 99)
\newcommand{\deflargestlabel}[2][99]{
\settowidth{\largestnum}{#1.}
\settowidth{\largestspkr}{~#2}}
% Now we define the largest label to be Elder 1 with a line number of 999
\deflargestlabel[999]{Elder 1}

\newcommand{\spkr}[1]{\refstepcounter{linenum}\makebox[\largestnum][r]{\thelinenum.}~\makebox[\largestspkr][l]{#1}}

%create an environment for each discourse so that the numbers will reset
%this could be made more complicated depending on whether you want to label
%them and include them in a list of discourses, etc., in which case
%using \newlistof from the tocloft package would be preferable.
\newenvironment{discourse}{\setcounter{linenum}{0}}{}

\begin{document}
\begin{discourse}
\setcounter{linenum}{97}
\ex[exno=\spkr{Elder 1}, exnoformat=X]
\begingl
\glpreamble\overmk{A1}An example test sentence//
\gla An exam\overmk{A2}ple test sentence//
\glb gl gl gl gl gl//
\glc A B C D E//
\glft Free translation//
\endgl
\xe

\ex[exno=\spkr{Host}, exnoformat=X,textoffset={\offset{A1}{A2}}]
\begingl
\glpreamble A second example test sentence//
\gla A se\overmk{B3}cond example te\overmk{B2}st sentence//
\glb gl gl gl gl gl//
\glc A B C D E//
\glft Free translation//
\endgl
\xe

\ex[exno=\spkr{Elder 1}, exnoformat=X,textoffset={\offset{A1}{B2}}]
\begingl
\glpreamble A second example test sentence//
\gla A second example test sentence//
\glb gl gl gl gl gl//
\glc A B C D E//
\glft Free translation//
\endgl
\xe
\end{discourse}
\begin{discourse}
\ex[exno=\spkr{Elder 2}, exnoformat=X,textoffset={\offset{A1}{B3}}]
\begingl
\glpreamble A second example test sentence//
\gla A second example test sentence//
\glb gl gl gl gl gl//
\glc A B C D E//
\glft Free translation//
\endgl
\xe
\end{discourse}

\end{document}


• @jan I've added an adjustment of 1em which is the default offset set by ExPex. Now things line up exactly. Mar 21, 2016 at 3:37
• @jan I noticed that too, but decided just to solve it by putting it in the \gla line. But I've updated the answer so that it works in the preamble too. Mar 21, 2016 at 17:45
• @jan To reset the number, I would create a {discourse} environment. I've updated the code and also added code to right align the numbers (and a modification of the macro to set the largest width.) Mar 26, 2016 at 18:29
• @jan Sorry about that. They were remnants of the code I used to make the red lines in the image. I've removed them. Mar 27, 2016 at 2:00
• @jan I thought about doing that, but couldn't think of an easy way to do it. I may take a look later if I have some time. Apr 27, 2016 at 15:16