1

I am trying to reproduce my university bibliography style in biblatex.

In the bibliography, every entry is prefixed with label in parentheses which consists of institution or authors, year and cited page (optional). When there are two entries with the same institution or authors and the same year, the year should be suffixed with consecutive letters as pictured below:

university template

At this point, the code generating bibliography looks as follows:

\defbibenvironment{bibliography}{%
  \list{%
    \printtext[parens]{%
      \printlist{institution}%
      \setunit*{\addcomma\addspace}%
      \printnames[author-label][-2]{author}%
      \setunit*{,\addspace}%
      \printfield{year}%
      \iffieldundef{thiscite}{}
        {\addcomma\space\printfield{thiscite}}%
    }%
    \enspace---\enspace%
  }{%
    \setlength{\labelwidth}{\labelnumberwidth}%
    \setlength{\leftmargin}{\labelwidth}%
    \setlength{\labelsep}{0pt}%
    \addtolength{\leftmargin}{\labelsep}%
    \setlength{\itemsep}{\bibitemsep}%
    \setlength{\parsep}{\bibparsep}}%
    \renewcommand*{\makelabel}[1]{\hss##1}
}{\endlist}{\item}

…which produces the following:

illustration of bibliography environment

I was only able to find partial snippets in the biblatex documentation, but there was no concrete example, so I was not able to make anything out of it.

How can I check if there are two labels with the same institution/authors and year and insert suffix after the year?

MWE

wsb.bbx:

\ProvidesFile{wsb.bbx}[2020/01/11 WSB bibliography style]

\RequireBibliographyStyle{standard}

\DeclareDatamodelFields[type=field, datatype=range, skipout=false]{thiscite}
\DeclareFieldFormat{thiscite}{\mkpageprefix{#1}}

\def\printname{\usebibmacro{name:family}{\namepartfamily}{\namepartgiven}{\namepartprefix}{\namepartsuffix}}
\DeclareNameFormat{author-label}{%
  % If there are more than three names, print only the first one
  \ifmorenames%
    {\ifthenelse{\value{listcount}=1}
      {\printname{} \bibstring{andothers}}
      {}}
    {\printname{}}%
}

\DeclareNameFormat{author}{%
  \namepartfamily%
  \ifdefvoid{\namepartgiven}
    {}{\addcomma\space\namepartgiveni}%
  \ifthenelse{\value{listcount}=\value{liststop}}
    {}{\addcomma\space}%
  \usebibmacro{name:andothers}%
}

\defbibenvironment{bibliography}{%
  \list{%
    \printtext[parens]{%
      \printlist{institution}%
      \setunit*{\addcomma\addspace}%
      \printnames[author-label][-2]{author}%
      \setunit*{,\addspace}%
      \printfield{year}%
      \iffieldundef{thiscite}{}
        {\addcomma\space\printfield{thiscite}}%
    }%
    \enspace---\enspace%
  }{%
    \setlength{\labelwidth}{\labelnumberwidth}%
    \setlength{\leftmargin}{\labelwidth}%
    \setlength{\labelsep}{0pt}%
    \addtolength{\leftmargin}{\labelsep}%
    \setlength{\itemsep}{\bibitemsep}%
    \setlength{\parsep}{\bibparsep}}%
    \renewcommand*{\makelabel}[1]{\hss##1}
}{\endlist}{\item}

\newbibmacro*{institution+author+year}{%
  \printlist{institution}%
  \setunit*{\addcomma\addspace}%
  \printnames{author}%
  \setunit{,\addspace}%
  \printfield{year}%
}

\DeclareBibliographyDriver{report}{%
  \usebibmacro{institution+author+year}%
  \newunit\newblock%
  \printfield{title}%
  \setunit{\addcomma\addspace}%
  \iffieldundef{journaltitle}{}
    {\usebibmacro{in:}%
      \printfield{journaltitle}}%
  \setunit{\addcomma\addspace}%
  \printfield{number}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{url+urldate}%
  \setunit{\addcomma\addspace}%
  \printfield{pages}%
  \newunit\newblock%
\finentry}

mve.tex:

\documentclass[]{article}

\usepackage[
    bibstyle=wsb,
    sortcites=true,
    sorting=nty,
]{biblatex}

\usepackage{filecontents}
\begin{filecontents*}{sample.bib}
@report{gus_2016,
    title = "Działalność innowacyjna przedsiębiorstw w~latach 2013-2016",
    institution = "GUS",
    url = "http://stat.gov.pl/obszary-tematyczne/nauka-i-technikaspoleczenstwo-informacyjne/nauka-i-technika/dzialanosc-innowacyjnaprzedsiebiorstw-w-latach-2013-2015,2,14.html",
    urldate = "2017-07-18",
    thiscite = "3",
    year = 2016,
}

@report{gus_2016a,
    title = "Badanie organizacji i~rozkładu czasu pracy w~Polsce w~2015 roku",
    institution = "GUS",
    url = "http://stat.gov.pl/obszary-tematyczne/rynekpracy/opracowania/badanie-organizacji-i-rozkladu-czasu-pracy-wpolsce-w-2015-r-,12,1.html",
    urldate = "2017-07-18",
    thiscite = "38",
    year = 2016,
}
\end{filecontents*}
\addbibresource{sample.bib}

\begin{document}
Citation number one \cite{gus_2016}.

Citation number two \cite{gus_2016a}.

\printbibliography{}
\end{document}
1
  • 3
    You may want to look into basing your style onto authoryear (check out authoryear.bbx and authoryear.cbx). Biber can calculate uniqueness information and add disambiguation letters where required (extradate info). – moewe Jan 23 '20 at 21:15
3

I suggest you base your style on authoryear or one of its derivatives. biblatex (or rather Biber/BibTeX) automatically calculate uniqueness information for author/editor-year combinations and make them available in the extradate field (which is automatically printed with \printlabeldateextra, \printdateextra and friends).

Then the repetition of the citation in the bibliography can be implemented as in my biblatex-ext styles (the introcite=plain, feature). This made it possible to remove a few now unused macros.

There are some smaller changes to the style as well

  • It is good practice to make sure that all bibliography drivers start with \usebibmacro{bibindex}\usebibmacro{begentry} and end with \usebibmacro{finentry}.
  • Data model commands need to be in a separate .dbx file.

Finally, I changed the field for GUS in the example entries from institution to author. author and editor are functional roles, so if the author was an institution, there is no reason not to include it there. The institution and organization fields are similar in role to the publisher field. Compare also If no author use organization or institution.

In total (with .bbx, .cbx, .dbx file produced by inline filecontents to make the example self contained)

\documentclass[polish]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\begin{filecontents}{wsb.bbx}
\ProvidesFile{wsb.bbx}[2020/01/24 WSB bibliography style]

\RequireBibliographyStyle{authortitle}

\DeclareFieldFormat{thiscite}{\mkpageprefix{#1}}

\newbibmacro*{bbx:introcite}{\usebibmacro{cite}}

\newcommand*{\extblx@introcite@init}{%
  \iftoggle{blx@citation}
    {}
    {\togglefalse{blx@bibliography}%
     \toggletrue{blx@citation}}%
  \delimcontext{bbx@introcite}%
  \csuse{blx@hook@cite}%
  \csuse{blx@hook@citekey}%
  \DeclareFieldFormat{bibhyperref}{##1}%
  \undef\cbx@lasthash
  \undef\cbx@lastyear
  \citetrackerfalse\pagetrackerfalse\backtrackerfalse
  \defcounter{maxnames}{\blx@maxcitenames}%
  \defcounter{minnames}{\blx@mincitenames}%
}

\newbibmacro{introcite:typeset}{%
  \begingroup
    \extblx@introcite@init
    \printtext[bbx@introcite]{\usebibmacro{bbx:introcite}}%
  \endgroup
}

\newbibmacro{introcite:plain}{%
  \usebibmacro{introcite:typeset}%
  \printunit*{\introcitepunct}}

\DeclareFieldFormat{bbx@introcite}{\mkbibparens{#1}}
\newcommand*{\introcitepunct}{\enspace---\enspace}%

\renewbibmacro{begentry}{%
  \usebibmacro{introcite:plain}}


\newbibmacro*{institution+author+year}{%
  \printlist{institution}%
  \setunit*{\addcomma\space}%
  \printnames{author}%
  \setunit{\addcomma\space}%
  \printdate
}

\DeclareBibliographyDriver{report}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{institution+author+year}%
  \newunit\newblock%
  \printfield{title}%
  \setunit{\addcomma\addspace}%
  \iffieldundef{journaltitle}
    {}
    {\usebibmacro{in:}%
      \printfield{journaltitle}}%
  \setunit{\addcomma\addspace}%
  \printfield{number}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{url+urldate}%
  \setunit{\addcomma\addspace}%
  \printfield{pages}%
  \newunit\newblock%
  \usebibmacro{finentry}}

\endinput
\end{filecontents}

\begin{filecontents}{wsb.cbx}
\ProvidesFile{wsb.cbx}[2020/01/24 WSB citation style]

\RequireCitationStyle{authoryear}

\ExecuteBibliographyOptions{autocite=inline}

\DeclareDelimFormat{nameyeardelim}{\addcomma\space}

\endinput
\end{filecontents}

\begin{filecontents}{wsb.dbx}
\ProvidesFile{wsb.dbx}[2020/01/24 WSB bib/cite style data model]

\DeclareDatamodelFields[type=field, datatype=range, skipout=false]{thiscite}

\DeclareDatamodelEntryfields{thiscite}

\endinput
\end{filecontents}

\usepackage[
  style=wsb,
  sortcites=true,
]{biblatex}

\begin{filecontents*}{\jobname.bib}
@report{gus_2016,
  title       = {Działalność innowacyjna przedsiębiorstw w~latach 2013-2016},
  author      = {GUS},
  url         = {http://stat.gov.pl/obszary-tematyczne/nauka-i-technikaspoleczenstwo-informacyjne/nauka-i-technika/dzialanosc-innowacyjnaprzedsiebiorstw-w-latach-2013-2015,2,14.html},
  urldate     = {2017-07-18},
  thiscite    = {3},
  year        = 2016,
}
@report{gus_2016a,
  title       = {Badanie organizacji i~rozkładu czasu pracy w~Polsce w~2015 roku},
  author      = {GUS},
  url         = {http://stat.gov.pl/obszary-tematyczne/rynekpracy/opracowania/badanie-organizacji-i-rozkladu-czasu-pracy-wpolsce-w-2015-r-,12,1.html},
  urldate     = {2017-07-18},
  thiscite    = {38},
  year        = 2016,
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
Citation number one \autocite{gus_2016}.

Citation number two \autocite{gus_2016a}.

\printbibliography
\end{document}

(GUS, 2016a) — GUS, 2016. Badanie organizacji i rozkładu czasu pracy w Polsce w 2015 roku, url: http://stat.gov.pl/obszary-tematyczne/rynekpracy/opracowania/badanie-organizacji-i-rozkladu-czasu-pracy-wpolsce-w-2015-r-,12,1.html (term. wiz. 18.07.2017).//(GUS, 2016b) — GUS, 2016. Działalność innowacyjna przedsiębiorstw w latach 2013-2016, url: http://stat.gov.pl/obszary-tematyczne/nauka-i-technikaspoleczenstwo-informacyjne/nauka-i-technika/dzialanosc-innowacyjnaprzedsiebiorstw-w-latach-2013-2015,2,14.html (term. wiz. 18.07.2017).

5
  • What do these lines do? \undef\cbx@lasthash \undef\cbx@lastyear I have seen them used in authoryear.bbx, but I could not find any explanation in the documentation. Also, why do you disable trackers in the next line? Thank you for the answer and corrections. I will accept the answer as soon as I will apply it in my bibliography style. – Cezary Drożak Jan 24 '20 at 13:12
  • I have tried to compile your example, but I have an error "Missing \begin{document}" on the line with \begin{filecontents*}[force]{\jobname.bib} – Cezary Drożak Jan 24 '20 at 13:35
  • I had to remove [force] from the code. – Cezary Drożak Jan 24 '20 at 14:01
  • @CzarekDrożak [force] was introduced in LaTeX version 2019-10-01, so if you are using an older version that might produce errors. I wanted to remove all [force] options anyway to avoid overwriting stuff, but forgot that one. Will edit in a sec. – moewe Jan 24 '20 at 14:33
  • 1
    @CzarekDrożak \cbx@lasthash and \cbx@lastyear are used in some styles to implement the citation -comp feature, which turns "(Knuth 1984, Knuth 1986)" into "(Knuth 1984, 1986)". This is not desired when the citation is repeated in the bibliography and needs to be turned off. Same for some of the tracking features. I copied the code from biblatex-ext, where it has to deal with all sort of styles and situations, not all of the precautions may be needed in your case. – moewe Jan 24 '20 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.