%% ---------------------------------------------------------------
%% biblatex-dtk --- A set of biblatex implementations of
%%   dtk bibliography styles for DANTE's journal 
%%   "Die TeXnische Kom��die"
%% Maintained by Herbert Vo��
%% (C) herbert@dante.de
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ---------------------------------------------------------------
%% 
\ProvidesFile{dtk.bbx}[2024/01/20 v0.13 biblatex bibliography style for DTK]

% Load the standard style to avoid copy-pasting unnecessary material
\RequireBibliographyStyle{chem-angew}
%\RequireBibliographyStyle{numeric}
%\RequireBibliographyStyle{authoryear}

\DeclareBibliographyOption{dashed}[true]{%
  \ifstrequal{#1}{true}
    {\ExecuteBibliographyOptions{pagetracker}%
     \newbibmacro*{bbx:savehash}{\savefield{fullhash}{\bbx@lasthash}}}
    {\newbibmacro*{bbx:savehash}{}}}

\ExecuteBibliographyOptions
  {
    doi          = true ,
    eprint       = true , 
    giveninits   = false,
    isbn         = true ,
    maxnames     = 3   ,
    minnames     = 1   ,
%    maxcitenames= 2     ,
%    pageranges  = true  ,
    url          = true,
    articletitle = true,
    chaptertitle = true,
%    biblabel    = parens,
     sorting     = nyvt,  
     dashed      = true,
     datezeros   = false,
}

\newbool{bbx@inset}
\providebibmacro*{date+extrayear}{}


\DeclareFieldFormat{date}{#1}
\DeclareFieldFormat{booktitle}{#1\isdot}
\DeclareFieldFormat{journaltitle}{\mkbibemph{#1}\isdot}
\DeclareFieldFormat{removecomma}{\mkbibnocomma{#1}}
\DeclareFieldFormat{title}{#1\isdot}
\DeclareFieldFormat[ctan]{url}{\url{CTAN: #1}}
\DeclareFieldFormat[article]{number}{\mkbibemph{#1}}

\DeclareFieldFormat{isbn}{ISBN\addcolon\space #1}
\DeclareFieldFormat{isrn}{ISRN\addcolon\space #1}
\DeclareFieldFormat{issn}{ISSN\addcolon\space #1}

\newbibmacro*{ctanurl+urldate}{%
  \printfield{url}
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addspace}%
     \usebibmacro{urldate}}}

\DeclareListFormat{language}{}{}

\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\printnames{author}\setunit{\addcolon\space}%
     \iffieldundef{authortype}
       {}
       {\setunit{\addcolon\space}%
        \usebibmacro{authorstrg}}}
    {}}
    
\renewbibmacro*{journal+issuetitle}{%
  \usebibmacro{journal}%
  \setunit*{\addcomma\addspace}%
  \iffieldundef{series}
    {}
    {\newunit
     \printfield{series}%
     \setunit{\addspace}}%
  \usebibmacro{volume+number+eid}%
  \setunit{\addspace}%
  \usebibmacro{issue+date}%
  \setunit{\addcolon\space}%
  \usebibmacro{issue}%
  \newunit}

\renewcommand*\labelnamepunct{\addcolon\addspace}

\DeclareNameFormat{default}{%
  \nameparts{#1}%
  \usebibmacro{name:given-family}{\namepartfamily}{\namepartgiven}{\namepartprefix}{\namepartsuffix}%
%  \usebibmacro{name:given-family}\namepartfamily}{\namepartgiveni}{\namepartprefix}{\namepartsuffix}
  \usebibmacro{name:andothers}}

\newbibmacro*{bbx:dashcheck}[2]{%
  \ifboolexpr{%
    test {\iffieldequals{fullhash}{\bbx@lasthash}}
    and
    not test \iffirstonpage
    and
    (
       not bool {bbx@inset}
       or
       test {\iffieldequalstr{entrysetcount}{1}}
    )%
  }{#1}{#2}}

\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\usebibmacro{bbx:savehash}%
        \printnames{author}%
        \iffieldundef{authortype}
          {\setunit{\addspace}}
          {\setunit{\addcomma\space}}}%
     \iffieldundef{authortype}
       {}
       {\usebibmacro{authorstrg}%
        \setunit{\addspace}}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\addspace}}%
  \usebibmacro{date+extrayear}}

\renewcommand*\bibnamedash{\textemdash\hspace{1em}}%
%  \ifdimless{\leftmargin}{0.75em}
%    {\mbox{\textemdash\space}}
%    {\makebox[\leftmargin][l]{%
%       \ifdimless{\leftmargin}{1.25em}
%         {\textendash}
%         {\textemdash}}}}



\DeclareBibliographyDriver{ctan}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\labelnamepunct} %\newblock
  \usebibmacro{title}%
%  \newunit
%  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit %\newblock
  \usebibmacro{byeditor+others}%
  \newunit %\newblock
  \printfield{version}%
  \newunit
  \printfield{note}%
  \newunit %\newblock
  \printlist{organization}%
  \newunit\newblock
  \usebibmacro{date}%
  \newunit %\newblock
  \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  \newunit %\newblock
  \usebibmacro{ctanurl+urldate}%
  \newunit %\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}}
%

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{maintitle+title}%
  \newunit
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{isbn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}%
}





%\setlength\labelnumberwidth{1.5em}
%\setlength\biblabelsep{1em}
\defbibenvironment{dtk@bib}
  {\list
     {\printtext[labelnumberwidth]{%
	\printfield{prefixnumber}%
	\printfield{labelnumber}}}
     {\setlength{\labelwidth}{\labelnumberwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{\hss##1}%
      \RaggedRight}
  {\endlist}
  {\item}

%%
%% 
\endinput