# How to use amsmath environment \Bmatrix inside a glossary?

I´d like to use the following environment from amsmath-package for a glossary-entry but latex fails (TexStudio with pdflatex):

\begin{Bmatrix}...\end{Bmatrix}

Here is my MWE:

\documentclass{scrbook}
\usepackage{amsmath}
\usepackage{glossaries}
%
\begin{document}
\section{in Textmode everything is fine}
$\begin{Bmatrix}W_{ij}\end{Bmatrix}$, brackets with the required height
%
\section{trying the same using glossaries}
%
the working one:\par
%
\newglossaryentry{mat:Wij}{%
name=\ensuremath{\left\{W_{ij}\right\}},
description={working entry, tensor brackets manually}
}%
%
\gls{mat:Wij}, Problem: brackets don´t have the required height\\
\\
%%
the one with the following mistake:\par
line 30: Undefined control sequence. \} \\
%
%\newglossaryentry{mat:Mij}{%
%name=\ensuremath{
%\begin{Bmatrix}
%M_{ij}
%\end{Bmatrix}},
%description={entry with mistake, tensor brackets by Bmatrix-command}
%}%
%%
%\gls{mat:Mij}, brackets with the required height
\end{document}


The problem is caused by expansion.

Working version:

\documentclass{scrbook}
\usepackage{amsmath}
\usepackage{glossaries}

\glsnoexpandfields

\newglossaryentry{mat:Mij}{%
name=\ensuremath{
\begin{Bmatrix}
M_{ij}
\end{Bmatrix}},
description={entry with mistake, tensor brackets by Bmatrix-command}
}

\newglossaryentry{mat:Wij}{%
name=\ensuremath{\left\{W_{ij}\right\}},
description={working entry, tensor brackets manually}
}%

\begin{document}
\section{in Textmode everything is fine}
$\begin{Bmatrix}W_{ij}\end{Bmatrix}$, brackets with the required height

\section{trying the same using glossaries}

the working one:

\gls{mat:Wij}, Problem: brackets don´t have the required height

the one with the following mistake:\par
line 30: Undefined control sequence. \}

\gls{mat:Mij}, brackets with the required height
\end{document}


I recommend you move your definitions to the preamble (as I've done above). If you really want them in the document use

\usepackage[docdefs=restricted]{glossaries-extra}


\usepackage{glossaries}


If you intend to add \printglossaries, remember to add the sort key for those entries:

\newglossaryentry{mat:Mij}{%
sort={Mij},
name=\ensuremath{
\begin{Bmatrix}
M_{ij}
\end{Bmatrix}},
description={entry with mistake, tensor brackets by Bmatrix-command}
}

\newglossaryentry{mat:Wij}{%
sort={Wij},
name=\ensuremath{\left\{W_{ij}\right\}},
description={working entry, tensor brackets manually}
}

• I contend that also \left\{W_{ij\right\} is wrong and it should simply be \{W_{ij}\}. – egreg Sep 7 '16 at 16:39
• @egreg (Deleted my previous comment.) Actually, I suspect it was just there for comparison with Bmatrix for testing, but only the OP can confirm that. – Nicola Talbot Sep 7 '16 at 18:21
• Many thanks, the solution is such simple knowing the right command... (-: – wabu Sep 9 '16 at 6:01
• @egreg: It´s the thing Nicola perceived, \left\{W_{ij}\right\} i added only to show what I expect from Bmatrix. Problem with your recommendation will be, no automatic adjustment of brackets height. Compare e.g: \left\{\dfrac{1}{2}}\right\} and \{\dfrac{1}{2}\} – wabu Sep 9 '16 at 6:13