[Tex/LaTex] Sort thebibliography by citation order

bibliographiessorting

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

Best Answer

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.