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

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

Make addbibresource{} choose one out of many .bib

Post by arstaer »

Dear all,

Here is the issue, I plan to make

Code: Select all

\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,

Code: Select all

\addbibresource{Zotero2012.bib}   
\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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

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

Make addbibresource{} choose one out of many .bib

Post by cgnieder »

You probably want something like

Code: Select all

\IfFileExists{Zotero2012.bib}
  {\addbibresource{Zotero2012.bib}}
  {}
\IfFileExists{T:/MYDOCS~1/MYBIBT~1/Zotero2012.bib}
  {\addbibresource{T:/MYDOCS~1/MYBIBT~1/Zotero2012.bib}}
  {}
Regards
site moderator & package author
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Make addbibresource{} choose one out of many .bib

Post by cgnieder »

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

Code: Select all

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{test,
  author = {me} ,
  title = {test}
}
@article{test,
  author = {also me} ,
  title = {also a test}
}
\end{filecontents}

\usepackage{biblatex}
\addbibresource{\jobname.bib}

\begin{document}

foo \cite{test}

\end{document}
gives

Code: Select all

Running `Biber' on `test' with ``biber test''
...
WARN - Duplicate entry key: 'test' in file 'test.bib', skipping ...
...
INFO - WARNINGS: 1
site moderator & package author
arstaer
Posts: 12
Joined: Sun Jun 17, 2012 5:56 am

Make addbibresource{} choose one out of many .bib

Post by arstaer »

Thank you for the reply!

I tried to use this but then I get

Code: Select all

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.84 
     
I tried to debug it but I don't know where the problems lie.

I created an MWE:

Code: Select all

 \documentclass[12pt]{article}    
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

    \IfFileExists{Zotero2012.bib}
    {\addbibresource{Zotero2012.bib}}
    
    \IfFileExists{T:/MYDOCS~1/MYBIBT~1/Zotero2012.bib}
    {\addbibresource{T:/MYDOCS~1/MYBIBT~1/Zotero2012.bib}}

\begin{document}    
  Furthermore, the NAV-price arbitrage...
  \end{document}
And it still gives me the missing document error.

Code: Select all

! 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!

Code: Select all

\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: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Make addbibresource{} choose one out of many .bib

Post by cgnieder »

\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.
site moderator & package author
Post Reply