# Math mode bug using \dot and \hat

EDIT: I want to write this

but with a dot over the middle - for differentiation of the value in parenthesis with respect to frame I. However when I do ${^{\rm I}(\dot {I_{\rm p} \omega_{\rm p} \hat b_3})}$ I get

I have tried all sorts of variations that should give me something close to what I want but none of them work. The closest I can get is

by purposefully putting the hat over the whole b_3 symbol using (\hat {b_3}). However I need the hat to be over the b only.

• MathJax is intentionally disabled on the TeX.SE, as users are likely far more interested in seeing the underlying TeX and LaTeX code than in the way it's rendered on screen. – Mico Nov 14 '17 at 16:24
• \rm has been deprecated for over 20 years, don't use it (especially not in math mode) – David Carlisle Nov 14 '17 at 16:44
• Weird, I use it all the time. How is roman text compiled in math mode now? – Thomas Kirven Nov 14 '17 at 16:45
• \rm has not been defined in the latex format since 1993. It is added as a back compatibility definition by article.cls but not all classes do this. for example. \mathrm{p} – David Carlisle Nov 14 '17 at 16:47
• @ThomasKirven yes although I'd be interested to know the results if you tested the patch I just posted, as I could add that to amsmath, but the code here is very delicate.... – David Carlisle Nov 14 '17 at 23:15

It's another instance of Why do arguments to nested \tilde or \breve commands reappear when amsmath is used?

\documentclass{article}
\usepackage{amsmath}

\newsavebox{\accentbox}
\newcommand{\compositeaccents}[2]{%
\sbox\accentbox{$#2$}#1{\usebox\accentbox}}

\begin{document}

Bad: ${^{\rm I}(\dot {I_{\rm p} \omega_{\rm p} \hat b_3})}$

\bigskip

Good: ${}^{\mathrm{I}}\compositeaccents{\dot}{(I_{\mathrm{p}} \omega_{\mathrm{p}} \hat{b}_3})$

\end{document}


However, I'd avoid such notation.

Please, note that \rm has been deprecated for 25 years.

• shouldn't I fix that in amsmath ? – David Carlisle Nov 14 '17 at 17:33
• @DavidCarlisle You're welcome! – egreg Nov 14 '17 at 17:42
• @DavidCarlisle if it isn't a feature, you should... – Skillmon Nov 14 '17 at 18:42

It is impossible to see why you are getting overprinting from your fragments, the following document produces

\documentclass{article}

\begin{document}

${^{\mathrm{I}}\dot {({I}_{\mathrm{p}} \omega_{\mathrm{p}} \hat{b}_3})}$
\end{document}


As it turns out, this is an amsmath feature (although amsmath was not mentioned in the question) Not fully tested but one possible fix is below. I could add something like this to amsmath but it needs more testing, if you have a larger real docuemnt I'd be interested if this works

\documentclass{article}
\usepackage{amsmath}

\makeatletter

\def\mathaccentV#1#2#3#4#5{%
\ifmmode
\gdef\macc@tmp{\macc@depth\@ne}%
\setbox\z@\hbox{%
% only short circuit \mathaccentV if only one token after expansion
% not quite the right test but hard to test for only one math atom
\ifcat$\@gobble#5\@empty$\let\mathaccentV\macc@test\fi
% end of change
\let\use@mathgroup\@gobbletwo \let\select@group\@gobblethree
\frozen@everymath{}$#5$%
}%
\macc@tmp
\ifnum\macc@depth=\@ne
\global\let\macc@nucleus\@empty
\mathaccent"\accentclass@
\else
\@xp\macc@nested
\fi
#2#3#4{#5}%
\macc@nucleus
\else
\@xp\nonmatherr@\csname#1\endcsname
\fi
}

\makeatother
\begin{document}

$\dot{\hat{b}}$

${^{\mathrm{I}}\dot {({I}_{\mathrm{p}} \omega_{\mathrm{p}} \hat{b}_3})}$
\end{document}


An alternative:

\documentclass{article}
\usepackage{amsmath,stackengine}
\stackMath
\begin{document}
$^{\mathrm{I}}(\stackon[1pt]{I_{\mathrm{p}} \omega_{\mathrm{p}} \hat b_3}{.})$
\end{document}


You might also consider something less confusing, such as $^{\mathrm{I}}[\frac{d}{dt}(I_{\mathrm{p}} \omega_{\mathrm{p}} \hat b_3)]$

or, if the syntax makes sense, $\frac{d}{dt}\,^{\mathrm{I}}(I_{\mathrm{p}} \omega_{\mathrm{p}} \hat b_3)$

• You sir are a gentleman and a scholar. But yeah I introduce the dot notation earlier in the paper (usually it's over just one symbol so it's less confusing) so I just gotta stick with that. – Thomas Kirven Nov 14 '17 at 16:51
• Note: amsmath is not required for this answer. – Steven B. Segletes Nov 14 '17 at 16:53
• @ThomasKirven nothing is wrong with using two notations for the same thing if one is better in some the other in other cases. – Skillmon Nov 14 '17 at 18:44