| 1 |
%% This is part of the OpTeX project, see http://petr.olsak.net/optex |
| 2 |
|
| 3 |
\_famdecl [Heros] \Heros {TeX Gyre Heros fonts based on Helvetica} |
| 4 |
{\caps \cond} {\rm \bf \it \bi} {FiraMath} |
| 5 |
{[texgyreheros-regular]} |
| 6 |
{\_def\_fontnamegen{[texgyreheros\_condV-\_currV]:\_capsV\_fontfeatures}} |
| 7 |
|
| 8 |
\_wlog{\_detokenize{% |
| 9 |
Modifiers:^^J |
| 10 |
\caps ...... caps & small caps^^J |
| 11 |
\cond ...... condensed variants^^J |
| 12 |
}} |
| 13 |
|
| 14 |
\_moddef \resetmod {\_fsetV caps={},cond={} \_fvars regular bold italic bolditalic } |
| 15 |
\_moddef \caps {\_fsetV caps=+smcp;\_ffonum; } |
| 16 |
\_moddef \nocaps {\_fsetV caps={} } |
| 17 |
\_moddef \cond {\_fsetV cond=cn } |
| 18 |
\_moddef \nocond {\_fsetV cond={} } |
| 19 |
|
| 20 |
\_initfontfamily % new font family must be initialized |
| 21 |
|
| 22 |
\_ifmathloading |
| 23 |
\_loadmath {[FiraMath-Regular]} |
| 24 |
\_addUmathfont \_xits {[XITSMath-Regular]}{} {[XITSMath-Bold]}{} {} |
| 25 |
\_addto\_frak{\_fam\_xits}\_addto\_cal{\_fam\_xits} \_public \frak \cal ; |
| 26 |
% \bf, \bi from FiraMath: |
| 27 |
\_let\_bsansvariables=\_bfvariables |
| 28 |
\_let\_bsansGreek=\_bfGreek |
| 29 |
\_let\_bsansgreek=\_bfgreek |
| 30 |
\_let\_bsansdigits=\_bfdigits |
| 31 |
\_let\_bisansvariables=\_bivariables |
| 32 |
\_let\_bisansgreek=\_bigreek |
| 33 |
% \_resetmathchars <fam-number> <list of \Umathchardef csnames> ; |
| 34 |
\_mathchars \_xits {\bigtriangleup \bigblacktriangleup \blacktriangle |
| 35 |
\vartriangle \smallblacktriangleright |
| 36 |
\unicodevdots \unicodeadots \unicodeddots} % ... etc. you can add more |
| 37 |
\_fi |
| 38 |
|
| 39 |
\_endcode |
| 40 |
|
| 41 |
The font family file declares the font family for selecting fonts from this |
| 42 |
family at the arbitrary size and with various shapes. Unicode fonts (OTF) |
| 43 |
are preferred. The following example declares the Heros family: |
| 44 |
|
| 45 |
\printdoc f-heros.opm |
| 46 |
|
| 47 |
If you want to write such a font family file, you need to keep the following rules. |
| 48 |
|
| 49 |
\begitems |
| 50 |
* Use the \^`\_famdecl` command first. It has the following syntax: |
| 51 |
\begtt \catcode`\<=13 |
| 52 |
\_famdecl [<Name of family>] \<Familyselector> {<comments>} |
| 53 |
{<modifiers>} {<variant selectors>} {<comments about math fonts>} |
| 54 |
{<font-for-testing>} |
| 55 |
{\_def\_fontnamegen{<font name or font file name generated>}} |
| 56 |
\endtt |
| 57 |
This writes information about font family at the |
| 58 |
terminal and prevents loading such file twice. Moreover, it probes |
| 59 |
existence of `<font-for-testing>` in your system. If it doesn't exist, the |
| 60 |
file loading is skipped with a warning on the terminal. |
| 61 |
The \^`\_ifexistfam` macro returns false in this case. |
| 62 |
The \^`\_fontnamegen` macro must be defined in the last parameter of the |
| 63 |
\^`\_famdecl`. More about it is documented below. |
| 64 |
* You can use `\_wlog{\_detokenize{...` to write additional information into a log file. |
| 65 |
* You can declare optical sizes using \~`\_regoptsizes` if there are more font files |
| 66 |
with different optical sizes (like in Latin Modern). See `f-lmfonts.opm` |
| 67 |
file for more information about this special feature. |
| 68 |
* Declare font modifiers using \~`\moddef` if they are present. The \`\resetmod` |
| 69 |
must be declared in each font family. |
| 70 |
* Check if all your declared modifiers do not produce any space in |
| 71 |
horizontal mode. For example check: `X\caps Y`, the letters `XY` must |
| 72 |
be printed without any space. |
| 73 |
* Optionally, declare new variants by the \^`\famvardef` macro. |
| 74 |
* Run `\_initfontfamily` to start the family (it is mandatory). |
| 75 |
* If math font should be loaded, use `\_loadmath{<math font>}`. |
| 76 |
\enditems |
| 77 |
|
| 78 |
{\noindent \bf The \`\_fontnamegen` macro} |
| 79 |
(declared in the last parameter of the \^`\_famdecl`) |
| 80 |
must expand (at the expand processor level only) to a file name of the loaded font (or to its font |
| 81 |
name) and to optional font features appended. The Font Selection |
| 82 |
System uses this macro at the primitive level in the following sense: |
| 83 |
|
| 84 |
\begtt \catcode`\<=13 |
| 85 |
\font \<font-switch> {\_fontnamegen} \_sizespec |
| 86 |
\endtt |
| 87 |
% |
| 88 |
Note that the extended `\font` syntax |
| 89 |
`\font\<font-switch> {<font name>:<font features>} <size spec.>` or |
| 90 |
`\font\<font-switch> {[<font file name>]:<font features>} <size spec.>` |
| 91 |
is expected here. |
| 92 |
|
| 93 |
\seccc Example 1 |
| 94 |
|
| 95 |
Assume an abstract font family with fonts `xx-Regular.otf`, |
| 96 |
`xx-Bold.otf`, `xx-Italic.otf` and `xx-BoldItalic.otf`. Then you can declare |
| 97 |
the \^`\resetmod` (for initializing the family) by: |
| 98 |
\begtt |
| 99 |
\_moddef\resetmod{\_fvars Regular Bold Italic BoldItalic } |
| 100 |
\endtt |
| 101 |
and define the \^`\_fontnamegen` in the last parameter of the \^`\_famdecl` by: |
| 102 |
\begtt |
| 103 |
\_famdecl ... |
| 104 |
{\def\_fontnamegen{[xx-\_currV]}} |
| 105 |
\endtt |
| 106 |
The following auxiliary macros are used here: |
| 107 |
\begitems |
| 108 |
* \^`\moddef` declares the family dependent modifier. The \^`\resetmod` saves |
| 109 |
initial values for the family. |
| 110 |
* \^`\_fvars` saves four names to the memory, they are used by the \^`\_currV` macro. |
| 111 |
* \^`\_currV` expands to one of the four names dependent on `\rm` or `\bf` or |
| 112 |
`\it` or `\bi` variant is required. |
| 113 |
\enditems |
| 114 |
Assume that the user needs `\it` variant in this family. Then the |
| 115 |
`\_fontnamegen` macro expands to `[xx-\_currV]` and it expands to |
| 116 |
`[xx-Italic]`. The Font Selection System uses `\font {[xx-Italic]}`. |
| 117 |
This command loads the `xx-Italic.otf` font file. |
| 118 |
|
| 119 |
See more advanced examples are in `f-<family>.opm` files. |
| 120 |
|
| 121 |
\seccc Example 2 |
| 122 |
|
| 123 |
The `f-heros.opm` is listed here. Look at it. |
| 124 |
When Heros family is selected and `\bf` is asked then |
| 125 |
`\font {[texgyreheros-bold]:+tlig;} at10pt` |
| 126 |
is processed. |
| 127 |
|
| 128 |
You can use any expandable macros or expandable primitives in the `\_fontnamegen` |
| 129 |
macro. The simple macros in our example with names `\_<word>V` are preferred. They |
| 130 |
expand typically to their content. The macro \^`\_fsetV` `<word>=<content>` |
| 131 |
(terminated by a space) is equivalent to `\def\_<word>V{<content>}` and you |
| 132 |
can use it in font modifiers. You can use the \^`\_fsetV` macro in more |
| 133 |
general form: |
| 134 |
|
| 135 |
\begtt \catcode`\<=13 |
| 136 |
\_fsetV <word-a>=<value-a>,<word-b>=<value-b> ...etc. terminated by a space |
| 137 |
\endtt |
| 138 |
% |
| 139 |
with obvious result `\def\_<word-a>V {<value-a>}\def\_<word-b>V {<value-b>}` etc. |
| 140 |
|
| 141 |
\seccc Example 3 |
| 142 |
|
| 143 |
If both font modifiers `\caps`, `\cond` were applied in Heros |
| 144 |
family, then `\def\_capsV{+smcp;\_ffonum;}` and `\def\_condV{cn}` were processed |
| 145 |
by these font modifiers. If a user needs the `\bf` variant at 11\,pt now then |
| 146 |
the |
| 147 |
|
| 148 |
\begtt |
| 149 |
\font {[texgyreheroscn-bold]:+smcp;+onum;+pnum;+tlig;} at11pt |
| 150 |
\endtt |
| 151 |
% |
| 152 |
is processed. We assume that a font file `texgyreheroscn-bold.otf` is present |
| 153 |
in your \TeX/ system. |
| 154 |
|
| 155 |
\seccc The \code{\\_onlyif} macro |
| 156 |
|
| 157 |
has the syntax \^`\_onlyif` `<word>=<value-a>,<value-b>,...<value-n>: {<what>}`. It can |
| 158 |
be used inside `\moddef` as simple IF statement: the `<what>` is processed only |
| 159 |
if `<word>` has `<value-a>` or `<value-b>` \dots or `<value-n>`. See |
| 160 |
`f-roboto.opm` for examples of usage of many `\_onlyif`'s. |
| 161 |
|
| 162 |
Recommendation: use the \^`\_fontfeatures` macro at the end of the `\_fontnamegen` |
| 163 |
macro in order to the \^`\setff`, \^`\setfontcolor`, \^`\setletterspace` |
| 164 |
macros can work. |
| 165 |
|
| 166 |
\seccc The \code{\\moddef} macro |
| 167 |
|
| 168 |
has the syntax \^`\moddef\<modifier>{<what to do>}`. It does more things than simple `\_def`: |
| 169 |
|
| 170 |
\begitems |
| 171 |
* The modifier macros are defined as `\_protected`. |
| 172 |
* The modifier macros are defined as family-dependent. |
| 173 |
* If the declared control sequence is defined already (and it is not a font |
| 174 |
modifier) then it is re-defined with a warning. |
| 175 |
\enditems |
| 176 |
\noindent |
| 177 |
The \^`\famvardef` macro has the same features. |
| 178 |
|
| 179 |
\bigskip |
| 180 |
{\noindent\bf The `\<Familyselector>`} |
| 181 |
is defined by the \^`\_famdecl` macro as: |
| 182 |
\begtt \catcode`<=13 |
| 183 |
\protected\def\<Familyselector> {% |
| 184 |
\_def\_currfamily {<Familyselector>}% |
| 185 |
\_def\_fontnamegen {...}% this is copied from 7-th parameter of \_famdecl |
| 186 |
\resetmod |
| 187 |
<run all family-dependent font modifiers used before Familyselector without warnings> |
| 188 |
\endtt |
| 189 |
|
| 190 |
{\noindent\bf The \^`\_initfontfamily`}\nl |
| 191 |
must be run after modifier's decaration. |
| 192 |
It runs the `\<Familyselector>` and it runs `\_rm`, |
| 193 |
so the first font from the new family is loaded and it is ready to use it. |
| 194 |
|
| 195 |
\seccc Name conventions |
| 196 |
|
| 197 |
Create font modifiers, new variants, and the `\<Familyselector>` only in |
| 198 |
public namespace without `_` prefix. We assume that if a user re-defines them then he/she needs |
| 199 |
not them, so we have no problems. If the user's definition was done before loading |
| 200 |
the font family file then it is re-defined and \OpTeX/ warns about it. See the end of |
| 201 |
section~\ref[fontcommands]. |
| 202 |
|
| 203 |
If you need to use an internal control sequence declared in your fontfile, |
| 204 |
use the reserved name space with names starting with two `_` followed by family |
| 205 |
identifier or by `vf` if it relates to variable fonts. |
| 206 |
|
| 207 |
The name of `\<Familyselector>` should begin with an uppercase letter. |
| 208 |
|
| 209 |
Please, look at |
| 210 |
\ulink[http://petr.olsak.net/ftp/olsak/optex/op-catalog.pdf]{\OpTeX/ font catalogue} |
| 211 |
before you will create your font family file and use the same names for |
| 212 |
analogical font modifiers (like `\cond`, `\caps`, `\sans`, `\mono` etc.)\ |
| 213 |
and for extra variant selectors (like `\lf`, `\li`, `\kf`, `\ki` etc.\ used in |
| 214 |
Roboto font family). |
| 215 |
|
| 216 |
If you are using the same font modifier names to analogical font shapes then |
| 217 |
such modifiers are kept when the family is changed. For example: |
| 218 |
|
| 219 |
\begtt |
| 220 |
\fontfam [Termes] \fontfam[Heros] |
| 221 |
\caps\cond\it Caps+Cond italic in Heros \Termes\currvar Caps italic in Termes. |
| 222 |
\endtt |
| 223 |
% |
| 224 |
The family selector first resets all modifiers data by |
| 225 |
\^`\resetmod` and then it tries to run all currently used family-dependent modifiers |
| 226 |
before the family switching (without warnings if such modifier is |
| 227 |
unavailable in the new family). |
| 228 |
In this example, `\Termes` does `\resetmod` followed by `\caps\cond`. |
| 229 |
The `\caps` is applied and `\cond` is silently ignored in Termes family. |
| 230 |
|
| 231 |
If you need to declare your private modifier (because it is used in other |
| 232 |
modifiers or macros, for example), use the name `\_wordM`. You can be |
| 233 |
sure that such a name does not influence the private namespace used by \OpTeX/. |
| 234 |
|
| 235 |
\seccc Additional notes |
| 236 |
|
| 237 |
See the font family file `f-libertine-s.opm` which is another example where no |
| 238 |
font files but font names are used. |
| 239 |
|
| 240 |
See the font family file `f-lmfonts.opm` or `f-poltawski.opm` where you can find the |
| 241 |
the example of the optical sizes declaration including documentation about |
| 242 |
it. |
| 243 |
|
| 244 |
Several fonts don't switch to the font features if the features are |
| 245 |
specified directly as documented above. You must add the `script=latn;` |
| 246 |
specification to the features string when using these fonts, see |
| 247 |
`f-baskerville.opm` for example. The reason: these fonts don't follow the |
| 248 |
OpenType specification and they don't set the `DFLT` script but only scripts |
| 249 |
with given names like `latn`. And the tables implementing all font features |
| 250 |
are included here. You can check the internals of the font by FontForge: |
| 251 |
View / Show~ATT / OpenType Tables / GSUB. Do you see the `DFLT` script here? |
| 252 |
|
| 253 |
If you need to create a font family file with a non-Unicode font, you can do it. |
| 254 |
The `\_fontnamegen` must expand to the name of TFM file in this case. But we |
| 255 |
don't prefer such font family files, because they are usable only with |
| 256 |
languages with alphabet subset to ISO-8859-1 (Unicodes are equal to letter's |
| 257 |
codes of such alphabets), but middle or east Europe use languages where |
| 258 |
such a condition is not true. |