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'm trying to make a system-wide glossary database (with acronyms and definitions) as a package.

My file is: /usr/local/texlive/texmf-local/tex/latex/local/myglossary.sty

One needs to run:

sudo texhash

so that TeXLive sees the file.

Of course, I don't need all the definitions every time. So I split the definitions by domain.

File: /usr/local/texlive/texmf-local/tex/latex/local/myglossary.sty

% myglossary.sty
% acronyms and definitions

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{myglossary}

\RequirePackage{glossaries}

\DeclareOption{computer}{\option@computer} %% Execute \option@computer if option computer

\newcommand\option@computer{%
  \newacronym{w3c}{W3C}{World Wide Web Consortium}

  \newglossaryentry{css}{%
    name={CSS},%
    description={Style sheet language used for describing the presentation semantics (the look and formatting) of a document written in a markup language.},%
    plural={CSS}}
}

\ProcessOptions

\endinput

File: ~/Desktop/test/document.tex:

% document.tex
\documentclass{minimal}

\usepackage[computer]{myglossary}% note the option "computer"

\begin{document}

  \gls{w3c}
  \gls{css}

\end{document}

Compiled using:

pdflatex document.tex

The error is:

! Package glossaries Error: Glossary entry `w3c' has already been defined.

Thanks for the help.

share|improve this question
    
Just from personal interest: in my understanding the glossaries mechanism is somewhat similar to the bibtex logic. This means I can add as many entries a I like and makeindex/xindy take care that only the entries that are used in the document get to the glossary. Therefore I don't see any needs to segment the myglossary package into domains. The only thing where I could imagine this to be useful is when you want to change the explanations depending on the audience you write for. –  Benedikt Bauer Jan 2 '13 at 11:39

1 Answer 1

up vote 2 down vote accepted

I probably would rather set the option as a boolean switch:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{myglossary.sty}
% myglossary.sty
% acronyms and definitions

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{myglossary}

\RequirePackage{glossaries}

\newif\if@myglossary@computer

\DeclareOption{computer}{\@myglossary@computertrue} %
\ProcessOptions

\if@myglossary@computer
\newacronym{w3c}{W3C}{World Wide Web Consortium}

\newglossaryentry{css}{%
    name={CSS},%
    description={Style sheet language used for describing the presentation semantics (the look and formatting) of a document written in a markup language.},%
    plural={CSS}}
\fi

\endinput
\end{filecontents}

\usepackage[computer]{myglossary}% note the option "computer"
\makeglossaries
\begin{document}

  \gls{w3c}
  \gls{css}

\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.