Biblatex, author-year, square brackets

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


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

(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}