![使用 \setTransitionsForLatin 后,fontspec 对更改英文字体没有影响](https://linux22.com/image/303409/%E4%BD%BF%E7%94%A8%20%5CsetTransitionsForLatin%20%E5%90%8E%EF%BC%8Cfontspec%20%E5%AF%B9%E6%9B%B4%E6%94%B9%E8%8B%B1%E6%96%87%E5%AD%97%E4%BD%93%E6%B2%A1%E6%9C%89%E5%BD%B1%E5%93%8D.png)
我想用两种语言(高棉语和英语)写一段文字。有时我想更改字体。代码如下:
\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}