| 1 |
%%^^A%% um-code-fontparam.dtx -- part of UNICODE-MATH <wspr.io/unicode-math> |
| 2 |
%%^^A%% Cross-platform interface for font parameters |
| 3 |
|
| 4 |
% \section{Cross-platform interface for font parameters} |
| 5 |
% |
| 6 |
% \begin{macrocode} |
| 7 |
%<*package> |
| 8 |
% \end{macrocode} |
| 9 |
% |
| 10 |
% \XeTeX\ and \LuaTeX\ have different interfaces for math font parameters. |
| 11 |
% We use \LuaTeX’s interface because it’s much better, but rename the primitives to be more \LaTeX3-like. |
| 12 |
% There are getter and setter commands for each font parameter. |
| 13 |
% The names of the parameters is derived from the \LuaTeX\ names, with underscores inserted between words. |
| 14 |
% For every parameter \cs{Umath\meta{\LuaTeX\ name}}, we define an expandable getter command \cs{@@_\meta{\LaTeX3 name}:N} and a protected setter command \cs{@@_set_\meta{\LaTeX3 name}:Nn}. |
| 15 |
% The getter command takes one of the style primitives (\cs{displaystyle} etc.)\ and expands to the font parameter, which is a \meta{dimension}. |
| 16 |
% The setter command takes a style primitive and a dimension expression, which is parsed with \cs{dim_eval:n}. |
| 17 |
% |
| 18 |
% Often, the mapping between font dimensions and font parameters is bijective, but there are cases which require special attention: |
| 19 |
% \begin{itemize} |
| 20 |
% \item Some parameters map to different dimensions in display and non-display styles. |
| 21 |
% \item Likewise, one parameter maps to different dimensions in non-cramped and cramped styles. |
| 22 |
% \item There are a few parameters for which \XeTeX\ doesn’t seem to provide \cs{fontdimen}s; in this case the getter and setter commands are left undefined. |
| 23 |
% \end{itemize} |
| 24 |
% |
| 25 |
% \paragraph{Cramped style tokens} |
| 26 |
% \LuaTeX\ has \cs{crampeddisplaystyle} etc.,\ but they are loaded as \cs{luatexcrampeddisplaystyle} etc.\ by the \pkg{luatextra} package. |
| 27 |
% \XeTeX, however, doesn’t have these primitives, and their syntax cannot really be emulated. |
| 28 |
% Nevertheless, we define these commands as quarks, so they can be used as arguments to the font parameter commands (but nowhere else). |
| 29 |
% Making these commands available is necessary because we need to make a distinction between cramped and non-cramped styles for one font parameter. |
| 30 |
% |
| 31 |
% \begin{macro}{\@@_new_cramped_style:N} |
| 32 |
% \darg{command} |
| 33 |
% Define \meta{command} as a new cramped style switch. |
| 34 |
% For \LuaTeX, simply rename the correspronding primitive if it is not |
| 35 |
% already defined. |
| 36 |
% For \XeTeX, define \meta{command} as a new quark. |
| 37 |
% \begin{macrocode} |
| 38 |
\cs_new_protected_nopar:Nn \@@_new_cramped_style:N |
| 39 |
%<XE> { \tl_const:Nn #1 { \use_none:n #1 } } |
| 40 |
%<LU> { |
| 41 |
%<LU> \cs_if_exist:NF #1 |
| 42 |
%<LU> { \cs_new_eq:Nc #1 { luatex \cs_to_str:N #1 } } |
| 43 |
%<LU> } |
| 44 |
% \end{macrocode} |
| 45 |
% \end{macro} |
| 46 |
% |
| 47 |
% \begin{macro}{\crampeddisplaystyle} |
| 48 |
% \begin{macro}{\crampedtextstyle} |
| 49 |
% \begin{macro}{\crampedscriptstyle} |
| 50 |
% \begin{macro}{\crampedscriptscriptstyle} |
| 51 |
% The cramped style commands. |
| 52 |
% \begin{macrocode} |
| 53 |
\@@_new_cramped_style:N \crampeddisplaystyle |
| 54 |
\@@_new_cramped_style:N \crampedtextstyle |
| 55 |
\@@_new_cramped_style:N \crampedscriptstyle |
| 56 |
\@@_new_cramped_style:N \crampedscriptscriptstyle |
| 57 |
% \end{macrocode} |
| 58 |
% \end{macro} |
| 59 |
% \end{macro} |
| 60 |
% \end{macro} |
| 61 |
% \end{macro} |
| 62 |
% |
| 63 |
% \paragraph{Font dimension mapping} |
| 64 |
% Font parameters may differ between the styles. |
| 65 |
% \LuaTeX\ accounts for this by having the parameter primitives take a style token argument. |
| 66 |
% To replicate this behavior in \XeTeX, we have to map style tokens to specific combinations of font dimension numbers and math fonts (\cs{textfont} etc.). |
| 67 |
% |
| 68 |
% \begin{macro}{\@@_font_dimen:Nnnnn} |
| 69 |
% \darg{style token} |
| 70 |
% \darg{font dimen for display style} |
| 71 |
% \darg{font dimen for cramped display style} |
| 72 |
% \darg{font dimen for non-display styles} |
| 73 |
% \darg{font dimen for cramped non-display styles} |
| 74 |
% Map math style to \XeTeX\ math font dimension. |
| 75 |
% \meta{style token} must be one of the style switches (\cs{displaystyle}, \cs{crampeddisplaystyle}, \dots). |
| 76 |
% The other parameters are integer constants referring to font dimension numbers. |
| 77 |
% The macro expands to a dimension which contains the appropriate font dimension. |
| 78 |
% \begin{macrocode} |
| 79 |
%<*XE> |
| 80 |
\cs_new_nopar:Npn \@@_font_dimen:Nnnnn #1 #2 #3 #4 #5 { |
| 81 |
\fontdimen |
| 82 |
\cs_if_eq:NNTF #1 \displaystyle { |
| 83 |
#2 \textfont |
| 84 |
} { |
| 85 |
\cs_if_eq:NNTF #1 \crampeddisplaystyle { |
| 86 |
#3 \textfont |
| 87 |
} { |
| 88 |
\cs_if_eq:NNTF #1 \textstyle { |
| 89 |
#4 \textfont |
| 90 |
} { |
| 91 |
\cs_if_eq:NNTF #1 \crampedtextstyle { |
| 92 |
#5 \textfont |
| 93 |
} { |
| 94 |
\cs_if_eq:NNTF #1 \scriptstyle { |
| 95 |
#4 \scriptfont |
| 96 |
} { |
| 97 |
\cs_if_eq:NNTF #1 \crampedscriptstyle { |
| 98 |
#5 \scriptfont |
| 99 |
} { |
| 100 |
\cs_if_eq:NNTF #1 \scriptscriptstyle { |
| 101 |
#4 \scriptscriptfont |
| 102 |
} { |
| 103 |
% \end{macrocode} |
| 104 |
% Should we check here if the style is invalid? |
| 105 |
% \begin{macrocode} |
| 106 |
#5 \scriptscriptfont |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
% \end{macrocode} |
| 115 |
% Which family to use? |
| 116 |
% \begin{macrocode} |
| 117 |
2~ |
| 118 |
} |
| 119 |
%</XE> |
| 120 |
% \end{macrocode} |
| 121 |
% \end{macro} |
| 122 |
% |
| 123 |
% \paragraph{Font parameters} |
| 124 |
% This paragraph contains macros for defining the font parameter interface, as well as the definition for all font parameters known to \LuaTeX. |
| 125 |
% |
| 126 |
% \begin{macro}{\@@_font_param:nnnnn} |
| 127 |
% \darg{name} |
| 128 |
% \darg{font dimension for non-cramped display style} |
| 129 |
% \darg{font dimension for cramped display style} |
| 130 |
% \darg{font dimension for non-cramped non-display styles} |
| 131 |
% \darg{font dimension for cramped non-display styles} |
| 132 |
% This macro defines getter and setter functions for the font parameter \meta{name}. |
| 133 |
% The \LuaTeX\ font parameter name is produced by removing all underscores and prefixing the result with |Umath|. |
| 134 |
% The \XeTeX\ font dimension numbers must be integer constants. |
| 135 |
% \begin{macrocode} |
| 136 |
\cs_new_protected_nopar:Nn \@@_font_param:nnnnn |
| 137 |
%<*XE> |
| 138 |
{ |
| 139 |
\@@_font_param_aux:ccnnnn { @@_ #1 :N } { @@_set_ #1 :Nn } |
| 140 |
{ #2 } { #3 } { #4 } { #5 } |
| 141 |
} |
| 142 |
%</XE> |
| 143 |
%<*LU> |
| 144 |
{ |
| 145 |
\tl_set:Nn \l_@@_tmpa_tl { #1 } |
| 146 |
\tl_remove_all:Nn \l_@@_tmpa_tl { _ } |
| 147 |
\@@_font_param_aux:ccc { @@_ #1 :N } { @@_set_ #1 :Nn } |
| 148 |
{ Umath \l_@@_tmpa_tl } |
| 149 |
} |
| 150 |
%</LU> |
| 151 |
% \end{macrocode} |
| 152 |
% \end{macro} |
| 153 |
% |
| 154 |
% \begin{macro}{\@@_font_param:nnn} |
| 155 |
% \darg{name} |
| 156 |
% \darg{font dimension for display style} |
| 157 |
% \darg{font dimension for non-display styles} |
| 158 |
% This macro defines getter and setter functions for the font parameter \meta{name}. |
| 159 |
% The \LuaTeX\ font parameter name is produced by removing all underscores and prefixing the result with |Umath|. |
| 160 |
% The \XeTeX\ font dimension numbers must be integer constants. |
| 161 |
% \begin{macrocode} |
| 162 |
\cs_new_protected_nopar:Nn \@@_font_param:nnn |
| 163 |
{ |
| 164 |
\@@_font_param:nnnnn { #1 } { #2 } { #2 } { #3 } { #3 } |
| 165 |
} |
| 166 |
% \end{macrocode} |
| 167 |
% \end{macro} |
| 168 |
% |
| 169 |
% \begin{macro}{\@@_font_param:nn} |
| 170 |
% \darg{name} |
| 171 |
% \darg{font dimension} |
| 172 |
% This macro defines getter and setter functions for the font parameter \meta{name}. |
| 173 |
% The \LuaTeX\ font parameter name is produced by removing all underscores and prefixing the result with |Umath|. |
| 174 |
% The \XeTeX\ font dimension number must be an integer constant. |
| 175 |
% \begin{macrocode} |
| 176 |
\cs_new_protected_nopar:Nn \@@_font_param:nn |
| 177 |
{ |
| 178 |
\@@_font_param:nnnnn { #1 } { #2 } { #2 } { #2 } { #2 } |
| 179 |
} |
| 180 |
% \end{macrocode} |
| 181 |
% \end{macro} |
| 182 |
% |
| 183 |
% \begin{macro}{\@@_font_param:n} |
| 184 |
% \darg{name} |
| 185 |
% This macro defines getter and setter functions for the font parameter \meta{name}, which is considered unavailable in \XeTeX\@. |
| 186 |
% The \LuaTeX\ font parameter name is produced by removing all underscores and prefixing the result with |Umath|. |
| 187 |
% \begin{macrocode} |
| 188 |
\cs_new_protected_nopar:Nn \@@_font_param:n |
| 189 |
%<XE> { } |
| 190 |
%<LU> { \@@_font_param:nnnnn { #1 } { 0 } { 0 } { 0 } { 0 } } |
| 191 |
% \end{macrocode} |
| 192 |
% \end{macro} |
| 193 |
% |
| 194 |
% \begin{macro}{\@@_font_param_aux:NNnnnn} |
| 195 |
% \begin{macro}{\@@_font_param_aux:NNN} |
| 196 |
% Auxiliary macros for generating font parameter accessor macros. |
| 197 |
% \begin{macrocode} |
| 198 |
%<*XE> |
| 199 |
\cs_new_protected_nopar:Nn \@@_font_param_aux:NNnnnn |
| 200 |
{ |
| 201 |
\cs_new_nopar:Npn #1 ##1 |
| 202 |
{ |
| 203 |
\@@_font_dimen:Nnnnn ##1 { #3 } { #4 } { #5 } { #6 } |
| 204 |
} |
| 205 |
\cs_new_protected_nopar:Npn #2 ##1 ##2 |
| 206 |
{ |
| 207 |
#1 ##1 \dim_eval:n { ##2 } |
| 208 |
} |
| 209 |
} |
| 210 |
\cs_generate_variant:Nn \@@_font_param_aux:NNnnnn { cc } |
| 211 |
%</XE> |
| 212 |
%<*LU> |
| 213 |
\cs_new_protected_nopar:Nn \@@_font_param_aux:NNN |
| 214 |
{ |
| 215 |
\cs_new_nopar:Npn #1 ##1 |
| 216 |
{ |
| 217 |
#3 ##1 |
| 218 |
} |
| 219 |
\cs_new_protected_nopar:Npn #2 ##1 ##2 |
| 220 |
{ |
| 221 |
#3 ##1 \dim_eval:n { ##2 } |
| 222 |
} |
| 223 |
} |
| 224 |
\cs_generate_variant:Nn \@@_font_param_aux:NNN { ccc } |
| 225 |
%</LU> |
| 226 |
% \end{macrocode} |
| 227 |
% \end{macro} |
| 228 |
% \end{macro} |
| 229 |
% |
| 230 |
% Now all font parameters that are listed in the \LuaTeX\ reference follow. |
| 231 |
% \begin{macrocode} |
| 232 |
\@@_font_param:nn { axis } { 15 } |
| 233 |
\@@_font_param:nn { operator_size } { 13 } |
| 234 |
\@@_font_param:n { fraction_del_size } |
| 235 |
\@@_font_param:nnn { fraction_denom_down } { 45 } { 44 } |
| 236 |
\@@_font_param:nnn { fraction_denom_vgap } { 50 } { 49 } |
| 237 |
\@@_font_param:nnn { fraction_num_up } { 43 } { 42 } |
| 238 |
\@@_font_param:nnn { fraction_num_vgap } { 47 } { 46 } |
| 239 |
\@@_font_param:nn { fraction_rule } { 48 } |
| 240 |
\@@_font_param:nn { limit_above_bgap } { 29 } |
| 241 |
\@@_font_param:n { limit_above_kern } |
| 242 |
\@@_font_param:nn { limit_above_vgap } { 28 } |
| 243 |
\@@_font_param:nn { limit_below_bgap } { 31 } |
| 244 |
\@@_font_param:n { limit_below_kern } |
| 245 |
\@@_font_param:nn { limit_below_vgap } { 30 } |
| 246 |
\@@_font_param:nn { over_delimiter_vgap } { 41 } |
| 247 |
\@@_font_param:nn { over_delimiter_bgap } { 38 } |
| 248 |
\@@_font_param:nn { under_delimiter_vgap } { 40 } |
| 249 |
\@@_font_param:nn { under_delimiter_bgap } { 39 } |
| 250 |
\@@_font_param:nn { overbar_kern } { 55 } |
| 251 |
\@@_font_param:nn { overbar_rule } { 54 } |
| 252 |
\@@_font_param:nn { overbar_vgap } { 53 } |
| 253 |
\@@_font_param:n { quad } |
| 254 |
\@@_font_param:nn { radical_kern } { 62 } |
| 255 |
\@@_font_param:nn { radical_rule } { 61 } |
| 256 |
\@@_font_param:nnn { radical_vgap } { 60 } { 59 } |
| 257 |
\@@_font_param:nn { radical_degree_before } { 63 } |
| 258 |
\@@_font_param:nn { radical_degree_after } { 64 } |
| 259 |
\@@_font_param:nn { radical_degree_raise } { 65 } |
| 260 |
\@@_font_param:nn { space_after_script } { 27 } |
| 261 |
\@@_font_param:nnn { stack_denom_down } { 35 } { 34 } |
| 262 |
\@@_font_param:nnn { stack_num_up } { 33 } { 32 } |
| 263 |
\@@_font_param:nnn { stack_vgap } { 37 } { 36 } |
| 264 |
\@@_font_param:nn { sub_shift_down } { 18 } |
| 265 |
\@@_font_param:nn { sub_shift_drop } { 20 } |
| 266 |
\@@_font_param:n { subsup_shift_down } |
| 267 |
\@@_font_param:nn { sub_top_max } { 19 } |
| 268 |
\@@_font_param:nn { subsup_vgap } { 25 } |
| 269 |
\@@_font_param:nn { sup_bottom_min } { 23 } |
| 270 |
\@@_font_param:nn { sup_shift_drop } { 24 } |
| 271 |
\@@_font_param:nnnnn { sup_shift_up } { 21 } { 22 } { 21 } { 22 } |
| 272 |
\@@_font_param:nn { supsub_bottom_max } { 26 } |
| 273 |
\@@_font_param:nn { underbar_kern } { 58 } |
| 274 |
\@@_font_param:nn { underbar_rule } { 57 } |
| 275 |
\@@_font_param:nn { underbar_vgap } { 56 } |
| 276 |
\@@_font_param:n { connector_overlap_min } |
| 277 |
% \end{macrocode} |
| 278 |
% |
| 279 |
% \subsection{Historical commands} |
| 280 |
% |
| 281 |
% \begin{macro}{\@@_fontdimen_to_percent:nN} |
| 282 |
% \begin{macro}{\@@_fontdimen_pc_to_pt:nN} |
| 283 |
% \darg{Font dimen number} |
| 284 |
% \darg{Font `variable'} |
| 285 |
% \cmd\fontdimen s |10|, |11|, and |65| aren't actually dimensions, they're percentage values given in units of |sp|. |
| 286 |
% \cs{@@_fontdimen_to_percent:nn} takes a font dimension number and outputs the decimal value of the associated parameter. |
| 287 |
% \cs{@@_fontdimen_pc_to_pt:nn} returns a dimension correspond to the current |
| 288 |
% font size relative proportion based on that percentage. |
| 289 |
% \begin{macrocode} |
| 290 |
\cs_set:Nn \@@_fontdimen_to_percent:nN |
| 291 |
{ |
| 292 |
\fp_eval:n { \dim_to_decimal_in_sp:n { \fontdimen #1 #2 } / 100 } |
| 293 |
} |
| 294 |
\cs_new:Nn \@@_fontdimen_pc_to_pt:nN |
| 295 |
{ |
| 296 |
\fp_eval:n { \dim_to_decimal_in_sp:n { \fontdimen #1 #2 } / 100 * \f@size } |
| 297 |
} |
| 298 |
% \end{macrocode} |
| 299 |
% \end{macro} |
| 300 |
% \end{macro} |
| 301 |
% |
| 302 |
% \begin{macro}{\@@_mathstyle_scale:NnnN} |
| 303 |
% \darg{A math style (\cs{scriptstyle}, say)} |
| 304 |
% \darg{Macro that takes a non-delimited length argument (like \cmd\kern)} |
| 305 |
% \darg{Length control sequence to be scaled according to the math style} |
| 306 |
% \darg{Math font face to use for the lookups} |
| 307 |
% This macro is used to scale the lengths reported by \cmd\fontdimen\ according to the scale factor for script- and scriptscript-size objects. |
| 308 |
% \begin{macrocode} |
| 309 |
\cs_new:Nn \@@_mathstyle_scale:NnnN |
| 310 |
{ |
| 311 |
\ifx#1\scriptstyle |
| 312 |
#2 \@@_fontdimen_to_percent:nN {10} #4 #3 |
| 313 |
\else |
| 314 |
\ifx#1\scriptscriptstyle |
| 315 |
#2 \@@_fontdimen_to_percent:nN {11} #4 #3 |
| 316 |
\else |
| 317 |
#2 #3 |
| 318 |
\fi |
| 319 |
\fi |
| 320 |
} |
| 321 |
% \end{macrocode} |
| 322 |
% \end{macro} |
| 323 |
% |
| 324 |
% \begin{macrocode} |
| 325 |
%</package> |
| 326 |
% \end{macrocode} |
| 327 |
|
| 328 |
\endinput |
| 329 |
|
| 330 |
% /© |
| 331 |
% |
| 332 |
% ------------------------------------------------ |
| 333 |
% The UNICODE-MATH package <wspr.io/unicode-math> |
| 334 |
% ------------------------------------------------ |
| 335 |
% This package is free software and may be redistributed and/or modified under |
| 336 |
% the conditions of the LaTeX Project Public License, version 1.3c or higher |
| 337 |
% (your choice): <http://www.latex-project.org/lppl/>. |
| 338 |
% ------------------------------------------------ |
| 339 |
% Copyright 2006-2019 Will Robertson, LPPL "maintainer" |
| 340 |
% Copyright 2010-2017 Philipp Stephani |
| 341 |
% Copyright 2011-2017 Joseph Wright |
| 342 |
% Copyright 2012-2015 Khaled Hosny |
| 343 |
% ------------------------------------------------ |
| 344 |
% |
| 345 |
% ©/ |