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.}%
}%
}%
}
glossaries
while writing and say\newcommand*{\gls}[1]{#1}
and then switch when you have written the entries.