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}
  • Welcome to TeX.SE. Thanks for posting a complete MNWE as a good starting point! – user31729 Feb 8 '17 at 21:20
  • maybe duplicate: How to write \overset{\circ}{W}_2^{1,1} so that superscript looks good?. it, in turn, is marked as a dup, but the cited question doesn't cover your question as well. – barbara beeton Feb 8 '17 at 21:46
  • @ChristianHupfer thank you for your welcoming message! Your answer was exactly what I was looking for. Although late, upvoted and accepted it. Thanks! – claudio Mar 30 '17 at 7:53
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.

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.