How can I use ucharclasses
with babel
in XeLaTeX while defining the font with \babelfont
? Alternatively, is there a method to achieve automatic locale and font switching in XeLaTeX, rather than LuaLaTeX, without relying on ucharclasses
? I prefer not to replace babel
with polyglossia
, and I've seen this method on Stack Exchange before. Here's a minimal working example of my attempt.
\documentclass{article}
\usepackage{babel}
\usepackage[CJK,Cyrillics,Latin]{ucharclasses}
\babelprovide[import]{chinese}
\babelprovide[import,main]{english}
\babelprovide[import]{french}
\babelprovide[import]{russian}
\babelfont{rm}[
Extension = .otf,
BoldFont = NewCM10-Bold,
ItalicFont = NewCM10-BookItalic,
BoldItalicFont = NewCM10-BoldItalic
]{NewCM10-Book}
\babelfont{sf}[
Extension = .otf,
BoldFont = NewCMSans10-Bold,
ItalicFont = NewCMSans10-BookOblique,
BoldItalicFont = NewCMSans10-BoldOblique
]{NewCMSans10-Book}
\babelfont{tt}[
Extension = .otf,
BoldFont = NewCMMono10-Bold,
ItalicFont = NewCMMono10-BookItalic,
BoldItalicFont = NewCMMono10-BoldOblique
]{NewCMMono10-Book}
\babelfont[chinese]{rm}[
Extension = .otf,
BoldFont = FandolSong-Bold,
ItalicFont = FandolKai-Regular
]{FandolSong-Regular}
\babelfont[chinese]{sf}[
Extension = .otf,
BoldFont = FandolHei-Bold
]{FandolHei-Regular}
\babelfont[chinese]{tt}[
Extension = .otf
]{FandolFang-Regular}
\begin{document}
This is English.
这是中文。
Это русский.
\end{document}
I'd appreciate any insights on how to get ucharclasses
to work with babel
in XeLaTeX, or suggestions for alternative approaches to achieving automatic font and locale switching. Thanks in advance!