%%^^A%% um-code-epilogue.dtx -- part of UNICODE-MATH <wspr.io/unicode-math>

% \section{Epilogue}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% Lots of little things to tidy up.
%
% \subsection{Resolving Greek symbol name control sequences}
%
% \begin{macro}{\@@_resolve_greek:}
% This macro defines \cmd\Alpha\dots\cmd\omega\ as their corresponding
% Unicode (mathematical italic) character. Remember that the mapping
% to upright or italic happens with the mathcode definitions, whereas these macros
% just stand for the literal Unicode characters.
%    \begin{macrocode}
\AtBeginDocument{\@@_resolve_greek:}
\cs_new:Npn \@@_resolve_greek:
 {
  \clist_map_inline:nn
   {
    Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,
    alpha,beta,gamma,delta,epsilon,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,phi,chi,psi,omega,
    varTheta,varsigma,vartheta,varkappa,varrho,varpi,varepsilon,varphi
   }
   {
    \tl_set:cx {##1} { \exp_not:c { mit ##1 } }
    \tl_set:cx {up ##1} { \exp_not:N \symup \exp_not:c { ##1 } }
    \tl_set:cx {it ##1} { \exp_not:N \symit \exp_not:c { ##1 } }
   }
 }
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Unicode radicals}
%
% Make sure \cs{Uroot} is defined in the case where the \LaTeX{}
% kernel doesn't make it available with its native name.
%    \begin{macrocode}
%<*LU>
\cs_if_exist:NF \Uroot
  { \cs_new_eq:NN \Uroot \luatexUroot }
%</LU>
%    \end{macrocode}
%
%    \begin{macrocode}
\AtBeginDocument{\@@_redefine_radical:}
\cs_new:Nn \@@_redefine_radical:
%<*XE>
 {
  \@ifpackageloaded { amsmath } { }
   {
%    \end{macrocode}
% \begin{macro}{\r@@t}
% \darg{A mathstyle (for \cmd\mathpalette)}
% \darg{Leading superscript for the sqrt sign}
% A re-implementation of \LaTeX's hard-coded n-root sign using the appropriate \cmd\fontdimen s.
%    \begin{macrocode}
    \cs_set_nopar:Npn \r@@@@t ##1 ##2
     {
      \hbox_set:Nn \l_tmpa_box
       {
        \c_math_toggle_token
        \m@th
        ##1
        \sqrtsign { ##2 }
        \c_math_toggle_token
       }
      \@@_mathstyle_scale:Nnn ##1 { \kern }
       { \fontdimen 63 \l_@@_font }
      \box_move_up:nn
       {
        (\box_ht:N \l_tmpa_box - \box_dp:N \l_tmpa_box)
        * \number \fontdimen 65 \l_@@_font / 100
       }
       { \box_use:N \rootbox }
      \@@_mathstyle_scale:Nnn ##1 { \kern }
       { \fontdimen 64 \l_@@_font }
      \box_use_clear:N \l_tmpa_box
     }
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
   }
 }
%</XE>
%<*LU>
 {
  \@ifpackageloaded { amsmath } { }
   {
%    \end{macrocode}
% \begin{macro}{\root}
% Redefine this macro for \LuaTeX, which provides us a nice primitive to use.
%    \begin{macrocode}
    \cs_set:Npn \root ##1 \of ##2
     {
       \Uroot \l_@@_radical_sqrt_tl { ##1 } { ##2 }
     }
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
   }
 }
%</LU>
%    \end{macrocode}
%
% \subsubsection{Active fractions}
% Active fractions can be setup independently of any maths font definition;
% all it requires is a mapping from the Unicode input chars to the relevant
% \LaTeX\ fraction declaration.
%
%    \begin{macrocode}
\cs_new:Npn \@@_define_active_frac:Nw #1 #2/#3
 {
  \char_set_catcode_active:N #1
  \@@_char_gmake_mathactive:N #1
  \tl_rescan:nn
   {
    \catcode`\_=11\relax
    \catcode`\:=11\relax
   }
   {
    \cs_gset:Npx #1
     {
      \bool_if:NTF \l_@@_smallfrac_bool {\exp_not:N\tfrac} {\exp_not:N\frac}
          {#2} {#3}
     }
   }
 }
%    \end{macrocode}
% These are redefined for each math font selection in case the |active-frac|
% feature changes.
%    \begin{macrocode}
\cs_new:Npn \@@_setup_active_frac:
 {
  \group_begin:
  \@@_define_active_frac:Nw  ^^^^2189  0/3
  \@@_define_active_frac:Nw  ^^^^2152  1/{10}
  \@@_define_active_frac:Nw  ^^^^2151  1/9
  \@@_define_active_frac:Nw  ^^^^215b  1/8
  \@@_define_active_frac:Nw  ^^^^2150  1/7
  \@@_define_active_frac:Nw  ^^^^2159  1/6
  \@@_define_active_frac:Nw  ^^^^2155  1/5
  \@@_define_active_frac:Nw  ^^^^00bc  1/4
  \@@_define_active_frac:Nw  ^^^^2153  1/3
  \@@_define_active_frac:Nw  ^^^^215c  3/8
  \@@_define_active_frac:Nw  ^^^^2156  2/5
  \@@_define_active_frac:Nw  ^^^^00bd  1/2
  \@@_define_active_frac:Nw  ^^^^2157  3/5
  \@@_define_active_frac:Nw  ^^^^215d  5/8
  \@@_define_active_frac:Nw  ^^^^2154  2/3
  \@@_define_active_frac:Nw  ^^^^00be  3/4
  \@@_define_active_frac:Nw  ^^^^2158  4/5
  \@@_define_active_frac:Nw  ^^^^215a  5/6
  \@@_define_active_frac:Nw  ^^^^215e  7/8
  \group_end:
 }
\@@_setup_active_frac:
%    \end{macrocode}
%
% \subsection{Synonyms and all the rest}
%
% These are symbols with multiple names. Eventually to be taken care of
% automatically by the maths characters database.
%    \begin{macrocode}
\protected\def\to{\rightarrow}
\protected\def\le{\leq}
\protected\def\ge{\geq}
\protected\def\neq{\ne}
\protected\def\triangle{\mathord{\bigtriangleup}}
\protected\def\bigcirc{\mdlgwhtcircle}
\protected\def\circ{\vysmwhtcircle}
\protected\def\bullet{\smblkcircle}
\protected\def\mathyen{\yen}
\protected\def\mathsterling{\sterling}
\protected\def\diamond{\smwhtdiamond}
\protected\def\emptyset{\varnothing}
\protected\def\hbar{\hslash}
\protected\def\land{\wedge}
\protected\def\lor{\vee}
\protected\def\owns{\ni}
\protected\def\gets{\leftarrow}
\protected\def\mathring{\ocirc}
\protected\def\lnot{\neg}
\protected\def\longdivision{\longdivisionsign}
%    \end{macrocode}
% These are somewhat odd: (and their usual Unicode uprightness does not match their amssymb glyphs)
%    \begin{macrocode}
\protected\def\backepsilon{\upbackepsilon}
\protected\def\eth{\matheth}
%    \end{macrocode}
% These are names that are `frozen' in HTML but have dumb names:
%    \begin{macrocode}
\protected\def\dbkarow {\dbkarrow}
\protected\def\drbkarow{\drbkarrow}
\protected\def\hksearow{\hksearrow}
\protected\def\hkswarow{\hkswarrow}
%    \end{macrocode}
%
% Due to the magic of OpenType math, big operators are automatically
% enlarged when necessary. Since there isn't a separate unicode glyph for
% `small integral', I'm not sure if there is a better way to do this:
%    \begin{macrocode}
\protected\def\smallint{\mathop{\textstyle\int}\limits}
%    \end{macrocode}
%
% \begin{macro}{\underbar}
%    \begin{macrocode}
\cs_set_eq:NN \latexe_underbar:n \underbar
\renewcommand\underbar
 {
  \mode_if_math:TF \mathunderbar \latexe_underbar:n
 }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\colon}
% Define \cs{colon} as a mathpunct `|:|'.
% This is wrong: it should be \unichar{003A} {colon} instead!
% We hope no-one will notice.
%    \begin{macrocode}
\@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_@@_literal_colon_bool {:} { \mathpunct{:} }
   }
 }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\digamma}
% \begin{macro}{\Digamma}
% I might end up just changing these in the table.
%    \begin{macrocode}
\protected\def\digamma{\updigamma}
\protected\def\Digamma{\upDigamma}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \paragraph{Symbols}
%    \begin{macrocode}
\cs_set_protected:Npn \| {\Vert}
%    \end{macrocode}
% \cs{mathinner} items:
%    \begin{macrocode}
\cs_set_protected:Npn \mathellipsis {\mathinner{\unicodeellipsis}}
\cs_set_protected:Npn \cdots {\mathinner{\unicodecdots}}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set_eq:NN \@@_text_slash: \slash
\cs_set_protected:Npn \slash
 {
  \mode_if_math:TF {\mathslash} {\@@_text_slash:}
 }
%    \end{macrocode}
%
% \subsubsection{\cs{not}}
% \label{sec:negations}
%
% The situation of \cs{not} symbol is currently messy, in Unicode it is defined
% as a combining mark so naturally it should be treated as a math accent,
% however neither Lua\TeX\ nor \XeTeX\ correctly place it as it needs special
% treatment compared to other accents, furthermore a math accent changes the
% spacing of its nucleus, so \cs{not=} will be spaced as an ordinary not
% relational symbol, which is undesired.
%
% Here modify \cs{not} to a macro that tries to use predefined negated symbols,
% which would give better results in most cases, until there is more robust
% solution in the engines.
%
% This code is based on an answer to a TeX -- Stack Exchange question by Enrico
% Gregorio\footnote{\url{http://tex.stackexchange.com/a/47260/729}}.
%
%    \begin{macrocode}
\cs_new:Npn \@@_newnot:N #1
 {
   \tl_set:Nx \l_not_token_name_tl { \token_to_str:N #1 }
   \exp_args:Nx \tl_if_empty:nF { \tl_tail:V \l_not_token_name_tl }
    {
     \tl_set:Nx \l_not_token_name_tl { \tl_tail:V \l_not_token_name_tl }
    }
   \cs_if_exist:cTF { n \l_not_token_name_tl }
    {
     \use:c { n \l_not_token_name_tl }
    }
    {
     \cs_if_exist:cTF { not \l_not_token_name_tl }
      {
       \use:c { not \l_not_token_name_tl }
      }
      {
       \@@_oldnot: #1
      }
    }
 }
%    \end{macrocode}
%    \begin{macrocode}
\cs_set_eq:NN \@@_oldnot: \not
\AtBeginDocument{\cs_set_eq:NN \not \@@_newnot:N}
%    \end{macrocode}
%    \begin{macrocode}
\cs_new_protected_nopar:Nn \@@_setup_negations:
 {
  \cs_gset:cpn { not= }    { \neq }
  \cs_gset:cpn { not< }    { \nless }
  \cs_gset:cpn { not> }    { \ngtr }
  \cs_gset:Npn  \ngets     { \nleftarrow }
  \cs_gset:Npn  \nsimeq    { \nsime }
  \cs_gset:Npn  \nequal    { \ne }
  \cs_gset:Npn  \nle       { \nleq }
  \cs_gset:Npn  \nge       { \ngeq }
  \cs_gset:Npn  \ngreater  { \ngtr }
  \cs_gset:Npn  \nforksnot { \forks }
 }
%    \end{macrocode}
%
%
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}

\endinput

% /©
%
% ------------------------------------------------
% The UNICODE-MATH package  <wspr.io/unicode-math>
% ------------------------------------------------
% 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/>.
% ------------------------------------------------
% Copyright 2006-2017  Will Robertson, LPPL "maintainer"
% Copyright 2010-2017  Philipp Stephani
% Copyright 2011-2017  Joseph Wright
% Copyright 2012-2015  Khaled Hosny
% ------------------------------------------------
%
% ©/
