Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a document consisting of multiple tex files, one per chapter, I am using the glossaries package to create list of acronyms. Ideally I want to define acronyms as close to where they are used, i.e. in the chapter tex files, in order to make the chapters self contained. However, this leads to some double definitions (acronyms defined in multiple chapters), something which the glossaries package does not like (it throws a "Glossary entry `xx' has already been defined" error).

Therefore I was wondering if it would be possible to change the \newacronym command in a way that it would ignore attempts at defining acronyms that are already known.

Basically it would boil down to an if-then-else structure which first checks whether the acronym label is already known, if so does nothing and if not executes the original \newacronym code.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You could use glossaries' \ifglsentryexists macro to define a \provideacronym macro which will only define an acronym if not already defined. Additionally (as in my MWE) you could redefine \newacronym as \provideacronym.

\documentclass{article}

\usepackage{glossaries}

\let\oldnewacronym\newacronym

\newcommand*{\provideacronym}[3]{%
  \ifglsentryexists{#1}{%
  }{%
    \oldnewacronym{#1}{#2}{#3}%
  }%
}

\renewcommand*{\newacronym}{\provideacronym}

\newacronym{cd}{CD}{compact disk}

\newacronym{cd}{CD 2}{compact disk 2}

\begin{document}

Some text about \gls{cd}.

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.