Say you have a paper with an online appendix and some supplementary materials. Sometimes you want one PDF with everything, sometimes you want 3 separate PDFs.
Wouldn't it be cool to compile everything with 1 line + have references resolve properly across all documents?
Here is an example using a Bash script and tex-files here: compileThree.7z (Note: these files will not compile "out-of-the-box," they're just intended to get you started.)
Implemented successfully with texlive 2022 and 2023 on Cygwin, requires tex utility latexmk (from texlive-collection-binextra)
The bash script, compile_paper.bash, uses a master tex file, master.tex, and three sub-files, main.tex (the paper), appendices.tex and supplement.tex to produce all.pdf (everything), main.pdf, appendices.pdf and supplement.pdf.
The key parts are: (1) the %includeonlyline in master.tex and (2) the sed lines in compile_paper.bash. The basic steps are:
(1) (line 14 of compile_paper.bash) Use latexmk to compile the all-in-one PDF (all.pdf) and also create all the ancillary files (e.g., .aux, .ttt, .fff, etc.) we need to create cross-references in the standalone documents. (Don't delete these until the end!)
(2) (lines 20-22) the sed line replaces %includeonlyline in master-temp.tex with \includeonly{main}. Now latexmk will compile only the paper, without the appendix or supplement, as main.pdf.
(3) (lines 24-30) repeat for the appendices and the supplement, creating appendices.pdf and supplement.pdf
(4) Finally, we can clean up the ancillary files (lines 33-47)
The outputs are here: https://sites.google.com/view/rpguiter/research/BGD-San-Soc