34

On LaTeX-Community.org I've noticed a strange problem with nested \tilde and \breve commands, when amsmath is used.

In this code the X appears also in the output of the second and the third formula:

\documentclass{article} \usepackage{amsmath} \begin{document} \[ \breve{\tilde{X}} \] \[ \breve{\breve{{T}}\breve{{v}}} \] \[ \tilde{{\tilde{T}}{\tilde{v}}} \] \end{document} 

enter image description here

If I don't load amsmath, the code works fine. This seems to be a bug in amsmath. How can it be solved?

3
  • 13
    Question 10.000 ;-) Commented Oct 3, 2011 at 10:37
  • 11
    Our ten thousandth question! \o/ Commented Oct 3, 2011 at 10:37
  • Your work-round at latex-community.org/forum/viewtopic.php?f=46&p=56594 can be slightly simplified by making the first equation line \breve{\tilde{X}} \vphantom{\breve{}} Commented Oct 3, 2011 at 11:12

4 Answers 4

31

The problem comes up already with a "more minimal" example:

\documentclass{article} \usepackage{amsmath} \begin{document} $\breve{\breve{a}\breve{b}}$ \end{document} 

which produces

! Undefined control sequence. \macc@adjust ->\dimen@ \macc@kerna \advance \dimen@ \macc@kernb \kern -\dimen@ 

thus showing that the problem is not only in the repetition of the symbol. It happens with all math accents defined in terms of \mathaccentV,

\hat \check \tilde \acute \grave \dot \ddot \bar \vec \mathring 

because these accents work by looking if their argument contains another accented symbol, in order to stack precisely the accents. This requires doing some global definitions, but somehow, if the argument contains two of these accents, the mechanism fails.

The "repeated symbol" is contained in the macro \macc@nucleus: after $\tilde{\breve{X}$, it expands to X and this is why this symbol is repeated (but I've not digged much into the details), since the definition of \macc@nucleus is done via \gdef.

The amsmath documentation doesn't point out that only stacked accents on one symbols should be used and, actually, it's safe to put an accent on a subformula provided it doesn't contain accents.

Solution.

As the macros are quite complex and require global assignments, it seems quite difficult to do surgery on them, so a different approach is easier. Define

\newsavebox{\accentbox} \newcommand{\compositeaccents}[2]{% \sbox\accentbox{$#2$}#1{\usebox\accentbox}} 

Now \breve{\breve{a}\breve{b}} can be changed into

\compositeaccents{\breve}{\breve{a}\breve{b}} 

and all goes well. As one can see, the argument is typeset before applying the "global accent" and stored in a bin, over which we can safely put the "global accent".

Should one need such buildups also in superscripts or subscripts

\newcommand{\compositeaccentsX}[2]{% \let\accenttemp#1\mathpalette\docompositeaccents{#2}} \def\docompositeaccents#1#2{\compositeaccents\accenttemp{#1#2}} 

and $A_{\compositeaccentsX{\breve}{\breve{a}\breve{b}}}$ will work. It's better to stick with the simpler command, as the "extended" one requires to typeset four times the same formula.

Curiously enough, the accents package shows a bug in situations like this one:

\documentclass{article} \usepackage{amsmath,accents} \begin{document} $\breve{\breve{a}\breve{b}}$ \end{document} 

will give no error, but will eat up the "a".

Very nice 10000th question on TeX.SE!

5
  • your first code example is missing a closing brace. Commented Oct 3, 2011 at 11:54
  • 1
    Very good and it works well! I'll leave the question still open, looking for further fixes. Commented Oct 3, 2011 at 12:50
  • 1
    @StefanKottwitz I'm hoping that Javier Bezos is reading. His accents package is awesome and this bug should be addressed. Commented Oct 3, 2011 at 12:53
  • It worked with \widehat too, which i used to denote the Fourier Transform of accentuated symbols. Commented Jul 1, 2021 at 11:12
  • Thank you very much. I am experiencing the same issue in July 2025. Commented Jul 3 at 13:57
18

this is certainly a bug, and has already been reported as such to [email protected]. it has been added to the list for the next overhaul of the amsmath package.

here are two additional small tests that provide useful information:

\documentclass[11pt]{article} \usepackage[]{amsmath} \begin{document} \[ \breve{\breve{T} v} \] \end{document} 

this results in everything being terribly misplaced.

\documentclass[11pt]{article} \usepackage[]{amsmath} \begin{document} \[ \breve{\breve{T} \breve{v}} \] \end{document} 

this crashes with

! Undefined control sequence. \macc@adjust ->\dimen@ \macc@kerna \advance \dimen@ \macc@kernb \kern -\dimen@ l.6 \breve{\breve{T} \breve{v}} 

thanks for the additional diagnosis and suggestions.

7
  • In some way the accent macro should decide whether its argument consists only of one Acc atom and, in this case, do its work as it does now; otherwise it should typeset the argument and then put the accent over it. Commented Oct 3, 2011 at 13:22
  • Is that list accessible for the public? This could prevent such questions, if a bug is already known. Commented Oct 3, 2011 at 13:33
  • @Stefan -- good question. no, it's not. i'll discuss this with my group. however, the form of the list is very "telegraphic", with basically a one- or two-line description and a reference to sometimes quite extensive test files and documentation; it would not be a simple matter to make it easily digestible for someone who doesn't have access to the background material. Commented Oct 3, 2011 at 13:44
  • @barbarabeeton Could you give a brief update on this problem? Seems to be still there. Thank you. Commented Jul 19, 2015 at 7:42
  • @LaRiFaRi -- you've caught me at a bad time. i'm in darmstadt for the tug meeting, and won't be back in the office until august 4. before i left, i was working intermittently on creating a "public" list of the known bugs, but didn't finish; that is high on my to-do list when i return, but it is slow going, with the necessity to analyze hundreds of test files and background discussion to make the bug list intelligible to a user relatively unfamiliar with the internals. it's not forgotten. Commented Jul 19, 2015 at 8:58
6

If you load the accents package (after loading amsmath) with the single option set, you won't get the problems you describe:

\documentclass{article} \usepackage{amsmath} \usepackage[single]{accents} \begin{document} $\breve{\breve{a}\breve{c}}$, $\tilde{\tilde{T}\tilde{v}}$ \end{document} 

enter image description here

Observe that the positioning of the upper (second-storey) accent will be quite poor if the accented glyphs below it have significantly different heights and/or widths (as is the case with the second example above). If they're available, one should use the wide variants of the accent symbols for the upper (second-story) accents, e.g.,

$\widetilde{\tilde{T}\tilde{v}}$ 

Of course, there is (to my knowledge) no "wide" version of the breve accent, so this piece of advice can't be applied for all accents...

Addendum: A caveat to the generality of this solution: I've just discovered that if one uses the accents package for some of the additional accents it provides (such as \ddddot), you can't use these additional accents in the upper position in the examples above as, in that case, the first letter (but, curiously, not its accent) will be gobbled up. I've only tested this with the ddddot accent, to be sure, but this problem may be wider spread. :-(

0
4

Another approach could be resetting \macc@nucleus at a suitable place, such as here:

\documentclass{article} \usepackage{amsmath} \let\amsmathaccentV\mathaccentV \makeatletter \def\mathaccentV#1#2#3#4#5{% \amsmathaccentV{#1}{#2}{#3}{#4}{#5}% \global\let\macc@nucleus\@empty } \makeatother \begin{document} \[ \breve{\tilde{X}} \] \[ \breve{\breve{{T}}\breve{{v}}} \] \[ \tilde{{\tilde{T}}{\tilde{v}}} \] \end{document} 

Which gives:

nested accents

However, there would still be the open problem that the complete accented expression might not have its natural width, which can be seen if we let characters or symbols follow.

Mentioning this on the way of finding a good fix for amsmath.

2
  • 1
    It won't work with the "more minimal" example. Commented Oct 3, 2011 at 13:07
  • @egreg: Yes, I see, the other error regarding \macc@kerna still occurs in that MWE. Just adding a thought which may become a step in fixing. At least it fixes the question. Commented Oct 3, 2011 at 13:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.