TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wish to add a new entry to the biblatex bibliography type @online. For example,

@online{abc,
  author   = {A Author},
  title    = {Some lengthy title that's awesome},
  url      = {http://tex.stackexchange.com},
  breakurl = {}
}

I've added a breakurl field (that could be blank), that I want to condition on when using the online bibliography driver to possibly insert a line break. However, I'm unable to successfully achieve this, even after following the guidelines in Add field "tome" to biblatex entries.

Here is a minimal example:

enter image description here

\documentclass{article}

\usepackage{filecontents,showframe}
\usepackage{biblatex}

\begin{filecontents*}{mybib.bib}
@online{abc,
  author   = {A Author},
  title    = {Some lengthy title that's awesome},
  url      = {http://tex.stackexchange.com},
  breakurl = {}
}
\end{filecontents*}

\addbibresource{mybib.bib}

% http://tex.stackexchange.com/q/163303/5764
\DeclareDatamodelFields[type=field,datatype=verbatim,nullok=true]{breakurl}
\DeclareDatamodelEntryfields{breakurl}
\DeclareFieldFormat[online]{breakurl}{}% Used as a boolean variable

\begin{document}

\nocite{*}

\printbibliography

\end{document}

After compiling with biber, the breakurl field is not visible in the .bbl:

\refsection{0}
  \sortlist{nty}{nty}
    \entry{abc}{online}{}
      \name{author}{1}{}{%
        {{hash=1318a946c3fffa54cec1130748f21c17}{Author}{A\bibinitperiod}{A}{A\bibinitperiod}{}{}{}{}}%
      }
      \strng{namehash}{1318a946c3fffa54cec1130748f21c17}
      \strng{fullhash}{1318a946c3fffa54cec1130748f21c17}
      \field{sortinit}{A}
      \field{sortinithash}{b685c7856330eaee22789815b49de9bb}
      \field{labelnamesource}{author}
      \field{labeltitlesource}{title}
      \field{title}{Some lengthy title that's awesome}
      \verb{url}
      \verb http://tex.stackexchange.com
      \endverb
    \endentry
  \endsortlist
\endrefsection

The motivation behind adding a new field is that it can easily be ignored by biber or by the driver. An alternative would be to include such line breaks as part of the field entries in the @online source, but that is not acceptable.

The more general question would be: How can I add a field to an existing biblatex type?

share|improve this question
1  
In short: the data model commands should be put in a .dbx file that you then load in the options: \usepackage[datamodel=mydbxfile]{biblatex}. I'd probably also do: \DeclareDatamodelEntryfields[online]{breakurl} since this seems like a fairly specific use. – jon Jan 10 at 19:47
    
Can you pass the information to biber via another (existing) field, i.e. define \breakurl which expands to nothing when you are not using it? – ienissei Jan 10 at 19:48
    
Related Data model macro cannot be used in preamble. – moewe Jan 10 at 21:31
up vote 5 down vote accepted

The answer to Add field “tome” to biblatex entries was written back in the good old days when datamodel commands were still allowed in the document preamble, starting from version 2.9 those commands cannot be used in the preamble in order to avoid complications and unwanted behaviour. The answer has now been amended to reflect this change.

So if you want to use datamodel commands now you will have to use a datamodel file (either a .dbx or biblatex-dm.cfg). You could call this file werner.dbx, its content would be

\DeclareDatamodelFields[type=field,datatype=verbatim,nullok=true]{breakurl}
\DeclareDatamodelEntryfields{breakurl}

You would then have to load biblatex with the option datamodel=werner.

Please note that nullok=true does not ensure that the field appears in the .bbl even if it is empty, it just doesn't generate a warning. So breakurl = {}, does not make the field breakurl appear in the .bbl.


You seem to want to use the breakurl field as a boolean value. This can be done slightly easier with \DeclareEntryOption.

\newtoggle{blx@breakurl}
\DeclareEntryOption{breakurl}[true]{%
  \settoggle{blx@breakurl}{#1}%
  % or whatever you need to do here
}

Defines a new option breakurl that sets a toggle.

In your .bib entry you then have

options  = {breakurl},

to toggle breakurl on.

You can have a look at biblatex - citing dead author, How to remove comma from authoryear citation, Functionality of apacites \nocitemeta with biblatex-apa: adding asterisks to author lastnames (meta-analysis) and Change 'Chapter' in @inbook to 'Appendix' for one BibLaTex entry for more examples and uses of \DeclareEntryOption.

MWE

\documentclass{article}
\usepackage{filecontents}
\usepackage{biblatex}

\begin{filecontents*}{\jobname.bib}
@online{abc,
  author   = {A Author},
  title    = {Some lengthy title that's awesome},
  url      = {http://tex.stackexchange.com},
  options  = {breakurl},
}
\end{filecontents*}

\addbibresource{\jobname.bib}

\newtoggle{blx@breakurl}
\togglefalse{blx@breakurl}
\DeclareEntryOption{breakurl}[true]{%
  \settoggle{blx@breakurl}{#1}%
  % or whatever you need to do here
}

\begin{document}
\nocite{*}
\printbibliography
\end{document}
share|improve this answer

According to the biblatex manual (texdoc biblatex)

It is not possible to add to a loaded data model by using the macros below in your preamble as the preamble is read after Biblatex has defined critical internal macros based on the data model. If any data model macro is used in a document, it will be ignored and a warning will be generated.

The command to declare data model (and thus new field) should be in configuration files.

To insert them in a document one can use filecontents environment to generate the configuration file.

\begin{filecontents}{biblatex-dm.cfg}
\DeclareDatamodelFields[type=field,datatype=verbatim,nullok=true]{breakurl}
\DeclareDatamodelEntryfields{breakurl}
\DeclareFieldFormat[online]{breakurl}{}% Used as a boolean variable
\end{filecontents}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.