1

Why does the following simple code raise Undefined control sequence error?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\hat{\smash{\hat f}}$
\end{document}
  • What is it you are actually trying to accomplish? Having a double hat? What is important about the need for \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
  • @StevenB.Segletes Right, I want to have double hat. What I actually have is $\hat{\raisebox{.2ex}{\vphantom{f}}\smash{\hat{f}}}$. – Tianren Liu Sep 28 '20 at 00:26
  • Related: https://tex.stackexchange.com/a/10508/ – muzimuzhi Z Sep 28 '20 at 00:38
  • @muzimuzhiZ Thank you. I knew that solution. But it uses the package accents which 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

3 Answers3

2

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}

David Carlisle
  • 757,742
  • Thanks! This works surprisingly well. I got command undefined error when writing my double-hat macro \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
  • It seems that \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
1

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}

enter image description here

0

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.)