\ProvidesPackage{biblatex-greifswald}[2026/05/25 v1 tabular authoryear bibliographies for biblatex]
% license: MIT
% author-maintainer: Jonathan Garbe, jonathan.garbe at stud.uni-greifswald.de

\RequirePackage{biblatex-ext-tabular, longtable}

% Lengths
\ifdefined\greifswalddatesep\else
\newlength\greifswalddatesep\fi
\ifdefined\greifswaldcolsep\else
\newlength\greifswaldcolsep\fi
\ifdefined\greifswalddatewidth\else
    \newlength\greifswalddatewidth
    \settowidth\greifswalddatewidth{2000m/2000}
\fi
% Approximation for the space caused by \\ in the table
\newlength\greifswald@lineskip
\setlength\greifswald@lineskip{1em}

% Macros
\newbibmacro{greifswald:author}{\usebibmacro{tabular:sortname}}
\newbibmacro{greifswald:date}{\usebibmacro{date+extradate}}
\newbibmacro{greifswald:omitauthor+date}{%
    \usebibmacro{tabular:omitsortname}%
    \clearfield{date}%
    \clearfield{year}%
}

% Alternative to \bbx@lasthash
\newcommand\greifswald@lasthash{}

% Bibliography definition
\defbibtabular{bibtabular}{
    % Remove longtable top margin and \vskip\bibnamesep
    \vspace{\dimexpr-\LTpre-\greifswald@lineskip-\bibnamesep\relax}%
    \begin{longtable}{
        @{}
        p{\greifswalddatewidth}
        @{\hspace{\greifswaldcolsep}}
        p{\dimexpr\columnwidth-\greifswalddatewidth-\greifswaldcolsep\relax}
        @{}
    }%
}{%
    \end{longtable}
}{%
    % \multicolumn can only be placed directly after \\
    \\[-\greifswald@lineskip]%
    \multicolumn{2}{@{}p{\columnwidth}@{}}{%
        \plainlang{%
            % Check whether a new author has to be printed
            \let\bbx@lasthash\greifswald@lasthash%
            \usebibmacro{bbx:dashcheck}{%
                \vspace{\bibitemsep}%
            }{%
                % Author
                \vskip\bibnamesep%
                \usebibmacro{greifswald:author}%
                \vspace*{\greifswalddatesep}%
            }%             
            \savefield{bibnamehash}\greifswald@lasthash%
        }
    }\\*%
    % Date
    \anchorlang{\usebibmacro{greifswald:date}}&%
    % Body
    \driver{\usebibmacro{greifswald:omitauthor+date}}%
}