[Tex/LaTex] Remove parentheses for empty year field biblatex ieee style

biblatexbibtexieee-style

By using biblatex ieee style, I found that the reference will display empty brackets even though the field "year" is undefined. How can I remove it without having to change the biblatex.bst?

\documentclass{article}

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

\usepackage{filecontents}

\begin{filecontents}{\x.bib}
@ELECTRONIC{MEMSnet,
  title = {What is {MEMS}?},
  organization = {MEMSnet},
  url = {http://www.memsnet.org/mems/what_is.html},
  urldate = {Dec. 01, 2013}
}
\end{filecontents}

\addbibresource{\x.bib}

\nocite{*}

\begin{document}

\printbibliography

\end{document}

I got

(). What is MEMS? MEMSnet, [Online]. Available: http://www.memsnet.org/mems/what_is.html.

which is not a correct citation style. I would like to have:

What is MEMS? MEMSnet, [Online]. Available: http://www.memsnet.org/mems/what_is.html.

Many Thanks

Best Answer

In ieee.bbx we find the lines

\DeclareBibliographyDriver{online}{%
  [...]
  \setunit{\adddot\addspace}%
  \printtext[parens]{\usebibmacro{date}}%
  \setunit{\adddot\addspace}%
  [...]

So biblatex tries to use the date macro (which actually just defaults to \printdate) and wrap its output into parentheses. If it does not print anything, well, then an empty string is wrapped into parentheses, resulting in what you got above.

The obvious cure is to provide the entry with a date field (after all, [almost] every bib entry should have one, see also Joseph Wright's comment above), this can be difficult and outright impossible with some @online resources though.

Since we do not want to rewrite the whole @online driver (an obvious way to fix the problem), we patch it using xpatch.

Load \usepackage{xpatch} and put this code into your preamble

\xpatchbibdriver{online}
  {\printtext[parens]{\usebibmacro{date}}}
  {\iffieldundef{year}
    {}
    {\printtext[parens]{\usebibmacro{date}}}}
  {}
  {\typeout{There was an error patching biblatex-ieee (specifically, ieee.bbx's @online driver)}}

It will replace the offending line discussed above (\printtext[parens]{\usebibmacro{date}}) by a (more or less sophisticated) construction in which we check if there is a year field (i.e. a sufficient date field) and only if that condition is met (i.e. only if a year exists; here of course we presuppose that year is the bare minimum requirement for a date output in the bibliography) we go on to print the date, otherwise nothing is done.

\documentclass{article}
\usepackage[style=ieee,backend=bibtex]{biblatex}
\usepackage{xpatch}

\begin{filecontents}{\jobname.bib}
@ELECTRONIC{MEMSnet,
  title = {What is {MEMS}?},
  organization = {MEMSnet},
  url = {http://www.memsnet.org/mems/what_is.html},
  urldate = {2013-12-01},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\xpatchbibdriver{online}
  {\printtext[parens]{\usebibmacro{date}}}
  {\iffieldundef{year}
    {}
    {\printtext[parens]{\usebibmacro{date}}}}
  {}
  {\typeout{There was an error patching biblatex-ieee (specifically, ieee.bbx's @online driver)}}

\begin{document}
  \nocite{MEMSnet,wilde,markey}
  \printbibliography
\end{document}

enter image description here

Related Question