# two documents sharing same reference numbering

I am writing a scientific paper with supplementary information in an additional document. The paper and the supplement share many references, which in the paper are numbered by first appearance in the text.

I would like the references in the supplement to have the same numbers as in the paper. I have additional references there and not all references from the paper show up in the supplement.

I am still working on the documents and the `.bib`-file is changing. It is generated by Icculus Referencer.

Is there a way to achieve the numbering the way I like? I haven't tried, but I think, that one way could be to create a `.bib`-file with all references that I want to use and then number all of them, regardless of their use in the current document. The problem is, that when I change the first appearance of one reference, I have to change the order of the bibtex-entries in the `.bib`-files, which is not very handy.

-
 Should the bibliography in the supplement contain also the referenced items that appear in the main document? – egreg Dec 4 '11 at 17:24 @egreg, that is not specified by the journal, so it does not matter. – Sebastian Langer Dec 6 '11 at 15:05

You could try using the `\nocite` command (see this Wikibook entry for a quick explanation)... there's also a `\nocite{*}` command to list a whole `bib` file (see this TeX FAQ entry).

EDIT: referring to my comment below... I came up with an UGLY Python script to do just that:

``````import re

# input and output files
input = 'in.tex'
output = 'out.tex'

# remove duplicates whilst preserving order
def uniq (seq):
seen = set ()
return [x for x in seq if x not in seen and not seen_add (x)]

# pattern to look for
pat = '((\\cite)|(\\citet)|(\\citep)|(\\citet\*)|(\\citep\*)|(\\citeauthor)|(\\citeauthor\*)|(\\citeyear)|(\\citeyearpar)|(\\citealt)|(\\citealp))(\[.*?\])?\{(.*?)\}'

# get the file
f = open (input)
# close it
f.close ()

# get the list of references, with no duplicates, and preserving order
ms = uniq ((','.join ([(list (x))[-1:][0] for x in re.findall (pat, i)])).split (','))

# initialize output to empty string
o = ''

# for every reference...
for m in ms:
# generate \nocite command
o += '\\nocite{' + m + '}\n'

# open output file
f = open (output, 'w')
# write output away
f.write (o)
# close it
f.close ()
``````

change `input` (`in.tex`) and `output` (`out.tex`) as needed, run it through Python, and you'll get the `\nocite`s in the order in which they first appeared in the input file.

Hope it helps! ;)

EDIT 2: changed the regular expression to support all the cite type given in this Wikibook entry.

-
`\nocite{*}` is helpful for listing uncited bibentries in the bibliography. The OP's question, however, is about a "unified" numbering scheme for multiple documents. – lockstep Dec 8 '11 at 19:04
@lockstep: Although this is not the answer to my problem, it hints to a painful workaround. Using \nocite{*} on a bibliography, that is preordered according to first appearance of citations in a document, I get the right numbering of citations in the document, but unfortunately all the references are listed in both documents. If I could find a way to filter the unused ones out again, I would be fine. Unfortunately there are 2 problems: 1. I have to presort the bibliography, 2. I don't know, how to eliminate the unused references. – Sebastian Langer Jan 6 '12 at 1:25
I think one could write a Python / Perl / Bash / whatever script to get the reference's keys from your "main" paper (by looking for `\cite` commands), then write out `\nocite`s for them to a file, say `mainrefs.tex`. Then in your "secondary" paper you could `\input{mainrefs}` at the very beginning ;) – mpr Jan 6 '12 at 12:10
Done just that in the answer proper ;) – mpr Jan 6 '12 at 14:27