5

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.

5
  • 1
    Sorry, but .... What is the matter? The child document have a cite that obviously cannot be compiled as a standalone document since you are not using \printbibliography here. Subfiles load the preamble, not the end of the document. Beside this, all seem the expected ...
    – Fran
    Commented Mar 30, 2015 at 18:41
  • Hi... thanks for response. I added \printbibliography to childdoc.tex... and still get the same output.
    – Quantifeye
    Commented Mar 30, 2015 at 18:59
  • found this in log file Package auxhook Warning: Cannot patch \document, (auxhook) using \AtBeginDocument instead.
    – Quantifeye
    Commented Mar 30, 2015 at 19:29
  • when I place the childdoc.tex in the same folder as the rootdoc.tex then it works fine.
    – Quantifeye
    Commented Mar 30, 2015 at 19:35
  • Because the child document expect, as the main document, the bibliography file in ./bib/ (i.e., inside tex/), not in ../bib/ (i.e, besides tex/), I guess...
    – Fran
    Commented Mar 30, 2015 at 19:56

2 Answers 2

6

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.

0

I have spend some hours with this problem too. I basically just want to be able to compile single subfiles in order to have the possibility of sending single chapters to my thesis supervisor during my writing process.

The different solutions from the two links provided by Quantifeye are definitely more flexible, but my solution below is very simple and works for my workflow:

Simply just use the absolute path to your .bib-file when calling \addbibresource{...} in the preamble, i.e. do something like

\documentclass{book}    
%some packages    
\usepackage{subfiles}    
\usepackage[colorlinks=true]{hyperref}    
\usepackage[backend=biber,style=numeric]{biblatex}    
%Use absolute paths to .bib-files for the subfiles to understand their location:
    \addbibresource{/home/Username/Dropbox/Thesis/TeX_code/thesisReferences.bib}

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

and in the subfiles

\documentclass[../rootdoc.tex]{subfiles}
\begin{document}
\chapter{Sample Chapter}
some text that i have to cite\cite{ross}
%\printbibliography %Comment or un-comment depending on desired output
\end{document}

If I want my supervisor to see the references I will of course add the \printbibliography to the subfile, but my main concern has just been to compile anything else without my citations looking weird or having my editor throw me an error message.

NOTE: This solution is obviously not optimal if you work on a shared document, or if you want to work on more machines with different file systems.

It is however a very simple solution and it works well for me and my requirements to my workflow.

1

You must log in to answer this question.

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