3

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} 
\addbibresource{Bibliography.bib}                       
\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}
\renewcommand*{\nameyeardelim}{\addcomma\space}
\renewcommand*{\labelnamepunct}{\addcolon\space}
\renewcommand{\multinamedelim}{\addsemicolon\space}
\renewcommand{\finalnamedelim}{\addsemicolon\space}
\DeclareNameAlias{author}{last-first}
\DeclareNameAlias{labelname}{last-first}
\DeclareFieldFormat{title}{#1}
\DeclareFieldFormat{url}{verf{\"u}gbar unter\addcolon\space\url{#1}}
\DefineBibliographyStrings{ngerman}{urlseen = letzter Zugriff\addcolon}
\DeclareFieldFormat[article]{title}{#1}
\DeclareFieldFormat{journaltitle}{#1}
\renewcommand{\bibfootnotewrapper}[1]{\bibsentence#1\addspace}
\DefineBibliographyStrings{ngerman}{
    editor = {(Hrsg\adddot)},
    editors={(Hrsg\adddot)}
}
\renewbibmacro*{editor+others}{
    \ifboolexpr{
        test \ifuseeditor
        and
        not test {\ifnameundef{editor}}
    }
    {
        \printnames{editor}%
        \setunit{\space}%
        \usebibmacro{editor+othersstrg}%
        \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},
 address = {Location},
 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},
 address = {Location},
 urldate = {2015-09-05},
 downloaded = {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: enter image description here

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.

lockstep
  • 250,273
Wrstkpp
  • 327
  • 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 05 '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 05 '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 05 '15 at 13:22
  • Changed to \DeclareFieldFormat{editortype}{\mkbibparens{#1}} - thanks for that. – Wrstkpp Sep 05 '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? – Wrstkpp Sep 05 '15 at 13:28
  • More or less. Should I answer, I will include the code in a form I find visually pleasing and not causing any spurious white space. – moewe Sep 05 '15 at 13:30
  • If downloadedis set "Download am" should be displayed. Otherwise "letzter Zugriff". – Wrstkpp Sep 05 '15 at 13:30
  • No specific reason why I double-braced the year - maybe Citavi did this. – Wrstkpp Sep 05 '15 at 13:31
  • While we are at it (this fills up rather fast with all the short messages) I don't quite get your \mkcitation, why do you add \space? – moewe Sep 05 '15 at 13:31
  • The thing with downloaded will require quite a lot of machinery (a sneak peak if you are interested can be found here), though I believe it can be done. Can't you think of an easier way (maybe some kind of keyword you set) that involves using only the urldate field? – moewe Sep 05 '15 at 13:34
  • I canged labelname to achieve a "lastname, initial of firstname" in footnotes as well as in the bibliography. – Wrstkpp Sep 05 '15 at 13:34
  • \mkcitation was changed due to this discussion (http://tex.stackexchange.com/questions/261006/getting-rid-of-round-brackets-around-superscript) and your answer ... ;-) – Wrstkpp Sep 05 '15 at 13:36
  • Since the date I downloaded a PDF should be the same as the one I visited it the last time, a keyword should be absolutely fine. – Wrstkpp Sep 05 '15 at 13:37
  • Oh, you should never trust me ;-) (did you see the updated question and the discussion in the comments?). Using a keyword will make thinks much easier I hope, let me think of a good solution. – moewe Sep 05 '15 at 13:39

1 Answers1

4

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},
  downloadon = {Download am},
}

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{downloadon}}
      {\bibstring{urlseen}}%
    \addcolon\space#1}}

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{url}{\bibstring{urlfrom}\addcolon\space\url{#1}}
\DeclareFieldFormat{urldate}{%
  \mkbibparens{%
    \iftoggle{blx:pdf}
      {\bibstring{downloadon}}
      {\bibstring{urlseen}}%
    \addcolon\space#1}}

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},
 address   = {Location},
 urldate   = {2015-09-05},
}
@misc{WwwSource.2016,
 editor   = {Ellen Ditor},
 year     = {2016},
 title    = {Just Any Old Website},
 url      = {http://example.com},
 keywords = {Quelle},
 address  = {Location},
 urldate  = {2015-09-05},
}
\end{filecontents*}
\addbibresource{\jobname.bib}   

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

\renewcommand*{\bibfootnotewrapper}[1]{\bibsentence#1\addspace}

\renewcommand*{\nameyeardelim}{\addcomma\space}
\renewcommand*{\labelnamepunct}{\addcolon\space}
\renewcommand*{\multinamedelim}{\addsemicolon\space}
\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}


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

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

\DeclareFieldFormat{url}{\bibstring{urlfrom}\addcolon\space\url{#1}}
\DeclareFieldFormat{urldate}{%
  \mkbibparens{%
    \iftoggle{blx:pdf}
      {\bibstring{downloadon}}
      {\bibstring{urlseen}}%
    \addcolon\space#1}}



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

\begin{document}
Some Text \autocite{WwwSource.2015,WwwSource.2016}

\printbibliography
\end{document}

enter image description here

moewe
  • 175,683
  • 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 05 '15 at 14:16
  • Awesome! Thanks a lot! This works like a charm! – Wrstkpp Sep 06 '15 at 10:04