\startcomponent work-en-document

\product work-en

\chapter{How to create a document}

\index{input file}

Let's assume you want to create a simple \PDF\ document for printing. It has
some structure and contains a title page, a few chapters, sections and
sub sections. Of course there is a table of contents and an index.

\CONTEXT\ can create such a document automatically if you
offer the right input by means of a file. So first you have
to create an input file. An input file consists of a name
and an extension. You can choose any name you want but the
extension has to be \type{tex}. If you create a file with
the name \type{myfile.tex} you will find no difficulties in
running \CONTEXT.

An \pagereference[inputfile] input file could look like
this:

\startbuffer
\starttext

\startstandardmakeup
  \midaligned{How to make a document.}
  \midaligned{by}
  \midaligned{The Author}
\stopstandardmakeup

\completecontent

\chapter{Introduction}

... your text\index{indexentry} ...

\chapter{One Chapter}

\section[firstsection]{The first section}

... your text ...

\section{The second section}

\subsection{the first sub section}

... your text\index{another indexentry} ...

\subsection{the second sub section}

... your text ...

\section{The third section}

... your text ...

\chapter{Another Chapter}

... your text ...

\chapter[lastchapter]{The Last Chapter}

... your text ...

\completeindex

\stoptext
\stopbuffer

{\switchtobodyfont[9pt]\typebuffer}

\CONTEXT\ expects a plain \UTF\ input file. Of course you can
use any texteditor or wordprocessor you want, but you should not
forget that \CONTEXT\ can only read text files, no binary
formats. Most text editors and word processors can export your file
as \UTF\ or the subset thereof, \ASCII.

The input file should contain the text you want to be
processed by \CONTEXT\ and the \CONTEXT\ commands. A
\CONTEXT\ command begins with a backslash~\tex{}. With
the command \type{\starttext} you indicate the beginning of
your text. The area before \type{\starttext} is called the
set up area and is used for defining new commands and setting up
the layout of your document.

A command is often followed by a left and right bracket
pair \type{[]} and/or a left and right brace \type{{}}. 

Except for a few very special cases that will be discussed in later
chapters, arguments between curly braces are in some way typeset by
the command, whereas arguments between square brackets modify or
augment the behaviour of the command. Arguments in square brackets
are sometimes optional.
 
In \type{\chapter[lastchapter]{The Last Chapter}} the command
\type{\chapter} for example tells \CONTEXT\ to perform a
few actions concerning design, typography and structure.
These actions may be:

\startitemize[n,packed]
\item start a new page
\item increase chapter number by one
\item place chapter number in front of chapter title
\item reserve some vertical space
\item use a big font
\item put chapter title (and page number) in table of contents
\stopitemize

These actions will be performed on the argument that is
given between the left and right braces: \type{{The Last
Chapter}}.

The \type{[lastchapter]} between brackets has not been
mentioned yet. This is a label with a logical name that can
be used for refering to that specific chapter. This can be
done with yet some other \CONTEXT\ commands:
\type{\in{chapter}[lastchapter]} that typesets the chapter
number, while \type{\about[lastchapter]} returns the title.

So now the list of actions can be extended with:

\startitemize[continue]
\item let label \type{lastchapter} be chapter number
      and title (and store these for later use)
\stopitemize

Other actions concerning running heads, number resetting and
interactivity are disregarded at this moment.

Assuming you have succeeded in making \CONTEXT\ process this example
file, you will obtain a very simple document with a few numbered
chapters and section headers (running \CONTEXT\ is explained in
the next section).

While processing the file \CONTEXT\ takes care of many things.
One of these things is for example page numbering.  But in order
to make a table of contents \CONTEXT\ needs page numbers that
are not yet known to \CONTEXT\ at the first run, so it will have
to process the input file twice (a two pass job). \CONTEXT\ will
produce an auxilliary file to store this kind of information.
In some instances \CONTEXT\ has to proces an input file thrice
or even more often, for example because inclusion of a table of
contents can change the following page numbers. 

\stopcomponent
