Lower diacritics sometimes centering as opposed to upper diacritics

It seems there are some inconsistencies in how upper diacritics (\", \u, etc.) behave as opposed to lower diacritics (\c, \k, etc.). Upper diacritics are placed on

• the first character (or \i/\j) of the argument, unless
• the argument starts with {} or a command (\c c), then it places on a space inserted before the first part

Lower diacritics, on the other hand, are placed

• the first character of the argument, unless
• the argument starts with {} or a command or the argument is not completely a-z, then it centers on the whole argument

Below is some sample TeX (output from Overleaf with pdfLaTeX) to demonstrate this:

\begin{enumerate}
\item \u{A}
\item \u{\i}
\item \u{\c A}
\item \c{aa}
\item \c{aA}
\item \c{AA}
\item \c{11}
\item \c{\u A}
\end{enumerate}


Are these differences documented somewhere, or otherwise explained? I am trying to convert such diacritics to Unicode (which does not seem possible for the centered cedillas, at least) for a BibTeX parser.

• Welcome to tex.sx. – barbara beeton Mar 14 '20 at 20:37
• You can't apply two accents to letters (at least not in that way); definitely you can't apply them to complex constructs such as \copyright. – egreg Mar 14 '20 at 20:58
• Where's a cedilla centered between two characters used? – egreg Mar 14 '20 at 21:07
• @egreg I don't know where that would be used, I'm just wondering what the rules are so I can implement them. I guess this would be "undefined behavior" then? – LarsW Mar 14 '20 at 21:17
• Probably the best behavior copy for a LaTeX to Unicode converter is the behavior in tuenc.def which is used in XeLaTeX and LuaLaTeX: \c{...} (or similar) is converted to ... followed by the combining character corresponding to \c, except if ... is empty, then the combining char is set on top of a space. – Marcel Krüger Mar 18 '20 at 22:40

The differences are due to the fact that TeX can only really set upper diacritics. The mechanism is described in the TeXbook, p. 54.

Every character from the font can be used as an accent using the \accent primitive. For example, \accent19 a sets the character in slot 19 (for Computer Modern fonts, this is the acute accent) on the letter a, yielding á. The command \' is defined in plain.tex as

\def\'#1{{\accent19 #1}}


When a character from the font is used as an accent, TeX assumes that it was designed for a character with the height of 1ex of the respective font; if the character is taller or shorter, the accent is shifted up or down to account for the difference. This is why this mechanism fails for lower diacritics: The character c in Computer Modern is 1ex high and indeed, \accent24 c produces an appropriate cedilla on the c. Character d, however, is taller, so TeX shifts the accent up and \accent24 d gives a d with a raised cedilla. Therefore, these lower diacritics are implemented in a much different way:

\def\c#1{{\setbox\z@\hbox{#1}\ifdim\ht\z@=1ex\accent24 #1%
\else\ooalign{\unhbox\z@\crcr\hidewidth\char24\hidewidth}\fi}}


If the character to be accented is 1ex high, it is set directly like an upper diacritic with \accent24 #1, but otherwise, the accent is set separately and aligned with the following character.

Now the crucial point is that following an \accent.. command, TeX is looking for a character to be accented. Only mode-independent commands such as assignments (especially font changes if you want the accent and the character to come from different fonts) are allowed to occur between the two, but no grouping operations or boxes. Therefore,

\'{\hbox{a}}    \'{{a}}    \'{{}a}


will all prevent TeX from finding the a before concluding that no suitable character has followed the \accent, and in such a situation TeX resorts to setting the accent as if it was a normal character and then proceeding to typeset the rest. This is the same for \copyright which isn't a simple character but composed of a circle and a c, with a definition containing boxes. Since \c usually just aligns its input with the cedilla, it operates on boxes and doesn't have the same problem. However, if that box is 1ex high, it will still fail because then it will use accent24 directly. Therefore,

\c{\hbox{c}}


sets the cedilla before the c, but

\c{\hbox{d}}


gets the d accented correctly.

So to summarize, here is what behavior you have to expect from using an accent command. It depends actually does not depend on whether you are using an upper or lower diacritic, but whether your expression will expand to \accent.. #1 or whether accent and accentee will be aligned in another way:

• If the \accent primitive is applied to the argument, it accents the first character it finds, but nothing that involves braces may intervene. In the latter case, the accent is put in front of the character.
• If they will be aligned differently, it depends on the exact implementation, but in the case of \c, it will center the accent below the argument.

Upper diacritics are placed on

• the first character (or \i/\j) of the argument, unless

true if the upper diacritic expands to an expression like \accent.. #1

• the argument starts with {} or a command (\c c), then it places on a space inserted before the first part

or in general, if the argument involves anything more than assignments; also it technically isn't placed on a space that is inserted, but the glyph from the font is inserted directly

Lower diacritics, on the other hand, are placed

• the first character of the argument, unless
• the argument starts with {} or a command or the argument is not completely a-z, then it centers on the whole argument

depends on the implementation, but if it is not set with \accent.. #1 directly, it is typically centered on the whole argument. The claim that it is not centered for arguments consisting entirely of a-z is an illusion: This only applies if all characters are 1ex high, because then we are in the \accent24 #1 case of the definition of \c and TeX will be happy to have found a suitable character to apply this to. If you try \c{ad}, you'll see that the cedilla is put in the middle again, as the box is now higher than 1ex.