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.

  • Welcome to TeX.SX! This post is related tex.stackexchange.com/questions/101325/… – Andrew Jun 19 '15 at 7:59
  • You could also use pdfpages to simply insert the papers as is. – suvayu Jun 19 '15 at 9:55
  • Do you see a way to combine pdfpages with subfiles or standalone so that the documentclass and packages are inherited from the main file? @suvayu – Leo Jun 19 '15 at 12:54
  • I think maybe you are misunderstanding how pdfpages work. AFAIU, it simply includes the specified pages from the existing pdf, almost like including a figure. Something like this example (see page 65 onwards). – suvayu Jun 20 '15 at 10:59

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.

Following is the folder-file structure I have been using for many years after trying \includeonly for about a year. It uses \jobname a lot for automating things.

  • GRAPHICS (Folder for the editable graphics from which the pdfs were made.)

    1   Folder for the graphics for Chapter 1
    2   Folder for the graphics for Chapter 2
    101   Folder for the graphics for Appendix 1

    FIGURES (Folder for the pdfs used in the \includegraphics)

    1   Folder for the pdfs for Chapter 1
    2   Folder for the pdfs for Chapter 2
    101   Folder for the pdfs for Appendix 1
  • STYLESHEETS  Folder containing only the following two files:

    GraphicsPaths.sty    contains only the following command:
    Preamble.sty    This file contains the various  \usepackage and the definition of the various \definecolor, \newcounter, \newcommand, etc.

    TEXT-CONTENTS (Folder for the files containing just the CONTENT of the chapter)

    1.tex   Content of Chapter 1
    2.tex   Content of Chapter 2
    101.tex   Content of Appendix 1

    Each of the above files contains the following code followed by the content of the chapter

        %!TEX root = ../Text-controls/\jobname.tex
        %!TEX TS-program = pdflatexmk  
    BOOK.tex This is the content file for the whole book and contains ONLY the following code:
        %!TEX root = ../Text-controls/\jobname.tex
        %!TEX TS-program = pdflatexmk  
  • TEXT-CONTROLS folder for the files controlling the content files. (After compilation, this folder will also contains the aux files, toc files, etc and the pdf for each chapter.)

    1.tex  Control of Chapter 1
    2.tex  Control of Chapter 2
    101.tex  Control of Appendix 1
    Each of the above files contains ONLY the following code:
        % !TEX TS-program = pdflatexmk
        \addtocounter{page}{n}  (where n+1 will be the number of the first page of the chapter.)
    BOOK.tex is the control file for the whole book and contains ONLY the following code:
        % !TEX TS-program = pdflatexmk
            \hspace{-12mm}{\Large \textsc{Name of the Book}}
            etc, etc

The same structure can be used for the ancillaries. See http://tug.org/pracjourn/2010-2/schremmer.html

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.