[Tex/LaTex] Subfiles and Referencing

subfiles

I am having some trouble getting a modular document to work.

This is what my files look like at the moment

./rootdoc.tex

./tex/childdoc.tex

./bib/bibliography.bib

the files look like…

./rootdoc

\documentclass{book}    
%some packages    
\usepackage{subfiles}    
\usepackage[colorlinks=true]{hyperref}    
\usepackage[backend=biber,style=numeric]{biblatex}    
    \addbibresource{bib/bibliography.bib}

\begin{document}    
    \subfile{tex/childdoc.tex}    
    \printbibliography[heading=bibintoc]    
\end{document}

./tex/childdoc

\documentclass[../rootdoc.tex]{subfiles}
\begin{document}
\chapter{Sample Chapter}
some text that i have to cite\cite{ross}
\printbibliography
\end{document}

When compiling the root document everything works fine and I get the following
rootdoc compiled

But when I compile .\tex.childdoc I get

enter image description here

Any help will be greatly appreciated.

Best Answer

This is not my solution, but I thought I would combine two other solutions that I found on the site.

Bibliographies when using subfiles and subfiles inside a subfile using relative paths

As Before

./rootdoc.tex
./tex/childdoc.tex
./bib/bibliography.bib

in the ./rootdoc.tex file

\documentclass{book}

\usepackage{subfiles}
\usepackage[colorlinks=true]{hyperref}

\providecommand{\main}{.}
\usepackage[backend=biber,style=numeric]{biblatex}
    \addbibresource{\main/bib/bibliography.bib}
\makeatletter
    \newrobustcmd*{\nobibliography}{%
      \@ifnextchar[%]
        {\blx@nobibliography}
        {\blx@nobibliography[]}}
    \def\blx@nobibliography[#1]{}
    \appto{\skip@preamble}{\let\printbibliography\nobibliography}
\makeatother

\begin{document}
    \subfile{./tex/childdoc.tex} 
    \printbibliography[heading=bibintoc]
\end{document}

and in the ./tex/childdoc.tex file

\providecommand{\main}{..}
\documentclass[../rootdoc.tex]{subfiles}
\begin{document}
\chapter{Sample Chapter}
some text that i have to cite\cite{ross}
\printbibliography
\end{document}

now the correct .bibfile is referenced and when child is compiled the bibliography does not appear twice when the root document is compiled.

Related Question