2

The hyperref package, when it tries to link to a label that doesn't yet exist, gives a warning but continues without making the link. Is it possible to have a similar setup with the glossaries package? For example, if I use \gls{boat} could it be configured to just print "boat" without linking to a glossary entry if such an entry does not exist?

I would like to work on the project and include \gls{} commands as I go, and then write all the glossary entries later.

1
  • 1
    You could just not load glossaries while writing and say \newcommand*{\gls}[1]{#1} and then switch when you have written the entries.
    – cfr
    Nov 19, 2014 at 2:23

1 Answer 1

1

With the glossaries-extra extension package you can use the package option undefaction=warn, which will generate a warning instead of an error message if any entries are undefined. As with \cite and \ref, it will display ?? in the document text.

Example:

\documentclass{article}

\usepackage[undefaction=warn]{glossaries-extra}

\begin{document}

A \gls{boat}.

\end{document}

This generates the warning

Package glossaries-extra Warning: Glossary entry `boat' has not been defined on
 input line 7.

The result is just

A ??.

If you want the label to appear instead of ?? you can redefine \glsdoifexists to locally change \glsxtrundeftag to the label:

\documentclass{article}

\usepackage[undefaction=warn]{glossaries-extra}

\renewcommand{\glsdoifexists}[2]{%
  \ifglsentryexists{#1}{#2}%
  {%
    \edef\glslabel{\glsdetoklabel{#1}}%
    {% scope
       \let\glsxtrundeftag\glslabel
       \glsxtrundefaction{Glossary entry `\glslabel'
       has not been defined}{You need to define a glossary entry before
       you can reference it.}%
    }%
  }%
}

\begin{document}

A \gls{boat}.

\end{document}

This may have some unwanted side-effects. It might be better to add some markup to highlight that the entry is undefined when proof-reading. For example:

\renewcommand{\glsdoifexists}[2]{%
  \ifglsentryexists{#1}{#2}%
  {%
    \edef\glslabel{\glsdetoklabel{#1}}%
    {% scope
       \def\glsxtrundeftag{[?\glslabel?]}%
       \glsxtrundefaction{Glossary entry `\glslabel'
       has not been defined}{You need to define a glossary entry before
       you can reference it.}%
    }%
  }%
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .