Useful LaTeX packages: linguistic examples

This is the conclusion of a short series of entries on LaTeX packages I found useful while preparing the examination copy of my PhD thesis.

Today’s entry is a package for displaying linguistic examples (ie, samples of text which you then want to discuss and analyse).  The LaTeX for Linguists Home Page is a good general resource for linguists and computational linguists using LaTeX. I discuss gb4e here because I had to do some messing around to get it to display example numbers the way I want (and the way my supervisor wanted: he likes in-text references to look like “example (4.1)” rather than “example 4.1″), and to get it to work with cleveref, and no one seems to have written that up to my knowledge.


gb4e is a linguistic examples package.


Input looks like:

\ex This is an example sentence\label{example}
\ex This is another example sentence.
This is a cleveref reference to \cref{example}.
This is a normal reference to example (\ref{example}).

You can mark sentences with * and ? and so on:

\ex[*] {This is an sentence ungrammatical.}
\ex[?] {This is an questionably grammatical sentence.}

You can do sub-examples:

\ex This is an example.
\ex This is a sub-example.
\ex This is another sub-example.

A few things to do to make gb4e play really nicely. First, some cleveref config. gb4e doesn’t yet automatically tell cleveref how to refer to examples, so you need to tell it that the term is “example”, and second, if you want braces around the number (“example (1.1)” rather than “example 1.1″ you need to tell it to use brackets:

% tell cleveref to use the word "example" to refer to examples,
% and to put example numbers in brackets

Also, by default, the gb4e numbering does not reset in chapters. That is, your examples will be numbered (1), (2), (3) etc right through a thesis. You probably want more like (1.1), (1.2), (2.1), (2.2), ie chapter.number. Change to this with the following in your preamble:

% Store the old chapter command so that
% our redefinition can still refer to it
% Redefine the chapter command so that it resets the
% 'exx' counter that gb4e uses on every new chapter.
% Redefine how example numbers are shown so that they are
% chapter number dot example number
You could also get it to reset in sections by replacing \chapter and \thechapter with \section and \thesection in the above.