summaryrefslogtreecommitdiff
path: root/macros/luatex/optex/f-heros.opm
blob: 5a03746cae2c1c029790d7e4053e071ee7b54064 (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
%% This is part of OpTeX project, see http://petr.olsak.net/optex

\_fontdecl [Heros] \Heros {TeX Gyre Heros fonts based on Helvetica}
        {\caps \cond} {\rm \bf \it \bi} {FiraMath}
        {[texgyreheros-regular]}

\_wlog{\_detokenize{%
Modifiers:^^J
 \caps ...... caps & small caps^^J
 \cond ...... condensed variants^^J
}}

\_protected\_def \Heros {%
   \_def \_currfamily {Heros}%
   \_def \_fontnamegen {[texgyreheros\_condV-\_currV]:\_capsV\_fontfeatures}%
   \_resetmod
}
\_moddef \resetmod {\_fsetV caps={},cond={} \_fvars regular bold italic bolditalic }
\_moddef \caps     {\_fsetV caps=+smcp;+onum; }
\_moddef \nocaps   {\_fsetV caps={} }
\_moddef \cond     {\_fsetV cond=cn }
\_moddef \nocond   {\_fsetV cond={} }

\_initfontfamily % new font family must be initialized

\_loadmath {[FiraMath-Regular]}

\_endcode


The usage of font \OpTeX/ selection system is described in the
fonts-select.opm file.


\sec How to write font-macro-file for \OpTeX/ like this file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The font-macro-file declares a font family for selecting a font from such
family at arbitrary size and with various shapes. Unicode fonts (OTF)
are preferred. If we want to write such font file, we need to keep following
rules.

\begitems
* Use 
\begtt
\_fontdecl [<Name of family>] \<Main-command> {<comments>}
     {<modifiers>} {<variant selectors>} {<comments about math fonts>}
     {<font-for-testing>}
\endtt
  as first command in this file. This writes information about font family at
  terminal and prevents loading such file twice. Moreover, it probes
  existence of `<font-for-testing>` in your system. If it isn't exist, the
  file loading is skipped with a warning on the terminal.
  The \_ifexistfam macro returns false in such case.
* You can use `\_wlog{\_detokenize{...` to write aditional information into
  log file.
* Define `\<Main-command>` (the commend `\Heros` here) as a `\_protected`
  macro. This macro initializes the family and it must do:
  \begitems
  * Define `\_currfamily` as a short name of the font family. It must be
    exactly the same as `<Main-command>` name but without backslash 
    (it is case sensitive).
  * Define `\_fontfeatures` if they are something special.
  * Define `\_fontnamegen` as a template of generic font name used as file
    names (or font names) of OTF fonts. The rules about `\_fontnamegen` macro
    are documented below.
  * Use \_resetmod modifier to initialize values.
  \enditems 
* You can declare optical sizes using `\_regoptsizes` if there are more font files
  with different optical sizes (like in Latin Modern). See `f-lmfonts.ofm`
  file for more information about this special feature.
* Declare font modifiers using `\_moddef` if they are present. The
  \_resetmod must be declared in each font family.
* Check if all your declared modifiers does not produce any space in
  horizontal mode. For example check: X\caps Y, the letters XY must 
  be printed without any space. Do the same test with \<Main-command>
  before releasing your font file, for example X\Heros Y.
* Run `\_initfontfamily` in order to start the family.
\enditems

The font file must declare `\_fontnamegen` macro which must expand (at
expand processor level only) to a file name of loaded font (or to its font
name) and to optional fontfeatures appended. The font selection 
system uses this macro at primitive level in the following sense:

\begtt
   \font {\_fontnamegen} \_sizespec
\endtt

For example, using macros from `f-heros.opm` the `\font` command expands its
parameters to:

\begtt
   \font {[texgyreheros-regular]:+tlig;} at10pt
\endtt

if the `\rm` variant is processed and if no additional font modifiers are
activated. Of course, you need to know something about fontname syntax for
extended `\font` primitive used with OTF fonts. The `[` `]` brackets tell us
that the file name (no font name) is specified inside such brackets. This
file (with additional `.otf` or `.ttf` extension) must be accessible by
Lua\TeX/ in your filesystem. Without spaces, there are font features
appended to file name (or font name) divided by semicolon. The `+tlig` font
feature means that TeX like ligatures (minus minus = endash, for example)
are active. Normal ligatures are active by default. You can list font
features of given font by `otfinfo -f fontfile.otf`.

The `\_fontnamegen` macro must include colon followed by family dependent
font features (optional) and followed by `\_fontfeatures` (required). 
If this is not true then font modifiers `\setff`, `\setfontcolor`, 
`\setletterspace` and `\setwordspace` don't work.

You can use any expandable macros or expandable primitives in `\fontnamegen`
macro. The simple macros in it with names `\_<word>V` are preferred. They
expand typically to their content. The macro `\_fsetV <word>=<content>`
(terminated by a space) is equivalent to `\def\_<word>V{<content>}` and you
can use it in font modifiers. You can use the `\_fsetV` macro in more
general form:

\begtt
   \_fsetV <wordA>=<valueA>,<wordB>=<valueB>  ...etc. terminated by a space 
\endtt

with obvious result `\def\_<wordA>V{<valueA>}\def\_<wordB>V{<valueB>} etc.

There is one special macro `\_currV` which expands to one of four variants
depending on which variant selector is in process. Four strings can be
saved by `\_fvars rm-variant bf-variant it-variant bi-varaiant` (all four strings
must be terminated by a space). One of these
string is used as expansion output of `\_currV` macro. Because we store

\begtt
   \_fvars regular bold italic bolditalic
\endtt

in `\resetmod` modifier then the `\_currV` expands (for example) 
to `italic` if the `\it` variant selector is in process.

Example: if both modifiers `\caps` and `\cond` were applied from this family
Heros and `\bf` variant is needed at 11pt then

\begtt
  \font {[texgyreheroscn-bold]:+smcp;+tlig;} at11pt
\endtt

is processed. We assume that a font file texgyreheroscn-bold.otf is present
in your TeX system.

Define all modifiers using `\_moddef` macro. 
The `\_moddef` macro does more things than simple `\_def`:

\begitems
* The modifier macros are defined as `\_protected`.
* The modifier macros are defined as family-dependent. If user loads more
  families then `\LMfonts \caps` does somewhat different job than 
  `\Heros \caps`, for example.
\enditems

Finally the `\_initfontfamily` must be run. It runs \<Main-command>. 
So, the `\_resetmod` macro (declared as `\resetmod`) is processed. Finally it
runs `\_rm`, so first font from new family is loaded and is ready to use it.

\secc Name conventions
%---------------------

Create modificators, new variants and `\<Main-command>` only as public, i.e.
without `_` prefix. We assume that if user re-defines them then he/she need
not them, so we have no problems.

If you need to declare your private modifier (because it is used in another
modifiers or macros, for example), use the name `\_wordM`. You can be
sure that such name does not influence the private name space used by \OpTeX/.

The private variant `\_resetmod` must be used in your 
`\<Main-command>` but you need not to declare it as private,
it is done automatically. Declare only `\restmod` by `\_moddef` macro.

The name of `\<Main-command>` should begin with uppercase letter.

See font-macro-file `f_libertine-s.opm` which is another example where no
font files but font names are used.

\secc Additional notes
%---------------------

In very rare situations we have more files with almost the same font but
designed for different optimal sizes (so called "optical sizes"). See a
collection of lmroman*.otf files, for example. You can declare such font
files for various optical sizes using `\_optname` macro in the
`\_fontnamegen` macro. See the file `f-lmfonts.opm` for more details.

If you need to create font-macro-file with non unicode font, you can do it.
The `\_fontnamegen` must expand to the name of TFM file in such case. But we
don't prefer such font-macro-files, because they are usable only with
laguages with alphabet subset to ISO-8859-1 (unicodes are equal to letter
codes of such alphabets), but middle or east Europe use languages where
such condition is not true.