[Tex/LaTex] Standalone chapters with separate references and counters

bibunitsdocument-configurationstandalonesubfiles

I'm looking for a convenient way to integrate standalone chapters in a main.tex (scrbook) file. More specifically, they will be already published papers within a thesis framework text and should

  • each have their own counters for figures, tables, equations
  • each have their own references with the references not showing up in the references of main.tex (preferably natbib)
  • inherit everthing else like formatting, header, footer, packages from main.tex
  • preferably compile with main.tex

I have looked at the standalone and subfiles packages, together with chapterbib or bibunits and with resetting the counters before each paper. Although I think I could somehow get this to work, this seems like an ugly workaround for something that has probably been encountered by someone else earlier.

Best Answer

Personally I think this comes down to file and document organization. Few comments based on the work flow I evolved into using:

  • Unless preparing a MWE, I never have a single file for a project or even part of a document.
  • I agree it can be very helpful to keep chapters or other types of hierarchy as stand-alone and fully compilable document because you never know what you will want to examine or share.
  • I separate each stand-alone document, such as a chapter in a larger report, into a main file that loads my particular class file and/or preamble used \begin{document} \input{../Files/ActualStandAloneContent} \end{document} to direct the compiler to my chapter content.
  • I keep all source files in subfolders of my project, such as the /Files/ mentioned above.
  • I keep all possible main files in a common folder where I have batch files prepared to compile ALL Tex files in this directory. Note this is where it is crucial not to have incomplete Tex files because the compiler will fail if they don't try and load a document class and begin/end the document. This means I may have a folder with main.tex main_Ch1.tex main_Ch2.tex etc... and when I run my xelatexCompile.bat I will get main.pdf main_Ch1.pdf main_Ch2.pdf which keeps everything current.
  • whether you manage your references (I like bibunits) in the main files by using a syntax like \begin{bibunit} \input{File} \putbib \end{bibunit} or you include this process in your standalone chapter, it doesn't make much difference. Personally, I keep this stuff in the main file as I never know when I am going to subdivide stand-alone files.
  • if you have common front-matter like Tables of Contents, figures, equations, nomenclature from glossaries or something, I recommend a distinct file to load via something like \input{../Files/FrontMatter.tex} which you would always include in your main file to save repetition.
  • your header footer structure would be aspects I control in my cls file, but could also be done in main specific tex file preambles if you need customization.
Related Question