是否可以将文档中当前字体的单个文本字母替换为系统中可用的另一种字体。当前字体的其余字符应保留。这可行吗?
我知道我可以使用 unicode-math 和 \setmathfont[range={}] 对数学进行此操作,但对于 fontspec 则无法执行此操作。
假设我的文档字体是 Computer Modern Roman。我希望只有 f 自动转换为 BaskervilleF(或我系统上可用的任何其他字体)的对应 f。这适用于小写和大写 f 和 F,粗体和斜体。基本上,只有一个字母应该被另一种字体的对应字母替换
答案1
您可以放入f
其自己的角色类别:
\documentclass{article}
\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\fclass
\XeTeXcharclass `\f \fclass
\XeTeXinterchartoks 0 \fclass = {\myf}
\XeTeXinterchartoks 4095 \fclass = {\myf}
\XeTeXinterchartoks \fclass \fclass = {\myf}
\newcommand\myf[1]{\textsf{\large \fbox{F}}}
\begin{document}
One two three four five safe iff difficult.
\end{document}
问题编辑后,f 和 F 以及检查当前字体系列。
\documentclass{article}
\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\fclass
\XeTeXcharclass `\f \fclass
\XeTeXcharclass `\F \fclass
\XeTeXinterchartoks 0 \fclass = {\myf}
\XeTeXinterchartoks 4095 \fclass = {\myf}
\XeTeXinterchartoks \fclass \fclass = {\myf}
\def\ffamily{lmr}
\makeatletter
\newcommand\myf[1]{{\XeTeXinterchartokenstate=0
\ifx\f@family\ffamily\sffamily\large\fi % only switch if currently lmr
#1}}
\makeatother
\begin{document}
Roman lmr
One two three Four Five safe iff difficult.
\textbf{One two three four five safe iff difficult.}
Italic lmr \textit{One two three Four Five safe iff difficult.
\textbf{One two three four five safe iff difficult.}}
tt not affected \texttt{One two three Four Five safe iff difficult.}
\end{document}