mercoledì 14 dicembre 2011

The Shunned House -- Managing Long Documents, Page size and margins, step 2

Since "The Shunned House" is over 60k characters long, one usually wonders if there is a way to subdivide this document in more manageable pieces. It would be neat to follow document's structure and create a separate file for every chapter, and a central document file to assemble all chapters in a single book.
It turns out that TeX -- and ConTeXt has such a mechanism. The \input <texfile> command tells TeX to search and load a TeX subdocument into the main document. With this feature, we can thus subdivide "The Shunned House" in five chapter, each beginning with \chapter{} and each ending with \stopcolumns.



So, our main document -- which we'll name "The_Shunned_House_3.tex" -- will have this form:

% -----------------------------
% individual chapter files -- and all TeX files
% to be included in this project --must
% be placed in the same directory
% of this document.
% ----------------------------
\starttext 
The Shunned House

By H. P. LOVECRAFT

\input chapter_1
\input chapter_2
\input chapter_3
\input chapter_4
\input chapter_5

\stoptext
Files named chapter_[xxx] will contain -- of course! -- chapter text. After you've created and filled single chapters, compile and test the document by launching texexec The_Shunned_House_3.tex

Page and Margins

Our document is slowly taking shape -- we already have a two-columns layout, chapters do have their own style, but all small things that give an RPG its distinctive look -- page layout, fonts, colors, etc. -- are lacking. From now on, we'll see how to implement them. Let's start by setting proper margins.

Create a new tex file, in the same directory of The_Shunned_House_3 named preamble.tex. This new file won't contain any body text. Instead, it'll contain the commands needed to give our document the needed look. We will edit this file and we will then include it in the main document file, by using \input command.

Let'start by setting page size, page margins and first line indentation. Here's the first iteration of preamble.tex

%---------------- page size, spacing ------------------------------
\setuppapersize[a4][a4] 
\setuplayout[topspace=0.5cm,
            backspace=2cm,
               header=1.5cm,
               footer=2cm,
           leftmargin=2cm,
          rightmargin=1cm,
                width=fit,
               height=fit]

%----------- page numbering -- symmetrical layout ---------
\setuppagenumbering[alternative=doublesided]

%---- first line indentation -------------------------------
\parindent=0.5cm

Wow! four new commands! Let's examine them:

\setuppapersize tells ConTeXt that our document must be laid out on a page of the type specified on the first parameter, and printed on a sheet of the type specified on the second parameter. We could lay out our book on a A5 sheet and generate PDF with A4 pages, for instance.

\setuplayout set page margins for our document. It's got a lot more parameter than those shown; I'll dedicate a future post to the intricacies of layout setting because, by working some trickeries with layout parameters, you can implement some nifty page designs. For now, you should stick with these definitions. What you're going to get is a page which has a footer 2cm high, an header 1.5cm high whose distance from top border is 5mm, a left margin of 2cm and a right margin of 1cm. width and height parameters have the fit value: these parameters determine the size of main text area, and these values tell ConTeXt that the size of these area must be computed out by taking into account previous layout parameters.

\setuppagenumbering is used to set up page numbering style. This form, however, tells ConTeXt that layout specified in the previous command must be mirrored for facing pages. This means that anything placed on the "left" side means on the "internal" side, near the book spine, while anything on the "right" side means on the "external" side. So "leftmargin" means "internal margin", and "right margin" means "external margin".
\parindent is more a variable than a command. We use it to set first line indent for new paragraph. It is very useful to improve text readability. When you'll render the document, you will notice that all paragraph starting from second one will have their first line of text indented by 5 millimeters.

So, save the document with the name preamble.tex and include it in the main file, this way.

% -----------------------------
% individual chapter files -- and all TeX files
% to be included in this project --must
% be placed in the same directory
% of this document.
% ----------------------------

% -- page layout definitions usually go BEFORE main text
\input preamble


\starttext 
The Shunned House

By H. P. LOVECRAFT

\input chapter_1
\input chapter_2
\input chapter_3
\input chapter_4
\input chapter_5

\showlayout

\stoptext
Compile the project and compare with previous PDF: you'll notice smaller margins, and different layout for even and odd pages. If your PDF viewer has "book view mode", where you can see facing pages, activate it. You'll notice internal and external margins. And notice paragraph indentation.

While text proportions are far from optimum, the book is starting to resemble an RPG manual. Just one more word about the \showlayout command near the end: this command draws layout borders and outputs all \setuplayout parameters, including those not explicitly specified.. If you want to tinker with \setuplayout, you'll want to check results by examining \showlayout output.

Next time, we'll see how to format text span, and change font sizes.

The documents mentioned in this post can be downloaded here

Nessun commento:

Posta un commento