18

I have researched the topic how to split my big book project into several files. Basically there are two main packages I found one should work with which are the “standalone” and the “subFile” package. It seems also that /input in combination with “standalone” is the best option for the whole setup since /input can be nested and with /standalone one can compile even the child files. besides with /input one can even connect glossary-term files into the main document. I hope that correct so far! Now I’m wondering if there is something like an “up-to-date best practice guide” here somewhere handling this topic or is there a chance to set something like that up here. I can imagine a lot of newbies like me would love such a guide for this important topic?

All the best A

aerioeus
  • 627
  • this is an opinion-based question, and as such a candidate for closure. the goal of having a "best practices" guide is a worthy one, but the methods often depend on the field involved, which gets messy. (although i disagree strongly with the method described, i was not responsible for the down-vote.) – barbara beeton Apr 13 '18 at 18:54
  • There are several best-practice questions at tex.stackexchange. This is an interesting question that deserves answers, not closing votes! – Sveinung Apr 13 '18 at 19:13
  • 3
    Is there any reason that you need a package at all, many books having been produced using the standard latex \include and \input commands. You do not give any requirements that suggest that you need anything else. – David Carlisle Apr 13 '18 at 19:18
  • Dear Community, sorry, I did not want to step on someone’s feet. My goal was simply to ask if the result my little research yielded was correct from a “pro” point of view and thought indeed it would be a good idea to have such “Starter guides” for most important topics anyone could basically use to get started. I know these types of guides for most questions from other forums (coding) and they usually serve their purpose well and are cherished by the community,. If the rules here are different then I apologize, will delete the post and reopen another one with a concrete question. Sorry A – aerioeus Apr 13 '18 at 21:24
  • 1
    @David, as you are asking: I have no predisposition regarding the topic. Jus5 wanted to make my 400 pages book easier to handle by splitting it up. If you say I don’t even need one of the 2 packages I have mentioned, even better. I just want to create separate files for each chapter, the glossary terms, the colors, the listlisting (code) and want to be able to compile each .tex file on its own not only .main. That’s about it...merci for any support since that topic is totally new (like the rest) for me. Cheers A – aerioeus Apr 13 '18 at 21:30
  • This is an interesting proposal: being able to compile parts of a document while they all share the same settings and can be combined together to form the whole thing. This is fundamentally different to just including chunks of source code. – lblb Apr 13 '18 at 21:54
  • @aerioeus If you want to compile each .tex on its own, I suggest the subfiles package, see https://tex.stackexchange.com/a/373439/36296 for a short example – samcarter_is_at_topanswers.xyz Apr 13 '18 at 21:55
  • @aerioeus While you wait for an answer to this question, can you go back to your previous ones and look if the answers solve your problems and accept them, if they do? – samcarter_is_at_topanswers.xyz Apr 13 '18 at 21:58
  • Merci @samcarter, I’m still doing my research elsewhere and will put the results here since I do believe such a question should have a basic guide...however as to you recommendation: am I right that you can compile every subfile independently when using the ‘subfile” package and each subfile will automatically use the preamble in the main file? – aerioeus Apr 13 '18 at 22:01
  • @aerioeus Correct! That is the main advantage of the subfiles package. – samcarter_is_at_topanswers.xyz Apr 13 '18 at 22:15
  • One thing I haven’t found a satisfying answer to is: how to handle references across a Multi-file .tex doc. Can anyone here can direct me or should I better open a separate question for that? Merci A – aerioeus Apr 13 '18 at 22:16
  • @aerioeus If you compile the main file, references across different subfiles work just fine. For compiling subfiles alone, there is a little trick in teh answer I linked to in my previous comment – samcarter_is_at_topanswers.xyz Apr 13 '18 at 22:20
  • Merci @samcarter, so you say basically that the “sub Files” package is superior/ better suited than the “Standalone” package? Or can I load both at the same time without a hicup? – aerioeus Apr 13 '18 at 22:23
  • @aerioeus In my opinion, the standalone package has a slightly different focus. It is suited to create images etc. in individual files and to include documents with different preambles into a large document. – samcarter_is_at_topanswers.xyz Apr 13 '18 at 22:29
  • @aerioeus If you have a minute, please have a look at How do you accept an answer? – samcarter_is_at_topanswers.xyz Apr 13 '18 at 22:32
  • Thank you for the hint, @samcarter, I will do the acceptances tomorrow. Merci A – aerioeus Apr 13 '18 at 22:43
  • looking at this (over long) comment thread my recommendation would still be to use the standard include mechanism and not standalone (which is mostly for different issues) or subfiles. – David Carlisle Apr 13 '18 at 23:09
  • Merci @David, but isn’t it true that without using the subfiles package I cannot compile the chapters individually but only the main file? That’s a big disadvantage from my point of view since I don’t need. All of the 400 pages to compile each time... – aerioeus Apr 13 '18 at 23:16
  • no the \includeonly mechanism allows you to work on one chapter at a time and as it is built in to the core of latex it does not cause complications with other packages for cross referencing etc. subfiles is useful if you have say many existing complete documents written as separate documents that you need to re-purpose as parts of a combined document (eg a conference proceeedings where each paper was written separately) but for a new document where you are writing chapters designed as chapters I would not use it – David Carlisle Apr 13 '18 at 23:30

1 Answers1

25

I think that the multifile howto is pretty easy, but as commented, it depends on what you want to achieve or how you organize your contents in the hard disk. Also, you must be aware that some package may not work as expected using subdocuments (before to start a big project, test your approach), but that is the main idea:

  1. You want to only split a huge text: Use \input or \include for whole chapters. For some partial previews of books/thesis the also standard \includeonly could be enough. More information in When should I use \input vs. \include?

  2. As above, but is very important for you to have instant previews of any subdocument (even sections) where you are working on, without deal with the main file at all: Then each subdocument must be a complete document by itself and use docmute, standalone or sufiles to include them (as incomplete document,i.e., without the preamble) in the main file. For more information just run texdoc docmute and texdoc standalone, etc.

  3. You have not only a huge text, but also a lot of images tables or something else that you want organize/store/manage in a hierarchical directory structure. The problem here is that obviously the relative paths of the subdocuments cannot work when included in a document that is another directory. The solution to this problem is to use the package import. It can combine with approach (2) at least with docmute (e.g., my answer in How to organize large documents in small nested folders). More information running texdoc import.

  4. You want a collection of independent manuscripts, such as conference proceedings. Then the combine class is an option. Run texdoc combine for more. Also, paper (an article-like class) documents can be combined with the journal class (warning: only German documentation in this case).

Indeed a best practice about any LaTeX task is search for a related topic in CTAN as https://ctan.org/topic/subdocs where there are some other packages for dealing with subdocuments.

Finally, if you are comfortable with Rmarkdown to produce LaTeX documents, then bookdown is an interesting option that cover points 1-3. Briefly, what bookdown make is merge all the sudocuments in a single markdown file and then is exported to LaTeX, so there are no need of special LaTeX packages or LaTeX commands for this. But you can also compile each subdocument as a normal rmarkdown file. If a subdocument not compilable as is, because include commands that need some package or definition loaded elsewhere, you can alwys specify in _bookdown.yml the list of files to compile in the book:

rmd_files: ["abstract.Rmd", "intro.Rmd"]

This make a preview only of the abstract and the introduction without headaches. With bookdown you only have to take care that all path o all files must be relatives to the main project directory.

More recently, Quarto markdown aims to be the sucessor of Rmarkdown and it have almost the same features that bookdown, but the proyect is managed from a _quarto.yml. For instance, if you have a book with four chapters, this file should have the list of these chapters in this way:

  chapters:
    - 01-chapter.qmd 
    - 02-chapter.qmd 
    - 03-chapter.qmd 
    - 04-chapter.qmd   

To make the PDF only with chapter 3, is just reduce the list to:

  chapters:
    - 03-chapter.qmd 

Or better:

  chapters:
    # - 01-chapter.qmd 
    # - 02-chapter.qmd 
    - 03-chapter.qmd 
    # - 04-chapter.qmd   

So you can restore the hidden chapter just removing the # that is the equivalent of % in LaTeX to convert the rest of the line in a comment.

Fran
  • 80,769
  • 1
    Merci; that was extensive answers a lot of my questions. – aerioeus Apr 14 '18 at 11:17
  • n.b. as noted here, the combine class is no longer compatible with current LaTeX distributions. Any alternate package suggestions would be appreciated. – jessexknight Aug 29 '23 at 12:41
  • @jessexknight Yes, unfortunatelly, afaik there are not still a similar alternative to combine different clasess, but maybe pdfpages or confproc could be useful for you. With several pros and cons, to work with large projects, and partial compllations, personally I prefer Quarto. – Fran Aug 29 '23 at 16:41
  • 1
    The original question is several years old. Currently, the subfiles package might be a good choice. It can also be used together with standalone. Once upon a time, the subfiles package had a different name, was not at CTAN, and did not have the LPPL license. Nowadays it has all of that. – rallg Aug 29 '23 at 17:22