Path for bib file: working simultaneously in TexStudio and Overleaf

bibtexoverleaftexstudio

I have a project with several tex files in different folders, all of which use the same bib file that is in the parent folder:

ref.bib
Folder1 -> file1.tex
Folder2 -> file2.tex
...

I compile the tex files with TexStudio. Inside the tex files, I can reference ref.bib as follows:

\bibliography{../ref}

However, my colleagues work in Overleaf. There, for some reason, this does not work, and they have to reference it as follows:

\bibliography{ref}

Probably, TexStudio looks for bib files in the folder of the current tex files, while Overleaf looks for them in the root of the current project.

The bib file changes frequently, so duplicating it to the different folders is not a good option.

Is there a way to make this work on both TexStudio and Overleaf?

NOTE: I am on Windows 10.

Best Answer

You could use \bibliography{ref} and locally set BIBINPUTS enviornment variable to the parent directory but perhaps simpler would be to use

\bibliography{\ifnum\pdfstrcmp{\jobname}{output}=0 ref\else ../ref\fi}

as Overleaf always sets the jobname to output

Related Question