# Randomly undefined citations, depending on order in .bib file

I'm using BibTex to build my bibliography. I have a lot of references and most of them work fine, but for some reason LaTeX claims some of them are undefined.
Here's a part of my .bib file:

@misc{REF1,
title={{Title 1}},
url={https://url.one/},
journal={url.one},
},

@misc{REF2,
title={{Title 2}},
url={https://url.two/,
author={Author, Two},
year={2}
},

@misc{REF3,
title={{Title 3}},
author={Author, Three},
year={3}
},

@book{REF4,
place={Place 4},
title={Title 4},
publisher={Publisher 4},
author={Author, Four},
year={4}
},


This way, all citations are fine, except for REF3. Switching REF2 and REF3 from place in the .bib file suddenly makes REF4 undefined.

I'm not sure what's going wrong here.

My main.tex file is built from a bunch of other .tex files which I \input{}, and at the end of this file I insert my bibliography in IEEEtran style.

• Welcome to TeX.SX! The extra , after the entries is unnecessary (if not wrong) and you are missing a } in url={https://url.two/, in REF2. Jun 12 '19 at 10:11
• Ah, well, that explains it... I used a program that auto-generates citations which insert the commas for some reason. I also don't understand how I didn't notice the missing bracket, I've been staring at it for so long. Thanks for lending me your attention to detail! Jun 12 '19 at 10:15
• No problems :-) I checked and the extra commas are accepted there (they are just ignored), so the only problem is the missing }. However the commas do change the error message! If you look at the <main text name here>.blg (which you should, when there are problems with the bibliography) the error message is more clear without the commas (it says I was expecting a ,' or a }' instead of the more cryptic "{" immediately follows a field name). Jun 12 '19 at 10:22

Never disregard error messages or warnings: upon running BibTeX, I get

This is BibTeX, Version 0.99d (TeX Live 2019)
The top-level auxiliary file: joshua.aux
The style file: plain.bst
Database file #1: joshua.bib
"{" immediately follows a field name---line 14 of file joshua.bib
: @misc
:      {REF3,
I'm skipping whatever remains of this entry
Warning--I didn't find a database entry for "REF3"
Warning--to sort, need author or key in REF1
Warning--to sort, need author or key in REF2
(There was 1 error message)


So it's not of a surprise that REF3 turns out to be unknown: BibTeX is exactly telling you so.

Fix REF2 to be

@misc{REF2,
title={{Title 2}},
url={https://url.two/},
author={Author, Two},
year={2}
}


The commas after entries are useless, but not harmful either, because BibTeX ignores material that is not between @<TYPE>{...} or @<TYPE>"..." (the former syntax should be preferred): see https://tex.stackexchange.com/a/21710/4427

1. Don't use commas between citations
2. Don't forget { and } brackets. If you've stared yourself blind at trying to find a missing bracket, ask someone for help.

Thanks Phelype Oleinik