Using amsmath and mathabx messes up stacking a widehat on a vec

Here's a minimal example:

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{mathabx}

\begin{document}

$\widehat{\vec{v}_{i-1}}$

\end{document}


What I expect this to generate is a widehat over the entire \vec{v}_{i-1}, but instead the various components are randomly spaced and overlapping. If I remove either amsmath or mathabx, the problem goes away. How should I fix this? I need to typeset this in a paper that makes essential use of both amsmath and mathabx.

• Interesting... A temporary solution is to reset the definition \def\widehat{\mathaccent "0362} after \usepackage{mathabx}. Or you can use \let\OldWidehat\widehat \usepackage{mathabx} \let\widehat\OldWidehat . Not sure if this will break other things though. Sep 23 '17 at 3:51

While amsmath uses a quite complicated way of dealing with math accents, in order to be able to stack two of them correctly, it doesn't modify the definition of \widehat (and \widetilde). However, it does redefine the workings of \DeclareMathAccent, so that accents declared after loading it use the code for stacking accents.

On the other hand, mathabx isn't really compatible with amsmath, as it does redefinitions that obliterate several amsmath features.

The solution for the specific problem is to reinstate working definitions for \widehat and \widetilde.

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{mathabx}

\renewcommand{\widehat}{\mathaccent "0670\relax}
\renewcommand{\widetilde}{\mathaccent "0672\relax}

\begin{document}

$\widehat{\vec{v}_{i-1}}\qquad \widetilde{\vec{v}_{i-1}}$

\end{document}


You should probably import the symbols you need, rather than loading the whole mathabx, see Importing a Single Symbol From a Different Font

If you don't need mathx family, using only \usepackage[matha,mathb]{mathabx} it works.

\documentclass[11 pt]{article}

\usepackage{amsmath}
\usepackage[matha,mathb]{mathabx}

\begin{document}

$\widehat{\vec{v}_{i-1}}$

\end{document}


Otherwise, here is a dirty workaround:

\documentclass[11 pt]{article}
\usepackage{stackengine}

\usepackage{amsmath}
\usepackage{mathabx}

\begin{document}
$\stackinset{c}{}{t}{-3pt}{\widehat{\phantom{{v}_{i-1}}}}{\vec{v}_{i-1}}$
\end{document}
`