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:
Render of MWE










share|improve this question




























    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:
    Render of MWE










    share|improve this question


























      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:
      Render of MWE










      share|improve this question















      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:
      Render of MWE







      biblatex biber






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 20:04

























      asked Nov 10 at 18:53









      H. Rosendahl

      936




      936






















          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}


          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{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 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.






          share|improve this answer























          • Thanks! This explains nicely why it fails and what to do to correct it.
            – H. Rosendahl
            Nov 11 at 7:38


















          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}


          enter image description here






          share|improve this answer

















          • 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











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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

























          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}


          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{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 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.






          share|improve this answer























          • Thanks! This explains nicely why it fails and what to do to correct it.
            – H. Rosendahl
            Nov 11 at 7:38















          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}


          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{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 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.






          share|improve this answer























          • Thanks! This explains nicely why it fails and what to do to correct it.
            – H. Rosendahl
            Nov 11 at 7:38













          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}


          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{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 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.






          share|improve this answer














          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{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 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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 11:16

























          answered Nov 10 at 21:37









          moewe

          82.7k8106317




          82.7k8106317












          • 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




          Thanks! This explains nicely why it fails and what to do to correct it.
          – H. Rosendahl
          Nov 11 at 7:38










          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}


          enter image description here






          share|improve this answer

















          • 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















          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}


          enter image description here






          share|improve this answer

















          • 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













          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}


          enter image description here






          share|improve this answer












          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 22:24









          nidhin

          1,450820




          1,450820








          • 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














          • 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








          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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine