111

What's the correct way to comment out sections of explanatory text (included for humans to read) in a .bib file? I would like biber/biblatex to simply ignore this text.

When I put in text like

#######################################################################
## PREPRINTS

I get warnings like

WARN - BibTeX subsystem: /tmp/8XsEEmjVOo/bib-latest.bib_14175.utf8, line 7, warning: 139 characters of junk seen at toplevel
Simd
  • 6,785

3 Answers3

95

Anything that is not inside a recognized entry is a comment. So just type along! Any .bib interpreter that complains about it is buggy, as it is not following the rules laid down in btxdoc. However, you can use an entry like @COMMENT, which will hopefully not trigger any complains.

mafp
  • 19,096
  • 2
    See addition to question. – Simd Jan 15 '13 at 20:25
  • 3
    So Biber does not discard this stuff, whereas BibTeX does, whereas Biber respects %, whereas BibTeX does not? – cfr Feb 02 '18 at 23:10
  • 1
    @cfr I think you are correct. a bit messy really. but personally I prefer biber's behaviour as it is basically what you would expect from a tex file and more flexible. – ArTourter May 10 '18 at 12:13
  • @ArTourter But it still spews warnings about it all, which TeX wouldn't. It's a comment - why does Biber tell me it's junk? – cfr May 22 '18 at 01:01
  • @cfr, what do you mean? Are you saying that biber is spewing warnings when you use the % comment syntax or the @COMMENT one? It doesn't say anything for me about the % and I used these things all over the place. – ArTourter May 24 '18 at 19:52
  • @cfr, actually I just tried to have a @COMMENT{} entry in my bib file and biber (version 2.11, from texlive 2018) didn't complain at all. – ArTourter May 24 '18 at 20:26
  • 1
    @ArTourter I use % and it spews warnings all the time. I know I can ignore them, but it is a pain as they clutter the output. – cfr May 25 '18 at 01:48
  • @cfr can you give me an mwe for something that spew out warnings? as I can't reproduce at all... also may this conversation might be better off in a chat – ArTourter May 25 '18 at 10:31
  • @ArTourter Sorry. I think I'm just wrong. I can't reproduce it either. I was sure this was the reason I get all those junk warnings, but maybe it isn't. Probably something else. Apologies for the wild goose chase. – cfr May 26 '18 at 00:54
42

At least with biber, you should be able to use the same commenting method as with LaTeX, that is using % for the commented line.

After a few test comments can be outside entries, within entries (commenting a whole line) or commenting the end of a line.

%%%%%%%%%%%
% PREPRINT
@article{myarticle,
    author = {Onymous, A. N.}, %The author
    % the title of the article
    title = {A Nice title},
}

Should work as expected. However this may not be the case with bibtex.

ArTourter
  • 17,315
  • 9
    Re: "However this may not be the case with bibtex". Indeed, this does not seem to work with bibtex. I have an entry in my .bib file with a line like author = {Onymous, A. N.}, %The author in it. In TeXShop, when I hit the Typeset button with BibTex selected in the drop down next to it, I get a message in the console saying "You're missing a field name" and "I'm skipping whatever remains of this entry". The rest of my entry was indeed ignored and I got an incomplete reference in my .pdf. – Jacob Akkerboom Jan 28 '16 at 11:44
  • @JacobAkkerboom no but the question was about biber/biblatex. I never claimed that this solution would work with bibtex. – ArTourter Jan 28 '16 at 19:29
  • yes, you are right. I felt it was worth investigating, but now that I realise the question is probably about alternatives to bibtex, I realise my comment is probably not so useful. I'm quite a novice at these things, do you think mine is a case of a buggy .bib interpreter, as the other answer suggests? Thanks for your reply. – Jacob Akkerboom Jan 28 '16 at 19:43
21

I had difficulties commenting out entries in a .bib file (as opposed to adding free-standing comments). Posts to date on this thread did not address this particular problem.

I'm using Overleaf). What I observed:

  • bibtex looks for entries (@blah) before it checks if the line starts with a % (or so I figured).
  • but only that line gets processed; if you commented out the entire entry the rest of it (title=, etc) is ignored and you end up with errors ('missing field') attributable to @blah

Sheesh.

This doesn't work:

%@article{foo2019,
% ...
% }

This works (replace the @):

%%article{foo2019,
% ...
% }

I poked around in Overleaf and found this explanation (note that mine, above, is a bit different):

% is actually not a comment character in .bib files! So, inserting a % in .bib files not only fails to comment out the line, it also causes some BibTEX errors. To get BibTEX to ignore a particular field we just need to rename the field to something that BibTEX doesn’t recognise. For example, if you want to keep a date field around but prefer that it’s ignored (perhaps because you want BibTEX to use the year field instead) write Tdate = {...} or the more human-readable IGNOREdate = {...}.

To get BibTEX to ignore an entire entry you can remove the @ before the entry type. A valid reference entry always starts with a @ followed by the entry type; without the @ character BibTEX skips the lines until it encounters another @.

bibtex is very focused on @; biber apparently respects %s (but you'd have to use biblatex). See pointers provided by moewe (in the comments) for other discussion.

  • 1
    Note that there is a difference in behaviour between Biber (btparse) and BibTeX. See for example https://tex.stackexchange.com/q/261261/35864, https://tex.stackexchange.com/q/325696/35864. – moewe May 25 '19 at 05:15
  • Thank you Kurt & moewe. I looked into things a bit more carefully and amended the post. When you search for a particular problem you typically get a bunch of hits. If you're lucky you click on the right one. Sometimes you don't. – Alex Rudnicky May 25 '19 at 21:05