\NeedsTeXFormat{LaTeX2e}[2019/01/01]
\def\fileversion{0.31}
\def\filedate{2020/06/20}
\ProvidesPackage{kpfonts-otf}[\filedate\space\fileversion]

% Ensure luatex or xetex engine
\RequirePackage{iftex}[2019/10/24]
\RequireTUTeX
%
\newif\ifkp@math	\kp@mathtrue
\newif\ifkp@text  	\kp@texttrue
\newif\ifkp@sf      \kp@sftrue
\newif\ifkp@tt      \kp@tttrue
%
\newif\ifkp@lighttext
\newif\ifkp@largesmallcaps
\newif\ifkp@osn
\newif\ifkp@os
\newif\ifkp@vos
\newif\ifkp@Qtail
%
\newif\ifkp@lightmath
\newif\ifkp@osnm
\newif\ifkp@narrowiints
\newif\ifkp@partialup
\newif\ifkp@Dcommand    \kp@Dcommandtrue
\newif\ifkp@sfmathbb
\newif\ifkp@frenchstyle
\newif\ifkp@calasscr
\newif\ifkp@oldReIm
\newif\ifkp@symbols     \kp@symbolstrue
%
% Global options
\DeclareOption{light}             {\kp@lighttexttrue\kp@lightmathtrue}
\DeclareOption{nomath}            {\kp@mathfalse\kp@symbolsfalse}
\DeclareOption{notext}            {\kp@textfalse}
\DeclareOption{nosf}              {\kp@sffalse}
\DeclareOption{nott}              {\kp@ttfalse}
\DeclareOption{onlyrm}            {\kp@ttfalse\kp@sffalse}
% Text options
\DeclareOption{lighttext}         {\kp@lighttexttrue}
\DeclareOption{oldstylenums}      {\kp@osntrue}
\DeclareOption{oldstyle}          {\kp@ostrue\kp@Qtailtrue}
\DeclareOption{veryoldstyle}      {\kp@vostrue\kp@Qtailtrue}
\DeclareOption{largesmallcaps}    {\kp@largesmallcapstrue}
% Math options
\DeclareOption{lightmath}         {\kp@lightmathtrue}
\DeclareOption{bbsans}            {\kp@sfmathbbtrue}
\DeclareOption{mathcal}           {\kp@calasscrtrue}
\DeclareOption{narrowiints}       {\kp@narrowiintstrue}
\DeclareOption{frenchstyle}       {\kp@frenchstyletrue}
\DeclareOption{partialup}         {\kp@partialuptrue}
\DeclareOption{oldstylenumsmath}  {\kp@osnmtrue}
\DeclareOption{fancyReIm}         {\kp@oldReImtrue}
\DeclareOption{noDcommand}        {\kp@Dcommandfalse}
\DeclareOption{symbols}           {\kp@textfalse\kp@sffalse\kp@ttfalse
                                   \kp@mathfalse}
\ProcessOptions

\ifkp@symbols  % true unless "nomath"
  \RequirePackage{unicode-math}[2019/01/01]
  % \D close integral
  \ifkp@Dcommand
    \newcommand*{\D}[1]{\mathclose{\,\symup{d}}#1}%
  \fi
\fi
% Loading Math fonts...
\ifkp@math
  \ifkp@lightmath
    \ifkp@calasscr
      \defaultfontfeatures+[KpMath-Light.otf]{RawFeature=+ss01}
    \fi
    \ifkp@sfmathbb
      \defaultfontfeatures+[KpMath-Light.otf]{RawFeature=+ss02}
    \fi
    \ifkp@narrowiints
      \defaultfontfeatures+[KpMath-Light.otf]{RawFeature=+ss03}
    \fi
    \ifkp@frenchstyle
      \defaultfontfeatures+[KpMath-Light.otf]{math-style=french}
    \fi
    \ifkp@osnm
      \defaultfontfeatures+[KpMath-Light.otf]{Numbers=Lowercase}
    \fi
    \ifkp@oldReIm
      \defaultfontfeatures+[KpMath-Light.otf]{RawFeature=+cv03}
    \fi
    \ifkp@partialup
      \defaultfontfeatures+[KpMath-Light.otf]{partial=upright}
    \fi
    \setmathfont{KpMath-Light.otf}
  \else
    \ifkp@calasscr
      \defaultfontfeatures+[KpMath-Regular.otf]{RawFeature=+ss01}
    \fi
    \ifkp@sfmathbb
      \defaultfontfeatures+[KpMath-Regular.otf]{RawFeature=+ss02}
    \fi
    \ifkp@narrowiints
      \defaultfontfeatures+[KpMath-Regular.otf]{RawFeature=+ss03}
    \fi
    \ifkp@frenchstyle
      \defaultfontfeatures+[KpMath-Regular.otf]{math-style=french}
    \fi
    \ifkp@osnm
      \defaultfontfeatures+[KpMath-Regular.otf]{Numbers=Lowercase}
    \fi
    \ifkp@oldReIm
      \defaultfontfeatures+[KpMath-Regular.otf]{RawFeature=+cv03}
    \fi
    \ifkp@partialup
      \defaultfontfeatures+[KpMath-Regular.otf]{partial=upright}
    \fi
    \setmathfont{KpMath-Regular.otf}
  \fi
\fi

% Loading Text fonts...
\ifkp@text
  \RequirePackage{fontspec}[2019/01/01]
  \defaultfontfeatures+[\rmfamily,\KpLight]{Contextuals={WordFinal,Alternate}}
  %Oldstylenums
  \ifkp@osn
    \ifkp@sf
      \ifkp@tt
        \defaultfontfeatures+[\rmfamily,\KpLight,\sffamily,\ttfamily]%
                             {Numbers=Lowercase}
      \else
        \defaultfontfeatures+[\rmfamily,\KpLight,\sffamily]{Numbers=Lowercase}
      \fi
    \else
        \defaultfontfeatures+[\rmfamily,\KpLight]{Numbers=Lowercase}
    \fi
  \fi
  % Oldstyle
  \ifkp@os
    \ifkp@sf
      \defaultfontfeatures+[\rmfamily,\KpLight,\sffamily]{%
              Style=Swash,Ligatures={TeX,Rare},Numbers=Lowercase}
    \else
      \defaultfontfeatures+[\rmfamily,\KpLight]{%
              Style=Swash,Ligatures={TeX,Rare},Numbers=Lowercase}
    \fi
    \ifkp@tt\defaultfontfeatures+[\ttfamily]{Numbers=Lowercase}\fi
  \fi
  % Veryoldstyle
  \ifkp@vos
    \ifkp@sf
      \defaultfontfeatures+[\rmfamily,\KpLight,\sffamily]{%
              Style=Historic, Ligatures={TeX,Historic}}
    \else
      \defaultfontfeatures+[\rmfamily,\KpLight]{%
              Style=Historic, Ligatures={TeX,Historic}}
    \fi
  \fi
  \ifkp@largesmallcaps
    \defaultfontfeatures+{SmallCapsFeatures = {Letters=SmallCaps}}
  \else
    \defaultfontfeatures+{SmallCapsFeatures = {Letters=PetiteCaps}}
  \fi
  % Text Serif fonts:
  \setmainfont{KpRoman}[
      Extension = .otf,
      UprightFont =    *-Regular,
      BoldFont =       *-Bold,
      ItalicFont =     *-Italic,
      BoldItalicFont = *-BoldItalic
  ]
  \newfontfamily\KpLight{KpRoman-Light}[
      Extension = .otf,
      BoldFont =       KpRoman-Semibold,
      ItalicFont =     KpRoman-LightItalic,
      BoldItalicFont = KpRoman-SemiboldItalic,
      Ligatures=TeX
  ]
  \newfontface\Light{KpRoman-Light.otf}[Ligatures=TeX]
  \newfontface\LightItalic {KpRoman-LightItalic.otf}[Ligatures=TeX]
  \newfontface\Semibold{KpRoman-Semibold.otf}[Ligatures=TeX]
  \newfontface\SemiboldItalic{KpRoman-SemiboldItalic.otf}[Ligatures=TeX]
\fi
% Text Sans Serif fonts:
\ifkp@sf
  \defaultfontfeatures+[\sffamily]{Contextuals={WordFinal,Alternate}}
  \setsansfont{KpSans}[
    Extension = .otf,
    UprightFont =    *-Regular,
    BoldFont =       *-Bold,
    ItalicFont =     *-Italic,
    BoldItalicFont = *-BoldItalic
  ]
\fi
% Text Typewriter fonts:
\ifkp@tt
  \defaultfontfeatures+[\ttfamily]{Contextuals={WordFinal,Alternate}}
  \setmonofont{KpMono}[
    Extension = .otf,
    UprightFont =    *-Regular,
    BoldFont =       *-Bold,
    ItalicFont =     *-Italic,
    BoldItalicFont = *-BoldItalic
  ]
\fi
% Light option
\ifkp@lighttext
  \renewcommand{\rmfamily}{\KpLight}
\fi

% Large/Petites smallcaps
\DeclareRobustCommand\lscshape{\addfontfeatures{RawFeature=+smcp}}
\DeclareRobustCommand\pscshape{\addfontfeatures{RawFeature=+pcap}}
\DeclareRobustCommand\textlsc[1]{{\lscshape #1}}
\DeclareRobustCommand\textpsc[1]{{\pscshape #1}}

\ifkp@symbols
  % Style aliases
  \newopentypefeature{Style}{mathcal}{ss01}
  \newopentypefeature{Style}{bbsans}{ss02}
  \newopentypefeature{Style}{narrowiints}{ss03}
  \newopentypefeature{Style}{leqslant}{ss04}
  \newopentypefeature{Style}{smaller}{ss05}
  \newopentypefeature{Style}{subsetneq}{ss06}
  \newopentypefeature{Style}{parallelslant}{ss07}
  \AtBeginDocument{%
    % Kpfonts specific math symbols
    \Umathchardef\msanspartial =         0 0 "E000 \relax
    \Umathchardef\mitsanspartial =       0 0 "E010 \relax
    \Umathchardef\mitsanswp =            0 0 "E015 \relax
    \Umathchardef\mitsansell =           0 0 "E019 \relax
    \Umathchardef\varemptyset =          0 0 "E021 \relax
    \Umathchardef\lambdaslash =          0 0 "E029 \relax
    \Umathchardef\lambdabar =            0 0 "E02A \relax
    \Umathchardef\mbfvec =               0 0 "E044 \relax
    \Umathchardef\mbfwp =                0 0 "E045 \relax
    \Umathchardef\mbfimath =             0 0 "E046 \relax
    \Umathchardef\mbfjmath =             0 0 "E047 \relax
    \Umathchardef\mbfell =               0 0 "E049 \relax
    \Umathchardef\mbhbar =               0 0 "E068 \relax
    \Umathchardef\mbhslash =             0 0 "E06F \relax
    \Umathchardef\mithbar =              0 0 "E078 \relax
    \Umathchardef\parallelbackslant =    3 0 "E080 \relax
    \Umathchardef\nparallelbackslant =   3 0 "E081 \relax
    \Umathchardef\parallelslant  =       3 0 "E090 \relax
    \Umathchardef\nparallelslant =       3 0 "E091 \relax
    \Umathchardef\nsubseteqq =           3 0 "E0AE \relax
    \Umathchardef\nsupseteqq =           3 0 "E0AF \relax
    \Umathchardef\@idotsint =            1 0 "E111 \relax
    \Umathchardef\Mmapsfrom =            0 0 "E400 \relax
    \Umathchardef\Mmapsto =              0 0 "E401 \relax
    \Umathchardef\mmapsfrom =            0 0 "E402 \relax
    \Umathchardef\mmapsto =              0 0 "E403 \relax
    \Umathchardef\Longmmapsfrom =        0 0 "E404 \relax
    \Umathchardef\Longmmapsto =          0 0 "E405 \relax
    \Umathchardef\longmmapsfrom =        0 0 "E406 \relax
    \Umathchardef\longmmapsto =          0 0 "E407 \relax
    \Umathchardef\leftrightdasharrow =   0 0 "E408 \relax
    \Umathchardef\leadsto =              0 0 "E409 \relax
    \Umathchardef\leadstoext =           0 0 "E40A \relax
    \Umathchardef\longleadsto =          0 0 "E40B \relax
    \Umathchardef\colonapprox =          0 0 "E410 \relax
    \Umathchardef\colonsim =             0 0 "E411 \relax
    \Umathchardef\Colonapprox =          0 0 "E412 \relax
    \Umathchardef\Colonsim =             0 0 "E413 \relax
    \Umathchardef\colondash =            0 0 "E414 \relax
    \Umathchardef\eqqColon =             0 0 "E415 \relax
    \Umathchardef\Colondash =            0 0 "E416 \relax
    \Umathchardef\dashColon =            0 0 "E417 \relax
    \Umathchardef\strictif =             0 0 "E418 \relax
    \Umathchardef\strictfi =             0 0 "E419 \relax
    \Umathchardef\strictiff =            0 0 "E41A \relax
    \Umathchardef\circledwedge =         0 0 "E41B \relax
    \Umathchardef\circledvee =           0 0 "E41C \relax
    \Umathchardef\circledbar =           0 0 "E41D \relax
    \Umathchardef\multimapdot =          0 0 "E420 \relax
    \Umathchardef\multimapdotinv =       0 0 "E421 \relax
    \Umathchardef\multimapdotboth =      0 0 "E422 \relax
    \Umathchardef\multimapbothvert =     0 0 "E423 \relax
    \Umathchardef\multimapdotbothvert =  0 0 "E424 \relax
    \Umathchardef\multimapdotbothAvert = 0 0 "E425 \relax
    \Umathchardef\multimapdotbothBvert = 0 0 "E426 \relax
    \Umathchardef\Wr =                   0 0 "E427 \relax
    \Umathchardef\boxbar =               0 0 "E428 \relax
    \Umathchardef\opentimes =            0 0 "E429 \relax
    \Umathchardef\openJoin =             0 0 "E42A \relax
    \Umathchardef\VvDash =               0 0 "E42B \relax
    \Umathchardef\Diamondright =         0 0 "E430 \relax
    \Umathchardef\Diamondleft =          0 0 "E431 \relax
    \Umathchardef\Diamonddotright =      0 0 "E432 \relax
    \Umathchardef\Diamonddotleft =       0 0 "E433 \relax
    \Umathchardef\boxright =             0 0 "E434 \relax
    \Umathchardef\boxleft =              0 0 "E435 \relax
    \Umathchardef\boxdotright =          0 0 "E436 \relax
    \Umathchardef\boxdotleft =           0 0 "E437 \relax
    \Umathchardef\DiamondRight =         0 0 "E438 \relax
    \Umathchardef\DiamondLeft =          0 0 "E439 \relax
    \Umathchardef\DiamonddotRight =      0 0 "E43A \relax
    \Umathchardef\DiamonddotLeft =       0 0 "E43B \relax
    \Umathchardef\boxRight  =            0 0 "E43C \relax
    \Umathchardef\boxLeft =              0 0 "E43D \relax
    \Umathchardef\boxdotRight =          0 0 "E43E \relax
    \Umathchardef\boxdotLeft =           0 0 "E43F \relax
    \Umathchardef\circleright =          0 0 "E440 \relax
    \Umathchardef\circleleft =           0 0 "E441 \relax
    \Umathchardef\circledotright =       0 0 "E442 \relax
    \Umathchardef\circledotleft =        0 0 "E443 \relax
    \Umathchardef\capplus =              0 0 "E444 \relax
    \Umathchardef\bigcapplus =           0 0 "E445 \relax
    \Umathchardef\sqcapplus =            0 0 "E447 \relax
    \Umathchardef\bigsqcapplus =         0 0 "E448 \relax
    \Umathchardef\sqcupplus =            0 0 "E44A \relax
    \Umathchardef\bigsqcupplus =         0 0 "E44B \relax
    \Umathchardef\oint@cw =              1 0 "E44E \relax
    \Umathchardef\oiint@acw =            1 0 "E450 \relax
    \Umathchardef\varoiint@cw =          1 0 "E452 \relax
    \Umathchardef\oiiint@acw =           1 0 "E454 \relax
    \Umathchardef\varoiiint@cw =         1 0 "E456 \relax
    \Umathchardef\varoiint@acw =         1 0 "E458 \relax
    \Umathchardef\oiint@cw =             1 0 "E45A \relax
    \Umathchardef\varoiiint@acw =        1 0 "E45C \relax
    \Umathchardef\oiiint@cw =            1 0 "E45E \relax
    \Umathchardef\sq@iint =              1 0 "E460 \relax
    \Umathchardef\sq@iiint =             1 0 "E462 \relax
    \Umathchardef\var@int =              1 0 "E464 \relax
    \Umathchardef\var@iint =             1 0 "E466 \relax
    \Umathchardef\var@iiint =            1 0 "E468 \relax
    \Umathchardef\var@iiiint =           1 0 "E46A \relax
    \Umathchardef\var@idotsint =         1 0 "E46C \relax
    \Umathchardef\varoint@acw =          1 0 "E46E \relax
    \DeclareRobustCommand{\ointclockwise}{\oint@cw\nolimits}%
    \DeclareRobustCommand{\varointctrclockwise}{\varoint@acw\nolimits}%
    \DeclareRobustCommand{\oiintclockwise}{\oiint@cw\nolimits}%
    \DeclareRobustCommand{\oiintctrclockwise}{\oiint@acw\nolimits}%
    \DeclareRobustCommand{\varoiintclockwise}{\varoiint@cw\nolimits}%
    \DeclareRobustCommand{\varoiintctrclockwise}{\varoiint@acw\nolimits}%
    \DeclareRobustCommand{\oiiintclockwise}{\oiiint@cw\nolimits}%
    \DeclareRobustCommand{\oiiintctrclockwise}{\oiiint@acw\nolimits}%
    \DeclareRobustCommand{\varoiiintclockwise}{\varoiiint@cw\nolimits}%
    \DeclareRobustCommand{\varoiiintctrclockwise}{\varoiiint@acw\nolimits}%
    \DeclareRobustCommand{\idotsint}{\@idotsint\nolimits}%
    \DeclareRobustCommand{\sqiint}{\sq@iint\nolimits}%
    \DeclareRobustCommand{\sqiiint}{\sq@iiint\nolimits}%
    \DeclareRobustCommand{\varint}{\var@int\nolimits}%
    \DeclareRobustCommand{\variint}{\var@iint\nolimits}%
    \DeclareRobustCommand{\variiint}{\var@iiint\nolimits}%
    \DeclareRobustCommand{\variiiint}{\var@iiiint\nolimits}%
    \DeclareRobustCommand{\varidotsint}{\var@idotsint\nolimits}%
    \Umathchardef\IM =                   0 0 "E7FE \relax
    \Umathchardef\RE =                   0 0 "E7FF \relax
    %\widearc and\overrightarc
    \newcommand*{\widearc}{\Umathaccent  0 0 "E540 }%
    \newcommand*{\widearcarrow}{\Umathaccent 0 0 "20D5 }%
    \let\overrightarc\widearcarrow
    % amssymb
    \@ifpackageloaded{amssymb}%
      {\PackageWarning{kpfonts-otf}{%
         kpfonts-otf provides all AMS symbols.\MessageBreak
         Loading amssymb.sty is not advisable.\MessageBreak
         Reported}%
      }%
      {% AMS Symbols not referenced in unicode-math-table.tex
       % \Umathchardef\sum = <math type> <family> <slot>
       % <math type> : \mathord=0 \mathrel=3 ; <family>=0
       \Umathchardef\circledR =       0 0 "24C7 \relax
       \Umathchardef\circledS =       0 0 "24C8 \relax
       \Umathchardef\npreceq =        3 0 "E096 \relax
       \Umathchardef\nsucceq =        3 0 "E097 \relax
       \Umathchardef\diagup =         0 0 "E0A0 \relax
       \Umathchardef\diagdown =       0 0 "E0A1 \relax
       \Umathchardef\shortmid =       3 0 "E0A2 \relax
       \Umathchardef\shortparallel =  3 0 "E0A3 \relax
       \Umathchardef\nshortmid =      3 0 "E0A4 \relax
       \Umathchardef\nshortparallel = 3 0 "E0A5 \relax
       \Umathchardef\lvertneqq =      3 0 "E0A6 \relax
       \Umathchardef\gvertneqq =      3 0 "E0A7 \relax
       \Umathchardef\varsubsetneq =   3 0 "E0AC \relax
       \Umathchardef\varsupsetneq =   3 0 "E0AD \relax
       \Umathchardef\varsubsetneqq =  3 0 "E09C \relax
       \Umathchardef\varsupsetneqq =  3 0 "E09D \relax
       \Umathchardef\nleqslant =      3 0 "E0A8 \relax
       \Umathchardef\ngeqslant =      3 0 "E0A9 \relax
       \Umathchardef\nleqq =          3 0 "E0AA \relax
       \Umathchardef\ngeqq =          3 0 "E0AB \relax
       \Umathchardef\leadsto =        3 0 "E409 \relax
       \let\centerdot\cdotp                % vysmblksquare ?
       \let\restriction\upharpoonright
       \let\doteqdot\Doteq
       \let\doublecup\Cup
       \let\doublecap\Cap
       \let\llless\lll
       \let\gggtr\ggg
       \let\circlearrowleft\acwopencirclearrow
       \let\circlearrowright\cwopencirclearrow
       \let\lozenge\diamondsuit
       \let\blacklozenge\vardiamondsuit
       \let\square\mdlgwhtsquare
       \let\blacksquare\mdlgblksquare
       \let\dashleftarrow\leftdasharrow
       \let\dashrightarrow\rightdasharrow
       \let\ntriangleleft\nvartriangleleft
       \let\ntriangleright\nvartriangleright
       \let\varpropto\propto
       \let\thicksim\sim
       \let\thickapprox\approx
       \let\smallsmile\smile
       \let\smallfrown\frown
      }%
    % latexsym
    \@ifpackageloaded{latexsym}%
      {\PackageWarning{kpfonts-otf}{%
         kpfonts-otf provides all LaTeX symbols.\MessageBreak
         Loading latexsym.sty is not advisable.\MessageBreak
         Reported}%
      }%
      {\let\lhd\triangleleft
       \let\rhd\triangleright
       \let\unlhd\trianglelefteq
       \let\unrhd\trianglerighteq
       \let\Box\mdlgwhtsquare
       \let\Diamond\mdwhtdiamond
      }%
  }
\fi

\endinput
