2

In a use-case more complex then the MWE I want to generate the symbol key of a glossary entry based on other keys (e.g. name & description). In the use-case the symbol a will be a math expression compossed of other custom keys b & c which are math expressions and need to be combined e.g. a:= b^c.

My approach in the MWE does work out for a first level entry, but fails for the second level entries. Please see the MWE output table column "Remarks" below for what I expect. I observed that the generated Symbol is allways that of the last defined child newglossaryentryin the script.

enter image description here

I would appreciate some help and suggestions for improvement.

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

\usepackage{longtable}
\usepackage{booktabs}

\usepackage[nomain,nonumberlist]{glossaries}           

\newglossary[sog]{symbol}{soi}{soo}{Symbols}

\newglossarystyle{groupedsymbols}{%  
    \renewenvironment{theglossary}%  
    {\begin{longtable}{llp{\glsdescwidth}}}%  
        {\bottomrule % booktabs
        \end{longtable}}%  
    \renewcommand*{\glossaryheader}{%
        \toprule % booktabs 
        \bfseries Category & %
        \bfseries Symbol & %
        \bfseries Remark %
        \\\endhead
        \midrule % booktabs
    }%  
    \renewcommand*{\glsgroupheading}[1]{}% 
    %    
    \renewcommand*{\glossentry}[2]{%
        %\glsentryitem{##1} %
        \bfseries \glsentrydesc{##1} & & %
        \\
    }% 
    \renewcommand*{\subglossentry}[3]{%  
         & \glsentrysymbol{##2} & \glsentrydesc{##2} %
        \\
    }% 
    \renewcommand*{\glsgroupskip}{\relax}
}

\makeglossaries

\newglossaryentry{group}{%
    type=symbol,
    name={testgroup},
    description={Categ. 1}
}

\newglossaryentry{groupentrytwo}{%
    type=symbol,
    parent=group,
    name={yabc},  
    description={Symbol WRONG ! should be: yabc},
    symbol={\glsentryname{\glslabel}}
} 

\newglossaryentry{groupentryone}{%
    type=symbol,
    parent=group,
    name={zabc},  
    description={Symbol is zabc correctly},
    symbol={\glsentryname{\glslabel}}
} 

\begin{document}
    \glsaddall[types={symbol}]
    \printglossary[type=symbol,style=groupedsymbols]
\end{document}
4reigner
  • 109
  • I suspect a grouping problem. If you use \renewcommand*{\subglossentry}[3]{% & \glsentrytext{##2} & \glsentrydesc{##2} % \\ }% it will work –  Mar 29 '16 at 13:13
  • Thank you for the suggestion, but that does not improve my somehow wrong approach to "construct a key from others in subentries" - which I need for my usecase. – 4reigner Mar 29 '16 at 13:30
  • Perhaps Nicola Talbot should answer this. –  Mar 29 '16 at 13:35
  • Obviously I did not get your point right away, until EngBIRD explained in greater detail. Thanks again for the proposed workaround. Please make a short answer out of your comment, so I can upvote it. Mind if I accept EngBIRD's answer as it is more complete? – 4reigner Mar 29 '16 at 18:23
  • No, just accept EngBIRD's answer. If you really want to upvote something, look for some other answers of mine ;-) I am not really sure where the culprit is. –  Mar 29 '16 at 18:26

1 Answers1

3

I believe Christian Hupfer had the solution to your problem. But if indeed it isn't what you were looking for perhaps you could clarify further. I have expanded your MWE with the solution described above and I get the results that I infer to be expected. Perhaps a more complex MWE is needed

enter image description here

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

\usepackage{longtable}
\usepackage{booktabs}

\usepackage[nomain,nonumberlist]{glossaries}           

\newglossary[sog]{symbol}{soi}{soo}{Symbols}

\newglossarystyle{groupedsymbols}{%  
    \renewenvironment{theglossary}%  
    {\begin{longtable}{llp{\glsdescwidth}}}%  
        {\bottomrule % booktabs
        \end{longtable}}%  
    \renewcommand*{\glossaryheader}{%
        \toprule % booktabs 
        \bfseries Category & %
        \bfseries Symbol & %
        \bfseries Remark %
        \\\endhead
        \midrule % booktabs
    }%  
    \renewcommand*{\glsgroupheading}[1]{}% 
    %    
    \renewcommand*{\glossentry}[2]{%
        %\glsentryitem{##1} %
        \bfseries \glsentrydesc{##1} & & %
        \\
    }% 
    \renewcommand*{\subglossentry}[3]{%  
         & \glsentrytext{##2} & \glsentrydesc{##2} %
        \\
    }% 
    \renewcommand*{\glsgroupskip}{\relax}
}

\makeglossaries

\newglossaryentry{group}{%
    type=symbol,
    name={testgroup},
    description={Categ. 1}
}

\newglossaryentry{quadratic}{%
    type=symbol,
    name={testgrouptwo},
    description={quadratic formulas}
}

\newglossaryentry{groupentrytwo}{%
    type=symbol,
    parent=group,
    name={yabc},  
    description={Symbol WRONG ! should be: yabc  Not anymore.  This is what I expected.},
    symbol={\glsentryname{\glslabel}}
} 

\newglossaryentry{groupentryone}{%
    type=symbol,
    parent=group,
    name={zabc},  
    description={Symbol is zabc correctly as expected},
    symbol={\glsentryname{\glslabel}}
} 

\newglossaryentry{grouptwoentrytwo}{%
    type=symbol,
    parent=quadratic,
    name={$ax^2 + bx + c = 0$},  
    description={This is what I expect},
    symbol={\glsentryname{\glslabel}}
} 

\newglossaryentry{grouptwoentryone}{%
    type=symbol,
    parent=quadratic,
    name={$x = \frac{{ - b \pm \sqrt {b^2 - 4ac} }}{{2a}}$},  
    description={This is what I expect},
    symbol={\glsentryname{\glslabel}}
} 

\begin{document}
    \glsaddall[types={symbol}]
    \printglossary[type=symbol,style=groupedsymbols]
\end{document}
EngBIRD
  • 3,985
  • Thank you for adding more detail to the answer of Christian Hupfer. I got the point now. It seems to work with every key (pre or userdefined) except for symbol. Is that a bug or a feature? – 4reigner Mar 29 '16 at 18:26
  • @4reigner could you be more specific about what you mean about "except for symbol"? If memory serves I have used many symbols (text annotations, Greek, and mathematical) in the past. Give me a newglossaryentry or other MWE adjustment that doesn't work and I will do my best to investigate and help out. – EngBIRD Mar 29 '16 at 18:43
  • apparently I was a bit to lax in my comment. I meant the symbol={..} approach in the initial MWE. – 4reigner Mar 29 '16 at 20:04
  • @4reigner When I add a \glssymbol{grouptwoentryone} call below the \printglossary call, I get the resulting math formula? Is this what isn't working for you? Or is this not what you were expecting to get? Perhaps you could be a bit more verbose in your comment, you have plenty of characters. – EngBIRD Mar 29 '16 at 20:16
  • As discussed in http://tex.stackexchange.com/questions/301090/combining-multiple-math-mode-glossary-entries I need a fully expandable glossaries-command. AFAIK from the discussion therein \glssymbol is not expandable and according to the initial MWE of this question here \glsentrysymbol does not work. As a solution has been found, I suggest to close this case. – 4reigner Mar 31 '16 at 05:51
  • @4reigner I am glad you found a solution to your problem. I think I now understand the symbol instance you were describing. Since my tex file didn't contain a \glsentrysymbol I couldn't find it and was getting lost. For what it's worth, I also get the same result if I use \glssymbol{##2} inplace of \glsentrytext{##2} so keep that in mind if you ever have to move away from your definition of symbol={\glsentryname{\glslabel}} – EngBIRD Mar 31 '16 at 14:34