3

I'm using MiKTeX 2.9, LyX 2.1.3, and biblatex/biber for bibliography management.

I need to have a portable set of project files since I'm working on multiple computers and everything is synchronized using a version control system. Although the relative paths are the same on each computer, the absolute paths are different due to different account names and drive letters. Using BibLatex and LyX requires that the path names to the bib files to be absolute references.

So on Computer A, I need to have the following in the preamble:

\addbibresource{C:/Users/accountname/dir1/dir2/filename.bib}

And on Computer B, I need to have the following:

\addbibresource{S:/dir3/dir1/dir2/filename.bib}

I've tried using both commands together in the same project, but if the first \addbibresource line is used on Computer B, it will fail with a "Cannot find" error when running biblatex. It will work fine on Computer A, since it work for the first file (and then fail on the second).

What I would like it to do is to ignore file missing errors--skip the missing file and use the other bibresource as necessary. Unfortunately, it dies with a fatal error and doesn't attempt the second file. Is this something that could be changed?

Is there another solution I've overlooked? Unfortunately, it seems that something has to give. I either have to give up biblatex/biber and revert back to standard bibtex, with which relative paths worked in LyX. I'm enjoying the flexibility of biblatex and I've spent a lot of time setting it up with my project, so I don't want to give up biblatex. I've read that I could add my bib file to the TEXMF tree, but I'd like to avoid this approach since I don't want to add project specific files to a 'global' repository. I also don't want to have to comment and uncomment the appropriate lines as I switch from computer to computer. I update the project on a daily basis, so it would be tedious to keep manually changing which bibresource is used. Does anyone have any suggestions?

7
  • you don't have to move the bib file, just add that directory to your BIBINPUTS and TEXINPTS paths Commented Nov 20, 2015 at 8:06
  • I don't understand what you mean by that relative pathes don't work with biblatex. I just tried \addbibresource{../Z-Temp/Minibsp/Diplomarbeit.bib} and it worked fined. Perhaps you only used the wrong "starting point". Commented Nov 20, 2015 at 9:17
  • @UlrikeFischer, I think the requirement for absolute paths is set by LyX and not by biblatex. Although biblatex by itself handles relative paths fine, since LyX compiles documents in a temporary directory, relative paths don't work. But since biblatex is used, I have to use the syntax allowed by biblatex.
    – user44666
    Commented Nov 20, 2015 at 13:21
  • That's what I meant with the starting point. Can't you set the relative pathes relative to the temporary directory? Or force biber to start from the document location and add the path to the tempory directory? Commented Nov 20, 2015 at 13:42
  • @UlrikeFischer, I think that approach would be even more difficult. The temporary directory has a random name, so there's no way to know what it will be until runtime. And the relative paths from the temporary directory back to project folders would be even harder to determine since the temporary folder may not be on the same drive as the project folders. It would certainly be best if LyX automatically converted relative paths to absolute paths before compiling, but that doesn't sound like it's going to happen.
    – user44666
    Commented Nov 20, 2015 at 14:16

2 Answers 2

9

I would just use

\addbibresource{filename.bib}

and arrange the input paths on the two machines so that works in both cases. Either by putting the file in your normal texmf tree or setting the environment variables so S:/dir3/dir1/dir2/filename.bib is found.

but if you don't want to do that for some reason, do

\IfFileExists{S:/dir3/dir1/dir2/filename.bib}
 {\addbibresource{S:/dir3/dir1/dir2/filename.bib}}

and similarly for the other path.

2
  • Thanks. I thought of doing your second suggestion just a few minutes ago. I tested it and it works well. I think this is going to be the easiest approach and my accepted solution.
    – user44666
    Commented Nov 20, 2015 at 8:12
  • On Linux, if you use a path relative to your home directory starting with ~ as an argument for \IfFileExists, escape the tilde as follows: \string~.
    – pavel
    Commented Sep 5, 2019 at 6:16
1

Since I wasn't allowed to comment on Carlisle's post:

I had the same problem, only with two computers running different OSes, Windows and MacOS. Using the code above in Windows at least:

\IfFileExists{D:/Dropbox/library.bib}{
\addbibresource{D:/Dropbox/library.bib}}

\IfFileExists{/Users/.../Dropbox/library.bib}{
\addbibresource{/Users/.../Dropbox/library.bib}}

Returned an error (maybe because there is no /Users/ in Windows (?))

So I had to change the code slightly (taken from: IfFileExists and filecontents causes an error):

\begingroup\newif\ifmx
\IfFileExists{D:/Dropbox/library.bib}{\mxtrue}{}
\ifmx%{%
\addbibresource{D:/Dropbox/library.bib}%}
\fi\endgroup

\begingroup\newif\ifmy
\IfFileExists{/Users/.../Dropbox/library.bib}{\mytrue}{}
\ifmy%{%
\addbibresource{/Users/.../Dropbox/library.bib}%}
\fi\endgroup

I could also have used [remote] in the \addbibresource as it sits in my Dropbox, but that doesn't work with autocompletion in TexStudio:

\addbibresource[location=remote]{https://www.dropbox.com/.../library.bib?dl=1}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .