[Tex/LaTex] Bibtex ordering by appearence of the .bib file instead of the .tex file

bibtexsorting

I'm using TexMaker + BibTex + XeLaTeX and everything was fine, until I noticed that it was ordering the references by the .bib file order instead of the .tex file order. So it starts at [5] instead of [1] because my first citation it's the 5th element in the bib file.

This are the packages which I'm using:

\usepackage{graphicx} % images
\usepackage{fontspec} %font to show accents in xelatex
\usepackage{url} %for urls
\usepackage[portuguese]{babel} %portuguese documment
\usepackage{color} %for text color

I put the references before the end document:

\bibliographystyle{IEEEtran} %for IEEE references style
\bibliography{references}
\end{document}

Also I always do the F1F11F1F1 to compile.

Best Answer

When a \nocite{*} appears in the document, all entries in the .bib database are automatically inserted in the bibliography, with the same order as specified by the chosen bibliography style, in the case of IEEEtran it's "unsorted".

Find the offending command and remove it, or place it at the end, where it won't influence the "unsorted" order of explicit citations. Of course, using \nocite{*} in such a document requires organizing the .bib file in some sensible order, so I'd recommend not using it. If you want to have some entry in the bibliography that wasn't cited in the document, use

\nocite{<key1>,<key2>,...}

just before the \bibliography{command}, where the keys are ordered as you wish.