通过 NFSS 调用 (luatex-)combo 字体

通过 NFSS 调用 (luatex-)combo 字体

经过一番努力,我找到了一种调用组合字体(结合两种字体的字形)的方法,这样我就可以得到各种字体大小。

有谁知道如何注入此代码(或具有类似行为的其他代码)以便\DeclareFontShape可以通过 NFSS 调用字体?

\documentclass[parskip=half-]{scrartcl}
\usepackage{fontspec,xfp}

\newcommand\requestmycombofont[1]{%
\ifcsname mycombofont.#1\endcsname 
\else
  \font \one = {file:lmmono10-regular.otf}  at \fpeval{#1*10}pt
  \font \two = {file:lmsans10-regular.otf}  at \fpeval{#1*15}pt
  \expandafter\font \csname mycombofont.#1\endcsname
                 = "combo: 1 -> \fontid \one            ;
                           2 -> \fontid \two , 0x41-0x5A;"%
\fi                           
\csname mycombofont.#1\endcsname                    
}

\DeclareFontFamily{TU}{xxx}{}

%\DeclareFontShape{TU}{xxx}{m}{n}{<-> how to call the combo font here ??????? }{}
% simply defining \csname TU/xxx/m/n\endcsname is not enough ...


\begin{document}
\section{Direct call}
{
\requestmycombofont{1.1}%
Some Text with Capital Words

\requestmycombofont{1.3}%
Some Text with Capital Words

\requestmycombofont{0.5}%
Some Text with Capital Words

}

\section{Call through nfss?}
\normalsize
\fontfamily{xxx}\selectfont
% should do \makeatletter \requestmycombofont{\fpeval{\f@size/10}}
Some Text with Capital Words

\large
% should do \requestmycombofont{\fpeval{\f@size/10}}
Some Text with Capital Words
\end{document}

在此处输入图片描述

答案1

David Carlisle 给我提供了使用大小函数注入必要代码的建议\DeclareFontShape,因此我编写了一个小型的(非常实验性的)包combofonthttp://www.ctan.org/pkg/combofont

使用它,字体可以像这样声明:

\RequirePackage{luatex85}
\documentclass[parskip=half-]{scrartcl}
\usepackage{combofont}

\setupcombofont{combotest-regular}
 {
  {file:lmmono10-regular.otf:\combodefaultfeat} at #1pt,
  {file:lmsans10-regular.otf} at \fpeval{#1/10*15}pt
 }
 {
   {} ,
   0x41-0x5A*0x21*0x3F
 }


\DeclareFontFamily{TU}{combotest}{}
\DeclareFontShape{TU} {combotest}{m}{n}{<->combo*combotest-regular}{}
\begin{document}

\fontfamily{combotest}\selectfont
A Text with Some Capitals!

\large
A Text with Some Capitals!

\scriptsize
A Text with Some Capitals!

\end{document}

在此处输入图片描述

相关内容