summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/lualatex/combofont/combofont.tex
blob: 6c098b87e108e728474f5b991c080808aecff2dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
% !Mode:: "TeX:DE:UTF-8:Main"
\RequirePackage{luatex85}
\documentclass[parskip=half-,egregdoesnotlikesansseriftitles]{scrartcl}
\usepackage{combofont}
\usepackage{ydoc-code,ydoc-desc}
\usepackage{fontspec}

\usepackage{xcolor}


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

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



\DeclareFontFamily{TU}{combotest}{}
\DeclareFontShape{TU} {combotest}{m}{n}{<->combo*combotest-regular}{}
\DeclareFontShape{TU} {combotest}{bx}{n}{<->combo*combotest-bold}{}

\title{The \texttt{combofont} package}
\author{Ulrike Fischer\thanks{fischer@troubleshooting-tex.de}}
\newcommand\package[1]{\texttt{#1}}
\begin{document}
\maketitle

\section{Status: EXPERIMENTAL}

This is a EXPERIMENTAL package.

It can disappear without notice e.\,g. if the \package{luaotfload} changes so that it no longer work, or if luatex changes, or if \package{fontspec} includes the code.

It is also possible that syntax and commands change in a incompatible way. So if you use it in a production environment: \textbf{You have been warned}.

\section{Introduction}
In version 2.7. \package{luaotfload} supports combining characters from multiple fonts into a single virtualized one.

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.

The methods 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.

The main problem with the examples in the \package{luaotfload} manual is that it creates fonts of a fix size. This means that they don't respond to command like \verb+\large+ or \verb+\footnotesize+.

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 define with \verb+\DeclareSizeFunction+ to inject the needed code to size the combo-font in a nfss-\verb+\DeclareFontShape+-command.

\package{combofont.sty} is the result.

It is not meant as a production package but as package that helps to exploit the use of combo fonts.

\section{Requirements}
You need at least an up-to-date TeXLive 2016. TeXLive 2017 with luatex 1.0.4. or a current miktex is better. 

\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.


\section{Using combo fonts}

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):

\begin{enumerate}
\item Setup and describe the building of the combo font with \verb+\setupcombofont+

\item Write \texttt{nfss}-declarations
\end{enumerate}

\subsection{Setup the combo font}

\DescribeMacro\setupcombofont{<name>}{<comma list of basefonts>}{<comma list of ranges and code-points>}

\begin{description}
  \item[\marg{name}] is the name of the font. It should be some unique ascii-string without spaces. If you intent 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}.

  \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:

\begin{verbatim}
{
 {file:lmroman10-regular.otf:\combodefaultfeat} at #1pt,
 {file:lmsans10-regular.otf} at \fpeval{#1/10*15}pt,
 {file:cmunrm.otf}           at #1pt
}
\end{verbatim}

\minisec{Important points are:}
\begin{description}
\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;}.

\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!}
    
\item Be careful with the commas: there shouldn't be one after the last font.    
\end{description}

\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:

\begin{verbatim}
{
   {} ,
   0x41-0x5A*0x21*0x3F,
   fallback
}
\end{verbatim}

\minisec{Important points:}
\begin{enumerate}
\item There should be as many settings as there are fonts.
\item Empty entries should be marked with a pair of braces (normally the first entry is empty).
\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.
\item The keyword \texttt{fallback} means that this font is used for „missing glyphs“ (in the example for the cyrillic glyphs).
\end{enumerate}
\end{description}

\subsection{Write \texttt{nfss}-declarations}

After all the fonts you need have been setup, you can write suitable \texttt{nfss}-declaration which make it possible to call the font by family and other font commands. Example:

\begin{verbatim}
\DeclareFontFamily{TU}{combotest}{}
\DeclareFontShape {TU}{combotest}{m}{n} {<->combo*combotest-regular}{}
\DeclareFontShape {TU}{combotest}{bx}{n}{<->combo*combotest-bold}{}
\end{verbatim}

The important point is the size-function \verb+combo*+ which does all the work.


\section{Demonstration}


\verb+\fontfamily{combotest}\selectfont+:
\fontfamily{combotest}\selectfont
Some Text with Capital Words!
Eh bien, mon prince. Gênes et Lueques ne sont plus que des
apanages, des поместья, de la famille Buonaparte?
%

\verb+\large+\large:
Some Text with Capital Words!
Eh bien, mon prince. Gênes et Lueques ne sont plus que des
apanages, des поместья, de la famille Buonaparte?

\verb+\tiny+\tiny:
Some Text with Capital Words!
Eh bien, mon prince. Gênes et Lueques ne sont plus que des
apanages, des поместья, de la famille Buonaparte?

\verb+\bfseries\normalsize+\bfseries
\normalsize:
Some Text with Capital Words!
Eh bien, mon prince. Gênes et Lueques ne sont plus que des
apanages, des поместья, de la famille Buonaparte?


\verb+\tiny+\tiny:
Some Text with Capital Words!
Eh bien, mon prince. Gênes et Lueques ne sont plus que des
apanages, des поместья, de la famille Buonaparte?
%

\normalfont\normalsize

\section{About Math (new in version 0.2)}\enlargethispage{2\baselineskip}

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.

\minisec{Important points:}
\begin{enumerate}
\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.
\item  Start with a real math font with a math constants table. 
\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.   
\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.

       The font name database of luaotfload-names.lua contains for \textsf{TeX Gyre Pagella Math} these entries:
       
       \begin{verbatim}
       ["plainname"]="TeXGyrePagellaMath-Regular",
       ["psname"]="texgyrepagellamathregular",
       \end{verbatim}
       
  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.
\end{enumerate}


\section{Remarks and open questions}

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:

\begin{description}
  \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.
  \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).
  \item[Speed] I didn't try to optimize the loading of the fonts.
  \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.
  \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.
\end{description}
\end{document}