112

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

3 Answers 3

96

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.

9
  • 2
    See addition to question.
    – Simd
    Jan 15, 2013 at 20:25
  • 3
    So Biber does not discard this stuff, whereas BibTeX does, whereas Biber respects %, whereas BibTeX does not?
    – cfr
    Feb 2, 2018 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, 2018 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, 2018 at 1:01
  • 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, 2018 at 1:48
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.

3
  • 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. Jan 28, 2016 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, 2016 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. Jan 28, 2016 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.

2
  • 1
    Note that there is a difference in behaviour between Biber (btparse) and BibTeX. See for example tex.stackexchange.com/q/261261/35864, tex.stackexchange.com/q/325696/35864.
    – moewe
    May 25, 2019 at 5: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. May 25, 2019 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .