如何在 ucharclases 中对同一个 unicode 块使用不同的字体系列?

如何在 ucharclases 中对同一个 unicode 块使用不同的字体系列?

以下是 MWE:

\documentclass{article}
\usepackage{fontspec}
\usepackage[Sinhala,Latin]{ucharclasses}

\newfontfamily\FooBarr{Noto Sans}
\newfontfamily\sinhala{Noto Sans Sinhala}
\newfontfamily\sinhalaa{Noto Serif Sinhala}
\setDefaultTransitions{\FooBarr}{}
\setTransitionTo{Sinhala}{\sinhalaa}

\begin{document}
ananother word {\sinhala මගේ වායුපායානයේ} {\sinhalaa ආඳන් පිරී ඇත.}
\end{document}

对于同一个unicode块,是否有一种优雅的方法可以从一种字体系列更改为另一种字体系列?

答案1

我可以为您提供“家庭感知”的切换命令。

\documentclass{article}
\usepackage{fontspec}
\usepackage[Sinhala,Latin]{ucharclasses}

\setmainfont{Noto Serif}[NFSSFamily=standardserif]
\setsansfont{Noto Sans}[NFSSFamily=standardsans]

\newfontfamily\sinhalaserif{Noto Serif Sinhala}[
  NFSSFamily=sinhalaserif,
]
\newfontfamily\sinhalasans{Noto Sans Sinhala}[
  NFSSFamily=sinhalasans,
]

\setDefaultTransitions{\switchto{standard}}{}
\setTransitionTo{Sinhala}{\switchto{sinhala}}

\ExplSyntaxOn
\NewDocumentCommand{\switchto}{m}
 {
  \str_case_e:vnF {f@family}
   {
    { standardsans } { \fontfamily{#1sans}\selectfont }
    { sinhalasans } { \fontfamily{#1sans}\selectfont }
   }
   { \fontfamily{#1serif}\selectfont }
 }
\cs_generate_variant:Nn \str_case_e:nnF { v }
\ExplSyntaxOff

\begin{document}

a word මගේ වායුපායානයේ

\textsf{a word  ආඳන් පිරී ඇත.}

\end{document}

在此处输入图片描述

答案2

这是另一种方法,它利用了xeCJK可以处理 CJK 以外的其他语言:

% !TeX program = XeLaTeX
\documentclass{article}
\usepackage[no-math]{xeCJK}% loads fontspec
\xeCJKDeclareCharClass{HangulJamo}{"200D,"0D80 -> "0DFF}
% https://en.wikipedia.org/wiki/Sinhala_(Unicode_block)+ZWJ
% https://en.wikipedia.org/wiki/Zero-width_joiner
% The HangulJamo class has the property that no additional code is inserted
% between characters within this class.
\xeCJKsetup{CJKspace=true}
% Keep spaces between characters.
\xeCJKDeclareCharClass{HalfLeft}{"2018, "201C}
\xeCJKDeclareCharClass{HalfRight}{%
  "00B7, "2019, "201D, "2013, "2014, "2025, "2026, "2027, "2E3A}
% In Unicode, some Latin and CJK punctuation marks share the same code points.
% We make sure that these punctuation marks are the Latin ones.

\setmainfont{NotoSerif-Regular.ttf}
\setsansfont{NotoSans-Regular.ttf}
\setCJKmainfont{NotoSerifSinhala-Regular.ttf}
\setCJKsansfont{NotoSansSinhala-Regular.ttf}

\newcommand\test{%
  My hovercraft is full of eels.\par % ;-)
  මාගේ වායු පා යානයේ ආඳන් පිරී ඇත.\par
}
\begin{document}
\test
\medskip
{\sffamily
\test}
\end{document}

例子

缺点?嗯,的文档xeCJK只有中文版……

答案3

这不完全是ucharclasses,但babel支持带有字体系列的僧伽罗语。它需要一些标记,但你似乎\sinhala无论如何都在使用命令。继续使用 XeLaTeX(它可能也适用于 HarfTeX。)

\documentclass{article}
% To fit within a TeX.SX MWE:
\usepackage[paperwidth=10cm]{geometry}

\usepackage[english]{babel}
\usepackage{fontspec}

\babelprovide[import]{Sinhala}

\defaultfontfeatures{Scale=MatchLowercase}

\babelfont{rm}[Scale=1.0]{Noto Serif}
\babelfont{sf}{Noto Sans}
\babelfont[Sinhala]{rm}{Noto Serif Sinhala}
\babelfont[Sinhala]{sf}{Noto Sans Sinhala}

\begin{document}

A word.

\foreignlanguage{Sinhala}{මගේ වායුපායානයේ}

\sffamily

Another word.

\foreignlanguage{Sinhala}{ආඳන් පිරී ඇත.}

\end{document}

诺托僧伽罗语样本

您会收到一些关于字体不包含语言“英语”的无害警告。如果您愿意,可以通过用 替换[english]包选项来抑制它们\babelprovide[import, main, language=Default]{english},但请注意,包维护者不建议这样做。

相关内容