% --------------------------------------------------------------------------
% the CNLTX bundle
%
%   LaTeX source code and output
%
% --------------------------------------------------------------------------
% Clemens Niederberger
% Web:    https://github.com/cgnieder/cnltx/
% E-Mail: contact@mychemistry.eu
% --------------------------------------------------------------------------
% Copyright 2013--2019 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% 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.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Clemens Niederberger.
% --------------------------------------------------------------------------
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% --------------------------------------------------------------------------
\RequirePackage{cnltx-base}
\ProvidesPackage{cnltx-tools}[\cnltx@@date\space \cnltx@@version\space \cnltx@@info]

% --------------------------------------------------------------------------
\cnltx@create@bundle@message{tools}{Error}
\cnltx@create@bundle@message{tools}{Warning}
\cnltx@create@bundle@message{tools}{WarningNoLine}
\cnltx@create@bundle@message{tools}{Info}

\cnltx@load@module{translations}

% --------------------------------------------------------------------------
% \newcommand*\cnltx@name@first[1]{#1}
% \newcommand*\cnltx@name@last[1]{\textsc{#1}}
% \newcommand*\cnltx@name@base[1]{#1}

% \pgfkeys{
%   cnltx/.cd,
%     last-name-format/.code = \def\cnltx@name@last##1{#1} ,
%     first-name-format/.code = \def\cnltx@name@first##1{#1} ,
%     name-format/.code = \def\cnltx@name@base##1{#1}
% }

% \newcommand*\cnltx@name@idx[2]{\index{#1@#2}}
% \newrobustcmd*\cnltx@name@star[2]{%
%   \ifblank{#1}
%     {\cnltx@name@base{\cnltx@name@last{#2}}}
%     {\cnltx@name@base{\cnltx@name@first{#1} \cnltx@name@last{#2}}}%
% }
% \newrobustcmd*\cnltx@name@nostar[2]{%
%   \ifblank{#1}
%     {%
%       \cnltx@name@base{\cnltx@name@last{#2}}%
%       \cnltx@name@idx{#2}{\cnltx@name@base{\cnltx@name@last{#2}}}%
%     }
%     {%
%       \cnltx@name@base{\cnltx@name@first{#1} \cnltx@name@last{#2}}%
%       \cnltx@name@idx{#2, #1}{%
%         \cnltx@name@base{\cnltx@name@last{#2}},
%         \cnltx@name@base{\cnltx@name@first{#1}}%
%       }%
%     }%
% }
% \newrobustcmd*\cnltx@name{\@ifstar{\cnltx@name@star}{\cnltx@name@nostar}}

% \newrobustcmd*\cnltx@newname[3]{%
%   \csdef{\cnltx@stripbs#1@short}{%
%     \cnltx@name@base{\cnltx@name@last{#3}}%
%     \cnltx@name@idx{#3, #2}{%
%       \cnltx@name@base{\cnltx@name@last{#3}, \cnltx@name@first{#2}}%
%     }%
%   }%
%   \csdef{\cnltx@stripbs#1@long}{%
%     \cnltx@name@base{\cnltx@name@first{#2} \cnltx@name@last{#3}}%
%     \cnltx@name@idx{#3, #2}{%
%       \cnltx@name@base{\cnltx@name@last{#3}},
%       \cnltx@name@base{\cnltx@name@first{#2}}%
%     }%
%   }%
%   \newrobustcmd*#1{%
%     \@ifstar
%       {\csuse{\cnltx@stripbs#1@short}}
%       {\csuse{\cnltx@stripbs#1@long}}%
%     }%
% }

% \newrobustcmd*\newname{\cnltx@newname}

% \newrobustcmd*\name{%
%   \@ifstar
%     {\@testopt{\cnltx@name@user*}{}}
%     {\@testopt{\cnltx@name@user{}}{}}%
% }
% \def\cnltx@name@user#1[#2]#3{\cnltx@name#1{#2}{#3}}


% --------------------------------------------------------------------------
\PassOptionsToPackage{space=true}{accsupp}
\RequirePackage{accsupp}
% #1: actual text
% #2: other options
% #3: TeX text
\newrobustcmd\cnltx@accsupp[3]{%
  \begingroup
  \BeginAccSupp{ ActualText = #1 , #2 }%
    #3%
  \EndAccSupp{}%
  \endgroup
}

\AtBeginDocument{%
  \@ifpackageloaded{hyperref}
    {}
    {%
      \providecommand\nohyperpage[1]{#1}%
      \providecommand\texorpdfstring[2]{#1}%
    }%
}

\def\cnltx@acronym@format{\scshape}

\pgfkeys{
  cnltx/.cd,
    acronym-format/.code = \def\cnltx@acronym@format{#1}
}

\newcommand*\cnltx@acronym[2]{%
  \ifblank{#1}
    {%
      \texorpdfstring
        {%
          \cnltx@accsupp{#2}{}{\cnltx@acronym@format#2}%
          \index{#2@{\cnltx@acronym@format#2}}%
        }
        {#2}%
    }
    {%
      \texorpdfstring
        {%
          \cnltx@accsupp{#1}{}{\cnltx@acronym@format#2}%
          \index{#1@{\cnltx@acronym@format#2}}%
        }
        {#1}%
    }%
}

\newcommand*\cnltxacronym{\cnltx@acronym}

% --------------------------------------------------------------------------
% abbreviations:

% \def\cnltx@abbr@ifdot{\ltx@ifnextchar@nospace.}
\protected\def\cnltx@abbr@dot#1{\cnltx@ifpunctuation*[.]{#1\@}{#1.\@}}

% --------------------------------------------------------------------------
% \defabbr
\protected\def\cnltx@defabbr@dot#1#2{\def#1{\cnltx@abbr@dot{#2}}}
\protected\def\cnltx@defabbr@nodot#1#2{\def#1{#2}}

% \newabbr
\protected\def\cnltx@newabbr@dot#1#2{%
  \cnltx@ifdef#1{}{\protected\def#1{\cnltx@abbr@dot{#2}}}}

\protected\def\cnltx@newabbr@nodot#1#2{%
  \cnltx@ifdef#1{}{\protected\def#1{#2}}}

% \renewabbr
\protected\def\cnltx@renewabbr@dot#1#2{%
  \cnltx@ifdef#1{\protected\def#1{\cnltx@abbr@dot{#2}}}{}}

\protected\def\cnltx@renewabbr@nodot#1#2{%
  \cnltx@ifdef#1{\protected\def#1{#2}}{}}

\def\cnltx@ifdef#1{%
  \ifcsname\expandafter\@gobble\string#1\endcsname
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}

\newrobustcmd*\newabbr{%
  \@ifstar{\cnltx@newabbr@nodot}{\cnltx@newabbr@dot}%
}

\newrobustcmd*\renewabbr{%
  \@ifstar{\cnltx@renewabbr@nodot}{\cnltx@renewabbr@dot}%
}

\newrobustcmd*\defabbr{%
  \@ifstar{\cnltx@defabbr@nodot}{\cnltx@defabbr@dot}%
}

% --------------------------------------------------------------------------
\RequirePackage{translations}

\newcommand*\cnltxlatin[1]{\textit{#1}}

\newabbr\ie{\GetTranslation{cnltx-i.e.}}
\newabbr\eg{\GetTranslation{cnltx-e.g.}}
\newabbr\cf{\GetTranslation{cnltx-cf.}}
\newabbr\etc{\GetTranslation{cnltx-etc.}}
\newabbr\vs{\GetTranslation{cnltx-vs.}}

\newabbr\zB{z.\,B}
\newabbr\ZB{Z.\,B}
\newabbr\usw{usw}
\newabbr\usf{usf}
\newabbr\uswusf{usw.\@\space usf}
\newabbr\bzw{bzw}
\newabbr\dsh{d.\,h}
\newabbr\Dsh{D.\,h}
\newabbr\vgl{vgl}
\newabbr\Vgl{Vgl}

\newcommand*\cnltxtimeformat[1]{\textsc{\,#1}}
\newabbr\PM{\cnltxtimeformat{p.m}}
\newabbr\AM{\cnltxtimeformat{a.m}}
\newabbr\BC{\cnltxtimeformat{b.c}}
\newabbr\AD{\cnltxtimeformat{a.d}}

\endinput

% --------------------------------------------------------------------------
HISTORY:

2013/09/10 v0.2  - first published version
2013/09/30 v0.7  - added abbreviations
2013/11/22 v0.9  - \bzw
2014/03/11 v0.11 - bug fixes in the \newname definitions
                 - new command \name
                 - use \cnltx@load@module
2014/??/?? v0.?? - \vs