%%
%% This is file `unicode-math.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% unicode-math.dtx  (with options: `package')
%% Copyright 2006-2010 by Will Robertson <will.robertson@latex-project.org>
%% 
%% 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): <http://www.latex-project.org/lppl/>.
%% 
%% This work is "author-maintained" by Will Robertson.
\ProvidesPackage{unicode-math}
  [2010/06/03 v0.5 Unicode maths in XeLaTeX]
\usepackage{ifxetex,ifluatex}
\ifxetex\else\ifluatex\else
  \PackageError{unicode-math}{%
    Cannot be run with pdfLaTeX!\MessageBreak
    Use XeLaTeX or LuaLaTeX instead.%
  }\@ehd
\fi\fi
\RequirePackage{expl3}[2009/08/12]
\RequirePackage{xparse}[2009/08/31]
\RequirePackage{l3keys2e}
\RequirePackage{fontspec}[2010/05/18]
\ExplSyntaxOn
\@ifclassloaded{memoir}{
  \cs_set_eq:NN \um_after_pkg:nn \AtEndPackage
}{
  \RequirePackage{scrlfile}
  \cs_set_eq:NN \um_after_pkg:nn \AfterPackage
}
\cs_generate_variant:Nn \tl_put_right:Nn {cx}
\cs_generate_variant:Nn \seq_if_in:NnTF {NV}
\cs_generate_variant:Nn \prop_gput:Nnn {Nxn}
\cs_generate_variant:Nn \prop_get:NnN {cxN}
\cs_generate_variant:Nn \prop_if_in:NnTF {cx}
\cs_new:Npn \exp_args:NNcc #1#2#3#4 {
  \exp_after:wN #1 \exp_after:wN #2
    \cs:w #3 \exp_after:wN \cs_end:
    \cs:w #4 \cs_end:
}
\bool_new:N \l_um_fontspec_feature_bool
\bool_new:N \l_um_ot_math_bool
\bool_new:N \l_um_init_bool
\bool_new:N \l_um_implicit_alph_bool
\bool_new:N \g_um_literal_bool
\bool_new:N \g_um_upLatin_bool
\bool_new:N \g_um_uplatin_bool
\bool_new:N \g_um_upGreek_bool
\bool_new:N \g_um_upgreek_bool
\bool_new:N \g_um_bfliteral_bool
\bool_new:N \g_um_bfupLatin_bool
\bool_new:N \g_um_bfuplatin_bool
\bool_new:N \g_um_bfupGreek_bool
\bool_new:N \g_um_bfupgreek_bool
\bool_new:N \g_um_upsans_bool
\bool_new:N \g_um_sfliteral_bool
\bool_new:N \g_um_upNabla_bool
\bool_new:N \g_um_uppartial_bool
\bool_new:N \g_um_literal_Nabla_bool
\bool_new:N \g_um_literal_partial_bool
\bool_new:N \g_um_texgreek_bool
\bool_new:N \l_um_smallfrac_bool
\bool_new:N \g_um_literal_colon_bool
\int_new:N \g_um_fam_int
\tl_set:Nn \g_um_math_alphabet_name_latin_tl {Latin,~lowercase}
\tl_set:Nn \g_um_math_alphabet_name_Latin_tl {Latin,~uppercase}
\tl_set:Nn \g_um_math_alphabet_name_greek_tl {Greek,~lowercase}
\tl_set:Nn \g_um_math_alphabet_name_Greek_tl {Greek,~uppercase}
\tl_set:Nn \g_um_math_alphabet_name_num_tl   {Numerals}
\tl_set:Nn \g_um_math_alphabet_name_misc_tl  {Misc.}
\prg_new_conditional:Nnn \um_glyph_if_exist:n {p,TF,T,F} {
  \etex_iffontchar:D \l_um_font #1 \scan_stop:
    \prg_return_true:
  \else:
    \prg_return_false:
  \fi:
}
\cs_generate_variant:Nn \um_glyph_if_exist_p:n {c}
\cs_generate_variant:Nn \um_glyph_if_exist:nTF {c}
\cs_generate_variant:Nn \um_glyph_if_exist:nT  {c}
\cs_generate_variant:Nn \um_glyph_if_exist:nF  {c}
\xetex_or_luatex:nnn { \cs_new:Npn \um_cs_compat:n #1 }
  { \cs_set_eq:cc {U#1} {XeTeX#1}   }
  { \cs_set_eq:cc {U#1} {luatexU#1} }
\um_cs_compat:n {mathcode}
\um_cs_compat:n {delcode}
\um_cs_compat:n {mathcodenum}
\um_cs_compat:n {mathcharnum}
\um_cs_compat:n {mathchardef}
\um_cs_compat:n {radical}
\um_cs_compat:n {mathaccent}
\um_cs_compat:n {delimiter}
\cs_generate_variant:Nn \fontspec_select:nn {x}
\cs_new:Npn \usv_set:nnn #1#2#3 {
  \tl_set:cn { \um_to_usv:nn {#1}{#2} } {#3}
}
\cs_new:Npn \um_to_usv:nn #1#2 { g_um_#1_#2_usv }
\usv_set:nnn {up}{num}{48}
\usv_set:nnn {up}{Latin}{65}
\usv_set:nnn {up}{latin}{97}
\usv_set:nnn {up}{Greek}{"391}
\usv_set:nnn {up}{greek}{"3B1}
\usv_set:nnn {it}{Latin}{"1D434}
\usv_set:nnn {it}{latin}{"1D44E}
\usv_set:nnn {it}{Greek}{"1D6E2}
\usv_set:nnn {it}{greek}{"1D6FC}
\usv_set:nnn {bb}{num}{"1D7D8}
\usv_set:nnn {bb}{Latin}{"1D538}
\usv_set:nnn {bb}{latin}{"1D552}
\usv_set:nnn {scr}{Latin}{"1D49C}
\usv_set:nnn {scr}{latin}{"1D4B6}
\usv_set:nnn {frak}{Latin}{"1D504}
\usv_set:nnn {frak}{latin}{"1D51E}
\usv_set:nnn {sf}{num}{"1D7E2}
\usv_set:nnn {sfup}{num}{"1D7E2}
\usv_set:nnn {sfit}{num}{"1D7E2}
\usv_set:nnn {sfup}{Latin}{"1D5A0}
\usv_set:nnn {sf}{Latin}{"1D5A0}
\usv_set:nnn {sfup}{latin}{"1D5BA}
\usv_set:nnn {sf}{latin}{"1D5BA}
\usv_set:nnn {sfit}{Latin}{"1D608}
\usv_set:nnn {sfit}{latin}{"1D622}
\usv_set:nnn {tt}{num}{"1D7F6}
\usv_set:nnn {tt}{Latin}{"1D670}
\usv_set:nnn {tt}{latin}{"1D68A}
\usv_set:nnn {bf}{num}{"1D7CE}
\usv_set:nnn {bfup}{num}{"1D7CE}
\usv_set:nnn {bfit}{num}{"1D7CE}
\usv_set:nnn {bfup}{Latin}{"1D400}
\usv_set:nnn {bfup}{latin}{"1D41A}
\usv_set:nnn {bfup}{Greek}{"1D6A8}
\usv_set:nnn {bfup}{greek}{"1D6C2}
\usv_set:nnn {bfit}{Latin}{"1D468}
\usv_set:nnn {bfit}{latin}{"1D482}
\usv_set:nnn {bfit}{Greek}{"1D71C}
\usv_set:nnn {bfit}{greek}{"1D736}
\usv_set:nnn {bffrak}{Latin}{"1D56C}
\usv_set:nnn {bffrak}{latin}{"1D586}
\usv_set:nnn {bfscr}{Latin}{"1D4D0}
\usv_set:nnn {bfscr}{latin}{"1D4EA}
\usv_set:nnn {bfsf}{num}{"1D7EC}
\usv_set:nnn {bfsfup}{num}{"1D7EC}
\usv_set:nnn {bfsfit}{num}{"1D7EC}
\usv_set:nnn {bfsfup}{Latin}{"1D5D4}
\usv_set:nnn {bfsfup}{latin}{"1D5EE}
\usv_set:nnn {bfsfup}{Greek}{"1D756}
\usv_set:nnn {bfsfup}{greek}{"1D770}
\usv_set:nnn {bfsfit}{Latin}{"1D63C}
\usv_set:nnn {bfsfit}{latin}{"1D656}
\usv_set:nnn {bfsfit}{Greek}{"1D790}
\usv_set:nnn {bfsfit}{greek}{"1D7AA}
\usv_set:nnn {bfsf}{Latin}{ \bool_if:NTF \g_um_upLatin_bool \g_um_bfsfup_Latin_usv \g_um_bfsfit_Latin_usv }
\usv_set:nnn {bfsf}{latin}{ \bool_if:NTF \g_um_uplatin_bool \g_um_bfsfup_latin_usv \g_um_bfsfit_latin_usv }
\usv_set:nnn {bfsf}{Greek}{ \bool_if:NTF \g_um_upGreek_bool \g_um_bfsfup_Greek_usv \g_um_bfsfit_Greek_usv }
\usv_set:nnn {bfsf}{greek}{ \bool_if:NTF \g_um_upgreek_bool \g_um_bfsfup_greek_usv \g_um_bfsfit_greek_usv }
\usv_set:nnn {bf}{Latin}{ \bool_if:NTF \g_um_bfupLatin_bool \g_um_bfup_Latin_usv \g_um_bfit_Latin_usv }
\usv_set:nnn {bf}{latin}{ \bool_if:NTF \g_um_bfuplatin_bool \g_um_bfup_latin_usv \g_um_bfit_latin_usv }
\usv_set:nnn {bf}{Greek}{ \bool_if:NTF \g_um_bfupGreek_bool \g_um_bfup_Greek_usv \g_um_bfit_Greek_usv }
\usv_set:nnn {bf}{greek}{ \bool_if:NTF \g_um_bfupgreek_bool \g_um_bfup_greek_usv \g_um_bfit_greek_usv }
\usv_set:nnn {up}{varTheta}{"3F4}
\usv_set:nnn {up}{Digamma}{"3DC}
\usv_set:nnn {up}{varepsilon}{"3F5}
\usv_set:nnn {up}{vartheta}{"3D1}
\usv_set:nnn {up}{varkappa}{"3F0}
\usv_set:nnn {up}{varphi}{"3D5}
\usv_set:nnn {up}{varrho}{"3F1}
\usv_set:nnn {up}{varpi}{"3D6}
\usv_set:nnn {up}{digamma}{"3DD}
\usv_set:nnn {bfup}{varTheta}{"1D6B9}
\usv_set:nnn {bfup}{Digamma}{"1D7CA}
\usv_set:nnn {bfup}{varepsilon}{"1D6DC}
\usv_set:nnn {bfup}{vartheta}{"1D6DD}
\usv_set:nnn {bfup}{varkappa}{"1D6DE}
\usv_set:nnn {bfup}{varphi}{"1D6DF}
\usv_set:nnn {bfup}{varrho}{"1D6E0}
\usv_set:nnn {bfup}{varpi}{"1D6E1}
\usv_set:nnn {bfup}{digamma}{"1D7CB}
\usv_set:nnn {it}{varTheta}{"1D6F3}
\usv_set:nnn {it}{varepsilon}{"1D716}
\usv_set:nnn {it}{vartheta}{"1D717}
\usv_set:nnn {it}{varkappa}{"1D718}
\usv_set:nnn {it}{varphi}{"1D719}
\usv_set:nnn {it}{varrho}{"1D71A}
\usv_set:nnn {it}{varpi}{"1D71B}
\usv_set:nnn {bfit}{varTheta}{"1D72D}
\usv_set:nnn {bfit}{varepsilon}{"1D750}
\usv_set:nnn {bfit}{vartheta}{"1D751}
\usv_set:nnn {bfit}{varkappa}{"1D752}
\usv_set:nnn {bfit}{varphi}{"1D753}
\usv_set:nnn {bfit}{varrho}{"1D754}
\usv_set:nnn {bfit}{varpi}{"1D755}
\usv_set:nnn {bfsfup}{varTheta}{"1D767}
\usv_set:nnn {bfsfup}{varepsilon}{"1D78A}
\usv_set:nnn {bfsfup}{vartheta}{"1D78B}
\usv_set:nnn {bfsfup}{varkappa}{"1D78C}
\usv_set:nnn {bfsfup}{varphi}{"1D78D}
\usv_set:nnn {bfsfup}{varrho}{"1D78E}
\usv_set:nnn {bfsfup}{varpi}{"1D78F}
\usv_set:nnn {bfsfit}{varTheta}  {"1D7A1}
\usv_set:nnn {bfsfit}{varepsilon}{"1D7C4}
\usv_set:nnn {bfsfit}{vartheta}  {"1D7C5}
\usv_set:nnn {bfsfit}{varkappa}  {"1D7C6}
\usv_set:nnn {bfsfit}{varphi}    {"1D7C7}
\usv_set:nnn {bfsfit}{varrho}    {"1D7C8}
\usv_set:nnn {bfsfit}{varpi}     {"1D7C9}
\usv_set:nnn {up}    {Nabla}{"02207}
\usv_set:nnn {it}    {Nabla}{"1D6FB}
\usv_set:nnn {bfup}  {Nabla}{"1D6C1}
\usv_set:nnn {bfit}  {Nabla}{"1D735}
\usv_set:nnn {bfsfup}{Nabla}{"1D76F}
\usv_set:nnn {bfsfit}{Nabla}{"1D7A9}
\usv_set:nnn {up}    {partial}{"02202}
\usv_set:nnn {it}    {partial}{"1D715}
\usv_set:nnn {bfup}  {partial}{"1D6DB}
\usv_set:nnn {bfit}  {partial}{"1D74F}
\usv_set:nnn {bfsfup}{partial}{"1D789}
\usv_set:nnn {bfsfit}{partial}{"1D7C3}
\usv_set:nnn {up}{B}{`\B}
\usv_set:nnn {up}{C}{`\C}
\usv_set:nnn {up}{D}{`\D}
\usv_set:nnn {up}{E}{`\E}
\usv_set:nnn {up}{F}{`\F}
\usv_set:nnn {up}{H}{`\H}
\usv_set:nnn {up}{I}{`\I}
\usv_set:nnn {up}{L}{`\L}
\usv_set:nnn {up}{M}{`\M}
\usv_set:nnn {up}{N}{`\N}
\usv_set:nnn {up}{P}{`\P}
\usv_set:nnn {up}{Q}{`\Q}
\usv_set:nnn {up}{R}{`\R}
\usv_set:nnn {up}{Z}{`\Z}
\usv_set:nnn {it}{B}{"1D435}
\usv_set:nnn {it}{C}{"1D436}
\usv_set:nnn {it}{D}{"1D437}
\usv_set:nnn {it}{E}{"1D438}
\usv_set:nnn {it}{F}{"1D439}
\usv_set:nnn {it}{H}{"1D43B}
\usv_set:nnn {it}{I}{"1D43C}
\usv_set:nnn {it}{L}{"1D43F}
\usv_set:nnn {it}{M}{"1D440}
\usv_set:nnn {it}{N}{"1D441}
\usv_set:nnn {it}{P}{"1D443}
\usv_set:nnn {it}{Q}{"1D444}
\usv_set:nnn {it}{R}{"1D445}
\usv_set:nnn {it}{Z}{"1D44D}
\usv_set:nnn {up}{d}{`\d}
\usv_set:nnn {up}{e}{`\e}
\usv_set:nnn {up}{g}{`\g}
\usv_set:nnn {up}{h}{`\h}
\usv_set:nnn {up}{i}{`\i}
\usv_set:nnn {up}{j}{`\j}
\usv_set:nnn {up}{o}{`\o}
\usv_set:nnn {it}{d}{"1D451}
\usv_set:nnn {it}{e}{"1D452}
\usv_set:nnn {it}{g}{"1D454}
\usv_set:nnn {it}{h}{"0210E}
\usv_set:nnn {it}{i}{"1D456}
\usv_set:nnn {it}{j}{"1D457}
\usv_set:nnn {it}{o}{"1D45C}
\usv_set:nnn {bb}    {h}{"1D559}
\usv_set:nnn {tt}    {h}{"1D691}
\usv_set:nnn {scr}   {h}{"1D4BD}
\usv_set:nnn {frak}  {h}{"1D525}
\usv_set:nnn {bfup}  {h}{"1D421}
\usv_set:nnn {bfit}  {h}{"1D489}
\usv_set:nnn {sfup}  {h}{"1D5C1}
\usv_set:nnn {sfit}  {h}{"1D629}
\usv_set:nnn {bffrak}{h}{"1D58D}
\usv_set:nnn {bfscr} {h}{"1D4F1}
\usv_set:nnn {bfsfup}{h}{"1D5F5}
\usv_set:nnn {bfsfit}{h}{"1D65D}
\usv_set:nnn {up}{dotlessi}{"00131}
\usv_set:nnn {up}{dotlessj}{"00237}
\usv_set:nnn {it}{dotlessi}{"1D6A4}
\usv_set:nnn {it}{dotlessj}{"1D6A5}
\usv_set:nnn {bb}{C}{"2102}
\usv_set:nnn {bb}{H}{"210D}
\usv_set:nnn {bb}{N}{"2115}
\usv_set:nnn {bb}{P}{"2119}
\usv_set:nnn {bb}{Q}{"211A}
\usv_set:nnn {bb}{R}{"211D}
\usv_set:nnn {bb}{Z}{"2124}
\usv_set:nnn {up}{Pi}       {"003A0}
\usv_set:nnn {up}{pi}       {"003C0}
\usv_set:nnn {up}{Gamma}    {"00393}
\usv_set:nnn {up}{gamma}    {"003B3}
\usv_set:nnn {up}{summation}{"02211}
\usv_set:nnn {it}{Pi}       {"1D6F1}
\usv_set:nnn {it}{pi}       {"1D70B}
\usv_set:nnn {it}{Gamma}    {"1D6E4}
\usv_set:nnn {it}{gamma}    {"1D6FE}
\usv_set:nnn {bb}{Pi}       {"0213F}
\usv_set:nnn {bb}{pi}       {"0213C}
\usv_set:nnn {bb}{Gamma}    {"0213E}
\usv_set:nnn {bb}{gamma}    {"0213D}
\usv_set:nnn {bb}{summation}{"02140}
\usv_set:nnn {bbit}{D}{"2145}
\usv_set:nnn {bbit}{d}{"2146}
\usv_set:nnn {bbit}{e}{"2147}
\usv_set:nnn {bbit}{i}{"2148}
\usv_set:nnn {bbit}{j}{"2149}
\usv_set:nnn {scr}{B}{"212C}
\usv_set:nnn {scr}{E}{"2130}
\usv_set:nnn {scr}{F}{"2131}
\usv_set:nnn {scr}{H}{"210B}
\usv_set:nnn {scr}{I}{"2110}
\usv_set:nnn {scr}{L}{"2112}
\usv_set:nnn {scr}{M}{"2133}
\usv_set:nnn {scr}{R}{"211B}
\usv_set:nnn {scr}{e}{"212F}
\usv_set:nnn {scr}{g}{"210A}
\usv_set:nnn {scr}{o}{"2134}
\usv_set:nnn {frak}{C}{"212D}
\usv_set:nnn {frak}{H}{"210C}
\usv_set:nnn {frak}{I}{"2111}
\usv_set:nnn {frak}{R}{"211C}
\usv_set:nnn {frak}{Z}{"2128}
\DeclareDocumentCommand \unimathsetup {m} {
  \clist_clear:N \l_um_unknown_keys_clist
  \keys_set:nn {unicode-math} {#1}
}
\keys_define:nn {unicode-math} {
  normal-style .choice_code:n =
  {
    \bool_set_false:N \g_um_literal_bool
    \ifcase \l_keys_choice_int
      \bool_set_false:N \g_um_upGreek_bool
      \bool_set_false:N \g_um_upgreek_bool
      \bool_set_false:N \g_um_upLatin_bool
      \bool_set_false:N \g_um_uplatin_bool
    \or
      \bool_set_true:N \g_um_upGreek_bool
      \bool_set_false:N \g_um_upgreek_bool
      \bool_set_false:N \g_um_upLatin_bool
      \bool_set_false:N \g_um_uplatin_bool
    \or
      \bool_set_true:N \g_um_upGreek_bool
      \bool_set_true:N \g_um_upgreek_bool
      \bool_set_true:N \g_um_upLatin_bool
      \bool_set_false:N \g_um_uplatin_bool
    \or
      \bool_set_true:N \g_um_upGreek_bool
      \bool_set_true:N \g_um_upgreek_bool
      \bool_set_true:N \g_um_upLatin_bool
      \bool_set_true:N \g_um_uplatin_bool
    \or
      \bool_set_true:N \g_um_literal_bool
    \fi
  } ,
  normal-style .generate_choices:n = {ISO,TeX,french,upright,literal} ,
}
\keys_define:nn {unicode-math} {
  math-style .choice_code:n =
  {
    \ifcase \l_keys_choice_int
      \unimathsetup {
        normal-style=ISO,
        bold-style=ISO,
        sans-style=italic,
        nabla=upright,
        partial=italic,
      }
    \or
      \unimathsetup {
        normal-style=TeX,
        bold-style=TeX,
        sans-style=upright,
        nabla=upright,
        partial=italic,
      }
    \or
      \unimathsetup {
        normal-style=french,
        bold-style=upright,
        sans-style=upright,
        nabla=upright,
        partial=upright,
      }
    \or
      \unimathsetup {
        normal-style=upright,
        bold-style=upright,
        sans-style=upright,
        nabla=upright,
        partial=upright,
      }
    \or
      \unimathsetup {
        normal-style=literal,
        bold-style=literal,
        sans-style=literal,
        colon=literal,
        nabla=literal,
        partial=literal,
      }
    \fi
  } ,
  math-style .generate_choices:n = {ISO,TeX,french,upright,literal} ,
}
\keys_define:nn {unicode-math} {
  bold-style .choice_code:n = {
    \bool_set_false:N \g_um_bfliteral_bool
    \ifcase \l_keys_choice_int
      \bool_set_false:N \g_um_bfupGreek_bool
      \bool_set_false:N \g_um_bfupgreek_bool
      \bool_set_false:N \g_um_bfupLatin_bool
      \bool_set_false:N \g_um_bfuplatin_bool
    \or
      \bool_set_true:N \g_um_bfupGreek_bool
      \bool_set_false:N \g_um_bfupgreek_bool
      \bool_set_true:N \g_um_bfupLatin_bool
      \bool_set_true:N \g_um_bfuplatin_bool
    \or
      \bool_set_true:N \g_um_bfupGreek_bool
      \bool_set_true:N \g_um_bfupgreek_bool
      \bool_set_true:N \g_um_bfupLatin_bool
      \bool_set_true:N \g_um_bfuplatin_bool
    \or
      \bool_set_true:N \g_um_bfliteral_bool
    \fi
  } ,
  bold-style .generate_choices:n = {ISO,TeX,upright,literal} ,
}
\keys_define:nn {unicode-math} {
  sans-style .choice_code:n = {
    \ifcase \l_keys_choice_int
      \bool_set_false:N \g_um_upsans_bool
    \or
      \bool_set_true:N \g_um_upsans_bool
    \or
      \bool_set_true:N \g_um_sfliteral_bool
    \fi
  } ,
  sans-style .generate_choices:n = {italic,upright,literal} ,
}
\keys_define:nn {unicode-math} {
  nabla .choice_code:n = {
    \bool_set_false:N \g_um_literal_Nabla_bool
    \ifcase \l_keys_choice_int
      \bool_set_true:N \g_um_upNabla_bool
    \or
      \bool_set_false:N \g_um_upNabla_bool
    \or
      \bool_set_true:N \g_um_literal_Nabla_bool
    \fi
  } ,
  nabla .generate_choices:n = {upright,italic,literal} ,
}
\keys_define:nn {unicode-math} {
  partial .choice_code:n = {
    \bool_set_false:N \g_um_literal_partial_bool
    \ifcase \l_keys_choice_int
      \bool_set_true:N \g_um_uppartial_bool
    \or
      \bool_set_false:N \g_um_uppartial_bool
    \or
      \bool_set_true:N \g_um_literal_partial_bool
    \fi
  } ,
  partial .generate_choices:n = {upright,italic,literal} ,
}
\keys_define:nn {unicode-math} {
  vargreek-shape .choice: ,
  vargreek-shape / unicode .code:n = {
    \bool_set_false:N \g_um_texgreek_bool
  } ,
  vargreek-shape / TeX .code:n = {
    \bool_set_true:N \g_um_texgreek_bool
  }
}
\keys_define:nn {unicode-math} {
  colon .choice: ,
  colon / literal .code:n = {
    \bool_set_true:N \g_um_literal_colon_bool
  } ,
  colon / TeX .code:n = {
    \bool_set_false:N \g_um_literal_colon_bool
  }
}
\keys_define:nn {unicode-math} {
  slash-delimiter .choice: ,
  slash-delimiter / ascii .code:n = {
    \tl_set:Nn \g_um_slash_delimiter_usv {"002F}
  } ,
  slash-delimiter / frac .code:n = {
    \tl_set:Nn \g_um_slash_delimiter_usv {"2044}
  } ,
  slash-delimiter / div .code:n = {
    \tl_set:Nn \g_um_slash_delimiter_usv {"2215}
  }
}
\keys_define:nn {unicode-math} {
  active-frac .choice: ,
  active-frac / small .code:n = {
    \cs_if_exist:NTF \tfrac {
      \bool_set_true:N \l_um_smallfrac_bool
    }{
      \um_warning:n {no-tfrac}
      \bool_set_false:N \l_um_smallfrac_bool
    }
    \use:c{um_setup_active_frac:}
  } ,
  active-frac / normalsize .code:n = {
    \bool_set_false:N \l_um_smallfrac_bool
    \use:c{um_setup_active_frac:}
  }
}
\keys_define:nn {unicode-math} {
  trace .choice: ,
  trace / debug .code:n = {
    \msg_redirect_module:nnn { unicode-math } { trace } { warning }
  } ,
  trace / on .code:n = {
    \msg_redirect_module:nnn { unicode-math } { trace } { trace }
  } ,
  trace / off .code:n = {
    \msg_redirect_module:nnn { unicode-math } { trace } { none }
  } ,
}
\clist_new:N \l_um_unknown_keys_clist
\keys_define:nn {unicode-math} {
  unknown .code:n = {
    \clist_put_right:No \l_um_unknown_keys_clist {
      \l_keys_key_tl = {#1}
    }
  }
}
\unimathsetup {math-style=TeX}
\unimathsetup {slash-delimiter=ascii}
\unimathsetup {trace=off}
\cs_if_exist:NT \tfrac {
  \unimathsetup {active-frac=small}
}
\ProcessKeysOptions {unicode-math}
\tl_map_inline:nn {
  \new@mathgroup\cdp@list\cdp@elt\DeclareMathSizes
  \@DeclareMathSizes\newmathalphabet\newmathalphabet@@\newmathalphabet@@@
  \DeclareMathVersion\define@mathalphabet\define@mathgroup\addtoversion
  \version@list\version@elt\alpha@list\alpha@elt
  \restore@mathversion\init@restore@version\dorestore@version\process@table
  \new@mathversion\DeclareSymbolFont\group@list\group@elt
  \new@symbolfont\SetSymbolFont\SetSymbolFont@\get@cdp
  \DeclareMathAlphabet\new@mathalphabet\SetMathAlphabet\SetMathAlphabet@
  \DeclareMathAccent\set@mathaccent\DeclareMathSymbol\set@mathchar
  \set@mathsymbol\DeclareMathDelimiter\@xxDeclareMathDelimiter
  \@DeclareMathDelimiter\@xDeclareMathDelimiter\set@mathdelimiter
  \set@@mathdelimiter\DeclareMathRadical\mathchar@type
  \DeclareSymbolFontAlphabet\DeclareSymbolFontAlphabet@
}{
  \tl_remove_in:Nn \@preamblecmds {\do#1}
}
\def\new@mathgroup{\alloc@8\mathgroup\chardef\@cclvi}
\let\newfam\new@mathgroup
\cs_set:Npn \um_set_mathsymbol:nNNn #1#2#3#4 {
  \prg_case_tl:Nnn #3 {
    \mathop {
      \um_set_big_operator:nnn {#1} {#2} {#4}
    }
    \mathopen {
      \tl_if_in:NnTF \l_um_radicals_tl {#2} {
        \cs_gset:cpx {\cs_to_str:N #2 sign} { \um_radical:nn {#1} {#4} }
      }{
        \um_set_delcode:n {#4}
        \um_set_mathcode:nnn {#4} \mathopen {#1}
        \cs_gset:Npx #2 { \um_delimiter:Nnn \mathopen {#1} {#4} }
      }
    }
    \mathclose {
      \um_set_delcode:n {#4}
      \um_set_mathcode:nnn {#4} \mathclose {#1}
      \cs_gset:Npx #2 { \um_delimiter:Nnn \mathclose {#1} {#4} }
    }
    \mathfence {
      \um_set_mathcode:nnn {#4} {#3} {#1}
      \um_set_delcode:n {#4}
      \cs_gset:cpx {l \cs_to_str:N #2} { \um_delimiter:Nnn \mathopen  {#1} {#4} }
      \cs_gset:cpx {r \cs_to_str:N #2} { \um_delimiter:Nnn \mathclose {#1} {#4} }
    }
    \mathaccent {
      \cs_gset:Npx #2 { \um_accent:Nnn #3 {#1} {#4} }
    }
  }{
    \um_set_mathcode:nnn {#4} {#3} {#1}
  }
}
\cs_new:Npn \um_set_big_operator:nnn #1#2#3 {
  \group_begin:
    \char_make_active:n {#3}
    \char_gmake_mathactive:n {#3}
    \um@scanactivedef #3 \@nil { \csname\cs_to_str:N #2 _sym\endcsname }
  \group_end:
  \um_set_mathchar:cNnn {\cs_to_str:N #2 op} \mathop {#1} {#3}
  \cs_gset:cpx { \cs_to_str:N #2 _sym } {
    \exp_not:c { \cs_to_str:N #2 op   }
    \exp_not:n { \tl_if_in:NnT \l_um_nolimits_tl {#2} \nolimits }
  }
}
\cs_set:Npn \um_set_mathcode:nnnn #1#2#3#4 {
  \Umathcode \intexpr_eval:n {#1} =
    \mathchar@type#2 \csname sym#3\endcsname \intexpr_eval:n {#4} \scan_stop:
}
\cs_set:Npn \um_set_mathcode:nnn #1#2#3 {
  \Umathcode \intexpr_eval:n {#1} =
    \mathchar@type#2 \csname sym#3\endcsname \intexpr_eval:n {#1} \scan_stop:
}
\cs_set:Npn \um_set_mathchar:NNnn #1#2#3#4 {
  \Umathchardef #1 =
    \mathchar@type#2 \csname sym#3\endcsname \intexpr_eval:n {#4} \scan_stop:
}
\cs_new:Npn \um_radical:nn #1#2 {
  \Uradical \csname sym#1\endcsname #2 \scan_stop:
}
\cs_new:Npn \um_delimiter:Nnn #1#2#3 {
  \Udelimiter \mathchar@type#1 \csname sym#2\endcsname #3 \scan_stop:
}
\cs_new:Npn \um_accent:Nnn #1#2#3 {
  \Umathaccent \mathchar@type#1 \csname sym#2\endcsname #3 \scan_stop:
}
\cs_generate_variant:Nn \um_set_mathchar:NNnn {c}
\cs_new:Npn \char_gmake_mathactive:N #1 {
  \global\mathcode `#1 = "8000 \scan_stop:
}
\cs_new:Npn \char_gmake_mathactive:n #1 {
  \global\mathcode #1 = "8000 \scan_stop:
}
\cs_new:Npn \um_init: {
  \let\glb@currsize\relax
  \bool_set_true:N \l_um_init_bool
  \seq_clear:N \l_um_char_range_seq
  \clist_clear:N \l_um_char_num_range_clist
  \seq_clear:N \l_um_mathalph_seq
  \clist_clear:N \l_um_unknown_keys_clist
  \seq_clear:N \l_um_missing_alph_seq
}
\DeclareDocumentCommand \setmathfont { O{} m } {
  \um_init:
  \csname S@\f@size\endcsname
  \tl_set:Nn \l_um_mversion_tf {normal}
  \DeclareMathVersion{\l_um_mversion_tf}
  \tl_set:Nn \l_um_script_features_tl  {ScriptStyle}
  \tl_set:Nn \l_um_sscript_features_tl {ScriptScriptStyle}
  \tl_set:Nn \l_um_script_font_tl      {#2}
  \tl_set:Nn \l_um_sscript_font_tl     {#2}
  \keys_set:nn {unicode-math} {#1}
  \um_fontspec_select_font:n {#2}
%%  \ifdim \dimexpr\fontdimen9\l_um_font*65536\relax =65pt\relax
%%    \bool_set_true:N \l_um_ot_math_bool
%%  \else
%%    \bool_set_false:N \l_um_ot_math_bool
%%    \PackageWarningNoLine{unicode-math}{
%%      The~ font~ '#2' ~is~ not~ a~ valid~ OpenType~ maths~ font.~
%%      Some~ maths~ features~ will~ not~ be~ available~ or~ behave~
%%      in~ a~ substandard~ manner
%%    }
%%  \fi
  \bool_if:NTF \l_um_init_bool {
    \tl_set:Nn \um_symfont_tl {um_allsym}
    \msg_trace:nnx {unicode-math} {default-math-font} {#2}
    \cs_set_eq:NN \UnicodeMathSymbol \um_process_symbol_noparse:nnnn
    \cs_set_eq:NN \um_set_mathalphabet_char:Nnn \um_mathmap_noparse:Nnn
    \cs_set_eq:NN \um_remap_symbol:nnn \um_remap_symbol_noparse:nnn
    \cs_set_eq:NN \um_maybe_init_alphabet:n \um_init_alphabet:n
    \cs_set_eq:NN \um_map_char_single:nn \um_map_char_noparse:nn
  }{
    \int_incr:N \g_um_fam_int
    \tl_set:Nx \um_symfont_tl {um_fam\int_use:N\g_um_fam_int}
    \cs_set_eq:NN \UnicodeMathSymbol \um_process_symbol_parse:nnnn
    \cs_set_eq:NN \um_set_mathalphabet_char:Nnn \um_mathmap_parse:Nnn
    \cs_set_eq:NN \um_remap_symbol:nnn \um_remap_symbol_parse:nnn
    \cs_set_eq:NN \um_maybe_init_alphabet:n \use_none:n
    \cs_set_eq:NN \um_map_char_single:nn \um_map_char_parse:nn
  }
  \DeclareSymbolFont{\um_symfont_tl}
    {\encodingdefault}{\zf@family}{\mddefault}{\updefault}
  \@input{unicode-math-table.tex}
  \cs_set_eq:NN \UnicodeMathSymbol \use_none:nnnn
  \um_remap_symbols:
  \um_setup_mathactives:
  \um_setup_delcodes:
  \um_setup_alphabets:
  \ignorespaces
}
\cs_new:Npn \um_fontspec_select_font:n #1 {
  \bool_set_true:N \l_um_fontspec_feature_bool
  \fontspec_select:xn
    {
      BoldFont = {}, ItalicFont = {},
      Script = Math,
      SizeFeatures = {
        {Size = \tf@size-} ,
        {Size = \sf@size-\tf@size ,
         Font = \l_um_script_font_tl ,
         \l_um_script_features_tl
        } ,
        {Size = -\sf@size ,
         Font = \l_um_sscript_font_tl ,
         \l_um_sscript_features_tl
        }
      },
      \l_um_unknown_keys_clist
    }
    {#1}
  \tl_set_eq:NN \l_um_font \zf@basefont
  \bool_set_false:N \l_um_fontspec_feature_bool
}
\cs_set:Npn \um_process_symbol_noparse:nnnn #1#2#3#4 {
  \um_set_mathsymbol:nNNn {\um_symfont_tl} #2#3{#1}
}
\cs_set:Npn \um_process_symbol_parse:nnnn #1#2#3#4 {
  \um@parse@term{#1}{#2}{#3}{
    \um_process_symbol_noparse:nnnn{#1}{#2}{#3}{#4}
  }
}
\cs_new:Npn \um_remap_symbols: {
  \um_remap_symbol:nnn{`\-}{\mathbin}{"02212}% hyphen to minus
  \um_remap_symbol:nnn{`\*}{\mathbin}{"02217}% text asterisk to "centred asterisk"
  \bool_if:NF \g_um_literal_colon_bool {
    \um_remap_symbol:nnn{`\:}{\mathrel}{"02236}% colon to ratio (i.e., punct to rel)
  }
}
\cs_new:Npn \um_remap_symbol_parse:nnn #1#2#3 {
  \um@parse@term {#3} {\@nil} {#2} {
    \um_remap_symbol_noparse:nnn {#1} {#2} {#3}
  }
}
\cs_new:Npn \um_remap_symbol_noparse:nnn #1#2#3 {
  \clist_map_inline:nn {#1} {
    \um_set_mathcode:nnnn {##1} {#2} {\um_symfont_tl} {#3}
  }
}
\cs_new:Npn \um_setup_mathactives: {
  \um_make_mathactive:nNN {"2032} \um_prime_single_mchar \mathord
  \um_make_mathactive:nNN {"2033} \um_prime_double_mchar \mathord
  \um_make_mathactive:nNN {"2034} \um_prime_triple_mchar \mathord
  \um_make_mathactive:nNN {"2057} \um_prime_quad_mchar   \mathord
  \um_make_mathactive:nNN {"2035} \um_backprime_single_mchar \mathord
  \um_make_mathactive:nNN {"2036} \um_backprime_double_mchar \mathord
  \um_make_mathactive:nNN {"2037} \um_backprime_triple_mchar \mathord
  \um_make_mathactive:nNN {`\'} \mathstraightquote \mathord
  \um_make_mathactive:nNN {`\`} \mathbacktick      \mathord
}
\cs_new:Npn \um_make_mathactive:nNN #1#2#3 {
  \um_set_mathchar:NNnn #2 #3 {\um_symfont_tl} {#1}
  \char_gmake_mathactive:n {#1}
}
\cs_new:Npn \um_setup_delcodes: {
  \um_set_delcode:nn {`\/}   {\g_um_slash_delimiter_usv}
  \um_set_delcode:nn {"2044} {\g_um_slash_delimiter_usv} % fracslash
  \um_set_delcode:nn {"2215} {\g_um_slash_delimiter_usv} % divslash
  \um_set_delcode:n {"005C} % backslash
  \um_set_delcode:nn {`\<} {"27E8} % angle brackets with ascii notation
  \um_set_delcode:nn {`\>} {"27E9} % angle brackets with ascii notation
  \um_set_delcode:n {"2191} % up arrow
  \um_set_delcode:n {"2193} % down arrow
  \um_set_delcode:n {"2195} % updown arrow
  \um_set_delcode:n {"219F} % up arrow twohead
  \um_set_delcode:n {"21A1} % down arrow twohead
  \um_set_delcode:n {"21A5} % up arrow from bar
  \um_set_delcode:n {"21A7} % down arrow from bar
  \um_set_delcode:n {"21A8} % updown arrow from bar
  \um_set_delcode:n {"21BE} % up harpoon right
  \um_set_delcode:n {"21BF} % up harpoon left
  \um_set_delcode:n {"21C2} % down harpoon right
  \um_set_delcode:n {"21C3} % down harpoon left
  \um_set_delcode:n {"21C5} % arrows up down
  \um_set_delcode:n {"21F5} % arrows down up
  \um_set_delcode:n {"21C8} % arrows up up
  \um_set_delcode:n {"21CA} % arrows down down
  \um_set_delcode:n {"21D1} % double up arrow
  \um_set_delcode:n {"21D3} % double down arrow
  \um_set_delcode:n {"21D5} % double updown arrow
  \um_set_delcode:n {"21DE} % up arrow double stroke
  \um_set_delcode:n {"21DF} % down arrow double stroke
  \um_set_delcode:n {"21E1} % up arrow dashed
  \um_set_delcode:n {"21E3} % down arrow dashed
  \um_set_delcode:n {"21E7} % up white arrow
  \um_set_delcode:n {"21E9} % down white arrow
  \um_set_delcode:n {"21EA} % up white arrow from bar
  \um_set_delcode:n {"21F3} % updown white arrow
}
\cs_new:Npn \um_set_delcode:nn #1#2 {
  \Udelcode#1 = \csname sym\um_symfont_tl\endcsname #2
}
\cs_new:Npn \um_set_delcode:n #1 {
  \Udelcode#1 = \csname sym\um_symfont_tl\endcsname #1
}
\cs_set:Npn \um_mathmap_noparse:Nnn #1#2#3 {
  \clist_map_inline:nn {#2} {
    \tl_put_right:cx {um_switchto_\cs_to_str:N #1:} {
      \um_set_mathcode:nnnn{##1}{\mathalpha}{\um_symfont_tl}{#3}
    }
  }
}
\cs_set:Npn \um_mathmap_parse:Nnn #1#2#3 {
  \clist_if_in:NnT \l_um_char_num_range_clist {#3} {
    \um_mathmap_noparse:Nnn {#1}{#2}{#3}
  }
}
\tl_new:Nn \l_um_nolimits_tl {
  \int\iint\iiint\iiiint\oint\oiint\oiiint
  \intclockwise\varointclockwise\ointctrclockwise\sumint
  \intbar\intBar\fint\cirfnint\awint\rppolint
  \scpolint\npolint\pointint\sqint\intlarhk\intx
  \intcap\intcup\upint\lowint
}
\DeclareDocumentCommand \addnolimits {m} {
  \tl_put_right:Nn \l_um_nolimits_tl {#1}
}
\DeclareDocumentCommand \removenolimits {m} {
  \tl_remove_all_in:Nn \l_um_nolimits_tl {#1}
}
\tl_new:Nn \l_um_radicals_tl {\sqrt}
\let\left@primitive\left
\def\left{\mathopen{}\left@primitive}
\newcommand\um@zf@feature[2]{
  \define@key[zf]{options}{#1}[]{
    \bool_if:NTF \l_um_fontspec_feature_bool {
      #2
    }{
      \um_warning:n {maths-feature-only}
    }
  }
}
\um@zf@feature{ScriptStyle}{
  \zf@update@ff{+ssty=0}
}
\um@zf@feature{ScriptScriptStyle}{
  \zf@update@ff{+ssty=1}
}
\keys_define:nn {unicode-math}
{
  script-features  .tl_set:N =  \l_um_script_features_tl ,
  sscript-features .tl_set:N = \l_um_sscript_features_tl ,
       script-font .tl_set:N =      \l_um_script_font_tl ,
      sscript-font .tl_set:N =     \l_um_sscript_font_tl ,
}
\seq_new:N \l_um_mathalph_seq
\seq_new:N \l_um_char_range_seq
\keys_define:nn {unicode-math} {
  range .code:n = {
    \bool_set_false:N \l_um_init_bool
    \seq_clear:N \l_um_char_range_seq
    \seq_clear:N \l_um_mathalph_seq
    \clist_map_inline:nn {#1} {
      \um_if_mathalph_decl:nTF {##1} {
        \seq_put_right:Nx \l_um_mathalph_seq {
          { \exp_not:V \l_um_tmpa_tl }
          { \exp_not:V \l_um_tmpb_tl }
          { \exp_not:V \l_um_tmpc_tl }
        }
      }{
        \seq_put_right:Nn \l_um_char_range_seq {##1}
      }
    }
  }
}
\prg_new_conditional:Nnn \um_if_mathalph_decl:n {TF} {
  \KV_remove_surrounding_spaces:nw {\tl_set:Nf\l_um_tmpa_tl} #1 \q_nil
  \tl_clear:N \l_um_tmpb_tl
  \tl_clear:N \l_um_tmpc_tl
  \tl_if_in:NnT \l_um_tmpa_tl {->} {
    \exp_after:wN \um_split_arrow:w \l_um_tmpa_tl \q_nil
  }
  \tl_if_in:NnT \l_um_tmpa_tl {/} {
    \exp_after:wN \um_split_slash:w \l_um_tmpa_tl \q_nil
  }
  \tl_if_empty:NT \l_um_tmpc_tl { \tl_set_eq:NN \l_um_tmpc_tl \l_um_tmpa_tl }
  \seq_if_in:NVTF \g_um_mathalph_seq \l_um_tmpa_tl {
    \prg_return_true:
  }{
    \prg_return_false:
  }
}
\cs_set:Npn \um_split_arrow:w #1->#2 \q_nil {
  \tl_set:Nn \l_um_tmpa_tl {#1}
  \tl_set:Nn \l_um_tmpc_tl {#2}
}
\cs_set:Npn \um_split_slash:w #1/#2 \q_nil {
  \tl_set:Nn \l_um_tmpa_tl {#1}
  \tl_set:Nn \l_um_tmpb_tl {#2}
}
\newcommand\um@parse@term[4]{
  \seq_map_variable:NNn \l_um_char_range_seq \@ii {
    \unless\ifx\@ii\@empty
      \@tempswafalse
      \expandafter\um@firstchar\expandafter{\@ii}
      \ifx\@tempa\um@backslash
        \expandafter\ifx\@ii#2\relax
          \@tempswatrue
        \else
          \expandafter\ifx\@ii#3\relax
            \@tempswatrue
          \fi
        \fi
      \else
        \expandafter\um@parse@range\@ii-\@marker-\@nil#1\@nil
      \fi
      \if@tempswa
        \clist_put_right:Nx \l_um_char_num_range_clist { \intexpr_eval:n {#1} }
        #4
      \fi
    \fi
  }
}
\def\um@firstof#1#2\@nil{#1}
\edef\um@backslash{\expandafter\um@firstof\string\string\@nil}
\def\um@firstchar#1{\edef\@tempa{\expandafter\um@firstof\string#1\@nil}}
\def\um@parse@range#1-#2-#3\@nil#4\@nil{
  \def\@tempa{#1}
  \def\@tempb{#2}
  \expandafter\ifx\expandafter\@marker\@tempb\relax
    \intexpr_compare:nT {#4=#1} \@tempswatrue
  \else
    \ifx\@empty\@tempb
      \intexpr_compare:nT {#4>#1-1} \@tempswatrue
    \else
      \ifx\@empty\@tempa
        \intexpr_compare:nT {#4<#2+1} \@tempswatrue
      \else
        \intexpr_compare:nT {#4>#1-1} {
          \intexpr_compare:nT {#4<#2+1} \@tempswatrue
        }
      \fi
    \fi
  \fi
}
\AtBeginDocument{\um_resolve_greek:}
\cs_new:Npn \um_resolve_greek: {
  \clist_map_inline:nn {
    Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,
    alpha,beta,gamma,delta,        zeta,eta,theta,iota,kappa,lambda,
    Mu,Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,
    mu,nu,xi,omicron,pi,rho,sigma,tau,upsilon,    chi,psi,omega,
    varTheta,
    varsigma,vartheta,varkappa,varrho,varpi
  }{
    \tl_set:cx {##1} { \exp_not:c { mit ##1 } }
  }
  \tl_set:Nn \epsilon {
    \bool_if:NTF \g_um_texgreek_bool \mitvarepsilon \mitepsilon
  }
  \tl_set:Nn \phi {
    \bool_if:NTF \g_um_texgreek_bool \mitvarphi \mitphi
  }
  \tl_set:Nn \varepsilon {
    \bool_if:NTF \g_um_texgreek_bool \mitepsilon \mitvarepsilon
  }
  \tl_set:Nn \varphi {
    \bool_if:NTF \g_um_texgreek_bool \mitphi \mitvarphi
  }
}
\seq_new:N \g_um_mathalph_seq
\AtEndOfPackage{
  \tl_map_inline:nn {
    \mathup\mathit\mathbb\mathbbit
    \mathscr\mathfrak\mathtt
    \mathsf\mathsfup\mathsfit
    \mathbf\mathbfup\mathbfit
    \mathbfscr\mathbffrak
    \mathbfsf\mathbfsfup\mathbfsfit
  }{
    \seq_put_right:Nn \g_um_mathalph_seq {#1}
    \um_prepare_mathstyle:f {\exp_after:wN \use_none:nnnnn \token_to_str:N #1}
  }
}
\cs_new:Npn \um_prepare_mathstyle:n #1 {
  \um_init_alphabet:x {#1}
  \cs_set:cpn {_um_math#1_aux:n} ##1 {
    \use:c {um_switchto_math#1:} ##1 \egroup
  }
  \cs_set_protected:cpx {math#1} {
    \exp_not:n{
      \bgroup
      \mode_if_math:F {
        \egroup\expandafter
        \non@alpherr\expandafter{\csname math#1\endcsname\space}
      }
    }
    \exp_not:c {_um_math#1_aux:n}
  }
}
\cs_generate_variant:Nn \um_prepare_mathstyle:n {f}
\cs_set:Npn \um_init_alphabet:n #1 {
  \um_trace:nx {alph-initialise} {#1}
  \cs_set_eq:cN {um_switchto_math#1:} \prg_do_nothing:
}
\cs_generate_variant:Nn \um_init_alphabet:n {x}
\cs_new:Npn \um_maybe_init_alphabet:V {
  \exp_args:NV \um_maybe_init_alphabet:n
}
\seq_new:N \g_um_default_mathalph_seq
\clist_map_inline:nn {
  {\mathup    } {latin,Latin,greek,Greek,num,misc} {\mathup    }  ,
  {\mathit    } {latin,Latin,greek,Greek,misc}     {\mathit    }  ,
  {\mathbb    } {latin,Latin,num,misc}             {\mathbb    }  ,
  {\mathbbit  } {misc}                             {\mathbbit  }  ,
  {\mathscr   } {latin,Latin}                      {\mathscr   }  ,
  {\mathfrak  } {latin,Latin}                      {\mathfrak  }  ,
  {\mathtt    } {latin,Latin,num}                  {\mathtt    }  ,
  {\mathsfup  } {latin,Latin,num}                  {\mathsfup  }  ,
  {\mathsfit  } {latin,Latin}                      {\mathsfit  }  ,
  {\mathbfup  } {latin,Latin,greek,Greek,num,misc} {\mathbfup  }  ,
  {\mathbfit  } {latin,Latin,greek,Greek,misc}     {\mathbfit  }  ,
  {\mathbfscr } {latin,Latin}                      {\mathbfscr }  ,
  {\mathbffrak} {latin,Latin}                      {\mathbffrak}  ,
  {\mathbfsfup} {latin,Latin,greek,Greek,num,misc} {\mathbfsfup}  ,
  {\mathbfsfit} {latin,Latin,greek,Greek,misc}     {\mathbfsfit}
}{
  \seq_put_right:Nn \g_um_default_mathalph_seq {#1}
}
\seq_new:N \l_um_missing_alph_seq
\cs_new:Npn \um_setup_alphabets: {
  \seq_if_empty:NTF \l_um_mathalph_seq {
    \um_trace:n {setup-implicit}
    \seq_set_eq:NN \l_um_mathalph_seq \g_um_default_mathalph_seq
    \bool_set_true:N \l_um_implicit_alph_bool
    \um_maybe_init_alphabet:n  {sf}
    \um_maybe_init_alphabet:n  {bf}
    \um_maybe_init_alphabet:n  {bfsf}
  }
  {
    \um_trace:n {setup-explicit}
    \bool_set_false:N \l_um_implicit_alph_bool
    \cs_set_eq:NN \um_set_mathalphabet_char:Nnn \um_mathmap_noparse:Nnn
    \cs_set_eq:NN \um_map_char_single:nn \um_map_char_noparse:nn
  }
  \seq_map_inline:Nn \l_um_mathalph_seq {
    \tl_set:No \l_um_tmpa_tl { \use_i:nnn   ##1 }
    \tl_set:No \l_um_tmpb_tl { \use_ii:nnn  ##1 }
    \tl_set:No \l_um_remap_style_tl { \use_iii:nnn ##1 }
    \tl_set:Nx \l_um_remap_style_tl {
      \exp_after:wN \exp_after:wN \exp_after:wN \use_none:nnnnn
      \exp_after:wN \token_to_str:N \l_um_remap_style_tl
    }
    \tl_if_empty:NT \l_um_tmpb_tl {
      \cs_set_eq:NN \um_maybe_init_alphabet:n \um_init_alphabet:n
      \tl_set:Nn \l_um_tmpb_tl { latin,Latin,greek,Greek,num,misc }
    }
    \um_setup_math_alphabet:VVV
      \l_um_tmpa_tl \l_um_tmpb_tl \l_um_remap_style_tl
  }
  \um_warn_missing_alphabets:
}
\cs_new:Npn \um_warn_missing_alphabets: {
  \seq_if_empty:NF \l_um_missing_alph_seq {
    \typeout{
      Package~unicode-math~Warning:~
      missing~math~alphabets~in~font~ \fontname\l_um_font
    }
    \seq_map_inline:Nn \l_um_missing_alph_seq {
      \typeout{\space\space\space\space##1}
    }
  }
}
\cs_new:Npn \um_setup_math_alphabet:Nnn #1#2#3 {
  \tl_set:Nx \l_um_style_tl {
    \exp_after:wN \use_none:nnnnn \token_to_str:N #1
  }
  \clist_map_inline:nn {#2} {
    \cs_if_exist:cT {um_config_ \l_um_style_tl _##1:n} {
      \tl_if_eq:nnTF {##1}{misc} {
        \um_maybe_init_alphabet:V \l_um_style_tl
        \clist_map_break:
      }{
        \um_glyph_if_exist:cT { \um_to_usv:nn {#3}{##1} }{
          \um_maybe_init_alphabet:V \l_um_style_tl
          \clist_map_break:
        }
      }
    }
  }
  \clist_map_inline:nn {#2} {
    \cs_if_exist:cT {um_config_ \l_um_style_tl _##1:n} {
      \tl_if_eq:nnTF {##1}{misc} {
        \um_trace:nx {setup-alph} {math \l_um_style_tl~(##1)}
        \use:c {um_config_ \l_um_style_tl _##1:n} {#3}
      }{
        \um_glyph_if_exist:cTF { \um_to_usv:nn {#3}{##1} } {
          \um_trace:nx {setup-alph} {math \l_um_style_tl~(##1)}
          \use:c {um_config_ \l_um_style_tl _##1:n} {#3}
        }{
          \bool_if:NTF \l_um_implicit_alph_bool {
            \seq_put_right:Nx \l_um_missing_alph_seq {
              \@backslashchar math \l_um_style_tl \space
              (\tl_use:c{g_um_math_alphabet_name_##1_tl})
            }
          }{
            \use:c {um_config_ \l_um_style_tl _##1:n} {up}
          }
        }
      }
    }
  }
}
\cs_generate_variant:Nn \um_setup_math_alphabet:Nnn {VVV}
\cs_set:Npn \um_map_chars_range:nnn #1#2#3 {
  \prg_stepwise_inline:nnnn {0}{1}{#1-1} {
    \um_map_char_single:nn {#2+##1}{#3+##1}
  }
}
\cs_generate_variant:Nn \um_map_chars_range:nnn {ncc}
\cs_new:Npn \um_map_chars_range:nnnn #1#2#3#4 {
  \um_map_chars_range:ncc {#1} { \um_to_usv:nn {#2}{#4} }
                               { \um_to_usv:nn {#3}{#4} }
}
\cs_new:Npn \um_map_char_noparse:nn #1#2 {
  \um_set_mathcode:nnnn {#1}{\mathalpha}{\um_symfont_tl}{#2}
}
\cs_new:Npn \um_map_char_parse:nn #1#2 {
  \um@parse@term {#1} {\@nil} {\mathalpha} {
    \um_map_char_noparse:nn {#1}{#2}
  }
}
\cs_set:Npn \um_map_chars_Latin:nn #1#2 {
  \clist_map_inline:nn {#1} {
    \um_map_chars_range:nnnn {26} {##1} {#2} {Latin}
  }
}
\cs_set:Npn \um_map_chars_latin:nn #1#2 {
  \clist_map_inline:nn {#1} {
    \um_map_chars_range:nnnn {26} {##1} {#2} {latin}
  }
}
\cs_set:Npn \um_map_chars_greek:nn #1#2 {
  \clist_map_inline:nn {#1} {
    \um_map_chars_range:nnnn {25} {##1} {#2} {greek}
    \um_map_char_single:nnn {##1} {#2} {varepsilon}
    \um_map_char_single:nnn {##1} {#2} {vartheta}
    \um_map_char_single:nnn {##1} {#2} {varkappa}
    \um_map_char_single:nnn {##1} {#2} {varphi}
    \um_map_char_single:nnn {##1} {#2} {varrho}
    \um_map_char_single:nnn {##1} {#2} {varpi}
  }
}
\cs_set:Npn \um_map_chars_Greek:nn #1#2 {
  \clist_map_inline:nn {#1} {
    \um_map_chars_range:nnnn {25} {##1} {#2} {Greek}
    \um_map_char_single:nnn {##1} {#2} {varTheta}
  }
}
\cs_set:Npn \um_map_chars_numbers:nn #1#2 {
  \um_map_chars_range:nnnn {10} {#1} {#2} {num}
}
\cs_new:Npn \um_map_char_single:cc { \exp_args:Ncc \um_map_char_single:nn }
\cs_new:Npn \um_map_char_single:nnn #1#2#3 {
  \um_map_char_single:cc { \um_to_usv:nn {#1}{#3} }
                         { \um_to_usv:nn {#2}{#3} }
}
\cs_set:Npn \um_map_single:nnn #1#2#3 {
  \cs_if_exist:cT { \um_to_usv:nn {#3} {#1} }
  {
    \clist_map_inline:nn {#2} {
      \um_map_char_single:nnn {##1} {#3} {#1}
    }
  }
}
\cs_new:Npn \um_set_mathalph_range:nNnn #1#2#3#4 {
  \prg_stepwise_inline:nnnn {0}{1}{#1-1} {
    \um_set_mathalphabet_char:Nnn {#2} { ##1 + #3 } { ##1 + #4 }
  }
}
\cs_generate_variant:Nn \um_set_mathalph_range:nNnn {nNcc}
\cs_new:Npn \um_set_mathalphabet_pos:Nnnn #1#2#3#4 {
  \cs_if_exist:cT { \um_to_usv:nn {#4}{#2} } {
    \clist_map_inline:nn {#3} {
      \um_set_mathalphabet_char:Nnnn #1 {##1} {#4} {#2}
    }
  }
}
\cs_new:Npn \um_set_mathalphabet_numbers:Nnn #1#2#3 {
  \clist_map_inline:nn {#2} {
    \um_set_mathalph_range:nNnnn {10} #1  {##1} {#3} {num}
  }
}
\cs_new:Npn \um_set_mathalphabet_Latin:Nnn #1#2#3 {
  \clist_map_inline:nn {#2} {
    \um_set_mathalph_range:nNnnn {26} #1 {##1} {#3} {Latin}
  }
}
\cs_new:Npn \um_set_mathalphabet_latin:Nnn #1#2#3 {
  \clist_map_inline:nn {#2} {
    \um_set_mathalph_range:nNnnn {26} #1 {##1} {#3} {latin}
    \um_set_mathalphabet_char:Nnnn    #1 {##1} {#3} {h}
  }
}
\cs_new:Npn \um_set_mathalphabet_Greek:Nnn #1#2#3 {
  \clist_map_inline:nn {#2} {
    \um_set_mathalph_range:nNnnn {25} #1 {##1} {#3} {Greek}
    \um_set_mathalphabet_char:Nnnn    #1 {##1} {#3} {varTheta}
  }
}
\cs_new:Npn \um_set_mathalphabet_greek:Nnn #1#2#3 {
  \clist_map_inline:nn {#2} {
    \um_set_mathalph_range:nNnnn {25} #1 {##1} {#3} {greek}
    \um_set_mathalphabet_char:Nnnn    #1 {##1} {#3} {varepsilon}
    \um_set_mathalphabet_char:Nnnn    #1 {##1} {#3} {vartheta}
    \um_set_mathalphabet_char:Nnnn    #1 {##1} {#3} {varkappa}
    \um_set_mathalphabet_char:Nnnn    #1 {##1} {#3} {varphi}
    \um_set_mathalphabet_char:Nnnn    #1 {##1} {#3} {varrho}
    \um_set_mathalphabet_char:Nnnn    #1 {##1} {#3} {varpi}
  }
}
\cs_new:Npn \um_set_mathalphabet_char:Ncc {
  \exp_args:NNcc \um_set_mathalphabet_char:Nnn
}
\cs_new:Npn \um_set_mathalphabet_char:Nnnn #1#2#3#4 {
  \um_set_mathalphabet_char:Ncc #1 { \um_to_usv:nn {#2} {#4} }
                                   { \um_to_usv:nn {#3} {#4} }
}
\cs_new:Npn \um_set_mathalph_range:nNnnn #1#2#3#4#5 {
  \um_set_mathalph_range:nNcc {#1} #2 { \um_to_usv:nn {#3} {#5} }
                                      { \um_to_usv:nn {#4} {#5} }
}
\cs_new:Npn \um_config_up_num:n #1 {
  \um_map_chars_numbers:nn {up}{#1}
  \um_set_mathalphabet_numbers:Nnn \mathup {up}{#1}
}
\cs_new:Npn \um_config_up_Latin:n #1 {
  \bool_if:NTF \g_um_literal_bool {
    \um_map_chars_Latin:nn {up} {#1}
  }{
    \bool_if:NT \g_um_upLatin_bool {
      \um_map_chars_Latin:nn {up,it} {#1}
    }
  }
  \um_set_mathalphabet_Latin:Nnn \mathup {up,it}{#1}
}
\cs_new:Npn \um_config_up_latin:n #1 {
  \bool_if:NTF \g_um_literal_bool {
    \um_map_chars_latin:nn {up} {#1}
  }{
    \bool_if:NT \g_um_uplatin_bool {
      \um_map_chars_latin:nn        {up,it} {#1}
      \um_map_single:nnn        {h} {up,it} {#1}
      \um_map_single:nnn {dotlessi} {up,it} {#1}
      \um_map_single:nnn {dotlessj} {up,it} {#1}
    }
  }
  \um_set_mathalphabet_latin:Nnn \mathup {up,it}{#1}
}
\cs_new:Npn \um_config_up_Greek:n #1 {
  \bool_if:NTF \g_um_literal_bool {
    \um_map_chars_Greek:nn {up}{#1}
  }{
    \bool_if:NT \g_um_upGreek_bool {
      \um_map_chars_Greek:nn {up,it}{#1}
    }
  }
  \um_set_mathalphabet_Greek:Nnn \mathup {up,it}{#1}
}
\cs_new:Npn \um_config_up_greek:n #1 {
  \bool_if:NTF \g_um_literal_bool {
    \um_map_chars_greek:nn {up} {#1}
  }{
    \bool_if:NT \g_um_upgreek_bool {
      \um_map_chars_greek:nn {up,it} {#1}
    }
  }
  \um_set_mathalphabet_greek:Nnn \mathup {up,it} {#1}
}
\cs_new:Npn \um_config_up_misc:n #1 {
  \bool_if:NTF \g_um_literal_Nabla_bool {
    \um_map_single:nnn {Nabla}{up}{up}
  }{
    \bool_if:NT \g_um_upNabla_bool {
      \um_map_single:nnn {Nabla}{up,it}{up}
    }
  }
  \bool_if:NTF \g_um_literal_partial_bool {
    \um_map_single:nnn {partial}{up}{up}
  }{
    \bool_if:NT \g_um_uppartial_bool {
      \um_map_single:nnn {partial}{up,it}{up}
    }
  }
  \um_set_mathalphabet_pos:Nnnn \mathup  {partial} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathup    {Nabla} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathup {dotlessi} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathup {dotlessj} {up,it} {#1}
}
\cs_new:Npn \um_config_it_Latin:n #1 {
  \bool_if:NTF \g_um_literal_bool {
    \um_map_chars_Latin:nn {it} {#1}
  }{
    \bool_if:NF \g_um_upLatin_bool {
      \um_map_chars_Latin:nn {up,it} {#1}
    }
  }
  \um_set_mathalphabet_Latin:Nnn \mathit {up,it}{#1}
}
\cs_new:Npn \um_config_it_latin:n #1 {
  \bool_if:NTF \g_um_literal_bool {
    \um_map_chars_latin:nn {it} {#1}
    \um_map_single:nnn {h}{it}{#1}
  }{
    \bool_if:NF \g_um_uplatin_bool {
      \um_map_chars_latin:nn {up,it} {#1}
      \um_map_single:nnn {h}{up,it}{#1}
      \um_map_single:nnn {dotlessi}{up,it}{#1}
      \um_map_single:nnn {dotlessj}{up,it}{#1}
    }
  }
  \um_set_mathalphabet_latin:Nnn \mathit            {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn  \mathit {dotlessi} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn  \mathit {dotlessj} {up,it} {#1}
}
\cs_new:Npn \um_config_it_Greek:n #1 {
  \bool_if:NTF \g_um_literal_bool {
    \um_map_chars_Greek:nn {it}{#1}
  }{
    \bool_if:NF \g_um_upGreek_bool {
      \um_map_chars_Greek:nn {up,it}{#1}
    }
  }
  \um_set_mathalphabet_Greek:Nnn \mathit {up,it}{#1}
}
\cs_new:Npn \um_config_it_greek:n #1 {
  \bool_if:NTF \g_um_literal_bool {
    \um_map_chars_greek:nn {it} {#1}
  }{
    \bool_if:NF \g_um_upgreek_bool {
      \um_map_chars_greek:nn {it,up} {#1}
    }
  }
  \um_set_mathalphabet_greek:Nnn \mathit {up,it} {#1}
}
\cs_new:Npn \um_config_it_misc:n #1 {
  \bool_if:NTF \g_um_literal_Nabla_bool {
    \um_map_single:nnn {Nabla}{it}{it}
  }{
    \bool_if:NF \g_um_upNabla_bool {
      \um_map_single:nnn {Nabla}{up,it}{it}
    }
  }
  \bool_if:NTF \g_um_literal_partial_bool {
    \um_map_single:nnn {partial}{it}{it}
  }{
    \bool_if:NF \g_um_uppartial_bool {
      \um_map_single:nnn {partial}{up,it}{it}
    }
  }
  \um_set_mathalphabet_pos:Nnnn \mathit {partial} {up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn \mathit {Nabla}   {up,it}{#1}
}
\cs_new:Npn \um_config_bb_latin:n #1 {
  \um_set_mathalphabet_latin:Nnn \mathbb {up,it}{#1}
}
\cs_new:Npn \um_config_bb_Latin:n #1 {
  \um_set_mathalphabet_Latin:Nnn \mathbb {up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbb {C} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbb {H} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbb {N} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbb {P} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbb {Q} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbb {R} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbb {Z} {up,it} {#1}
}
\cs_new:Npn \um_config_bb_num:n #1 {
  \um_set_mathalphabet_numbers:Nnn \mathbb {up}{#1}
}
\cs_new:Npn \um_config_bb_misc:n #1 {
  \um_set_mathalphabet_pos:Nnnn \mathbb        {Pi} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathbb        {pi} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathbb     {Gamma} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathbb     {gamma} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathbb {summation} {up} {#1}
}
\cs_new:Npn \um_config_bbit_misc:n #1 {
  \um_set_mathalphabet_pos:Nnnn \mathbbit {D} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathbbit {d} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathbbit {e} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathbbit {i} {up,it} {#1}
  \um_set_mathalphabet_pos:Nnnn \mathbbit {j} {up,it} {#1}
}
\cs_new:Npn \um_config_scr_Latin:n #1 {
  \um_set_mathalphabet_Latin:Nnn \mathscr    {up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {B}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {E}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {F}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {H}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {I}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {L}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {M}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {R}{up,it}{#1}
}
\cs_new:Npn \um_config_scr_latin:n #1 {
  \um_set_mathalphabet_latin:Nnn \mathscr    {up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {e}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {g}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathscr {o}{up,it}{#1}
}
\cs_new:Npn \um_config_frak_Latin:n #1 {
  \um_set_mathalphabet_Latin:Nnn \mathfrak    {up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathfrak {C}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathfrak {H}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathfrak {I}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathfrak {R}{up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathfrak {Z}{up,it}{#1}
}
\cs_new:Npn \um_config_frak_latin:n #1 {
  \um_set_mathalphabet_latin:Nnn \mathfrak {up,it}{#1}
}
\cs_new:Npn \um_config_sfup_num:n #1 {
  \um_set_mathalphabet_numbers:Nnn \mathsf   {up}{#1}
  \um_set_mathalphabet_numbers:Nnn \mathsfup {up}{#1}
}
\cs_new:Npn \um_config_sfup_Latin:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_Latin:nn {sfup} {#1}
    \um_set_mathalphabet_Latin:Nnn \mathsf {up}{#1}
  }{
    \bool_if:NT \g_um_upsans_bool {
      \um_map_chars_Latin:nn {sfup,sfit} {#1}
      \um_set_mathalphabet_Latin:Nnn \mathsf {up,it}{#1}
    }
  }
  \um_set_mathalphabet_Latin:Nnn \mathsfup {up,it}{#1}
}
\cs_new:Npn \um_config_sfup_latin:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_latin:nn {sfup} {#1}
    \um_set_mathalphabet_latin:Nnn \mathsf {up}{#1}
  }{
    \bool_if:NT \g_um_upsans_bool {
      \um_map_chars_latin:nn {sfup,sfit} {#1}
      \um_set_mathalphabet_latin:Nnn \mathsf {up,it}{#1}
    }
  }
  \um_set_mathalphabet_latin:Nnn \mathsfup {up,it}{#1}
}
\cs_new:Npn \um_config_sfit_Latin:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_Latin:nn {sfit} {#1}
    \um_set_mathalphabet_Latin:Nnn \mathsf {it}{#1}
  }{
    \bool_if:NF \g_um_upsans_bool {
      \um_map_chars_Latin:nn {sfup,sfit} {#1}
      \um_set_mathalphabet_Latin:Nnn \mathsf {up,it}{#1}
    }
  }
  \um_set_mathalphabet_Latin:Nnn \mathsfit {up,it}{#1}
}
\cs_new:Npn \um_config_sfit_latin:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_latin:nn {sfit} {#1}
    \um_set_mathalphabet_latin:Nnn \mathsf {it}{#1}
  }{
    \bool_if:NF \g_um_upsans_bool {
      \um_map_chars_latin:nn {sfup,sfit} {#1}
      \um_set_mathalphabet_latin:Nnn \mathsf {up,it}{#1}
    }
  }
  \um_set_mathalphabet_latin:Nnn \mathsfit {up,it}{#1}
}
\cs_new:Npn \um_config_tt_num:n #1 {
  \um_set_mathalphabet_numbers:Nnn \mathtt {up}{#1}
}
\cs_new:Npn \um_config_tt_Latin:n #1 {
  \um_set_mathalphabet_Latin:Nnn \mathtt {up,it}{#1}
}
\cs_new:Npn \um_config_tt_latin:n #1 {
  \um_set_mathalphabet_latin:Nnn \mathtt {up,it}{#1}
}
\cs_new:Npn \um_config_bfit_Latin:n #1 {
  \bool_if:NF \g_um_bfupLatin_bool {
    \um_map_chars_Latin:nn {bfup,bfit} {#1}
  }
  \um_set_mathalphabet_Latin:Nnn \mathbfit {up,it}{#1}
  \bool_if:NTF \g_um_bfliteral_bool {
    \um_map_chars_Latin:nn {bfit} {#1}
    \um_set_mathalphabet_Latin:Nnn \mathbf {it}{#1}
  }{
    \bool_if:NF \g_um_bfupLatin_bool {
      \um_map_chars_Latin:nn {bfup,bfit} {#1}
      \um_set_mathalphabet_Latin:Nnn \mathbf {up,it}{#1}
    }
  }
}
\cs_new:Npn \um_config_bfit_latin:n #1 {
  \bool_if:NF \g_um_bfuplatin_bool {
    \um_map_chars_latin:nn {bfup,bfit} {#1}
  }
  \um_set_mathalphabet_latin:Nnn \mathbfit {up,it}{#1}
  \bool_if:NTF \g_um_bfliteral_bool {
    \um_map_chars_latin:nn {bfit} {#1}
    \um_set_mathalphabet_latin:Nnn \mathbf {it}{#1}
  }{
    \bool_if:NF \g_um_bfuplatin_bool {
      \um_map_chars_latin:nn {bfup,bfit} {#1}
      \um_set_mathalphabet_latin:Nnn \mathbf {up,it}{#1}
    }
  }
}
\cs_new:Npn \um_config_bfit_Greek:n #1 {
  \um_set_mathalphabet_Greek:Nnn \mathbfit {up,it}{#1}
  \bool_if:NTF \g_um_bfliteral_bool {
    \um_map_chars_Greek:nn {bfit}{#1}
    \um_set_mathalphabet_Greek:Nnn \mathbf {it}{#1}
  }{
    \bool_if:NF \g_um_bfupGreek_bool {
      \um_map_chars_Greek:nn {bfup,bfit}{#1}
      \um_set_mathalphabet_Greek:Nnn \mathbf {up,it}{#1}
    }
  }
}
\cs_new:Npn \um_config_bfit_greek:n #1 {
  \um_set_mathalphabet_greek:Nnn \mathbfit {up,it} {#1}
  \bool_if:NTF \g_um_bfliteral_bool {
    \um_map_chars_greek:nn {bfit} {#1}
    \um_set_mathalphabet_greek:Nnn \mathbf {it} {#1}
  }{
    \bool_if:NF \g_um_bfupgreek_bool {
      \um_map_chars_greek:nn {bfit,bfup} {#1}
      \um_set_mathalphabet_greek:Nnn \mathbf {up,it} {#1}
    }
  }
}
\cs_new:Npn \um_config_bfit_misc:n #1 {
  \bool_if:NTF \g_um_literal_Nabla_bool {
    \um_map_single:nnn {Nabla}{bfit}{#1}
  }{
    \bool_if:NF \g_um_upNabla_bool {
      \um_map_single:nnn {Nabla}{bfup,bfit}{#1}
    }
  }
  \bool_if:NTF \g_um_literal_partial_bool {
    \um_map_single:nnn {partial}{bfit}{#1}
  }{
    \bool_if:NF \g_um_uppartial_bool {
      \um_map_single:nnn {partial}{bfup,bfit}{#1}
    }
  }
  \um_set_mathalphabet_pos:Nnnn  \mathbfit {partial} {up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbfit {Nabla}   {up,it}{#1}
  \bool_if:NTF \g_um_literal_partial_bool {
    \um_set_mathalphabet_pos:Nnnn  \mathbf {partial} {it}{#1}
  }{
    \bool_if:NF \g_um_uppartial_bool {
      \um_set_mathalphabet_pos:Nnnn  \mathbf {partial} {up,it}{#1}
    }
  }
  \bool_if:NTF \g_um_literal_Nabla_bool {
    \um_set_mathalphabet_pos:Nnnn  \mathbf {Nabla}   {it}{#1}
  }{
    \bool_if:NF \g_um_upNabla_bool {
      \um_set_mathalphabet_pos:Nnnn  \mathbf {Nabla}   {up,it}{#1}
    }
  }
}
\cs_new:Npn \um_config_bfup_num:n #1 {
  \um_set_mathalphabet_numbers:Nnn \mathbf   {up}{#1}
  \um_set_mathalphabet_numbers:Nnn \mathbfup {up}{#1}
}
\cs_new:Npn \um_config_bfup_Latin:n #1 {
  \bool_if:NT \g_um_bfupLatin_bool {
    \um_map_chars_Latin:nn {bfup,bfit} {#1}
  }
  \um_set_mathalphabet_Latin:Nnn \mathbfup {up,it}{#1}
  \bool_if:NTF \g_um_bfliteral_bool {
    \um_map_chars_Latin:nn {bfup} {#1}
    \um_set_mathalphabet_Latin:Nnn \mathbf {up}{#1}
  }{
    \bool_if:NT \g_um_bfupLatin_bool {
      \um_map_chars_Latin:nn {bfup,bfit} {#1}
      \um_set_mathalphabet_Latin:Nnn \mathbf {up,it}{#1}
    }
  }
}
\cs_new:Npn \um_config_bfup_latin:n #1 {
  \bool_if:NT \g_um_bfuplatin_bool {
    \um_map_chars_latin:nn {bfup,bfit} {#1}
  }
  \um_set_mathalphabet_latin:Nnn \mathbfup {up,it}{#1}
  \bool_if:NTF \g_um_bfliteral_bool {
    \um_map_chars_latin:nn {bfup} {#1}
    \um_set_mathalphabet_latin:Nnn \mathbf {up}{#1}
  }{
    \bool_if:NT \g_um_bfuplatin_bool {
      \um_map_chars_latin:nn {bfup,bfit} {#1}
      \um_set_mathalphabet_latin:Nnn \mathbf {up,it}{#1}
    }
  }
}
\cs_new:Npn \um_config_bfup_Greek:n #1 {
  \um_set_mathalphabet_Greek:Nnn \mathbfup {up,it}{#1}
  \bool_if:NTF \g_um_bfliteral_bool {
    \um_map_chars_Greek:nn {bfup}{#1}
    \um_set_mathalphabet_Greek:Nnn \mathbf {up}{#1}
  }{
    \bool_if:NT \g_um_bfupGreek_bool {
      \um_map_chars_Greek:nn {bfup,bfit}{#1}
      \um_set_mathalphabet_Greek:Nnn \mathbf {up,it}{#1}
    }
  }
}
\cs_new:Npn \um_config_bfup_greek:n #1 {
  \um_set_mathalphabet_greek:Nnn \mathbfup {up,it} {#1}
  \bool_if:NTF \g_um_bfliteral_bool {
    \um_map_chars_greek:nn {bfup} {#1}
    \um_set_mathalphabet_greek:Nnn \mathbf {up} {#1}
  }{
    \bool_if:NT \g_um_bfupgreek_bool {
      \um_map_chars_greek:nn {bfup,bfit} {#1}
      \um_set_mathalphabet_greek:Nnn \mathbf {up,it} {#1}
    }
  }
}
\cs_new:Npn \um_config_bfup_misc:n #1 {
  \bool_if:NTF \g_um_literal_Nabla_bool {
    \um_map_single:nnn {Nabla}{bfup}{#1}
  }{
    \bool_if:NT \g_um_upNabla_bool {
      \um_map_single:nnn {Nabla}{bfup,bfit}{#1}
    }
  }
  \bool_if:NTF \g_um_literal_partial_bool {
    \um_map_single:nnn {partial}{bfup}{#1}
  }{
    \bool_if:NT \g_um_uppartial_bool {
      \um_map_single:nnn {partial}{bfup,bfit}{#1}
    }
  }
  \um_set_mathalphabet_pos:Nnnn  \mathbfup {partial} {up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbfup {Nabla}   {up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbfup {digamma} {up}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbfup {Digamma} {up}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbf   {digamma} {up}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbf   {Digamma} {up}{#1}
  \bool_if:NTF \g_um_literal_partial_bool {
    \um_set_mathalphabet_pos:Nnnn  \mathbf {partial} {up}{#1}
  }{
    \bool_if:NT \g_um_uppartial_bool {
      \um_set_mathalphabet_pos:Nnnn  \mathbf {partial} {up,it}{#1}
    }
  }
  \bool_if:NTF \g_um_literal_Nabla_bool {
    \um_set_mathalphabet_pos:Nnnn  \mathbf {Nabla}   {up}{#1}
  }{
    \bool_if:NT \g_um_upNabla_bool {
      \um_set_mathalphabet_pos:Nnnn  \mathbf {Nabla}   {up,it}{#1}
    }
  }
}
\cs_new:Npn \um_config_bffrak_Latin:n #1 {
  \um_set_mathalphabet_Latin:Nnn \mathbffrak {up,it}{#1}
}
\cs_new:Npn \um_config_bffrak_latin:n #1 {
  \um_set_mathalphabet_latin:Nnn \mathbffrak {up,it}{#1}
}
\cs_new:Npn \um_config_bfscr_Latin:n #1 {
  \um_set_mathalphabet_Latin:Nnn \mathbfscr {up,it}{#1}
}
\cs_new:Npn \um_config_bfscr_latin:n #1 {
  \um_set_mathalphabet_latin:Nnn \mathbfscr {up,it}{#1}
}
\cs_new:Npn \um_config_bfsfup_num:n #1 {
  \um_set_mathalphabet_numbers:Nnn \mathbfsf   {up}{#1}
  \um_set_mathalphabet_numbers:Nnn \mathbfsfup {up}{#1}
}
\cs_new:Npn \um_config_bfsfup_Latin:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_Latin:nn {bfsfup} {#1}
    \um_set_mathalphabet_Latin:Nnn \mathbfsf {up}{#1}
  }{
    \bool_if:NT \g_um_upsans_bool {
      \um_map_chars_Latin:nn {bfsfup,bfsfit} {#1}
      \um_set_mathalphabet_Latin:Nnn \mathbfsf {up,it}{#1}
    }
  }
  \um_set_mathalphabet_Latin:Nnn \mathbfsfup {up,it}{#1}
}
\cs_new:Npn \um_config_bfsfup_latin:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_latin:nn {bfsfup} {#1}
    \um_set_mathalphabet_latin:Nnn \mathbfsf {up}{#1}
  }{
    \bool_if:NT \g_um_upsans_bool {
      \um_map_chars_latin:nn {bfsfup,bfsfit} {#1}
      \um_set_mathalphabet_latin:Nnn \mathbfsf {up,it}{#1}
    }
  }
  \um_set_mathalphabet_latin:Nnn \mathbfsfup {up,it}{#1}
}
\cs_new:Npn \um_config_bfsfup_Greek:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_Greek:nn {bfsfup}{#1}
    \um_set_mathalphabet_Greek:Nnn \mathbfsf {up}{#1}
  }{
    \bool_if:NT \g_um_upsans_bool {
      \um_map_chars_Greek:nn {bfsfup,bfsfit}{#1}
      \um_set_mathalphabet_Greek:Nnn \mathbfsf {up,it}{#1}
    }
  }
  \um_set_mathalphabet_Greek:Nnn \mathbfsfup {up,it}{#1}
}
\cs_new:Npn \um_config_bfsfup_greek:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_greek:nn {bfsfup} {#1}
    \um_set_mathalphabet_greek:Nnn \mathbfsf {up} {#1}
  }{
    \bool_if:NT \g_um_upsans_bool {
      \um_map_chars_greek:nn {bfsfup,bfsfit} {#1}
      \um_set_mathalphabet_greek:Nnn \mathbfsf {up,it} {#1}
    }
  }
  \um_set_mathalphabet_greek:Nnn \mathbfsfup {up,it} {#1}
}
\cs_new:Npn \um_config_bfsfup_misc:n #1 {
  \bool_if:NTF \g_um_literal_Nabla_bool {
    \um_map_single:nnn {Nabla}{bfsfup}{#1}
  }{
    \bool_if:NT \g_um_upNabla_bool {
      \um_map_single:nnn {Nabla}{bfsfup,bfsfit}{#1}
    }
  }
  \bool_if:NTF \g_um_literal_partial_bool {
    \um_map_single:nnn {partial}{bfsfup}{#1}
  }{
    \bool_if:NT \g_um_uppartial_bool {
      \um_map_single:nnn {partial}{bfsfup,bfsfit}{#1}
    }
  }
  \um_set_mathalphabet_pos:Nnnn  \mathbfsfup {partial} {up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbfsfup {Nabla}   {up,it}{#1}
  \bool_if:NTF \g_um_literal_partial_bool {
    \um_set_mathalphabet_pos:Nnnn  \mathbfsf {partial} {up}{#1}
  }{
    \bool_if:NT \g_um_uppartial_bool {
      \um_set_mathalphabet_pos:Nnnn  \mathbfsf {partial} {up,it}{#1}
    }
  }
  \bool_if:NTF \g_um_literal_Nabla_bool {
    \um_set_mathalphabet_pos:Nnnn  \mathbfsf {Nabla}   {up}{#1}
  }{
    \bool_if:NT \g_um_upNabla_bool {
      \um_set_mathalphabet_pos:Nnnn  \mathbfsf {Nabla}   {up,it}{#1}
    }
  }
}
\cs_new:Npn \um_config_bfsfit_Latin:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_Latin:nn {bfsfit} {#1}
    \um_set_mathalphabet_Latin:Nnn \mathbfsf {it}{#1}
  }{
    \bool_if:NF \g_um_upsans_bool {
      \um_map_chars_Latin:nn {bfsfup,bfsfit} {#1}
      \um_set_mathalphabet_Latin:Nnn \mathbfsf {up,it}{#1}
    }
  }
  \um_set_mathalphabet_Latin:Nnn \mathbfsfit {up,it}{#1}
}
\cs_new:Npn \um_config_bfsfit_latin:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_latin:nn {bfsfit} {#1}
    \um_set_mathalphabet_latin:Nnn \mathbfsf {it}{#1}
  }{
    \bool_if:NF \g_um_upsans_bool {
      \um_map_chars_latin:nn {bfsfup,bfsfit} {#1}
      \um_set_mathalphabet_latin:Nnn \mathbfsf {up,it}{#1}
    }
  }
  \um_set_mathalphabet_latin:Nnn \mathbfsfit {up,it}{#1}
}
\cs_new:Npn \um_config_bfsfit_Greek:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_Greek:nn {bfsfit}{#1}
    \um_set_mathalphabet_Greek:Nnn \mathbfsf {it}{#1}
  }{
    \bool_if:NF \g_um_upsans_bool {
      \um_map_chars_Greek:nn {bfsfup,bfsfit}{#1}
      \um_set_mathalphabet_Greek:Nnn \mathbfsf {up,it}{#1}
    }
  }
  \um_set_mathalphabet_Greek:Nnn \mathbfsfit {up,it}{#1}
}
\cs_new:Npn \um_config_bfsfit_greek:n #1 {
  \bool_if:NTF \g_um_sfliteral_bool {
    \um_map_chars_greek:nn {bfsfit} {#1}
    \um_set_mathalphabet_greek:Nnn \mathbfsf {it} {#1}
  }{
    \bool_if:NF \g_um_upsans_bool {
      \um_map_chars_greek:nn {bfsfup,bfsfit} {#1}
      \um_set_mathalphabet_greek:Nnn \mathbfsf {up,it} {#1}
    }
  }
  \um_set_mathalphabet_greek:Nnn \mathbfsfit {up,it} {#1}
}
\cs_new:Npn \um_config_bfsfit_misc:n #1 {
  \bool_if:NTF \g_um_literal_Nabla_bool {
    \um_map_single:nnn {Nabla}{bfsfit}{#1}
  }{
    \bool_if:NF \g_um_upNabla_bool {
      \um_map_single:nnn {Nabla}{bfsfup,bfsfit}{#1}
    }
  }
  \bool_if:NTF \g_um_literal_partial_bool {
    \um_map_single:nnn {partial}{bfsfit}{#1}
  }{
    \bool_if:NF \g_um_uppartial_bool {
      \um_map_single:nnn {partial}{bfsfup,bfsfit}{#1}
    }
  }
  \um_set_mathalphabet_pos:Nnnn  \mathbfsfit {partial} {up,it}{#1}
  \um_set_mathalphabet_pos:Nnnn  \mathbfsfit {Nabla}   {up,it}{#1}
  \bool_if:NTF \g_um_literal_partial_bool {
    \um_set_mathalphabet_pos:Nnnn  \mathbfsf {partial} {it}{#1}
  }{
    \bool_if:NF \g_um_uppartial_bool {
      \um_set_mathalphabet_pos:Nnnn  \mathbfsf {partial} {up,it}{#1}
    }
  }
  \bool_if:NTF \g_um_literal_Nabla_bool {
    \um_set_mathalphabet_pos:Nnnn  \mathbfsf {Nabla}   {it}{#1}
  }{
    \bool_if:NF \g_um_upNabla_bool {
      \um_set_mathalphabet_pos:Nnnn  \mathbfsf {Nabla}   {up,it}{#1}
    }
  }
}
\begingroup
  \char_make_other:N \^
  \cs_gset:Npn \um@scancharlet#1="#2\@nil {
    \lowercase{
      \tl_rescan:nn {
        \char_make_other:N \{
        \char_make_other:N \}
        \char_make_other:N \&
        \char_make_other:N \%
        \char_make_other:N \$
      }{
        \global\let#1=^^^^^#2
      }
    }
  }
  \gdef\um@scanactivedef"#1\@nil#2{
    \lowercase{
      \tl_rescan:nn{
        \ExplSyntaxOn
        \char_make_math_superscript:N\^
      }{
        \global\def^^^^^#1{#2}
      }
    }
  }
\endgroup
\AtBeginDocument{
  \group_begin:
    \char_make_math_superscript:N\^
    \def\UnicodeMathSymbol#1#2#3#4{
      \bool_if:nF { \cs_if_eq_p:NN #3 \mathaccent ||
                    \cs_if_eq_p:NN #3 \mathopen   ||
                    \cs_if_eq_p:NN #3 \mathclose } {
        \um@scancharlet#2=#1\@nil\ignorespaces
      }
    }
    \char_make_other:N \#
    \@input{unicode-math-table.tex}
  \group_end:
}
\group_begin:
  \lccode`\*=`\\
  \char_make_escape:N \|
  \char_make_other:N \\
  |lowercase{
    |AtBeginDocument{
      |let|backslash=*
    }
  }
|group_end:
\muskip_new:N \g_um_primekern_muskip
\muskip_gset:Nn \g_um_primekern_muskip { -\thinmuskip/2 }% arbitrary
\int_new:N \l_um_primecount_int
\cs_new:Npn \um_nprimes:Nn #1#2 {
  ^{
     #1
     \prg_replicate:nn {#2-1} { \mskip \g_um_primekern_muskip #1 }
   }
}
\cs_new:Npn \um_nprimes_select:nn #1#2 {
  \prg_case_int:nnn {#2}{
    {1} { ^{#1} }
    {2} {
      \um_glyph_if_exist:nTF {"2033} { ^{\um_prime_double_mchar} } {\um_nprimes:Nn #1 {#2}}
    }
    {3} {
      \um_glyph_if_exist:nTF {"2034} {^{\um_prime_triple_mchar} } {\um_nprimes:Nn #1 {#2}}
    }
    {4} {
      \um_glyph_if_exist:nTF {"2057} { ^{\um_prime_quad_mchar} } {\um_nprimes:Nn #1 {#2}}
    }
  }{
    \um_nprimes:Nn #1 {#2}
  }
}
\cs_new:Npn \um_nbackprimes_select:nn #1#2 {
  \prg_case_int:nnn {#2}{
    {1} { ^{#1} }
    {2} {
      \um_glyph_if_exist:nTF {"2033} { ^{\um_backprime_double_mchar} } {\um_nprimes:Nn #1 {#2}}
    }
    {3} {
      \um_glyph_if_exist:nTF {"2034} {^{\um_backprime_triple_mchar} } {\um_nprimes:Nn #1 {#2}}
    }
  }{
    \um_nprimes:Nn #1 {#2}
  }
}
\cs_new:Npn \um_scan_prime: {
  \int_zero:N \l_um_primecount_int
  \um_scanprime_collect:N \um_prime_single_mchar
}
\cs_new:Npn \um_scan_dprime: {
  \int_set:Nn \l_um_primecount_int {1}
  \um_scanprime_collect:N \um_prime_single_mchar
}
\cs_new:Npn \um_scan_trprime: {
  \int_set:Nn \l_um_primecount_int {2}
  \um_scanprime_collect:N \um_prime_single_mchar
}
\cs_new:Npn \um_scan_qprime: {
  \int_set:Nn \l_um_primecount_int {3}
  \um_scanprime_collect:N \um_prime_single_mchar
}
\cs_new:Npn \um_scanprime_collect:N #1 {
  \int_incr:N \l_um_primecount_int
  \peek_meaning_remove:NTF ' {
    \um_scanprime_collect:N #1
  }{
    \peek_meaning_remove:NTF \um_scan_prime: {
      \um_scanprime_collect:N #1
    }{
      \peek_meaning_remove:NTF ^^^^2032 {
        \um_scanprime_collect:N #1
      }{
        \peek_meaning_remove:NTF \um_scan_dprime: {
          \int_incr:N \l_um_primecount_int
          \um_scanprime_collect:N #1
        }{
          \peek_meaning_remove:NTF ^^^^2033 {
            \int_incr:N \l_um_primecount_int
            \um_scanprime_collect:N #1
          }{
            \peek_meaning_remove:NTF \um_scan_trprime: {
              \int_add:Nn \l_um_primecount_int {2}
              \um_scanprime_collect:N #1
            }{
              \peek_meaning_remove:NTF ^^^^2034 {
                \int_add:Nn \l_um_primecount_int {2}
                \um_scanprime_collect:N #1
              }{
                \peek_meaning_remove:NTF \um_scan_qprime: {
                  \int_add:Nn \l_um_primecount_int {3}
                  \um_scanprime_collect:N #1
                }{
                  \peek_meaning_remove:NTF ^^^^2057 {
                    \int_add:Nn \l_um_primecount_int {3}
                    \um_scanprime_collect:N #1
                  }{
                    \um_nprimes_select:nn {#1} {\l_um_primecount_int}
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
\cs_new:Npn \um_scan_backprime: {
  \int_zero:N \l_um_primecount_int
  \um_scanbackprime_collect:N \um_backprime_single_mchar
}
\cs_new:Npn \um_scan_backdprime: {
  \int_set:Nn \l_um_primecount_int {1}
  \um_scanbackprime_collect:N \um_backprime_single_mchar
}
\cs_new:Npn \um_scan_backtrprime: {
  \int_set:Nn \l_um_primecount_int {2}
  \um_scanbackprime_collect:N \um_backprime_single_mchar
}
\cs_new:Npn \um_scanbackprime_collect:N #1 {
  \int_incr:N \l_um_primecount_int
  \peek_meaning_remove:NTF ` {
    \um_scanbackprime_collect:N #1
  }{
    \peek_meaning_remove:NTF \um_scan_backprime: {
      \um_scanbackprime_collect:N #1
    }{
      \peek_meaning_remove:NTF ^^^^2035 {
        \um_scanbackprime_collect:N #1
      }{
        \peek_meaning_remove:NTF \um_scan_backdprime: {
          \int_incr:N \l_um_primecount_int
          \um_scanbackprime_collect:N #1
        }{
          \peek_meaning_remove:NTF ^^^^2036 {
            \int_incr:N \l_um_primecount_int
            \um_scanbackprime_collect:N #1
          }{
            \peek_meaning_remove:NTF \um_scan_backtrprime: {
              \int_add:Nn \l_um_primecount_int {2}
              \um_scanbackprime_collect:N #1
            }{
              \peek_meaning_remove:NTF ^^^^2037 {
                \int_add:Nn \l_um_primecount_int {2}
                \um_scanbackprime_collect:N #1
              }{
                \um_nbackprimes_select:nn {#1} {\l_um_primecount_int}
              }
            }
          }
        }
      }
    }
  }
}
\AtBeginDocument {
  \cs_set_eq:NN \prime       \um_scan_prime:
  \cs_set_eq:NN \drime       \um_scan_dprime:
  \cs_set_eq:NN \trprime     \um_scan_trprime:
  \cs_set_eq:NN \qprime      \um_scan_qprime:
  \cs_set_eq:NN \backprime   \um_scan_backprime:
  \cs_set_eq:NN \backdprime  \um_scan_backdprime:
  \cs_set_eq:NN \backtrprime \um_scan_backtrprime:
}
\group_begin:
  \char_make_active:N \'
  \char_make_active:N \`
  \char_make_active:n {"2032}
  \char_make_active:n {"2033}
  \char_make_active:n {"2034}
  \char_make_active:n {"2057}
  \char_make_active:n {"2035}
  \char_make_active:n {"2036}
  \char_make_active:n {"2037}
  \AtBeginDocument{
    \cs_set_eq:NN '        \um_scan_prime:
    \cs_set_eq:NN ^^^^2032 \um_scan_prime:
    \cs_set_eq:NN ^^^^2033 \um_scan_dprime:
    \cs_set_eq:NN ^^^^2034 \um_scan_trprime:
    \cs_set_eq:NN ^^^^2057 \um_scan_qprime:
    \cs_set_eq:NN `        \um_scan_backprime:
    \cs_set_eq:NN ^^^^2035 \um_scan_backprime:
    \cs_set_eq:NN ^^^^2036 \um_scan_backdprime:
    \cs_set_eq:NN ^^^^2037 \um_scan_backtrprime:
  }
\group_end:
\cs_set_nopar:Npn \r@@t #1#2 {
  \setbox\z@\hbox{$\m@th #1\sqrtsign{#2}$}
  \um_mathstyle_scale:Nnn{#1}{\kern}{\fontdimen63\l_um_font}
  \raise \dimexpr(
      \um_fontdimen_to_percent:nn{65}{\l_um_font}\ht\z@-
      \um_fontdimen_to_percent:nn{65}{\l_um_font}\dp\z@
    )\relax
    \copy \rootbox
  \um_mathstyle_scale:Nnn{#1}{\kern}{\fontdimen64\l_um_font}
  \box \z@
}
\cs_new:Npn \um_fontdimen_to_percent:nn #1#2 {
  0.\strip@pt\dimexpr\fontdimen#1#2 *65536\relax
}
\cs_new:Npn \um_mathstyle_scale:Nnn #1#2#3 {
  \ifx#1\scriptstyle
    #2\um_fontdimen_to_percent:nn{10}\l_um_font#3
  \else
    \ifx#1\scriptscriptstyle
      #2\um_fontdimen_to_percent:nn{11}\l_um_font#3
    \else
      #2#3
    \fi
  \fi
}
\prop_new:N \g_um_supers_prop
\prop_new:N \g_um_subs_prop
\group_begin:
\cs_set:Npn \um_setup_active_superscript:nn #1#2 {
  \prop_gput:Nxn \g_um_supers_prop   {\meaning #1} {#2}
  \char_make_active:N #1
  \char_gmake_mathactive:N #1
  \scantokens{
    \cs_gset:Npn #1 {
      \tl_set:Nn \l_um_ss_chain_tl {#2}
      \cs_set_eq:NN \um_sub_or_super:n \sp
      \tl_set:Nn \l_um_tmpa_tl {supers}
      \um_scan_sscript:
    }
  }
}
\um_setup_active_superscript:nn {^^^^2070} {0}
\um_setup_active_superscript:nn {^^^^00b9} {1}
\um_setup_active_superscript:nn {^^^^00b2} {2}
\um_setup_active_superscript:nn {^^^^00b3} {3}
\um_setup_active_superscript:nn {^^^^2074} {4}
\um_setup_active_superscript:nn {^^^^2075} {5}
\um_setup_active_superscript:nn {^^^^2076} {6}
\um_setup_active_superscript:nn {^^^^2077} {7}
\um_setup_active_superscript:nn {^^^^2078} {8}
\um_setup_active_superscript:nn {^^^^2079} {9}
\um_setup_active_superscript:nn {^^^^207a} {+}
\um_setup_active_superscript:nn {^^^^207b} {-}
\um_setup_active_superscript:nn {^^^^207c} {=}
\um_setup_active_superscript:nn {^^^^207d} {(}
\um_setup_active_superscript:nn {^^^^207e} {)}
\um_setup_active_superscript:nn {^^^^2071} {i}
\um_setup_active_superscript:nn {^^^^207f} {n}
\cs_set:Npn \um_setup_active_subscript:nn #1#2 {
  \prop_gput:Nxn \g_um_subs_prop   {\meaning #1} {#2}
  \char_make_active:N #1
  \char_gmake_mathactive:N #1
  \scantokens{
    \cs_gset:Npn #1 {
      \tl_set:Nn \l_um_ss_chain_tl {#2}
      \cs_set_eq:NN \um_sub_or_super:n \sb
      \tl_set:Nn \l_um_tmpa_tl {subs}
      \um_scan_sscript:
    }
  }
}
\um_setup_active_subscript:nn {^^^^2080} {0}
\um_setup_active_subscript:nn {^^^^2081} {1}
\um_setup_active_subscript:nn {^^^^2082} {2}
\um_setup_active_subscript:nn {^^^^2083} {3}
\um_setup_active_subscript:nn {^^^^2084} {4}
\um_setup_active_subscript:nn {^^^^2085} {5}
\um_setup_active_subscript:nn {^^^^2086} {6}
\um_setup_active_subscript:nn {^^^^2087} {7}
\um_setup_active_subscript:nn {^^^^2088} {8}
\um_setup_active_subscript:nn {^^^^2089} {9}
\um_setup_active_subscript:nn {^^^^208a} {+}
\um_setup_active_subscript:nn {^^^^208b} {-}
\um_setup_active_subscript:nn {^^^^208c} {=}
\um_setup_active_subscript:nn {^^^^208d} {(}
\um_setup_active_subscript:nn {^^^^208e} {)}
\um_setup_active_subscript:nn {^^^^2090} {a}
\um_setup_active_subscript:nn {^^^^2091} {e}
\um_setup_active_subscript:nn {^^^^1d62} {i}
\um_setup_active_subscript:nn {^^^^2092} {o}
\um_setup_active_subscript:nn {^^^^1d63} {r}
\um_setup_active_subscript:nn {^^^^1d64} {u}
\um_setup_active_subscript:nn {^^^^1d65} {v}
\um_setup_active_subscript:nn {^^^^2093} {x}
\um_setup_active_subscript:nn {^^^^1d66} {\beta}
\um_setup_active_subscript:nn {^^^^1d67} {\gamma}
\um_setup_active_subscript:nn {^^^^1d68} {\rho}
\um_setup_active_subscript:nn {^^^^1d69} {\phi}
\um_setup_active_subscript:nn {^^^^1d6a} {\chi}
\group_end:
\cs_new:Npn \um_scan_sscript: {
  \um_scan_sscript:TF {
    \um_scan_sscript:
  }{
    \um_sub_or_super:n {\l_um_ss_chain_tl}
  }
}
\cs_new:Npn \um_scan_sscript:TF #1#2 {
  \tl_set:Nx \l_peek_true_aux_tl { \exp_not:n{ #1 } }
  \tl_set_eq:NN \l_peek_true_tl \c_peek_true_remove_next_tl
  \tl_set:Nx \l_peek_false_tl {\exp_not:n{\group_align_safe_end: #2}}
  \group_align_safe_begin:
    \peek_after:NN \um_peek_execute_branches_ss:
}
\cs_new:Npn \um_peek_execute_branches_ss: {
  \bool_if:nTF {
    \token_if_eq_catcode_p:NN \l_peek_token \c_group_begin_token ||
    \token_if_eq_catcode_p:NN \l_peek_token \c_group_end_token ||
    \token_if_eq_meaning_p:NN \l_peek_token \c_space_token
  }
  { \l_peek_false_tl  }
  { \um_peek_execute_branches_ss_aux: }
}
\cs_new:Npn \um_peek_execute_branches_ss_aux: {
  \prop_if_in:cxTF
    {g_um_\l_um_tmpa_tl _prop}
    {\meaning\l_peek_token}
    {
      \prop_get:cxN
        {g_um_\l_um_tmpa_tl _prop}
        {\meaning\l_peek_token}
        \l_um_tmpb_tl
      \tl_put_right:NV \l_um_ss_chain_tl \l_um_tmpb_tl
      \l_peek_true_tl
    }
    {\l_peek_false_tl}
}
\cs_new:Npn \um_define_active_frac:Nw #1 #2/#3 {
  \char_make_active:N #1
  \char_gmake_mathactive:N #1
  \tl_rescan:nn {
    \ExplSyntaxOn
  }{
    \cs_gset:Npx #1 {
      \bool_if:NTF \l_um_smallfrac_bool {\exp_not:N\tfrac} {\exp_not:N\frac}
          {#2} {#3}
    }
  }
}
\cs_new:Npn \um_setup_active_frac: {
  \group_begin:
  \um_define_active_frac:Nw  ^^^^2152  1/{10}
  \um_define_active_frac:Nw  ^^^^2151  1/9
  \um_define_active_frac:Nw  ^^^^215b  1/8
  \um_define_active_frac:Nw  ^^^^2150  1/7
  \um_define_active_frac:Nw  ^^^^2159  1/6
  \um_define_active_frac:Nw  ^^^^2155  1/5
  \um_define_active_frac:Nw  ^^^^00bc  1/4
  \um_define_active_frac:Nw  ^^^^2153  1/3
  \um_define_active_frac:Nw  ^^^^215c  3/8
  \um_define_active_frac:Nw  ^^^^2156  2/5
  \um_define_active_frac:Nw  ^^^^00bd  1/2
  \um_define_active_frac:Nw  ^^^^2157  3/5
  \um_define_active_frac:Nw  ^^^^215d  5/8
  \um_define_active_frac:Nw  ^^^^2154  2/3
  \um_define_active_frac:Nw  ^^^^00be  3/4
  \um_define_active_frac:Nw  ^^^^2158  4/5
  \um_define_active_frac:Nw  ^^^^215a  5/6
  \um_define_active_frac:Nw  ^^^^215e  7/8
  \group_end:
}
\um_setup_active_frac:
\def\to{\rightarrow}
\def\overrightarrow{\vec}
\def\le{\leq}
\def\ge{\geq}
\def\neq{\ne}
\def\triangle{\mathord{\bigtriangleup}}
\def\bigcirc{\mdlgwhtcircle}
\def\circ{\vysmwhtcircle}
\def\bullet{\smblkcircle}
\def\mathyen{\yen}
\def\mathsterling{\sterling}
\@ifpackageloaded{amsmath}{
  % define their own colon, perhaps I should just steal it. (It does look much better.)
}{
  \cs_set_protected:Npn \colon {
    \bool_if:NTF \g_um_literal_colon_bool {:} { \mathpunct{:} }
  }
}
\def\mathcal{\mathscr}
\def\mathrm{\mathup}
\let\mathfence\mathord
\def\digamma{\updigamma}
\def\Digamma{\upDigamma}
\def\operator@font{\um_switchto_mathup:}
\cs_new:Npn \um_patch_pkg:nn #1#2 {
  \@ifpackageloaded {#1} {
    #2
  }{
    \um_after_pkg:nn {#1} {#2}
  }
}
\um_patch_pkg:nn {url} {
  \tl_put_left:Nn \Url@FormatString { \um_switchto_mathup: }
  \tl_put_right:Nn \UrlSpecials {
    \do\`{\mathchar`\`}
    \do\'{\mathchar`\'}
    \do\${\mathchar`\$}
    \do\&{\mathchar`\&}
  }
}
\um_patch_pkg:nn {amsmath} {
  \tl_remove_in:Nn \@begindocumenthook {
    \mathchardef\std@minus\mathcode`\-\relax
    \mathchardef\std@equal\mathcode`\=\relax
  }
  \def\std@minus{\Umathcharnum\Umathcodenum`\-\relax}
  \def\std@equal{\Umathcharnum\Umathcodenum`\=\relax}
  \def\@cdots{\mathinner{\cdots}}
  \cs_set_eq:NN \dotsb@ \cdots
}
\um_patch_pkg:nn {amsopn} {
  \cs_set:Npn \newmcodes@ {
    \mathcode`\'39\scan_stop:
    \mathcode`\*42\scan_stop:
    \mathcode`\."613A\scan_stop:
%%  \ifnum\mathcode`\-=45 \else
%%    \mathchardef\std@minus\mathcode`\-\relax
%%  \fi
    \mathcode`\-45\scan_stop:
    \mathcode`\/47\scan_stop:
    \mathcode`\:"603A\scan_stop:
  }
}
\cs_set:Npn \| {\Vert}
\cs_set:Npn \mathellipsis {\mathinner{\unicodeellipsis}}
\cs_set:Npn \cdots {\mathinner{\unicodecdots}}
\AtBeginDocument{
  \def\widehat{\hat}
  \def\widetilde{\tilde}
}
\AtEndOfPackage{
  \@ifclassloaded{beamer}{
    \ifbeamer@suppressreplacements\else
      \um_warning:n {disable-beamer}
      \beamer@suppressreplacementstrue
    \fi
  }{}
}
\cs_new:Npn \um_warning:n { \msg_warning:nn {unicode-math} }
\cs_new:Npn \um_trace:n   { \msg_trace:nn   {unicode-math} }
\cs_new:Npn \um_trace:nx  { \msg_trace:nnx  {unicode-math} }
\msg_new:nnn {unicode-math} {maths-feature-only}
{
  The~ '#1'~ font~ feature~ can~ only~ be~ used~ for~ maths~ fonts.
}
\msg_new:nnn {unicode-math} {disable-beamer}
{
  Disabling~ beamer's~ math~ setup.\\
  Please~ load~ beamer~ with~ the~ [professionalfonts]~ class~ option.
}
\msg_new:nnn {unicode-math} {no-tfrac}
{
  Small~ fraction~ command~ \protect\tfrac\ not~ defined.\\
  Load~ amsmath~ or~ define~ it~ manually~ before~ loading~ unicode-math.
}
\msg_new:nnn {unicode-math} {default-math-font}
{
  Defining~ the~ default~ maths~ font~ as~ '#1'.
}
\msg_new:nnn {unicode-math} {setup-implicit}
{
  Setup~ alphabets:~ implicit~ mode.
}
\msg_new:nnn {unicode-math} {setup-explicit}
{
  Setup~ alphabets:~ explicit~ mode.
}
\msg_new:nnn {unicode-math} {alph-initialise}
{
  Initialising~ \@backslashchar math#1.
}
\msg_new:nnn {unicode-math} {setup-alph}
{
  Setup~ alphabet:~ #1.
}
\ExplSyntaxOff
\errorcontextlines=999
