Debian Codegraph @

texmf-dist/tex/optex/base/fonts-opmac.opm

raw
1 %% This is part of the OpTeX project, see http://petr.olsak.net/optex
2
3 \_codedecl \typosize {Font managing macros from OPmac <2026-05-12>} % preloaded in format
4
5 \_doc -----------------------------
6 \`\typosize` `[<font-size>/<baselineskip>]` sets given parameters.
7 It sets text font size by the \^`\setfontsize` macro and math font sizes
8 by setting internal macros \^`\_sizemtext`, \^`\_sizemscript` and
9 \^`\_sizemsscript`. It uses common concept font sizes: 100\,\%,
10 70\,\% and 50\,\%.
11 The \^`\_setmainvalues` sets the parameters as main values when
12 the `\_typosize` is called first.
13 \_cod -----------------------------
14
15 \_protected\_def \_typosize [#1/#2]{%
16 \_textfontsize{#1}\_mathfontsize{#1}\_setbaselineskip{#2}%
17 \_setmainvalues \_ignorespaces
18 }
19 \_protected\_def \_textfontsize #1{\_if$#1$\_else \_setfontsize{at#1\_ptunit}\_fi}
20
21 \_def \_mathfontsize #1{\_if$#1$\_else
22 \_tmpdim=#1pt
23 \_edef\_sizemtext{\_ea\_ignorept \_the\_tmpdim \_ptmunit}%
24 \_tmpdim=0.7\_tmpdim
25 \_edef\_sizemscript{\_ea\_ignorept \_the\_tmpdim \_ptmunit}%
26 \_tmpdim=#1pt \_tmpdim=0.5\_tmpdim
27 \_edef\_sizemsscript{\_ea\_ignorept \_the\_tmpdim \_ptmunit}%
28 \_fi
29 }
30 \_public \typosize ;
31
32 \_doc -----------------------------
33 \`\typoscale` `[<font-factor>/<baseline-factor>]` scales
34 font size and baselineskip by given factors in respect to current values.
35 It calculates the \^`\typosize` parameters and runs the \^`\typosize`.
36 \_cod -----------------------------
37
38 \_protected\_def \_typoscale [#1/#2]{%
39 \_ifx$#1$\_def\_tmp{[/}\_else
40 \_settmpdim{#1}\_optsize
41 \_edef\_tmp{[\_ea\_ignorept\_the\_tmpdim/}\_fi
42 \_ifx$#2$\_edef\_tmp{\_tmp]}\_else
43 \_settmpdim{#2}\_baselineskip
44 \_edef\_tmp{\_tmp \_ea\_ignorept\_the\_tmpdim]}\_fi
45 \_ea\_typosize\_tmp
46 }
47 \_def\_settmpdim#1#2{%
48 \_tmpdim=#1pt \_divide\_tmpdim by1000
49 \_tmpdim=\_ea\_ignorept \_the#2\_tmpdim
50 }
51 \_public \typoscale ;
52
53 \_doc -----------------------------
54 \`\_setbaselineskip` `{<baselineskip>}` sets new `\baselineskip` and
55 more values of registers which are dependent on the `<baselineskip>`
56 including the \^`\strutbox`.
57 \_cod -----------------------------
58
59 \_def \_setbaselineskip #1{\_if$#1$\_else
60 \_tmpdim=#1\_ptunit
61 \_baselineskip=\_tmpdim \_relax
62 \_bigskipamount=\_tmpdim plus.33333\_tmpdim minus.33333\_tmpdim
63 \_medskipamount=.5\_tmpdim plus.16666\_tmpdim minus.16666\_tmpdim
64 \_smallskipamount=.25\_tmpdim plus.08333\_tmpdim minus.08333\_tmpdim
65 \_normalbaselineskip=\_tmpdim
66 \_jot=.25\_tmpdim
67 \_maxdepth=.33333\_tmpdim
68 \_setbox\_strutbox=\_hbox{\_vrule height.709\_tmpdim depth.291\_tmpdim width0pt}%
69 \_fi
70 }
71
72 \_doc -----------------------------
73 \`\_setmainvalues` sets the current font size and `\baselineskip`
74 values to the \`\mainfosize` and \hbox{\`\mainbaselineskip`} registers
75 and loads fonts at given sizes.
76 It redefines itself as \`\_setmainvaluesL`
77 to set the main values only first. The \^`\_setmainvaluesL` does only
78 fonts loading.
79 \nl
80 \`\scalemain` returns to these values if they were set. Else they are set
81 to 10/12\,pt.
82 \nl
83 \`\mfontsrule` gives the rule how math fonts are loaded when \^`\typosize`
84 or \^`\typoscale` are used. The value of \^`\mfontsrule` can be:
85 \begitems
86 * 0: no math fonts are loaded. User must use \^`\normalmath` or \^`\boldmath` explicitly.
87 * 1: `\_normalmath` is run if \^`\typosize`/\^`\typoscale` are used
88 first or they are run at outer group level. No
89 `\everymath`/`\everydisplay` are set in this case. If
90 \^`\typosize`/\^`\typoscale` are run repeatedly in a group then `\_normalmath` is
91 run only when math formula occurs. This is done using
92 `\everymath`/`\everydisplay` and \^`\_setmathfonts`.
93 \^`\mfontsrule=1` is default.
94 * 2: `\_normalmath` is run whenever \^`\typosize`/\^`\typoscale` are used.
95 `\everymath`/`\everydisplay` registers are untouched.
96 \enditems
97 \_cod -----------------------------
98
99 \_newskip \_mainbaselineskip \_mainbaselineskip=0pt \_relax
100 \_newdimen \_mainfosize \_mainfosize=0pt
101 \_newcount \_mfontsrule \_mfontsrule=1
102
103 \_def\_setmainvalues {%
104 \_mainbaselineskip=\_baselineskip
105 \_mainfosize=\_optsize
106 \_topskip=\_mainfosize \_splittopskip=\_topskip
107 \_ifmmode \_else \_rm \_fi % load and initialize \rm variant
108 \_ifnum \_mfontsrule>0 \_normalmath \_fi % load math fonts first
109 \_let \_setmainvalues =\_setmainvaluesL
110 }
111 \_def\_setmainvaluesL {\_relax \_ifmmode \_else \_rm \_fi % load text font
112 \_ifcase \_mfontsrule % load math fonts
113 \_or \_ifnum\_currentgrouplevel=0 \_normalmath
114 \_else \_everymath={\_setmathfonts}\_everydisplay={\_normalmath}%
115 \_let\_runboldmath=\_relax \_fi
116 \_or \_normalmath \_fi}
117 \_def\_scalemain {%
118 \_ifdim \_mainfosize=\_zo
119 \_mainfosize=10pt \_mainbaselineskip=12pt
120 \_let \_setmainvalues=\_setmainvaluesL
121 \_fi
122 \_optsize=\_mainfosize \_baselineskip=\_mainbaselineskip
123 }
124 \_public \scalemain \mainfosize \mainbaselineskip \mfontsrule ;
125
126 \_doc -----------------------------
127 Suppose following example:
128 `{\typosize[13/15] Let $M$ be a subset of $R$ and $x\in M$...}`
129 If \^`\mfontsrule=1` then \^`\typosize` does not load math fonts
130 immediately but at the first math formula. It is done by `\everymath`
131 register, but the contents of this register is processed inside the math
132 group. If we do `\everymath={\_normalmath}` then this complicated macro
133 will be processed three times in your example above. We want only one
134 processing, so we do `\everymath={`\`\_setmathfonts``}` and
135 this macro closes math mode first, loads fonts and opens math mode again.
136 \_cod -----------------------------
137
138 \_def\_setmathfonts{$\_normalmath\_everymath{}\_everydisplay{}$}
139
140 \_doc -----------------------------
141 \`\thefontsize` `[<size>]` and \`\thefontscale` `[<factor>]`
142 do modification of the size of the current font. They are implemented by the
143 \^`\newcurrfontsize` macro.
144 \_cod -----------------------------
145
146 \_protected\_def\_thefontsize[#1]{\_if$#1$\_else
147 \_tmpdim=#1\_ptunit
148 \_newcurrfontsize{at\_tmpdim}%
149 \_fi
150 \_ignorespaces
151 }
152 \_protected\_def\_thefontscale[#1]{\_ifx$#1$\_else
153 \_tmpdim=#1pt \_divide\_tmpdim by1000
154 \_tmpdim=\_ea\_ea\_ea\_ignorept \_pdffontsize\_font \_tmpdim
155 \_newcurrfontsize{at\_tmpdim}%
156 \_fi
157 \_ignorespaces
158 }
159 \_public \thefontsize \thefontscale ;
160
161 \_doc -----------------------------
162 \`\em` keeps the weight of the current variant and switches
163 roman $\leftrightarrow$ italic. It adds the italic correction by
164 the \`\_additcorr` and \`\_afteritcorr` macros. The second does not
165 add italic correction if the next character is dot or comma.
166 \_cod -----------------------------
167
168 \_protected\_def\_em {%
169 \_ea\_ifx \_the\_font \_tenit \_additcorr \_rm \_else
170 \_ea\_ifx \_the\_font \_tenbf \_bi\_aftergroup\_afteritcorr\_else
171 \_ea\_ifx \_the\_font \_tenbi \_additcorr \_bf \_else
172 \_it \_aftergroup\_afteritcorr\_fi\_fi\_fi
173 }
174 \_def\_additcorr{\_ifhmode \_ifdim\_lastskip>\_zo
175 \_skip0=\_lastskip \_unskip \_additcorrA \_hskip\_skip0 \_else \_additcorrA \_fi\_fi}
176 \_def\_additcorrA{\_ifnum\_lastpenalty=\_zo \_italcorr \_else
177 \_ea\_unpenalty \_ea\_italcorr \_ea\_penalty \_the\_lastpenalty \_relax \_fi}
178 \_def\_afteritcorr{\_futurelet\_next\_afteritcorrA}
179 \_def\_afteritcorrA{\_ifhmode \_ifx\_next.\_else\_ifx\_next,\_else \_italcorr \_fi\_fi\_fi}
180 \_let\_italcorr=\/
181
182 \_doc -----------------------------
183 The \`\boldify` macro does `\let\rm\bf`, `\let\it\bi` and
184 `\let\normalmath=\boldmath`. All following text will be in bold.
185 If should be used after \^`\typosize` or \^`\typoscale` macros.\nl
186 The internal \`\_runboldmath` macro runs `\_boldmath` immediately
187 if no delay of the math font loading is set by \^`\_setmainvaluesL`.\nl
188 The `\rm`, `\it` in math mode must keep its original meaning.
189 \_cod -----------------------------
190
191 \_protected\_def \_boldify {%
192 \_let \_setmainvalues=\_setmainvaluesL
193 \_let\it =\_bi \_let\rm =\_bf \_let\_normalmath=\_boldmath \_bf
194 \_runboldmath
195 \_ifx\_ncharrmA\_undefined \_protected\_addto\rm{\_fam0 }\_protected\_addto\it{\_fam1 }%
196 \_else \_protected\_def\rm {\_fmodbf \_fontsel \_marm}%
197 \_protected\_def\it {\_fmodbi \_fontsel \_mait}%
198 \_fi
199 }
200 \_def\_runboldmath{\_boldmath}
201
202 \_public \em \boldify ;
203
204 \_doc -----------------------------
205 We need to use a font selector for default pagination. Because we don't
206 know what default font size will be selected by the user, we use this
207 \`\_rmfixed` macro. It sets the `\rm` font from the default font size
208 (declared by first \^`\typosize` command and redefines itself be only
209 the font switch for the next pages.
210 \_cod -----------------------------
211
212 \_def \_rmfixed {% used in default \footline
213 {\_ifdim\_mainfosize=0pt \_mainfosize=10pt \_fi
214 \_fontdef\_tenrm{\_setfontsize{at\mainfosize}\_resetmod\_rm}%
215 \_glet\_rmfixed=\_tenrm}% next use will be font switch only
216 \_rmfixed
217 }
218 \_let \rmfixed = \_tenrm % user can redefine it
219
220 \_endcode % -------------------------------------
221
222 History:
223 2026-05-12 \ptunit -> pt, bug \ptunit^2 in math fixed
224 2024-01-25 \em: \_additcorr reimplemented to be more robust
225 2022-02-22 \_setmainvalues: only \rm initialized
226 2021-03-10 \boldify corrected
227 2021-03-09 \mfontsrule and \_setmathfonts introduced
228 2020-12-12 \_rmfixed fixed
229 2020-04-28 \boldify: removed \let\_rm=\_bf
230 2020-04-14 \_setmainvaluesL: \_ifmmode test added
231 2020-03-27 \_setmainvalues: \_splittopskip=\_topskip added