Ampersand as namessep in biblatex label

Hide the ampersand in a command (& is not good enough because the command name contains an ampersand, which still throws the XML off) and use detokenize to make sure the macro does not get expanded when it is written to the .bcf.

detokenize can often be a cheap work-around if biblatex options that may contain printable data explode. Often that happens because the value of the option needs to be written to the .bcf file, so Biber can consume its value. LaTeX usually performs full expansion when text is written to a file, so things may go wrong if the desired value is not expandable or (as in this case) expands to problematic text. detokenize stops this unwanted expansion. When the value is then picked up from the .bbl file, the tokens will be interpreted as usual and the output will be as expected.

The quoted passage on page 205 of the manual only applies to padchar and literal, the value of namessep needs escaping for special characters in both LaTeX and XML.

documentclass{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{csquotes}

usepackage[backend=biber,style=alphabetic,maxcitenames=2,mincitenames=2,giveninits=true,isbn=false,]{biblatex}

renewcommand*{labelalphaothers}{textsuperscript{+}}
newcommand*{ampersand}{&}

DeclareLabelalphaTemplate{
  labelelement{
    field[final]{shorthand}
    field{label}
    field[names=2, namessep=detokenize{addspaceampersandspace}]{labelname}
  }
  labelelement{
    literal{addspace}
  }
  labelelement{
    field[strside=right,strwidth=2]{year}
  }
}

addbibresource{biblatex-examples.bib}

begin{document}
cite{companion,sigfridsson,worman}

printbibliography
end{document}

Goossens & Mittelbach + 94; Sigfridsson & Ryde 98; Worman 02


I’m not a big fan of abusing alphabetic to obtain what is essentially a full-blown author-year style with square brackets and the labels in the bibliography, but because it is a bit tricky to get only the last two digits of the year and retain uniqueness features I can’t offer a simple implementation of the exact same style with style=authoryear, but

documentclass{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{csquotes}

usepackage[backend=biber,style=ext-authoryear,
  introcite=label,
  autocite=inline,
  maxcitenames=2,mincitenames=1,giveninits=true,uniquename=init,
  isbn=false]{biblatex}

DeclareOuterCiteDelims{parencite}{bibopenbracket}{bibclosebracket}

DeclareFieldFormat{[email protected]}{mkbibbrackets{#1}}


DeclareDelimFormat{finalnamedelim}{addspace&space}
DeclareDelimFormat[bib]{finalnamedelim}{%
  ifnumgreater{value{liststop}}{2}{finalandcomma}{}%
  addspacebibstring{and}space}

addbibresource{biblatex-examples.bib}

begin{document}
autocite{companion,sigfridsson,worman}

printbibliography
end{document}

could be a start.

The bibliography shows the citation labels, the space allocated for the labels is fixed, longer labels produce a line break to let the bibliography entry start on the next line

The ‘two-column’ layout of the alphabetic style that automatically allocates enough space for each label to not run into the entry data may seem preferable, but if you cite a work by Helena Bonham Carter and Ralph Vaughn Williams, you will soon notice that the space left for the actual entry data becomes painfully narrow and does not allow for good line breaks any more.

newcommand*{ambr}{&} didn’t work for me. newrobustcmd{ambr}{&} worked.

documentclass{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{csquotes}
usepackage{filecontents}
usepackage[
backend=biber,
style=alphabetic,
citestyle=alphabetic,
maxcitenames=2,
mincitenames=2,
giveninits=true,
isbn=false,
]{biblatex}

begin{filecontents*}{references.bib}
@article{einstein,
  author =       "Albert Einstein and Second Author",
  title =        "{Zur Elektrodynamik bewegter K{"o}rper}. ({German})
                 [{On} the electrodynamics of moving bodies]",
  journal =      "Annalen der Physik",
  volume =       "322",
  number =       "10",
  pages =        "891--921",
  year =         "1905",
  DOI =          "http://dx.doi.org/10.1002/andp.19053221004",
  keywords =     "physics"
}

@book{dirac,
  title={The Principles of Quantum Mechanics},
  author={Paul Adrien Maurice Dirac},
  isbn={9780198520115},
  series={International series of monographs on physics},
  year={1981},
  publisher={Clarendon Press},
  keywords = {physics}
}

@book{latexcompanion,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts",
    keywords  = "latex"
}
end{filecontents*}



renewcommand*{labelalphaothers}{${}^+$}
%newcommand*{ambr}{&}
newrobustcmd{ambr}{&}
DeclareLabelalphaTemplate{
  labelelement{
    field[final]{shorthand}
    field{label}
    field[names=2, namessep={addspaceambraddspace}]{labelname}
  }
  labelelement{
    literal{addspace}
  }
  labelelement{
    field[strside=right,strwidth=2]{year}
  }
}

addbibresource{references.bib}

begin{document}
section{First section}

Items that are cited: textit{The LaTeX Companion} book cite{latexcompanion}, The Einstein's journal paper cite{einstein} and the Dirac's book cite{dirac} are physics related items. Next, a citation about textit{The LaTeX Companion} book cite{latexcompanion}.

medskip

printbibliography
end{document}

enter image description here

Leave a Comment