%%
%% This is file `linguistix-nfss.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% linguistix.dtx  (with options: `nfss')
%% ---------------------------------------------------------
%% Bundle:       LinguisTiX
%% Version:      v0.5d
%% Author:       निरंजन
%% Description:  Enhanced support for linguistics.
%% Repository:   puszcza.gnu.org.ua/projects/linguistix
%% License:      GPLv3+, GFDLv1.3+
%% ---------------------------------------------------------
%% 
%% The LinguisTiX bundle v0.5d
%% Copyright © 2022, 2023, 2024, 2025 निरंजन
%% 
%% This program is free software: you can redistribute it
%% and/or modify it under the terms of the GNU General
%% Public License as published by the Free Software
%% Foundation, either version 3 of the License, or (at your
%% option) any later version.
%% 
%% This program is distributed in the hope that it will be
%% useful, but WITHOUT ANY WARRANTY; without even the
%% implied warranty of MERCHANTABILITY or FITNESS FOR A
%% PARTICULAR PURPOSE. See the GNU General Public License
%% for more details.
%% 
%% You should have received a copy of the GNU General Public
%% License along with this program. If not, see
%% <https://www.gnu.org/licenses/>.
%% 
%% ---------------------------------------------------------
\ProvidesExplPackage{linguistix-nfss}
                    {2025-07-11}
                    {v0.5d}
                    {%
                      An extension to the core NFSS commands
                      from the ‘LinguisTiX’ bundle.%
                    }

\tl_new:N \l__lngx_normalfont_tmp_tl
\tl_new:N \l__lngx_selectfont_tmp_tl
\tl_new:N \l__lngx_family_tmp_tl
\tl_new:N \l__lngx_nfss_tmp_tl

\tl_new:N \l_lngx_current_encoding_tl
\tl_new:N \l_lngx_current_meta_family_tl
\tl_new:N \l_lngx_current_super_family_tl
\tl_new:N \l_lngx_current_series_tl
\tl_new:N \l_lngx_current_shape_tl

\hook_gput_code:nnn { begindocument / end } { . } {
  \tl_const:Ne \c_lngx_default_rmdefault_tl { \rmdefault }
  \tl_const:Ne \c_lngx_default_sfdefault_tl { \sfdefault }
  \tl_const:Ne \c_lngx_default_ttdefault_tl { \ttdefault }
  \tl_set:Nn \l_lngx_current_super_family_tl { default }
  \tl_set:Ne \l_lngx_current_encoding_tl {
    \encodingdefault
  }
  \IfClassLoadedTF { beamer } {
    \tl_set:Ne \l_lngx_current_meta_family_tl { sf }
  } {
    \tl_set:Ne \l_lngx_current_meta_family_tl { rm }
  }
  \tl_set:Ne \l_lngx_current_series_tl { md }
  \tl_set:Ne \l_lngx_current_shape_tl { up }
}

\hook_gput_code:nnn { cmd / normalfont / before } { . } {
  \tl_set:Ne \l__lngx_normalfont_tmp_tl { \f@encoding }
}

\hook_gput_code:nnn { cmd / normalfont / after } { . } {
  \tl_set_eq:NN \l_lngx_current_encoding_tl
                \l__lngx_normalfont_tmp_tl
  \tl_clear:N   \l__lngx_normalfont_tmp_tl
}

\hook_gput_code:nnn { cmd / selectfont / before } { . } {
  \tl_set:Ne \l__lngx_selectfont_tmp_tl { \f@encoding }
}

\hook_gput_code:nnn { cmd / selectfont / after } { . } {
  \tl_set_eq:NN \l_lngx_current_encoding_tl
                \l__lngx_selectfont_tmp_tl
  \tl_clear:N   \l__lngx_selectfont_tmp_tl
}

\hook_gput_code:nnn { cmd / rmfamily / before } { . } {
  \tl_set:Nn \l_lngx_current_meta_family_tl { rm }
  \tl_set:Ne \l__lngx_family_tmp_tl { \f@encoding }
}

\hook_gput_code:nnn { cmd / rmfamily / after } { . } {
  \tl_set:Nn \l_lngx_current_meta_family_tl { rm }
  \tl_set_eq:NN \l_lngx_current_encoding_tl
                \l__lngx_family_tmp_tl
  \tl_clear:N   \l__lngx_family_tmp_tl
}

\hook_gput_code:nnn { cmd / sffamily / before } { . } {
  \tl_set:Nn \l_lngx_current_meta_family_tl { sf }
  \tl_set:Ne \l__lngx_family_tmp_tl { \f@encoding }
}

\hook_gput_code:nnn { cmd / sffamily / after } { . } {
  \tl_set:Nn \l_lngx_current_meta_family_tl { sf }
  \tl_set_eq:NN \l_lngx_current_encoding_tl
                \l__lngx_family_tmp_tl
  \tl_clear:N   \l__lngx_family_tmp_tl
}

\hook_gput_code:nnn { cmd / ttfamily / before } { . } {
  \tl_set:Nn \l_lngx_current_meta_family_tl { tt }
  \tl_set:Ne \l__lngx_family_tmp_tl { \f@encoding }
}

\hook_gput_code:nnn { cmd / ttfamily / after } { . } {
  \tl_set:Nn \l_lngx_current_meta_family_tl { tt }
  \tl_set_eq:NN \l_lngx_current_encoding_tl
                \l__lngx_family_tmp_tl
  \tl_clear:N   \l__lngx_family_tmp_tl
}

\hook_gput_code:nnn { cmd / mdseries / after } { . } {
  \tl_set:Nn \l_lngx_current_series_tl { md }
}

\hook_gput_code:nnn { cmd / bfseries / after } { . } {
  \tl_set:Nn \l_lngx_current_series_tl { bf }
}

\hook_gput_code:nnn { cmd / upshape / after } { . } {
  \tl_set:Nn \l_lngx_current_shape_tl { up }
}

\hook_gput_code:nnn { cmd / itshape / after } { . } {
  \tl_set:Nn \l_lngx_current_shape_tl { it }
}

\hook_gput_code:nnn { cmd / scshape / after } { . } {
  \tl_set:Nn \l_lngx_current_shape_tl { sc }
}

\hook_gput_code:nnn { cmd / sscshape / after } { . } {
  \tl_set:Nn \l_lngx_current_shape_tl { ssc }
}

\hook_gput_code:nnn { cmd / slshape / after } { . } {
  \tl_set:Nn \l_lngx_current_shape_tl { sl }
}

\hook_gput_code:nnn { cmd / swshape / after } { . } {
  \tl_set:Nn \l_lngx_current_shape_tl { sw }
}

\hook_gput_code:nnn { cmd / ulcshape / after } { . } {
  \tl_set:Nn \l_lngx_current_shape_tl { ulc }
}

\hook_gput_code:nnn { cmd / ulcshape / after } { . } {
  \tl_set:Nn \l_lngx_current_shape_tl { #1 }
}

\prg_new_conditional:Nnn \lngx_if_encoding:n {
  p,
  T,
  F,
  TF
} {
  \tl_if_eq:NnTF \l_lngx_current_encoding_tl { #1 } {
    \prg_return_true:
  } {
    \prg_return_false:
  }
}


\cs_new_eq:NN \IfEncodingTF \lngx_if_encoding:nTF
\cs_new_eq:NN \IfEncodingT  \lngx_if_encoding:nT
\cs_new_eq:NN \IfEncodingF  \lngx_if_encoding:nF

\prg_new_conditional:Nnn \lngx_if_meta_family:n {
  p,
  T,
  F,
  TF
} {
  \tl_if_eq:NnTF \l_lngx_current_meta_family_tl { #1 } {
    \prg_return_true:
  } {
    \prg_return_false:
  }
}

\cs_new_eq:NN \IfMetaFamilyTF \lngx_if_meta_family:nTF
\cs_new_eq:NN \IfMetaFamilyT  \lngx_if_meta_family:nT
\cs_new_eq:NN \IfMetaFamilyF  \lngx_if_meta_family:nF

\prg_new_conditional:Nnn \lngx_if_super_family:n {
  p,
  T,
  F,
  TF
} {
  \tl_if_eq:NnTF \l_lngx_current_super_family_tl { #1 } {
    \prg_return_true:
  } {
    \prg_return_false:
  }
}

\cs_new_eq:NN \IfSuperFamilyTF \lngx_if_super_family:nTF
\cs_new_eq:NN \IfSuperFamilyT  \lngx_if_super_family:nT
\cs_new_eq:NN \IfSuperFamilyF  \lngx_if_super_family:nF

\prg_new_conditional:Nnn \lngx_if_series:n {
  p,
  T,
  F,
  TF
} {
  \tl_if_eq:NnTF \l_lngx_current_series_tl { #1 } {
    \prg_return_true:
  } {
    \prg_return_false:
  }
}

\cs_new_eq:NN \IfSeriesTF \lngx_if_series:nTF
\cs_new_eq:NN \IfSeriesT  \lngx_if_series:nT
\cs_new_eq:NN \IfSeriesF  \lngx_if_series:nF

\prg_new_conditional:Nnn \lngx_if_shape:n {
  p,
  T,
  F,
  TF
} {
  \tl_if_eq:NnTF \l_lngx_current_shape_tl { #1 } {
    \prg_return_true:
  } {
    \prg_return_false:
  }
}

\cs_new_eq:NN \IfShapeTF \lngx_if_shape:nTF
\cs_new_eq:NN \IfShapeT  \lngx_if_shape:nT
\cs_new_eq:NN \IfShapeF  \lngx_if_shape:nF

\cs_generate_variant:Nn \prg_new_conditional:Nnn { cnn }

\clist_map_inline:nn {
  rm,
  sf,
  tt
} {
  \prg_new_conditional:cnn {
    lngx _ if _ meta _ family _ #1 :
  } {
    p, T, F, TF
  } {
    \tl_if_eq:NnTF \l_lngx_current_meta_family_tl { #1 } {
      \prg_return_true:
    } {
      \prg_return_false:
    }
  }
}

\clist_map_inline:nn {
  md,
  bf
} {
  \prg_new_conditional:cnn { lngx _ if _ series _ #1 : } {
    p, T, F, TF
  } {
    \tl_if_eq:NnTF \l_lngx_current_series_tl { #1 } {
      \prg_return_true:
    } {
      \prg_return_false:
    }
  }
}

\clist_map_inline:nn {
  up,
  it,
  sc,
  ssc,
  sl,
  sw,
  ulc
} {
  \prg_new_conditional:cnn { lngx _ if _ shape _ #1 : } {
    p, T, F, TF
  } {
    \tl_if_eq:NnTF \l_lngx_current_shape_tl { #1 } {
      \prg_return_true:
    } {
      \prg_return_false:
    }
  }
}

\clist_map_inline:nn {
  rm,
  sf,
  tt
} {
  \keys_define:nn { lngx _ nfss } {
    #1
    .code:n                = {
      \tl_gclear_new:c {
        g _ lngx _ \l__lngx_nfss_tmp_tl _ #1 default _ tl
      }
      \tl_gset:cn {
        g _ lngx _ \l__lngx_nfss_tmp_tl _ #1 default _ tl
      } { ##1 }
    }
  }
}

\cs_new_protected:Npn \lngx_super_font_family:nn #1#2 {
  \tl_set:Ne \l__lngx_nfss_tmp_tl { #1 }
  \keys_set:nn { lngx _ nfss } { #2 }
  \tl_clear:N \l__lngx_nfss_tmp_tl
}

\cs_set_eq:NN \superfontfamily
              \lngx_super_font_family:nn

\cs_new_protected:Npn \lngx_soft_super_font_family:nn #1#2 {
  \tl_set:Ne \l_lngx_current_super_family_tl { #1 }
  \clist_map_inline:nn {
    rm,
    sf,
    tt
  } {
    \tl_if_empty:cF { g _ lngx _ #1 _ ##1 default _ tl } {
      \cs_set:cpe { ##1 default } {
        \tl_use:c { g _ lngx _ #1 _ ##1 default _ tl }
      }
    }
  }
  \normalfont
  \clist_map_inline:nn { #2 } {
    \str_case:nn { ##1 } {
      { encoding } {
        \exp_args:NV \fontencoding
                     \l_lngx_current_encoding_tl
      }
      { family } {
        \use:c {
          \l_lngx_current_meta_family_tl family
        }
        \exp_args:NV \fontencoding
                     \l_lngx_current_encoding_tl
        \selectfont
      }
      { series } {
        \use:c {
          \l_lngx_current_series_tl series
        }
      }
      { shape }  {
        \use:c {
          \l_lngx_current_shape_tl shape
        }
      }
    }
  }
}

\cs_set_eq:NN \softsuperfontfamily
              \lngx_soft_super_font_family:nn

\cs_new_protected:Npn \lngx_softer_super_font_family:n #1 {
  \lngx_soft_super_font_family:nn { #1 } {
    family,
    series,
    shape
  }
}

\cs_set_eq:NN \softersuperfontfamily
              \lngx_softer_super_font_family:n

\cs_new_protected:Npn \lngx_softest_super_font_family:n #1 {
  \lngx_soft_super_font_family:nn { #1 } {
    encoding,
    family,
    series,
    shape
  }
}

\cs_set_eq:NN \softestsuperfontfamily
              \lngx_softest_super_font_family:n

\cs_new_protected:Npn \lngx_soft_normal_font:n #1 {
  \tl_set:Ne \l_lngx_current_super_family_tl { default }
  \clist_map_inline:nn {
    rm,
    sf,
    tt
  } {
    \cs_set:cpe { ##1 default } {
      \tl_use:c { c _ lngx _ default _ ##1 default _ tl }
    }
  }
  \normalfont
  \clist_map_inline:nn { #1 } {
    \str_case:nn { ##1 } {
      { encoding } {
        \exp_args:NV \fontencoding
                     \l_lngx_current_encoding_tl
      }
      { family } {
        \use:c {
          \l_lngx_current_meta_family_tl family
        }
        \exp_args:NV \fontencoding
                     \l_lngx_current_encoding_tl
        \selectfont
      }
      { series } {
        \use:c {
          \l_lngx_current_series_tl series
        }
      }
      { shape }  {
        \use:c {
          \l_lngx_current_shape_tl shape
        }
      }
    }
  }
}

\cs_set_eq:NN \softnormalfont \lngx_soft_normal_font:n

\cs_new_protected:Npn \lngx_softer_normal_font: {
  \lngx_soft_normal_font:n {
    family,
    series,
    shape
  }
}

\cs_set_eq:NN \softernormalfont \lngx_softer_normal_font:

\cs_new_protected:Npn \lngx_softest_normal_font: {
  \lngx_soft_normal_font:n {
    encoding,
    family,
    series,
    shape
  }
}

\cs_set_eq:NN \softestnormalfont \lngx_softest_normal_font:
\cs_new:Npn \CurrentEncoding {
  \tl_use:N \l_lngx_current_encoding_tl
}
\cs_new:Npn \CurrentMetaFamily {
  \tl_use:N \l_lngx_current_meta_family_tl
}
\cs_new:Npn \CurrentSuperFamily {
  \tl_use:N \l_lngx_current_super_family_tl
}
\cs_new:Npn \CurrentSeries {
  \tl_use:N \l_lngx_current_series_tl
}
\cs_new:Npn \CurrentShape {
  \tl_use:N \l_lngx_current_shape_tl
}
\endinput
%%
%% End of file `linguistix-nfss.sty'.
