| 1 |
%%^^A%% um-code-sym-commands.dtx -- part of UNICODE-MATH <wspr.io/unicode-math> |
| 2 |
%%^^A%% Definition of "math symbol alphabet" commands such as `\symbf` and co. |
| 3 |
|
| 4 |
% \section{Mapping in maths alphabets} |
| 5 |
% \label{sec:symcmd} |
| 6 |
% |
| 7 |
% \begin{macrocode} |
| 8 |
%<*package> |
| 9 |
% \end{macrocode} |
| 10 |
% |
| 11 |
% |
| 12 |
% \subsection{Setting styles} |
| 13 |
% |
| 14 |
% Algorithm for setting alphabet fonts. |
| 15 |
% By default, when |range| is empty, we are in \emph{implicit} mode. |
| 16 |
% If |range| contains the name of the math alphabet, we are in \emph{explicit} |
| 17 |
% mode and do things slightly differently. |
| 18 |
% |
| 19 |
% Implicit mode: |
| 20 |
% \begin{itemize} |
| 21 |
% \item Try and set all of the alphabet shapes. |
| 22 |
% \item Check for the first glyph of each alphabet to detect if the font supports each |
| 23 |
% alphabet shape. |
| 24 |
% \item For alphabets that do exist, overwrite whatever’s already there. |
| 25 |
% \item For alphabets that are not supported, \emph{do nothing}. |
| 26 |
% (This includes leaving the old alphabet definition in place.) |
| 27 |
% \end{itemize} |
| 28 |
% |
| 29 |
% Explicit mode: |
| 30 |
% \begin{itemize} |
| 31 |
% \item Only set the alphabets specified. |
| 32 |
% \item Check for the first glyph of the alphabet to detect if the font contains |
| 33 |
% the alphabet shape in the Unicode math plane. |
| 34 |
% \item For Unicode math alphabets, overwrite whatever’s already there. |
| 35 |
% \item Otherwise, use the \ascii\ glyph slots instead. |
| 36 |
% \end{itemize} |
| 37 |
% |
| 38 |
% |
| 39 |
% |
| 40 |
% \subsection{Defining the math style macros} |
| 41 |
% |
| 42 |
% We call the different shapes that a math alphabet can be a `math style’. |
| 43 |
% Note that different alphabets can exist within the same math style. E.g., |
| 44 |
% we call `bold’ the math style |bf| and within it there are upper and lower |
| 45 |
% case Greek and Roman alphabets and Arabic numerals. |
| 46 |
% |
| 47 |
% \begin{macro}{\@@_prepare_mathstyle:n} |
| 48 |
% \darg{math style name (e.g., \texttt{it} or \texttt{bb})} |
| 49 |
% Define the high level math alphabet macros (\cs{mathit}, etc.) in terms of |
| 50 |
% unicode-math definitions. Use \cs{bgroup}/\cs{egroup} so s’scripts scan the |
| 51 |
% whole thing. |
| 52 |
% |
| 53 |
% The flag \cs{l_@@_mathstyle_tl} is for other applications to query the |
| 54 |
% current math style. |
| 55 |
% \begin{macrocode} |
| 56 |
\@@_cs_new:Nn \@@_prepare_mathstyle:n |
| 57 |
{ |
| 58 |
\seq_gput_right:Nn \g_@@_mathstyles_seq {#1} |
| 59 |
\@@_init_alphabet:n {#1} |
| 60 |
\cs_set_protected:cpx {sym#1} |
| 61 |
{ |
| 62 |
\@@_group_begin: |
| 63 |
\exp_not:n |
| 64 |
{ |
| 65 |
\mode_if_math:F { \exp_args:Nc \non@alpherr {sym#1} } |
| 66 |
\tl_set:Nn \l_@@_mathstyle_tl {#1} |
| 67 |
} |
| 68 |
\@@_switch_to:n {#1} |
| 69 |
\@@_mathgroup_set:n {-1} |
| 70 |
\@@_group_end:n |
| 71 |
} |
| 72 |
} |
| 73 |
% \end{macrocode} |
| 74 |
% \end{macro} |
| 75 |
% |
| 76 |
% |
| 77 |
% \begin{macro}{\@@_init_alphabet:n} |
| 78 |
% \darg{math alphabet name (e.g., \texttt{it} or \texttt{bb})} |
| 79 |
% This macro initialises the macros used to set up a math alphabet. |
| 80 |
% First used when the math alphabet macro is first defined, but then used |
| 81 |
% later when redefining a particular maths alphabet. |
| 82 |
% \begin{macrocode} |
| 83 |
\@@_cs_new:Nn \@@_init_alphabet:n |
| 84 |
{ |
| 85 |
\@@_log:nx {alph-initialise} {#1} |
| 86 |
\tl_gclear_new:c {g_@@_switchto_#1_tl} |
| 87 |
\cs_set_protected:cpn {@@_switchto_#1:} { \tl_use:c {g_@@_switchto_#1_tl} } |
| 88 |
} |
| 89 |
\cs_new_protected:Nn \@@_switch_to:n |
| 90 |
{ |
| 91 |
\tl_use:c {g_@@_switchto_#1_tl} |
| 92 |
} |
| 93 |
% \end{macrocode} |
| 94 |
% \end{macro} |
| 95 |
% |
| 96 |
% \subsection{Definition of alphabets and styles} |
| 97 |
% |
| 98 |
% |
| 99 |
% The linking between named ranges and symbol style commands happens here. |
| 100 |
% It’s currently not using all of the machinery we’re in the process of setting up above. |
| 101 |
% Baby steps. |
| 102 |
% \begin{macrocode} |
| 103 |
\@@_cs_new:Nn \@@_default_mathalph:nnn |
| 104 |
{ |
| 105 |
\prop_new:c {g_@@_named_range_#1_prop} |
| 106 |
\seq_gput_right:Nn \g_@@_default_mathalph_seq {{#1}{#2}{#3}} |
| 107 |
\prop_gput:cnn { g_@@_named_range_#1_prop } { default-alpha } {#2} |
| 108 |
} |
| 109 |
% \end{macrocode} |
| 110 |
% \begin{macrocode} |
| 111 |
\@@_default_mathalph:nnn {up } {latin,Latin,greek,Greek,num,misc} {up } |
| 112 |
\@@_default_mathalph:nnn {it } {latin,Latin,greek,Greek,misc} {it } |
| 113 |
\@@_default_mathalph:nnn {bb } {latin,Latin,num,misc} {bb } |
| 114 |
\@@_default_mathalph:nnn {bbit } {misc} {bbit } |
| 115 |
\@@_default_mathalph:nnn {scr } {latin,Latin} {scr } |
| 116 |
\@@_default_mathalph:nnn {cal } {latin,Latin} {scr } |
| 117 |
\@@_default_mathalph:nnn {bfcal } {latin,Latin} {bfscr } |
| 118 |
\@@_default_mathalph:nnn {frak } {latin,Latin} {frak } |
| 119 |
\@@_default_mathalph:nnn {tt } {latin,Latin,num} {tt } |
| 120 |
\@@_default_mathalph:nnn {sfup } {latin,Latin,num} {sfup } |
| 121 |
\@@_default_mathalph:nnn {sfit } {latin,Latin} {sfit } |
| 122 |
\@@_default_mathalph:nnn {bfup } {latin,Latin,greek,Greek,num,misc} {bfup } |
| 123 |
\@@_default_mathalph:nnn {bfit } {latin,Latin,greek,Greek,misc} {bfit } |
| 124 |
\@@_default_mathalph:nnn {bfscr } {latin,Latin} {bfscr } |
| 125 |
\@@_default_mathalph:nnn {bffrak} {latin,Latin} {bffrak} |
| 126 |
\@@_default_mathalph:nnn {bfsfup} {latin,Latin,greek,Greek,num,misc} {bfsfup} |
| 127 |
\@@_default_mathalph:nnn {bfsfit} {latin,Latin,greek,Greek,misc} {bfsfit} |
| 128 |
% \end{macrocode} |
| 129 |
% |
| 130 |
% \subsubsection{Define symbol style commands} |
| 131 |
% Finally, all of the `symbol styles’ commands are set up, which are the commands to access each of the named alphabet styles. There is not a one-to-one mapping between symbol style commands and named style ranges! |
| 132 |
% \begin{macrocode} |
| 133 |
\clist_map_inline:nn |
| 134 |
{ |
| 135 |
up, it, bfup, bfit, sfup, sfit, bfsfup, bfsfit, bfsf, |
| 136 |
tt, bb, bbit, scr, bfscr, cal, bfcal, frak, bffrak, |
| 137 |
normal, literal, sf, bf, |
| 138 |
} |
| 139 |
{ |
| 140 |
\@@_prepare_mathstyle:n {#1} |
| 141 |
} |
| 142 |
% \end{macrocode} |
| 143 |
% |
| 144 |
% |
| 145 |
% \subsubsection{New names for legacy textmath alphabet selection} |
| 146 |
% In case a package option overwrites, say, \cs{mathbf} with \cs{symbf}. |
| 147 |
% \begin{macrocode} |
| 148 |
\clist_map_inline:nn |
| 149 |
{ rm, it, bf, sf, tt } |
| 150 |
{ \cs_set_eq:cc { mathtext #1 } { math #1 } } |
| 151 |
% \end{macrocode} |
| 152 |
% Perhaps these should actually be defined using a hypothetical unicode-math interface to creating new such styles. To come. |
| 153 |
% |
| 154 |
% |
| 155 |
% \subsubsection{Replacing legacy pure-maths alphabets} |
| 156 |
% The following are alphabets which do not have a math/text ambiguity. |
| 157 |
% \begin{macrocode} |
| 158 |
\clist_map_inline:nn |
| 159 |
{ |
| 160 |
normal, bb , bbit, scr, bfscr, cal, bfcal, frak, bffrak, tt, |
| 161 |
bfup, bfit, sfup, sfit, bfsfup, bfsfit, bfsf |
| 162 |
} |
| 163 |
{ |
| 164 |
\cs_set:cpx { math #1 } { \exp_not:c { sym #1 } } |
| 165 |
} |
| 166 |
% \end{macrocode} |
| 167 |
% |
| 168 |
% |
| 169 |
% \subsubsection{New commands for ambiguous alphabets} |
| 170 |
% |
| 171 |
% \begin{macrocode} |
| 172 |
\AtBeginDocument { \@@_setup_mathtext: } |
| 173 |
\@@_cs_new:Nn \@@_setup_mathtext: |
| 174 |
{ |
| 175 |
\clist_map_inline:nn |
| 176 |
{ rm, it, bf, sf, tt } |
| 177 |
{ |
| 178 |
\cs_set_protected:cpx { math ##1 } |
| 179 |
{ |
| 180 |
\exp_not:n { \bool_if:NTF } \exp_not:c { g_@@_ math ##1 _text_bool} |
| 181 |
{ \exp_not:c { mathtext ##1 } } |
| 182 |
{ \exp_not:c { sym ##1 } } |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
% \end{macrocode} |
| 187 |
% |
| 188 |
% \paragraph{Alias \cs{mathrm} as legacy name for \cs{mathup}} |
| 189 |
% \begin{macrocode} |
| 190 |
\cs_set_protected:Npn \mathup { \mathrm } |
| 191 |
\cs_set_protected:Npn \symrm { \symup } |
| 192 |
% \end{macrocode} |
| 193 |
% |
| 194 |
% |
| 195 |
% \begin{macrocode} |
| 196 |
%</package> |
| 197 |
% \end{macrocode} |
| 198 |
|
| 199 |
\endinput |
| 200 |
|
| 201 |
% /© |
| 202 |
% |
| 203 |
% ------------------------------------------------ |
| 204 |
% The UNICODE-MATH package <wspr.io/unicode-math> |
| 205 |
% ------------------------------------------------ |
| 206 |
% This package is free software and may be redistributed and/or modified under |
| 207 |
% the conditions of the LaTeX Project Public License, version 1.3c or higher |
| 208 |
% (your choice): <http://www.latex-project.org/lppl/>. |
| 209 |
% ------------------------------------------------ |
| 210 |
% Copyright 2006-2019 Will Robertson, LPPL "maintainer" |
| 211 |
% Copyright 2010-2017 Philipp Stephani |
| 212 |
% Copyright 2011-2017 Joseph Wright |
| 213 |
% Copyright 2012-2015 Khaled Hosny |
| 214 |
% ------------------------------------------------ |
| 215 |
% |
| 216 |
% ©/ |