Bibliographies when using subfiles

From subfiles.sty the \subfile command is defined as:

\newcommand\subfile[1]{\begingroup\skip@preamble\input{#1}\endgroup}

So it is straightforward to hook in some code to locally redefine \printbibliography to do nothing. For an example add the following to the preamble of the main file:

\makeatletter

\newrobustcmd*{\nobibliography}{%
  \@ifnextchar[%]
    {\blx@nobibliography}
    {\blx@nobibliography[]}}

\def\blx@nobibliography[#1]{}

\appto{\skip@preamble}{\let\printbibliography\nobibliography}

\makeatother

Note that biblatex makes bibliographic data available via citation commands. So unless you want to view the bibliography entries outside the main file, the subfiles need not invoke \printbibliography.


I also used Audrey's approach (https://tex.stackexchange.com/a/107111/85983) for a while, but I got annoyed of having to write \printbibliography at the end of each subfile. Now I'm using the following Latex Hooks in the preamble of my main file:

%%% Default start and end for each subfile
\AtBeginDocument{%
}

\AtEndDocument{%
    \printbibliography
    \listoffigures
    \listoftables
    \newpage
    \printacronyms[include-classes=abbrev,name=Acronyms]
}

Borrowing a post on this Latex Community thread, you can define your \printbibliography command in the preamble and then un-define it in the main document. Your main file will then contain its own call to \bibliography{} and \biblographystyle.

Something like:

Main.tex

\usepackage{subfiles, biblatex}
\newcommand{\dobib}{ % Define the command
    \bibliographystyle{acm}
    \bibliography{../../references} % Place the path relative to the subfile here
}

\begin{document}
\renewcommand{\dobib}{} % Un-define the command

    \subfile{Chapter1.tex}

    \bibliographystyle{acm}
    \bibliography{../references} % Place the path relative to the main file here
\end{document}

Chapter1.tex

\documentclass[Main.tex]{subfiles}
\begin{document}
    According to SomeGuy \cite{Someguy1981} pigs can fly.

    \dobib
\end{document}

This works fine for me.