I'd define one entry (say, digest) in the usual way and then use \gls{digest}
in the description field of the alternative entries. See section 8 of the glossaries
manual for details.
\documentclass{article}
\usepackage[nonumberlist]{glossaries}
\makeglossaries
\newglossaryentry{digest}{name={digest (\textmd{also} hash, hash code)},%
text=digest,description={The output of a hash function}}
\newglossaryentry{hash}
{name=hash,description={\emph{See} \gls{digest}}}
\newglossaryentry{hash code}
{name={hash code},description={\emph{See} \gls{digest}}}
\begin{document}
\null\vfill% just for the example
Some text about \gls{digest}.
Some text about \gls{hash}.
Some text about \gls{hash code}.
\printglossaries
\end{document}
Multiple parents aren't supported by glossaries
. If you have hyperlinks, there would be an ambiguity as to which glossary entry commands like \gls
would link to. There are however ways to get around it.
Approach 1:
Define two entries with the same name but different parents and use the relevant one in the context of its given parent. This works best if you don't have a location list. Example:
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: pdflatex
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[style=index,nonumberlist]{glossaries}
\makeglossaries
\newglossaryentry{parent1}
{%
name={parent 1},%
description={First parent}%
}
\newglossaryentry{parent2}
{%
name={parent 2},%
description={Second parent}%
}
\newglossaryentry{child1}
{%
name={sample},
description={an example},%
parent={parent1}%
}
\newglossaryentry{child2}
{%
name={sample},%
description={an example},%
parent={parent2}%
}
\begin{document}
Reference \gls{child1} in the context of \gls{parent1}.
Reference \gls{child2} in the context of \gls{parent2}.
\printglossaries
\end{document}
The first reference links to the entry under First parent
. The second reference links to the entry under Second parent
.
Approach 2:
This approach is more advanced. It stores a list of labels with which a child entry is associated and defines \mgls
to iterate through the list using \glsadd
for all except the final label for which it uses \gls
. Example:
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: pdflatex
\documentclass{article}
\usepackage{etoolbox}
\usepackage[colorlinks]{hyperref}
\usepackage[style=index]{glossaries}
\makeglossaries
\newglossaryentry{parent1}
{%
name={parent 1},%
description={First parent}%
}
\newglossaryentry{parent2}
{%
name={parent 2},%
description={Second parent}%
}
\newcommand{\dochild}[3]{%
\listcsadd{#2.labels}{#3.#2}%
\newglossaryentry{#3.#2}%
{%
#1,parent={#3}%
}%
}
% syntax: \addchild{label}{parent list}{key=val list}
\newcommand*{\addchild}[3]{%
\csdef{#1.labels}{}%
\forcsvlist{\dochild{#3}{#1}}{#2}%
}
\newcommand*{\mgls}[2][]{%
\def\glslastlabel{}%
\forlistcsloop
{%
\ifdefempty{\glslastlabel}{}{\glsadd[#1]{\glslastlabel}}%
\def\glslastlabel
}%
{#2.labels}%
\gls[#1]{\glslastlabel}%
}
\newcommand*{\mglsadd}[2][]{%
\forlistcsloop
{%
\glsadd[#1]%
}%
{#2.labels}%
}
\addchild{sample}{parent1,parent2}%
{%
name={sample},%
description={an example}%
}
\begin{document}
\mgls{sample}.
\printglossaries
\end{document}
Here \mgls
will link to the entry under the last named parent used when the child entry was defined with \addchild
.
If you would rather link to a different glossary entry, you can use \mglsadd
and explicitly use \gls
with the label in the form parent.
child. Like this:
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: pdflatex
\documentclass{article}
\usepackage{etoolbox}
\usepackage[colorlinks]{hyperref}
\usepackage[style=index]{glossaries}
\makeglossaries
\newglossaryentry{parent1}
{%
name={parent 1},%
description={First parent}%
}
\newglossaryentry{parent2}
{%
name={parent 2},%
description={Second parent}%
}
\newcommand{\dochild}[3]{%
\listcsadd{#2.labels}{#3.#2}%
\newglossaryentry{#3.#2}%
{%
#1,parent={#3}%
}%
}
% syntax: \addchild{label}{parent list}{key=val list}
\newcommand*{\addchild}[3]{%
\csdef{#1.labels}{}%
\forcsvlist{\dochild{#3}{#1}}{#2}%
}
\newcommand*{\mgls}[2][]{%
\def\glslastlabel{}%
\forlistcsloop
{%
\ifdefempty{\glslastlabel}{}{\glsadd[#1]{\glslastlabel}}%
\def\glslastlabel
}%
{#2.labels}%
\gls[#1]{\glslastlabel}%
}
\newcommand*{\mglsadd}[2][]{%
\forlistcsloop
{%
\glsadd[#1]%
}%
{#2.labels}%
}
\addchild{sample}{parent1,parent2}%
{%
name={sample},%
description={an example}%
}
\begin{document}
\mglsadd{sample}\gls{parent1.sample}.
\printglossaries
\end{document}
This produces the same looking result as previously, but now the sample entry links to the entry under the first parent instead of the second parent.
Best Answer
You could move the entry after printing the first glossary:
Note that I'm not sure if this will have untoward side-effects. Caveat emptor...