3

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

Additional requirements:

  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}
    \glsaddall

    % 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}

2 Answers 2

5

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}

enter image description here

5
  • 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?
    – EngBIRD
    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
    – 4reigner
    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
4

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}
    \glsaddall

    \printglossary[title=Symbols and Operators,type=symbol]
\end{document}

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

pdflatex test
makeindex -s test.ist -t test.sog -o test.soi test.soo test.foo
pdflatex test

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

image of merged glossary

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.