| 1 |
%%^^A%% fontspec-code-math.dtx -- part of FONTSPEC <latex3.github.io/fontspec> |
| 2 |
% |
| 3 |
% \section{Selecting maths fonts} |
| 4 |
% Here, the fonts used in math mode are redefined to correspond to the |
| 5 |
% default roman, sans serif and typewriter fonts. Unfortunately, you |
| 6 |
% can only define maths fonts in the preamble, otherwise I'd run this |
| 7 |
% code whenever \cs{setmainfont} and friends was run. |
| 8 |
% |
| 9 |
% \iffalse |
| 10 |
% \begin{macrocode} |
| 11 |
%<*fontspec> |
| 12 |
% \end{macrocode} |
| 13 |
% \fi |
| 14 |
% |
| 15 |
% \begin{macro}{\fontspec_setup_maths:} |
| 16 |
% Everything here is performed \cs{AtBeginDocument} in order to |
| 17 |
% overwrite \pkg{euler}'s attempt. This means \pkg{fontspec} must be |
| 18 |
% loaded \emph{after} \pkg{euler}. We set up a conditional to return |
| 19 |
% an error if this rule is violated. |
| 20 |
% |
| 21 |
% Since every maths setup is slightly different, we also take |
| 22 |
% different paths for defining various math glyphs depending which |
| 23 |
% maths font package has been loaded. |
| 24 |
% |
| 25 |
% \begin{macrocode} |
| 26 |
\@ifpackageloaded{euler} |
| 27 |
{ \bool_gset_true:N \g_@@_pkg_euler_loaded_bool } |
| 28 |
{ \bool_gset_false:N \g_@@_pkg_euler_loaded_bool } |
| 29 |
% \end{macrocode} |
| 30 |
% |
| 31 |
% \begin{macrocode} |
| 32 |
\cs_new:Nn \fontspec_setup_maths: |
| 33 |
{ |
| 34 |
\@ifpackageloaded{euler} |
| 35 |
{ |
| 36 |
\bool_if:NTF \g_@@_pkg_euler_loaded_bool |
| 37 |
{ \bool_gset_true:N \g_@@_math_euler_bool } |
| 38 |
{ \@@_error:n {euler-too-late} } |
| 39 |
} |
| 40 |
{} |
| 41 |
\@ifpackageloaded{lucbmath}{ \bool_gset_true:N \g_@@_math_lucida_bool }{} |
| 42 |
\@ifpackageloaded{lucidabr}{ \bool_gset_true:N \g_@@_math_lucida_bool }{} |
| 43 |
\@ifpackageloaded{lucimatx}{ \bool_gset_true:N \g_@@_math_lucida_bool }{} |
| 44 |
% \end{macrocode} |
| 45 |
% Knuth's CM fonts fonts are all squashed together, combining letters, |
| 46 |
% accents, text symbols and maths symbols all in the one font, |
| 47 |
% \texttt{cmr}, plus other things in other fonts. Because we are |
| 48 |
% changing the roman font in the document, we need to redefine all of |
| 49 |
% the maths glyphs in \LaTeX's \texttt{operators} maths font to still |
| 50 |
% go back to the legacy \texttt{cmr} font for all these random glyphs, |
| 51 |
% unless a separate maths font package has been loaded instead. |
| 52 |
% |
| 53 |
% In every case, the maths accents are always taken from the |
| 54 |
% \texttt{operators} font, which is generally the main text |
| 55 |
% font. (Actually, there is a \cmd\hat\ accent in |
| 56 |
% \texttt{EulerFractur}, but it's \emph{ugly}. So I ignore it. Sorry |
| 57 |
% if this causes inconvenience.) |
| 58 |
% \begin{macrocode} |
| 59 |
\DeclareSymbolFont{legacymaths}{OT1}{cmr}{m}{n} |
| 60 |
\SetSymbolFont{legacymaths}{bold}{OT1}{cmr}{bx}{n} |
| 61 |
\DeclareMathAccent{\acute} {\mathalpha}{legacymaths}{19} |
| 62 |
\DeclareMathAccent{\grave} {\mathalpha}{legacymaths}{18} |
| 63 |
\DeclareMathAccent{\ddot} {\mathalpha}{legacymaths}{127} |
| 64 |
\DeclareMathAccent{\tilde} {\mathalpha}{legacymaths}{126} |
| 65 |
\DeclareMathAccent{\bar} {\mathalpha}{legacymaths}{22} |
| 66 |
\DeclareMathAccent{\breve} {\mathalpha}{legacymaths}{21} |
| 67 |
\DeclareMathAccent{\check} {\mathalpha}{legacymaths}{20} |
| 68 |
\DeclareMathAccent{\hat} {\mathalpha}{legacymaths}{94} % too bad, euler |
| 69 |
\DeclareMathAccent{\dot} {\mathalpha}{legacymaths}{95} |
| 70 |
\DeclareMathAccent{\mathring}{\mathalpha}{legacymaths}{23} |
| 71 |
% \end{macrocode} |
| 72 |
% \paragraph{\cmd\colon: what's going on?} Okay, so \verb":" and \cmd\colon\ in maths mode are defined in a few places, so I need to work out what does what. Respectively, we have: |
| 73 |
% \begin{Verbatim} |
| 74 |
% % fontmath.ltx: |
| 75 |
% \DeclareMathSymbol{\colon}{\mathpunct}{operators}{"3A} |
| 76 |
% \DeclareMathSymbol{:}{\mathrel}{operators}{"3A} |
| 77 |
% |
| 78 |
% % amsmath.sty: |
| 79 |
% \renewcommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript |
| 80 |
% \mkern-\thinmuskip{:}\mskip6muplus1mu\relax} |
| 81 |
% |
| 82 |
% % euler.sty: |
| 83 |
% \DeclareMathSymbol{:}\mathrel {EulerFraktur}{"3A} |
| 84 |
% |
| 85 |
% % lucbmath.sty: |
| 86 |
% \DeclareMathSymbol{\@tempb}{\mathpunct}{operators}{58} |
| 87 |
% \ifx\colon\@tempb |
| 88 |
% \DeclareMathSymbol{\colon}{\mathpunct}{operators}{58} |
| 89 |
% \fi |
| 90 |
% \DeclareMathSymbol{:}{\mathrel}{operators}{58} |
| 91 |
% \end{Verbatim} |
| 92 |
% ($\mathrm{3A_{16}}=\mathrm{58_{10}}$) So I think, based on this summary, that it is fair to tell \pkg{fontspec} to `replace' the operators font with legacymaths for this symbol, except when \pkg{amsmath} is loaded since we want to keep its definition. |
| 93 |
% |
| 94 |
% |
| 95 |
% \begin{macrocode} |
| 96 |
\group_begin: |
| 97 |
\mathchardef\@tempa="603A \relax |
| 98 |
\ifx\colon\@tempa |
| 99 |
\DeclareMathSymbol{\colon}{\mathpunct}{legacymaths}{58} |
| 100 |
\fi |
| 101 |
\group_end: |
| 102 |
% \end{macrocode} |
| 103 |
% The following symbols are only defined specifically in \pkg{euler}, so skip them |
| 104 |
% if that package is loaded. |
| 105 |
% \begin{macrocode} |
| 106 |
\bool_if:NF \g_@@_math_euler_bool |
| 107 |
{ |
| 108 |
\DeclareMathSymbol{!}{\mathclose}{legacymaths}{33} |
| 109 |
\DeclareMathSymbol{:}{\mathrel} {legacymaths}{58} |
| 110 |
\DeclareMathSymbol{;}{\mathpunct}{legacymaths}{59} |
| 111 |
\DeclareMathSymbol{?}{\mathclose}{legacymaths}{63} |
| 112 |
% \end{macrocode} |
| 113 |
% And these ones are defined both in \pkg{euler} and \pkg{lucbmath}, |
| 114 |
% so we only need to run this code if no extra maths package has been |
| 115 |
% loaded. |
| 116 |
% \begin{macrocode} |
| 117 |
\bool_if:NF \g_@@_math_lucida_bool |
| 118 |
{ |
| 119 |
\DeclareMathSymbol{0}{\mathalpha}{legacymaths}{`0} |
| 120 |
\DeclareMathSymbol{1}{\mathalpha}{legacymaths}{`1} |
| 121 |
\DeclareMathSymbol{2}{\mathalpha}{legacymaths}{`2} |
| 122 |
\DeclareMathSymbol{3}{\mathalpha}{legacymaths}{`3} |
| 123 |
\DeclareMathSymbol{4}{\mathalpha}{legacymaths}{`4} |
| 124 |
\DeclareMathSymbol{5}{\mathalpha}{legacymaths}{`5} |
| 125 |
\DeclareMathSymbol{6}{\mathalpha}{legacymaths}{`6} |
| 126 |
\DeclareMathSymbol{7}{\mathalpha}{legacymaths}{`7} |
| 127 |
\DeclareMathSymbol{8}{\mathalpha}{legacymaths}{`8} |
| 128 |
\DeclareMathSymbol{9}{\mathalpha}{legacymaths}{`9} |
| 129 |
\DeclareMathSymbol{\Gamma}{\mathalpha}{legacymaths}{0} |
| 130 |
\DeclareMathSymbol{\Delta}{\mathalpha}{legacymaths}{1} |
| 131 |
\DeclareMathSymbol{\Theta}{\mathalpha}{legacymaths}{2} |
| 132 |
\DeclareMathSymbol{\Lambda}{\mathalpha}{legacymaths}{3} |
| 133 |
\DeclareMathSymbol{\Xi}{\mathalpha}{legacymaths}{4} |
| 134 |
\DeclareMathSymbol{\Pi}{\mathalpha}{legacymaths}{5} |
| 135 |
\DeclareMathSymbol{\Sigma}{\mathalpha}{legacymaths}{6} |
| 136 |
\DeclareMathSymbol{\Upsilon}{\mathalpha}{legacymaths}{7} |
| 137 |
\DeclareMathSymbol{\Phi}{\mathalpha}{legacymaths}{8} |
| 138 |
\DeclareMathSymbol{\Psi}{\mathalpha}{legacymaths}{9} |
| 139 |
\DeclareMathSymbol{\Omega}{\mathalpha}{legacymaths}{10} |
| 140 |
\DeclareMathSymbol{+}{\mathbin}{legacymaths}{43} |
| 141 |
\DeclareMathSymbol{=}{\mathrel}{legacymaths}{61} |
| 142 |
\DeclareMathDelimiter{(}{\mathopen} {legacymaths}{40}{largesymbols}{0} |
| 143 |
\DeclareMathDelimiter{)}{\mathclose}{legacymaths}{41}{largesymbols}{1} |
| 144 |
\DeclareMathDelimiter{[}{\mathopen} {legacymaths}{91}{largesymbols}{2} |
| 145 |
\DeclareMathDelimiter{]}{\mathclose}{legacymaths}{93}{largesymbols}{3} |
| 146 |
\DeclareMathDelimiter{/}{\mathord}{legacymaths}{47}{largesymbols}{14} |
| 147 |
\DeclareMathSymbol{\mathdollar}{\mathord}{legacymaths}{36} |
| 148 |
\renewcommand{\hbar}{{\mathchar"AF\mkern-9mu h}}% TODO: test with other fonts |
| 149 |
} |
| 150 |
} |
| 151 |
% \end{macrocode} |
| 152 |
% Finally, we change the font definitions for \cmd\mathrm\ and so |
| 153 |
% on. These are defined using the \cmd\g_@@_mathrm_tl\ (\dots) macros, |
| 154 |
% which default to \cmd\rmdefault\ but may be specified with the |
| 155 |
% \cmd\setmathrm\ (\dots) commands in the preamble. |
| 156 |
% |
| 157 |
% Since \LaTeX\ only generally defines one level of boldness, we omit |
| 158 |
% \cmd\mathbf\ in the \textsf{bold} maths series. It can be specified |
| 159 |
% as per usual with \cmd\setboldmathrm, which stores the appropriate |
| 160 |
% family name in \cmd\g_@@_bfmathrm_tl. |
| 161 |
% \begin{macrocode} |
| 162 |
\DeclareSymbolFont{operators}\g_fontspec_encoding_tl\g_@@_mathrm_tl\mddefault\shapedefault |
| 163 |
\SetSymbolFont{operators}{normal}\g_fontspec_encoding_tl\g_@@_mathrm_tl\mddefault\shapedefault |
| 164 |
\DeclareSymbolFontAlphabet\mathrm{operators} |
| 165 |
\SetMathAlphabet\mathit{normal}\g_fontspec_encoding_tl\g_@@_mathrm_tl\mddefault\itdefault |
| 166 |
\SetMathAlphabet\mathbf{normal}\g_fontspec_encoding_tl\g_@@_mathrm_tl\bfdefault\shapedefault |
| 167 |
\SetMathAlphabet\mathsf{normal}\g_fontspec_encoding_tl\g_@@_mathsf_tl\mddefault\shapedefault |
| 168 |
\SetMathAlphabet\mathtt{normal}\g_fontspec_encoding_tl\g_@@_mathtt_tl\mddefault\shapedefault |
| 169 |
\SetSymbolFont{operators}{bold}\g_fontspec_encoding_tl\g_@@_mathrm_tl\bfdefault\shapedefault |
| 170 |
\tl_if_empty:NTF \g_@@_bfmathrm_tl |
| 171 |
{ |
| 172 |
\SetMathAlphabet\mathit{bold}\g_fontspec_encoding_tl\g_@@_mathrm_tl\bfdefault\itdefault |
| 173 |
} |
| 174 |
{ |
| 175 |
\SetMathAlphabet\mathrm{bold}\g_fontspec_encoding_tl\g_@@_bfmathrm_tl\mddefault\shapedefault |
| 176 |
\SetMathAlphabet\mathbf{bold}\g_fontspec_encoding_tl\g_@@_bfmathrm_tl\bfdefault\shapedefault |
| 177 |
\SetMathAlphabet\mathit{bold}\g_fontspec_encoding_tl\g_@@_bfmathrm_tl\mddefault\itdefault |
| 178 |
} |
| 179 |
\SetMathAlphabet\mathsf{bold}\g_fontspec_encoding_tl\g_@@_mathsf_tl\bfdefault\shapedefault |
| 180 |
\SetMathAlphabet\mathtt{bold}\g_fontspec_encoding_tl\g_@@_mathtt_tl\bfdefault\shapedefault |
| 181 |
} |
| 182 |
% \end{macrocode} |
| 183 |
% \end{macro} |
| 184 |
% |
| 185 |
% \begin{macro}{\fontspec_maybe_setup_maths:} |
| 186 |
% We're a little less sophisticated about not executing the maths setup if various other maths font packages are loaded. This list is based on the wonderful `\LaTeX Font Catalogue': \url{http://www.tug.dk/FontCatalogue/mathfonts.html}. I'm sure there are more I've missed. Do the \TeX\ Gyre fonts have maths support yet? |
| 187 |
% |
| 188 |
% Untested: would |\unless\ifnum\Gamma=28672\relax\bool_set_false:N \g_@@_math_bool\fi| be a better test? |
| 189 |
% This needs more cooperation with euler and lucida, I think. |
| 190 |
% \begin{macrocode} |
| 191 |
\cs_new:Nn \fontspec_maybe_setup_maths: |
| 192 |
{ |
| 193 |
\@ifpackageloaded{anttor} |
| 194 |
{ |
| 195 |
\ifx\define@antt@mathversions a\bool_gset_false:N \g_@@_math_bool\fi |
| 196 |
}{} |
| 197 |
\@ifpackageloaded{arevmath} {\bool_gset_false:N \g_@@_math_bool}{} |
| 198 |
\@ifpackageloaded{eulervm} {\bool_gset_false:N \g_@@_math_bool}{} |
| 199 |
\@ifpackageloaded{mathdesign} {\bool_gset_false:N \g_@@_math_bool}{} |
| 200 |
\@ifpackageloaded{concmath} {\bool_gset_false:N \g_@@_math_bool}{} |
| 201 |
\@ifpackageloaded{cmbright} {\bool_gset_false:N \g_@@_math_bool}{} |
| 202 |
\@ifpackageloaded{mathesf} {\bool_gset_false:N \g_@@_math_bool}{} |
| 203 |
\@ifpackageloaded{gfsartemisia} {\bool_gset_false:N \g_@@_math_bool}{} |
| 204 |
\@ifpackageloaded{gfsneohellenic} {\bool_gset_false:N \g_@@_math_bool}{} |
| 205 |
\@ifpackageloaded{iwona} |
| 206 |
{ |
| 207 |
\ifx\define@iwona@mathversions a\bool_set_false:N \g_@@_math_bool\fi |
| 208 |
}{} |
| 209 |
\@ifpackageloaded{kpfonts}{\bool_gset_false:N \g_@@_math_bool}{} |
| 210 |
\@ifpackageloaded{kmath} {\bool_gset_false:N \g_@@_math_bool}{} |
| 211 |
\@ifpackageloaded{kurier} |
| 212 |
{ |
| 213 |
\ifx\define@kurier@mathversions a\bool_set_false:N \g_@@_math_bool\fi |
| 214 |
}{} |
| 215 |
\@ifpackageloaded{fouriernc} {\bool_gset_false:N \g_@@_math_bool}{} |
| 216 |
\@ifpackageloaded{fourier} {\bool_gset_false:N \g_@@_math_bool}{} |
| 217 |
\@ifpackageloaded{lmodern} {\bool_gset_false:N \g_@@_math_bool}{} |
| 218 |
\@ifpackageloaded{mathpazo} {\bool_gset_false:N \g_@@_math_bool}{} |
| 219 |
\@ifpackageloaded{mathptmx} {\bool_gset_false:N \g_@@_math_bool}{} |
| 220 |
\@ifpackageloaded{MinionPro} {\bool_gset_false:N \g_@@_math_bool}{} |
| 221 |
\@ifpackageloaded{unicode-math} {\bool_gset_false:N \g_@@_math_bool}{} |
| 222 |
\@ifpackageloaded{breqn} {\bool_gset_false:N \g_@@_math_bool}{} |
| 223 |
\@ifpackageloaded{pxfonts} {\bool_gset_false:N \g_@@_math_bool}{} |
| 224 |
\@ifpackageloaded{txfonts} {\bool_gset_false:N \g_@@_math_bool}{} |
| 225 |
\@ifpackageloaded{newpxmath} {\bool_gset_false:N \g_@@_math_bool}{} |
| 226 |
\@ifpackageloaded{newtxmath} {\bool_gset_false:N \g_@@_math_bool}{} |
| 227 |
\@ifpackageloaded{mtpro2} {\bool_gset_false:N \g_@@_math_bool}{} |
| 228 |
\bool_if:NT \g_@@_math_bool |
| 229 |
{ |
| 230 |
\@@_info:n {setup-math} |
| 231 |
\fontspec_setup_maths: |
| 232 |
} |
| 233 |
} |
| 234 |
\AtBeginDocument{\fontspec_maybe_setup_maths:} |
| 235 |
% \end{macrocode} |
| 236 |
% \end{macro} |
| 237 |
% |
| 238 |
% \iffalse |
| 239 |
% \begin{macrocode} |
| 240 |
%</fontspec> |
| 241 |
% \end{macrocode} |
| 242 |
% \fi |
| 243 |
|
| 244 |
|
| 245 |
\endinput |
| 246 |
|
| 247 |
% /© |
| 248 |
% ------------------------------------------------ |
| 249 |
% The FONTSPEC package <latex3.github.io/fontspec> |
| 250 |
% ------------------------------------------------ |
| 251 |
% Copyright 2022-2025 The LaTeX project, LPPL "maintainer" |
| 252 |
% Copyright 2004-2022 Will Robertson |
| 253 |
% Copyright 2009-2015 Khaled Hosny |
| 254 |
% Copyright 2013 Philipp Gesang |
| 255 |
% Copyright 2013-2016 Joseph Wright |
| 256 |
% ------------------------------------------------ |
| 257 |
% This package is free software and may be redistributed and/or modified under |
| 258 |
% the conditions of the LaTeX Project Public License, version 1.3c or higher |
| 259 |
% (your choice): <http://www.latex-project.org/lppl/>. |
| 260 |
% ------------------------------------------------ |
| 261 |
% ©/ |