# Macron accent above some Cyrillic letters is shifted

Consider the following MWE:

\documentclass{scrartcl}

\usepackage{polyglossia}
\usepackage{fontspec}

\setdefaultlanguage{russian}

\setmainfont{EB Garamond}
\newfontfamily\cyrillicfont{EB Garamond}

\KOMAoptions{fontsize = 14}

\begin{document}

ш\={ю}кан

\end{document}


It's supposed to produce a macron accent above ю, but you can see below that the bar is above the space between ю and к.

# Update

Solution

\DeclareTextCompositeCommand{\=}{TU}{ю}{\accent"0304 ю}


doesn't work very well. It creates a strange conflict between tabular, luatexja and xcolor. Consider the following MWE:

\documentclass{scrartcl}

\usepackage{polyglossia}
\usepackage[table]{xcolor}
\usepackage{luatexja}
\usepackage{luatexja-fontspec}
\usepackage[haranoaji]{luatexja-preset}

\ltjsetparameter{jacharrange = {-2, -3}}

\setotherlanguages{english, russian}
\setmainfont{EB Garamond}
\newfontfamily\cyrillicfont{EB Garamond}
\DeclareTextCompositeCommand{\=}{TU}{ю}{\accent"0304 ю}

\begin{document}

\begin{tabular}{p{0.5\linewidth} l}
習慣&ш\=юкан\\
\end{tabular}

\end{document}


It produces the following error:

luatexja/ltj-jfmglue.lua:647: attempt to perform arithmetic on a nil value (local 'c')


Removing either of the following makes it compile:

• \= from ш\=юкан
• \DeclareTextCompositeCommand{\=}{TU}{ю}{\accent"0304 ю}
• table from \usepackage[table]{xcolor}

# Update 2

I consider the conflict with luatexja a bug in luatexja. I hope they will fix it. Cyrillic is irrelevant for this conflict. luatexja just doesn't like \accent

# Update 3

Here is a workaround that silences luatexja:

\DeclareTextCompositeCommand{\=}{TU}{Ю}{\hspace*{0pt}\accent"0304 Ю}
\DeclareTextCompositeCommand{\=}{TU}{ю}{\hspace*{0pt}\accent"0304 ю}


# Update 4

luatexja developers are amazing. They fixed the bug within an hour after I filed it.

• Possibly \hspace*{0pt} or you could have line breaks in front of the accented characters. Feb 11 at 10:06
• @egreg Thanks! Updated. Feb 11 at 10:43

OpenType fonts require very patient work for supporting combining characters, that's a fact, and similar problems are, unfortunately, common.

Apparently, the font developer here forgot to add proper anchor points for combining characters in some slots of the font.

Also я Е О Э Ю Я suffer from the same problem. However, this can be cured by using the legacy method for accents.

\documentclass{scrartcl}

\usepackage{polyglossia}
\usepackage{fontspec}

\setdefaultlanguage{russian}

\setmainfont{EB Garamond}
\newfontfamily\cyrillicfont{EB Garamond}

\DeclareTextCompositeCommand{\=}{TU}{ю}{\accent"0304 ю}
\DeclareTextCompositeCommand{\=}{TU}{я}{\accent"0304 я}
\DeclareTextCompositeCommand{\=}{TU}{Е}{\accent"0304 Е}
\DeclareTextCompositeCommand{\=}{TU}{О}{\accent"0304 О}
\DeclareTextCompositeCommand{\=}{TU}{Э}{\accent"0304 Э}
\DeclareTextCompositeCommand{\=}{TU}{Ю}{\accent"0304 Ю}
\DeclareTextCompositeCommand{\=}{TU}{Я}{\accent"0304 Я}

\KOMAoptions{fontsize = 14}

\begin{document}

ш\={ю}кан

\=а\=е\=и\=о\=у\=э\=ю\=я

\=A\=Е\=И\=О\=У\=Э\=Ю\=Я

\end{document}


For the record, here's the output with the seven \DeclareTextCompositeCommand lines omitted.

• I wonder how to get attention of EB Garamond developer? Feb 2 at 13:38
• Feb 2 at 14:25
• It doesn't seem there is any activity recently in fixing issues on GitHub. Feb 3 at 4:49
• DeclareTextCompositeCommand conflicts with a combination of tabular, xcolor and luatexja. See the updated question. Feb 11 at 7:20
• @facetus No specific reason, actually Feb 11 at 20:17

To answer your follow-up question, you can use babel to get automatic language detection, rather than luatexja. It doesn’t necessarily support every luatexja and polyglossia feature you might be using, but it should work for you, and it fixes this bug.

\documentclass{scrartcl}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage{unicode-math}

\babelprovide[import, onchar=ids fonts]{japanese}
\babelprovide[import, main, onchar=ids fonts]{russian}

\defaultfontfeatures[HaranoAjiMincho]{
Renderer=HarfBuzz,
Scale=MatchUppercase
}

\babelfont{rm}{EBGaramond}
\babelfont[japanese]{rm}{HaranoAjiMincho}
\setmathfont{Garamond Math}

\DeclareTextCompositeCommand{\=}{TU}{ю}{\accent"0304 ю}

\begin{document}

\begin{tabular}{p{2cm} l}
習慣&ш\=юкан\\
\end{tabular}

\end{document}


• Thanks. I think it's always possible to get rid of a problem by reducing the functionality. We have a joke in Russia: the best remedy for a headache is the guillotine. But wouldn't it be wonderful to have everything? Feb 11 at 19:44
• @facetus There probably is a babel equivalent for whatever it is you wanted to do with the other packages, though. Feb 11 at 20:00
• Like tate text direction for Japanese? babel "does not care about any Japanese typesetting requirements". Source: ctan.math.illinois.edu/macros/latex/contrib/babel-contrib/… Feb 11 at 20:05
• @facetus There technically is support for rotated glyphs for vertical writing in fontspec, but only in XeLaTeX and only if you place them in a rotatebox yourself. So, in practical terms, good example, that’s unsupported. Feb 11 at 20:07
• @facetus Oh, sorry, I didn’t think we were arguing. Like I said in my answer originally, babel does not support all the features of lualatexja, and again, vertical writing was a good example. Feb 13 at 4:28