Automatic formatting of interlinear glosses with LaTeX

One of the most tedious tasks when writing a linguistic article is the formatting of interlinear glossed examples. In LaTeX, several packages make it easy to align words, but the formatting of abbreviated grammatical labels still needs to be done by hand, wrapping each label within a \textsc{} command. Even with the leipzig package, one still has to add some code within the interlinear glosses. This also makes more difficult importing interlinear data from popular software such as Toolbox. I present below a rather simple solution that alleviates the need to add code around grammatical labels: any string of upper case letters is automatically formatted correctly. The solution also works with leipzig commands.

Interlinear glosses

The Leipzig glossing rules are now a standard set of conventions for linguistic publications. They stipulate that in linguistic examples, the object language text should be followed by a gloss line aligned word-by-word with the original. Grammatical labels should appear in abbreviated form, preferably in small caps.

In LaTeX, such formattting is easily produced with a package such as  gb4e:

\documentclass{article}
\usepackage{gb4e}

\begin{document}
\begin{exe}
\ex
\gll My s Marko poexa-l-i avtobus-om v Peredelkino \\
1\textsc{pl} \textsc{com} Marko go-\textsc{pst}-\textsc{pl} bus-\textsc{ins} \textsc{all} Peredelkino \\
\glt `Marko and I went to Perdelkino by bus.'
\end{exe}
\end{document}

However, it is rather tedious to put a \textsc{} command aroung each grammatical label, especially if you want to copy-paste an example from a Toolbox database formatted with upper case labels:

\mb  My  s   Marko poexa-l-i avtobus-om v   Peredelkino
\ge 1PL COM Marko go-PST-PL bus-INS ALL Peredelkino

A better approach would be to use the leipzig package, which offers several advantages:

  • it automatically prints grammatical labels in small caps;
  • it can print the list of abbreviations used in the text;
  • a typo in a grammatical label produces an error, and typos are thus easily spotted;
  • it predefines all the standard abbreviations listed in the Leipzig glossing rules.

Still, it requires to put some special code into the examples to get the desired output:

\documentclass{article}
\usepackage{gb4e}
\usepackage{leipzig}
\makeglossaries

\begin{document}
\begin{exe}
\ex
\gll My s Marko poexa-l-i avtobus-om v Peredelkino \\
{\Fpl} {\Com} Marko go-\Pst-{\Pl} bus-{\Ins} {\All} Peredelkino \\
\glt `Marko and I went to Perdelkino by bus.'
\end{exe}

\printglosses[style=mcolblock]
\end{document}

Solution

I came up with a solution that only requires to enter grammatical labels in upper case:

\begin{exe}
\ex
\gll My s Marko poexa-l-i avtobus-om v Peredelkino \\
1PL COM Marko go-PST-PL bus-INS ALL Peredelkino \\
\glt `Marko and I went to Perdelkino by bus.'
\end{exe}

Advanced users can look directly at the package code, but basically it works as follows:

  • at the same time words are aligned vertically, each word in the second line is scanned with regular expressions for upper case strings and for the numbers 1, 2 and 3, but single upper case letters at the beginning of a word are ignored;
  • each match is then wrapped in a command that converts the matched string to lower case and, depending on whether leipzig is loaded or not, prints it in small caps or passes it to a leipzig command.

The only limitation is that you should not redefine the command \eachwordtwo to change the font style. Instead, I provide the command \eachwordtwostyle that you can redefine as you wish to add style specifications.

The full code is available as an experimental package igt-format.sty on bitbucket:
https://bitbucket.org/tpellard/igt-format

It still needs to be thoroughly tested, but it works with toy examples under either gb4e or langsci-gb4e, but I have no idea about compatibility with either linguex or expex. If you have problems or suggestions, do not hesitate to file an issue on bitbucket, or just contact me at thomas.pellard@cnrs.fr.

See also this post.

Ce billet peut être cité de la façon suivante: Thomas Pellard, « Automatic formatting of interlinear glosses with LaTeX », Cipanglossia, 13 juin 2019, https://cipanglo.hypotheses.org/1221.

Vous aimerez aussi...

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.