LaTeX forum ⇒ BibTeX, biblatex and biberMake addbibresource{} choose one out of many .bib

Information and discussion about BiBTeX - the bibliography tool for LaTeX documents.
arstaer
Posts: 12
Joined: Sun Jun 17, 2012 5:56 am

Make addbibresource{} choose one out of many .bib

Postby arstaer » Sat Mar 26, 2016 2:46 am

Dear all,

Here is the issue, I plan to make
  1. \addbibresource{}
to look for .bib files in different folders and choose the ones that are available without throwing errors if one of the bib files is not in the location specified.

Basically,
  1. \addbibresource{Zotero2012.bib}
  2. \addbibresource{T:/MYDOCS~1/MYBIBT~1/Zotero2012.bib}


Should skip the first one if it's not there and choose the second one if it's in that location and if it's in both locations, use both.

At the moment, if the first file is missing, but the 2nd one is present, the citations still don't get resolved.

That's to facilitate working with coauthors without uploading anything to the cloud.

Would appreciate any help! :)

Thank you,

AS

Tags:

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Sat Mar 26, 2016 3:56 pm

You probably want something like

  1. \IfFileExists{Zotero2012.bib}
  2. {\addbibresource{Zotero2012.bib}}
  3. {}
  4. \IfFileExists{T:/MYDOCS~1/MYBIBT~1/Zotero2012.bib}
  5. {\addbibresource{T:/MYDOCS~1/MYBIBT~1/Zotero2012.bib}}
  6. {}


Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Sat Mar 26, 2016 4:02 pm

BTW: if those two files contain the same bib data with the same cite keys I am pretty sure this will cause conflicts:

  1. \documentclass{article}
  2. \usepackage{filecontents}
  3. \begin{filecontents}{\jobname.bib}
  4. @article{test,
  5. author = {me} ,
  6. title = {test}
  7. }
  8. @article{test,
  9. author = {also me} ,
  10. title = {also a test}
  11. }
  12. \end{filecontents}
  13.  
  14. \usepackage{biblatex}
  15. \addbibresource{\jobname.bib}
  16.  
  17. \begin{document}
  18.  
  19. foo \cite{test}
  20.  
  21. \end{document}


gives

  1. Running `Biber' on `test' with ``biber test''
  2. ...
  3. WARN - Duplicate entry key: 'test' in file 'test.bib', skipping ...
  4. ...
  5. INFO - WARNINGS: 1
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

arstaer
Posts: 12
Joined: Sun Jun 17, 2012 5:56 am

Postby arstaer » Tue Mar 29, 2016 1:15 am

Thank you for the reply!

I tried to use this but then I get
  1. ! LaTeX Error: Missing \begin{document}.
  2.  
  3. See the LaTeX manual or LaTeX Companion for explanation.
  4. Type H <return> for immediate help.
  5. ...
  6.  
  7. l.84
  8.  

I tried to debug it but I don't know where the problems lie.

I created an MWE:
  1. \documentclass[12pt]{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage[T1]{fontenc}
  4.  
  5. \IfFileExists{Zotero2012.bib}
  6. {\addbibresource{Zotero2012.bib}}
  7.  
  8. \IfFileExists{T:/MYDOCS~1/MYBIBT~1/Zotero2012.bib}
  9. {\addbibresource{T:/MYDOCS~1/MYBIBT~1/Zotero2012.bib}}
  10.  
  11. \begin{document}
  12. Furthermore, the NAV-price arbitrage...
  13. \end{document}


And it still gives me the missing document error.

  1. ! LaTeX Error: Missing \begin{document}.


Thank you!

AS

Edit: The problem is in the \IfFileExists{T:/MYDOCS~1/MYBIBT~1/Zotero2012.bib}, is there a way to make this work? Spent hours, and still haven't been able to find a solution. Any help would be greatly appreciated as the submission deadline draws near.

Edit 2: Seems I found a way!
  1. \IfFileExists{T:/MYDOCS\string~1/MYBIBT\string~1/Zotero2012.bib} {\addbibresource{T:/MYDOCS\string~1/MYBIBT\string~1/Zotero2012.bib}}

now no missing begin document errors at compiling

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Tue Mar 29, 2016 12:41 pm

\IfFileExists has three arguments: one for the file name,one for the true branch and one for the false branch. Your example misses the third (probably empty) argument.
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim


Return to “BibTeX, biblatex and biber”

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests