pcubillos / bibmanager

A BibTeX manager for LaTeX projects
https://bibmanager.rtfd.io
MIT License
62 stars 13 forks source link

importing pdfs from relative file locations #84

Closed rhaynes74 closed 3 years ago

rhaynes74 commented 3 years ago

Hi folks, my .bib file has some 2500 papers. The pdfs exist for all but a dozen or so. The bibtex file has file= entries but the paths are relative paths, not absolute paths. Can I still import these in a way that I will be able to open them with bibmanager?

Best, R Haynes

pcubillos commented 3 years ago

Hi, The code should have no problems opening the PDFs once you link them to the entries. But note that when you link a PDF, the PDF file is moved form their current location to the bibmanager home directory. Take a look at the docs for more details and examples: https://bibmanager.readthedocs.io/en/latest/pdf.html#id1

rhaynes74 commented 3 years ago

Hi - thanks for the reply.  Just so that I am clear - is the software automatically able to link files from the

file=

entries in the .bib file?

Sincerely,

Dr. Ronald D. Haynes

Professor, Department of Mathematics and Statistics Chair, MSc and PhD Scientific Computing Programs Memorial University of Newfoundland

We acknowledge that the lands on which Memorial University’s campuses are situated are in the traditional territories of diverse Indigenous groups, and we acknowledge with respect the diverse histories and cultures of the Beothuk, Mi’kmaq, Innu, and Inuit of this province. On Jan 21, 2021, 4:15 AM -0330, Patricio Cubillos notifications@github.com, wrote:

Hi, The code should have no problems opening the PDFs once you link them to the entries. But note that when you link a PDF, the PDF file is moved form their current location to the bibmanager home directory. Take a look at the docs for more details and examples: https://bibmanager.readthedocs.io/en/latest/pdf.html#id1 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

pcubillos commented 3 years ago

Hi, Ahhh, I think I understand now the original question. So, you have something like this for the entries, right? :

@article{bibtexkey,
  author= ...,
  ...
  file=/path/to/file.pdf,
  ...
  }

No, the bibmanager code does not automatically recognize the file key as the PDF from the entries. Users need to run one of the bibm pdf commands to link PDF files to the entries.

Since you have this format, you could link the PDFs to their BibTeX entries with a simple short script. I have a good idea of how to do this if you want. But keep in mind that then the files will be moved from their locations into the bibmanager home folder.

rhaynes74 commented 3 years ago

Any suggestions as to the best way to handle this automatically for 2400+ papers? (all of which have a file= entry in the .bib file.

Sincerely,

Dr. Ronald D. Haynes

Professor, Department of Mathematics and Statistics Chair, MSc and PhD Scientific Computing Programs Memorial University of Newfoundland

We acknowledge that the lands on which Memorial University’s campuses are situated are in the traditional territories of diverse Indigenous groups, and we acknowledge with respect the diverse histories and cultures of the Beothuk, Mi’kmaq, Innu, and Inuit of this province. On Jan 22, 2021, 5:20 AM -0330, Patricio Cubillos notifications@github.com, wrote:

Hi, Ahhh, I think I understand now the original question. So, you have something like this for the entries, right? : @article{bibtexkey, author= ..., ... file=/path/to/file.pdf, ... } No, the bibmanager code does not automatically recognize the file key as the PDF from the entries. Users need to run one of the bibm pdf commands to link PDF files to the entries. Since you have this format, you could link the PDFs to their BibTeX entries with a simple short script. I have a good idea of how to do this if you want. But keep in mind that then the files will be moved from their locations into the bibmanager home folder. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

pcubillos commented 3 years ago

Hi, this Python3 script should do the trick.

import bibmanager.bib_manager as bm
import bibmanager.pdf_manager as pm
import bibmanager.utils as u

for bib in bm.load():
    fields = u.get_fields(bib.content)
    bibkey = next(fields)
    for key, value, nested in fields:
        if key == file:
            try:
                pm.set_pdf(bib.key, pdf=value, filename=None, replace=True)
            except Exception as e:
                print(str(e))