# Custom bib style for entries containing editor

I am trying to achieve the following bibliography style for websites (@misc):

Editor (Hrsg.) (2015): Title, Location. Verfügbar unter: http://some.kind.of.url (letzter Zugriff: 05.09.2015).

And I would like to add a field "downloaded" to the bibliography to get bibliography entries for publicly available PDF files:

Editor (Hrsg.) (2015): Title, Location. Verfügbar unter: http://some.kind.of.url/file.pdf (Download am: 05.09.2015).

This is my example what I did so far:

\documentclass[12pt, oneside]{Thesis}
\usepackage[babel, german=quotes]{csquotes}
\usepackage[backend=biber,%
citestyle=authoryear-icomp,%
bibstyle=authoryear,%
dashed=false,%
sorting=nyvt,%
autocite=footnote,%
autopunct=true,%
backrefstyle=three+,%
isbn=false,%
doi=false,%
pagetracker=true,%
useprefix=true,%
uniquename=init,%
firstinits=true,%
maxcitenames=2,%
]{biblatex}
\setlength{\bibitemsep}{1em}
\setlength{\bibhang}{2em}
\setlength{\footnotesep}{0.6\baselineskip}
\renewcommand{\mkcitation}[1]{\space#1}
\renewcommand{\mkblockquote}[4]{\singlespace\emph{#1}#2#4#3}
\urlstyle{same}
\DeclareNameAlias{author}{last-first}
\DeclareNameAlias{labelname}{last-first}
\DeclareFieldFormat{title}{#1}
\DefineBibliographyStrings{ngerman}{urlseen = letzter Zugriff\addcolon}
\DeclareFieldFormat[article]{title}{#1}
\DeclareFieldFormat{journaltitle}{#1}
\DefineBibliographyStrings{ngerman}{
}
\renewbibmacro*{editor+others}{
\ifboolexpr{
test \ifuseeditor
and
not test {\ifnameundef{editor}}
}
{
\printnames{editor}%
\setunit{\space}%
\clearname{editor}
\usebibmacro{date+extrayear}
}
{

}
}

\begin{document}
Some Text\blockquote[{\autocite[][]{WwwSource.2015}}]{with citation}{}.
\end{document}


This is my .bib entry for the first:

@misc{WwwSource.2015,
editor = {{Editor}},
year = {{2015}},
title = {Title},
url = {http://some.kind.of.url},
keywords = {Quelle},
urldate = {2015-09-05},
}


This is my .bib entry for the second:

@misc{WwwSource.2015,
editor = {{Editor}},
year = {{2015}},
title = {Title},
url = {http://some.kind.of.url/file.pdf},
keywords = {Quelle},
urldate = {2015-09-05},
}


The problem I am currently encountering is that with the redefinition of the macro editor+others in my bibliography the entries containing an editor are indented:

For the second part with the download date I don't have an idea how to do that.

Any help appreciated.

Thanks a lot in advance.

• BTW: I don't think it is good style to add the parentheses manually to \DefineBibliographyStrings{ngerman}, you can achieve the same output by \DeclareFieldFormat{editortype}{\mkbibparens{#1}}. – moewe Sep 5 '15 at 13:17
• Your \renewbibmacro*{editor+others} has the potential to cause lots of unwanted space. Read What is the use of percent signs (%) at the end of lines? – moewe Sep 5 '15 at 13:18
• You should also not change the labelname format if you don't know exactly what you are doing, it can destroy a lot - why did you change the format? – moewe Sep 5 '15 at 13:22
• Changed to \DeclareFieldFormat{editortype}{\mkbibparens{#1}} - thanks for that. – Grodon Sep 5 '15 at 13:26
• If I get you right, I should either add % at the end of every line in my \renewbibmacro*{editor+others} or put everything in one line, correct? – Grodon Sep 5 '15 at 13:28

Since we decided to use a keyword to decide whether to display "letzter Zugriff" or "Download am" the entire thing is not too complicated. We will also get to know a way to do this with the options field, instead of the old keywords.

Firstly, we need to define a new bibliography string

\NewBibliographyString{downloadon}


Then, we define the strings so they say the right things

\DefineBibliographyStrings{german}{%
urlfrom    = {verfügbar unter},
urlseen    = {letzter Zugriff},
}


Then we change the formats of the url and urldate fields to use the new strings, with keywords we need

\DeclareFieldFormat{url}{\bibstring{urlfrom}\addcolon\space\url{#1}}
\DeclareFieldFormat{urldate}{%
\mkbibparens{%
\ifkeyword{pdf}
{\bibstring{urlseen}}%


The urldate shows a different bibstring depending on whether the keyword pdf is present or not.

Alternatively, we can use options supplied to the entries. We then need

\newtoggle{blx:pdf}
\DeclareEntryOption{pdf}[true]{%
\settoggle{blx:pdf}{#1}}

\DeclareFieldFormat{urldate}{%
\mkbibparens{%
\iftoggle{blx:pdf}
{\bibstring{urlseen}}%


And you need to add options = {pdf}, to the bib entry instead of adding the keyword pdf.

We can even automate this process a bit such that all URLs that end in .pdf automatically trigger the pdf=true option via

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\step[fieldsource=url, match=\regexp{\.pdf\Z}, final]
\step[fieldset=options, append, fieldvalue={,pdf=true}]
}
}
}


MWE

\documentclass[ngerman]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber, style=authoryear-icomp,%
dashed=false,%
sorting=nyvt,%
autocite=footnote,%
autopunct=true,%
backrefstyle=three+,%
isbn=false,%
doi=false,%
pagetracker=true,%
useprefix=true,%
uniquename=init,%
firstinits=true,%
maxcitenames=2,%
]{biblatex}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@misc{WwwSource.2015,
editor    = {Ellen Ditor},
year      = {2015},
title     = {A Real PDF},
url       = {http://example.edu/file.pdf},
keywords  = {Quelle},
options   = {pdf},
urldate   = {2015-09-05},
}
@misc{WwwSource.2016,
editor   = {Ellen Ditor},
year     = {2016},
title    = {Just Any Old Website},
url      = {http://example.com},
keywords = {Quelle},
urldate  = {2015-09-05},
}
\end{filecontents*}

\renewcommand{\mkcitation}[1]{\space#1}
\renewcommand{\mkblockquote}[4]{\singlespace\emph{#1}#2#4#3}
\urlstyle{same}

\renewcommand*{\finalnamedelim}{\multinamedelim}

\DeclareNameAlias{sortname}{last-first}
\DeclareNameAlias{labelname}{last-first}
\DeclareFieldFormat{editortype}{\mkbibparens{#1}}
\DeclareFieldFormat{title}{#1}
\DeclareFieldFormat[article]{title}{#1}
\DeclareFieldFormat{journaltitle}{#1}

\DefineBibliographyStrings{german}{%
urlfrom    = {verfügbar unter},
urlseen    = {letzter Zugriff},
}

\newtoggle{blx:pdf}
\DeclareEntryOption{pdf}[true]{%
\settoggle{blx:pdf}{#1}}

\DeclareFieldFormat{urldate}{%
\mkbibparens{%
\iftoggle{blx:pdf}
{\bibstring{urlseen}}%

\makeatletter
\renewbibmacro*{bbx:editor}[1]{%
\ifboolexpr{
test \ifuseeditor
and
not test {\ifnameundef{editor}}
}
{\usebibmacro{bbx:dashcheck}
{\bibnamedash}
{\printnames{editor}%
\usebibmacro{bbx:savehash}}%
\usebibmacro{#1}%
\clearname{editor}%
{\global\undef\bbx@lasthash
\usebibmacro{labeltitle}%

• If you want to format all titles plain, then \DeclareFieldFormat*{title}{#1} should do it without having to issue a \DeclareFieldFormat[article]{title}{#1}. You will also notice that I did not change the author format, but the sortname format, this will give more uniform results in the bibliography if you add a second editor. – moewe Sep 5 '15 at 14:16