# Nomenclature with glossaries line break in name field

I'm using the glossaries package to generate a nomenclature for my document. The problem is that some of my entries have very long functions within the name field. How can I add a manual line break at the desired position? So e.g. after the first or second comma within the function of the second entry. What I don't want is to change the definition of \glssetwidest as the width fits well for most of the entries.

MWE:

\documentclass[12pt,a4paper]{report}

\usepackage{amsmath}
\usepackage{longtable}
\usepackage[acronym,toc,nopostdot]{glossaries}

\glssetwidest[0]{...................}

\newglossaryentry{first_entry}{
name = $\omega_i$ ,
description = Description
}

\newglossaryentry{second_entry}{
name = {$f(epq_{i}, tlz_{i+1}, xy)$} ,
description = Description
}

\makeglossaries

\begin{document}
\glsaddall

\printglossary[nonumberlist, style = alttree, title=Nomenclature]

\end{document}


Edit: If the description is long (e.g. three lines) and the symbol spans over two lines then there is a blank line within the description. How can I change this behaviour?

MWE of Edit:

\documentclass[12pt,a4paper]{report}

\usepackage{amsmath}
\usepackage{longtable}
\usepackage[acronym,toc,nopostdot]{glossaries}

\glssetwidest[0]{...................}

\newglossaryentry{first_entry}{
name = $\omega_i$ ,
description = Description
}

\newglossaryentry{second_entry}{
name = {$f(epq_{i}, tlz_{i+1},\newline xy)$},
text = {$f(epq_{i}, tlz_{i+1}, xy)$},
description = {Very long description lines with span several lines and gets broken by a blank line if the symbol span two line. Very long description lines with span several lines and gets broken by a blank line if the symbol span two line.}
}

\makeatletter
\newglossarystyle{alttree2}{%
\setglossarystyle{alttree}%
\renewcommand{\glossentry}[2]{%
\ifnum\@gls@prevlevel=0\relax
\else
\settowidth{\glstreeindent}{\glstreenamefmt{\@glswidestname\space}}%
\fi
\hangindent\glstreeindent
\parindent\glstreeindent
\makebox[0pt][r]{\parbox[t]{\glstreeindent}{\raggedright
\glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}}}%
\ifglshassymbol{##1}{(\glossentrysymbol{##1})\space}{}%
\glossentrydesc{##1}\glspostdescription \space ##2\par
\def\@gls@prevlevel{0}%
}%
}
\makeatother

\makeglossaries

\begin{document}
\glsaddall

\printglossary[nonumberlist, style = alttree2, title=Nomenclature]

\end{document}

• You're mwe has some errors (missing \begin{document}, undefined \f and the value of the name key needs braces when it contains commas). – Nicola Talbot Oct 31 '15 at 12:33

## 1 Answer

The alttree style uses \makebox which won't allow line breaks. You could make a new style based on the alttree style that uses a \parbox instead. For example:

\documentclass[12pt,a4paper]{report}

\usepackage{amsmath}
\usepackage{longtable}
\usepackage[acronym,toc,nopostdot]{glossaries}

\glssetwidest[0]{...................}

\newglossaryentry{first_entry}{
name = $\omega_i$ ,
description = Description
}

\newglossaryentry{second_entry}{
name = {$f(epq_{i}, tlz_{i+1},\newline xy)$},
text = {$f(epq_{i}, tlz_{i+1}, xy)$},
description = {Description}
}

\makeatletter
\newglossarystyle{alttree2}{%
\setglossarystyle{alttree}%
\renewcommand{\glossentry}[2]{%
\ifnum\@gls@prevlevel=0\relax
\else
\settowidth{\glstreeindent}{\glstreenamefmt{\@glswidestname\space}}%
\fi
\hangindent\glstreeindent
\parindent\glstreeindent
\makebox[0pt][r]{\parbox[t]{\glstreeindent}{\raggedright
\glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}}}%
\ifglshassymbol{##1}{(\glossentrysymbol{##1})\space}{}%
\glossentrydesc{##1}\glspostdescription \space ##2\par
\def\@gls@prevlevel{0}%
}%
}
\makeatother

\makeglossaries

\begin{document}
\glsaddall

\printglossary[nonumberlist, style = alttree2, title=Nomenclature]

\end{document}


This produces:

Edit:

The \parbox's height affects the first line of the description, which I'd forgotten about. This can be eliminated by using \smash like this:

\newglossarystyle{alttree2}{%
\setglossarystyle{alttree}%
\renewcommand{\glossentry}[2]{%
\ifnum\@gls@prevlevel=0\relax
\else
\settowidth{\glstreeindent}{\glstreenamefmt{\@glswidestname\space}}%
\fi
\hangindent\glstreeindent
\parindent\glstreeindent
\makebox[0pt][r]{\smash{\parbox[t]{\glstreeindent}{\raggedright
\glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}}}}%
\ifglshassymbol{##1}{(\glossentrysymbol{##1})\space}{}%
\glossentrydesc{##1}\glspostdescription \space ##2\par
\def\@gls@prevlevel{0}%
}%
}


This modification to the above MWE now produces:

However, since this removes the \parbox's height, if the description has fewer lines than the name this may cause the excess lines to clash with the next entry. If this is likely to happen, it may be better to use a tabular-like style. Another possibility you might want to consider is to allow the long name to overflow and start the description on the next line, like this:

\documentclass[12pt,a4paper]{report}

\usepackage{amsmath}
\usepackage{longtable}
\usepackage[acronym,toc,nopostdot]{glossaries}

\glssetwidest[0]{...................}

\newglossaryentry{first_entry}{
name = $\omega_i$ ,
description = Description
}

\newglossaryentry{second_entry}{
name = {$f(epq_{i}, tlz_{i+1}, xy)$},
description = {\newline Very long description lines with span several lines and gets broken by a blank line if the symbol span two line. Very long description lines with span several lines and gets broken by a blank line if the symbol span two line.}
}

\makeglossaries

\begin{document}
\glsaddall

\printglossary[nonumberlist, style = alttree, title=Nomenclature]

\end{document}


This produces:

• I'm sorry for the errors in the MWE, I will correct it. Your solution works perfect thank you. One more question: If the description is multiline (three lines) and the symbol is multiline (two lines) then I have a blank line within the description. How can I change it? – user2653422 Oct 31 '15 at 12:46
• @user2653422 I've updated my answer. – Nicola Talbot Oct 31 '15 at 13:29
• Great, works perfect. One thing I was trying to do was to add \phantom{f(} after the \newline in the name field in order to indent the xy a bit. However, the smash operator doesn't seem to like the \phantom command. Do you also have a solution for that? – user2653422 Oct 31 '15 at 14:24
• @user2653422 I don't get a problem with name = {$f(epq_{i}, tlz_{i+1},\newline \phantom{f(}xy)$}, What happened when you tried it? – Nicola Talbot Oct 31 '15 at 15:46
• The error is Incomplete \iffalse; all text was ignored after line 120.. But this error also occurs with the original alttree style. I'm not sure where this error comes from. – user2653422 Oct 31 '15 at 15:58