TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing my Ph.D. thesis in XeLaTeX with Biblatex, and there are times when I need to compile individual chapters, and times when I need to compile the entire document, so I use subfiles, which works wonderfully. However, in each of these chapters I have a \printbibliography command, which I would like to turn off when compiling the final document, so that only the \printbibliography command is run in the mainfile.

The file structure is something like:

  Main.tex
\usepackage{subfiles, biblatex}
\begin{document}

\subfile{Chapter1.tex}

\printbibliography
\end{document}

Chapter1.tex
\documentclass[Main.tex]{subfiles}
\begin{document}
\cite{Someguy1981}
\printbibliography
\end{document}
share|improve this question
up vote 9 down vote accepted

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.

share|improve this answer
    
I have tested this and it works perfectly. – Skander Apr 5 '13 at 23:39
1  
This stuff goes in the main file or in the subfile? Does it works with standard LaTeX or has something XeLaTeX specific? – Lucas Soares Jun 22 '14 at 2:29

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}
\define\dobib{ % Define the command
    \bibliographystyle{acm}
    \bibliography{../../references} % Place the path relative to the subfile here
}

\begin{document}
\define\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}
    \cite{Someguy1981}
    \dobib
\end{document}

This works fine for me.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.