3

I would like to combine 2 or more math mode glossary entries to form a complete expression in math-mode. Background is a separation of nomenclature and symbols.

I use expressions as in the second variant of this answer: https://tex.stackexchange.com/a/137506/101663

What I would like to get is shown in formula 1 of my MWE. What I get is shown in formula 2. What I suppose might happen is given in formula 3.

result of MWE

Ase one is not allowed (and it in fact doesn't work) to use gls-commands in the optional parameter of a gls the approach given in the manual does NOT help:

$\gls{Falpha}[^2]$

Is there any way to achieve my goal?

MWE:

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

\usepackage[acronym]{glossaries}

\newglossary[fog]{formula}{foi}{foo}{Formula} 

\makeglossaries

\newglossaryentry{mathpart1}{
    name=test, text=x_{ref},
    description=irrelevant, type=formula
} 

\newglossaryentry{mathpart2}{
    name=test2, text=^{abc},
    description=irrelevant2, type=formula
} 

\begin{document}
Desired output:
\[
    x_{ref}^{abc} = 0
\]

Achieved output with gls:
\[
    \gls{mathpart1}\gls{mathpart2} = 0
\]      

Similar behaviour:
\[
    {x_{ref}}^{abc} = 0
\]      
\end{document}
1
  • \[ \gls{mathpart1}^{\gls{mathpart2}} = 0 \] works, of course, and just remove the ^ from the abc stuff. I think it is better not to use ^ in the gls - entry – user31729 Mar 27 '16 at 14:50
3

See the improved update below at the end.

I suggest to omit the superscript operator in the gls replacement text and use \gls{foo}^{\gls{foobar}} rather.

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

\usepackage[acronym]{glossaries}

\newglossary[fog]{formula}{foi}{foo}{Formula} 

\makeglossaries

\newglossaryentry{mathpart1}{
    name=test, 
    text={\ensuremath{x_{ref}}},
    description=irrelevant, type=formula
} 

\newglossaryentry{mathpart2}{
    name=test2, 
    text={abc},
    description=irrelevant2, type=formula
} 



\begin{document}
Desired output:
\[
    x_{ref}^{abc} = 0
\]

Achieved output with gls:
\[
\gls{mathpart1}^{\gls{mathpart2}} = 0
\]      

Similar behaviour:
\[
    {x_{ref}}^{abc} = 0
\]      
\end{document}

Update -- According to the O.P. the \glstextentry is expandable, but \gls isn't. Use \glstextentry then.

Since \gls isn't expandable, \gls{foo}\gls{foobar} can't be expanded to something like foo^{foobar}.

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

\usepackage[acronym]{glossaries}

\newglossary[fog]{formula}{foi}{foo}{Formula} 

\makeglossaries

\newglossaryentry{mathpart1}{
    name=test, 
    text={\ensuremath{x_{ref}}},
    description=irrelevant, type=formula
} 

\newglossaryentry{mathpart2}{
    name=test2, 
    text={^{abc}},
    description=irrelevant2, type=formula
} 



\begin{document}
Desired output:
\[
    x_{ref}^{abc} = 0
\]

Achieved output with gls:
\[
\gls{mathpart1}\glsentrytext{mathpart2} = 0
\]      

Similar behaviour:
\[
    {x_{ref}}^{abc} = 0
\]      
\end{document}

enter image description here

5
  • Thank you for the quick answer. While that works for this special case in the MWE I loose generality. When later on I decide to e.g. interchange ^ and _ between symbols and nomenclature I need to go through my large document and manually replace things. – 4reigner Mar 27 '16 at 15:12
  • @4reigner: Honestly, I don't know whether it's possible at all what you desire. I fear that \gls.. isn't really expandable – user31729 Mar 27 '16 at 15:13
  • Thank you for the keyword "expandable". According to the doc $\glsentrytext$ is expandable. Replacing $\gls$ by $\glsentrytext$ in my MWE does the trick. Can I somehow accept your comment as the correct answer? – 4reigner Mar 27 '16 at 21:52
  • @4reigner: Well, I can change my answer to incorporate \glsentrytext, but comments can't be accepted. – user31729 Mar 28 '16 at 8:03
  • @4reigner: I added your comment into the answer – user31729 Mar 28 '16 at 10:01

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.