Due to some university requirements, I redefined the biblatex
citesytle
authoryear to use square brackets instead of round parentheses. Now I am trying to achieve the same for the bibstyle
.
My approach to this is to redefine the original style file, authoryear.bbx
. This worked fine for the citestyle
, which I am not repeating here because the styles work very differently.
Reading the manual [ 1 ], I found out that (round) parentheses are put around fields using the command \printtext[parens]{....}
. Here, the field parens
is defined as \DeclareFieldFormat{parens}{\mkbibparens{#1}}
[1, p. 268]. In analogy to this, I tried to define a new field bracks
like so: \DeclareFieldFormat{bracks}{\mkbibbrackets{#1}}
(see [1, p. 250]).
My approach is now to replace the field parens
by bracks
everywhere in the associated style file, see the MWE below:
\documentclass{scrartcl}
\usepackage{filecontents}
\begin{filecontents*}{authoryearbrak.bbx}
\ProvidesFile{authoryearbrak.bbx}
[\abx@bbxid]
% authoryear styles are special in the following way:
% The citation labels are "labelname (labelyear)" and since citation
% labels are the keys into the references section, the fact that the
% citation uses labelyear means that the references must also. This
% means we use a special \printdate[extra]label macro to generate the
% references section main date for an entry. Otherwise, if labeldate selects
% anything other than DATE (or equivalently, YEAR/MONTH), then the
% citation won't match the reference.
% Addition!
% Add new field for square brackets
\DeclareFieldFormat{bracks}{\mkbibbrackets{#1}}
\RequireBibliographyStyle{standard}
\DeclareBibliographyOption{dashed}[true]{%
\ifstrequal{#1}{true}
{\ExecuteBibliographyOptions{pagetracker}%
\renewbibmacro*{bbx:savehash}{\savefield{fullhash}{\bbx@lasthash}}}
{\renewbibmacro*{bbx:savehash}{}}}
\DeclareBibliographyOption{mergedate}[true]{%
\ifcsdef{bbx@opt@mergedate@#1}
{\csuse{bbx@opt@mergedate@#1}}
{\PackageError{biblatex}
{Invalid option 'mergedate=#1'}
{Valid values are 'maximum', 'compact', 'basic', 'minimum',\MessageBreak
'true' (=compact), and 'false'.}}}
\providebibmacro*{date+extrayear}{}
\def\bbx@opt@mergedate@true{\bbx@opt@mergedate@compact}
\def\bbx@opt@mergedate@maximum{%
\renewbibmacro*{date+extrayear}{%
\iffieldundef{labelyear}
{}
{\printtext[bracks]{%
\printfield{issue}%
\setunit*{\addspace}%
\printdateextralabel}}}%
\renewbibmacro*{date}{}%
\renewbibmacro*{issue+date}{}%
}
\def\bbx@opt@mergedate@compact{%
\renewbibmacro*{date+extrayear}{%
\iffieldundef{labelyear}
{}
{\printtext[s]{\printdateextralabel}}}%
\renewbibmacro*{date}{}%
\renewbibmacro*{issue+date}{%
\iffieldundef{issue}
{}
{\printtext[bracks]{\printfield{issue}}}%
\newunit}%
}
\def\bbx@opt@mergedate@basic{%
\renewbibmacro*{date+extrayear}{%
\iffieldundef{labelyear}
{}
{\printtext[bracks]{%
\printfield{labelyear}%
\printfield{extrayear}}}}%
\renewbibmacro*{date}{%
\iffieldundef{month}
{}
{\printdate}}%
\renewbibmacro*{issue+date}{%
\ifboolexpr{
test {\iffieldundef{issue}}
and
test {\iffieldundef{month}}
}
{}
{\printtext[bracks]{%
\printfield{issue}%
\setunit*{\addspace}%
\printdate}}%
\newunit}%
}
\def\bbx@opt@mergedate@minimum{%
\renewbibmacro*{date+extrayear}{%
\iffieldundef{labelyear}
{}
{\printtext[bracks]{%
\printfield{labelyear}%
\printfield{extrayear}}}}%
\renewbibmacro*{date}{%
\ifboolexpr{
test {\iffieldundef{month}}
and
test {\iffieldundef{extrayear}}
}
{}
{\printdate}}%
\renewbibmacro*{issue+date}{%
\ifboolexpr{
test {\iffieldundef{issue}}
and
test {\iffieldundef{month}}
and
test {\iffieldundef{extrayear}}
}
{}
{\printtext[bracks]{%
\printfield{issue}%
\setunit*{\addspace}%
\printdate}}%
\newunit}%
}
\def\bbx@opt@mergedate@false{%
\renewbibmacro*{date+extrayear}{%
\iffieldundef{labelyear}
{}
{\printtext[bracks]{%
\printfield{labelyear}%
\printfield{extrayear}}}}%
\renewbibmacro*{date}{\printdate}%
\renewbibmacro*{issue+date}{%
\printtext[bracks]{%
\printfield{issue}%
\setunit*{\addspace}%
\printdate}%
\newunit}%
}
\ExecuteBibliographyOptions{labeldate,sorting=nyt,pagetracker,mergedate}
\DeclareFieldFormat{shorthandwidth}{#1}
\setlength{\bibitemsep}{0pt}
\DeclareNameAlias{author}{sortname}
\DeclareNameAlias{editor}{sortname}
\DeclareNameAlias{translator}{sortname}
\defbibenvironment{bibliography}
{\list
{}
{\setlength{\leftmargin}{\bibhang}%
\setlength{\itemindent}{-\leftmargin}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}
{\endlist}
{\item}
\defbibenvironment{shorthands}
{\list
{\printfield[shorthandwidth]{shorthand}}
{\setlength{\labelwidth}{\shorthandwidth}%
\setlength{\leftmargin}{\labelwidth}%
\setlength{\labelsep}{\biblabelsep}%
\addtolength{\leftmargin}{\labelsep}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}%
\renewcommand*{\makelabel}[1]{##1\hss}}}
{\endlist}
{\item}
\InitializeBibliographyStyle{%
\global\undef\bbx@lasthash}
\newbibmacro*{bbx:savehash}{%
\savefield{fullhash}{\bbx@lasthash}}
\newbool{bbx@inset}
\DeclareBibliographyDriver{set}{%
\booltrue{bbx@inset}%
\entryset{}{}%
\newunit\newblock
\usebibmacro{setpageref}%
\finentry}
\renewbibmacro*{author}{%
\ifboolexpr{
test \ifuseauthor
and
not test {\ifnameundef{author}}
}
{\usebibmacro{bbx:dashcheck}
{\bibnamedash}
{\usebibmacro{bbx:savehash}%
\printnames{author}%
\iffieldundef{authortype}
{\setunit{\addspace}}
{\setunit{\addcomma\space}}}%
\iffieldundef{authortype}
{}
{\usebibmacro{authorstrg}%
\setunit{\addspace}}}%
{\global\undef\bbx@lasthash
\usebibmacro{labeltitle}%
\setunit*{\addspace}}%
\usebibmacro{date+extrayear}}
\renewbibmacro*{editor}{%
\usebibmacro{bbx:editor}{editorstrg}}
\renewbibmacro*{editor+others}{%
\usebibmacro{bbx:editor}{editor+othersstrg}}
\newbibmacro*{bbx:editor}[1]{%
\ifboolexpr{
test \ifuseeditor
and
not test {\ifnameundef{editor}}
}
{\usebibmacro{bbx:dashcheck}
{\bibnamedash}
{\printnames{editor}%
\setunit{\addcomma\space}%
\usebibmacro{bbx:savehash}}%
\usebibmacro{#1}%
\clearname{editor}%
\setunit{\addspace}}%
{\global\undef\bbx@lasthash
\usebibmacro{labeltitle}%
\setunit*{\addspace}}%
\usebibmacro{date+extrayear}}
\renewbibmacro*{translator}{%
\usebibmacro{bbx:translator}{translatorstrg}}
\renewbibmacro*{translator+others}{%
\usebibmacro{bbx:translator}{translator+othersstrg}}
\newbibmacro*{bbx:translator}[1]{%
\ifboolexpr{
test \ifusetranslator
and
not test {\ifnameundef{translator}}
}
{\usebibmacro{bbx:dashcheck}
{\bibnamedash}
{\printnames{translator}%
\setunit{\addcomma\space}%
\usebibmacro{bbx:savehash}}%
\usebibmacro{translator+othersstrg}%
\clearname{translator}%
\setunit{\addspace}}%
{\global\undef\bbx@lasthash
\usebibmacro{labeltitle}%
\setunit*{\addspace}}%
\usebibmacro{date+extrayear}}
\newbibmacro*{bbx:dashcheck}[2]{%
\ifboolexpr{
test {\iffieldequals{fullhash}{\bbx@lasthash}}
and
not test \iffirstonpage
and
(
not bool {bbx@inset}
or
test {\iffieldequalstr{entrysetcount}{1}}
)
}
{#1}
{#2}}
\newbibmacro*{labeltitle}{%
\iffieldundef{label}
{\iffieldundef{shorttitle}
{\printfield{title}%
\clearfield{title}}
{\printfield[title]{shorttitle}}}
{\printfield{label}}}
\endinput
\end{filecontents*}
\begin{filecontents*}{bibliography.bib}
@BOOK{Cornelisse1979,
author = {Cornelisse, J. W. and Schöyer, H. Ferry R. and Wakker, Karel F.},
title = {Rocket Propulsion and Spaceflight Dynamics},
year = {1979},
publisher = {Pitman},
}
\end{filecontents*}
\usepackage[bibstyle=authoryearbrak, citestyle=authoryear,%
backend=biber,]{biblatex}
\addbibresource{bibliography.bib}
\begin{document}
\autocite{Cornelisse1979}
\printbibliography
\end{document}
Sadly, this does not work, as the following screenshot demonstrates:
The brackets are missing altogether. It should say [1979]. For the default authoryear
style it would say (1979).
Where is this going wrong? How can I fix this, in order to get square brackets instead of round parentheses around the year?
[ 1 ] — http://archive.cs.uu.nl/mirror/CTAN/macros/latex/contrib/biblatex/doc/biblatex.pdf
Rationale for square brackets: Parenthesis typically indicate small additions or afterthoughts. Citations, however, are something entirely different, and thus deserve a special notation. This is also consistent with the pure numbering style that is sometimes used, e.g. [23] to indicate reference 23.
Best Answer
There is already a field format defined for square brackets - it is called
brackets
.In
authoryear
styles, theyear
part of the label is created by the macro\printdateextralabel
. In yourauthoryearbrak
, you have have a spurious[s]
format for\printdatextralabel
(line 59). Replacing that with[brackets]
yieldsDoes this answer the question ?