Debian Codegraph @

texmf-dist/doc/lualatex/combofont/combofont.tex

raw
1 % !Mode:: "TeX:DE:UTF-8:Main"
2 \documentclass[parskip=half-,egregdoesnotlikesansseriftitles]{scrartcl}
3 \usepackage{combofont}
4 \usepackage{ydoc-code,ydoc-desc}
5 \usepackage[english]{babel}
6 \usepackage[autostyle]{csquotes}
7 \usepackage{fontspec}
8
9 \usepackage{xcolor}
10
11
12 \setupcombofont{combotest-regular}
13 {
14 {file:lmroman10-regular.otf:\combodefaultfeat} at #1pt,
15 {file:lmsans10-regular.otf} at \fpeval{#1/10*15}pt,
16 {file:cmunrm.otf} at #1pt
17 }
18 {
19 {} ,
20 0x41-0x5A*0x21*0x3F,
21 fallback
22 }
23
24 \setupcombofont{combotest-bold}
25 {
26 {file:lmroman10-bold.otf:\combodefaultfeat} at #1pt,
27 {file:lmsans10-bold.otf} at \fpeval{#1/10*15}pt,
28 {file:cmunbbx.otf} at #1pt
29 }
30 {
31 {} ,
32 0x41-0x5A*0x21*0x3F,
33 fallback
34 }
35
36
37
38 \DeclareFontFamily{TU}{combotest}{}
39 \DeclareFontShape{TU} {combotest}{m}{n}{<->combo*combotest-regular}{}
40 \DeclareFontShape{TU} {combotest}{bx}{n}{<->combo*combotest-bold}{}
41
42 \title{The \texttt{combofont} package \\
43 {\normalsize Version \csname UlrikeFischer@package@ufcombofont@version\endcsname\
44 from \csname UlrikeFischer@package@ufcombofont@date\endcsname}}
45 \author{Ulrike Fischer\thanks{[email protected]}}
46 \newcommand\package[1]{\texttt{#1}}
47 \begin{document}
48 \maketitle
49
50 \section{Status: EXPERIMENTAL}
51
52 This is an EXPERIMENTAL package.
53
54 It can disappear without notice e.\,g. if the \package{luaotfload} changes so that it no longer works, or if luatex changes, or if \package{fontspec} includes the code.
55
56 It is also possible that syntax and commands change in an incompatible way. So if you use it in a production environment: \textbf{You have been warned}.
57
58 \section{Introduction}
59 In version 2.7 \package{luaotfload} supports combining characters from multiple fonts into a single virtualized one.
60
61 That means that one can build a font that takes e.g. the capital letters from a sans serif font and the lowercase letters from a serif font. Or a font that pulls in missing greek or cyrillic glyphs from another font.
62
63 The method pulls in \emph{only} glyphs. It is not suitable for every imaginable font combination -- some drawbacks are described below -- and one should use it with care. Nevertheless it is a quite neat extension of the tools to manipulate fonts.
64
65 The main problem with the examples in the \package{luaotfload} manual is that they create fonts of a fix size. This means that they don't respond to command like \verb+\large+ or \verb+\footnotesize+.
66
67 After trying around a bit and then asking a question (https://tex.stackexchange.com/questions/371647/call-a-luatex-combo-font-through-nfss) I got from David Carlisle the idea to use a \texttt{size}-Funktion which one defines with \verb+\DeclareSizeFunction+ to inject the needed code to size the combo-font in a nfss-\verb+\DeclareFontShape+-command.
68
69 \package{combofont.sty} is the result.
70
71 It is not meant as a production package but as package that helps to exploit the use of combo fonts.
72
73 \section{Requirements}
74 You need at least an up-to-date TeXLive 2016. TeXLive 2017 with luatex 1.0.4 or a current miktex is better.
75
76 \textbf{Change Version 0.2, 3.7.2017}: The style no longer loads the now obsolete \texttt{l3regex}, it assumes that it is loaded by \texttt{expl3}. In older \TeX-systems you will have to load the package.
77
78
79 \section{Using combo fonts}
80
81 To be able to use a combo font with standard \LaTeX\ font commands you have to do two things (the source code of this documentation is a complete example):
82
83 \begin{enumerate}
84 \item Setup and describe the building of the combo font with \verb+\setupcombofont+
85
86 \item Write \texttt{nfss}-declarations
87 \end{enumerate}
88
89 \subsection{Setup the combo font}
90
91 \DescribeMacro\setupcombofont{<name>}{<comma list of basefonts>}{<comma list of ranges and code-points>}
92
93 \begin{description}
94 \item[\marg{name}] is the name of the font. It should be some unique ascii-string without spaces. If you intend to define lots of fonts it would be a good idea to think about a sensible naming sheme. In the example here I simply used \texttt{combotest-regular} and \texttt{combotest-bold}.
95
96 \item[\marg{comma list of basefonts}] This should be a list of font declarations you want to use to build your combo font. The syntax used is described in the \package{luaotfload} manual. Example:
97
98 \begin{verbatim}
99 {
100 {file:lmroman10-regular.otf:\combodefaultfeat} at #1pt,
101 {file:lmsans10-regular.otf} at \fpeval{#1/10*15}pt,
102 {file:cmunrm.otf} at #1pt
103 }
104 \end{verbatim}
105
106 \minisec{Important points are:}
107 \begin{description}
108 \item[Order of the fonts] The first font is the main font which will receive the glyphs. So think carefully which font is should be and setup its font features correctly. \package{combofont} defines as a helper command \verb+\combodefaultfeat+ which sets \texttt{mode=node;script=latn;language=DFLT;+tlig;}.
109
110 \item[Size declaration] The font description should end with a size declaration line \verb+at #1pt+. When processing the font \verb+#1+ will be replaced by the current font size. As you can see in the second font you can do calculations. \emph{Don't forget the size declaration!}
111
112 \item Be careful with the commas: there shouldn't be one after the last font.
113 \end{description}
114
115 \item[\marg{comma list of ranges and code-points}] This is a comma list of settings which describe which glyphs are taken from the respective font. Example:
116
117 \begin{verbatim}
118 {
119 {} ,
120 0x41-0x5A*0x21*0x3F,
121 fallback
122 }
123 \end{verbatim}
124
125 \minisec{Important points:}
126 \begin{enumerate}
127 \item There should be as many settings as there are fonts.
128 \item Empty entries should be marked with a pair of braces (normally the first entry is empty).
129 \item You can add ranges of code points and single code points. Blocks are separated by an asterix \verb+*+. The example set the uppercase letters and the exclamation and the question mark.
130 \item The keyword \texttt{fallback} means that this font is used for \enquote{missing glyphs} (in the example for the cyrillic glyphs).
131 \end{enumerate}
132 \end{description}
133
134 \subsection{Write \texttt{nfss}-declarations}
135
136 After all the fonts you need have been setup, you can write suitable \texttt{nfss}-declarations which make it possible to call the font by family and other font commands. Example:
137
138 \begin{verbatim}
139 \DeclareFontFamily{TU}{combotest}{}
140 \DeclareFontShape {TU}{combotest}{m}{n} {<->combo*combotest-regular}{}
141 \DeclareFontShape {TU}{combotest}{bx}{n}{<->combo*combotest-bold}{}
142 \end{verbatim}
143
144 The important point is the size-function \verb+combo*+ which does all the work.
145
146
147 \section{Demonstration}
148
149
150 \verb+\fontfamily{combotest}\selectfont+:
151 \fontfamily{combotest}\selectfont
152 Some Text with Capital Words!
153 Eh bien, mon prince. Gênes et Lueques ne sont plus que des
154 apanages, des поместья, de la famille Buonaparte?
155 %
156
157 \verb+\large+\large:
158 Some Text with Capital Words!
159 Eh bien, mon prince. Gênes et Lueques ne sont plus que des
160 apanages, des поместья, de la famille Buonaparte?
161
162 \verb+\tiny+\tiny:
163 Some Text with Capital Words!
164 Eh bien, mon prince. Gênes et Lueques ne sont plus que des
165 apanages, des поместья, de la famille Buonaparte?
166
167 \verb+\bfseries\normalsize+\bfseries
168 \normalsize:
169 Some Text with Capital Words!
170 Eh bien, mon prince. Gênes et Lueques ne sont plus que des
171 apanages, des поместья, de la famille Buonaparte?
172
173
174 \verb+\tiny+\tiny:
175 Some Text with Capital Words!
176 Eh bien, mon prince. Gênes et Lueques ne sont plus que des
177 apanages, des поместья, de la famille Buonaparte?
178 %
179
180 \normalfont\normalsize
181
182 \section{About Math (new in version 0.2)}\enlargethispage{2\baselineskip}
183
184 Combofonts can also be used in math. There is a test file called \texttt{combofont-test-fira-math.tex} which shows how one can combine \textsf{TeX Gyre Pagella Math} with the \textsf{Fira Sans} textfont. It also shows how one can patch the font to adjust values of the math table.
185
186 \minisec{Important points:}
187 \begin{enumerate}
188 \item This a first try to get something working in math. It is in no way finished or complete, I'm rather certain that something will be missing or even faulty.
189 \item Start with a real math font with a math constants table.
190 \item Don't expect to get a perfect sans serif math font this way without work. It can take quite some time to adjust everything. Also a text font is not really meant to be used as math font.
191 \item The lua-code for the font patch compares \texttt{fontdata.psname} with the string \\\texttt{TeXGyrePagellaMath-Regular} to restrict the patch to the specific font.
192
193 The font name database of luaotfload-names.lua contains for \textsf{TeX Gyre Pagella Math} these entries:
194
195 \begin{verbatim}
196 ["plainname"]="TeXGyrePagellaMath-Regular",
197 ["psname"]="texgyrepagellamathregular",
198 \end{verbatim}
199
200 As you can see the correct string for the comparision with \texttt{fontdata.psname} is in \verb+["plainname"]+ and not in \verb+["psname"]+. Don't ask me why. \texttt{luaotfload} seems to copy the infos around quite a lot. So when adapting the code to other fonts, test with various font names if it seems not to work.
201 \end{enumerate}
202
203
204 \section{Remarks and open questions}
205
206 As mentioned in the introduction a combo font only pulls in glyphs. This has a lot of (not all yet understood or seen) side effects. Here a few things that should be considered when building a combo font:
207
208 \begin{description}
209 \item[Kerning] Obviously some kerning works (see e.g. the large W before the o in the demonstration). But it is quite unclear which values are used, how bad it can get and if one can correct it.
210 \item[Font features] Only font features of the first font are taken into account. E.g. adding a color setting has an effect only if applied to the first font and then colors all glyphs. \verb!+smcp! (the open type small caps feature) only has an effect if the first font knows it. Mixing scripts and languages is probably not possible (but I didn't try yet).
211 \item[Speed] I didn't try to optimize the loading of the fonts.
212 \item[Pulling glyphs in other positions] One interesting question would if it is possible to switch glyph positions before or after the pull. E.g. if one could move the chars a-z from a sans serif text font to the math sans serif positions.
213 \item[Side effects] I naturally directly found a side-effect of such a combo font declaration: https://github.com/lualatex/luaotfload/issues/414. So the question is if there are more.
214 \end{description}
215 \end{document}
216
217