16

Following this question BibLaTeX/BibTeX custom field to show file link and Notes after bibliography entry with Biber and biblatex I get it to work (well, more or less). In the code below I defined a field file and mynote. It is working for file but not for mynote. I don't understand why!

\documentclass[%
    a4paper,
    english,
    11pt,
]{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{Padial:2010,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    journal={Frontiers in Zoology},
    year=2010,
    month=may,
    volume=7,
    number=16,
    pages={1--14},
    doi={10.1186/1742-9994-7-16},
    issn={1742-9994},
    mynote={Very good book!},
    file={./article/2010_Wang.pdf},
    keywords={biology, taxonomy},
}
\end{filecontents*}

\usepackage{fixltx2e}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{type1ec}
%\usepackage{lmodern}
\usepackage{microtype}

\usepackage[%
    left=5cm,
    right=2cm,
    %showframe,
    ]{geometry}

\usepackage[color,notref,notcite]{showkeys}

\usepackage[strict,autostyle]{csquotes}

\usepackage[%
    backend=biber,
    style=ieee,
]{biblatex}
\DeclareRangeChars{~,;-+/{}} % add '{}' as page range delimiter
\addbibresource{\jobname.bib}

\DeclareFieldFormat{mynote}{\textbf{#1}}
\DeclareFieldFormat{file}{\href{file:#1}{\textbf{Open file}}}
\AtEveryBibitem{%
    \csappto{blx@bbx@\thefield{entrytype}}{% put at end of entry
        \iffieldundef{file}{\space \textbf{No file!}}{%
        \space \printfield{file}}
        \iffieldundef{mynote}{\space \textbf{No annotation!}}{\space\printfield{mynote}}
    }
}

\usepackage[%
    colorlinks,
    unicode,
    breaklinks,
]{hyperref}

\begin{document}

\nocite{*} % list all entries

\printbibliography
%\printbibliography[keyword=taxonomy]

\end{document}
cacamailg
  • 8,405

3 Answers3

21

This is because file is already a field to biblatex, although one not used by the standard styles, while mynote isn't. You must remap (via DeclareSourcemap) the mynote field to one of the user[a-f] fields before you can use them.

\documentclass{article}

\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib}
@article{Padial:2010,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    journal={Frontiers in Zoology},
    year=2010,
    month=may,
    volume=7,
    number=16,
    pages={1--14},
    doi={10.1186/1742-9994-7-16},
    issn={1742-9994},
    mynote={Very good book!},
    file={./article/2010_Wang.pdf},
    keywords={biology, taxonomy},
}
\end{filecontents*}

\usepackage[utf8]{inputenc}
\usepackage[color,notref,notcite]{showkeys}

\usepackage[%
    backend=biber,
    style=ieee,
]{biblatex}

\DeclareRangeChars{~,;-+/{}} % add '{}' as page range delimiter

\addbibresource{\jobname.bib}

\DeclareFieldFormat{file}{\href{file:#1}{\textbf{Open file}}}

\AtEveryBibitem{%
    \csappto{blx@bbx@\thefield{entrytype}}{% put at end of entry
        \iffieldundef{file}{\space \textbf{No file!}}{%
        \space \printfield{file}
      }
    }
  }

\DeclareSourcemap{
    \maps[datatype=bibtex]{
      \map{
        \step[fieldsource=mynote]
        \step[fieldset=usera,origfieldval]
    }
  }
}

\DeclareFieldFormat{usera}{\textbf{#1}}

\AtEveryBibitem{%
    \csappto{blx@bbx@\thefield{entrytype}}{% put at end of entry
        \iffieldundef{usera}{%
          \space \textbf{No annotation!}}{%
          \space\printfield{usera}
        }
    }
}

\usepackage[%
    colorlinks,
    unicode,
    breaklinks,
]{hyperref}

\begin{document}

\nocite{*} % list all entries

\printbibliography

\end{document}

enter image description here

henrique
  • 6,616
  • 1
    Very good answer. In the end I used the field annotation (as it is already defined in BibLaTeX) and did as I had done for file. – cacamailg May 02 '13 at 14:53
  • 1
    If so, you should consider changing your database to reflect this (specially since your use of mynote seems to fall into the purpose of annotation). I must say that IMHO, while this answer works fine and is a good approach to single files, Guido's answer seems to me to be the "right" one to choose, since it approaches the subject in a more generalized way. – henrique May 02 '13 at 19:46
  • 1
    This is the only answer I could get to work. It's perhaps good to emphasize that the field can only be mapped to user[a-f], and not another name of your choosing. – Stefan van der Walt Nov 24 '14 at 00:36
  • 1
    @StefanvanderWalt, Actually you do can create new, custom fields by playing with the data models (see §4.5.3 of the manual) instead of remapping it to the official custom ones (user[a-f] etc.). There were a typo in Guido's answer (filed instead of field). Perhaps if you try now? I just ran it with my MWE, only changing where I used usera to the new mynote field with no apparent problem. I insist that his is the correct answer because it addresses more general usage and makes use of the full power of biblatex+biber. – henrique Nov 25 '14 at 19:13
12

Biblatex offers builtin support for the file field (even if it is not a standard one). Users can extend the data model by creating new fields, but they have to be declared in configuration files According to the manual (page 175) they are ordered as follows:

blx-dm.def→
‘datamodel option’.dbx →
‘style option’.dbx →
‘citestyle option’.dbx and ‘bibstyle option’.dbx →
biblatex-dm.cfg

Thus, you can create a biblatex-dm.cfg file in the working directory and use

\DeclareDatamodelFields[type=field, datatype=literal, skipout=false]{mynote}

The creation of file can be done within your file using filecontents package and

\begin{filecontents}{biblatex-dm.cfg}
    \DeclareDatamodelFields[type=field, datatype=literal, skipout=false]{mynote}
\end{filecontents}
henrique
  • 6,616
Guido
  • 30,740
  • 1
    Just a couple of comments - you can omit skipout=false as this is the default. Also, you need \DeclareDatamodelEntryfields{mynote} too. This declares "mynote" as valid for all entrytypes and the macro you mentioned defines its type. – PLK May 02 '13 at 07:09
  • Indeed skipout=false can be omitted. For \DeclareDatamodelEntryfields apparently it is not needed. – Guido May 02 '13 at 07:35
0

One thing that I noticed, probably it is obvious but I was missing it, is that the datamodel definitions must precede biblatex loading. The order that works fine is:

  1. Use package filecontents:
\usepackage{filecontents}
  1. Detail the 'biblatex-dm.cfg' required content
\begin{filecontents}{biblatex-dm.cfg}
    \DeclareDatamodelFields[type=field, datatype=literal, skipout=false]{mynote}
    DeclareDatamodelEntryfields{mynote}
\end{filecontents}
  1. Load the biblatex with options:
\usepackage[backend=biber,style=ieee,sorting=none]{biblatex}

Many thanks to all for the question and for the answers! I was really surprised how powerful biblatex became.

ACosta
  • 1