There are good packages for numbering examples in linguistics which have been specifically designed by linguists to meet our needs. Two of the most commonly used ones are gb4e
and linguex
. The questions egreg linked to in the comments show some examples. A third package, ExPex is still in development, and is extremely powerful, although somewhat non-LaTeX like in its syntax. Here are examples of all three packages which show off some of their abilities. In the first example, three levels of example embedding are shown. In the second example, the automatic lining up of glosses for use with examples not in the language of the article you are writing. I've coded the same examples in all three packages to highlight differences in their syntax.
Overall evaluation
All three packages can very quickly produce standard examples and glosses quite quickly. For most users, and especially new users, either one of gb4e
or linguex
is a good choice. Personally I prefer gb4e
because it implements true semantic markup of examples using LaTeX environments. Many linguex
users prefer it, however, because the source input is simpler (and therefore not semantic at all). Since any good editor can insert chunks of code automatically, this has always struck me as being a weak argument.
I would really only recommend ExPex if you really require the degree of customization that it implements, especially in its handling of complex glossing systems. For some examples of its capabilities, see Type a interlinear text, bi or tri-lingual and Doing an interlinear text.
gb4e
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{gb4e}
\begin{document}
\begin{exe}
\ex Wh/Quantifier Interactions\label{WHQ}
\begin{xlist}
\ex[]{What did everyone bring to the party?}
\begin{xlist}
\ex {Beer. \hfill \emph{Individual answer}}
\ex {Bill brought beer, Sue brought wine, Sam brought vodka \hfill \emph{Pair List answer}}
\ex {His favourite drink. \hfill \emph{Functional answer}}
\end{xlist}
\ex[]{Who brought every dish to the party?}
\begin{xlist}
\ex[]{Sue \hfill \emph{Individual answer}}
\ex[*]{Bill brought the salsa, Sue brought the hummus, \\ Sam brought the tabouli \hfill \emph{Pair list answer}}
\ex[*]{Its maker \hfill \emph{Functional answer}}
\end{xlist}
\end{xlist}
\end{exe}
As we can see in (\ref{WHQ}) there is a subject/object asymmetry in the availability of the Pair list and functional answers.
In example (\ref{citko21}) we can see some data from Polish.
\begin{exe}
\ex\label{citko21}
\begin{xlist}
\ex[]{\gll Kogo Jan lubi e a Maria podziwia e?\\
who.ACC Jan likes e.ACC and Maria admires e.ACC\\
\trans `Who does Jan like and Maria admire?'}
\ex[*]{\gll Kogo/Komu Jan lubi e a Maria ufa e?\\
who.ACC/DAT Jan likes e.ACC and Maria trusts e.DAT\\
\trans `Who does Jan like and Maria trust?'}
\end{xlist}
\end{exe}
\end{document}

Advantages and disadvantages
Advantages
- Real semantic markup for examples
- Good support for grammaticality judgements
- Automatic lining up of glosses (same as
linguex
)
- Uses the standard
\label
and \ref
reference system
- counters are easy to manipulate
- allows for use of
_
and ^
outside of mathmode
Disadvantages
- Hard to customize the basic list margins
- allows for use of
_
and ^
outside of mathmode
linguex
The other commonly used package for linguistic examples is linguex
. Here's the same example coded using that package.
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{linguex}
\begin{document}
\ex. Wh/Quantifier Interactions\label{WHQ}
\a. What did everyone bring to the party?
\a. Beer. \hfill \emph{Individual answer}
\b. Bill brought beer, Sue brought wine, Sam brought vodka \hfill \emph{Pair List answer}
\b. His favourite drink. \hfill \emph{Functional answer}
\z.
\b. Who brought every dish to the party?
\a. Sue \hfill \emph{Individual answer}
\b. *Bill brought the salsa, Sue brought the hummus, \\ Sam brought the tabouli \hfill \emph{Pair list answer}
\b. *Its maker \hfill \emph{Functional answer}
As we can see in \ref{WHQ} there is a subject/object asymmetry in the availability of the Pair list and functional answers.
In example \ref{citko21} we can see some data from Polish.
\ex.\label{citko21}
\ag. Kogo Jan lubi e a Maria podziwia e?\\
who.ACC Jan likes e.ACC and Maria admires e.ACC\\
\trans `Who does Jan like and Maria admire?'
\bg. *Kogo/Komu Jan lubi e a Maria ufa e?\\
who.ACC/DAT Jan likes e.ACC and Maria trusts e.DAT\\
\trans `Who does Jan like and Maria trust?'
\end{document}
Advantages and disadvantages
Advantages
- Automatic lining up of glosses (same code as
gb4e
)
- Uses the standard
\label
and \ref
reference system
- shorthands for next and previous examples without using labels
- simple input syntax with contextual determination of levels (at the expense of semantics)
- easy to customize the basic list margins
Disadvantages
- markup is not semantic; contextual determination of levels
- some counters are hard coded and hard to modify
- handling of grammaticality judgements needs extra code to extend
- command for glossed examples is different from non-glossed examples
- example groups must be separated by a blank line
- cannot be used in conjunction with packages like
xcomment
which allow environments to be selectively excluded/included

ExPex
The ExPex package is an extremely powerful package for formatting examples and glosses. It is useable by both Plain TeX and LaTeX. It is highly customizable and supports multiple levels of glossing. It uses a syntax that is more TeX-like than LaTeX like, (for example the basic example environment uses \ex ... \xe
rather than \begin{ex} ... \end{ex}
and implements customizations using a syntax based on the PSTricks key-value system.
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{expex}
% ExPex doesn't implement 3 levels of embedding, so this code is
% required for the first example
\def\beginsubsub{%
\par
\begingroup
\advance\leftskip by 2em
\def\b##1{\par\leavevmode\llap{\hbox to 2em{##1\hfil}}\ignorespaces}}
\def\endsubsub{\par\endgroup}
\gathertags % write tags to external tag file
\Lingset{everygla=\upshape} % make first gloss line upright
\begin{document}
\pex~ Wh/Quantifier Interactions\deftagex{WHQ}
\a {What did everyone bring to the party?}
\beginsubsub
\b{i.} {Beer. \hfill \emph{Individual answer}}
\b{ii.} {Bill brought beer, Sue brought wine, Sam brought vodka \hfill \emph{Pair List answer}}
\b{iii.} {His favourite drink. \hfill \emph{Functional answer}}
\endsubsub
\a {Who brought every dish to the party?}
\beginsubsub
\b{i.} Sue \hfill \emph{Individual answer}
\b{ii.} {\ljudge{*}Bill brought the salsa, Sue brought the hummus, \\ Sam brought the tabouli \hfill \emph{Pair list answer}}
\b{iii.} \ljudge{*}Its maker \hfill \emph{Functional answer}
\endsubsub
\xe
As we can see in (\getref{WHQ}) there is a subject/object asymmetry in the availability of the Pair list and functional answers.
In example (\getref{citko21}) we can see some data from Polish.
\pex<citko21> % an alternative syntax for tagging
\a
\begingl
\gla Kogo Jan lubi e a Maria podziwia e?//
\glb who.ACC Jan likes e.ACC and Maria admires e.ACC//
\glft `Who does Jan like and Maria admire?'//
\endgl
\a
\begingl
\gla Kogo/Komu Jan lubi e a Maria ufa e?//
\glb who.ACC/DAT Jan likes e.ACC and Maria trusts e.DAT//
\glft `Who does Jan like and Maria trust?'//
\endgl
\xe
\end{document}

Advantages and Disadvantages
Advantages
- extremely customizable using a key/value interface
- support for multiple levels of glossing with very rich formatting
- usable with both Plain TeX and LaTeX
- powerful reference and labeling system but using methods distinct from the standard LaTeX
\label
and \ref
system
- independent macros for grammaticality judgements
Disadvantages
- very idiosyncratic syntax for LaTeX users (although not for Plain TeX users)
- fairly steep learning curve (71 pages of documentation)
- only two levels of automatic embedding