# Force hyphenation of glossary term in-text

In English, you sometimes want to add hyphens when the order of words can make the meaning ambiguous. Example:

Confusing:

 Springfield has little town charm.


Better:

 Springfield has little-town charm.


Now, let's say little town is defined in the glossary (glossary package) without hyphen (because the term does not normally require it) and I want to insert it in the sentence above, e.g.:

\documentclass{article}
\usepackage{glossaries}

\makeglossaries
\newglossaryentry{little_town}
{
name={little town},
description={A town that is small}
}

\begin{document}
Springfield has \gls{little_town} charm.

\printglossaries
\end{document}


How can I tell latex to hyphenate the term little town in this specific sentence?

• Welcome to TeX.SX!! It is better to post a full minimal working example. For example, A LaTeX MWE should start with a \documentclass command, have a minimal preamble and then \begin{document}...\end{document}. Unless the problem is a compilation error, the code should compile and be as small as possible to demonstrate your problem. This makes it much easier for people to help you --- and much more likely that they will! – Andrew May 28 '16 at 0:56

You could add your own field, and define the pattern in the entry definition. You would still have to manually point to which gls entry you want to use, but I can't see latex running a grammar check to evaluate this part for you.

\documentclass{article}
\usepackage{glossaries}

{hyphenated}        % new key
{\relax}            % default value if "hyphenated" isn't used in \newglossaryentry
{\glsentryhyph}     % analogous to \glsentrytext
{\Glsentryhyph}     % analogous to \Glsentrytext
{\glshyph}          % analogous to \glstext
{\Glshyph}          % analogous to \Glstext
{\GLShyph}          % analogous to \GLStext

\makeglossaries
\newglossaryentry{little_town}
{
name={little town},
hyphenated={little-town},
description={A town that is small}
}

\begin{document}
Springfield has \glshyph{little_town} charm.

\printglossaries
\end{document}