def add_eprint_to_bib(bib, eprint):
    """
    Insert the eprint information in a given bibtex string

    Parameters
    ----------
        bib: str
            The bibtex string without the arxiv number
        eprint: str
            The arxiv number

    Returns
    -------
        bib: str
            The bibtex string with the arxiv number
    """
    def bibtex_error():
        raise RuntimeError("CrossRef returned badly formed BibTeX file.")

    firstbrace = bib.find('{')
    if firstbrace == -1:
        bibtex_error()

    firstcomma = bib.find(',', firstbrace)
    if firstcomma == -1:
        bibtex_error()

    firstnewline = bib.find('\n', firstcomma)
    if firstnewline == -1:
        bibtex_error()

    bib = (bib[0:firstnewline] + '\n' + 
           '        eprint={' + eprint + '},\n' +
           '        archiveprefix={arXiv},' +
           bib[firstnewline:])

    return bib