Wednesday, December 15, 2010

LateX, glossaries, first use and figures

If you use LateX like I do, then you might have tried the glossaries package. It's a bit of a bitch to set up, but once it is it's no more trouble than a bibliography and it'll save you a lot of time with standardising your acronyms. But I just spent the last 2 days pulling out my hair because it was behaving rather peculiarly.

The normal behaviour is thus:

You refer to an item in your glossary list
\newglossaryentry{LOL}{name={LOL},description={Laugh out loud.},first={Laugh Out Loud (LOL)}, firstplural= {Laugh Out Loud (LOLs)},text{LOL}}
and then reference it in text:
When I saw my mistake I did many \glspl{LOL}. People heard my \gls{LOL}.
which would turn out to be:
"When I saw my mistake I did many Laugh Out Loud (LOLs). People heard my LOL."
You run makeglossaries and voila you have a glossary and all of your terms are defined in text and expanded for their first use.

But instead I would get:
"When I saw my mistake I did many LOLs. People heard my LOL."

So, my first reference was never correct and was simply the acronym. First use never worked for any of the acronyms in any part of the document, but everything else was fine. Massive fail for glossaries, that's kind of what it needs to do. I made a minimal example and that worked fine, I tried copying in all of my document after this example and it worked find. But when I replaced my minimal example with my text and compiled, it never worked properly. I tried \glsresetall and resetting specific acronyms, nothing worked.

So what was it? My first acronym was in a figure caption - shift the figure to after another term was defined in-text and voila, problem solved.