% for use with ContTeXt (see pragma-ade.com)

% this ConTeXt inputfile calculates one variant of a
% 'Diagonalkonstruktion' as described in the German book  'Jan Tschichold,
% Ausgewählte Aufsätze über Fragen der Gestalt des Buches und der
% Typographie' on page 66. This is used for calculating the papersize,
% textarea and margins to get a layout for typestting.
% 
% see below on how to use this file 
%
% Patrick Gundlach (pg), 08.03.2001, 09:29 
% initial version (0.1)
% todo: double side support,
%       nicer output of the calculated parameters (list or table ...)
%       add other kind of construction (9er Teilung)
%       scalefactor 1 does not work (?) -> check!
%       code cleanup -> add macro for tan = sin/cos
%       understand what all of this is really doing
%       add an interactive part. use javascript and a webserver to 
%           fill out a simple form and code the parameters into an url,
%           then contact the webserver to generate a file on the fly
%           (cgi??)

% see end of file for a changelog

\setupcolors[state=start]
\setuppapersize[A4][A4]
\setuppagenumbering[state=stop]
%\setupbodyfont[ppl]
\starttext
\startuseMPgraphic{diag}

boolean show_labels, show_lines ; 

vardef mylabel@\#(suffix z) =
%  label@\#(str z & " (" & 
  label@\#( "(" & 
  decimal (round ( (xpart z/_unit) * (10 ** significance) )  /  (10 **
  significance))
  & "," & 
  decimal (round ( (ypart z/_unit)* (10 ** significance) )  /  (10 **
  significance)) & ")",z)
enddef;

% <-------------  instructions:  ------------------->

% specify *one* of the following parameters in order to get a result:
% paper_width, paper_height, text_height, text_width, right_margin,
% top_margin, left_margin, bottom_margin.
% be sure to multiply it with your _unit! 

% example: paper_width=15 * _unit;

unit=1mm;
paper_width=150 * _unit;

show_labels := true ;
show_lines := true;
scalefactor = 0.7;
significance = 0; % # of significant digits


_unit = unit * scalefactor;
pair a[];
pair e[],t[],s[]; % e=page, t=aux points, s=text


paper_width=2pu; paper_height=3pu; % paper width / paper_heigth = 2/3

% just to get the angle I have to define this (??????)
a1=(0,0);
a2=(0,3);
a3=(2,3);
a4=(2,0);
alpha =angle a3;
beta = 90 -alpha ;

e1=(0,0);
e2=(0,paper_height);
e3=(paper_width,paper_height);
e4=(paper_width,0);

t1=0.5[e1,e2];
t2=0.5[t1,e2];
t3=0.5[t2,e2];

a=ypart (e2-t2);
b= a  / (sind alpha / cosd alpha) ;

theta = angle (2,1.5);
gamma = 180 - theta - alpha;

b2 = ( (b*sind theta) / sind gamma);
left_margin=(cosd alpha) * b2;
top_margin=(cosd beta ) * b2;
right_margin = (top_margin * cosd theta) / sind theta;
bottom_margin = (right_margin * cosd beta) / sind beta;

s1 = (xpart e2 + left_margin, ypart e2 - top_margin);
s2 = (xpart e3 - right_margin, ypart s1);
s3 = (xpart s2, bottom_margin);
s4 = (left_margin,bottom_margin);

text_width=xpart s2-xpart s1;
text_height=ypart s1 -ypart s4;


if show_labels:
  mylabel.top (s1);
  mylabel.top (s2);
  mylabel.bot (s3);
  mylabel.bot (s4);

  mylabel.bot (e1);
  mylabel.top (e2);
  mylabel.top (e3);
  mylabel.bot (e4);

fi;

if show_lines:
  drawoptions (dashed (evenly));
  draw t1 -- e3 ;
  draw t1 -- (xpart e4, ypart t1);
  draw t2 -- (xpart e4, ypart t2);
  draw t3 -- (xpart e4, ypart t3);
  draw e4 -- e2 ;
  draw (xpart e2+b,ypart e2) -- (xpart e2+b, ypart e2-a) ;
  draw t3 -- (xpart e2+b,ypart e2);
  drawoptions();
fi;

pickup pencircle scaled 1mm;
draw (e1 -- e2 -- e3 -- e4 -- cycle) ;
draw (s1 -- s2 -- s3 -- s4 -- cycle) ;

\stopuseMPgraphic
\useMPgraphic{diag}
\stoptext

\endinput
% changelog: 
2001-03-08  Patrick Gundlach  <patrick@gundla.ch>

        * diagonal_1.tex: inital version



%%% Local Variables: 
%%% mode: tex
%%% TeX-master: t
%%% End: 
