10

I have added a price attribute to my bibliography as such:

@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}
}

When I re-run my latexmk (which runs bibtex and xelatex the required number of times), I don't see the price show up in my bibliography. I don't get any errors or warnings either.

I'm using the following biblatex options:

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

UPDATE: I ultimately got this looking how I wanted as follows:

\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}}

screenshot

lockstep
  • 250,273
  • I think you have to use/define proper bibliography style. – Pouya Dec 17 '13 at 16:02
  • @Pouya okay...how? – Mark Richman Dec 17 '13 at 16:07
  • Have you tried using the note for this purpose (rather than creating an entirely new field and then having to instruct biblatex what to do with this field)? By the way, you need to prefix a backslash to the $ symbol. – Mico Dec 17 '13 at 16:09
  • note has no effect. – Mark Richman Dec 17 '13 at 16:14
  • One advantage of the BibTeX format is you can use any number or arbitrary fields, and BibTeX (and Biber) will happily ignore them if they don't know what they are for. (I often have a field for the call number of library books that I often (re-)check out.) To make them be used in the output, you need a style (a .bst with BibTeX, a .bbx with biblatex/biber) that does something with these fields. if you don't want to do that, for biblatex, usually the addendum field is the last thing printed, and you could put the price information there. – jon Dec 17 '13 at 16:42
  • @jon addendum had no effect either. Do I need to change my backend option? I'm using XeLaTeX. – Mark Richman Dec 17 '13 at 16:44
  • 'No effect' is pretty vague. Do you mean everything works fine and shows up in the bibliography except the addendum field? It definitely works for me, even with backend=bibtex. – jon Dec 17 '13 at 16:53
  • Also: is latexmk definitely aware that you've changed your .bib file and therefore knows it needs to run the full sequence of xelatex, biber, xelatex again? Try a manual run of each command just to be certain. – jon Dec 17 '13 at 16:57
  • I ran xelatex, bibtex, xelatex, xelatex. It DOES work when I use Addendum, but not Price. I got the output I wanted by doing this: Addendum = {Price: USD 30.55}. – Mark Richman Dec 17 '13 at 18:03
  • Right: price is not a standard field, and, as I said, both BibTeX and Biber will ignore all fields they have not been informed of. biblatex (with either backend) does make use of the addendum field if it is used. – jon Dec 17 '13 at 20:59
  • Regarding the update, your solution will mislead others. (1) You are not actually using the bibliography strings if you are hard-coding the word 'price' into your renewed bibmacro -- maybe because you are not using babel..? (2) Without something like \newunit\newblock between your hard-coded 'price' line and the printing of the addendum field, my guess is that there will be problems if an entry contains both a price and addendum field. Of course, if all is working the way you like, that's all to the good; but others might not notice the small ways your solution differs from @moewe's. – jon Dec 19 '13 at 05:21
  • Additionally to jon's comments you should note that defining the bibliography string price (as I did below) is unnecessary in your definition as it is never used. Here I would certainly advocate the use of bibstrings as explained below. – moewe Dec 19 '13 at 18:31
  • Also, I would be wary of printing text verbatim as in \textsc{price}, just add it to \DeclareFieldFormat like so: \DeclareFieldFormat{price}{\textsc{price}\addcolon\space#1}. Then you do not have to check for an empty price field and the macro becomes \renewbibmacro*{addendum+pubstate}{\newunit\newblock\printfield{price}\printfield{addendum}\newunit\newblock \printfield{pubstate}} (modulo line breaks and % percent signs to prevent spurious whitepsace). – moewe Dec 19 '13 at 18:32
  • I just assumed price were recognized because of what I found here: https://www.cs.arizona.edu/~collberg/Teaching/07.231/BibTeX/bibtex.html – Mark Richman Dec 19 '13 at 19:45

1 Answers1

9

You could just add the information to the addendum field.

See this 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}

You could also map the price field to the addendum via biber's sourcemapping features. This will note overwrite the addendum, but append the price information to it (preceded by a space). Since all standard styles seem to employ addendum this method is quite likely to make the price appear in the bibliography.

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

You might like to replace the second \step by \step[fieldset=addendum, fieldvalue={~\textsc{Price}:~}, append].

See this 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}

enter image description here


But with biber there is a much cooler way.

We define a new field price via a datamodel file (we use biblatex-dm.cfg; the file should be put somewhere LaTeX can find it; in the MWE the file is automatically created via the filecontents environment).

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

To make use of the fancy localisation features, we also define

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

Or, if you prefer "Price" to be in small caps, try

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

Then, we also have biblatex print the price information. The most stable idea would probably be to add it to the driver manually, but that is very tiresome, so we can use either of the following ways.

Add the information to the finentry hook.

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

Or, print the information just before the addendum field.

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

The MWE uses the latter method

\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}

enter image description here

moewe
  • 175,683
  • 1
    That's an incredible amount of work. I finally got what I wanted using Addendum = {Price: USD 30.55}. I just had to run xelatex, bibtex, xelatex, xelatex. – Mark Richman Dec 17 '13 at 18:08
  • 3
    @MarkRichman -- The advantage of this solution is that if you re-use the bibliography file in another document that uses biblatex, and don't want to print the price information, you won't need to subsequently delete all these addendum fields that mentions the price. The solution therefore increases the portability and therefore long-term viability of employing a single .bib file. (So: if the issue of a single .bib file is irrelevant, it is overkill -- albeit one with a 'cool' factor, as moewe says.) – jon Dec 17 '13 at 21:03
  • @jon I see your point! One last question - how to get "Price" in small caps to match ISBN and URL? Assuming that is stylistically accurate of course. – Mark Richman Dec 17 '13 at 21:09
  • @jon Just the word "Price" in small caps. "USD 30.55" should be in the default font. – Mark Richman Dec 17 '13 at 21:23
  • @MarkRichman -- Hmm, actually, changing the bibstrings might be best for internationalization. (Never thought about this whole problem before.) I think perhaps: \DefineBibliographyStrings{english}{price = {\mkbibacro{PRICE}},} (and the same for the other languages needed) is the best way. – jon Dec 17 '13 at 21:33
  • 2
    using biber as backend, you could also just remap the price field to addendum with \DeclareSourcemap (with something like \DeclareSourcemap{\maps[datatype=bibtex]{\map{\step[fieldsource=price,fieldset=addendum,origfieldval]}}}) – henrique Dec 17 '13 at 21:57
  • @henrique -- I thought about that, too. But won't that require not using the addendum field for anything else (in documents where the price needs to be included as well)? Otherwise, wouldn't you need to hardcode the string 'price' into the addendum field itself? – jon Dec 17 '13 at 22:26
  • Hey @jon, that's absolutely true, I just thought it worth mentioning a poor man's alternative :) – henrique Dec 18 '13 at 00:42
  • @henrique -- Indeed. It might be worth posting as an alternative example. – jon Dec 18 '13 at 05:31
  • I ultimately got this looking how I wanted. See update in question. – Mark Richman Dec 19 '13 at 03:01