8

I'm trying to work on individual sections of a paper separately. In order to do this, I need to wrap the text in

\begin{document}
...
\bibliography{bib}
\end{document}

The main file looks similar:

\begin{document}
\include{A}
\include{B}
...
\bibliography{bib}
\end{document}

However, with the bibliography included in the sub-file and the main file, I end up with these errors: Illegal, another \bibstyle command, Illegal, another \bibdata command. I think, had the builds worked, I would also have a duplicate bibliography.

So, the question: How can I keep the individual sub-documents compileable (with bibliography), but also have the "main" document compile with a working bibliography?

4
  • Don't put \begin{document} in your section files, to process just section B add \includeonly{B} and then process the main file. Feb 10, 2013 at 17:06
  • Unfortunately, that breaks my workflow - I need to be editing document B and building it in the same editor window (I'm using macvim + skim). Switching to the "main" file and editing it really is not a reasonable option (and right now, it's just as easy to comment out the bibliography in B as to add includeonly to the main file).
    – keflavich
    Feb 10, 2013 at 17:54
  • 1
    Could you please rephrase the title so that it builds a real phrase. To have some full minimal working examples (MWEs) incl. the \documentclass and minimal required packages would be create. I for example can't see at the moment if you are really using the standalone bundle as your title and tags suggest or not. If so, you can use the \ifstandalone switch around the \bibliography{bib} command. Feb 12, 2013 at 10:55
  • create -> great? Anyway, fixed title. I have \usepackage{standalone} in a preface.tex included in the main & sub documents. The \ifstandalone switch sounds very much like what I want; this post helps: tex.stackexchange.com/questions/29995/…
    – keflavich
    Feb 12, 2013 at 16:14

1 Answer 1

10

Assuming you are using the standalone bundle here then you can use the \ifstandalone switch around the \bibliography{..} command to ignore it if the sub-file is compiled as part of the main document. This switch is set to \iftrue by the standalone class, but to \iffalse by the standalone package in the main document. See the standalone package manual for more details.

% Subfile e.g. "A.tex"
\documentclass{standalone}
\begin{document}
...
\ifstandalone
\bibliography{bib}
\fi
\end{document}
% main document
\documentclass{book}
\usepackage{standalone}
\begin{document}
\include{A}
\include{B}
...
\bibliography{bib}
\end{document}

You must log in to answer this question.

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