我在这里找到了适用于印度语的新可变字体系列https://github.com/EkType/Anek/。我想用它来处理 LaTeX 中的梵文文本。一般我使用马拉地语包使用天城文文本。MWE 如下:
\documentclass{article}
\usepackage{marathi}
\टंक{Anek} # This command is used to change default font i.e. Shobhika
\begin{document}
मराठी मजकूर
\end{document}
但是它不适用于此可变字体。有没有手册指导如何在 Latex 中使用可变字体?
答案1
仅用于说明,展示可能的情况:
沿权重轴输出(理论上从1-1000):
沿宽度轴(百分比,通常为 75%-125%,字体设计者已定义):
(请注意,当前字体版本 1.002 中的म在宽度 < 100% 和宽度 > 100% 处存在错误。)
沿两个轴同时:
平均能量损失
*仅供参考。实际用例将使用一个\newfontfamily
加上相关\textXX
命令,可能只涉及三个或四个轴设置,而不是 64 个以上的\newfontface
命令(此处,多面方法用作快速 5 分钟代码复制粘贴的一部分)。
\documentclass[12pt]{article}
\newcommand\myfontpath{C:/Users/...really long path name .../}
\newcommand\test{मराठी मजकूर}
\newcommand\testb{मराठी}
\newcommand\fsetting{Path=\myfontpath,
Extension=.ttf,
Colour=blue,
UprightFont=*,
}
\newcommand\fname{AnekDevanagari[wdth,wght]}
\usepackage{xcolor}
\usepackage{fontspec}
\defaultfontfeatures{RawFeature={+axis={wght=400,wdth=100}}}
\setmainfont[
Path=\myfontpath,
Extension=.ttf,
UprightFont=*,
]{AnekDevanagari[wdth,wght]}
\newfontface\AnekBoldc[
Path=\myfontpath,
Extension=.ttf,
Colour=blue,
UprightFont=*,
UprightFeatures={RawFeature={+axis={wght=200,wdth=180}}},
BoldFont=*,
BoldFeatures={RawFeature={+axis={wght=900,wdth=125}}},
]{AnekDevanagari[wdth,wght]}
\newfontface\AnekBoldb[
Path=\myfontpath,
Extension=.ttf,
UprightFont=*,
BoldFont=*,
BoldFeatures={RawFeature={+axis={wght=700}}},
]{AnekDevanagari[wdth,wght]}
%---
\newfontface\AnekDga[\fsetting
UprightFeatures={RawFeature={+axis={wght=100}}},]{\fname}
\newfontface\AnekDgb[\fsetting
UprightFeatures={RawFeature={+axis={wght=200}}},]{\fname}
\newfontface\AnekDgc[\fsetting
UprightFeatures={RawFeature={+axis={wght=300}}},]{\fname}
\newfontface\AnekDgd[\fsetting
UprightFeatures={RawFeature={+axis={wght=400}}},]{\fname}
\newfontface\AnekDge[\fsetting
UprightFeatures={RawFeature={+axis={wght=500}}},]{\fname}
\newfontface\AnekDgf[\fsetting
UprightFeatures={RawFeature={+axis={wght=600}}},]{\fname}
\newfontface\AnekDgg[\fsetting
UprightFeatures={RawFeature={+axis={wght=700}}},]{\fname}
\newfontface\AnekDgh[\fsetting
UprightFeatures={RawFeature={+axis={wght=800}}},]{\fname}
%---
\newfontface\AnekDda[\fsetting
UprightFeatures={RawFeature={+axis={wdth=75}}},]{\fname}
\newfontface\AnekDdb[\fsetting
UprightFeatures={RawFeature={+axis={wdth=80}}},]{\fname}
\newfontface\AnekDdc[\fsetting
UprightFeatures={RawFeature={+axis={wdth=90}}},]{\fname}
\newfontface\AnekDdd[\fsetting
UprightFeatures={RawFeature={+axis={wdth=100}}},]{\fname}
\newfontface\AnekDde[\fsetting
UprightFeatures={RawFeature={+axis={wdth=110}}},]{\fname}
\newfontface\AnekDdf[\fsetting
UprightFeatures={RawFeature={+axis={wdth=115}}},]{\fname}
\newfontface\AnekDdg[\fsetting
UprightFeatures={RawFeature={+axis={wdth=120}}},]{\fname}
\newfontface\AnekDdh[\fsetting
UprightFeatures={RawFeature={+axis={wdth=125}}},]{\fname}
%--- Grid
\newfontface\AnekDgdaa[\fsetting UprightFeatures={RawFeature={+axis={wght=100,wdth=75}}},]{\fname} \newfontface\AnekDgdab[\fsetting UprightFeatures={RawFeature={+axis={wght=100,wdth=80}}},]{\fname} \newfontface\AnekDgdac[\fsetting UprightFeatures={RawFeature={+axis={wght=100,wdth=90}}},]{\fname} \newfontface\AnekDgdad[\fsetting UprightFeatures={RawFeature={+axis={wght=100,wdth=100}}},]{\fname} \newfontface\AnekDgdae[\fsetting UprightFeatures={RawFeature={+axis={wght=100,wdth=110}}},]{\fname} \newfontface\AnekDgdaf[\fsetting UprightFeatures={RawFeature={+axis={wght=100,wdth=115}}},]{\fname} \newfontface\AnekDgdag[\fsetting UprightFeatures={RawFeature={+axis={wght=100,wdth=120}}},]{\fname} \newfontface\AnekDgdah[\fsetting UprightFeatures={RawFeature={+axis={wght=100,wdth=125}}},]{\fname}
\newfontface\AnekDgdba[\fsetting UprightFeatures={RawFeature={+axis={wght=200,wdth=75}}},]{\fname} \newfontface\AnekDgdbb[\fsetting UprightFeatures={RawFeature={+axis={wght=200,wdth=80}}},]{\fname} \newfontface\AnekDgdbc[\fsetting UprightFeatures={RawFeature={+axis={wght=200,wdth=90}}},]{\fname} \newfontface\AnekDgdbd[\fsetting UprightFeatures={RawFeature={+axis={wght=200,wdth=100}}},]{\fname} \newfontface\AnekDgdbe[\fsetting UprightFeatures={RawFeature={+axis={wght=200,wdth=110}}},]{\fname} \newfontface\AnekDgdbf[\fsetting UprightFeatures={RawFeature={+axis={wght=200,wdth=115}}},]{\fname} \newfontface\AnekDgdbg[\fsetting UprightFeatures={RawFeature={+axis={wght=200,wdth=120}}},]{\fname} \newfontface\AnekDgdbh[\fsetting UprightFeatures={RawFeature={+axis={wght=200,wdth=125}}},]{\fname}
\newfontface\AnekDgdca[\fsetting UprightFeatures={RawFeature={+axis={wght=300,wdth=75}}},]{\fname} \newfontface\AnekDgdcb[\fsetting UprightFeatures={RawFeature={+axis={wght=300,wdth=80}}},]{\fname} \newfontface\AnekDgdcc[\fsetting UprightFeatures={RawFeature={+axis={wght=300,wdth=90}}},]{\fname} \newfontface\AnekDgdcd[\fsetting UprightFeatures={RawFeature={+axis={wght=300,wdth=100}}},]{\fname} \newfontface\AnekDgdce[\fsetting UprightFeatures={RawFeature={+axis={wght=300,wdth=110}}},]{\fname} \newfontface\AnekDgdcf[\fsetting UprightFeatures={RawFeature={+axis={wght=300,wdth=115}}},]{\fname} \newfontface\AnekDgdcg[\fsetting UprightFeatures={RawFeature={+axis={wght=300,wdth=120}}},]{\fname} \newfontface\AnekDgdch[\fsetting UprightFeatures={RawFeature={+axis={wght=300,wdth=125}}},]{\fname}
\newfontface\AnekDgdda[\fsetting UprightFeatures={RawFeature={+axis={wght=400,wdth=75}}},]{\fname} \newfontface\AnekDgddb[\fsetting UprightFeatures={RawFeature={+axis={wght=400,wdth=80}}},]{\fname} \newfontface\AnekDgddc[\fsetting UprightFeatures={RawFeature={+axis={wght=400,wdth=90}}},]{\fname} \newfontface\AnekDgddd[\fsetting UprightFeatures={RawFeature={+axis={wght=400,wdth=100}}},]{\fname} \newfontface\AnekDgdde[\fsetting UprightFeatures={RawFeature={+axis={wght=400,wdth=110}}},]{\fname} \newfontface\AnekDgddf[\fsetting UprightFeatures={RawFeature={+axis={wght=400,wdth=115}}},]{\fname} \newfontface\AnekDgddg[\fsetting UprightFeatures={RawFeature={+axis={wght=400,wdth=120}}},]{\fname} \newfontface\AnekDgddh[\fsetting UprightFeatures={RawFeature={+axis={wght=400,wdth=125}}},]{\fname}
\newfontface\AnekDgdea[\fsetting UprightFeatures={RawFeature={+axis={wght=500,wdth=75}}},]{\fname} \newfontface\AnekDgdeb[\fsetting UprightFeatures={RawFeature={+axis={wght=500,wdth=80}}},]{\fname} \newfontface\AnekDgdec[\fsetting UprightFeatures={RawFeature={+axis={wght=500,wdth=90}}},]{\fname} \newfontface\AnekDgded[\fsetting UprightFeatures={RawFeature={+axis={wght=500,wdth=100}}},]{\fname} \newfontface\AnekDgdee[\fsetting UprightFeatures={RawFeature={+axis={wght=500,wdth=110}}},]{\fname} \newfontface\AnekDgdef[\fsetting UprightFeatures={RawFeature={+axis={wght=500,wdth=115}}},]{\fname} \newfontface\AnekDgdeg[\fsetting UprightFeatures={RawFeature={+axis={wght=500,wdth=120}}},]{\fname} \newfontface\AnekDgdeh[\fsetting UprightFeatures={RawFeature={+axis={wght=500,wdth=125}}},]{\fname}
\newfontface\AnekDgdfa[\fsetting UprightFeatures={RawFeature={+axis={wght=600,wdth=75}}},]{\fname} \newfontface\AnekDgdfb[\fsetting UprightFeatures={RawFeature={+axis={wght=600,wdth=80}}},]{\fname} \newfontface\AnekDgdfc[\fsetting UprightFeatures={RawFeature={+axis={wght=600,wdth=90}}},]{\fname} \newfontface\AnekDgdfd[\fsetting UprightFeatures={RawFeature={+axis={wght=600,wdth=100}}},]{\fname} \newfontface\AnekDgdfe[\fsetting UprightFeatures={RawFeature={+axis={wght=600,wdth=110}}},]{\fname} \newfontface\AnekDgdff[\fsetting UprightFeatures={RawFeature={+axis={wght=600,wdth=115}}},]{\fname} \newfontface\AnekDgdfg[\fsetting UprightFeatures={RawFeature={+axis={wght=600,wdth=120}}},]{\fname} \newfontface\AnekDgdfh[\fsetting UprightFeatures={RawFeature={+axis={wght=600,wdth=125}}},]{\fname}
\newfontface\AnekDgdga[\fsetting UprightFeatures={RawFeature={+axis={wght=700,wdth=75}}},]{\fname} \newfontface\AnekDgdgb[\fsetting UprightFeatures={RawFeature={+axis={wght=700,wdth=80}}},]{\fname} \newfontface\AnekDgdgc[\fsetting UprightFeatures={RawFeature={+axis={wght=700,wdth=90}}},]{\fname} \newfontface\AnekDgdgd[\fsetting UprightFeatures={RawFeature={+axis={wght=700,wdth=100}}},]{\fname} \newfontface\AnekDgdge[\fsetting UprightFeatures={RawFeature={+axis={wght=700,wdth=110}}},]{\fname} \newfontface\AnekDgdgf[\fsetting UprightFeatures={RawFeature={+axis={wght=700,wdth=115}}},]{\fname} \newfontface\AnekDgdgg[\fsetting UprightFeatures={RawFeature={+axis={wght=700,wdth=120}}},]{\fname} \newfontface\AnekDgdgh[\fsetting UprightFeatures={RawFeature={+axis={wght=700,wdth=125}}},]{\fname}
\newfontface\AnekDgdha[\fsetting UprightFeatures={RawFeature={+axis={wght=800,wdth=75}}},]{\fname} \newfontface\AnekDgdhb[\fsetting UprightFeatures={RawFeature={+axis={wght=800,wdth=80}}},]{\fname} \newfontface\AnekDgdhc[\fsetting UprightFeatures={RawFeature={+axis={wght=800,wdth=90}}},]{\fname} \newfontface\AnekDgdhd[\fsetting UprightFeatures={RawFeature={+axis={wght=800,wdth=100}}},]{\fname} \newfontface\AnekDgdhe[\fsetting UprightFeatures={RawFeature={+axis={wght=800,wdth=110}}},]{\fname} \newfontface\AnekDgdhf[\fsetting UprightFeatures={RawFeature={+axis={wght=800,wdth=115}}},]{\fname} \newfontface\AnekDgdhg[\fsetting UprightFeatures={RawFeature={+axis={wght=800,wdth=120}}},]{\fname} \newfontface\AnekDgdhh[\fsetting UprightFeatures={RawFeature={+axis={wght=800,wdth=125}}},]{\fname}
\begin{document}
100: weight मराठी मजकूर
700: weight {\AnekBoldc\textbf{मराठी मजकूर}} wght 200 wdth 180: {\AnekBoldc मराठी मजकूर}
900: weight {\AnekBoldb\textbf{मराठी मजकूर}} no bold: {\AnekBoldb मराठी मजकूर}
\begin{tabular}{ll}
Weight & Example (at width=100) \\
100 & \AnekDga \test \\
200 & \AnekDgb \test \\
300 & \AnekDgc \test \\
400 & \AnekDgd \test \\
500 & \AnekDge \test \\
600 & \AnekDgf \test \\
700 & \AnekDgg \test \\
800 & \AnekDgh \test \\
\end{tabular}
\bigskip
\begin{tabular}{ll}
Width (\%) & Example (at weight=400) \\
75 & \AnekDda \test \\
80 & \AnekDdb \test \\
90 & \AnekDdc \test \\
100 & \AnekDdd \test \\
110 & \AnekDde \test \\
115 & \AnekDdf \test \\
120 & \AnekDdg \test \\
125 & \AnekDdh \test \\
\end{tabular}
%--- Grid Sample
\bigskip
\begin{tabular}{lllllllll}
& 75 & 80 & 90 & 100 & 110 & 115 & 120 & 125 \\
100 & \AnekDgdaa \testb & \AnekDgdab \testb & \AnekDgdac \testb & \AnekDgdad \testb & \AnekDgdae \testb & \AnekDgdaf \testb & \AnekDgdag \testb & \AnekDgdah \testb \\
200 & \AnekDgdba \testb & \AnekDgdbb \testb & \AnekDgdbc \testb & \AnekDgdbd \testb & \AnekDgdbe \testb & \AnekDgdbf \testb & \AnekDgdbg \testb & \AnekDgdbh \testb \\
300 & \AnekDgdca \testb & \AnekDgdcb \testb & \AnekDgdcc \testb & \AnekDgdcd \testb & \AnekDgdce \testb & \AnekDgdcf \testb & \AnekDgdcg \testb & \AnekDgdch \testb \\
400 & \AnekDgdda \testb & \AnekDgddb \testb & \AnekDgddc \testb & \AnekDgddd \testb & \AnekDgdde \testb & \AnekDgddf \testb & \AnekDgddg \testb & \AnekDgddh \testb \\
500 & \AnekDgdea \testb & \AnekDgdeb \testb & \AnekDgdec \testb & \AnekDgded \testb & \AnekDgdee \testb & \AnekDgdef \testb & \AnekDgdeg \testb & \AnekDgdeh \testb \\
600 & \AnekDgdfa \testb & \AnekDgdfb \testb & \AnekDgdfc \testb & \AnekDgdfd \testb & \AnekDgdfe \testb & \AnekDgdff \testb & \AnekDgdfg \testb & \AnekDgdfh \testb \\
700 & \AnekDgdga \testb & \AnekDgdgb \testb & \AnekDgdgc \testb & \AnekDgdgd \testb & \AnekDgdge \testb & \AnekDgdgf \testb & \AnekDgdgg \testb & \AnekDgdgh \testb \\
800 & \AnekDgdha \testb & \AnekDgdhb \testb & \AnekDgdhc \testb & \AnekDgdhd \testb & \AnekDgdhe \testb & \AnekDgdhf \testb & \AnekDgdhg \testb & \AnekDgdhh \testb \\
\end{tabular}
\end{document}
教程
这是关于如何设置可变字体的变量(在本例中,沿着其中一种 Anek 字体的粗细轴和宽度轴)的迷你教程。
该代码是在 Windows 上使用 TeXLive 2020 发行版编译的(TL2020 没有支持可变字体的 HarfBuzz 字体塑造引擎版本),并使用 lualatex 引擎作为编译器进行编译(因为 lualatex 下的 fontspec 可以切换字体渲染器,并且 lualatex 可以理解包含[
和的文件名]
)。
需要 HarfBuzz 来在复杂脚本中获得正确的连字(连接词)(例如,न + ् + त = न्त)。
许多事情需要同时发生,因此有很多细节。
- 熟悉参考文献。
参考:打开 Latex 字体指南 ( texdoc fntguide
) 和fontspec
手册 ( texdoc fontspec
)。
下载 Anek 字体。
这里使用了fontspec
Path=
选项,因此将字体安装为系统字体并不是绝对必要的(至少在 Windows 下)。该字体
AnekDevanagari[wdth,wght].ttf
仅用于演示。(要使用 xelatex 进行编译,请将字体文件重命名为纯字符;此外,xelatex 默认使用 HarfBuzz)。该字体用作主字体,没有特定的脚本或语言设置,因为它包含
latn
脚本。对于该Path=
选项,请输入系统上的实际路径,或将其输入到\myfontpath
宏中。
\setmainfont[
Path=\myfontpath,
Extension=.ttf,
Colour=black,
UprightFont=*,
]{AnekDevanagari[wdth,wght]}
- 对于天城文,请
dev2
优先使用脚本;它修复了原始deva
脚本中编码的一些误解)。
\newfontscript{Devanagari}{dev2,deva}
- 定义没有 HarfBuzz 的 Anek 字体并设置标准字体(UprightFont 和 BoldFont)的变量,以及自定义字体作为演示。
完整定义:
\newfontface\anekexamplefont[
Path=\myfontpath,
Extension=.ttf,
Colour=blue,
Script=Devanagari,
Language=Marathi,
UprightFont=*,
UprightFeatures={RawFeature={+axis={wght=400,wdth=100}}},
BoldFont=*,
BoldFeatures={RawFeature={+axis={wght=700,wdth=105}}},
FontFace={ubux}{n}{Font={*},RawFeature={+axis={wght=900,wdth=125}},
},
]{AnekDevanagari[wdth,wght]}
- 一步一步:告诉 fontspec 使用 Devanagari 脚本和 Marathi 语言:
Script=Devanagari,
Language=Marathi,
- 告诉 fontspec UprightFont 文件的名称与主名称相同:
UprightFont=*,
- 将直立字体的可变字体特征设置为“正常”值(重量=400,宽度=100):
UprightFeatures={RawFeature={+axis={wght=400,wdth=100}}},
重量是一个数字,理论上是 1(细)到 1000(重),宽度是一个百分比,通常为 75-125,但实际上是字体设计师设计的。
- 对 BoldFont 执行同样操作:
BoldFont=*,
BoldFeatures={RawFeature={+axis={wght=700,wdth=105}}},
- 定义一个自定义字体,它将是超粗体和超扩展系列(
ubux
)和正常形状(n
) -fntguide
列出了推荐的系列命名。
FontFace={ubux}{n}{Font={*},RawFeature={+axis={wght=900,wdth=125}},
},
- 定义具有相同设置的另一种字体,另外它将使用 HarfBuzz 渲染器:
\newfontface\anekexamplefonthb[
Path=\myfontpath,
Extension=.ttf,
Colour=blue,
Script=Devanagari,
Language=Marathi,
Renderer=HarfBuzz,
UprightFont=*,
UprightFeatures={RawFeature={+axis={wght=400,wdth=100}}},
BoldFont=*,
BoldFeatures={RawFeature={+axis={wght=700,wdth=105}}},
FontFace={ubux}{n}{Font={*},RawFeature={+axis={wght=900,wdth=125}},
},
]{AnekDevanagari[wdth,wght]}
- 定义一个静态字体,以便比较:
\newfontface\shobhikafont[Renderer=HarfBuzz,
Script=Devanagari,
Language=Marathi,]{Shobhika}
- 使用自定义系列定义命令
ubux
:
\DeclareRobustCommand{\ubuxseries}{\fontseries{ubux}\selectfont}
- 定义
\text....
使用自定义系列的命令:
\DeclareTextFontCommand{\textubux}{\ubuxseries}
- 现在,生成一些输出,以显示重量/宽度:
\anekexamplefont
\test
...
\textbf{\test}
...
\textubux{\test}
...
- 对于 HarfBuzz 版本也是如此,显示 HarfBuzz(在 TL2020 中)默认为正常重量/宽度:
\anekexamplefonthb
\test
...
\textbf{\test}
...
\textubux{\test}
...
- 准备好后更新你的 TeX 安装。:)
完整 MWE
\documentclass{article}
\newcommand\myfontpath{C:/Users/...<really long path name>.../Variable/}
\newcommand\test{मराठी मजकूर तलॆन्त}
\usepackage{xcolor}
\usepackage{fontspec}
%\defaultfontfeatures{RawFeature={+axis={wght=400,wdth=100}}}
\setmainfont[
Path=\myfontpath,
Extension=.ttf,
Colour=black,
UprightFont=*,
]{AnekDevanagari[wdth,wght]}
\newfontscript{Devanagari}{dev2,deva}
\newfontface\anekexamplefont[
Path=\myfontpath,
Extension=.ttf,
Colour=blue,
Script=Devanagari,
Language=Marathi,
UprightFont=*,
UprightFeatures={RawFeature={+axis={wght=400,wdth=100}}},
BoldFont=*,
BoldFeatures={RawFeature={+axis={wght=700,wdth=105}}},
FontFace={ubux}{n}{Font={*},RawFeature={+axis={wght=900,wdth=125}},
},
]{AnekDevanagari[wdth,wght]}
\newfontface\anekexamplefonthb[
Path=\myfontpath,
Extension=.ttf,
Colour=blue,
Script=Devanagari,
Language=Marathi,
Renderer=HarfBuzz,
UprightFont=*,
UprightFeatures={RawFeature={+axis={wght=400,wdth=100}}},
BoldFont=*,
BoldFeatures={RawFeature={+axis={wght=700,wdth=105}}},
FontFace={ubux}{n}{Font={*},RawFeature={+axis={wght=900,wdth=125}},
},
]{AnekDevanagari[wdth,wght]}
\newfontface\shobhikafont[Renderer=HarfBuzz,
Script=Devanagari,
Language=Marathi,]{Shobhika}
\DeclareRobustCommand{\ubuxseries}{\fontseries{ubux}\selectfont}
\DeclareTextFontCommand{\textubux}{\ubuxseries}
\begin{document}
This is the main font (default).
\bigskip
%
\section{A}
Without using HarfBuzz renderer: +weight, +width, no ligatures
This is an Anek variable font, acting as ``normal'' font:
\begin{quotation}
\anekexamplefont
\test
\par weight=400, width=100
\end{quotation}
%
\textbackslash textbf:
\begin{quotation}
\anekexamplefont
\textbf{\test}
\par normal-bold, normal-ish width:
\par weight=700, width=105
\end{quotation}
%
\textbackslash textubux:
\begin{quotation}
\anekexamplefont
\textubux{\test}
\par ultra-bold, ultra-extended:
\par weight=900, width=125
\end{quotation}
\bigskip
\section{B}
Using HarfBuzz font-shaping engine: ligatures, normal weight and width only
%
This is an Anek variable font, acting as ``normal'' font:
\begin{quotation}
\anekexamplefonthb\test
\par weight=400, width=100
\end{quotation}
%
\textbackslash textbf:
\begin{quotation}
\anekexamplefonthb\textbf{\test}
\par normal-bold, normal-ish width:
\par weight=700, width=105
\end{quotation}
%
\textbackslash textubux:
\begin{quotation}
\anekexamplefonthb\textubux{\test}
\par ultra-bold, ultra-extended:
\par weight=900, width=125
\end{quotation}
\bigskip
\section{C}
Static font using HarfBuzz:
Shobhika font, normal:
\begin{quotation}
\shobhikafont\test
\end{quotation}
\end{document}