2

Entries in my .bib file have a field in the date={year--month--day} format and in the bibliography it prints: April 1999 for instance. I want it to be simply 1999.

How can you do it with the unsrtnat bibliography style?

I tried to find the entry in the file unsrtnat.bst but changing the format.date function didn't work either. Do You have an idea?

edit: changed the format.date fucntion from:

FUNCTION {format.date} { year duplicate$ empty$ { "empty year in " cite$ * warning$ pop$ "" } 'skip$ if$ month empty$ 'skip$ { month " " * swap$ * } if$ extra.label * } 

to:

FUNCTION {format.date} { year duplicate$ empty$ { "empty year in " cite$ * warning$ pop$ "" } 'skip$ if$ month empty$ 'skip$ { } if$ extra.label * } 

but it didnt work

13
  • Sorry, natbib? Your question seems to be about biblatex? – Johannes_B Mar 12 '16 at 13:08
  • 1
    Sorry, should have read more carefully. Does natbib really support the date field? If so, don't use -- to separate year, month and day, – Johannes_B Mar 12 '16 at 13:09
  • Please confirm that you're using the unsrtnat bibliography style. As @Johannes_B already commented, the unsrtnat style isn't programmed to recognize, let alone process, a field named date; it does, however, recognize fields named year and month. – Mico Mar 12 '16 at 13:13
  • I export the bib file from zotero and i do not want to change the entries manually – velocity911 Mar 12 '16 at 13:13
  • yeah i use unsrtnat. But is reads the month from the date entry so it seems so work? – velocity911 Mar 12 '16 at 13:14
4

To modify the unsrtnat bibliography style so that month-related information is ignored, I suggest you take the following steps:

  • Find the file unsrtnat.bst in your TeX distribution and make a copy of this file. Name the copy, say, unsrtnat-nomonth.bst. (Do not edit a file from the TeX distribution directly.)

  • Open unsrtnat-nomonth.bst in a text editor. (The editor you use to modify your tex files will do fine.

  • Locate the function format.date. (It should start around line 417 of the file.) It should look like this:

    FUNCTION {format.date}
    { year duplicate$ empty$
        { "empty year in " cite$ * warning$
           pop$ "" }
        'skip$
      if$
      month empty$
        'skip$
        { month
          " " * swap$ *
        }
      if$
      extra.label *
    }
    
  • Delete the lines from month empty$ to the second if$. The modified function should look like this:

    FUNCTION {format.date}
    { year duplicate$ empty$
        { "empty year in " cite$ * warning$
           pop$ "" }
        'skip$
      if$
      extra.label *
    }
    
  • Save the file unsrtnat-nomonth.bst either to the directory where your main tex file is located or in a directory that's searched by BibTeX. If you choose the second option, be sure to also update the filename database of your TeX distribution.

  • In your main tex file, change \bibliographystyle{unsrtnat} to \bibliographystyle{unsrtnat-nomonth}. Then, re-run LaTeX, BibTeX, and LaTeX twice more to fully propagate all changes.

Happy BibTeXing!

A full MWE (with unsrtnat-nomonth.bst set up as described in the preceding material)

enter image description here

If unsrtnat were in use instead of unsrtnat-nomonth, one would get:

enter image description here

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{mybib.bib}
@article{xyz,
  author  = "X",
  title   = "Y",
  journal = "Z",
  year    = 3001,
  month   = "January",
  date    = "11-11-3001",
}
\end{filecontents}
\bibliographystyle{unsrtnat-nomonth}
\usepackage{natbib}
\begin{document}
\nocite{*}
\bibliography{mybib}
\end{document} 
5
  • I did this before but now the year is also missing! – velocity911 Mar 12 '16 at 13:40
  • @velocity911 - Please check how you've edited your code. Does the blg file report any errors? I've posted an addendum with an MWE that shows the outputs created by both unsrtnat-nomonth and unsrtnat. There seems to be no problem with showing the contents of the year field. – Mico Mar 12 '16 at 13:51
  • i have only date, no month try. Could that cause the problem? in your NWE you have a month field . – velocity911 Mar 12 '16 at 14:12
  • @velocity911 - If your entry has no month field to begin with, the unsrtnat bibliography style won't show any month-related information either. It will certainly not "borrow" month-related information from the field named date. Give it a try: Do recompile the MWE shown above with the month field deleted (or renamed) and the date field intact. (Remember to always run LaTeX, BibTeX, and LaTeX twice more to fully propagate all changes.) – Mico Mar 12 '16 at 14:18
  • your instruction was very usefull! it worked now! exactly as you said – velocity911 Mar 12 '16 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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