Engine problem? Creating dynamic diacritics using the Brill typeface

The XeTeX behavior is a combination of HarfBuzz “features” and font limitations.

Unicode has something called canonical equivalence. When a certain code point sequence is said to be canonically equivalent with another one, Unicode specify that both sequences should be rendered the same.

One example of this is (U+1E0D LATIN SMALL LETTER D WITH DOT BELOW) which is canonically equivalent with d + U+0323 COMBINING DOT BELOW. The first is called the composed form, and the later is called the decomposed form, and Unicode has normalization standards that map from one form to the other (NFC for the composed form, and NFD for the decomposed one).

HarfBuzz always prefers the composed form when supported by the font, so d + U+0323 COMBINING DOT BELOW is turned into ḍ if the font supports it.

Another part of Unicode canonical equivalence is the canonical ordering, which specifies how combining marks should be ordered no matter what the input order is. Again HarfBuzz applies the canonical ordering of the marks.

The combination of both cause 1) the order of the the marks in your input is not the same as what HarfBuzz will actually use 2) some base glyph + mark sequences are replaced with the composed form (e.g. the first d in your example ends up as + the other marks). In an ideal world this shouldn’t be an issue, but with Brill font the glyph does not have the same anchors for positioning combining marks as the d glyph which results in mark displacement. This is a font bug since it does not handle canonically equivalent sequences of code points the same way.

A work around for this is to insert U+200C ZERO WIDTH NON-JOINER character to prevent the problematic compositions or reordering:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Brill}
\ExplSyntaxOn
\NewDocumentCommand \dynamicdiacritics { }
  {
    Results ~ from ~
    \sys_if_engine_luatex:T { LuaLaTeX: ~ }
    \sys_if_engine_xetex:T  { XeLaTeX: ~ }
    d\char"200C\char"030C\char"0304\char"200C\char"0323\char"0326
    y\char"030D\char"0311\char"0310\char"0302\char"0301\char"0353\char"0347
    n\char"0306\char"0308\char"1DD8\char"0304\char"0307\char"200C\char"032D\char"0332\char"032B\char"0323
    a\char"0363\char"0306\char"0309\char"0324\char"0330\char"032A
  }
\ExplSyntaxOff
\begin{document}
\dynamicdiacritics
\end{document}

XeLaTeX output

You can even just insert it before any combining mark, it won’t hurt:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Brill}
\ExplSyntaxOn
\NewDocumentCommand \dynamicdiacritics { }
  {
    Results ~ from ~
    \sys_if_engine_luatex:T { LuaLaTeX: ~ }
    \sys_if_engine_xetex:T  { XeLaTeX: ~ }
    d\char"200C\char"030C\char"200C\char"0304\char"200C\char"0323\char"200C\char"0326
    y\char"200C\char"030D\char"200C\char"0311\char"200C\char"0310\char"200C\char"0302\char"200C\char"0301\char"200C\char"0353\char"200C\char"0347
    n\char"200C\char"0306\char"200C\char"0308\char"200C\char"1DD8\char"200C\char"0304\char"200C\char"0307\char"200C\char"032D\char"200C\char"0332\char"200C\char"032B\char"200C\char"0323
    a\char"200C\char"0363\char"200C\char"0306\char"200C\char"0309\char"200C\char"0324\char"200C\char"0330\char"200C\char"032A
  }
\ExplSyntaxOff
\begin{document}
\dynamicdiacritics
\end{document}

enter image description here


I don’t have the patience to type more than the first letter, but here’s the principle: enter the letter first, then the diacriticals above it, starting with the one closest to the letter and working out, and after that the diacriticals below it, again starting from the closest and working out.

Here I’ve done it entering the combining diacriticals directly (in Emacs, using C-x 8), and again using \char:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Brill}
\begin{document}
ḍ̦̌̄ \textit{or} d\char"030C\char"0304\char"0323\char"0326% no spaces, or the diacritics will appear after the character
\end{document}

output