[Tex/LaTex] Customizing the biblatex style authoryear – Part 2

biblatex

This is a follow up question to Customizing the biblatex style authoryear.

For my work I need 3 more types of literature altered:

@inbook:

Last Name, First Name (year): Title. In Last BookauthorName, First BookauthorName (Hg): Booktitle, Pages. Location, Publisher.

Here, "In" and "(Hg)" should be hardcoded (it's German). I managed to undo the italic style for the booktitle and the parentheses of the title by:

\DeclareFieldFormat[inbook]{booktitle}{#1}
\DeclareFieldFormat[inbook]{title}{#1}

but that's about it.

@article:

Last Name, First Name (year): Title. Journaltitle, Number (Series), Pages.

@online:

Last Name, First Name (year): Title, (besucht am Date). Url.

here, "besucht am" should be hardcoded but is no problem since it's biblatex standard in German.

I can imagine that all of this isn't quite straight forward.. But any help would be greatly appreciated! Thanks a lot!

What I have thus far:

\usepackage[style=authoryear]{biblatex}
\addbibresource{sources.bib}

\DeclareFieldFormat[book]{title}{#1} %titel non-italic
\DeclareFieldFormat[inbook]{booktitle}{#1} %booktitle non-italic
\DeclareFieldFormat[inbook]{title}{#1} %title without ""
\DeclareFieldFormat[article]{title}{#1} %title without ""
\DeclareFieldFormat[article]{journaltitle}{#1} %journaltitle non-italic
\DeclareFieldFormat[online]{title}{#1} %title non-italic

\renewbibmacro*{publisher+location+date}{%
\printlist{location}%
\setunit{\addcomma\space}%
\printlist{publisher}%
\setunit*{\addcomma\space}%
\usebibmacro{date}%
\newunit}

\renewcommand{\labelnamepunct}{\addcolon\space}

\begin{document}
\parencite{heybook}
\parencite{heyinbook}
\parencite{heyarticle}
\parencite{heyonline}
\printbibliography[heading=bibintoc]
\end{document}

My sources.bib file with examples looks the following:

@book{heybook,
author    ={Simon Beck},
title     ={Buchtitel},
publisher ={Verlag},
location  ={Ort},
date      ={2011} }

@inbook{heyinbook,
bookauthor={Simonbook Beckbook},
author    ={Simoninbook Beckinbook},
booktitle ={Buchtitel},
title     ={Kapiteltitel},
publisher ={Verlag},
location  ={Ort},
pages     ={123-124},
date      ={2012} }

@article{heyarticle,
author   ={Simonarticle Beckarticle},
title    ={Artikeltitel},
journaltitle={Zeitschrift},
number   ={12},
series    ={Jahrgang},
pages    ={123-124},
date     ={2013} }

@online{heyonline,
author   ={Simononline Beckonline},
title    ={Onlinetitle},
url      ={http://pes.ee.ethz.ch},
urldate  ={2014-04-12},
date     ={2014} }

Best Answer

Okay, look at your updated MWE:

\documentclass[a4 paper,12pt]{article}
\usepackage[style=authoryear,dashed=false]{biblatex}
\usepackage[ngerman]{babel} 

\begin{filecontents}{mybib.bib}
@book{heybook,
author    ={Simon Beck},
title     ={Buchtitel},
publisher ={Verlag},
location  ={Ort},
date      ={2011} }

@inbook{heyinbook,
% bookauthor={Simonbook Beckbook},
author    ={Simoninbook Beckinbook},
editor    ={Fritz HerausgeberGuy and Frieda HerausgeberGirl},
booktitle ={Buchtitel},
title     ={Kapiteltitel},
publisher ={Verlag},
location  ={Ort},
pages     ={123-124},
date      ={2012} }

@article{heyarticle,
author   ={Simonarticle Beckarticle},
title    ={Artikeltitel},
journaltitle={Zeitschrift},
number   ={12},
series    ={Jahrgang},
pages    ={123-124},
date     ={2013} }

@online{heyonline,
author   ={Simononline Beckonline},
title    ={Onlinetitle},
url      ={http://pes.ee.ethz.ch},
urldate  ={2014-04-12},
date     ={2014} }
\end{filecontents}


\addbibresource{mybib.bib}
\DeclareFieldFormat[book]{title}{#1} %titel non-italic
\DeclareFieldFormat[inbook]{booktitle}{#1} %booktitle non-italic


%my code:
\DeclareFieldFormat[inbook]{title}{#1} %title without ""
\DeclareFieldFormat[article]{journaltitle}{#1} %non-italic
\DeclareFieldFormat[online]{title}{#1} %non-italic
\DeclareFieldFormat[article]{title}{#1} %titel unquoted

\renewcommand{\intitlepunct}{}%no ":" after "in"

\DefineBibliographyStrings{german}{%redefine strings
editor= {Hg},%if you want to add a dot, add \adddot 
editors = {Hgg}
}


\renewbibmacro*{editor+others}{%from biblatex.def, parencites around editor
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\printnames{editor}%
     \addspace%
     \mkbibparens{\usebibmacro{editor+othersstrg}}%add parens
     \clearname{editor}}
    {}}



\DeclareBibliographyDriver{inbook}{%from standard.bbx; macro "editor..." instead of "byeditor..."
  \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{bybookauthor}%
  \newunit\newblock
  \setunit{\addspace}\newblock%added
  \usebibmacro{editor+others}%added
  \setunit{\addcolon\addspace}%added
  \usebibmacro{maintitle+booktitle}%moved
  \setunit{\addcomma\addspace}\newblock%moved
  \usebibmacro{chapter+pages}%moved
  % \newunit\newblock
  % \usebibmacro{byeditor+others}%
  % \newunit\newblock
  % \printfield{edition}%maybe add again if needed
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publisher+location+date}%
  \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{article}{%from standard.bbx, removed macro "in:"
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  % \usebibmacro{in:}%
  \usebibmacro{journal+issuetitle}%
  \newunit
  \usebibmacro{byeditor+others}%
  \newunit
  \usebibmacro{note+pages}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{issn}}
    {}%
  \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}}   


 \newbibmacro*{journal+issuetitle}{%standard.bbx, rearranged, parencites
  \usebibmacro{journal}%
  \setunit*{\addcomma\addspace}%
  \printfield{number}%
  \setunit{\addspace}%
  %end
  \iffieldundef{series}
    {}
    {%\newunit
     \printfield[parens]{series}%
     % \setunit{\addspace}}%
     }  
  \setunit{\addspace}%
  \usebibmacro{issue+date}%
  \setunit{\addcolon\space}%
  \usebibmacro{issue}%
  \newunit}


\DeclareBibliographyDriver{online}{%arrange, deleted some macros
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \setunit{\addcomma\addspace}%modified
  \usebibmacro{url+urldate}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}}

\renewbibmacro*{url+urldate}{%from biblatex.def, rearranged
  \iffieldundef{urlyear}
    {}
    {\printurldate}
  \setunit{\addperiod\addspace}%added
  \printfield{url}%moved
}


%your code
\renewbibmacro*{publisher+location+date}{%
\printlist{location}%
\setunit{\addcomma\space}%
\printlist{publisher}%
\setunit*{\addcomma\space}%
\usebibmacro{date}%
\newunit}

\renewcommand{\labelnamepunct}{\addcolon\space}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

This is rather much code. There may be better ways to do what you want, but it gives you a start. I've commented the code; in some parts it may not be the best, and you have to modify it to your needs. A few notes:

  • You should use editor (Herausgeber) instead of bookauthor.
  • Your citation style is inconsistent, but that's not a LaTeX-problem...
  • If you want to cite an article out of a book, consider to put both in your bibtex-file and refer it in the article via crossref={key}. So you can seperate things better and don't have to write data again and again. For example booktitle, this will be automaticall inherited if you put in a title-field from a book-entry and use crossref in your article.
  • The updated MWE also includes the bibfile as a filecontent.


Output:

output

Related Question