KatherinePupo / latex-lab

Automatically exported from code.google.com/p/latex-lab
0 stars 0 forks source link

Assemble document from multiple files (e.g. chapters of book) #260

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When writing a book, it's desirable to keep separate chapters in separate files 
and then include them all in the main document. This makes the chapters easier 
to manage, and allows them to be edited individually.

It would be nice to be able to compile and preview one of these individual 
chapters while editing it (getting the benefits of the split editing view), 
without having to switch to and compile the file for the entire book.

To allow previewing an individual chapter in this way the chapter needs to have 
its own \begin{document}, but LaTeX doesn't allow a file with its own document 
section to be included inside another document, meaning a chapter can't be both 
able to previewed on its own and able to be embedded in a larger document (the 
entire book).

The following package has an \includedoc function. Perhaps that would be the 
easiest way to make this possible.

http://tug.ctan.org/pkg/newclude

Am I being ignorant of an easy way to use this package, even though it doesn't 
seem to be available?

Original issue reported on code.google.com by markd...@gmail.com on 11 Jun 2011 at 4:06

GoogleCodeExporter commented 9 years ago
For anyone else trying to do this, this is how it can be achieved:

Have a main document using \documentclass{book}. Whenever you want to include 
the contents of another document, use \input{Ref} where Ref is the ID for a 
document that you've ticked in Project > Project Resources.

When editing the document that you want to include, DON'T use any 
\documentclass{}'s, \begin{document}s, etc. Just start with \chapter{Chapter 
Name} (assuming it's an entire chapter) and then write the chapter using 
standard LaTeX syntax. Before you can preview the chapter you'll need to tick 
the main document for the entire book in Project > Project Resources, and then 
in that dialogue choose that document as the Primary Resource (rather than 
"Current Document"). For some reason that setting isn't saving in my test 
document, and so I need to follow those steps in Project > Project Resources 
every time I edit a chapter. Still, once I've done that the results are fairly 
satisfactory. I can preview the entire book, but clickable line numbers only 
appear in the preview for the section that I'm currently editing and they work 
just as you'd expect them to.

In short, the document you select as Primary Resource in Project > Project 
Resources is the file that will be rendered in the Preview. \input is how you 
can include code from other files, thus neatly dividing a book into chapters.

Original comment by markd...@gmail.com on 20 Jul 2011 at 10:51