# Sort thebibliography by citation order

Can thebibliography be sorted by citation order? Or is there a solution with an inlined bibliography that can be sorted?

Not having an additional .bib file would be preferable.

My current bilbiography is inluded in the rest of the article inside a thebibliography block.

\begin{document}
\section{Example}
The citations in\cite{ne} the bibliography should\cite{flowers} be ordered
according which order they appear in the text.

\begin{thebibliography}{9}

\bibitem{fetebok} \emph{Internal Combustion Engine Fundamentals}

\bibitem{ne} \emph{Förbränningsmotorer}

\bibitem{flowers} \emph{HCCI Research Towards Development for Stationary Power
Applications}

\end{thebibliography}


Should output:

The citations in[1] the bibliography should[2] be ordered
according which order they appear in the text.

Bilbiography
[1] Förbränningsmotorer
[2] HCCI Research Towards Development for Stationary Power Applications
[3] Internal Combustion Engine Fundamentals

-
Welcome to tex.sx! It's not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting. –  Joseph Wright May 4 '11 at 9:41
The standard unsrt style does exactly this: a minimal example of your code would be very useful to give a more targeted answer. –  Joseph Wright May 4 '11 at 9:42
This is a duplicate of tex.stackexchange.com/questions/14976/…. This qn is a bit more clearly phrased and easier to find than the older qn, so it might be an idea to close the older one as a duplicate of this one. –  Charles Stewart May 4 '11 at 10:48
\bibliographystyle{unsrt} doesn't seem to work with \begin{thebibliography}. Nothing is changing anyway. –  Robert Foss May 4 '11 at 17:10
You might need to delete your .aux and .bbl files before it will work properly... –  Seamus May 4 '11 at 17:13

If you really need a bibliography sorted by citation order you have two choices:

(1) write the entries in thebibliography in citation order

(2) use a .bib file, \bibliographystyle{unsrt} and BibTeX.

There is a third choice, actually, but I did it just to prove it's possible:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}

\newcounter{mycite}
\newtoks\citetoks
\makeatletter
\DeclareRobustCommand\unscite[1]{%
\@ifundefined{uns@cite#1}
{\refstepcounter{mycite}\label{citelabel@#1}%
\expandafter\xdef\csname uns@cite#1\endcsname{\arabic{mycite}}%
\toks\z@=\expandafter{\the\citetoks}%
\toks\tw@=\expandafter\expandafter\expandafter{%
\csname uns@bibitem#1\endcsname}%
\edef\@tempcite{\the\toks\z@\the\toks\tw@}%
\global\citetoks=\expandafter{\@tempcite}%
}{}[\@nameuse{uns@cite#1}]}
\newcommand{\mybibitem}[2]{%
\@namedef{uns@bibitem#1}{\bibitem[\ref{citelabel@#1}]{#1}#2}}
\makeatother

% Define here the bibliography entries
\mybibitem{fetebok}{\emph{Internal Combustion Engine Fundamentals}}
\mybibitem{ne}{\emph{Förbränningsmotorer}}
\mybibitem{flowers}{\emph{HCCI Research Towards Development for Stationary
Power Applications}}

\begin{document}
\section{Example}
The citations in~\unscite{ne} the bibliography should~\unscite{flowers}
be ordered according which order they appear in the text.

\begin{thebibliography}{\arabic{mycite}}
\the\citetoks
\end{thebibliography}

\end{document}


Notice that this \unscite can't process lists of references or the optional argument like the usual \cite. It might be done, but I advise you against this approach.

-