使用 \setTransitionsForLatin 后,fontspec 对更改英文字体没有影响

使用 \setTransitionsForLatin 后,fontspec 对更改英文字体没有影响

我想用两种语言(高棉语和英语)写一段文字。有时我想更改字体。代码如下:

\documentclass{article}
\usepackage[no-math]{fontspec}
\setmainfont[Script=Khmer]{Khmer OS}
\setsansfont[Script=Khmer]{Khmer OS}
\setmonofont[Script=Khmer]{Khmer OS}
\usepackage{ucharclasses}
\setTransitionsForLatin{\fontspec{Latin Modern Roman}}{}
\begin{document}
    អត្ថបទជាភាសាខ្មែរ English text {\fontspec{Lucida Calligraphy} English text in Lucida Calligraphy}
\end{document}

它不会改变为卢西达书法正如我所料。出了什么问题?我该如何解决?

答案1

您必须正确设置过渡,并且切勿\fontspec在文档主体中使用。

\documentclass{article}
\usepackage[no-math]{fontspec}
\usepackage{ucharclasses}

\setmainfont{Khmer MN} % the only one I have supporting Khmer
\newfontfamily{\lmodern}{Latin Modern Roman}
\newfontfamily{\lucidacal}{Lucida Calligraphy OT}[Scale=MatchUppercase]

\setTransitionTo{Khmer}{\normalfont}
\setTransitionFrom{Khmer}{\lmodern}

\begin{document}
    អត្ថបទជាភាសាខ្មែរ English {\lucidacal English text in Lucida
      Calligraphy} and again Latin Modern

\end{document}

在此处输入图片描述

高棉语的翻译不太好,但我对该语言一无所知。

可以进行更复杂的设置;这是一个例子。

\documentclass{article}
\usepackage[no-math]{fontspec}
\usepackage{ucharclasses}
\usepackage{etoolbox}

\setmainfont{Khmer Sangam MN}
\newfontfamily{\khmeraltfam}{Code2000}[Script=Khmer]
\newfontfamily{\lmodernfam}{Latin Modern Roman}
\newfontfamily{\lucidacalfam}{Lucida Calligraphy OT}[Scale=MatchUppercase]

\newrobustcmd{\lmodern}{\lmodernfam\let\currentenglish\lmodernfam}
\newrobustcmd{\lucidacal}{\lucidacalfam\let\currentenglish \lucidacalfam}
\newrobustcmd{\khmernormal}{\normalfont\let\currentkhmer\normalfont}
\newrobustcmd{\khmeralt}{\khmeraltfam\let\currentkhmer\khmeraltfam}

\lmodern \khmernormal % initialize

\setTransitionTo{Khmer}{\currentkhmer}
\setTransitionFrom{Khmer}{\currentenglish}

\begin{document}
អត្ថបទជាភាសាខ្មែរ English {\lucidacal English text in Lucida
អត្ថបទជាភាសាខ្មែរ
Calligraphy} and again Latin Modern

{\khmeralt អត្ថបទជាភាសាខ្មែរ}

\end{document}

在此处输入图片描述

答案2

Bokor 的 MWE

为了完整性,使用不同的字体来说明:

手动字体切换按预期工作;自动字体切换按预期工作;手动和自动字体切换一起也按预期工作:当遇到高棉字符时,字体切换到自动字体。这发生在处理手动字体命令后。手动将自动字体 ( currentkhmer) 设置为 Bokor。用括号括起来以保持局部效果。

设置自动字体示例

\documentclass[12pt]{article}
\usepackage[no-math]{fontspec}
\usepackage{ucharclasses}
\usepackage{etoolbox}
\usepackage{xcolor}

\setmainfont[Script=Khmer]{AKbalthom KhmerHand}
\newfontfamily{\khmeraltfam}{Angkor Sovann Preah Vihear}[Script=Khmer]
\newfontfamily{\lmodernfam}{Noto Serif}
\newfontfamily{\lucidacalfam}{Lucida Calligraphy}[Scale=MatchUppercase]
\newfontfamily\bokor{Bokor}

\newrobustcmd{\lmodern}{\lmodernfam\let\currentenglish\lmodernfam}
\newrobustcmd{\lucidacal}{\lucidacalfam\let\currentenglish \lucidacalfam}
\newrobustcmd{\khmernormal}{\normalfont\let\currentkhmer\normalfont}
\newrobustcmd{\khmeralt}{\khmeraltfam\let\currentkhmer\khmeraltfam}

\lmodern \khmernormal % initialize

\setTransitionTo{Khmer}{\currentkhmer}
\setTransitionFrom{Khmer}{\currentenglish}

\begin{document}
\large
អត្ថបទជាភាសាខ្មែរ English {\lucidacal English text in Lucida
អត្ថបទជាភាសាខ្មែរ
Calligraphy} and again Latin Modern

khmeralt font (in braces) {\khmeralt អត្ថបទជាភាសាខ្មែរ} -- resets currentkhmer

main text (AKbalthom KhmerHand font)  អត្ថបទជាភាសាខ្មែរ

\textbackslash bokor switch \bokor អត្ថបទជាភាសាខ្មែរ --  no effect

bokor in braces: {\bokor អត្ថបទជាភាសាខ្មែរ} -- no effect

{
\let\currentkhmer\bokor
bokor assigned to currentkhmer អត្ថបទជាភាសាខ្មែរ -- works!
}

main text again   អត្ថបទជាភាសាខ្មែរ

red អត្ថបទជា{\color{red}ភាសា}ខ្មែរ more text

\end{document}

相关内容