[Tex/LaTex] How to manually choose the size of a wide accent? (math mode)

accentsmath-mode

I would like to replace the usual \hat in maths with a larger one, but I do not want it to stretch. The size I want is "the smallest \widehat" (as in $\widehat{.}$). Is there a way to put that one above a wide character like M ($\widehat{M}$ would stretch and give be an even wider hat).

I guess I have a lack of understanding for the mechanism behind accents that extend, so feel free to explain.

Best Answer

This is a bit tricky. I'm sorry. But the result is well.

\documentclass{article}
\usepackage{amsmath,accents}
\DeclareMathSymbol{\widehatsym}{\mathord}{largesymbols}{"62}
\newcommand\lowerwidehatsym{%
  \text{\smash{\raisebox{-1.3ex}{%
    $\widehatsym$}}}}
\newcommand\fixwidehat[1]{%
  \mathchoice
    {\accentset{\displaystyle\lowerwidehatsym}{#1}}
    {\accentset{\textstyle\lowerwidehatsym}{#1}}
    {\accentset{\scriptstyle\lowerwidehatsym}{#1}}
    {\accentset{\scriptscriptstyle\lowerwidehatsym}{#1}}
}

\begin{document}
$\fixwidehat{k}\fixwidehat{M}\fixwidehat{x}$

\[ \fixwidehat{abc} \]
$\fixwidehat{ab}^{\fixwidehat{ab}}$
\end{document}

enter image description here