Why does the following simple code raise Undefined control sequence error?
\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\hat{\smash{\hat f}}$
\end{document}
Why does the following simple code raise Undefined control sequence error?
\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\hat{\smash{\hat f}}$
\end{document}
As Steven says using \smash here probably doesn't work well in any case, but it should not give an internal command undefined error.
I haven't fully traced it but at one point the internal accent nesting counter gets set to 5 presumably because it is confused by teh \mathchoice in \smash evaluating its argument 4 times (in each of the styles display, text, script and scriptscript)
The simplest, although not necessarily best fix is to give the internal lengths a default setting of 0pt so if you end up here they just add a zero kern rather than error.
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\let\macc@kerna\z@
\let\macc@kernb\z@
\let\macc@nucleus\@empty
\makeatother
\begin{document}
$\hat{\smash{\hat f}}$
\end{document}
\newcommand{\hathat}[1]{\hat{\raisebox{.2ex}{\vphantom{\ensuremath{#1}}}\smash{\hat{#1}}}}. Your "simplest" fix makes it work!
– Tianren Liu
Sep 29 '20 at 05:17
\macc@nucleus should be reset every time. Otherwise, try compile $\hat{\hat x}$ $\hat{\smash{\hat{f}}}$, the outcome is hilarious.
– Tianren Liu
Sep 29 '20 at 05:46
Trying to place a hat on a smashed quantity makes no sense, as the height of the smashed quantity is set to 0pt. In the 3rd line, I emulate such an attempt. Yuck. First 2 lines are recommended...either remove the \smash, or only \smash at the end of the process.
\documentclass{article}
\usepackage{amsmath}
\parskip 1ex
\begin{document}
$\hat{\hat f}$ no smash
$\smash{\hat{\hat f}}$ final result smashed
$\sbox0{$\smash{\hat f}$}\hat{\box0}$ hatting a smash makes no sense
\end{document}
Thank Steven and David for your answers.
The simplest fix I found so far is \usepackage{accents}. (Though unfortunately for me, accents is not compatible with a conference template I'm using.)
\smash? Adding an accent to a smashed quantity, in general, makes no sense, as it would not know where to put it. – Steven B. Segletes Sep 28 '20 at 00:14$\hat{\raisebox{.2ex}{\vphantom{f}}\smash{\hat{f}}}$. – Tianren Liu Sep 28 '20 at 00:26accentswhich is not compatible with a conference template. So I'm trying to understand how their solution works. – Tianren Liu Sep 28 '20 at 01:15