# Working on Grid

## Enable grid typesetting

Typesetting on a grid is enabled with \setuplayout [grid=yes]. Alternative grid snapping methods are discussed in the description of \setuplayout. The grid can be visualized and debugged by using \showgrid.

## Placing structure heads on the grid

By default the structure heads are placed on the grid. Since the font size and often the baseline distance is different from the body text, things get more complicated. Single-line structure heads are simply placed on the grid. If the structure heads span multiple lines, then the last line is placed on the grid and the preceding lines are placed according to the corresponding baseline distance used for the head.

### Example

\setuplayout [grid=yes, width=12cm]
\definefont  [BigFont]  [Bold at 20pt] [24pt]

\showgrid
\starttext

\startsection [title=Lorem ipsum dolor]
\input ward
\stopsection

\startsection [title=Lorem ipsum dolor sit amet consectetur adipisicing elit]
\input ward
\stopsection

\stoptext


Lots of examples and the commands and options for head placement are provided in the manual It's in the details!. However, it is not covered how to place the first line of a multi-line structure head onto the grid. The solution is to frame the structure head and instruct to typeset the first line on the grid.

#### Example

% macros=mkvi
\setuplayout [grid=yes]
\definefont  [BigFont]  [Bold at 20pt] [24pt]

\unprotect
\newdimen\section_frame_width
\def\section_command#number#title{%
\section_frame_width\hsize             % we need to calculate the remaining
\setbox\scratchbox\hbox{#number\space} % horizontal space
#number\space
\framed [
width=\section_frame_width,
before=,
location=top,
align=right,]{#title}%
}

style=\BigFont,
after=,
before={\blank[2*line]},
command=\section_command,
]
\protect

\showgrid
\starttext
\startsection [title=Lorem ipsum dolor]
\input ward
\stopsection

\dorecurse{4}{%
\startsection [title=Lorem ipsum dolor sit amet consectetur adipisicing elit]
\input ward
\stopsection}
\stoptext


## Typesetting non grid aligned content

See the page design chapter of the new reference manual!

You can wrap that whole stuff inside

\startlinecorrection
...
\stoplinecorrection


The stuff inside that environment will not be grid-aligned, but the final resulting box will be.