1

Let's assume that you wish to reference all occurrences of a particular mathematical operator, say, supremum \sup, in a glossary. How? Well, my try would be to \let\sup\relax and then \DeclareMathOperator{\sup}{\gls{...}}. However, this approach generates unwanted horizontal space in front of "sup". How to get rid of it by default and still maintain the hyperlinks? Below, I compare the standard \sup with my approach.

Code:

\documentclass{svmono}%%% Obtainable from https://www.springer.com/gp/authors-editors/book-authors-editors/manuscript-preparation/5636
\usepackage{mathtools}%%% loads amsmath internally
\mathtoolsset{mathic=true} %%% See https://tex.stackexchange.com/a/3496/
\usepackage[hidelinks]{hyperref}
%%% The next hack improves how hyperref jives with svindd.ist, see https://tex.stackexchange.com/a/429446
\makeatletter
\def\@commahyperpage#1{\@@commahyperpage#1,\,,\\}
\def\@@commahyperpage#1,\,#2,#3\\{%
  \ifx\\#2\\%
    \HyInd@pagelink{#1}%
  \else
    \HyInd@pagelink{#1},\,\HyInd@pagelink{#2}%
  \fi
}
\makeatother
\usepackage[makeindex,toc,nogroupskip,nomain]{glossaries-extra}
\setglossarystyle{long3col}\renewcommand{\glspagelistwidth}{10em}
\GlsSetQuote{+} %%% Hack to work with makeindex
\newglossary[nlg]{notation}{not}{ntn}{Notation}
\makeglossaries
\glssetcategoryattribute{mathoperator}{hyperoutside}{false}
\glssetcategoryattribute{mathoperator}{textformat}{mathop}
\newglossaryentry{not:supremum}{type=notation, name={\(\mathrm{sup}\)}, category=mathoperator, text={\mathop{\mathrm{sup}}}, sort={supremum}, description={The supremum of a set is the smallest upper bound for the set.}}
\DeclareMathOperator{\mysup}{\gls{not:supremum}}
\begin{document}
\begin{align*}
  f(\sup S) &= \sup f(S)\\
  f(\mysup S) &= \mysup f(S)
\end{align*}
\printglossaries
\end{document}

Output, page 1:

page 1 of the result produced by pdflatex

Output, page 3:

page 3 of the result produced by pdflatex

As you see, there is some unwanted space between "(" and "sup" as well as some more space between "=" and "sup".

(An aside: I apologize for the size of the the question; a prior smaller revision of the question seems to have a technically correct but a useless answer.)

  • \DeclareMathOperator{\mysup}{sup\glsadd{not:supremum}} seems to work in your MWE, but I don't know if it works in general and how it interacts with the links you intend to use later. – moewe Jun 6 '18 at 20:30
  • Ah just as I feared, you lose the linking from \gls to the index with \glsadd{not:supremum}. Sorry ... – moewe Jun 6 '18 at 20:51
  • 2
    Please, use standard classes for minimal examples, if specific features are not needed. – egreg Jun 6 '18 at 21:04
2

I don't think it's a good idea to index every appearance of an object.

Anyway, the problem is that an ordinary atom is inserted in an inappropriate spot, which you can cure with \!

\documentclass{article}
\usepackage{mathtools}%%% loads amsmath internally
\mathtoolsset{mathic=true} %%% See https://tex.stackexchange.com/a/3496/
\usepackage[hidelinks]{hyperref}
%%% The next hack improves how hyperref jives with svindd.ist, see https://tex.stackexchange.com/a/429446
\makeatletter
\def\@commahyperpage#1{\@@commahyperpage#1,\,,\\}
\def\@@commahyperpage#1,\,#2,#3\\{%
  \ifx\\#2\\%
    \HyInd@pagelink{#1}%
  \else
    \HyInd@pagelink{#1},\,\HyInd@pagelink{#2}%
  \fi
}
\makeatother
\usepackage[makeindex,toc,nogroupskip,nomain]{glossaries-extra}

\setglossarystyle{long3col}\renewcommand{\glspagelistwidth}{10em}

\GlsSetQuote{+} %%% Hack to work with makeindex
\newglossary[nlg]{notation}{not}{ntn}{Notation}
\makeglossaries

\glssetcategoryattribute{mathoperator}{hyperoutside}{false}
\glssetcategoryattribute{mathoperator}{textformat}{mathop}

\let\supop\sup \let\sup\relax
\DeclareMathOperator*{\sup}{\gls{not:supremum}}

\newglossaryentry{not:supremum}{
  type=notation,
  name={\(\supop\)},
  category=mathoperator,
  text=\!\supop,
  sort={supremum},
  description={The supremum of a set is the smallest upper bound for the set.}
}


\begin{document}
\begin{align*}
  f(\supop S) &= \supop f(S)\\
  f(\sup S) &= \sup f(S) \\
  \max\sup\max &= \max\supop\max
\end{align*}

\printglossaries

\end{document}

enter image description here

  • 1
    @MdAyquassar No, that empty atom causes the insertion of a thin space. – egreg Jun 6 '18 at 21:11
  • 1
    @MdAyquassar Sorry, it should have been \DeclareMathOperator*, fixed. I just modified your code. – egreg Jun 7 '18 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy