2

I want to provide a symbol in math mode with a character above – like \tilde{...} or \hat{...}. I'm using that symbol sometimes with subscript indices as well as with superscript indices. The idea with the character above came that they do not interfere optically with the indices.

My first solution with \overset{\omega}{\phi} did not work, because the vertical alignment of a superscript includes the whole construction while it should only regard the lower, big character. After some internet search I found the accent package as a solution with \accentset{\omega}{\phi}, which indeed delivers the correct alignment. But when I want to pack it inside a glossaryentry from the glossaries package,

\newglossaryentry{foo} {
    name={\ensuremath{\accentset{\omega}{\phi}}},
    description={foo}
}

it can't compile – "Undefined control sequence" error.

How can I make both packages compatible or how do I simulate the behaviour of the \accentset command?

Here are both behaviours shown, with "2" as index:

example for both alignments

Here is a minimal not working example

\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{accents}
\usepackage{glossaries}
\newglossaryentry{foo} {
    name={\ensuremath{\accentset{\omega}{\phi}}},
    description={foo}
}
\makeglossaries
\begin{document}
$\overset{\omega}{\phi}^2$ wrong alignment \\
$\accentset{\omega}{\phi}^2$ correct alignment \\
$\gls{foo}$ not possible
\end{document}
claudio
  • 23

1 Answers1

4

\accentset is a fragile command, so use \protect\accentset for the write process to an external file.

\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{accents}
\usepackage{glossaries}
\newglossaryentry{foo} {
    name={\ensuremath{\protect\accentset{\omega}{\phi}}},
    description={foo}
}
\makeglossaries
\begin{document}
$\overset{\omega}{\phi}^2$ wrong alignment \\
$\accentset{\omega}{\phi}^2$ correct alignment \\
$\gls{foo}^2$ is possible now. 
\end{document}

If more occurences of \accentset are needed, it could be worth of thinking about robustification, i.e.

\usepackage{etoolbox}
\robustify{\accentset}

this means, \protect\accentset isn't needed any longer.