Letter

From ConTeXt wiki
Jump to: navigation, search

< Modules | User:Wolfgang_Schuster >


NOTE: This module is still in development

Contents

Introduction

The letter module provides a interface to write different kinds of correspondence with the support for different styles and extensions.

Example

\usemodule[letter]

\starttext

\startletter
  [opening={Dear Reader,},
   closing={Best regards,},
   signature={The TeXnician}]

\input knuth

\stopletter

\stoptext

produces

Styles

The layout of the letter can be changed with styles, the module comes with styles for:

The predefined styles are loaded from external files with the \useletterstyle command, in the past these files had names in the form <style>.nls. The name system has changed and personal styles have to follow the form “letter-<style>.tex”, you could also use “mkiv” and “mkii” as extensions.

To load the style you need only the <style> part as argument for the command because the “letter-” part is always added. It doesn't matter if you use .tex or .mkiv as file extension because the file is found in either case.


\startletter, \stopletter

The letter environment has only optional arguments which acts like a local version of \setupletter where the values are only used in the environment. When you use your document only for a single letter without anything else you can even drop \starttext and \stoptext, because this is handled by \startletter and \stopletter.

Setup

Previously there has been only the \setupletterstyle command to change the values of the elements, now the various types of elements have dedicated commands.

The “layers” (which are used for the “head”, “address” or “reference line”) are configured with \setupletterlayer and \setupletterframe command, the first is used to move the layer to its position on the page with the “x” and “y” keys and you can select one letter elements (which are created with \defineletterelement) with the “alternative” key. With \setupletterframe you can change the “width” and “height” of the element.

Thus, for example, the following will produce a small, sans serif header, 10pt from the bottom of the page and centered.

\defineletterelement[layer][foot][example]%
                    {This is my footer.}
\setupletterlayer[foot][alternative=example,style=\tfx\sans,y=10pt]

\setupletterframe[foot][align=middle]


The “sections” (which are used for the “subject” and “content”) are configured with \setuplettersection which allows you to change the alignment and spacing before and after the element.

Global settings like the bodyfont, whitespace or language can be changed with \setuplettersoptions.

The old \setupletterstyle command had been reduced to change the style and color for the variables which are set with \setupletter (or \startletter), e.g. you can say \setupletter[date][textstyle=bold,color=red] to change the layout of the date in the reference line.

A complete list with all values for the various commands can be seen in the following document: commands.pdf

List of Layers and Sections

These layers are defined and configurable:

These sections are defined and configurable:

\defineletterelement

One limitation of the old module was that element names had been shared between layers and section (i.e. it was impossible to have a layer and a section with the same name). This limitation was removed and it’s now possible to layers and sections with the same name but to handle this the \defineletterlement command needed a additional argument. The syntax for the command is now

  \defineletterelement[<type>][<element>][<name>]{<content>}

As an example I show a definition for the head with the name “test” which prints the value of the “firstname” key.

  \defineletterelement[layer][head][test]{\correspondenceparameter{firstname}}

The old \copyletterelement command is no longer available.

\startsetups

The old version used \startsetups for the content of the elements. With the current version all internals use now \letterelement but there is a method to feed them with the \startsetups argument, all you need is \setupletteroptions[option=setups] in your document. Nevertheless also the names for \startsetups have been changed to follow the unique named mentioned above and the old name “letter:location” is now “letter:layer:location”.

Layout

The layout of the letter environment can be changed with \setupletterlayout, it is possible to use a different layout for the first (firstpage) and the following (secondpage) pages, but starting from the second page one can also set different value for left (leftpage) and right (rightpage) pages.

Variables/Labels

There is only one way to set values for the letter variables, this is \setupletter with it’s keyval syntax, e.g. \setupletter[name=…,address=…]. (\setlettervalue from the previous version is gone and won’t come back.)

To change the labels in the reference line for the “Date” string, you have to use \setuplettertext, a special version of \setuplabeltext only for the letter module.

Features

It is possible to change the default input method to the one used by Hans Hagen in the m-letter module or Donald Knuths letter style in the TeXbook.


Further Information

You can find more informations here: 

The manual for module was included in some versions of the package and is available from:

Examples

List of enclosures/attachments

   \usemodule[letter] 
   
   \setupletterdescription 
   [enclosure] 
   [ 
   location=top, 
   leftmargin=1em, 
   symbol=bullet, % or "none"
   ] 
   
   \setupletter 
   [enclosure={list:One,Two,Three}] 
   
   \startletter 
   \input knuth 
   \stopletter 

Hraban’s complicated logo and address setup

Same as in Invoice sample.

   \mainlanguage[nl]
   \usemodule[letter]
   
   \setuplanguage [nl] [date={year, –, mm, –, dd}] % ISO 8601 date
   
   \setupbodyfont    [rm, 10pt]
   \setupinterlinespace[3.0ex] % default: 2.8ex
   \setbreakpoints[compound] % break at / and -
   
   \setupletteroptions
     [language=netherlands,
      bodyfont={rm,10pt},
      whitespace=1.5ex, %3ex
      ]
   
   \setuptabulate[distance=0pt]
   
   \setupletter[
       % Sender address in envelope window
       backaddress={Pragma ADE · H.\,Hagen · Riderstraat 27 · NL-8061 GH Hasselt}
   ]
   
   % Define logo for the first page
   \defineletterelement[layer][head][example]%
       {\framed[background=logohead,height=35mm,frame=off,align=right]%
           {\externalfigure[biglogo]}}
   
   % Other logo for subsequent (right) pages
   \defineletterelement[layer][nexthead][example]%
       {\externalfigure[logo][height=2cm,width=6cm]}
   
   % We put our logo in the head
   \setupletterlayer[head,nexthead]
       [x=128mm,
        y=15mm,
        alternative=example]
   
   \setupletterlayer[nexthead][state=right]
   
   \setupletter[
       name={Hans Hagen},
       street={Ridderstraat 27},
       city={NL-8061 GH Hasselt},
       phone={+31 (0)38 477\,53\,69},
       mobile={+31 (0)38 477\,53\,69},
       email={hh@pragma-ade.com},
       web={www.pragma-ade.com},
       skype={whoknows}
   ]
   
   % center around the :
   \defineletterelement[layer][location][example]%
       {\setuptabulate[bodyfont=small]
       \starttabulate[|Irw(5em)|Ip|]
       \NC person     \NC\correspondenceparameter{name} \NC\NR
       \NC location   \NC\correspondenceparameter{street}\\\correspondenceparameter{city}\NC\NR
       \NC phone      \NC\correspondenceparameter{phone}\\\correspondenceparameter{mobile} \NC\NR
       \NC internet    \NC\correspondenceparameter{email}\\\correspondenceparameter{web} \NC\NR
       \NC skype       \NC\correspondenceparameter{skype} \NC\NR
   \stoptabulate}
   
   \setupletterlayer[location]
       [alternative=example,
       x=152mm,
       y=30mm
       ]
   
   
   % Our own recipient setup without too much space before the address
   \defineletterelement[layer][address][example]%
       {\correspondenceparameter{toname}\\
       \correspondenceparameter{toaddress}
       \par}
       
   \setupletterlayer[address][alternative=example]
   
   % Subject and date on the same line, date below logo
   \defineletterelement[section][subject][example]%
       {\bTABLE[frame=off]
       \bTR
           \bTD[width=\dimexpr169mm-\backspace\relax]\correspondenceparameter{subject}\eTD
           \bTD{\tf\correspondenceparameter{date}}\eTD
           %\bTD{\tf 2012-12-12}\eTD
       \eTR
   \eTABLE}
   
   \setuplettersection[subject][alternative=example]
   
   % account information at the foot, below the logo
   \defineletterelement[layer][foot][example]%
     {\setuptabulate[bodyfont=small]
     \starttabulate[|Irw(39mm)|Ip|]
           \NC financial \NC \NC\NR
           \NC tax no. \NC 1234567890 \NC\NR
           \NC UStID \NC NL\,123\,456\,789 \NC\NR
           \NC Account \NC 123\,456\,890\\Context bank, BIC NLPRCOHA \NC\NR
           \NC IBAN \NC NL12\,345\,678\,908\,12 \NC\NR
       \stoptabulate}
   
   \setupletterlayer[foot][
       preset=leftbottom,
       x=127mm,
       y=34mm,
       alternative=example]
   
   % switch off reference line
   \setupletterlayer[reference][state=stop]
   
   % Move the text a bit up
   \setupletterlayout[firstpage][topspace=10cm]
   
   % Adjust text start on subsequent pages
   \setupletterlayout[secondpage][topspace=3cm]
   
   % Move marks to the paper rim (won't print on most printers)
   \setupletterlayer[topmark,botmark,cutmark][x=-2mm]
   
   \startletter[
       toname={MIT\\Prof. Donald Knuth},
       toaddress={13, Anywhere Outthere\\Utopia, MA\\USA},
       subject={Regression in latest release of i\TEX}]
   
   \input knuth
   
   \blank[2*big]
   Best regards,
   \blank[small]
   
   \externalfigure[signature]%
   Hans Hagen
   
   \stopletter

C O N T E X T G A R D E N

Personal tools
Namespaces
Variants
Actions
Help
External Help
Installation
Navigation
Toolbox