# Displaying & highlighting glossary entries that are not defined yet?

In my document I use the glossariespackage.

When referencing terms, that do not exist in the glossary (yet) the term is simply not displayed. Which IMHO forces a quite complex workflow.

Is there any possibility of displaying non-defined terms, but in a different color?

for example:

\gls{DefinedTerm} would be displayed in my default link-color and

\gls{UndedinfedTerm} would be displayed in another style, like red, underlined.

----UPDATE-----

The following does exactly what i was looking for:

\newcommand{\mygls}[1]{\ifglsentryexists{#1}{\gls{#1}}{\textcolor{red}{\underline{#1}}}}

put this in your preamble and simply use \mygls{Term}. Undefined terms will then be highlighted, while defined terms will be displayed using \gls{}

-
Please see the update in my answer. With the \let command, you can use only \gls and not worry about switching between your own command and using it. As you update your glossary, the entries will naturally switch from being red/underlined to being used as a normal \gls entry. –  J M Jul 21 '12 at 16:55
beautiful solution indeed - thanks a lot! –  Max Gherkins Jul 21 '12 at 17:36

--UPDATE--

I have updated the command as follows (you must include the xcolor pacakage in order to use the \textcolor command:

\let\originalgls\gls
\renewcommand{\gls}[1]{\ifglsentryexists{#1}{\originalgls{#1}}{\textcolor{red}{\underline{#1}}}}

You can now use the \gls command for all your entries, and as you define them, they will switch from being red/underlined to being used as a normal \gls entry.

--END UPDATE--

When I compile my thesis (which I'm in the middle of right now) and I include a \gls{UndefinedTerm} my compilation errors out, stating: "Glossary entry UndefinedTerm has not been defined". Does your compilation not fail? I would encourage you to simply add the terms as you go, it is truly not that cumbersome or time-consuming.

It even appears, looking at glossaries.sty, that it should throw an error (from lines 935-940 of glossaries.sty) To someone more able, this may be the place to modify the code and create the output you need.

\newcommand{\glsdoifexists}[2]{%
\ifglsentryexists{#1}{#2}{%
\PackageError{glossaries}{Glossary entry `#1' has not been
defined}{You need to define a glossary entry before you
can use it.}}%
}

Otherwise, if all that the \gls for an undefined term will do is print it in red and underline, why not simply make a command for that. You will have to go through the thesis and look for them anyway, then add the entry. I still think that this will be more hassle at the end.

ugls for "Undefined gls" \newcommand{\ugls}[1]{\textcolor{red}{\underline{#1}}}

-
Thank you so much for that! \newcommand{\mygls}[1]{\ifglsentryexists{#1}{\gls{#1}}{\textcolor{red}{\underli‌​ne{#1}}}} did the trick! –  Max Gherkins Jul 21 '12 at 8:05
Oh wonderful! I hadn't thought of using the \ifglsentryexists command. I may include that in my thesis as well. Make sure to include the xcolor package for the \textcolor command. –  J M Jul 21 '12 at 8:30