2

My citations work fine when the sources.bib file is within the same directory as my .tex file, as shown here:

\documentclass{article}
\usepackage{fancyhdr}

\begin{document}

\thispagestyle{fancy}
\everymath{\displaystyle}

\nocite{textbook}

\bibliographystyle{plain}
\bibliography{sources}

\end{document}

Here is the sources.bib file:

@book{textbook,
    author = {First, Last},
    title = {title},
}

My bibliography shows up just fine. However, if I simply move sources.bib outside into the parent directory, and adjust the code:

\documentclass{article}
\usepackage{fancyhdr}

\begin{document}

\thispagestyle{fancy}
\everymath{\displaystyle}

\nocite{textbook}

\bibliographystyle{plain}
\bibliography{../sources}

\end{document}

I receive the errors:

Citation `textbook' undefined
Empty `thebibliography' environment
There were undefined references.

What's wrong here?

1
  • You need to put your .bib file either in the current directory or in a place that TeX/BibTeX will search by default (or 'force' the issue, which I don't recommend). If you have TeX Live installed, you may (not sure about Windows) be able simply to type kpsewhich --var-value TEXMFHOME to find the base of your local tree. For me that gives: ~/texmf, so I can construct the BibTeX branch of that tree: mkdir ~/texmf/bibtex/bib and put my bibliography file there (or create a link to it from that directory). For MikTeX, I believe the arrangement is more complicated.
    – jon
    Sep 27, 2014 at 0:40

2 Answers 2

2

I've tried the code posted in U.Martinez-Corral's answer, unfortunately it's not work for me (Windows10 + sublime Text 3 (Build 3126) + LaTeXTools + Texlive).

This is a limitation of BibTeX:

Relative paths requiring upward directory traversal (..) don't work when using BibTeX and an output directory. This is a limitation of BibTeX, which doesn't really support the concept of an output directory. Citation not found if bib file in parent directory

Solution 1

Use absolute path instead.

\bibliography{../sources}                         % relative path: don't work
\bibliography{E:/GitKraken/test/sources}          % absolute path: work

Solution 2

My solution is using currfile-abspath package to build an absolute path \bibliography{\mainabsdir/../sources}.

./main.tex

\documentclass[a4paper]{article}
% \usepackage[backend=bibtex]{biblatex}

\usepackage{currfile-abspath}

\getmainfile % get real main file (can be different than jobname in some cases)
\getabspath{\themainfile} % or use \jobname.tex instead (not as safe)
\let\mainabsdir\theabsdir % save result away (macro will be overwritten by the next \getabspath
\let\mainabspath\theabspath % save result away (macro will be overwritten by the next \getabspath

\begin{document}

\cite{knuth1986texbook}

\bibliographystyle{plain}
\bibliography{\mainabsdir/../sources}

\end{document}

See Also: https://tex.stackexchange.com/a/54891/115852

2

Although it should have no effect in this case, it's better to keep the Minimum Working Example (MWE) the smallest possible, and provide all the files required to test it. The MWE is lacking the fancy style definition. Removing it and \everymath, and adding the content of the bibfile, this MWE works for me:

./main.tex

\documentclass[a4paper]{article}
\begin{document}

\cite{knuth1986texbook}

\bibliographystyle{plain}
\bibliography{../sources}

\end{document}

../sources.bib

@book{knuth1986texbook,
  keywords = {book},
  title={The texbook},
  author={Knuth, D.E. and Bibby, D.},
  volume={1993},
  year={1986},
  publisher={Addison-Wesley}
}

Just to be sure, remove all the auxiliary files and compile the whole sequence again (pdflatex + bibtex + pdflatex + pdflatex). Is it still not working?

3
  • sure, sorry about that. Even with this it does not work. To note, I am using latexing in sublime text, which "autobuilds" for me. I'd presume that such a minimal example should work regardless. I tried in Texshop and it fails as well. It seems to find the file (no "file not found" errors), but the actual reference cannot be found.
    – impguard
    Sep 26, 2014 at 23:20
  • Could you run it from the command line? Just to be sure it's not due to 'sublime', the plugin or Texshop failing. Sep 26, 2014 at 23:33
  • On my computer (Windows 8.1), it is important to clean all the auxiliary files generated before compiling the tex file again, or I got the error message that the *.bib file can not be found.
    – jdhao
    Feb 20, 2017 at 12:47

You must log in to answer this question.

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