10

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?

4
  • 1
    This seems a very strange thing to want to do. Do you want an arbitrarily assigned number to an arbitrary reference, or is there a system to this? In your example it looks like you want the citation number to be a multiple of 11. Is this by design?
    – Alan Munn
    Commented Jul 4, 2017 at 18:17
  • No. I have a set of numbers, say, 9, 3, and 14 and when I cite the first reference I would like it to appear as [9]. When I cite the second reference I would like to appear as [3]. Finally, when I cite the last reference, I would like it to appear as [14].
    – drzbir
    Commented Jul 4, 2017 at 18:51
  • I need this because I have a document with normal BibTeX references like [1], [2], etc. and I am writing a letter that uses some of the references of the document. So, for example, I need to cite references [9], [3] and [14] in the letter. If I use normal BibTeX I would get [1], [2] and [3].
    – drzbir
    Commented Jul 4, 2017 at 18:54
  • 1
    Since this is a one-off type use, I would do the citation numbers manually and use a normal list and the bibentry package to create the reference list. The approach here is what I have in mind: What is the most convenient way to create annotated bibliographies, e.g. in a literature review?
    – Alan Munn
    Commented Jul 4, 2017 at 20:11

4 Answers 4

12

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.

1
  • 1
    Note that when using hyperref you should replace \item by \H@item in the first \xpatchcmd to make it compatible (and hyperref should be imported before the patch).
    – Maxim
    Commented Mar 28, 2018 at 18:19
6

Here's a version of the solution I suggested to get you going. Given the limited use of this, it's probably not worth making the solution any more sophisticated. The basic syntax of a reference is:

\mycite{<number>}{<bib-key>}

If you want to refer to an already used citation (introduced with \mycite) you can simply use \ref{<bib=key}.

You then introduce the actual bibliography items using the \mybib for each item. These will appear with the number you used in the \mycite command, and will appear in the order in which you enter them in the itemize environment.

\begin{filecontents}{\jobname.bib}

@book{Knuth1984texbook,
    Author = {Knuth, D.E.},
    Title = {The TEXbook, volume A of Computers and typesetting},
    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[12pt]{article}
\usepackage{natbib}
\usepackage{calc}
\usepackage{etoolbox}
\usepackage{bibentry}
\usepackage{enumitem}
\SetLabelAlign{bibright}{\hss\llap{[#1]}}
\newcounter{mynum}
\newcommand\mycite[2]{[#1]\setcounter{mynum}{0}\addtocounter{mynum}{#1-1}\refstepcounter{mynum}\label{#2}}
\newcommand\mybib[1]{\item[\ref{#1}]\bibentry{#1}}

\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 \mycite{6}{Chomsky1957}, \emph{Aspects} \mycite{4}{Chomsky1965}, and  
Donald Knuth's TeXBook \mycite{10}{Knuth1984texbook}. The Linguistics related items are
[\ref{Chomsky1965},\ref{Chomsky1957}].
\medskip
\bibliographystyle{unsrtnat}
\nobibliography{\jobname}
\begin{itemize}[labelwidth=!,labelsep=1em,align=bibright]
\mybib{Chomsky1957}
\mybib{Chomsky1965}
\mybib{Knuth1984texbook}
\end{itemize}
\end{document}

output of code

2

After reading your comments, I think there is mauch easier way: There is the nice package xcite, this will let you import cites from your other document and you don't need to worry about the numbers (the following example assumes that the other document is called document.tex):

\documentclass{article}

\usepackage{xcite}
\externalcitedocument{document}

\begin{document}

\cite{knuth}


\end{document}
1
  • This is very useful if you have access to the source code of the other document! Commented Aug 21 at 8:03
1

Since the question is really about using custom labels to entries in the bib-database, I would like to add that there is a standard way of doing this with Biblatex. Simply use the data field shorthand, which will override the standard shorthand for only that entry in the database. I put some letters in the following minimal working example, but you can of course put numbers or what you like.

\begin{filecontents}{thebib.bib}
@article{Boll,
author = {Boll, Grodan},
title = {Frogs now and then},
year = 1995,
journal = {Allers},
volume = 3,
shorthand = {FN\&T}
}
\end{filecontents}
\documentclass{article}
\usepackage{biblatex}
\addbibresource{thebib.bib}
\begin{document}
Frogs are common, see also \cite{Boll}.
\printbibliography
\end{document}

This gives the output Screenshot from PDF file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .