2

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.

Main.tex

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

% \includeonly{Doc1}

\begin{document}

\include{Doc1}

\include{Doc2}

\end{document}

Doc1.tex

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

Doc2.tex

\begin{figure}
\centering\rule{1cm}{1cm}
\caption{This is a figure}
\label{fig1}
\end{figure}
  • Would subfiles be an alternative? see tex.stackexchange.com/a/378163/36296 – user36296 Aug 8 '17 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? – Ulrike Fischer Aug 8 '17 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! – aireties Aug 8 '17 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/… – aireties Aug 9 '17 at 0:48
2
+50

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

2

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. – aireties Aug 10 '17 at 15:49
1

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.