Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Don't put \begin{document} in your section files, to process just section B add \includeonly{B} and then process the main file. –  David Carlisle Feb 10 '13 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 '13 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. –  Martin Scharrer Feb 12 '13 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 '13 at 16:14
add comment

1 Answer

up vote 5 down vote accepted

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}
share|improve this answer
add comment

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.