%%
%% This is file `projlib-text.sty',
%% generated with the docstrip utility.
%%
%% Copyright (C) 2021-2022 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-text}
  {2022/07/03} {}
  {Text-related commands}

\keys_define:nn { projlib-text }
  {
    , unknown .code:n       = {}
  }
\ProcessKeyOptions [ projlib-text ]

\RequirePackage { projlib-paper }

\ProvideDocumentCommand \ItemDescription { m }
  {
    \textcolor { main-text!50!paper } { $($ #1 $)$  }
    \nobreakspace
    \ignorespaces
  }

\cs_new_protected:Nn \projlib_text_abbreviation_generic:nn
  % #1 is the text
  % #2 is usually some spacing adjustment
  {
    #1
    % if followed by a dot, then remove that dot and adjust the spacing
    \peek_meaning_ignore_spaces:NTF .
      { #2 \use_none:n }
      {
        % if followed by a comma, then act like nothing happens
        % otherwise adjust the spacing
        \peek_meaning_ignore_spaces:NTF ,
          { \prg_do_nothing: }
          { #2 }
      }
  }

\hook_gput_code:nnn { begindocument/before } { projlib-text }
  {
    % i.e.
    \ProvideDocumentCommand { \ie } { }
      {
        \projlib_text_abbreviation_generic:nn { \textit{i. \nobreak \hskip.2ex \nobreak e.} } { \skip_horizontal:n { -.25ex } }
      }

    % e.g.
    \ProvideDocumentCommand { \eg } { }
      {
        \projlib_text_abbreviation_generic:nn { \textit{e. \nobreak \hskip.2ex \nobreak g.} } { \skip_horizontal:n { -.25ex } }
      }

    % cf.
    \ProvideDocumentCommand { \cf } { }
      {
        \projlib_text_abbreviation_generic:nn { \textit{cf.} } { }
      }

    % etc.
    \ProvideDocumentCommand { \etc } { }
      {
        \projlib_text_abbreviation_generic:nn { etc. } { }
      }
  }

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