Ampersand as namessep in biblatex label
up vote
9
down vote
favorite
I am trying to change the way that labels are generated. Some of it I already got working (only at maximum two authors, only last two digits of the year), but one thing does not seem to work, which is putting an ampersand between the authors if there are at least two.
In the manual on page 205 it is explained, that one can use special characters without escaping them as literals or padding, but what about the namessep field?
In the MWE I used 'X' in the place where an '&' should be placed, but I do not know how to do it.
I suspect, that since it is converted into the .bcf
file, which is XML, that the ampersand makes troubles there, so is this a bug?
Here is a MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{csquotes}
usepackage{filecontents}
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*}
usepackage[
backend=biber,
style=alphabetic,
citestyle=alphabetic,
maxcitenames=2,
mincitenames=2,
giveninits=true,
isbn=false,
]{biblatex}
renewcommand*{labelalphaothers}{${}^+$}
DeclareLabelalphaTemplate{
labelelement{
field[final]{shorthand}
field{label}
field[names=2, namessep={addspace{X}addspace}]{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}
Render of MWE:
biblatex biber
add a comment |
up vote
9
down vote
favorite
I am trying to change the way that labels are generated. Some of it I already got working (only at maximum two authors, only last two digits of the year), but one thing does not seem to work, which is putting an ampersand between the authors if there are at least two.
In the manual on page 205 it is explained, that one can use special characters without escaping them as literals or padding, but what about the namessep field?
In the MWE I used 'X' in the place where an '&' should be placed, but I do not know how to do it.
I suspect, that since it is converted into the .bcf
file, which is XML, that the ampersand makes troubles there, so is this a bug?
Here is a MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{csquotes}
usepackage{filecontents}
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*}
usepackage[
backend=biber,
style=alphabetic,
citestyle=alphabetic,
maxcitenames=2,
mincitenames=2,
giveninits=true,
isbn=false,
]{biblatex}
renewcommand*{labelalphaothers}{${}^+$}
DeclareLabelalphaTemplate{
labelelement{
field[final]{shorthand}
field{label}
field[names=2, namessep={addspace{X}addspace}]{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}
Render of MWE:
biblatex biber
add a comment |
up vote
9
down vote
favorite
up vote
9
down vote
favorite
I am trying to change the way that labels are generated. Some of it I already got working (only at maximum two authors, only last two digits of the year), but one thing does not seem to work, which is putting an ampersand between the authors if there are at least two.
In the manual on page 205 it is explained, that one can use special characters without escaping them as literals or padding, but what about the namessep field?
In the MWE I used 'X' in the place where an '&' should be placed, but I do not know how to do it.
I suspect, that since it is converted into the .bcf
file, which is XML, that the ampersand makes troubles there, so is this a bug?
Here is a MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{csquotes}
usepackage{filecontents}
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*}
usepackage[
backend=biber,
style=alphabetic,
citestyle=alphabetic,
maxcitenames=2,
mincitenames=2,
giveninits=true,
isbn=false,
]{biblatex}
renewcommand*{labelalphaothers}{${}^+$}
DeclareLabelalphaTemplate{
labelelement{
field[final]{shorthand}
field{label}
field[names=2, namessep={addspace{X}addspace}]{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}
Render of MWE:
biblatex biber
I am trying to change the way that labels are generated. Some of it I already got working (only at maximum two authors, only last two digits of the year), but one thing does not seem to work, which is putting an ampersand between the authors if there are at least two.
In the manual on page 205 it is explained, that one can use special characters without escaping them as literals or padding, but what about the namessep field?
In the MWE I used 'X' in the place where an '&' should be placed, but I do not know how to do it.
I suspect, that since it is converted into the .bcf
file, which is XML, that the ampersand makes troubles there, so is this a bug?
Here is a MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{csquotes}
usepackage{filecontents}
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*}
usepackage[
backend=biber,
style=alphabetic,
citestyle=alphabetic,
maxcitenames=2,
mincitenames=2,
giveninits=true,
isbn=false,
]{biblatex}
renewcommand*{labelalphaothers}{${}^+$}
DeclareLabelalphaTemplate{
labelelement{
field[final]{shorthand}
field{label}
field[names=2, namessep={addspace{X}addspace}]{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}
Render of MWE:
biblatex biber
biblatex biber
edited Nov 10 at 20:04
asked Nov 10 at 18:53
H. Rosendahl
936
936
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
6
down vote
accepted
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}
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{bbx@introcite}{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 '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.
Thanks! This explains nicely why it fails and what to do to correct it.
– H. Rosendahl
Nov 11 at 7:38
add a comment |
up vote
3
down vote
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}
1
That's why I had thedetokenize
as well, you need to make sure that the ampersand does not expand when it is written to the.bcf
. A robust command as you used it would be the other possibility.
– moewe
Nov 10 at 22:29
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
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}
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{bbx@introcite}{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 '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.
Thanks! This explains nicely why it fails and what to do to correct it.
– H. Rosendahl
Nov 11 at 7:38
add a comment |
up vote
6
down vote
accepted
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}
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{bbx@introcite}{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 '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.
Thanks! This explains nicely why it fails and what to do to correct it.
– H. Rosendahl
Nov 11 at 7:38
add a comment |
up vote
6
down vote
accepted
up vote
6
down vote
accepted
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}
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{bbx@introcite}{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 '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.
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}
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{bbx@introcite}{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 '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.
edited Nov 11 at 11:16
answered Nov 10 at 21:37
moewe
83.2k8107320
83.2k8107320
Thanks! This explains nicely why it fails and what to do to correct it.
– H. Rosendahl
Nov 11 at 7:38
add a comment |
Thanks! This explains nicely why it fails and what to do to correct it.
– H. Rosendahl
Nov 11 at 7:38
Thanks! This explains nicely why it fails and what to do to correct it.
– H. Rosendahl
Nov 11 at 7:38
Thanks! This explains nicely why it fails and what to do to correct it.
– H. Rosendahl
Nov 11 at 7:38
add a comment |
up vote
3
down vote
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}
1
That's why I had thedetokenize
as well, you need to make sure that the ampersand does not expand when it is written to the.bcf
. A robust command as you used it would be the other possibility.
– moewe
Nov 10 at 22:29
add a comment |
up vote
3
down vote
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}
1
That's why I had thedetokenize
as well, you need to make sure that the ampersand does not expand when it is written to the.bcf
. A robust command as you used it would be the other possibility.
– moewe
Nov 10 at 22:29
add a comment |
up vote
3
down vote
up vote
3
down vote
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}
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}
answered Nov 10 at 22:24
nidhin
1,892922
1,892922
1
That's why I had thedetokenize
as well, you need to make sure that the ampersand does not expand when it is written to the.bcf
. A robust command as you used it would be the other possibility.
– moewe
Nov 10 at 22:29
add a comment |
1
That's why I had thedetokenize
as well, you need to make sure that the ampersand does not expand when it is written to the.bcf
. A robust command as you used it would be the other possibility.
– moewe
Nov 10 at 22:29
1
1
That's why I had the
detokenize
as well, you need to make sure that the ampersand does not expand when it is written to the .bcf
. A robust command as you used it would be the other possibility.– moewe
Nov 10 at 22:29
That's why I had the
detokenize
as well, you need to make sure that the ampersand does not expand when it is written to the .bcf
. A robust command as you used it would be the other possibility.– moewe
Nov 10 at 22:29
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459362%2fampersand-as-namessep-in-biblatex-label%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown