biblatex 标签中的“&”符号作为 namesep

biblatex 标签中的“&”符号作为 namesep

我正在尝试改变标签的生成方式。其中一些我已经成功了(最多只有两位作者,只有年份的最后两位数字),但有一件事似乎行不通,那就是如果至少有两个作者,则在作者之间添加一个 & 符号。在第 205 页的手册据称,人们可以使用特殊字符而不将其转义为文字或填充,但是 namesep 字段呢?

在 MWE 中,我使用“X”代替了应该放置“&”的位置,但我不知道该怎么做。我怀疑,由于它被转换为.bcfXML 文件,因此“&”符号会造成麻烦,所以这是一个错误吗?

以下是 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}

MWE 的渲染: MWE 渲染图

答案1

在命令中隐藏“与”符号(\&这并不好,因为命令名称包含“与”符号,这仍然会使 XML 失效)并使用\detokenize确保宏在写入时不会扩展.bcf

\detokenizebiblatex如果包含可打印数据的选项可能激增,这通常是一种廉价的解决方法。这种情况经常发生,因为选项的值需要.bcf写入文件,因此 Biber 可以使用其值。LaTeX 通常在将文本写入文件时执行完全扩展,因此如果所需值不可扩展或(如本例中)扩展为有问题的文本,则可能会出错。\detokenize停止这种不必要的扩展。当从文件中获取值时.bbl,将照常解释标记,并且输出将符合预期。

手册第 205 页引用的段落仅适用于padchar\literal,的值namessep需要对 LaTeX 和 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{\addspace\ampersand\space}]{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


我不太喜欢滥用alphabetic来获得本质上是完整的作者年份样式,带有方括号和参考书目中的标签,但因为获取年份的最后两位数字并保留唯一性特征有点棘手,我无法提供完全相同样式的简单实现style=authoryear,但是

\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}{}%
  \addspace\bibstring{and}\space}

\addbibresource{biblatex-examples.bib}

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

\printbibliography
\end{document}

可能是一个开始。

参考书目显示引用标签,分配给标签的空间是固定的,较长的标签会产生换行符,让参考书目条目在下一行开始

自动为每个标签分配足够的空间而不会超出输入数据的“双栏”布局样式alphabetic似乎更可取,但如果您引用海伦娜·伯翰·卡特和拉尔夫·沃恩·威廉姆斯的作品,您很快就会注意到,留给实际输入数据的空间变得非常狭窄,不再允许良好的换行。

答案2

\newcommand*{\ambr}{\&}对我没用。\newrobustcmd{\ambr}{\&}有用。

\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={\addspace\ambr\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}

在此处输入图片描述

相关内容