[Tex/LaTex] Incorrect order of references

bibliographiessorting

I am preparing a draft in two column format, but unfortunately I have a major problem: I have written my references in a separately text file and called that art-bib, also I have used of

\begin{thebibliography}{}

     \include{art-bib}

\end{thebibliography}

for summons that.

Although it calls references, but in such an arrangement on which had written reference file and not the order of calling them. For example:

The first sentence~\cite{ref5} and after that the second sentence~\cite{ref10} and so on.. 

It writes to me as:

The first sentence [5] and after that the second sentence [10] and so on..

I expect I have :

The first sentence [1] and after that the second sentence [2] and so on..

Best Answer

If you compile the following example

\documentclass{article}

\begin{document}

\cite{ugly} and \cite{good} followed by \cite{bad}

\begin{thebibliography}{3}

\bibitem{good} C. Eastwood, \emph{A good paper}, Journal \textbf{42} (2015), pp.~1--2.

\bibitem{bad} L. Van Cleef, \emph{A bad paper}, Journal \textbf{42} (2015), pp.~3--4.

\bibitem{ugly} E. Wallach, \emph{An ugly paper}, Journal \textbf{42} (2015), pp.~5--6.

\end{thebibliography}

\end{document}

LaTeX produces

enter image description here

Using \input{art-bib}, where art-bib.tex contains the bibliographic data, is the same. Don't call \include for this in any case: it is wrong.

LaTeX does no sorting whatsoever. You can do this without using BibTeX, provided you add some macros and type in the bibliographic data in a different way.

\documentclass{article}

\makeatletter
\renewcommand{\citation}[1]{%
  \g@addto@macro{\citation@list}{,#1}%
}
\newcommand*{\citation@list}{} % initialize
\newcommand{\sortbibitem}[2]{%
  \global\@namedef{bibitem@#1}{%
    \bibitem{#1} #2
  }%
}
\newcommand{\sort@bibitems}{%
  \@for\next:=\citation@list\do{%
    \@nameuse{bibitem@\next}%
    \global\@namedef{bibitem@\next}{}%
  }%
}
\expandafter\def\expandafter\endthebibliography\expandafter{%
  \expandafter\sort@bibitems\endthebibliography
}
\makeatother

\begin{document}

\cite{ugly} and \cite{good} followed by \cite{bad}

Again \cite{good}

\begin{thebibliography}{3}

\sortbibitem{good}{C. Eastwood, \emph{A good paper}, Journal \textbf{42} (2015), pp.~1--2.}

\sortbibitem{bad}{L. Van Cleef, \emph{A bad paper}, Journal \textbf{42} (2015), pp.~3--4.}

\sortbibitem{ugly}{E. Wallach, \emph{An ugly paper}, Journal \textbf{42} (2015), pp.~5--6.}

\end{thebibliography}

\end{document}

enter image description here

This is not provided by the LaTeX kernel, because BibTeX is much better at it. Prepare a file art-bib.bib containing

@article{good,
  author={Eastwood, C.},
  title={A good paper},
  journal={Journal},
  volume={42},
  year=2015,
  pages={1-2},
}
@article{bad,
  author={Van Cleef, L.},
  title={A bad paper},
  journal={Journal},
  volume={42},
  year=2015,
  pages={3-4},
}
@article{ugly,
  author={Wallach, E.},
  title={An ugly paper},
  journal=Journal},
  volume={42},
  year=2015,
  pages={5-6},
}

Then your document can be

\documentclass{article}

\begin{document}

\cite{ugly} and \cite{good} followed by \cite{bad}

\bibliographystyle{unsrt}
\bibliography{art-bib}

\end{document}

Let's say your main file is named myarticle.tex. Upon compilation with pdflatex myarticle, you run bibtex myarticle and again pdflatex (twice if the terminal tells you to).

The output will be essentially the same. The big advantage is that the data in art-bib.bib is reusable in several different formats, as specified by the bibliography style you select with the \bibliographystyle command.

Note that the above type of sorting is only possible with the order of citation. Alphabetical sorting by author can only be obtained with BibTeX or its successors biblatex/Biber.

Related Question