0

I am using the glossaries-extra package (https://ctan.org/pkg/glossaries-extra?lang=en) provided by TeX Live 2023 for consistently typesetting tensorial quantities in mathematical equations throughout my document.

Such quantities may be denoted by a bold symbol (σ for the stress tensor) or in index notation (σ_{ij} for component ij of the stress tensor). The indices should be provided by the user or assume default values if no indices are provided. This may be accomplished by defining the tensorial quantity and its components in separate entries (Glossary entry with extra parameter which was answered by the package author)

% tensor definition with components in extra entry
\newglossaryentry{Strain}{%
category    = {2ndOTnsrs},%
name        = {\ensuremath{\boldsymbol{\varepsilon}}},%
description = {strain tensor},%
}
\newglossaryentry{strain}{%
category    = {2ndOTnsrs},%
name        = {\ensuremath{\varepsilon_{\ijIdx}}},%
description = {components of the \glsdesc{Strain}},%
}

and referring to the entries by means of \gls-like commands

\glsdesc{Strain} \gls{Strain} with components \gls{strain} or \gls{strain}[kl]

which produces the desired output

enter image description here

However, it would be more convenient to define a single entry

\newglossaryentry{stress}{%
category    = {2ndOTnsrs},%
name        = {\ensuremath{ \boldsymbol{\sigma}^{} }},%
description = {stress tensor},
components  = {\ensuremath{ \sigma_{\ijIdx} }},%
}

and refer to the index notation of the quantity by a \glstext-like command

\glsdesc{stress} \gls{stress} with components \glscomp{stress} or \glscomp{stress}[kl]

My current solution

% save \glsinsert for \glstext-like commands
\renewcommand*{\glsxtrsaveinsert}[2]{\def\glsinsert{#2}}
% replace indices for \gls-like and \glstext-like commands
\let\origglstextformat\glstextformat
\renewcommand{\glstextformat}[1]{%
    \ifdefempty{\glsinsert}{}{%
        \let\ijIdx\glsinsert%   \ijIdx is set to \glsinsert
        \def\glsinsert{}%       \glsinsert is set to none
    }%    
    \origglstextformat{#1}%
}

produces the following output

enter image description here

While the default indices are correctly replaced with the provided insert, the insert is repeated at the end of the expression.

Is there a way to get rid of the repeated insert at the end of the expression for \glstext-like commands?

Full MWE: https://www.overleaf.com/read/dbqtfrmnpdbh#ba4018

Paul Hofer
  • 11
  • 2

0 Answers0