解決方案1

解決方案1

sources.bib當文件與我的文件位於同一目錄中時,我的引文工作正常.tex,如下所示:

\documentclass{article}
\usepackage{fancyhdr}

\begin{document}

\thispagestyle{fancy}
\everymath{\displaystyle}

\nocite{textbook}

\bibliographystyle{plain}
\bibliography{sources}

\end{document}

這是sources.bib文件:

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

我的參考書目顯示得很好。但是,如果我只是移動sources.bib到父目錄中,並調整程式碼:

\documentclass{article}
\usepackage{fancyhdr}

\begin{document}

\thispagestyle{fancy}
\everymath{\displaystyle}

\nocite{textbook}

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

\end{document}

我收到錯誤:

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

這是怎麼回事?

答案1

我已經嘗試過發布的程式碼U.Martinez-Corral 的回答,不幸的是它不適合我(Windows10 + sublime Text 3 (Build 3126) + LaTeXTools + Texlive)。

這是 BibTeX 的限制:

使用 BibTeX 和輸出目錄時,需要向上目錄遍歷的相對路徑 (..) 無法運作。這是 BibTeX 的限制,它並不真正支援輸出目錄的概念。 如果 bib 檔案位於父目錄中,則找不到引文

解決方案1

請改用絕對路徑。

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

解決方案2

我的解決方案是使用currfile-abspathpackage 來建立絕對路徑\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}

也可以看看:https://tex.stackexchange.com/a/54891/115852

答案2

雖然在這種情況下應該沒有任何效果,但最好將最小工作範例 (MWE) 保持盡可能小,並提供測試它所需的所有檔案。 MWE 缺乏fancy風格定義。刪除它 和\everymath,並添加 bibfile 的內容,這個 MWE 對我有用:

./main.tex

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

\cite{knuth1986texbook}

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

\end{document}

../來源.bib

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

為了確定起見,請刪除所有輔助檔案並再次編譯整個序列(pdflatex + bibtex + pdflatex + pdflatex)。還不行嗎?

相關內容