如何在参考书目中包含价格?

如何在参考书目中包含价格?

我在我的参考书目中添加了一个price属性:

@book{1578203120,
  Author = {Janice Reynolds},
  Title = {The Complete E-Commerce Book: Design, Build \& Maintain a Successful Web-based Business},
  Publisher = {CRC Press},
  Year = {2004},
  ISBN = {1578203120},
  URL = {http://www.amazon.com/dp/1578203120},
  price = {USD 30.55}
}

当我重新运行我的程序latexmk(运行bibtex所需xelatex的次数)时,我没有看到书目中出现价格。我也没有收到任何错误或警告。

我正在使用以下biblatex选项:

\usepackage[backend=bibtex,url=true]{biblatex}

更新:我最终得到了我想要的样子,如下所示:

\begin{filecontents*}{biblatex-dm.cfg}
\DeclareDatamodelFields[type=field,datatype=literal]{price}
\DeclareDatamodelEntryfields{price}
\end{filecontents*}

\NewBibliographyString{price}
\DefineBibliographyStrings{english}{price = {price}}

\renewbibmacro*{addendum+pubstate}{%
  \iffieldundef{price}
    {}
    % {\textsc{\bibstring{price}}\addcolon\space\printfield{price}}
    {\addperiod\space\textsc{price}\addcolon\space\printfield{price}}
  \printfield{addendum}%
  \newunit\newblock
  \printfield{pubstate}}

截屏

答案1

您只需将信息添加到附录字段即可。

参见此 MWE

\documentclass{article}
\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage[backend=bibtex,url=true]{biblatex}
\usepackage{filecontents}
\addbibresource{\jobname.bib}
\begin{filecontents*}{\jobname.bib}
@book{1578203120,
  Author = {Janice Reynolds},
  Title = {The Complete E-Commerce Book: Design, Build \& Maintain a Successful Web-based Business},
  Publisher = {CRC Press},
  Year = {2004},
  ISBN = {1578203120},
  URL = {http://www.amazon.com/dp/1578203120},
  addendum = {USD 30.55},
}
\end{filecontents*}

\begin{document}
  \nocite{*}
  \printbibliography
\end{document}

您还可以通过 的源映射功能将价格字段映射到附录biber。这不会覆盖附录,但会将价格信息附加到其中(前面有一个空格)。由于所有标准样式似乎都采用addendum这种方法,因此很可能使价格出现在参考书目中。

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite=true]{
      \step[fieldsource=price, final]
      \step[fieldset=addendum, fieldvalue={~}, append]
      \step[fieldset=addendum, origfieldval, append]
    }
  }
}

您可能希望将第二个替换\step\step[fieldset=addendum, fieldvalue={~\textsc{Price}:~}, append]

参见此 MWE

\documentclass{article}
\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage[backend=biber,url=true]{biblatex}
\usepackage{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\begin{filecontents*}{\jobname.bib}
@book{1578203120,
  Author = {Janice Reynolds},
  Title = {The Complete E-Commerce Book: Design, Build \& Maintain a Successful Web-based Business},
  Publisher = {CRC Press},
  Year = {2004},
  ISBN = {1578203120},
  URL = {http://www.amazon.com/dp/1578203120},
  price = {USD 30.55},
  addendum = {A nice book, for less than fifty dollar.},
}
\end{filecontents*}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite=true]{
      \step[fieldsource=price, final]
      \step[fieldset=addendum, fieldvalue={~\textsc{Price}:~}, append]
      \step[fieldset=addendum, origfieldval, append]
    }
  }
}

\begin{document}
  \nocite{1578203120,wilde}
  \printbibliography
\end{document}

在此处输入图片描述


biber还有一种更酷的方法。

我们price通过数据模型文件定义一个新字段(我们使用biblatex-dm.cfg;该文件应该放在 LaTeX 可以找到的地方;在 MWE 中,该文件是通过环境自动创建的filecontents)。

\DeclareDatamodelFields[type=field, datatype=literal]{price}
\DeclareDatamodelEntryfields{price}

为了利用奇特的本地化功能,我们还定义

\NewBibliographyString{price}
\DefineBibliographyStrings{english}{%
  price = {price},
}
\DefineBibliographyStrings{ngerman}{%
  price = {Preis},
}
\DeclareFieldFormat{price}{\bibstring{price}\addcolon\space#1}

或者,如果您希望“价格”采用小写字母,请尝试

\DeclareFieldFormat{price}{\bibstring[\textsc]{price}\addcolon\space#1}

然后我们还要biblatex打印这些price信息。最稳定的想法可能是手动将其添加到驱动程序中,但是这很累,所以我们可以使用以下任何一种方式。

将信息添加到finentry钩子中。

\renewbibmacro*{finentry}{%
  \printfield{price}%
  \newunit\newblock
  \finentry}

或者,在字段之前打印信息addendum

\renewbibmacro*{addendum+pubstate}{%
  \printfield{price}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \printfield{pubstate}}

MWE 采用后一种方法

\documentclass{article}
\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage[backend=biber,url=true]{biblatex}
\usepackage{filecontents}
\addbibresource{\jobname.bib}
\begin{filecontents*}{\jobname.bib}
@book{1578203120,
  Author = {Janice Reynolds},
  Title = {The Complete E-Commerce Book: Design, Build \& Maintain a Successful Web-based Business},
  Publisher = {CRC Press},
  Year = {2004},
  ISBN = {1578203120},
  URL = {http://www.amazon.com/dp/1578203120},
  price = {USD 30.55},
}
\end{filecontents*}

\begin{filecontents*}{biblatex-dm.cfg}
\DeclareDatamodelFields[type=field,datatype=literal]{price}
\DeclareDatamodelEntryfields{price}
\end{filecontents*}

\NewBibliographyString{price}
\DefineBibliographyStrings{english}{%
  price = {price},
}
\DefineBibliographyStrings{ngerman}{%
  price = {Preis},
}

\DeclareFieldFormat{price}{\bibstring[\textsc]{price}\addcolon\space#1}

\renewbibmacro*{addendum+pubstate}{%
  \printfield{price}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \printfield{pubstate}}

\begin{document}
  \nocite{*}
  \printbibliography
\end{document}

在此处输入图片描述

相关内容