I am looking to have a document Main.tex that references content in two sub-documents, Doc1.tex and Doc2.tex via \include{} and that can be configured to only compile to PDF the content in a particular one of those documents. Following the discussion in this answer to: Splitting(!) one latex document into two pdf outputs including references , I can get the basics working just fine. But, when I use the endfloat package the functionality falls apart. Below is a minimal working example. It works fine if I:

  1. First compile Main.tex with the \includeonly{} command commented out.

  2. Then re-compile Main.tex removing the comment from \includeonly{}.

But, as soon as I remove the comment to load the endfloat package, I lose the ability to reference figures in Doc2.tex - instead, the references just appear as ?? in the compiled PDF.


% \usepackage[notablist,nofiglist,nomarkers]{endfloat}  %% places all figures and tables at the end.

% \includeonly{Doc1}






As I show in Figure \ref{fig1} in Doc2 ...


\caption{This is a figure}
  • Would subfiles be an alternative? see tex.stackexchange.com/a/378163/36296 Aug 8, 2017 at 20:41
  • It can't really work. endfloat writes the figures to an external file. If this file is not process the labels are not there. And I also don't really understand what should happen at the end with the figures. Are some printed and if yes which one and where? Aug 8, 2017 at 21:28
  • @UlrikeFischer Regarding the desired behavior - the goal is to only print figures from Doc1, and to do so at the end of Doc1, but to be able to reference figures from Doc2 from within Doc1. Thanks! Aug 8, 2017 at 22:03
  • @samcarter I think that has some potential. But, I've also run into difficulties with the subfiles package. See the new question that I posted here describing those challenges: tex.stackexchange.com/questions/385485/… Aug 9, 2017 at 0:48

3 Answers 3


This question can be broken down into two parts:

  • Compiling the two parts separately. I recommend the subfiles for this - it allows you to easily share the preamble of the main file with the subfiles

  • cross referencing between the subfiles. With the xr-hyper package you can import labels from another file. The trick is to use this only for the compilation of the subfiles, not when the main file is compiled, that's why the inclusion in the below references answer tests for the jobname of the compilation.

An example how to use both can be found at Cross Reference problem


If as you mention in the comment the figures can be at the end of every subfile then this will probably work:

Put \processdelayedfloats at the end of every subdocument.

Compile without the \includeonly until everything is stable and then use \includeonly.

  • Great, thank you very much for these suggestions. They are both helpful on their own and in aiding me in discovering yet another solution to the problem, which is to switch my compiler for the .tex files. Aug 10, 2017 at 15:49

Interestingly, I discovered that my original scripts actually work just as given if I compile them using TeXShop, but not if I compile them, as I was previously doing, with Sublime LaTeXing. I still am not fully certain of the reason for this. But, in TeXShop, a successful workflow is:

  1. Compile Main.tex
  2. Compile Main.tex again, making no changes
  3. Uncomment the includeonly{ } and then compile Main.tex one more time.

Props to the answer from @Ulrike Fischer that got me to try out variations along these lines, first precisely as suggested in Ulrike's answer and then to realize that the basic procedure from Ulrike would work even on the original scripts I had posted if I switched my compiler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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