Take the 2-minute tour ×
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.

How can I declare different strings for different entry? For example, for ordinary url, the urldate will be printed as "Accessed: urldate" while for Wikipedia, the urldate will be printed as "Last modified: urldate".

I tried something like \iffieldequalstr but it seems to be not working. Below is a MWE

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

@ELECTRONIC{WikiMEMS,
  author = {Wikipedia},
  title = {Microelectromechanical systems},
  organization = {Wikipedia.org},
  url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
  timestamp = {09:59},
  urldate = {28 November 2013}
}

\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 (ieee.bbx's @online driver)}}

 \AtEveryBibitem{
  \ifentrytype{online}{
   \iffieldequalstr{author}{Wikipedia}{
     \DefineBibliographyStrings{english}{%
       urlseen = {Last modified}
      }
     \DeclareFieldFormat{urldate}{\mkbibbrackets{\bibstring{urlseen}\addcolon\space#1\addcomma\space\printfield{timestamp}}}
    }{
     \DefineBibliographyStrings{english}{%
      urlseen = {Accessed}
     }
     \DeclareFieldFormat{urldate}{\mkbibbrackets{\bibstring{urlseen}\addcolon\space#1}}
    }
   }{}
  }

\begin{document}
  \nocite{MEMSnet,WikiMEMS,wilde,markey}
  \printbibliography
\end{document}
share|improve this question
    
One can only modify the bibstrings in the preamble, so when it gets to AtEveryBibitem that is too late. Moreover it is not consistent to use urldate for what it's intended in almost all cases, but abuse it as something entirely different for Wikipedia entries. You should think about creating a custom type @wiki (or similar) in which date is prefixed by "last modified". It just does not seem to be right to use urldate for that; urldates indicates when you last saw that page, not when it was last modified, that almost certainly is date's job. –  moewe Dec 25 '13 at 15:58
    
thanks @moewe for replying all my questions on Christmas Day. Merry Christmas to you. Just wonder how can I add a custom entry type? I am actually quite new to latex –  user25196 Dec 25 '13 at 16:24
    
Merry Christmas to you too. There seems to be a solution to do what you want after all, but I have also written up something about custom entry types. –  moewe Dec 25 '13 at 17:04
    
If this is not something you need a lot, you could also just use the addendum or note field to add this information. I tend to agree that date, rather than urldate, is the natural place for this information if you want to use a standard date field. "Last modified" seems roughly like the specification of an edition of a book, for example. –  cfr Dec 25 '13 at 17:06

1 Answer 1

up vote 3 down vote accepted

One solution that comes pretty close to what you want is to do the following, declare a new bibstring, aptly named lastmodified, via

\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
  lastmodified = {last modified}
}

To be able to compare the name author we need a macro \wikitestname. Unfortunately, there is as of now no easy way to check a name* against a string, so we need to use \ifnameequals to check against a macro; the name format is very specific however, you can look it up in the .bbl file.

\def\wikitestname{{}{{{}{Wikipedia}{W.}{}{}{}{}{}{}}}}

We then check whether the entry currently processed is a Wiki one

\AtEveryBibitem{
  \ifentrytype{online}{
    \ifnameequals{author}{\wikitestname}
      {\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{lastmodified}\space#1}}}
      {\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{urlseen}\space#1}}}
  }
}

and change the string preceding urldate accordingly if necessary.

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

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

@ELECTRONIC{WikiMEMS,
  author = {Wikipedia},
  title = {Microelectromechanical systems},
  organization = {Wikipedia.org},
  url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
  timestamp = {09:59},
  date = {2013-11-28},
  urldate = {2013-12-25},
}

\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 (ieee.bbx's @online driver)}}


\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
  lastmodified = {last modified}
}

\def\wikitestname{{}{{{}{Wikipedia}{W.}{}{}{}{}{}{}}}}
 \AtEveryBibitem{
    \ifentrytype{online}{
     \ifnameequals{author}{\wikitestname}
       {\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{lastmodified}\space#1}}} 
       {\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{urlseen}\space#1}}} 
    }
  }

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

enter image description here


* biblatex distinguishes between names, fields and lists. For example, author is a name, series a field and organization a list. There are different macros to check for equality between those fields. You cannot use \iffieldequalstr to check whether a name equals a given string. Since names are arguably the most complex part of what biblatex has to deal with they also have the most complicated identity conditions. After all one would not want the name given in a .bib file as Peter Smith to match the string Smith, but you would want both Peter Smith and Smith, Peter to match Peter Smith since both input formats are equally valid in the .bib file. So biblatex accepts only comparing against macros that are supposed to already include the proper name syntax as given in the .bbl file. In our case {}{{{}{Wikipedia}{W.}{}{}{}{}{}{}}}.


On a different note. In this case it might be quite apt do define a dedicated entry type (one might like to call it @wiki) for this task.

As you seem to use BibTeX as backend and not the (in my opinion at least) far superior biber, let us first explore our possibilities with BibTeX and then go on to see how much better we can do with biber.

biblatex by default has six entry types for custom modifications: these are customa to customf. Here we will use customa.

From now on, if you want to cite a wiki entry, do not use @online/@electronic, but @customa.

@customa{WikiMEMS,
  author = {Wikipedia},
  title = {Microelectromechanical systems},
  url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
  organization = {Wikipedia, The Free Encyclopedia},
  date = {2013-11-28},
  urldate = {2013-12-25},
}

The fields are as expected; note that urldate takes the date the resource was last accessed and date the date the resource was last modified, just as one would expect.

Once again we have

\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
  lastmodified = {last modified}
}

Finally we have the driver, the piece of code that prints the bibliography entry

\DeclareBibliographyDriver{customa}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\addperiod\addspace}%or \setunit{\adddot\addspace}
  \iffieldundef{year}%
    {}
    {\printtext[parens]{\bibstring{lastmodified}\space\usebibmacro{date}}}%
  \setunit{\adddot\addspace}%
  \usebibmacro{title}%
  \setunit{\adddot\addspace}%
  \printlist{language}%
  \setunit{\adddot\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\adddot\addspace}%
  \usebibmacro{byeditor+others}%
  \setunit{\adddot\addspace}%
  \printfield{version}%
  \setunit{\adddot\addspace}%
  \printfield{note}%
  \newunit\newblock
  \printlist{organization}%
  \setunit{\adddot\addspace}%
  \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  \newunit\newblock
  \usebibmacro{url+urldate}%
  \setunit{\adddot\addspace}%
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{related}%
  \usebibmacro{finentry}%
}

This driver is almost a one-to-one copy of ieee.bbx's @online driver, save for a slight modification in the date area to print "last modified".

MWE

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

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

@customa{WikiMEMS,
  author = {Wikipedia},
  title = {Microelectromechanical systems},
  url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
  organization = {Wikipedia, The Free Encyclopedia},
  date = {2013-11-28},
  urldate = {2013-12-25},
}

\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 (ieee.bbx's @online driver)}}

\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
  lastmodified = {last modified}
}

\DeclareBibliographyDriver{customa}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\addperiod\addspace}%or \setunit{\adddot\addspace}
  \iffieldundef{year}%
    {}
    {\printtext[parens]{\bibstring{lastmodified}\space\usebibmacro{date}}}%
  \setunit{\adddot\addspace}%
  \usebibmacro{title}%
  \setunit{\adddot\addspace}%
  \printlist{language}%
  \setunit{\adddot\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\adddot\addspace}%
  \usebibmacro{byeditor+others}%
  \setunit{\adddot\addspace}%
  \printfield{version}%
  \setunit{\adddot\addspace}%
  \printfield{note}%
  \newunit\newblock
  \printlist{organization}%
  \setunit{\adddot\addspace}%
  \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  \newunit\newblock
  \usebibmacro{url+urldate}%
  \setunit{\adddot\addspace}%
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{related}%
  \usebibmacro{finentry}%
}

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

With biber we can instead define a new type @wiki just by defining the driver as above with wiki

\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
  lastmodified = {last modified}
}

\DeclareBibliographyDriver{wiki}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\addperiod\addspace}%or \setunit{\adddot\addspace}
  \iffieldundef{year}%
    {}
    {\printtext[parens]{\bibstring{lastmodified}\space\usebibmacro{date}}}%
  \setunit{\adddot\addspace}%
  \usebibmacro{title}%
  \setunit{\adddot\addspace}%
  \printlist{language}%
  \setunit{\adddot\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\adddot\addspace}%
  \usebibmacro{byeditor+others}%
  \setunit{\adddot\addspace}%
  \printfield{version}%
  \setunit{\adddot\addspace}%
  \printfield{note}%
  \newunit\newblock
  \printlist{organization}%
  \setunit{\adddot\addspace}%
  \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  \newunit\newblock
  \usebibmacro{url+urldate}%
  \setunit{\adddot\addspace}%
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{related}%
  \usebibmacro{finentry}%
}

The .bib file as expected

@wiki{WikiMEMS,
  author = {Wikipedia},
  title = {Microelectromechanical systems},
  url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
  organization = {Wikipedia, The Free Encyclopedia},
  date = {2013-11-28},
  urldate = {2013-12-25},
}

The MWE

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

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

@wiki{WikiMEMS,
  author = {Wikipedia},
  title = {Microelectromechanical systems},
  url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
  organization = {Wikipedia, The Free Encyclopedia},
  date = {2013-11-28},
  urldate = {2013-12-25},
}

\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 (ieee.bbx's @online driver)}}

\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
  lastmodified = {last modified}
}

\DeclareBibliographyDriver{wiki}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\addperiod\addspace}%or \setunit{\adddot\addspace}
  \iffieldundef{year}%
    {}
    {\printtext[parens]{\bibstring{lastmodified}\space\usebibmacro{date}}}%
  \setunit{\adddot\addspace}%
  \usebibmacro{title}%
  \setunit{\adddot\addspace}%
  \printlist{language}%
  \setunit{\adddot\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\adddot\addspace}%
  \usebibmacro{byeditor+others}%
  \setunit{\adddot\addspace}%
  \printfield{version}%
  \setunit{\adddot\addspace}%
  \printfield{note}%
  \newunit\newblock
  \printlist{organization}%
  \setunit{\adddot\addspace}%
  \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  \newunit\newblock
  \usebibmacro{url+urldate}%
  \setunit{\adddot\addspace}%
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{related}%
  \usebibmacro{finentry}%
}

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

Both MWEs above yield enter image description here


With biber one could now very easily add custom fields; for example a licence field, describing the terms of use of the @wiki entry. This can be done as described in How to include price in bibliography?.

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.