6

I am using biblatex with biber from TL2018 for my PhD thesis. Due to various reasons, I am forced to use Mendeley for citation managements and cannot switch to another tool now. Mendeley is capable of generating a bib file - but it is compatible with only the classic natbib/bibtex combo (although it correctly escapes special characters).

I understand that with biblatex/biber combo, the month field is not a string, but rather must be an integer. So, as expected and discussed here, I get the warning

 [784] Utils.pm:193> WARN - month field 'Apr' in entry 'coolauthor2012' is not an integer - this will probably not sort properly.

Taking inspiration from a tangentially related question here, I used the following month -> integer hand-conversion in the preamble.

\DeclareSourcemap{
    \maps[datatype=bibtex]{
        \map[overwrite]{
            \step[fieldsource=month, match={jan}, replace=${1}]
            \step[fieldsource=month, match={feb}, replace=${2}]
            \step[fieldsource=month, match={mar}, replace=${3}]
            \step[fieldsource=month, match={apr}, replace=${4}]
            \step[fieldsource=month, match={may}, replace=${5}]
            \step[fieldsource=month, match={jun}, replace=${6}]
            \step[fieldsource=month, match={jul}, replace=${7}]
            \step[fieldsource=month, match={aug}, replace=${8}]
            \step[fieldsource=month, match={sep}, replace=${9}]
            \step[fieldsource=month, match={oct}, replace=${10}]
            \step[fieldsource=month, match={nov}, replace=${11}]
            \step[fieldsource=month, match={dec}, replace=${12}]
        }
    }
}

I have two nagging questions now.

  1. Will this work? I don't see any more of the aforementioned warnings, but I wonder if the citations are correctly sorted, and the month replacement was indeed accounted for and handled correctly.
  2. Is there a better way to handle this problem? Clearly, hand-mapping each month to an integer is not efficient.

This will help all folks who want to use mendeley especially for re-using their existing mendeley library for manuscript submissions to publishers who are mostly stuck behind in natbib/bibtex era.

  • Note that month = {apr}, is also wrong for most classical BibTeX styles, they just won't complain as loudly as Biber. – moewe Jun 28 '18 at 14:59
  • @moewe what should it be instead? I only looked at couple of examples , 'jan' and 'feb' and proceeded with the conversion assuming that the month fields generated by mendeley shall always be three-character abbreviations. Am I wrong? Is apr the only exception? – Dr Krishnakumar Gopalakrishnan Jun 28 '18 at 15:01
  • The three-letter abbreviations are valid but should be written without braces. So month = apr, would be correct. Naturally apr is not special and all months behave the same. – moewe Jun 28 '18 at 15:02
  • Ha. Got it.... I think I wasn't clear in the question. mendeley does indeed generate the month-fields in all entries in the exported bib file as {jan}, {feb}, {mar} and so on (with the braces). Also, I have no clue of using regexes. Does it mean that my replacement string is wrong? Should it be , replace=1, I also wonder that that $ is doing there. I'd appreciate some help in correctly formulating this month -> integer conversion command. – Dr Krishnakumar Gopalakrishnan Jun 28 '18 at 15:06
  • Sorry, my comment was not clear. I was just saying that Mendeley is wrong to produce these strings with braces even for BibTeX. (This is contradicting your claim that this is (only) compatible with natbib/BibTeX - it usually isn't.) – moewe Jun 28 '18 at 15:08
  • hmm... But mendeley is far too popular, particularly in the UK, right? I wonder why would they make such an elementary mistake? And, naturally one expects that such an error should have been noticed by someone else long time time". I am using the latest mendeley version 1.19.1. They claim bibtex compatibility in their manuals/software interface. Is there a credible source/reference link that you could point me to that supports your claim that month abbreviations should not be surrounded by braces? – Dr Krishnakumar Gopalakrishnan Jun 28 '18 at 15:11
  • http://mirrors.ctan.org/biblio/bibtex/base/btxdoc.pdf says: "You should use the standard three-letter abbreviation, as described in Appendix B.1.3 of the LaTeX book." which indeed does not specifically address whether or not the field value should be delimited. Item 9 on p. 13 uses undelimited months, which could give a hint towards best practice. I don't have the LaTeX book at hand to check what it has to say, but I can refer you to Q13 of http://mirrors.ctan.org/biblio/bibtex/contrib/doc/btxFAQ.pdf – moewe Jun 28 '18 at 15:23
  • @moewe amazing. Thanks for pointing to the reference. I wonder why mendeley cripples its users this way. – Dr Krishnakumar Gopalakrishnan Jun 28 '18 at 15:25
  • I assume they are just oblivious of the shortcomings of their current approach. Not many people need the month field and maybe some people don't care. Plus I'm not sure how large the LaTeX user base of Mendeley is. There are some long-standing issues with Mendeleys .bib export that have not been fixed (I think I once saw quite an old thread on a Mendeley feedback site about URLs and escaped characters, see also https://tex.stackexchange.com/questions/436684/c/436687#comment1095539_436684). (Re the months again: https://www.ece.ucdavis.edu/~jowens/biberrors.html) – moewe Jun 28 '18 at 15:31

1 Answers1

11
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=month, match=\regexp{\A(j|J)an(uary)?\Z}, replace=1]
      \step[fieldsource=month, match=\regexp{\A(f|F)eb(ruary)?\Z}, replace=2]
      \step[fieldsource=month, match=\regexp{\A(m|M)ar(ch)?\Z}, replace=3]
      \step[fieldsource=month, match=\regexp{\A(a|A)pr(il)?\Z}, replace=4]
      \step[fieldsource=month, match=\regexp{\A(m|M)ay\Z}, replace=5]
      \step[fieldsource=month, match=\regexp{\A(j|J)un(e)?\Z}, replace=6]
      \step[fieldsource=month, match=\regexp{\A(j|J)ul(y)?\Z}, replace=7]
      \step[fieldsource=month, match=\regexp{\A(a|A)ug(ust)?\Z}, replace=8]
      \step[fieldsource=month, match=\regexp{\A(s|S)ep(tember)?\Z}, replace=9]
      \step[fieldsource=month, match=\regexp{\A(o|O)ct(ober)?\Z}, replace=10]
      \step[fieldsource=month, match=\regexp{\A(n|N)ov(ember)?\Z}, replace=11]
      \step[fieldsource=month, match=\regexp{\A(d|D)ec(ember)?\Z}, replace=12]
    }
  }
}

This replaces either three-letter name abbreviations or full month names with the correct month number. Since Biber's RegExp is case sensitive this matches the lower-case month abbreviation and the version where the first letter is capitalised (i.e. jan and Jan). (biber 2.12 and higher support matchi for case-insensitive matches; see this issue.)

This is only needed to suppress the warnings that Biber throws when it is presented with

month = {mar},

even without this code the month will be correctly recognised.


Note that for most BibTeX styles month = {mar}, is also not the best (correct) form of input. The brace-less month = mar, is usually better because it is then converted to the desired output via BibTeX strings. Q13 of BibTeX Tips and FAQ

Q13: Should I use words or numerals for the month, edition, etc., fields, and why?

You should always use the three letter month macros (undelimited) for the name of the month (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec) as this lets each .bst file format the month names as is required for that bibliography style.

BTXdoc states on p. 10

month The month in which the work was published or, for an unpublished work, in which it was written. You should use the standard three-letter abbreviation, as described in Appendix B.1.3 of the LaTeX book

See also https://www.ece.ucdavis.edu/~jowens/biberrors.html

Danica
  • 148
moewe
  • 175,683
  • This does not work. I get an error ! Undefined control sequence. \blx@tempf ...e="month" map\string _match="\regex {\Ajan \Z }" map_replace="1" – Dr Krishnakumar Gopalakrishnan Jun 28 '18 at 15:17
  • @Krishna I forgot a p try again, please – moewe Jun 28 '18 at 15:18
  • Yay. Yes, got the regexp fixed. That did work! I wonder why mendeley folks haven't noticed that even their basic bibtex export is broken with the braces and stuff. But thank you for your help. Upvoted and marked as accepted. – Dr Krishnakumar Gopalakrishnan Jun 28 '18 at 15:22
  • Related https://tex.stackexchange.com/q/286261/35864 – moewe Jun 29 '18 at 08:24
  • This stopped working with a recent update of biblatex/biber. Sigh! I don't know why. Is this still working for you. – Dr Krishnakumar Gopalakrishnan Sep 09 '18 at 14:59
  • @Krishna There has not been an update for biblatex or Biber since February and the answer was posted in June so it was tested with the current version. I just tested in a short example and it still works for me (i.e. it suppresses the Biber warning one would get from month = {mar},). If it does not work for you, please ask a new question with an MWE and with the .blg file. – moewe Sep 09 '18 at 15:03
  • upon close inspection, the warning is due to lowercase month-names. How can the regex be widened to catch this one? I think it is preferable to update this question so that other Mendeley users facing this may have a single reference page . I asked the question here, but this is looks strongly like a duplicate to me. – Dr Krishnakumar Gopalakrishnan Sep 09 '18 at 15:17