3

Inspired by this question I created a glossary entry with an optional parameter as a subscript. However when I try to have a superscript there as well I can't use the trick where I pass the superscript as an optional argument because I already have one. Is there any workaround?

MWE

\documentclass{article}
\usepackage{glossaries-extra}
\glsnoexpandfields

\newglossaryentry{A}{
    category={arg},
    user1={1},
    name={\(A_{\glsarg}\)},
    text={A_{\glsarg}},
    description={A}}

\preto\glsentryfmt{%
    \glsifcategory{\glslabel}{arg}% if category set to "arg"
    {%
        \ifdefempty\glsinsert
        {\glsfieldfetch{\glslabel}{useri}{\glsarg}}%
        {%
            \let\glsarg\glsinsert
            \let\glsinsert\empty
        }%
    }%
    {}%
}

\begin{document}
    Tried:
    \[\gls{A}[ij]^T\]
    \[\gls{A}[ij^T]\]
    Desired outcome:
    \[A^T_{ij}\]
\end{document}
2

You essentially have this:

\documentclass{article}

\begin{document}
\newcommand{\glsarg}{ij^T}
\[A_{\glsarg}\]
\end{document}

which puts ij^T as the subscript (that is, A_{ij^T}) where ^T is the superscript of j.

The following, which moves the braces, works:

\documentclass{article}

\begin{document}
\newcommand{\glsarg}{{ij}^T}
\[A_\glsarg\]
\end{document}

Applying this to the MWE:

\documentclass{article}
\usepackage{glossaries-extra}
\glsnoexpandfields

\newglossaryentry{A}{
    category={arg},
    user1={1},
    name={\(A_{\glsarg}\)},
    text={A_\glsarg},
    description={A}}

\preto\glsentryfmt{%
    \glsifcategory{\glslabel}{arg}% if category set to "arg"
    {%
        \ifdefempty\glsinsert
        {\glsfieldfetch{\glslabel}{useri}{\glsarg}}%
        {%
            \let\glsarg\glsinsert
            \let\glsinsert\empty
        }%
    }%
    {}%
}

\begin{document}
Compare
\[\gls{A}[{ij}^T]\]
With:
\[A^T_{ij}\]
\end{document}

Compare A<sup>T</sup><sub>ij</sub> With: A<sup>T</sup><sub>ij</sub>

Note that with this method you must remember to always apply the grouping in the optional argument if there's more than one subscript. For example:

\[\gls{A}[{ij}]\]

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.