Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to add a block at the beginning of my bib entries of the form

[Lastnameauthor(s) Year]

When the shortauthor field is defined it should use this field +Year instead. The following example is fairly minimal:

\begin{filecontents*}{test.bbx}
\ProvidesFile{test.bbx} 
[\abx@bbxid $Id: test.bbx,v 0.9d 2010/09/03 20:11:58 lehman beta $] 
\RequireBibliographyStyle{authoryear}

\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  %---add something here---
  \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}%
  \usebibmacro{finentry}}

\endinput
 \end{filecontents*}
\begin{filecontents*}{MeineBib.bib}
  @article{example,
 author={Firstname Lastname and First Last},
  title={Title},
 journal={Journal},
 year={Year},
  pages={Pages},
} 
  \end{filecontents*}

\documentclass[12pt,ngerman,    ]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{filecontents}
\usepackage[babel,german=quotes]{csquotes}
\usepackage [bibstyle=test]{biblatex}
\bibliography{MeineBib} 
\begin{document}
\tableofcontents
\cite{example}
\printbibliography\end{document}

I'm guessing the solution lies here

DeclareBibliographyDriver{article}{%
      \usebibmacro{bibindex}%
      \usebibmacro{begentry}%
      %---add something here---
      \usebibmacro{author/translator+others}%

but I can't find out how. It should look like this which is an existing style (natdin) in BibTeX, but not in biblatex.

share|improve this question
add comment

1 Answer 1

up vote 13 down vote accepted

Way back, I answered a very similar question at the German-speaking forum mrunix.de. The trick is to add \usebibmacro{cite} to the bibmacro begentry (which does nothing by default). Then choose the citestyle authoryear and the bibliography style authortitle, sort the bibliography by author-year-title, remove dashes for recurrent authors ... and you're set. ;-)

\documentclass{article}

\usepackage[citestyle=authoryear-comp,bibstyle=authortitle,sorting=nyt,dashed=false,%
    maxcitenames=1]{biblatex}

\newcounter{mymaxcitenames}
\AtBeginDocument{%
  \setcounter{mymaxcitenames}{\value{maxnames}}%
}

\renewbibmacro*{begentry}{%
  \printtext[brackets]{%
    \begingroup
    \defcounter{maxnames}{\value{mymaxcitenames}}%
    \printnames{labelname}%
    \setunit{\nameyeardelim}%
    \usebibmacro{cite:labelyear+extrayear}%
    \endgroup
    }%
  \quad% or \addspace
}

\DeclareNameAlias{sortname}{first-last}

\usepackage{filecontents}

\begin{filecontents}{biblatextest.bib}
@misc{A01,
  author = {Author, A. and Buthor, B.},
  year = {2001},
  title = {Alpha},
}
\end{filecontents}

\addbibresource{biblatextest.bib}

\begin{document}

Some text \autocite{A01}.

\printbibliography

\end{document}

enter image description here

EDIT: Improved redefinition of begentry to allow for cases where maxnames differs between in-text-citations and the bibliography. (\defcounter is an etoolbox macro that allows [in contrast to \setcounter] for local redefinitions of counter values.)

EDIT 2: Removed need to manually set custom counter.

EDIT 3: Changed format of author names to first-last.

EDIT 4: Replaced \usebibmacro{cite} with lower-level commands in order to make example also work with comp styles (which compress recurring author names in citations).

(In case anyone is wondering about these piecemeal enhancements: This question has become sort of a "Parallel Campaign" to another question at mrunix.de.)

share|improve this answer
    
@ lockstep: Thanks a lot! As it turns out, my thoughts were way tooo complicated... –  meep.meep Feb 23 '11 at 17:24
2  
Just to mention - I hope to implement user-definable labelapha in biber soon and so these labels will be customisable. –  PLK Jun 25 '11 at 8:20
2  
The \usebibmacro{cite:labelyear+extrayear}% should be replaced by \printfield{labelyear}% \printfield{extrayear}% for the entry not to be linked, since links doesnt make sence in the bibliography –  Skip Jan 20 '12 at 22:20
    
When trying this minimal example I get ! Package keyval Error: maxcitenames undefined. Is this a problem with the version of biblatex? –  pirad Mar 24 '12 at 8:44
1  
@pluton Add \renewbibmacro*{author}{}. –  lockstep Jan 25 '13 at 8:36
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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