You don't want to do it. Notwithstanding that a respected user recommended it, it's not right (at least in my opinion).
Anyway, you can redefine \hat to look for its argument and see whether
- it's more than one token (use
\widehat)
- it's a single uppercase Latin letter (use
\widehat)
- it's a single command denoting an uppercase Greek letter (use
\widehat)
In all other cases use \hat.
\documentclass{article}
\usepackage{amsmath}
\NewCommandCopy{\amsmathhat}{\hat}
\ExplSyntaxOn
\RenewDocumentCommand{\hat}{m}
{
\joeli_hat:n { #1 }
}
\clist_const:Nn \c__joeli_hat_greek_clist
{
\Gamma,\Delta,\Theta,\Kappa,\Lambda,\Xi,\Pi,\Sigma,\Upsilon,\Phi,\Omega
}
\cs_new_protected:Nn \joeli_hat:n
{
\tl_if_single:nTF { #1 }
{% just one token
__joeli_hat_single:N #1
}
{
\widehat{#1}
}
}
\cs_new_protected:Nn __joeli_hat_single:N
{
\token_if_cs:NTF #1
{
__joeli_hat_greek:N #1
}
{
\str_if_eq:eeTF { #1 } { \str_uppercase:n { #1 } }
{ \widehat{#1} }
{ \amsmathhat{#1} }
}
}
\cs_new_protected:Nn __joeli_hat_greek:N
{
\clist_if_in:NnTF \c__joeli_hat_greek_clist { #1 }
{ \widehat{#1} }
{ \amsmathhat{#1} }
}
\ExplSyntaxOff
\begin{document}
$\hat{a}\hat{A}\hat{b}\hat{B}\hat{\gamma}\hat{\Gamma}\hat{ABC}$
\end{document}

Compare with the standard

\hat{}.\let\hat\widehatwould assign\widehatto\hatmeaning from the point of definition onward all\hatwould act as\widehatuntil the end of a document or the next re-definition. You can narrow this effect to a group, e.g.{\let\hat\widehat ...}– Celdor Sep 02 '22 at 10:36