\startcomponent correspondence-letter-reference

\environment correspondence-environment

% Text for each example

\startbuffer[reference]

\setupletterstyle
  [whitespace=line]

\setupletter
  [name=Willi Maier,
   phone=01234-56789,
   fax=3456-9853,
   date=\currentdate]

\setupletter
  [fromname={Max Mustermann},
   fromaddress={Musterstraße 12\\12345 Musterstadt}]

\setupletter
  [toname={Hans Hansen},
   toaddress={Zielgasse 23\\34789 New Mustertown}]

\setupletter
  [subject={Grund des Anschreibens},
   opening={Sehr geehrte Damen und Herren,},
   closing={Mit freundlichen Grüßen}]

\stopbuffer



% Chapter intro

\chapter{Reference line}

The reference lines is used to show information like the date and other information.

A few styles are predefined and you can select them with:

\starttyping
\setupletterstyle[reference][alternative=...]
\stoptyping

By default only the current date is shown in the reference line but you can change
this with list key, you can give a single value or a comma list as argument.

\starttyping
\setupletterstyle[reference][list=...]
\stoptyping

For backward compatibility you could set both values also with the \type{\setupletter}
command which are passed down to the \type{\setupletterstyle} command.

\starttyping
\setupletter
  [alternative=...,
   list=...]
\stoptyping



% Alternative a

\start

\getbuffer[reference]

\setupletter
  [alternative=a,
   list={name,phone,date}]

\setupletter
  [name,date,phone]
  [titlestyle=\tfx]

\startletter
\input knuth\par
\stopletter

\stop

\section{Alternative \type{a}}

The reference alternative \type{a} is enabled with the default style, the only
value you can see is the date. The setup in the default style for the reference
line is like this:  

\starttyping
\setupletterstyle
  [reference]
  [alternative=a,
   list=date]
\stoptyping

This leads to the following output, you get two lines which are aligned to the right
side with a label in the current mainlanguage on the top line and the current date
on the bottom line.

\start

\startelement
\letterelement[reference][a]
\stopelement

\stop

You could also show more elements in the reference line when you write them
as argument the list key.

\starttyping
\setupletterstyle
  [reference]
  [list={name,phone,date}]
\stoptyping

The values are shown in the given order and spread across the line like below.
To get this effect you need a list with at least two elements, otherwise it
is moved to the right side lie you can see in the first example.

\start

\getbuffer[reference]

\setupletterstyle[reference][alternative=a,list={name,phone,date}]

\startelement
\letterelement[reference][a]
\stopelement

\stop



% Alternative b

\start

\getbuffer[reference]

\setupletter
  [alternative=b,
   list={yourref,yourmail,myref,mymail,line,name,room,phone,fax,line,date}]

\setupletter
  [yourref,yourmail,myref,mymail,line,name,room,phone,fax,line,date]
  [titlestyle=\tfxx,
   separator=: ]

\setupletter
  [yourref=,
   yourmail={2880-01-15},
   myref={IV 1 - 24 00},
   mymail=,
   name={Max Mustermann},
   phone={01234-56789},
   fax={3456-9853},
   date=\currentdate]

\startletter
\input knuth\par
\stopletter

\stop

\section{Alternative \type{b}}

\starttyping
\setupletterstyle
  [reference]
  [alternative=b]

\setupletter[date][separator=: ]
\stoptyping

\start

\setupletter[date][separator=: ]

\startelement
\letterelement[reference][b]
\stopelement

\stop

\starttyping
\setupletterstyle
  [reference]
  [alternative=b,
   list={name,phone,date}]

\setupletter
  [name,phone,date]
  [separator=: ]
\stoptyping

\start

\getbuffer[reference]

\setupletter
  [name,phone,date]
  [%titlestyle=\tfxx,
   separator=: ]

\setupletterstyle[reference][list={name,phone,date}]

\startelement
\letterelement[reference][b]
\stopelement

\stop

\starttyping
\setupletter
  [name,phone,date]
  [titlestyle=\tx,
   separator=: ]
\stoptyping

\start

\getbuffer[reference]

\setupletter
  [name,phone,date]
  [titlestyle=\tx,
   separator=: ]

\setupletterstyle[reference][list={name,phone,date}]

\startelement
\letterelement[reference][b]
\stopelement

\stop



% Alternative c

\start

\getbuffer[reference]

\setupletter
  [alternative=c,
   list=reference]

\setupletter
  [reference=\rightaligned{Place, \currentdate}]

\startletter
\input knuth\par
\stopletter

\stop

\section{Alternative \type{c}}

\starttyping
\setupletterstyle
  [reference]
  [alternative=c,
   list=reference]

\setupletter[reference=\rightaligned{\currentdate}]
\stoptyping

\start

\setupletterstyle[reference][list=reference]

\setupletter[reference=\rightaligned{\currentdate}]

\startelement
\letterelement[reference][c]
\stopelement

\stop

\starttyping
\setupletterstyle
  [reference]
  [alternative=c,
   list=reference]

\setupletter
  [reference=\line{\lettervalue{name}\hfill\lettervalue{date}}]
\stoptyping

\start

\getbuffer[reference]

\setupletterstyle[reference][list=reference]

\setupletter[reference=\line{\lettervalue{name}\hfill\lettervalue{date}}]

\startelement
\letterelement[reference][c]
\stopelement

\stop

You could also use the alternative \type{c} to create your own reference line.

The following example show you a way to create own similar the alternative \type{a}
but now with a natural table and a hard coded order of the elements.

\starttyping
\setupletterstyle
  [reference]
  [alternative=c,
   list=reference]

\startsetups reference:customized

    \bTABLE[frame=off,offset=0pt,width=.25\hsize]
        \bTR
            \bTD \labeltext{letter:name}  \eTD
            \bTD \labeltext{letter:phone} \eTD
            \bTD \labeltext{letter:fax}   \eTD
            \bTD \labeltext{letter:date}  \eTD
        \eTR
        \bTR
            \bTD \lettervalue{name}       \eTD
            \bTD \lettervalue{phone}      \eTD
            \bTD \lettervalue{fax}        \eTD
            \bTD \lettervalue{date}       \eTD
        \eTR
    \eTABLE

\stopsetups

\setupletter
  [reference=\setups{reference:customized}]
\stoptyping

The code results in the following result.

\start

\getbuffer[reference]

\setupletterstyle[reference][list=reference]

\startsetups reference:customized
\bTABLE[frame=off,offset=0pt,width=.25\hsize]
  \bTR
    \bTD \labeltext{letter:name}  \eTD
    \bTD \labeltext{letter:phone} \eTD
    \bTD \labeltext{letter:fax}   \eTD
    \bTD \labeltext{letter:date}  \eTD
  \eTR
  \bTR
    \bTD \lettervalue{name}       \eTD
    \bTD \lettervalue{phone}      \eTD
    \bTD \lettervalue{fax}        \eTD
    \bTD \lettervalue{date}       \eTD
  \eTR
\eTABLE
\stopsetups

\setupletter[reference=\setups{reference:customized}]

\startelement
\letterelement[reference][b]
\stopelement

\stop


% Alternative d

\start

\getbuffer[reference]

\setupletter
  [alternative=d,
   list={yourref,yourmail,myref,mymail,line,name,room,phone,fax,line,date}]

\setupletter
  [yourref,yourmail,myref,mymail,line,name,room,phone,fax,line,date]
  [titlestyle=\tfxx,
   separator=: ]

\setupletter
  [yourref=,
   yourmail={2880-01-15},
   myref={IV 1 - 24 00},
   mymail=,
   name={Max Mustermann},
   phone={01234-56789},
   fax={3456-9853},
   date=\currentdate]

\startletter
\input knuth\par
\stopletter

\stop

\section{Alternative \type{d}}

\starttyping
\setupletterstyle
  [reference]
  [alternative=b]
\stoptyping

\start

\startelement
\letterelement[reference][d]
\stopelement

\stop

\starttyping
\setupletterstyle
  [reference]
  [alternative=d,
   list={name,phone,date}]
\stoptyping

\start

\getbuffer[reference]

\setupletterstyle[reference][list={name,phone,date}]

\startelement
\letterelement[reference][d]
\stopelement

\stop

\starttyping
\setupletter
  [name,phone,date]
  [separator=: ]
\stoptyping

\start

\getbuffer[reference]

\setupletterstyle[reference][list={name,phone,date}]

\setupletter[name,phone,date][separator=: ]

\startelement
\letterelement[reference][d]
\stopelement

\stop

\starttyping
\setupletter
  [name,phone,date]
  [titlestyle=\tx,
   separator=: ]
\stoptyping

\start

\getbuffer[reference]

\setupletterstyle[reference][list={name,phone,date}]

\setupletter[name,phone,date][titlestyle=\tx,separator=: ]

\startelement
\letterelement[reference][d]
\stopelement

\stop



% Alternative e

\start

\getbuffer[reference]

\setupletter
  [alternative=e,
   list={name,phone,date}]

\setupletter
  [name,date,phone]
  [titlestyle=\tfx,
   width=\dimexpr\textwidth/3\relax]

\startletter
\input knuth\par
\stopletter

\stop

\section{Alternative \type{e}}

\starttyping
\setupletterstyle
  [reference]
  [alternative=b]
\stoptyping

\start

\startelement
\letterelement[reference][e]
\stopelement

\stop

\starttyping
\setupletterstyle
  [reference]
  [alternative=e,
   list={name,phone,date}]

\setupletter
  [name,date,phone]
  [width=.25\textwidth]
\stoptyping

\start

\getbuffer[reference]

\setupletterstyle[reference][list={name,phone,date}]

\setupletter[name,date,phone][width=.25\hsize]

\startelement
\letterelement[reference][e]
\stopelement

\stop



% Alternative none

\start

\getbuffer[reference]

\setupletterstyle[reference][alternative=none]

\startletter
\input knuth\par
\stopletter

\stop

\section{Alternative \type{none}}

The last alternative \type{none} is different from the previous alternatives.

It disables the complete reference line and use as only alternative the values
from layout for the first page to the distance till the first line of the letter
while the other ignores this values and calculate it based on the position, height
and distance after the reference line.

You choose in the same way as the other alternatives.

\starttyping
\setupletterstyle
  [reference]
  [alternative=none]
\stoptyping



% User defined line

\start

\getbuffer[reference]

\defineletterelement[reference][customized]
  {\setupTABLE          [height=18mm,frame=off,offset=0pt]%
   \setupTABLE[c][1,2]  [width=50.8mm]%
   \setupTABLE[c][3,4,5][width=25.4mm]%
   \bTABLE
     \bTR
       \bTD[m=3]  \labeltext{letter:fax}    \\\lettervalue{fax}     \eTD
       \bTD       \labeltext{letter:email}  \\\lettervalue{email}   \eTD
     \eTR
     \bTR
       \bTD       \labeltext{letter:yourref}\\\lettervalue{yourref} \eTD
       \bTD       \labeltext{letter:myref}  \\\lettervalue{myref}   \eTD
       \bTD[nx=2] \labeltext{letter:phone}  \\\lettervalue{phone}   \eTD
       \bTD       \labeltext{letter:date}   \\\lettervalue{date}    \eTD
     \eTR
   \eTABLE}

\setupletterstyle
  [reference]
  [alternative=customized,
   voffset=\dimexpr80.4mm-\strutht\relax]

\setupletterstyle
  [firstpage]
  [topspace=11.5cm]

\setupletter
  [yourref={2880-01-15},
   myref={IV 1 - 24 00},
   name={Max Mustermann},
   phone={01234-56789},
   fax={3456-9853},
   date={\currentdate[year,--,mm,--,dd]}]

\startletter
\input knuth\par
\stopletter

\stop

\section{Customized reference line}

\start\setuptyping[bodyfont=small]
\starttyping
\defineletterelement[reference][customized]%
  {\setupTABLE          [height=18mm,frame=off,offset=0pt]%
   \setupTABLE[c][1,2]  [width=50.8mm]%
   \setupTABLE[c][3,4,5][width=25.4mm]%
   \bTABLE
     \bTR
       \bTD[m=3]  \labeltext{letter:fax}    \\\lettervalue{fax}     \eTD
       \bTD       \labeltext{letter:email}  \\\lettervalue{email}   \eTD
     \eTR
     \bTR
       \bTD       \labeltext{letter:yourref}\\\lettervalue{yourref} \eTD
       \bTD       \labeltext{letter:myref}  \\\lettervalue{myref}   \eTD
       \bTD[nx=2] \labeltext{letter:phone}  \\\lettervalue{phone}   \eTD
       \bTD       \labeltext{letter:date}   \\\lettervalue{date}    \eTD
     \eTR
   \eTABLE}
\stoptyping
\stop

%\starttyping
%\defineletterelement[reference][sideline]%
%  {}
%\stoptyping

\starttyping
\setupletterstyle
  [firstpage]
  [topspace=11.5cm]

\setupletterstyle
  [reference]
  [alternative=customized]
\stoptyping

\page[right]

\starttyping
\defineletterelement[reference][customized]%
  {\bTABLE[frame=off,offset=0pt,width=.25\hsize]
     \bTR
       \bTD \labeltext{letter:name}  \eTD
       \bTD \labeltext{letter:phone} \eTD
       \bTD \labeltext{letter:fax}   \eTD
       \bTD \labeltext{letter:date}  \eTD
     \eTR
     \bTR
       \bTD \lettervalue{name}       \eTD
       \bTD \lettervalue{phone}      \eTD
       \bTD \lettervalue{fax}        \eTD
       \bTD \lettervalue{date}       \eTD
     \eTR
   \eTABLE}
\stoptyping

\page[left]

\start

\useletterstyle[dina]

\getbuffer[reference]

\defineletterelement[reference][sideline]
  {\framed
     [frame=off,
      align={right,high},
      foregroundstyle=small,
      width=4cm,
      height=\textwidth]
     {Vorname Nachname\\
      01234/567890\\
      hans.meier@muster.de}}

\setupletterstyle
  [firstpage,secondpage]
  [topspace=8cm,
   width=13cm]

\setupletterstyle
  [reference]
  [alternative=sideline,
   hoffset=\dimexpr\backspace+\textwidth+1em\relax,
   voffset=\topspace]

\startletter
\input knuth\par
\stopletter

\stop

\starttyping
\defineletterelement[reference][sideline]
  {\framed
     [frame=off,
      align={right,high},
      foregroundstyle=small,
      width=4cm,
      height=\textwidth]
     {Vorname Nachname\\
      01234/567890\\
      hans.meier@muster.de}}

\setupletterstyle
  [firstpage,secondpage]
  [topspace=8cm,
   width=13cm]

\setupletterstyle
  [reference]
  [alternative=sideline,
   hoffset=\dimexpr\backspace+\textwidth+1em\relax,
   voffset=\topspace]
\stoptyping

\stopcomponent
