# Dot Derivative Discrepancy

I am trying to typeset some higher-order time derivatives using the dot notation, and I've noticed something strange. The expressions

$\dot y + y = \cos(\dot y)$
$\ddot y + y = \cos(\dot y)$


give the expected results. However,

$\dddot y + y = \cos(\dot y)$
$\ddddot y + y = \cos(\dot y)$


causes the higher derivative term to be slightly raised, see below. Any thoughts?

Here is my preamble:

\documentclass{article}
\usepackage{amsmath, amssymb, amsfonts, amsthm, fouriernc}

-
Your code snippets don't compile for me. Where is \ds defined? Please compose a fully compilable MWE that illustrates the problem. –  Peter Grill Jan 27 '12 at 3:06
@PeterGrill: I've edited the OP's code for clarity and removed the unnecessary \ds terms. –  Mico Jan 27 '12 at 7:44
In addition to the problem of \dddot- and \ddddot-accented letters not being set correctly on the baseline, it seems there's a second problem: The size of the dots for one- and two-dot accents is smaller than that of the dots of the three- and four-dot accents. This seems to be a "feature" caused by the loading of the fouriernc package: if amsmath is loaded without the fouriernc package, at least all dots have the same size. (I noticed this problem right away in the image the OP posted, but I don't know if it's so evident to others as well.) –  Mico Jan 27 '12 at 13:33

The problem in placement stems from the fact that both \dddot and \ddddot construct their arguments as \mathop in order to place a "limit" on top of it. However, \mathop centres its contents vertically on the math axis if the argument is a single character (see mathop shifts the baseline, DeclareMathOperator doesn't) - a feature.

So, you should trick LaTeX in thinking it is actually more than a single character by adding (say) \hspace{0pt}:

\documentclass{article}
\usepackage{amsmath, amssymb, amsfonts, amsthm, fouriernc}
\begin{document}
\begin{enumerate}
\item $\dot{y} + y = \cos(\dot y)$
\item $\ddot{y} + y = \cos(\dot y)$
\item $\dddot{y\hspace{0pt}} + y = \cos(\dot y)$
\item $\ddddot{y\hspace{0pt}} + y = \cos(\dot y)$
\end{enumerate}
\end{document}


One can correct automatically the behavior by adding the following code after \usepackage{amsmath}:

\makeatletter
\renewcommand{\dddot}[1]{%
{\mathop{\kern\z@#1}\limits^{\vbox to-1.4\ex@{\kern-\tw@\ex@
\hbox{\normalfont ...}\vss}}}}
\renewcommand{\ddddot}[1]{%
{\mathop{\kern\z@#1}\limits^{\vbox to-1.4\ex@{\kern-\tw@\ex@
\hbox{\normalfont....}\vss}}}}
\makeatother

-
It's clearly a bug in amsmath. –  egreg Jan 27 '12 at 10:10
definitely a bug in amsmath, reported first in 2003. curiously, in the original report, submitted with accented uppercase letters, the affected terms were lowered, leading to a slightly different statement of the problem. but it's the same problem, and it's on our list. –  barbara beeton Jan 27 '12 at 13:41
@barbarabeeton Letters without descenders are lowered, those with discenders and no ascenders are raised. It's curious that amsmath has corrected in \overset the similar bug in \stackrel, but hasn't a \kern\z@ in \dddot and \ddddot. –  egreg Jan 27 '12 at 13:53
@egreg -- it's not that a bug was corrected in \overset. the \kern\z@ in \overset was inherited from ams-tex, as were the definitions of \dddot and \ddddot, and the same bug still exists for those two accents in ams-tex. it's unlikely that any more bugs will ever be fixed in ams-tex, but thanks for making me check; i'll add them to that list now. as for \stackrel, that's defined in latex.ltx so any bug report should go to the latex bugs database -- there's nothing there now, so can you take care of that, please? –  barbara beeton Jan 27 '12 at 14:19
@barbarabeeton I meant that amsmath (or amstex) took care of not making the same error as in \stackrel. I guess it's too late to change \stackrel in latex.ltx: it's become a feature. :) –  egreg Jan 27 '12 at 14:27

The accents package fixes this buggy behaviour of \dddot and \ddddot (and also a few other issues; see below). If the accents versions still don't make you happy, give the code at the end of this answer a try.

Werner gave a great explanation of how the vertical positioning problem arises and how it can be fixed. I'd like to discuss a few more (not quite as conspicious) issues I see with \dddot and \ddddot. These occur also without using the fouriernc package (which in addition leads to overly large dots, as Mico noted in his comment to the question), so I didn't load fouriernc for producing the screenshots below.

1.   As one sees in the image, the dots in \dddot{y\hspace{0pt}} are quite a bit farther apart than in \ddot{y}. (I don't think that this is intentional.)

2. If one looks a bit closer, then one sees that the dots from \dddot are also a bit higher than those from \ddot.

3. With \dddot and \ddddot, the horizontal positioning of the dots isn't satisfactory either, in my opinion. Namely, these commands don't take into account the skew of the character like the math accents \dot and \ddot do. This isn't obvious in the image with y above, but a comparison of \dddot{J\hspace{0pt}} and \ddot{J} makes it clear: . (And this is not the fault of the \hspace{0pt} fix.)

4. \dddot and \ddddot don't work properly in sub- and superscripts: the dots have the same size and spacing as in \textstyle. But I don't see a real problem here since probably one shouldn't use those commands in sub- and superscripts anyway.

5. On an overly pedantic note, the dots in \dddot (black) are a few percent larger than those in \ddot (red). Moreover, the bounding box of \dddot{y} is not quite high enough. The latter might be a minor issue, but I didn't encounter any problems.

The accents package fixes some of the above issues by redefining \dddot and \ddddot appropriately. In particular, the dots are placed like accents to that the skew is taken into account, and the dots are closer together. For \ddddot, they are in fact noticeably closer together than in \ddot. All in all, it looks much better:

One clearly sees that one would have to put some extra space around \ddddot{l} in the right hand side of the above formula. The reason is that the dots are defined in a way that they take up no horizontal space. (This is a side effect of \ddddot being defined as a math accent.) On the left hand side this behaviour leads to nice spacing in the left hand side.

Issue #2 is not fixed by accents: strangely enough, the package sets the dots a bit lower than in \ddot. Actually the dots are lowered a bit more than they're raised with amsmath. Also point #4 in the list isn't quite fixed, the most obvious point being that \dddot doesn't work properly in \scriptstyle since the definition contains a \textstyle that should be removed:

\def\dddot{\accentset{{\cc@style.\mkern-1.7mu\textstyle.\mkern-1.7mu.}}}


If you're still not quite satisfied with the versions from the accents package, then you can use my implementation of \dddot and \ddddot below which fixes all the issues above (except for the marginally too large dot-size mentioned in #5 :-)). The code only works together with amsmath since it hacks into amsmath's accent placement (just like here). In the image below I compare my implementation (line 1) with the accents (line 2) and amsmath (line 3) implementations. (Note that I didn't use Werner's fix for amsmath.)

\documentclass{article}
\usepackage{amsmath}%, fouriernc}
\let\amsdddot\dddot
\let\amsddddot\ddddot
\usepackage{accents}
\let\accdddot\dddot
\let\accddddot\ddddot
\makeatletter
\renewcommand*\dddot[1]{%
\placeaccent{\acc@dot\mkern1.4mu\acc@dot\mkern1.4mu\acc@dot}{#1}%
}
\renewcommand*\ddddot[1]{%
\placeaccent{\acc@dot\mkern1.4mu\acc@dot\mkern1.4mu\acc@dot\mkern1.4mu\acc@dot}{#1}%
}
\newcommand*\placeaccent[2]{%
\begingroup
\def\acc@dot{\kern-0.08em.\kern-0.08em}%
\def\acc@skip{\ifx\macc@style\displaystyle0.32
\else\ifx\macc@style\textstyle0.32
\else\ifx\macc@style\scriptstyle0.22
\else0.15\fi\fi\fi ex}%
\def\mathaccent##1##2{%
\setbox6\hbox{$\m@th\macc@style#1$}%
\@tempdima\wd4
\divide\@tempdima\tw@
\@tempdimb\z@
\ifdim\@tempdima<\z@ \@tempdimb-\@tempdima \@tempdima\z@ \fi
\vbox{\offinterlineskip
\moveright\@tempdima\box6
\kern\acc@skip
\moveright\@tempdimb\box4}%
}%
\macc@depth\@ne
\let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
\mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
\macc@set@skewchar\relax
\let\mathaccentV\macc@nested@a
\macc@nested@a\relax111{#2}%
\endgroup
}
\makeatother
\begin{document}
\fboxrule0.0001pt
\fboxsep0pt
\begin{enumerate}
\item $\dot y + \ddot y + \dddot y + \ddddot{y} = \cos(\ddddot l)$,
\quad \fbox{$\dddot{y}$}, \quad
$\ddot{A}_{\dddot{x}_{\ddddot{x}}} \ne \dddot{A}_{\ddot{x}_{\dot{x}}}$
\let\dddot\accdddot
\let\ddddot\accddddot
\item $\dot y + \ddot y + \dddot y + \ddddot{y} = \cos(\ddddot l)$,
\quad \fbox{$\dddot{y}$}, \quad
$\ddot{A}_{\dddot{x}_{\ddddot{x}}} \ne \dddot{A}_{\ddot{x}_{\dot{x}}}$
\let\dddot\amsdddot
\let\ddddot\amsddddot
\item $\dot y + \ddot y + \dddot y + \ddddot{y} = \cos(\ddddot l)$,
\quad \fbox{$\dddot{y}$}, \quad
$\ddot{A}_{\dddot{x}_{\ddddot{x}}} \ne \dddot{A}_{\ddot{x}_{\dot{x}}}$
\end{enumerate}
\end{document}

-
If there is need, I can add some explanations to my code. –  Hendrik Vogt Jun 23 '12 at 9:35

Unicode has dedicated accent characters for those: 0x20DB and 0x20DC.

So with unicode-math, \dddot and \ddddot should work correctly. It should be noted that Will Robertson, the author of unicode-math, states in the README:

I am a little wary of encouraging people to use this package for production work

Nevertheless, Unicode is certainly The Way Of The Future™.

-
those look like primes, not dots. –  Roelof Spijker Jan 27 '12 at 12:59
@wh1t3 what they look like here depends on… a gazillion of things. Maybe I'll take them off from the answer since there's no way to make sure the client can see them correctly. –  morbusg Jan 27 '12 at 13:04