%%
%% This is file `unicode-math.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% unicode-math.dtx  (with options: `preamble')
%% unicode-math.dtx  (with options: `msg')
%% unicode-math.dtx  (with options: `load')
%% Copyright 2006-2013   Will Robertson <will.robertson@latex-project.org>
%% Copyright 2010-2013 Philipp Stephani <st_philipp@yahoo.de>
%% Copyright 2012-2013     Khaled Hosny <khaledhosny@eglug.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}
  [2013/02/22 v0.7b Unicode maths in XeLaTeX and LuaLaTeX]
\usepackage{ifxetex,ifluatex}
\ifxetex
  \ifdim\number\XeTeXversion\XeTeXrevision in<0.9998in%
    \PackageError{unicode-math}{%
      Cannot run with this version of XeTeX!\MessageBreak
      You need XeTeX 0.9998 or newer.%
    }\@ehd
  \fi
\else\ifluatex
  \ifnum\luatexversion<64%
    \PackageError{unicode-math}{%
      Cannot run with this version of LuaTeX!\MessageBreak
      You need LuaTeX 0.64 or newer.%
    }\@ehd
  \fi
\else
  \PackageError{unicode-math}{%
    Cannot be run with pdfLaTeX!\MessageBreak
    Use XeLaTeX or LuaLaTeX instead.%
  }\@ehd
\fi\fi
\RequirePackage{expl3}[2011/07/01]
\RequirePackage{xparse}[2009/08/31]
\RequirePackage{l3keys2e}
\RequirePackage{fontspec}[2010/10/25]
\RequirePackage{catchfile}
\RequirePackage{fix-cm} % avoid some warnings
\RequirePackage{filehook}[2011/01/03]
\ExplSyntaxOn
\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_set: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_ot_math_bool
\bool_new:N \l_um_init_bool
\bool_new:N \l_um_implicit_alph_bool
\bool_new:N \g_um_mainfont_already_set_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_set_true: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_const:Nn \c_um_math_alphabet_name_latin_tl {Latin,~lowercase}
\tl_const:Nn \c_um_math_alphabet_name_Latin_tl {Latin,~uppercase}
\tl_const:Nn \c_um_math_alphabet_name_greek_tl {Greek,~lowercase}
\tl_const:Nn \c_um_math_alphabet_name_Greek_tl {Greek,~uppercase}
\tl_const:Nn \c_um_math_alphabet_name_num_tl   {Numerals}
\tl_const:Nn \c_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}
\cs_generate_variant:Nn \fontspec_set_family:Nnn {Nx}
\cs_generate_variant:Nn \fontspec_set_fontface:NNnn {NNx}
\DeclareDocumentCommand \unimathsetup {m}
 {
  \keys_set:nn  {unicode-math} {#1}
 }
\cs_new:Nn \um_tl_map_dbl:nN
  {
    \__um_tl_map_dbl:Nnn #2 #1 \q_recursion_tail {}{} \q_recursion_stop
  }
\cs_new:Nn \__um_tl_map_dbl:Nnn
  {
    \quark_if_recursion_tail_stop:n {#2}
    \quark_if_recursion_tail_stop:n {#3}
    #1 {#2} {#3}
    \__um_tl_map_dbl:Nnn #1
 }
\cs_new:Nn \um_keys_choices:nn
 {
  \cs_set:Npn \um_keys_choices_fn:nn { \um_keys_choices_aux:nnn {#1} }
  \use:x
   {
    \exp_not:N \keys_define:nn {unicode-math}
     {
      #1 .choice: ,
      \um_tl_map_dbl:nN {#2} \um_keys_choices_fn:nn
     }
   }
 }
\cs_new:Nn \um_keys_choices_aux:nnn { #1 / #2 .code:n = { \exp_not:n {#3} } , }
\um_keys_choices:nn {normal-style}
 {
   {ISO} {
       \bool_set_false:N \g_um_literal_bool
       \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 }
   {TeX} {
       \bool_set_false:N \g_um_literal_bool
       \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 }
   {french} {
       \bool_set_false:N \g_um_literal_bool
       \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 }
   {upright} {
       \bool_set_false:N \g_um_literal_bool
       \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 }
   {literal} {
       \bool_set_true:N  \g_um_literal_bool }
 }
\um_keys_choices:nn {math-style}
 {
  {ISO} {
      \unimathsetup { nabla=upright, partial=italic,
       normal-style=ISO, bold-style=ISO, sans-style=italic } }
  {TeX} {
      \unimathsetup { nabla=upright, partial=italic,
        normal-style=TeX, bold-style=TeX, sans-style=upright } }
  {french} {
      \unimathsetup { nabla=upright, partial=upright,
        normal-style=french, bold-style=upright, sans-style=upright } }
  {upright} {
      \unimathsetup { nabla=upright, partial=upright,
        normal-style=upright, bold-style=upright, sans-style=upright } }
  {literal} {
      \unimathsetup { colon=literal, nabla=literal, partial=literal,
        normal-style=literal, bold-style=literal, sans-style=literal } }
 }
\um_keys_choices:nn {bold-style}
 {
  {ISO} {
      \bool_set_false:N \g_um_bfliteral_bool
      \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 }
  {TeX} {
      \bool_set_false:N \g_um_bfliteral_bool
      \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 }
  {upright} {
      \bool_set_false:N \g_um_bfliteral_bool
      \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 }
  {literal} {
      \bool_set_true:N \g_um_bfliteral_bool }
 }
\um_keys_choices:nn {sans-style}
 {
  {italic}  { \bool_set_false:N \g_um_upsans_bool    }
  {upright} { \bool_set_true:N  \g_um_upsans_bool    }
  {literal} { \bool_set_true:N  \g_um_sfliteral_bool }
 }
\um_keys_choices:nn {nabla}
 {
  {upright} { \bool_set_false:N \g_um_literal_Nabla_bool
              \bool_set_true:N  \g_um_upNabla_bool    }
  {italic}  { \bool_set_false:N \g_um_literal_Nabla_bool
              \bool_set_false:N \g_um_upNabla_bool    }
  {literal} { \bool_set_true:N  \g_um_literal_Nabla_bool }
 }
\um_keys_choices:nn {partial}
 {
  {upright} { \bool_set_false:N \g_um_literal_partial_bool
              \bool_set_true:N  \g_um_uppartial_bool    }
  {italic}  { \bool_set_false:N \g_um_literal_partial_bool
              \bool_set_false:N \g_um_uppartial_bool    }
  {literal} { \bool_set_true:N  \g_um_literal_partial_bool }
 }
\um_keys_choices:nn {vargreek-shape}
 {
  {unicode} {\bool_set_false:N \g_um_texgreek_bool}
  {TeX}     {\bool_set_true:N  \g_um_texgreek_bool}
 }
\um_keys_choices:nn {colon}
 {
  {literal} {\bool_set_true:N  \g_um_literal_colon_bool}
  {TeX}     {\bool_set_false:N \g_um_literal_colon_bool}
 }
\um_keys_choices:nn {slash-delimiter}
 {
  {ascii} {\tl_set:Nn \g_um_slash_delimiter_usv {"002F}}
  {frac}  {\tl_set:Nn \g_um_slash_delimiter_usv {"2044}}
  {div}   {\tl_set:Nn \g_um_slash_delimiter_usv {"2215}}
 }
\um_keys_choices:nn {active-frac}
 {
   {small}
   {
    \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:}
   }

   {normalsize}
   {
    \bool_set_false:N \l_um_smallfrac_bool
    \use:c {um_setup_active_frac:}
   }
 }
\keys_define:nn {unicode-math}
  {
    warnings-off .code:n =
      {
        \clist_map_inline:nn {#1}
          { \msg_redirect_name:nnn { unicode-math } { ##1 } { none } }
      }
  }
\um_keys_choices:nn {trace}
 {
  {on}    {} % default
  {debug} { \msg_redirect_module:nnn { unicode-math } { log } { warning } }
  {off}   { \msg_redirect_module:nnn { unicode-math } { log } { none } }
 }
\unimathsetup {math-style=TeX}
\unimathsetup {slash-delimiter=ascii}
\unimathsetup {trace=off}
\cs_if_exist:NT \tfrac { \unimathsetup {active-frac=small} }
\ProcessKeysOptions {unicode-math}
\cs_new:Npn \um_warning:n { \msg_warning:nn {unicode-math} }
\cs_new:Npn \um_log:n   { \msg_log:nn   {unicode-math} }
\cs_new:Npn \um_log:nx  { \msg_log:nnx  {unicode-math} }
\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~ '\l_um_fontname_tl'.
}
\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.
}
\msg_new:nnn { unicode-math } { missing-alphabets }
  {
    Missing~math~alphabets~in~font~ "\fontname\l_um_font" \\ \\
    \seq_map_function:NN \l_um_missing_alph_seq \um_print_indent:n
  }
\cs_new:Nn \um_print_indent:n { \space\space\space\space #1 \\ }
\msg_new:nnn {unicode-math} {macro-expected}
{
  I've~ expected~ that~ #1~ is~ a~ macro,~ but~ it~ isn't.
}
\msg_new:nnn {unicode-math} {wrong-meaning}
{
  I've~ expected~ #1~ to~ have~ the~ meaning~ #3,~ but~ it~ has~ the~ meaning~ #2.
}
\msg_new:nnn {unicode-math} {patch-macro}
{
  I'm~ going~ to~ patch~ macro~ #1.
}
\msg_new:nnn { unicode-math } { mathtools-overbracket } {
  Using~ \token_to_str:N \overbracket\ and~
         \token_to_str:N \underbracke\ from~
 `mathtools'~ package.\\
  \\
  Use~ \token_to_str:N \Uoverbracket\ and~
       \token_to_str:N \Uunderbracke\ for~
       original~ `unicode-math'~ definition.
}
\msg_new:nnn { unicode-math } { mathtools-colon } {
  I'm~ going~ to~ overwrite~ the~ following~ commands~ from~
  the~ `mathtools'~ package: \\ \\
  \ \ \ \ \token_to_str:N \dblcolon,~
  \token_to_str:N \coloneqq,~
  \token_to_str:N \Coloneqq,~
  \token_to_str:N \eqqcolon. \\ \\
  Note~ that~ since~ I~ won't~ overwrite~ the~ other~ colon-like~
  commands,~ using~ them~ will~ lead~ to~ inconsistencies.
}
\msg_new:nnn { unicode-math } { colonequals } {
  I'm~ going~ to~ overwrite~ the~ following~ commands~ from~
  the~ `colonequals'~ package: \\ \\
  \ \ \ \ \token_to_str:N \ratio,~
          \token_to_str:N \coloncolon,~
          \token_to_str:N \minuscolon, \\
  \ \ \ \ \token_to_str:N \colonequals,~
          \token_to_str:N \equalscolon,~
          \token_to_str:N \coloncolonequals. \\ \\
  Note~ that~ since~ I~ won't~ overwrite~ the~ other~ colon-like~
  commands,~ using~ them~ will~ lead~ to~ inconsistencies.~
  Furthermore,~ changing~ \token_to_str:N \colonsep \c_space_tl
  or~ \token_to_str:N \doublecolonsep \c_space_tl won't~ have~
  any~ effect~ on~ the~ re-defined~ commands.
}
\luatex_if_engine:T { \RequirePackage{unicode-math-luatex} \endinput }
\xetex_if_engine:T  { \RequirePackage{unicode-math-xetex}  \endinput }
