4

I'm trying to write an expression in which an accented expression enclosed by parentheses has an accent over the parentheses. For example,

\vec{(\dot{x})}

This typesets fine when amsmath is not loaded, but with amsmath present, the x is typeset to the right of the dot, as if the inner expression is being treated as

\dot{}x

This behavior only happens when a closing parentheses (or bracket or brace) is part of the argument to the outer accent.

The best workaround I've been able to find is to use overset for the outer accent instead of the actual accent command (or accentset).

Is this behavior expected/documented anywhere?


I believe that this question was previously asked at amsmath possible bug: \dot over bracketed \dot{x}, but was incorrectly marked as a duplicate of \dot over \vec over : amsmath bug/feature?. The latter question was about the differences in typesetting between dotting a subscripted character and subscripting a dotted character.

  • I guess this is rather related to tex.stackexchange.com/q/30327/4427. On the other hand, (\vec{\dot{x}) seems better syntax. – egreg Mar 30 at 16:14
  • Thanks. On the syntax question, putting the parentheses outside the \vec command is semantically different from applying the \vec to the whole contents of the parentheses. My \vec{(\dot{x})} minimal example probably would not be used in practice, but applying accents to parenthetically-delimited expressions or to matrices has multiple use-cases. – RLH Mar 30 at 16:27
  • How's the reader supposed to know the difference between \vec{(\dot{x})} and (\vec{\dot{x}})? And, if you have \vec{(blahblah)} the problem is even worse. – egreg Mar 30 at 16:29
  • As I said, I don't think that my minimal example will be used in practice. An expression like \dot{\begin{bmatrix} x \\ \dot{x} \end{bmatrix}} has a use-case (in explaining basic controls systems principles), and gets mangled by this bug. As a second example, in \vec{(\exp \dot{x})} vs (\vec{\exp \dot{x}}), the \vec is set higher on the first expression, clearly indicating that it applies to the contents of the parentheses. – RLH Mar 30 at 16:37
  • Funny thing, I wrote a package to shift the accents of \mathaccentV (the macro amsmath uses internally for \dot, etc.), which doesn't suffer from this issue. I'll try to provide a patch from that. – Skillmon Mar 30 at 18:34
3

This has to do with a long-standing amsmath issue, see Why do arguments to nested \tilde or \breve commands reappear when amsmath is used?

I can offer a workaround.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\dblacc}[2]{\mathpalette\dblacc@{{#1}{#2}}}
\newcommand{\dblacc@}[2]{\dblacc@@#1#2}
\newcommand{\dblacc@@}[3]{%
  \begingroup
  \sbox\z@{$\m@th#1#3$}%
  #2{\box\z@}%
  \endgroup
}
\makeatother

\begin{document}

\begin{gather*}
\dblacc\vec{(\dot{x})}
\\
\dblacc\dot{\begin{bmatrix} x \\ \dot{x} \end{bmatrix}}
\\
\dblacc\vec{(\exp \dot{x})}
\end{gather*}

\end{document}

enter image description here

A version that works also with accents:

\documentclass{article}
\usepackage{amsmath}
\usepackage{accents}

\makeatletter
\newsavebox{\dblacc@boxa}
\newsavebox{\dblacc@boxb}
\DeclareRobustCommand{\dblacc}[2]{\mathpalette\dblacc@{{#1}{#2}}}
\newcommand{\dblacc@}[2]{\dblacc@@#1#2}
\newcommand{\dblacc@@}[3]{%
  \begingroup
  \sbox\dblacc@boxa{$\m@th#1#3$}%
  \sbox\dblacc@boxb{$\m@th#1#2{\copy\dblacc@boxa}$}%
  \box\dblacc@boxb
  \endgroup
}
\makeatother

\begin{document}

\begin{gather*}
\dblacc\vec{(\dot{x})}\quad\scriptscriptstyle\dblacc\vec{(\dot{x})}
\\
\dblacc\dot{\begin{bmatrix} x \\ \dot{x} \end{bmatrix}}
\\
\dblacc\vec{(\exp \dot{x})}
\end{gather*}

\end{document}
  • Thanks very much. If it's not too much trouble, is there a way to make this compatible with the accents package? I'm using the \accentset command in my document for a custom accent, and with the accents package turned on, the arguments to the outer accent all disappear. – RLH Mar 30 at 17:13
  • @RLH \newcommand{\myaccent}[1]{\accentset{<accent>}{#1}} and \dblacc\myaccent{whatever} should work – egreg Mar 30 at 17:51
  • Sorry for the miscommunication: The problem I'm running into is that if I add \usepackage{accents} to the preamble of the example document you posted, only the outer accent character appears -- the rest of the expression is not typeset. – RLH Mar 30 at 18:07
  • @RLH Problem solved. :-D – egreg Mar 30 at 21:33
4

The following redefines an internal of amsmath. After that the output of your example looks good. I don't know whether this has any possibility of breaking other stuff. I've added every test case egreg used in his answer and the output looks good. It doesn't work with the accents package, though.

\documentclass[]{article}

\usepackage[]{amsmath}

\makeatletter
\protected\def\mathaccentV#1#2#3#4#5%
  {%
    \ifmmode
      \mathaccentV@do{#2}{#3}{#4}{#5}%
    \else
      \@xp\nonmatherr@\csname #1\endcsname
    \fi
  }
\def\mathaccentV@do#1#2#3#4%
  {%
    \global\let\macc@nucleus\@empty
    \mathaccent"\accentclass@#1#2#3{#4}\macc@nucleus
  }
\makeatother

\begin{document}
\begin{gather*}
\vec{(\dot{x})}
\\
\dot{\begin{bmatrix} x \\ \dot{x} \end{bmatrix}}
\\
\vec{(\exp \dot{x})}
\end{gather*}
\end{document}

enter image description here

  • Thanks very much. Is there something fundamental about the accents package that breaks solutions of the kind that you and egreg suggested? – RLH Mar 30 at 19:01
  • @RLH accents redefines all those accents macros to no longer use \mathaccentV, so my fix is bound to not work there. I didn't dig too deep into why the accents package fails to do the alignment right, so I can't really state anything else about the issue. – Skillmon Mar 30 at 19:05
  • Thanks again for your help! – RLH Mar 30 at 19:16
  • @RLH note that this patch changes the way \vec{\dot{x}} would be typeset (the arrow is moved slightly to the right which yields imperfect placement, but not severely misplacement). In the original use case of my package where something like this is done, that is not that bad, because the default placement of the accents would be very bad there. – Skillmon Mar 30 at 19:27
  • @RLH if you only use accents for \accentset, you can use the package option single. That way my fix above will still be applied. – Skillmon Mar 30 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.