[Tex/LaTex] 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.

Best Answer

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 ()
    seen_add = seen.add
    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)
#read it into i
i = f.read ()
# 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 \nocites 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.