[Tex/LaTex] Custom biblatex style for IET Journal (bbx)

biblatex

I would adapt the numeric-comp style in biblatex to give the following reference/citation format sepcified by the IET Journals:

Journal article

Smith, T., and Jones, M.: ‘The title of the paper’, IET Syst. Biol., 2007, 1, (2), pp. 1–7

Conference paper

Jones, L., and Brown, D.: ‘The title of the conference paper’. Proc. Int. Conf. Systems Biology, Stockholm, Sweden, May 2006, pp. 1–7

Book, book chapter and manual

Hodges, A., and Smith, N.: ‘The title of the book chapter’, in Brown, S. (Ed.): ‘Handbook of Systems Biology’ (IEE Press, 2004, 1st edn.), pp. 1–7

Harrison, E.A., and Abbott, C.: ‘The title of the book’ (XYZ Press, 2005, 2nd edn. 2006)

Thesis

Abbott, N.L.: ‘The title of the thesis’. PhD thesis, XYZ University, 2005


but I have no idea where to start. This is what I have done so far:

\documentclass{article}

\usepackage[style=numeric-comp,sorting=none,firstinits=true,maxbibnames=999,isbn=false,doi=false]{biblatex}
\DeclareNameAlias{default}{last-first}
\DeclareFieldFormat
  [article,inbook,incollection,inproceedings,patent,thesis,unpublished]
  {title}{`#1'}
\DefineBibliographyStrings{english}{%
edition = {edn.}
}
\renewcommand*{\newunitpunct}{\addcomma\space}
\DeclareFieldFormat[article]{volume}{\mkbibbold{#1}}
\DeclareFieldFormat[article]{number}{\mkbibparens{#1}}
\renewbibmacro*{volume+number+eid}{%
  \printfield{volume}%
  \setunit*{\addcomma\space}%
  \printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}
\renewbibmacro{in:}{%
  \ifentrytype{article}{%
  }{%
    \printtext{\bibstring{in}\intitlepunct}%
  }%
}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@ARTICLE{zierler_linear_1959,
  author = {Zierler, N.},
  title = {Linear recurring sequences},
  journaltitle = {J. Soc. Ind. Appl. Math.},
  year={1959},
  volume = {7},
  number = {1},
  pages = {31--48}
}
@incollection{serfling_asymptotic_2011,
    address = {London},
    title = {Asymptotic relative efficiency in estimation},
    volume = {1},
    isbn = {978-3-642-04897-5},
    booktitle = {International Encyclopedia of Statistical Science},
    publisher = {Springer},
    author = {Serfling, Robert},
    editor = {Lovric, Miodrag},
    year = {2011},
    pages = {68--72}
}
@PHDTHESIS{enqvist_linear_2005,
  author = {Anon, B.},
  title = {A PhD Thesis},
  school = {\LaTeX University},
  year = {1999},
  location = {London}
}
@inproceedings{wong_sysid_2012,
author = {Anon, B.},
title = {Writing in \LaTeX},
eventtitle = {Some conference},
location = {Brussels, Belgium},
eventdate = {2012-07}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\nocite{*}

\begin{document}

\printbibliography

\end{document}

gives

Zierler, N., ‘Linear recurring sequences’, J. Soc. Ind. Appl. Math. 7, (1)
(1959), pp. 31–48.

Serfling, R., ‘Asymptotic relative efficiency in estimation’, in: Interna-
tional Encyclopedia of Statistical Science, ed. by Lovric, M., vol. 1, London:
Springer, 2011, pp. 68–72.

Anon, B., ‘A PhD Thesis’, PhD thesis, London: LATEX University, 1999.

Anon, B., ‘Writing in LATEX’, in: Some conference (July 2012), Brussels,
Belgium.

which isn't exactly right.
Noticeably, lack of colons, parentheses in book publishers, etc

Thank you very much in advance.

Best Answer

Let's tackle it systematically.

First locate the relevant driver for an entry type that's causing problems: in this case book (well, actually, in your data incollection: but we're much better of starting with book). We find that, after a bit of digging in standard.bbx (edited).

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{maintitle+title}%
  ...
  \newunit\newblock
  \printfield{edition}%
  ...
  \newunit\newblock
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  .... 
  \usebibmacro{finentry}}

Almost immediately we get a clue to the first problem -- the colon. It looks as if \labelnamepunct gets printed after the author. That turns out to be common to all the drivers we are interested in, and we can redefine it to obtain our colon:

\renewcommand\labelnamepunct{\addcolon\space}

The publisher information is trickier. Let's identify what we want. The information in parentheses seems to consist of the publisher, then a comma, then the original year of publication, then the edition (including 1st), then NO comma, then the year of publication of the most recent edition if it hasn't been printed before. What a muddle!

Our first thought might be to fiddle with the publisher+location+date macro. But if we look at standard.def we can see that it's used in a variety of places, not just books and book-like documents; so we might want to be careful. For the moment, it seems safer to define a new macro. Let's take it in stages.

Normally I'd start with a wrapper to make sure there was something to print. But actually we know there will be, because if nothing else everything will be a first edition!

\newbibmacro{publication:info}{%
    \printtext{\bibopenparen}
    % PUBLISHER,
    % ORIGINAL YEAR IF THERE IS ONE OTHERWISE YEAR IF THERE IS ONE,
    % EDITION or 1st EDITION
    % YEAR IF NOT ALREADY PRINTED
    \printtext{\bibcloseparen}}

That gives us a skeleton. Now we can fill in the parts.

Publisher is easy:

  \printlist{publisher}%
  \newunit

Original or most recent year is a bit trickier: we need to test and clear the year field if it is used to stop it being printed twice

\iffieldundef{origyear}
  {\iffieldundef{year}
     {}
     {\printfield{year}%
      \clearfield{year}}}
  {\printfield{origyear}%
   \clearfield{origyear}}%
\newunit

Edition has only one complication: if no edition has been given, we assume the first (which apparently gets printed -- not something I've ever seen!)

  \iffieldundef{edition}
    {\printtext{\mkbibordinal{1}\space\bibstring{edition}}}
    {\printfield{edition}}

Then we have a complication: we don't want a comma, but a space before the year (if it remains to be printed). Since we have cleared the field if it's already been used, we don't need to do any checking

  \setunit{\addspace}%
  \printfield{year}%

And finally we have to reckon with the possibility that we may have some stray punctuation hanging around, so we get rid of that before closing the parens;

  \setunit{}%
  \printtext{\bibcloseparen}}

Having done that we then need to reincorporate it into our driver. Since we are going to be handling the edition in the publication:info macro we delete the lines dealing with that. We then incorporate the publication:info, but since this is parenthetical, we put spaces around it. So we replace the lines around \usebibmacro{publisher+location+date} as follows:

\setunit{\addspace}\newblock
\usebibmacro{publication:info}%
\setunit{\addspace}\newblock

Now we test this in various ways, and if we are happy it's working for a book, we then work out what other drivers need to have the edition and publisher info replaced: certainly inbook and incollection: possibly others.

The end result of the amendment to the book driver is given at the end of this long answer. I've taken it slowly because if you are working on a standard style it may be helpful to see some tips about how to tackle the task; I don't say they are perfect, but they work for me most of the time. Do remember that if this is intended to be a standard style you need to reckon with the possibility of less-than-perfect data, and decide how graceful you will be with it. And you need lots of test data and to test constantly, because it's terribly easy to make a small change that causes havoc, such as a missing comment character in a macro that throws all your spacing.

\renewcommand{\labelnamepunct}{\addcolon\space}

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{maintitle+title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{note}%
  \setunit{\addspace}\newblock
  \usebibmacro{publication:info}%
  \setunit{\addspace}\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{isbn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

\newbibmacro{publication:info}{%
  \printtext{\bibopenparen}%
  \printlist{publisher}%
  \newunit
  \iffieldundef{origyear}
    {\iffieldundef{year}
       {}
       {\printfield{year}%
        \clearfield{year}}}
    {\printfield{origyear}%
     \clearfield{origyear}}%
  \newunit
  \iffieldundef{edition}
    {\printtext{\mkbibordinal{1}\space\bibstring{edition}}}
    {\printfield{edition}}%
  \setunit{\addspace}%
  \printfield{year}%
  \setunit{}%
  \printtext{\bibcloseparen}}