%%^^A%% um-code-sym-commands.dtx -- part of UNICODE-MATH %%^^A%% Definition of "math symbol alphabet" commands such as `\symbf` and co. % \section{Mapping in maths alphabets} % \label{sec:symcmd} % % \begin{macrocode} %<*package> % \end{macrocode} % % % \subsection{Setting styles} % % Algorithm for setting alphabet fonts. % By default, when |range| is empty, we are in \emph{implicit} mode. % If |range| contains the name of the math alphabet, we are in \emph{explicit} % mode and do things slightly differently. % % Implicit mode: % \begin{itemize} % \item Try and set all of the alphabet shapes. % \item Check for the first glyph of each alphabet to detect if the font supports each % alphabet shape. % \item For alphabets that do exist, overwrite whatever’s already there. % \item For alphabets that are not supported, \emph{do nothing}. % (This includes leaving the old alphabet definition in place.) % \end{itemize} % % Explicit mode: % \begin{itemize} % \item Only set the alphabets specified. % \item Check for the first glyph of the alphabet to detect if the font contains % the alphabet shape in the Unicode math plane. % \item For Unicode math alphabets, overwrite whatever’s already there. % \item Otherwise, use the \ascii\ glyph slots instead. % \end{itemize} % % % % \subsection{Defining the math style macros} % % We call the different shapes that a math alphabet can be a `math style’. % Note that different alphabets can exist within the same math style. E.g., % we call `bold’ the math style |bf| and within it there are upper and lower % case Greek and Roman alphabets and Arabic numerals. % % \begin{macro}{\@@_prepare_mathstyle:n} % \darg{math style name (e.g., \texttt{it} or \texttt{bb})} % Define the high level math alphabet macros (\cs{mathit}, etc.) in terms of % unicode-math definitions. Use \cs{bgroup}/\cs{egroup} so s’scripts scan the % whole thing. % % The flag \cs{l_@@_mathstyle_tl} is for other applications to query the % current math style. % \begin{macrocode} \@@_cs_new:Nn \@@_prepare_mathstyle:n { \seq_gput_right:Nn \g_@@_mathstyles_seq {#1} \@@_init_alphabet:n {#1} \cs_set_protected:cpx {sym#1} { \@@_group_begin: \exp_not:n { \mode_if_math:F { \exp_args:Nc \non@alpherr {sym#1} } \tl_set:Nn \l_@@_mathstyle_tl {#1} } \@@_switch_to:n {#1} \@@_mathgroup_set:n {-1} \@@_group_end:n } } % \end{macrocode} % \end{macro} % % % \begin{macro}{\@@_init_alphabet:n} % \darg{math alphabet name (e.g., \texttt{it} or \texttt{bb})} % This macro initialises the macros used to set up a math alphabet. % First used when the math alphabet macro is first defined, but then used % later when redefining a particular maths alphabet. % \begin{macrocode} \@@_cs_new:Nn \@@_init_alphabet:n { \@@_log:nx {alph-initialise} {#1} \tl_gclear_new:c {g_@@_switchto_#1_tl} \cs_set_protected:cpn {@@_switchto_#1:} { \tl_use:c {g_@@_switchto_#1_tl} } } \cs_new_protected:Nn \@@_switch_to:n { \tl_use:c {g_@@_switchto_#1_tl} } % \end{macrocode} % \end{macro} % % \subsection{Definition of alphabets and styles} % % % The linking between named ranges and symbol style commands happens here. % It’s currently not using all of the machinery we’re in the process of setting up above. % Baby steps. % \begin{macrocode} \@@_cs_new:Nn \@@_default_mathalph:nnn { \prop_new:c {g_@@_named_range_#1_prop} \seq_gput_right:Nn \g_@@_default_mathalph_seq {{#1}{#2}{#3}} \prop_gput:cnn { g_@@_named_range_#1_prop } { default-alpha } {#2} } % \end{macrocode} % \begin{macrocode} \@@_default_mathalph:nnn {up } {latin,Latin,greek,Greek,num,misc} {up } \@@_default_mathalph:nnn {it } {latin,Latin,greek,Greek,misc} {it } \@@_default_mathalph:nnn {bb } {latin,Latin,num,misc} {bb } \@@_default_mathalph:nnn {bbit } {misc} {bbit } \@@_default_mathalph:nnn {scr } {latin,Latin} {scr } \@@_default_mathalph:nnn {cal } {latin,Latin} {scr } \@@_default_mathalph:nnn {bfcal } {latin,Latin} {bfscr } \@@_default_mathalph:nnn {frak } {latin,Latin} {frak } \@@_default_mathalph:nnn {tt } {latin,Latin,num} {tt } \@@_default_mathalph:nnn {sfup } {latin,Latin,num} {sfup } \@@_default_mathalph:nnn {sfit } {latin,Latin} {sfit } \@@_default_mathalph:nnn {bfup } {latin,Latin,greek,Greek,num,misc} {bfup } \@@_default_mathalph:nnn {bfit } {latin,Latin,greek,Greek,misc} {bfit } \@@_default_mathalph:nnn {bfscr } {latin,Latin} {bfscr } \@@_default_mathalph:nnn {bffrak} {latin,Latin} {bffrak} \@@_default_mathalph:nnn {bfsfup} {latin,Latin,greek,Greek,num,misc} {bfsfup} \@@_default_mathalph:nnn {bfsfit} {latin,Latin,greek,Greek,misc} {bfsfit} % \end{macrocode} % % \subsubsection{Define symbol style commands} % 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! % \begin{macrocode} \clist_map_inline:nn { up, it, bfup, bfit, sfup, sfit, bfsfup, bfsfit, bfsf, tt, bb, bbit, scr, bfscr, cal, bfcal, frak, bffrak, normal, literal, sf, bf, } { \@@_prepare_mathstyle:n {#1} } % \end{macrocode} % % % \subsubsection{New names for legacy textmath alphabet selection} % In case a package option overwrites, say, \cs{mathbf} with \cs{symbf}. % \begin{macrocode} \clist_map_inline:nn { rm, it, bf, sf, tt } { \cs_set_eq:cc { mathtext #1 } { math #1 } } % \end{macrocode} % Perhaps these should actually be defined using a hypothetical unicode-math interface to creating new such styles. To come. % % % \subsubsection{Replacing legacy pure-maths alphabets} % The following are alphabets which do not have a math/text ambiguity. % \begin{macrocode} \clist_map_inline:nn { normal, bb , bbit, scr, bfscr, cal, bfcal, frak, bffrak, tt, bfup, bfit, sfup, sfit, bfsfup, bfsfit, bfsf } { \cs_set:cpx { math #1 } { \exp_not:c { sym #1 } } } % \end{macrocode} % % % \subsubsection{New commands for ambiguous alphabets} % % \begin{macrocode} \AtBeginDocument { \@@_setup_mathtext: } \@@_cs_new:Nn \@@_setup_mathtext: { \clist_map_inline:nn { rm, it, bf, sf, tt } { \cs_set_protected:cpx { math ##1 } { \exp_not:n { \bool_if:NTF } \exp_not:c { g_@@_ math ##1 _text_bool} { \exp_not:c { mathtext ##1 } } { \exp_not:c { sym ##1 } } } } } % \end{macrocode} % % \paragraph{Alias \cs{mathrm} as legacy name for \cs{mathup}} % \begin{macrocode} \cs_set_protected:Npn \mathup { \mathrm } \cs_set_protected:Npn \symrm { \symup } % \end{macrocode} % % % \begin{macrocode} % % \end{macrocode} \endinput % /© % % ------------------------------------------------ % The UNICODE-MATH package % ------------------------------------------------ % This package is free software and may be redistributed and/or modified under % the conditions of the LaTeX Project Public License, version 1.3c or higher % (your choice): . % ------------------------------------------------ % Copyright 2006-2019 Will Robertson, LPPL "maintainer" % Copyright 2010-2017 Philipp Stephani % Copyright 2011-2017 Joseph Wright % Copyright 2012-2015 Khaled Hosny % ------------------------------------------------ % % ©/