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 need to customize the author-year citation in biblatex for a template at work. Right now biblatex cites like this:

Ruschmeyer u. a. 1995, S. 123

They way I was told it needs to cite is:

[Ruschmeyer u. a. 1995, S. 123]

This seems pretty simple and I thought it would be done in a second, but after reading through the biblatex documentation for the second time, I still don't really have a clue.

share|improve this question
add comment

3 Answers

up vote 20 down vote accepted

An alternative to lockstep's solution is to redefine the high-level parentheses commands. With the default option setting parentracker=true, these are context-sensitive; nested parentheses may be set as brackets, depending on the nesting level.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear]{biblatex}

%\ExecuteBibliographyOptions{parentracker=false}

\makeatletter

\newrobustcmd*{\parentexttrack}[1]{%
  \begingroup
  \blx@blxinit
  \blx@setsfcodes
  \blx@bibopenparen#1\blx@bibcloseparen
  \endgroup}

\AtEveryCite{%
  \let\parentext=\parentexttrack%
  \let\bibopenparen=\bibopenbracket%
  \let\bibcloseparen=\bibclosebracket}

\makeatother

\addbibresource{biblatex-examples.bib}
\begin{document}
\null\vfill\noindent
Filler text \parencite[see][59--63]{markey}. \\
Filler text \parencite[see][\pno~59 \parentext{last paragraph}]{markey}. \\
Filler text \parencite[see][\pno~59 \brackettext{last paragraph}]{markey}. \\
\parentext{Filler text \parencite[see][\pno~59 \parentext{last paragraph}]{markey}.} \\
\brackettext{Filler text \parencite[see][\pno~59 \parentext{last paragraph}]{markey}.} \\
\citeauthor{markey} show that this is filler text \parencite*{markey}. \\
\textcite[see][\pno~59 \parentext{last paragraph}]{markey} show that this is filler text. \\
Filler text \autocite{markey}. \\
\citeauthor{markey} show that this is filler text \autocite*{markey}. \\
Filler text.\smartcite[\pno~59 \brackettext{last paragraph}]{markey}
Filler text.\footnote{More filler text \smartcite[see][\pno~59 \brackettext{last paragraph}]{markey}.} \\
\parencites{markey,knuth:ct:b} \\
\textcites{markey,knuth:ct:b} \\
\printbibliography
\end{document}

enter image description here

share|improve this answer
1  
+1 for \ifcitation. This answer should become the accepted one. –  lockstep Apr 27 '11 at 22:11
    
thanks so much! –  Tim Apr 28 '11 at 16:07
    
And how do I get a bibliography in table style (the names in brackets on the left hand side and the informations about the references on the right hand side? –  pirad Mar 23 '12 at 12:51
    
@pirad This post might help. If that isn't what you had in mind, feel free to post a new question. –  Audrey Mar 23 '12 at 14:46
    
+1 for the nice solution. Still, I thought 'just' adding some brackets would not be so complicated with the newer biblatex... –  Alexander May 11 '12 at 16:17
show 1 more comment

(I suspect that a better solution will turn up.)

\documentclass{article}

\usepackage[style=authoryear]{biblatex}

\renewbibmacro*{textcite}{%
  \ifnameundef{labelname}
    {\iffieldundef{shorthand}
       {\usebibmacro{cite:label}%
    \setunit{%
      \global\booltrue{cbx:parens}%
      \addspace\bibopenbracket}%
    \ifnumequal{\value{citecount}}{1}
      {\usebibmacro{prenote}}
      {}%
    \usebibmacro{cite:labelyear+extrayear}}
       {\usebibmacro{cite:shorthand}}}
    {\printnames{labelname}%
     \setunit{%
       \global\booltrue{cbx:parens}%
       \addspace\bibopenbracket}%
     \ifnumequal{\value{citecount}}{1}
       {\usebibmacro{prenote}}
       {}%
     \usebibmacro{citeyear}}}

\renewbibmacro*{textcite:postnote}{%
  \iffieldundef{postnote}
    {\ifbool{cbx:parens}
       {\bibclosebracket}
       {}}
    {\ifbool{cbx:parens}
       {\setunit{\postnotedelim}}
       {\setunit{\addspace\bibopenbracket}}%
     \printfield{postnote}\bibclosebracket}}

\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {\ifbool{cbx:parens}
     {\bibclosebracket\global\boolfalse{cbx:parens}}
     {}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}

\DeclareCiteCommand{\parencite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\parencite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citeyear}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\smartcite}[\iffootnote\mkbibbrackets\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\usepackage{filecontents}

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

\addbibresource{\jobname.bib}

\begin{document}

\textcite{A01}

\parencite{A01}

\autocite{A01}

\printbibliography

\end{document}
share|improve this answer
add comment

First, if you want brackets or parentheses, you should use \parencite{}, instead of \cite{}.

By default, this will produce round parentheses () in the author-year citation style. If you want square brackets [] instead, you can create your own .cbx file, and the easiest way is to modify an existing one. I provide an example at the end of the post.

(Note: Audrey's solution is simpler than this one, but it did not work when I tried it. This solution worked for me.)

Save the modified cbx file in your working directory as authoryearbrack.cbx, and then in your .tex file use:

\usepackage[bibstyle=authoryear,citestyle=authoryearbrak]{biblatex}

instead of

\usepackage[style=authoryear]{biblatex}

That should do it. If you are interested in creating your own .cbx files more generally, read on.

In a standard TeX Live distribution, with biblatex installed, you should find all the default biblatex .cbx files under texmf-dist/tex/latex/biblatex/cbx. For example, authoryear.cbx is for the basic author-year citation style, and you'll also find authoryear-comp.cbx, authoryear-ibid.cbx, etc.

In order to produce the file below, I started with authoryear.cbx and did just two things:

  1. Changed every occurrence of \mkbibparens to \mkbibbrackets, and
  2. Changed the comments and ProvidesFile lines at the top of the file to reflect the new file name.

Here is the modified version of authoryear.cbx which uses brackets instead of parentheses, and which you should save as authoryearbrack.cbx:

% $Id: authoryearbrack.cbx,v 1 anon $

\ProvidesFile{authoryearbrack.cbx}
[\abx@cbxid $Id: authoryearbrack.cbx,v 1 anon $]

\ExecuteBibliographyOptions{labelyear,uniquename,uniquelist,autocite=inline}
\newbool{cbx:parens}

\newbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\addspace}}
       {\printnames{labelname}%
        \setunit{\nameyeardelim}}%
     \usebibmacro{cite:labelyear+extrayear}}
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{citeyear}{%
  \iffieldundef{shorthand}
    {\iffieldundef{labelyear}
       {\usebibmacro{cite:label}}
       {\usebibmacro{cite:labelyear+extrayear}}}
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{textcite}{%
  \ifnameundef{labelname}
    {\iffieldundef{shorthand}
       {\usebibmacro{cite:label}%
    \setunit{%
      \global\booltrue{cbx:parens}%
      \addspace\bibopenparen}%
    \ifnumequal{\value{citecount}}{1}
      {\usebibmacro{prenote}}
      {}%
    \usebibmacro{cite:labelyear+extrayear}}
       {\usebibmacro{cite:shorthand}}}
    {\printnames{labelname}%
     \setunit{%
       \global\booltrue{cbx:parens}%
       \addspace\bibopenparen}%
     \ifnumequal{\value{citecount}}{1}
       {\usebibmacro{prenote}}
       {}%
     \usebibmacro{citeyear}}}

\newbibmacro*{cite:shorthand}{%
  \printtext[bibhyperref]{\printfield{shorthand}}}

\newbibmacro*{cite:label}{%
  \iffieldundef{label}
    {\printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}
    {\printtext[bibhyperref]{\printfield{label}}}}

\newbibmacro*{cite:labelyear+extrayear}{%
  \iffieldundef{labelyear}
    {}
    {\printtext[bibhyperref]{%
       \printfield{labelyear}%
       \printfield{extrayear}}}}

\newbibmacro*{textcite:postnote}{%
  \iffieldundef{postnote}
    {\ifbool{cbx:parens}
       {\bibcloseparen}
       {}}
    {\ifbool{cbx:parens}
       {\setunit{\postnotedelim}}
       {\setunit{\addspace\bibopenparen}}%
     \printfield{postnote}\bibcloseparen}}

\DeclareCiteCommand{\cite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\cite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citeyear}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\parencite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\parencite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citeyear}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcite}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\smartcite}[\iffootnote\mkbibbrackets\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {\ifbool{cbx:parens}
     {\bibcloseparen\global\boolfalse{cbx:parens}}
     {}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}

\endinput
share|improve this answer
1  
What exactly "did not work" in Audrey's solution? –  lockstep Dec 26 '11 at 23:59
2  
Taking a closer look at your solution, a) \bibopenparen/ \bibcloseparen should be replaced with \bibopenbracket/\bibclosebracket b) the result will closely mirror my answer. ;-) That said, welcome to tex.sx! –  lockstep Dec 27 '11 at 0:10
    
@Steve Did the problem relate to parenthesis tracking? If not, could you elaborate? –  Audrey Dec 27 '11 at 6:03
add comment

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.