4

I have exported the bibliography from Zotero in biblatex format. All the references contain a date field, but now year field.

Is there a simple way (a tool, a script etc.) to convert the date field or to append year and month fields?

Example:

@article{kattan_timeseries_2015,
  title = {Time-series event-based prediction: An unsupervised learning framework based on genetic programming},  
  journaltitle = {Information Sciences},
  author = {Kattan, Ahmed and Fatima, Shaheen and Arif, Muhammad},
  date = {2015-04}
}

and I want to be

@article{kattan_timeseries_2015,
  title = {Time-series event-based prediction: An unsupervised learning framework based on genetic programming},  
  journaltitle = {Information Sciences},
  author = {Kattan, Ahmed and Fatima, Shaheen and Arif, Muhammad},
  date = {2015-04},
  year = {2015},
  month = {04}
}
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Marco Daniel Sep 5 '15 at 10:01
  • You want a modification of an existing bib-file. From my point of view there is no relation to LaTeX/TeX but rather to perl – Marco Daniel Sep 5 '15 at 10:15
  • Why do you want it? Biblatex/biber can/will extract the year from the date. – Ulrike Fischer Sep 5 '15 at 10:20
  • 1
    biblatex can deal with the date field in YYYY-MM-DD format. If you actually use biblatex in the end, this will only confuse everyone involved. And if you don't you shouldn't export in biblatex format in the first place, I think. – moewe Sep 5 '15 at 12:52
  • Interestingly, the contents of the date field always override the contents of the year and month field; the day field is not overwritten if it comes after the date field. – moewe Sep 5 '15 at 12:58
5

This is something Biber can do in its tool mode.

We need the following config file, called say biber-date.conf

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <output_fieldcase>lower</output_fieldcase>
  <sourcemap>
    <maps datatype="bibtex" map_overwrite="1">
      <map map_overwrite="1">
        <map_step map_field_source="date" map_match="[0-9]{4}?-([0-9]{2}?)" map_final="1"/>
        <map_step map_field_set="month" map_field_value="$1"/>
      </map>
      <map map_overwrite="1">
        <map_step map_field_source="date" map_match="([0-9]{4}?)" map_final="1"/>
        <map_step map_field_set="year" map_field_value="$1"/>
      </map>
    </maps>
  </sourcemap>
</config>

The regular expressions are not particularly elegant, but the first one copies the month position of the date field to the month field, the second maps the year position to the year field.

Now you just need to run biber --tool --configfile=biber-date.conf <yourbibfile>

On the example file augustus.bib

@article{kattan_timeseries_2015,
  title = {Time-series event-based prediction: An unsupervised learning framework based on genetic programming},  
  journaltitle = {Information Sciences},
  author = {Kattan, Ahmed and Fatima, Shaheen and Arif, Muhammad},
  date = {2015-04}
}
@book{lorem,
  title = {Lorem},  
  author = {Anne Uthor},
  date = {2015}
}
@book{ipsum,
  title = {Ipsum},  
  author = {Anne Uthor},
  date = {2015-08-07},
}

the output (which you can find in augustus_bibertools.bib after the biber --tool --configfile=biber-date.conf augustus.bib run) is

@article{kattan_timeseries_2015,
  author       = {Kattan, Ahmed and Fatima, Shaheen and Arif, Muhammad},
  date         = {2015-04},
  journaltitle = {Information Sciences},
  month        = {04},
  title        = {Time-series event-based prediction: An unsupervised learning framework based on genetic programming},
  year         = {2015},
}

@book{lorem,
  author = {Anne Uthor},
  date   = {2015},
  title  = {Lorem},
  year   = {2015},
}

@book{ipsum,
  author = {Anne Uthor},
  date   = {2015-08-07},
  month  = {08},
  title  = {Ipsum},
  year   = {2015},
}
  • If you also add <output_resolve>1</output_resolve> Biber will automatically resolve crossrefs/xrefs with inheritance, together with <output_safechars>1</output_safechars> you might come very close to creating a fully (BibTeX) downward-compatible version of your .bib file. (Though there is no such thing as "BibTeX compatible" as different styles support different fields.) – moewe Sep 5 '15 at 19:22
  • But please note the caveat mentioned in my comment to the question. A year and month field together with a date field will confuse Biber quite a bit, that is something one should avoid. Note that in the solution above possibly existing month and years are overwritten (the map_overwrite="1" does that). – moewe Sep 5 '15 at 19:53

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.