When I use ucharclasses with XeLaTeX to automatically change the font for Greek text, I find that it sometimes inserts transitions at the wrong point, within the Greek text. (Note: I am using the GreekExtended option of ucharclasses because my Greek text uses accents and breathing marks of various sorts as is conventional in typesetting ancient Greek.)
In particular, it looks like it works fine if the first character of Greek has an accent or breathing mark on it but not (or not always) otherwise. (This question appears to be related to this one, but I'm not sure how to apply the partial answers given there to my issue.)
Is there some way to fix this?
MWE 1: it works
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[12pt]{article}
\usepackage{fontspec}
\newfontfamily\defaultfont[Mapping=tex-text]{Times}
\newfontfamily\greekfont{Gentium}
\usepackage[Latin, GreekExtended]{ucharclasses}
\setDefaultTransitions{\defaultfont}{}
\setTransitionsForGreek{\greekfont}{}
\begin{document}
Latin text.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
\end{document}
The output is correct, with the Latin in Times and the Greek in Gentium, the fonts I chose to use for each.
MWE 2: does not work when first Greek character is not accented
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[12pt]{article}
\usepackage{fontspec}
\newfontfamily\defaultfont[Mapping=tex-text]{Times}
\newfontfamily\greekfont{Gentium}
\usepackage[Latin, GreekExtended]{ucharclasses}
\setDefaultTransitions{\defaultfont}{}
\setTransitionsForGreek{\greekfont}{}
\begin{document}
Latin text.
μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
\end{document}
This time, with the first word deleted, the fonts are now incorrect: in particular, the first word, μοι, appears in the Times font (which I had set as the default font), even though the rest of the Greek text appears in the Gentium font (which I had set as the Greek font).


GreekExtendedtoGreek. Is that the answer to my question? Do I misunderstand the purpose ofGreekExtended? – Alex Roberts Feb 02 '21 at 12:51\babelprovide[import=el-polyton, onchar=ids fonts]{greek}together with\babelfont[greek]to change the fonts automatically. – Davislor Feb 02 '21 at 14:13