Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to create a mini book with LaTeX on Windows in order to learn the basic thing with LaTeX.

I would like to divide my book into different projects but I have some sort of style defined for whole document. When I divide it into different section, I need to apply this design over and over again.

How can I achieve that without repeating myself? Is there something like Master Page on LaTeX?

share|improve this question
1  
The \input command is your friend. :) –  Count Zero Oct 19 '11 at 14:28
    
@CountZero if you can provide any sample code, you will be my friend ;) –  tugberk Oct 19 '11 at 14:29

4 Answers 4

up vote 6 down vote accepted

Suppose you have a main file, in which you have the style definitions. At some point then you can insert the other chapters like this:

\documentclass{article}

\usepackage{<somepackage>}

\begin{document}

Your text

\input{chapter1}

More text

\input{chapter2}

etc.

\end{document}

The \input command will take as an argument the name of the LaTeX file you want to insert. The extension is required only if it is different from .tex. There is the 'brother' of this command, \include. The difference is explained here: When should I use \input vs \include ?

share|improve this answer

Besides keeping you style definitions and list of packages in a separate file and including them with \usepackage{<somepackage>}, I'd recommend you use the standalone package as well. This will allow you to compile each chapter as you go and and then use that file directly in the main book.

So, first create a somepackage.sty file to contain all your custom macros and packages such as:

\usepackage{amsmath}% or any others that you use
\usepackage{lipsum}% for dummy text
\usepackage{standalone}% Need standalone package

This file will become sort of you master page. I'd include the geometry information for the margins in here, watermarks, as well as any footers, headers, etc...

Then create separate files for each chapter. Here is an example for chapter1.tex which is a complete file and can be compiled by itself:

\documentclass{book}
\usepackage{somepackage}% your custom list of macros and packages
\begin{document}
\chapter{First Chapter}
    \section{}
    \lipsum[1]% ... contents of chapter 1 here...
\end{document}

Similarly for the other chapters. Then your main file would look like:

\documentclass{book}  
\usepackage{somepackage}% your custom list of macros and packages

\begin{document}
  \input{chapter1}
  \input{chapter2}
\end{document}

One important thing to keep in mind is that main file must include the standalone package as well as all ALL the packages required by the individual chapter files.

share|improve this answer

It is opssible too to include the definitions. Assuming you have a file called layout.tex contaning all your packages (and maybe the class too) and definitions you can use it with

\documentclass{article}
\input{layout}
\begin{document}
  Text
\end{document}

If you like to use layout.tex in many documents you can move it to your user texmf folder to make LaTeX find it like a package or class file. To find out the right file open the “Run-Program“ (Don’t know the english name it’s “Eingabeaufforderung“ in German windows) and type kpsewhich -var-value=TEXMFHOME.

share|improve this answer

You could also use the subfiles package, which would allow you to have the entire preamble in the master document, and then each separate file will inherit the preamble of the main file when compiled. It functions similarly to the standalone package mentioned above.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.