[Tex/LaTex] How to customize bibtex numbering in a document

bibliographiesbibtexciting

I have a simple LaTeX document that has some BibTeX references:

\documentclass[12pt]{article}
\begin{document}
 
\section{First section}
 
This document is an example of \texttt{thebibliography} environment using 
in bibliography management. Three items are cited: \textit{The \LaTeX\ Companion} 
book \cite{latexcompanion}, the Einstein journal paper \cite{einstein}, and the 
Donald Knuth's website \cite{knuthwebsite}. The \LaTeX\ related items are
\cite{latexcompanion,knuthwebsite}. 
 
\medskip
\bibliographystyle{unsrt}
\bibliography{sample}
 
\end{document}

The output of this is as follows.

enter image description here

I would like to change the numbering of the reference in the text and in the References section with some set of specific numbers of my choice. How can I do this?

Let us say I would like to have something like this:

1 First section

This document is an example of thebibliography environment using in
bibliography management. Three items are cited: The LATEX Companion
book [11], the Einstein journal paper [22], and the Donald Knuth's website [33].
The LATEX related items are [11, 33].

References

[11] Michel Goossens, Frank Mittelbach, and Alexander Samarin. The LATEX
Companion. Addison-Wesley, Reading, Massachusetts, 1993.

[22] Albert Einstein. Zur Elektrodynamik bewegter Korper. (German) [On the
electrodynamics of moving bodies]. Annalen der Physik, 322(10):891{921,
1905.

[33] Donald Knuth. Knuth: Computers and typesetting.

Can I do this with LaTeX and BibTeX?

Best Answer

You can first prepare your bibliography in the usual way. Then you can set the numbers you prefer in the way shown below, by adding the code between %%START and %%END.

The filecontents environment is used just for the example, use your own database.

\begin{filecontents}{\jobname.bib}
@book{Knuth1984texbook,
    Author = {Knuth, D.E.},
    Title = {The \TeX book, volume A of Computers and typesetting},
    Publisher = {Addison-Wesley},
    Year = {1984},
}
@book{Chomsky1957,
    Address = {The Hague},
    Author = {Noam Chomsky},
    Publisher = {Mouton},
    Title = {Syntactic Structures},
    Year = {1957},
}
@book{Chomsky1965,
    Address = {Cambridge Mass.},
    Author = {Noam Chomsky},
    Publisher = {MIT Press},
    Title = {Aspects of the Theory of Syntax},
    Year = {1965},
}
\end{filecontents}

\documentclass{article}
\usepackage{xpatch} % also loads expl3

%%START
\makeatletter
\xpatchcmd{\@bibitem}
  {\item}
  {\item[\@biblabel{\changekey{#1}}]}
  {}{}
\xpatchcmd{\@bibitem}
  {\the\value{\@listctr}}
  {\changekey{#1}}
  {}{}
\makeatother

\ExplSyntaxOn
\cs_new:Npn \changekey #1
 {
  \str_case:nVF {#1} \g_changekey_list_tl { ?? }
 }
\cs_new_protected:Npn \setchangekey #1 #2
 {
  \tl_gput_right:Nn \g_changekey_list_tl { {#1}{#2} }
 }
\tl_new:N \g_changekey_list_tl
\cs_generate_variant:Nn \str_case:nnF { nV }
\ExplSyntaxOff

\setchangekey{Knuth1984texbook}{9}
\setchangekey{Chomsky1957}{3}
\setchangekey{Chomsky1965}{7}
%%END

\begin{document}
\section{First section}

This document is an example of \texttt{thebibliography} environment using 
 bibliography management. Three items are cited: \emph{Syntactic Structures} 
book \cite{Chomsky1957}, \emph{Aspects} \cite{Chomsky1965}, and  
Donald Knuth's \TeX book \cite{Knuth1984texbook}.

\bibliographystyle{plain}
\bibliography{\jobname}

\end{document}

enter image description here

I used the same data as Alan Munn just for laziness.

Related Question