KOMA-scrartcl Type Area

From Wiki
Revision as of 00:49, 4 September 2005 by Brooks (talk | contribs) (Slight formatting and clarification.)
Jump to navigation Jump to search

< From LaTeX to ConTeXt >

LaTeX

The scrartcl class from the KOMA package does some fairly sophisticated calculations to determine an optimal page layout, with the text width set in terms of average characters-per-line, and the text height and location set to provide pleasing proportions based on that and the paper proportions. A sample document (with a framebox to show the text area) is simply:

\documentclass[DIVcalc,twoside]{scrartcl}
\begin{document}
\noindent\framebox{\rule{0pt}{\textheight}\rule{\textwidth}{0pt}}
\end{document}

ConTeXt

The following code duplicates the scrartcl calculations to set the text area and produces a similar sample document, again with a framed box to show the text area.

\def\BCOR{3mm}% eventual bounding correction
\newdimen\PageWidth \PageWidth=\paperwidth
\doifmode{BCOR}{\PageWidth=\dimexpr(\PageWidth-\BCOR)}
\edef\Ratio{\withoutpt{\the\dimexpr(2\paperheight/(\PageWidth/32768))}}
\setbox\scratchbox\hbox{\dorecurse{26}{\character\recurselevel}}
\newdimen\Width \newdimen\Height \newdimen\Back
\Width=\dimexpr(2.6\wd\scratchbox) \Height=\dimexpr(\Ratio\Width)
\doifmodeelse{oneside}{\Back=\dimexpr((\PageWidth - \Width) / 2)}
    {\Back=\dimexpr((\PageWidth - \Width) / 3)}
\doifmode{BCOR}{\Back=\dimexpr(\Back + \BCOR)}
\edef\Top{\the\dimexpr((\paperheight - \Height) / 3 - 3\lineheight)}
\Height=\dimexpr(\Height + 8\lineheight)
\setuplayout[backspace=\the\Back,height=\the\Height,width=\the\Width,
header=2\lineheight,headerdistance=\lineheight,
footer=2\lineheight,footerdistance=3\lineheight,topspace=\Top]

\starttext
\framed[width=\textwidth,height=\textheight]{}
\stoptext