# Labeling linguistic examples with language information

I'm writing a linguistics paper that uses a large amount of linguistic examples from a wide variety of languages, using the gb4e package. I want to be able to label each example with information about the language it comes from, as I've seen in some texts, sort of like this:

Language (family, citation, etc.)
(1) example text
glosses
'translation'


gb4e is great at formatting the examples themselves, but I can't seem to get the label placed where I want it, that is, placed immediately before the example and without an indent. Here's some example code:

\documentclass{article}
\usepackage{gb4e}
\usepackage{lipsum}

\begin{document}
\lipsum[2]

Hungarian (Finn-Ugric, \emph{reference})
\begin{exe}
\ex \gll    J\'anos h\'aza\\
John house.his\\
\glt    John's house'
\end{exe}

\lipsum[3]
\end{document}


If the label text is outside the exe environment, it's treated like a regular paragraph, but if I try to put it inside, it gives me an error. How can I make it look the way I want? I've looked at other packages that do numbered examples, but they don't seem to have solutions either, and they also don't have the same functionality as gb4e that I need.

Any help would be greatly appreciated.

-
I have edited your question to include lipsum package for introducing dummy text for better readability and focus, you can also use egreg's kantlipsum package for the same purpose. Please rollback if this is not desired. –  percusse Mar 27 '12 at 3:19
Didn't even know those existed. Thank you! –  Garrett Mar 27 '12 at 14:07

If you use Alexis Dimitriadis' version of cgloss4e available here as cgloss.sty you can put language information right aligned with the first line of the example. This is IMO a very nice way to format such information, and quite common in the field:

\documentclass{article}
\usepackage{gb4e}
\usepackage{cgloss}
\usepackage{lipsum}

\begin{document}
\lipsum[2]

\begin{exe}
\ex \gll    J\'anos h\'aza\\
John house.his\\ \hfill Hungarian (Finno-Ugric, \emph{reference})
\glt    John's house'
\end{exe}

\lipsum[3]
\end{document}


### Solution also works with linguex

Another popular package for formatting linguistic examples is the linguex package. Since linguex also uses cgloss4e, the solution given above will also work. Here's the same example using the linguex commands:

\documentclass{article}
\usepackage{linguex}
\usepackage{cgloss}
\usepackage{lipsum}

\begin{document}
\lipsum[2]

\exg.
J\'anos h\'aza\\
John house.his\\ \hfill Hungarian (Finno-Ugric, \emph{reference})
\glt    John's house'

\lipsum[3]
\end{document}


-
That does look nice. Does cgloss4e otherwise work the same as gb4e? I noticed it's not included in Texlive. –  Garrett Mar 27 '12 at 14:11
cgloss4e is loaded by gb4e; it's the part that handles the glosses and part of the regular gb4e distribution. You don't see it because you usually never load it by itself. cgloss is a replacement for cgloss4e not for gb4e itself. But yes, it works identically as far as I know. I'm not sure why Alexis has never put it up on CTAN. –  Alan Munn Mar 27 '12 at 14:16
So if I load cgloss, does it automatically replace cgloss4e? Also, should it be loaded before or after gb4e? I've discovered that gb4e usually needs to be loaded last or it causes problems. –  Garrett Mar 27 '12 at 14:23
Yes. You should load it after gb4e. And yes, gb4e should be loaded almost last since it messes with the category codes of _ and ^. –  Alan Munn Mar 27 '12 at 14:27

Here's a (rather ugly) solution by wrapping the language label in an un-numbered example via \sn:

\newcommand\langlabel[1]{\sn\hspace*{-\leftmargin}{#1}\\[-1em]}
...
\begin{exe}
\langlabel{Hungarian (Finn-Ugric, \emph{reference})}
\ex \gll    J\'anos h\'aza\\
John house.his\\
\glt    John's house'
\end{exe}


-

You can also just put the language label between the \ex and \gll commands:

\begin{exe}
\ex Hungarian (Finn-Ugric, \emph{reference}) \gll    J\'anos h\'aza\\
John house.his\\
\glt    John's house'
\end{exe}

-

If you're using linguex, you might encounter an error if you use Alan's method from answer #1 above. I had to replace l.361--63 of linguex.sty,...

\def\gl@stop{{\hskip -\glossglue}\unhbox\gline\end{flushleft}%
\global\glossfalse%
\ifindex\expandafter\lookforwords\fi {} }


...with the following:

\def\gl@stop{{\hskip -\glossglue}\unhbox\gline\leavevmode \egroup
\global\glossfalse%
\ifindex\expandafter\lookforwords\fi {} }


The reason was that cgloss redefines \gl@stop, but then linguex re-re-defines it. The changes above avoid that problem by combining both re-definitions.

In addition, replace line 34 in linguex.sty...

\RequirePackage{xspace,cgloss4e}


...by...

\RequirePackage{xspace,cgloss}


...and linguex loads cgloss, so you don't have to call it seperately.

It works fine on my installation.

-
Welcome to TeX.sx! You can add highlighting of code by selecting it and hitting Ctrl + K (or click the button marked {} above the answer field. Blocks are indented by four spaces, inline code placed between backticks (). –  Torbjørn T. Jan 22 at 15:30