%%
%% This is file `projlib-font.sty',
%% generated with the docstrip utility.
%%
%% Copyright (C) 2021-2024 by Jinwen XU
%% 
%% This is part of the ProjLib Toolkit.
%% 
%% This work may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License, either version 1.3c of this license or (at
%% your option) any later version. The latest version of this license is in
%% 
%%     http://www.latex-project.org/lppl.txt
%% 
%% and version 1.3c or later is part of all distributions of LaTeX version
%% 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[2022-06-01]
\ProvidesExplPackage
  {projlib-font}
  {2024/02/24} {}
  {Font selection and configuration}

\keys_define:nn { projlib-font }
  {
    , use-osf              .bool_set:N   = \l__projlib_font_useosf_bool
    , useosf              .initial:n    = { false }
    , use~osf              .bool_set:N   = \l__projlib_font_useosf_bool
    , use osf              .bool_set:N   = \l__projlib_font_useosf_bool
    , old-style-figures   .bool_set:N   = \l__projlib_font_useosf_bool
    , old~style~figures   .bool_set:N   = \l__projlib_font_useosf_bool
    , old-style~figures   .bool_set:N   = \l__projlib_font_useosf_bool
    , old style~figures   .bool_set:N   = \l__projlib_font_useosf_bool
    , old style figures   .bool_set:N   = \l__projlib_font_useosf_bool
    , old-style-figure    .bool_set:N   = \l__projlib_font_useosf_bool
    , old~style~figure    .bool_set:N   = \l__projlib_font_useosf_bool
    , old-style~figure    .bool_set:N   = \l__projlib_font_useosf_bool
    , old style~figure    .bool_set:N   = \l__projlib_font_useosf_bool
    , old style figure    .bool_set:N   = \l__projlib_font_useosf_bool
    , new-computer-modern .bool_set:N   = \l__projlib_font_newcomputermodern_bool
    , new-computer-modern .initial:n    = { false }
    , new~computer~modern .bool_set:N   = \l__projlib_font_newcomputermodern_bool
    , new computer modern .bool_set:N   = \l__projlib_font_newcomputermodern_bool
    , newcm               .bool_set:N   = \l__projlib_font_computermodern_bool
    , computer-modern     .bool_set:N   = \l__projlib_font_computermodern_bool
    , computer-modern     .initial:n    = { false }
    , computer~modern     .bool_set:N   = \l__projlib_font_computermodern_bool
    , computer modern     .bool_set:N   = \l__projlib_font_computermodern_bool
    , latin-modern        .initial:n    = { false }
    , latin-modern        .bool_set:N   = \l__projlib_font_latinmodern_bool
    , latin~modern        .bool_set:N   = \l__projlib_font_latinmodern_bool
    , latin modern        .bool_set:N   = \l__projlib_font_latinmodern_bool
    , lmodern             .bool_set:N   = \l__projlib_font_latinmodern_bool
    , palatino            .bool_set:N   = \l__projlib_font_palatino_bool
    , palatino            .initial:n    = { false }
    , times               .bool_set:N   = \l__projlib_font_times_bool
    , times               .initial:n    = { false }
    , garamond            .bool_set:N   = \l__projlib_font_garamond_bool
    , garamond            .initial:n    = { false }
    , bembo               .bool_set:N   = \l__projlib_font_bembo_bool
    , bembo               .initial:n    = { false }
    , biolinum            .bool_set:N   = \l__projlib_font_biolinum_bool
    , biolinum            .initial:n    = { false }
    , noto                .bool_set:N   = \l__projlib_font_noto_bool
    , noto                .initial:n    = { false }
    , use-font            .meta:n       = { #1 }
    , use~font            .meta:n       = { #1 }
    , use font            .meta:n       = { #1 }
    , unknown             .code:n       = {}
  }
\ProcessKeyOptions [ projlib-font ]

\bool_new:N \g_projlib_font_already_set_bool
\bool_gset_false:N \g_projlib_font_already_set_bool

\RequirePackage { anyfontsize }
\RequirePackage { setspaceenhanced }

\cs_new:Nn \projlib_font_set_linespacing_latin:n
  {
    \cs_if_exist:NTF \projlib_language_set_linespacing_latin:n
      {
        \projlib_language_set_linespacing_latin:n { #1 }
      }
      {
        #1
      }
  }

\bool_if:NT \l__projlib_font_newcomputermodern_bool
  {
    \RequirePackage [default] { fontsetup }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
    \bool_gset_true:N \g_projlib_font_already_set_bool
  }

\bool_if:NT \l__projlib_font_computermodern_bool
  {
    \RequirePackage [olddefault] { fontsetup }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
    \bool_gset_true:N \g_projlib_font_already_set_bool
  }

\bool_if:NT \l__projlib_font_latinmodern_bool
  {
    \RequirePackage { amssymb }
    \bool_if:NTF \l__projlib_font_useosf_bool
      {
        \RequirePackage { cfr-lm }
      }
      {
        \RequirePackage { lmodern }
      }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
    \bool_gset_true:N \g_projlib_font_already_set_bool
  }

\bool_if:NT \l__projlib_font_palatino_bool
  {
    \RequirePackage { mathpazo }
    \PassOptionsToPackage { defaultsups } { newpxtext }
    \PassOptionsToPackage { no-math } { fontspec }
    \hook_gput_code:nnn { begindocument/before } { projlib-font }
      {
        \bool_if:NT \l__projlib_font_useosf_bool
          {
            \PassOptionsToPackage { osf } { newpxtext }
          }
        \RequirePackage { newpxtext }
        \sys_if_engine_pdftex:F
          {
            \setsansfont { texgyreheros }
              [
                Scale          = MatchUppercase ,
                UprightFont    = *-regular ,
                BoldFont       = *-bold ,
                ItalicFont     = *-italic ,
                BoldItalicFont = *-bolditalic ,
              ]
          }
      }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.07 } }
    \bool_gset_true:N \g_projlib_font_already_set_bool
  }

\bool_if:NT \l__projlib_font_times_bool
  {
    \PassOptionsToPackage { no-math } { fontspec }
    \hook_gput_code:nnn { begindocument/before } { projlib-font }
      {
        \sys_if_engine_pdftex:TF
          {
            \bool_if:NT \l__projlib_font_useosf_bool
              {
                \PassOptionsToPackage { osf } { newtxtext }
              }
            \PassOptionsToPackage { defaultsups } { newtxtext }
            \RequirePackage { newtxtext }
            \RequirePackage { newtxmath }
          }
          {
            \RequirePackage { fontspec }
            \setmainfont { texgyretermes }
              [
                Scale          = MatchUppercase ,
                UprightFont    = *-regular ,
                BoldFont       = *-bold ,
                ItalicFont     = *-italic ,
                BoldItalicFont = *-bolditalic ,
              ]
            \setsansfont { texgyreheros }
              [
                Scale          = MatchUppercase ,
                UprightFont    = *-regular ,
                BoldFont       = *-bold ,
                ItalicFont     = *-italic ,
                BoldItalicFont = *-bolditalic ,
              ]
            \setmonofont { texgyrecursor }
              [
                Scale          = MatchUppercase ,
                UprightFont    = *-regular ,
                BoldFont       = *-bold ,
                ItalicFont     = *-italic ,
                BoldItalicFont = *-bolditalic ,
              ]
            \setmonofont{inconsolata}[Scale=MatchLowercase]
            \RequirePackage { unicode-math }
            \setmathfont { texgyretermes-math }
          }
      }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
    \bool_gset_true:N \g_projlib_font_already_set_bool
  }

\bool_if:NT \l__projlib_font_garamond_bool
  {
    \bool_if:NF \l__projlib_font_useosf_bool
      {
        \PassOptionsToPackage { lining } { ebgaramond }
      }
    \RequirePackage [ cmintegrals, cmbraces ] { newtxmath }
    \cs_undefine:c { openbox }
    \RequirePackage { ebgaramond-maths }
    \RequirePackage { ebgaramond }
    \cs_undefine:c { Bbbk }
    \cs_undefine:c { Top }
    % https://tex.stackexchange.com/a/215272
    \DeclareSymbolFont{ntxletters}{OML}{ntxmi}{m}{it}
    \SetSymbolFont{ntxletters}{bold}{OML}{ntxmi}{b}{it}
    \re@DeclareMathSymbol{\leftharpoonup}{\mathrel}{ntxletters}{"28}
    \re@DeclareMathSymbol{\leftharpoondown}{\mathrel}{ntxletters}{"29}
    \re@DeclareMathSymbol{\rightharpoonup}{\mathrel}{ntxletters}{"2A}
    \re@DeclareMathSymbol{\rightharpoondown}{\mathrel}{ntxletters}{"2B}
    \re@DeclareMathSymbol{\triangleleft}{\mathbin}{ntxletters}{"2F}
    \re@DeclareMathSymbol{\triangleright}{\mathbin}{ntxletters}{"2E}
    \re@DeclareMathSymbol{\partial}{\mathord}{ntxletters}{"40}
    \re@DeclareMathSymbol{\flat}{\mathord}{ntxletters}{"5B}
    \re@DeclareMathSymbol{\natural}{\mathord}{ntxletters}{"5C}
    \re@DeclareMathSymbol{\star}{\mathbin}{ntxletters}{"3F}
    \re@DeclareMathSymbol{\smile}{\mathrel}{ntxletters}{"5E}
    \re@DeclareMathSymbol{\frown}{\mathrel}{ntxletters}{"5F}
    \re@DeclareMathSymbol{\sharp}{\mathord}{ntxletters}{"5D}
    \re@DeclareMathAccent{\vec}{\mathord}{ntxletters}{"7E}
    \sys_if_engine_pdftex:F
      {
        \setsansfont { texgyreheros }
          [
            Scale          = MatchUppercase ,
            UprightFont    = *-regular ,
            BoldFont       = *-bold ,
            ItalicFont     = *-italic ,
            BoldItalicFont = *-bolditalic ,
          ]
      }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
    \bool_gset_true:N \g_projlib_font_already_set_bool
  }

\bool_if:NT \l__projlib_font_bembo_bool
  {
    \bool_if:NT \l__projlib_font_useosf_bool
      {
        \PassOptionsToPackage { osf } { fbb }
      }
    \sys_if_engine_pdftex:F
      {
        \RequirePackage { fontspec }
      }
    \RequirePackage [full] { textcomp } % to get the right copyright, etc.
    \RequirePackage [p] { fbb }
    \RequirePackage [scaled=.95,type1] { cabin } % sans serif in style of Gill Sans
    \RequirePackage [varqu,varl] { zi4 }% inconsolata typewriter
    \RequirePackage [T1] { fontenc }
    \RequirePackage [libertine] { newtxmath }
    \RequirePackage [cal=boondoxo,bb=boondox,frak=boondox] { mathalfa }
    \cs_undefine:c { openbox }
    \cs_undefine:c { Bbbk }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
    \bool_gset_true:N \g_projlib_font_already_set_bool
  }

\bool_if:NT \l__projlib_font_biolinum_bool
  {
    \RequirePackage [ OT1 ] { eulervm }
    \sys_if_engine_pdftex:TF
      {
        \bool_if:NT \l__projlib_font_useosf_bool
          {
            \PassOptionsToPackage { osf } { biolinum }
          }
          \RequirePackage { biolinum }
          \tl_gset:Nn \familydefault { \biolinum@family }
      }
      {
        \PassOptionsToPackage { no-math } { fontspec }
        \RequirePackage { fontspec }
        \bool_if:NTF \l__projlib_font_useosf_bool
          {
            \setmainfont { LinBiolinum_R.otf }
              [
                BoldFont       = LinBiolinum_RB.otf  ,
                ItalicFont     = LinBiolinum_RI.otf  ,
                BoldItalicFont = LinBiolinum_RBO.otf ,
                Numbers        = OldStyle            ,
              ]
          }
          {
            \setmainfont { LinBiolinum_R.otf }
              [
                BoldFont       = LinBiolinum_RB.otf  ,
                ItalicFont     = LinBiolinum_RI.otf  ,
                BoldItalicFont = LinBiolinum_RBO.otf ,
              ]
          }
      }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.05 } }
    \RequirePackage [ italic, defaultmathsizes ] { mathastext }
    \bool_gset_true:N \g_projlib_font_already_set_bool
  }

\bool_if:NT \l__projlib_font_noto_bool
  {
    \bool_if:NT \l__projlib_font_useosf_bool
      {
        \PassOptionsToPackage { oldstyle } { notomath }
      }
    \RequirePackage { anyfontsize }
    \RequirePackage { notomath }
    \cs_undefine:c { openbox }
    \cs_undefine:c { Bbbk }
    \projlib_font_set_linespacing_latin:n { \setstretch { 1.00 } }
    \bool_gset_true:N \g_projlib_font_already_set_bool
  }


\PassOptionsToPackage { verbose = silent } { microtype }
\RequirePackage { microtype }

\endinput
%%
%% End of file `projlib-font.sty'.
