% !Mode:: "TeX:UTF-8"
%% udesoftec-biblatex.sty
%% Copyright 2015 J. Peter M. Schuler
%% 2021/02/22 v1.7.1 udesoftec

%
% 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 `author-maintained'.
% 
% The current maintainer of this work is J. Peter M. Schuler
% j.peter.m.schuler@uni-due.de
%
% This work consists of the files 
% * udesoftec.cls 
% * udesoftec.bst
% * udesoftec-bibcommon.sty
% * udesoftec-biblatex.sty
% * udesoftec-bst.sty
% * udesoftec-extra.sty
%
% As this work is based on years of mostly undocumented improvement, 
% it includes parts, for which sources can't be identified anymore. Public postings
% in the LaTeX community were used as an input and if source is known, it is
% mentioned below. If anybody identifies parts of his/her own code,
% feel free to contact the maintainer in order to get listed. 
%
% Special thanks to all contributors and for the help of the tex-live team,
% e.g. Axel K.; Norbert P.; Petra R.; Rainer S.; Reinhard K.; Robin F.
%
% For further information refer to:
% http://mirrors.ctan.org/macros/latex/contrib/udesoftec/README
% and
% http://mirrors.ctan.org/macros/latex/contrib/udesoftec/udesoftec-doc.pdf

\NeedsTeXFormat{LaTeX2e}%
\ProvidesPackage{udesoftec-biblatex}[2021/02/22 v1.7.1 udesoftec-biblatex.sty udesoftec bibstyle configuration for biblatex]%

% 
% \newif\ifprimaryDocumentLanguageGerman
% \DeclareOption{de}          {\primaryDocumentLanguageGermantrue}
% \DeclareOption{en}          {\primaryDocumentLanguageGermanfalse}

\newif\ifdocumentIsFinal
\documentIsFinalfalse
\DeclareOption{final}          {\documentIsFinaltrue}

\DeclareOption*{\PackageWarning{udesoftec-biblatex}{Unknown option \CurrentOption}}

\ProcessOptions\relax
%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{udesoftec-bibcommon}

\usepackage[
    backend=biber,
    style=authoryear,
    natbib=true, %full cite command fallback
    dashed=false,
    %sortcites=true,
    sorting=nyt,
    maxcitenames=2,
    giveninits=true,
    terseinits=true,
    uniquename=false,
    uniquelist=false,
    urldate=long,
    maxbibnames=99]{biblatex}
\@ifpackageloaded{biblatex_legacy}
{
\ExecuteBibliographyOptions{labeldate,sorting=nyt,pagetracker}
}{
\ExecuteBibliographyOptions{labeldateparts,sorting=nyt,pagetracker}
}
\setlength{\bibhang} {1.5em} %hanging indentation for list of references
\setlength{\bibitemsep} {.25em}
\setlength{\bibnamesep} {.25em}
\setlength{\bibinitsep} {.25em}


\DeclareFieldFormat*{title}{\bblFontTitle{#1}}
\renewcommand*{\mkbibacro}[1]{#1}
\DeclareFieldFormat{isbn}{\mkbibacro{ISBN}\addcolon{}#1}
\DeclareFieldFormat{isrn}{\mkbibacro{ISRN}\addcolon{}#1}
\DeclareFieldFormat{issn}{\mkbibacro{ISSN}\addcolon{}#1}
\DeclareFieldFormat{doi}{\bbldoi{#1}}


\renewcommand*{\mkbibnameprefix}[1]{\bblFontAuthorInText{#1}}
\renewcommand*{\mkbibnamefamily}[1]{\bblFontAuthorInText{#1}}

\renewcommand*{\labelnamepunct}{\bblAuthorTitleSep}
\renewcommand*{\revsdnamedelim}{\bblAuthorsSep}
\renewcommand*{\multinamedelim}{\bblAuthorsSep}
\renewcommand*{\finalnamedelim}{ \bblFontAuthorInText{\bblAuthorsSepInText}}

\renewcommand*{\multilistdelim}{\bblAuthorsSep}
\renewcommand*{\finallistdelim}{\bblAuthorsSep}

\renewcommand*{\andothersdelim}{\space}
\renewcommand*{\nameyeardelim}{\space}


\renewcommand*{\finentrypunct}{}


\DeclareFieldFormat{booktitle}{\bblFontInBookTitle{#1}\isdot}
\DeclareFieldFormat{journaltitle}{\bblFontJournalTitle{#1}\isdot}
\DeclareFieldFormat{issuetitle}{\bblFontInBookTitle{#1}\isdot}
\DeclareFieldFormat{maintitle}{\bblFontInBookTitle{#1}\isdot}

\AtBeginBibliography{%
    \renewcommand*{\finalnamedelim}{\bblAuthorsSep}
%    \renewcommand*{\mkbibnameprefix}[1]{#1}
    \renewcommand*{\mkbibnamelast}[1]{#1}
    \renewcommand*{\mkbibnamegiven}[1]{#1}
    \renewcommand*{\mkbibnamefamily}[1]{#1}
%    \renewcommand*{\mkbibnameaffix}[1]{#1}
    \renewcommand*{\bibnamedelimd}{\bblFirstnameSep}
    \renewcommand*{\multinamedelim}{\bblAuthorsSep}
    \renewcommand*{\finalnamedelim}{\bblAuthorsSep}%
    \renewcommand*{\revsdnamepunct}{}
    \doublehyphendemerits=10000
    \raggedright    
}



  \toggletrue{abx@bool@giveninits}%
  \DeclareNameAlias{default}{family-given}%
    \renewbibmacro*{name:last-first}[5]{%
        \usebibmacro{name:delim}{#1}%
         \ifblank{#3}{}{\bibnamedelimd\mkbibnameprefix{#3}\isdot}%
         \mkbibnamelast{#1}\isdot%
         \ifblank{#4}{}{\bibnamedelimd\mkbibnameaffix{#4}\isdot}%
         \ifblank{#2}{}{\bibnamedelimd\mkbibnamefirst{#2}}%
    
}

\DeclareNameAlias{sortname}{last-first} %alle Autoren in der Biblografie gleich


\DefineBibliographyStrings{ngerman}{%
    references = {\bblheading},
    andothers         = {\bblFontAuthorInText{\bbletal}}, % we don't use et al in bbl
    editor        = {\bbled},%
    editors       = {\bbleds},%
    urlseen   = {\bbllastaccesswas}%
}

\DefineBibliographyStrings{english}{%
references = {\bblheading},
  andothers         = {\bblFontAuthorInText{\bbletal}}, % we don't use et al in bbl
  editor        = {\bbled},%
  editors       = {\bbleds},%
  urlseen   = {\bbllastaccesswas}%
%  page             = {{Seite}{S\adddot}},
%  pages            = {{Seiten}{S\adddot}},
}

\DefineBibliographyStrings{british}{%
references = {\bblheading},
  andothers         = {\bblFontAuthorInText{\bbletal}}, % we don't use et al in bbl
  editor        = {\bbled},%
  editors       = {\bbleds},%
  urlseen   = {\bbllastaccesswas}%
%  page             = {{Seite}{S\adddot}},
%  pages            = {{Seiten}{S\adddot}},
}

\AtEveryBibitem{\clearlist{language}}
\AtEveryBibitem{\clearfield{pagetotal}}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newbibmacro*{byeditor+suffix}{%
  \ifnameundef{editor}
    {}
    {%\usebibmacro{byeditor+othersstrg}%
     %\setunit{\addspace}%
     \printnames[byeditor]{editor}%
     \clearname{editor}%
  \usebibmacro{editorstrg}%
     \newunit}%
  \usebibmacro{byeditorx}%
  \usebibmacro{bytranslator+others}%
 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% suppress URL and ISBN if doi present
\settoggle{bbx:isbn}{false} %deactivate normal isbn output
\renewbibmacro*{doi+eprint+url}{%
  \iffieldundef{doi}
  {
  \printfield{isbn}
  \printfield{issn}
   \usebibmacro{url+urldate}
  }
  {
    \printfield{doi}
     \newunit\newblock
    \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  }
 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% for compatibility with bibcommon's citemulti
\providecommand{\bibstyle@udesoftec}{}
\providecommand{\bibstyle@udesoftecmulticite}{}

\let\defaultCite\cite%
\let\cite\citep%

\renewcommand*{\citemulti}[1]{%
\let\cite\defaultCite%
\mkbibparens{#1}%
\let\cite\citep%
}


\providebibmacro*{date+extradate}{}

\def\bbx@opt@mergedate@true{\bbx@opt@mergedate@compact}

% merge date/issue with date label
\def\bbx@opt@mergedate@maximum{%
  \renewbibmacro*{date+extradate}{%
    \iffieldundef{\thefield{datelabelsource}year}
      {}
      {\printtext[parens]{%
         \printfield{issue}%
         \setunit*{\addspace}%
         \iffieldsequal{year}{\thefield{datelabelsource}year}
           {\printdateextralabel}%
           {\printfield{labelyear}%
            \printfield{extradate}}}}}%
  \renewbibmacro*{date}{}%
  \renewbibmacro*{issue+date}{}}

% merge date with date label
\def\bbx@opt@mergedate@compact{%
  \renewbibmacro*{date+extradate}{%
    \iffieldundef{\thefield{datelabelsource}year}
      {}
      {\printtext[parens]{%
         \iffieldsequal{year}{\thefield{datelabelsource}year}
           {\printdateextralabel}%
           {\printfield{labelyear}%
            \printfield{extradate}}}}}%
  \renewbibmacro*{date}{}%
  \renewbibmacro*{issue+date}{%
    \iffieldundef{issue}
      {}
      {\printtext[parens]{\printfield{issue}}}%
    \newunit}}

% merge year-only date with date label
\def\bbx@opt@mergedate@basic{%
  \renewbibmacro*{date+extradate}{%
    \iffieldundef{\thefield{datelabelsource}year}
      {}
      {\printtext[parens]{%
         \printfield{\thefield{datelabelsource}year}%
         \printfield{extradate}}}}%
  \renewbibmacro*{date}{%
    \iffieldundef{month}
      {}
      {\printdate}}%
  \renewbibmacro*{issue+date}{%
    \ifboolexpr{
      test {\iffieldundef{issue}}
      and
      test {\iffieldundef{month}}
    }
      {}
      {\printtext[parens]{%
         \printfield{issue}%
         \setunit*{\addspace}%
         \printdate}}%
    \newunit}}

% merge year-only date with year-only date label
\def\bbx@opt@mergedate@minimum{%
  \renewbibmacro*{date+extradate}{%
    \iffieldundef{\thefield{datelabelsource}year}
      {}
      {\printtext[parens]{%
         \printfield{\thefield{datelabelsource}year}%
         \printfield{extradate}}}}%
  \renewbibmacro*{date}{%
    \ifboolexpr{
      test {\iffieldundef{month}}
      and
      test {\iffieldundef{extradate}}
    }
      {}
      {\printdate}}%
  \renewbibmacro*{issue+date}{%
    \ifboolexpr{
      test {\iffieldundef{issue}}
      and
      test {\iffieldundef{month}}
      and
      test {\iffieldundef{extradate}}
    }
      {}
      {\printtext[parens]{%
         \printfield{issue}%
         \setunit*{\addspace}%
         \printdate}}%
    \newunit}}

% don't merge date/issue with date label
\def\bbx@opt@mergedate@false{%
  \renewbibmacro*{date+extradate}{%
    \iffieldundef{\thefield{datelabelsource}year}
      {}
      {\printtext[parens]{%
         \printfield{\thefield{datelabelsource}year}%
         \printfield{extradate}}}}%
  \renewbibmacro*{date}{\printdate}%
  \renewbibmacro*{issue+date}{%
    \printtext[parens]{%
      \printfield{issue}%
      \setunit*{\addspace}%
      \printdate}%
    \newunit}}

\defbibheading{udesoftec}[\bibname]{%
    \addchap{#1}
}
\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\bblFontAuthorInList{\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}}%
\bblFontYearInList{\usebibmacro{date+extradate}}}
\renewbibmacro*{in:}{\printtext{\bblin}}
\renewbibmacro*{editor}{%
  \usebibmacro{bbx:editor}{editorstrg}}
\renewbibmacro*{editor+others}{%
  \usebibmacro{bbx:editor}{editor+othersstrg}}
  
  
%remove punctuation before (eds) and make bold
\renewbibmacro*{bbx:editor}[1]{%
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\bblFontAuthorInList{\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\printnames{editor}%
        \setunit{\bblEdPrefix}%
        \usebibmacro{bbx:savehash}}%
     \usebibmacro{#1}%
     \clearname{editor}%
     \setunit{\addspace}}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\addspace}}%
\bblFontYearInList{\usebibmacro{date+extradate}}}
 % erst publisher, dann location
 \renewbibmacro*{publisher+location+date}{%
  \printlist{publisher}%
  \setunit*{\addcomma\space}%
  \printlist[][1-1]{location}%nur erste Location
  \setunit*{\addcomma\space}%
  \usebibmacro{date}%
  \newunit}

% location ohne schnickscnack
\DeclareListFormat{location}{#1}
%Todo: Bundesland/Land entfernen


\renewbibmacro*{event+venue+date}{%
  \printfield{eventtitle}%
  \iffieldundef{eventtitleaddon}%
  {}%
  {%
  \newunit%
  \printfield{eventtitleaddon}%
  }
  \ifboolexpr{
    test {\iffieldundef{venue}}
    and
    test {\iffieldundef{eventyear}}
  }
    {}
    {\setunit*{\addspace}%
     \printtext[parens]{%
       \printfield{venue}%
       \setunit*{\addcomma\space}%
       \printeventdate}}%
  \newunit}



% remove double editors from proceedings

\DeclareBibliographyDriver{proceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{editor+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{maintitle+title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{event+venue+date}%
  \newunit\newblock
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \printlist{organization}%
  \newunit
  \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}}
  
  
  
  
  
  
  

\DeclareBibliographyDriver{inproceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{in:}%
  \usebibmacro{byeditor+suffix}%
  \usebibmacro{maintitle+booktitle}%
  \newunit\newblock
  \usebibmacro{event+venue+date}%
  \newunit\newblock
  \newunit\newblock
  \iffieldundef{series}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
%  \printlist{organization}%
%  \newunit
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \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}
  }
  
 \DeclareBibliographyDriver{incollection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{in:}%
  \usebibmacro{byeditor+suffix}%
  \usebibmacro{maintitle+booktitle}%
  \newunit\newblock
  \iffieldundef{series}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
%  \printlist{organization}%
%  \newunit
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \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}
  } 
  
  
  
  

%%%%%%%%%%%%
% link whole cite including name
% http://tex.stackexchange.com/questions/15951/hyperlink-name-with-biblatex-authoryear-biblatex-1-4b
%%%%%%%%%%%%
\DeclareFieldFormat{citehyperref}{%
  \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
  \bibhyperref{#1}}

\DeclareFieldFormat{textcitehyperref}{%
  \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
  \bibhyperref{%
    #1%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}}}

\savebibmacro{cite}
\savebibmacro{textcite}

\renewbibmacro*{cite}{%
  \printtext[citehyperref]{%
    \restorebibmacro{cite}%
    \usebibmacro{cite}}}

\renewbibmacro*{textcite}{%
  \ifboolexpr{
    ( not test {\iffieldundef{prenote}} and
      test {\ifnumequal{\value{citecount}}{1}} )
    or
    ( not test {\iffieldundef{postnote}} and
      test {\ifnumequal{\value{citecount}}{\value{citetotal}}} )
  }
    {\DeclareFieldAlias{textcitehyperref}{noformat}}
    {}%
  \printtext[textcitehyperref]{%
    \restorebibmacro{textcite}%
    \usebibmacro{textcite}}}

\AtEveryCitekey{%
\clearfield{shorthand}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput%