[Tex/LaTex] Interlinear glosses with overlaps, line numbers, and speaker labels

expexgb4elinguexlinguisticstabbing

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.

enter image description here

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}

Best Answer

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}

output of code with lines

Related Question