TransWikia.com

How to get a bibliography to work in subfiles?

TeX - LaTeX Asked by Shan Kasal on July 10, 2021

I’m trying to get a bibliography to work while using subfiles for my dissertation. My goal is to have one main bibliography for all chapters. The current structure of my files is:

  1. Main Folder

    • Thesis.txt

    • Thesis.bib

  2. Introduction Folder

    • Introduction.txt

I have tried several different methods with natbib and biblatex, including most highly rated answer from this question (Handle .bib in subfiles), with no luck. My bibliography is available in the main Thesis.txt file and if I try to cite something there it’s fine. However when I try and cite something in the subfile (Introduction.txt), cite will auto fill but I always get the error for undefined citations. This is also the case if I try and compile the main Thesis.txt file with the subfile Introduction.txt.

My current simplified code is as such:

Thesis.txt

documentclass{ucetd}
usepackage[super,comma]{natbib}
        bibliographystyle{unsrtnat}
usepackage{subfiles}

providecommand{main}{.}  
defbiblio{bibliographystyle{unsrtnat}bibliography{main/Thesis}}

begin{document}
defbiblio{}

renewcommandbibname{References}
    newpage
    addcontentsline{toc}{chapter}{References}
    begin{singlespace}
        bibliography{Thesis}
    end{singlespace}

end{document}

Introduction.txt

providecommand{main}{..}  % *Modification: redefine path location, must go before documentclass
documentclass[main/Thesis.tex]{subfiles}

begin{document}

some text. cite{}

newpage
biblio
end{document}

I have also tried including the bibliography in the subfile and this still does not resolve the error. Moreover I tried the biblatex exaple(Handle .bib in subfiles) and that did not work either.

I’m at my wits end please help.

One Answer

With recent versions of the subfiles package, the general rule is

Choose the path relative to the file it appears in.

The following example works with a current LaTeX distribution.

%%%%%%%% thesis.tex
documentclass{article}
usepackage[super,comma]{natbib}
bibliographystyle{unsrtnat}
renewcommandbibname{References}
usepackage{subfiles}
begin{document}
subfile{introduction/introduction}
bibliography{thesis}
end{document}

%%%%%%%% thesis.bib
@Article{TheSource,
  author =   {T.Sourcerer},
  title =    {The Source Of Everything},
  journal =      {Resources},
  year =     {2021}
}

%%%%%%%% introduction/introduction.tex
documentclass[../thesis]{subfiles}
begin{document}
Some text~cite{TheSource}.

ifSubfilesClassLoaded{%
  bibliography{../thesis}%
}{}
end{document}

Now you can either typeset the main document with

pdflatex thesis
bibtex thesis
pdflatex thesis
pdflatex thesis

or the introduction in the subdirectory with

cd introduction
pdflatex introduction
bibtex introduction
pdflatex introduction
pdflatex introduction

There are also several examples for generating sub-bibliographies in the subfiles-repository on Github, see the subdirectories biblatex, bibunits and chapterbib in the subdirectory test.

Answered by gernot on July 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP