# Merge multiple glossaries types in one single glossary

I would like to "merge" two glossaries in a single \printglossary or something equivalent (see MWE).

1. enable sorting by e.g. name across the glossaries

Is there a way to do so?

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage[nomain,nonumberlist]{glossaries}

\newglossary[sog]{symbol}{soi}{soo}{Symbols}
\newglossary[fog]{operator}{foi}{foo}{Operators}

\makeglossaries

\newglossaryentry{typeAentry1}{%
type=symbol,
name={A1},
description={none}
}

\newglossaryentry{typeBentry1}{%
type=operator,
name={B1},
description={none}
}

\begin{document}

% single separated glossaries
\printglossary[title=Symbols,type={symbol}]
\printglossary[title=Operators,type={operator}]

%what i would like to do
%\printglossary[title=Symbols and Operators,type={symbols LOGICAL OR operator}]
\end{document}


This isn't merging, but moving from one glossary to another one with \glsmoveentry{label}{target glossary}.

Since there is more than one entry (most likely) one could use the

\forallglsentries[operator]{\localfoo}{\glsmoveentry{\localfoo}{symbol}}


command, to move all entries from, say, operator to symbol. The \localfoo is an 'arbitrary' command sequence and expands to the current gls label of the entry, e.g. \typeBentry1 in the current setup.

The use case is in my point of view where the entries are for different glossaries are stored in an individual file for each glossary and are loaded with \loadglsentries.

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage[nomain,nonumberlist]{glossaries}

\newglossary[sog]{symbol}{soi}{soo}{Symbols}
\newglossary[fog]{operator}{foi}{foo}{Operators}

\makeglossaries

\newglossaryentry{typeAentry1}{%
type=symbol,
name={A1},
description={Is a symbol}
}

\newglossaryentry{typeBentry1}{%
type=operator,
name={B1},
description={comes from Operator}
}

\begin{document}

\def\localfoo{}
\forallglsentries[operator]{\localfoo}{\glsmoveentry{\localfoo}{symbol}}

\gls{typeBentry1} and \gls{typeAentry1}

% single separated glossaries
\printglossary[title=Symbols,type={symbol}]
%\printglossary[title=Operators,type={operator}]

%what i would like to do
%\printglossary[title=Symbols and Operators,type={symbols LOGICAL OR operator}]
\end{document}


• There's one backdraw: Nothing is moved if the the glslabel is not used so far.
– user31729
Mar 31, 2016 at 14:36
• If you were to surround your \forallglsentries loop with \glsaddall and \glsresetall to trick the migration into being complete, would that work? Or would it have the undesired consequence of including it in the new glossary even if it hadn't been used? Mar 31, 2016 at 14:39
• @EngBIRD: I am unsure. I don't think this will work, but perhaps, I am not seeing the possibilities here ;-)
– user31729
Mar 31, 2016 at 14:44
• @EngBIRD @Christian Hupfer : the \glsaddall' approach does not work for me on trying out, but the restrictions of the given solution are acceptable in my usecase. Thx Mar 31, 2016 at 15:39
• @4reigner: I know, that's why I used \gls explicitly. I try to figure out why this is the case.
– user31729
Mar 31, 2016 at 16:02

Another approach is to get makeindex to merge them. For example, suppose the following document is called test.tex:

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage[nomain,nonumberlist]{glossaries}

\newglossary[sog]{symbol}{soi}{soo}{Symbols}
\newglossary[fog]{operator}{foi}{foo}{Operators}

\makeglossaries

\newglossaryentry{typeAentry1}{%
type=symbol,
name={A1},
description={none}
}

\newglossaryentry{typeBentry1}{%
type=operator,
name={B1},
description={none}
}

\begin{document}

Then you can merge the operator glossary into the symbol glossary using:
pdflatex test

(or replace pdflatex with latex or xelatex`, as appropriate). This produces: