% \iffalse meta-comment
%
% Copyright 2008, 2009, 2010 by Boris Oriet <http://boris.oriet.net>
% -------------------------------------------------------
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.3c or later is part of all distributions of LaTeX 
% version 2008/05/04 or later.
%
% This file has the LPPL maintenance status "author-maintained".
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{chletter.dtx}
\documentclass[a4paper]{ltxdoc}
\usepackage{hypdoc}
\pdfstringdefDisableCommands{\def\url{}}
\makeatletter
\let\PrintMacroName\HDorg@PrintMacroName
\let\PrintDescribeMacro\HDorg@PrintDescribeMacro
\makeatother
\setlength\parindent{0pt}
\setlength\unitlength{.59pt}
\CodelineIndex
\begin{document}
  \DocInput{chletter.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{1057}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v1.0}{2008/07/29}{Initial version}
% \changes{v1.1}{2009/11/05}{Internal interim version, minor changes}
% \changes{v2.0}{2010/10/10}{Code overhaul, new features, code frozen}
%
% \title{The \textsf{chletter} Document Class
% \thanks{This document corresponds to \textsf{chletter} v2.0, dated 2010/10/10.}}
% \author{Boris \textsc{Oriet}\\\url{http://boris.oriet.net}}
% \maketitle
% \bigskip\bigskip
% \tableofcontents
% \pagebreak
%
% \section{Introduction}
%
% The \textsf{chletter} class is suited for typesetting letters with letterhead 
% corresponding to the swiss norm SN~010130.\bigskip
%
% The default letterhead is set according to Swiss rules. It fits into both right
% and left windowed ISO 269 C5 and C6/5 envelopes.\bigskip
%
% This class is mostly compatible with the standard \LaTeXe{} classes.
% It is not limited to letters and may be used as a generic document class.\bigskip
%
% Its basic usage is very simple and user friendly. 
% It is appropriate to quickly typeset casual documents and letters.\bigskip
%
% It is however highly configurable and may be used within complex setups 
% to provide automated letters composition.
%
% \section{Usage}
%
% The following examples describe the regular usage of the \textsf{chletter} class.
% Basically, this class behaves in a similar way to a standard class and accepts the
% regular \textsf{letter} commands, including the dedicated |letter| environment. 
% Much like with standard classes, the only mandatory commands are |\documentclass|
% and the |document| environment (|\begin{document}| and |\end{document}|).
%
% \subsection{A basic letter}
%
% This example shows the plain usage of the \textsf{chletter} class.\medskip
%
% |\author|, |\address| and |\date| are markup commands which store
% global values used to build the letterhead. The |letter| environment actually creates the
% letter with its letterhead and all the needed layout. |\opening|, |\closing|, |\encl| and
% |\cc| are mainly formatting commands. To have multiple lines in a field, one may use
% |\newline| (shortcut |\\| as in this example) or |\par| (shortcut is an empty line).\medskip
%
% Please note that this example would also compile straightforward with the
% standard \textsf{letter} class (giving a somewhat different output).
%
% \begin{verbatim}
% \documentclass{chletter}
%
% \author{My name}
% \address{My address\\My city}
% \date{Location, \today}
%
% \begin{document}
%  \begin{letter}{Name\\Address\\City}
%   \opening{Salutation,}
%   Hello World!
%   \closing{Valediction.}
%   \encl{enclosures}
%   \cc{other recipients}
%  \end{letter}
% \end{document}
% \end{verbatim}
%
% \begin{figure}
% \begin{picture}(596,842)(0,0)
% \fontsize{7}{7}\selectfont
% \thicklines
% \put(0,0){\framebox(596,842){}}
% \thinlines
% \put(72,758){My name}
% \put(72,746){My address}
% \put(72,734){My city}
% \put(334,758){Location, October 10, 2010}
% \put(334,686){Name}
% \put(334,674){Address}
% \put(334,662){City}
% \put(108,542){Salutation,}
% \put(108,518){Hello World!}
% \put(108,494){Valediction.}
% \put(334,446){My name}
% \end{picture}
% \caption{Standard letter output by \textsf{chletter}.}
% \end{figure}
%
% \subsection{A customized letter}
%
% This example provides a good overview of the different class options and macros.\medskip
%
% The |leftwin| option is to be used with a left windowed envelope, inverting the sender's
% and recipient's addresses. The |leftsig| option places the signature against the left body
% margin. The |foldmark| option will include a thin line to help folding of C6/5 letters.
% The |footfill| option will throw the letter foot against the document footer, for refined
% vertical balancing.\medskip
%
% |\makelabels| creates an addtional envelope page with only the recipient's address and
% the sender's return address. |\addresswidth| adjusts the letterhead layout (here it is
% computed to right align the date field, mimicking the standard \textsf{letter} class
% behaviour). |\location|, |\name|, |\return| and |\telephone| are supplementary markup
% commands. |\object| and |\ps| are extra layout commands. |\longindentation| (which is
% also provided by the standard \textsf{letter} class) enables alignement of the text with
% the addresses.\medskip
%
% Please note that lines with a comment (|%|) should be removed to allow compilation with the
% standard \textsf{letter} class.
%
% \begin{verbatim}
% \documentclass[leftwin,leftsig,foldmark,footfill]{chletter}
%
% \settowidth\addresswidth{\today} %
%
% \makelabels
%
% \location{Our Company}
% \name{My name}
% \return{\fromlocation, My address, My city} %
% \address{My address\\My city}
% \telephone{My phone\\My email}
% \signature{My signature\\\footnotesize My position}
% \title{\textbf{About the \textsf{chletter} document class}}
%
% \begin{document}
%  \begin{letter}{Name\\Address\\City}
%   \object %
%   \opening{Dear \toname,}
%   Body text.
%   \closing{Yours truly,}
%   \encl{Enclosures}
%   \cc{Other recipients}
%   \ps{P. S.}{Don't forget\par\hspace{\longindentation}long indentation!}
%  \end{letter}
% \end{document}
% \end{verbatim}
%
% \begin{figure}
% \begin{picture}(596,842)(0,0)
% \fontsize{7}{7}\selectfont
% \thicklines
% \put(0,0){\framebox(596,842){}}
% \thinlines
% \put(424,758){Our Company}
% \put(424,746){My name}
% \put(424,734){My address}
% \put(424,722){My city}
% \put(424,710){\tiny My phone}
% \put(424,698){\tiny My email}
% \put(72,686){\textsuperscript{\underline{Our Company, My address, My city}}}
% \put(72,674){Name}
% \put(72,662){Address}
% \put(72,650){City}
% \put(424,614){October 10, 2010}
% \put(0,554){\line(1,0){18}}
% \put(108,542){\textbf{About the \textsf{chletter} document class}}
% \put(108,512){Dear Name,}
% \put(108,482){Body text.}
% \put(108,452){Yours truly,}
% \put(108,400){My signature}
% \put(108,388){\tiny My position}
% \put(72,168){\makebox(36,0)[r]{\strut encl~}}
% \put(108,168){\makebox(0,0)[l]{\strut Enclosures}}
% \put(72,144){\makebox(36,0)[r]{\strut cc~}}
% \put(108,144){\makebox(0,0)[l]{\strut Other recipients}}
% \put(72,120){\makebox(36,0)[r]{\strut P. S.~}}
% \put(108,120){\makebox(0,0)[l]{\strut Don't forget}}
% \put(424,108){\makebox(0,0)[l]{\strut |long indentation|!}}
% \end{picture}
% \caption{Customized letter output by \textsf{chletter}.}
% \end{figure}
%
% \begin{figure}
% \begin{picture}(596,842)(0,0)
% \fontsize{7}{7}\selectfont
% \thicklines
% \put(0,0){\framebox(596,842){}}
% \thinlines
% \put(72,686){\textsuperscript{\underline{Our Company, My address, My city}}}
% \put(72,674){Name}
% \put(72,662){Address}
% \put(72,650){City}
% \end{picture}
% \caption{Cover page output by \textsf{chletter}.}
% \end{figure}\pagebreak
%
% \section{Compatibility}
%
% The \textsf{chletter} class is based upon the standard classes of the \LaTeXe{} distribution. 
% Many documents founded on these classes will also compile with \textsf{chletter}.
%
% \subsection{With the \LaTeXe{} \textsf{letter} class}
%
% The \textsf{chletter} class is `source compatible' (ascending) with the standard 
% \textsf{letter} class. For the most part a file which compiles with \textsf{letter} will
% recompile straightforward with \textsf{chletter}. There are however some functional
% differencies, which are described in the following sections.
%
% \subsection{With other \LaTeXe{} classes}
%
% The \textsf{chletter} class is largely `source compatible' (ascending) with other standard
% \LaTeXe{} classes. It doesn't implement the sectioning mecanism, but accepts the related
% commands (|\section| for example). Some commands behave differently (|\maketitle| for
% example). Obvsiously, any command specific to the \textsf{chletter} class will prevent
% compilation with other classes.
%
% \subsection{With older versions of \textsf{chletter}}
%
% The \textsf{chletter} class has been completely overhauled between versions |1.0| and |2.0|.
% The new code is far more compact and efficient, so is its usage (the commands no more have
% a plethora of optional arguments). The versions of the class are mostly `source compatible,'
% given the deprecated commands are not used: |\conc| (replaced by |\object|), |\letterindent|,
% |\letterskip|, |\fromheight| (replaced by |\titletopheight|, |\toheight| (replaced by
% |\titlemidheight|) and |\stockheight| (replaced by |\titlebotheight|). To add a
% `compilability layer', the following code can be inserted in the preamble:
% \begin{verbatim}
%  \newcommand\conc[2]{\object{#2}}
%  \let\letterindent\parindent
%  \let\letterskip\parskip
%  \let\fromheight\titletopheight
%  \let\toheight\titlemidheight
%  \let\stockheight\titlebotheight
% \end{verbatim}
%
% \subsection{With upcoming versions of \textsf{chletter}}
%
% The \textsf{chletter} class is now considered mature and won't evolve further
% (the code is frozen). The class has been thoroughly tested, and there are no known deficiencies.
%
% \subsection{With other packages}
%
% The \textsf{chletter} class is generic in the sense that it doesn't rely on anything but
% the \LaTeXe\ kernel. There is no known command clash with any package.\medskip
%
% Please note that a \textsf{chextras} companion package is available (but not mandatory).
% It simplifies the preparation of documents and letters by loading and setting up font,
% linguistic and other common packages. It also implements a `glue code' for full source
% compatibility with older \textsf{chletter v1.0} documents.
%
% \section{Configuration}
% 
% The default values used by the \textsf{chletter} class are balanced for casual writing of
% simple articles (the class can eventually replace the standard \textsf{article} class) and 
% letters (of course). Nevertheless this class is highly configurable and customizable.
%
% \subsection{Class options}
%
% The \textsf{chletter} class accepts the options provided by the \LaTeXe\ default classes.
% These options are: |a4paper|, |a5paper|, |b5paper|, |letterpaper|, |legalpaper|,
% |executivepaper|, |landscape|, |10pt|, |11pt|, |12pt|, |oneside|, |twoside|, |draft|, |final|,
% |leqno|, |fleqn|, |onecolumn|, |twocolumn|. The defaults are: |a4paper|, |10pt|, |oneside|,
% |final|, |onecolumn|. Additionally, the \textsf{chletter} class provides four extra options
% (described just below) to adjust the general layout of the letters.\bigskip
%
% \DescribeMacro{leftwin}
% \DescribeMacro{leftsig}
% \DescribeMacro{foldmark}
% \DescribeMacro{footfill}
% |leftwin| places the recipient's address to the left of the letterhead rather than to the
% right. |leftsig| aligns the signature with the left body margin rather than with the right
% address. |foldmark| puts a thin line to help folding of C6/5 letters. |footfill| adds an
% infinite glue between the signature and the letter foot.
%
% \subsection{Page layout}
%
% The default page layout provided by the \textsf{chletter} class, while generic enough,
% leaves more place for the text than the standard classes do.\bigskip
%
% \DescribeMacro{\textwidth}
% \DescribeMacro{\textheight}
% \DescribeMacro{\oddsidemargin}
% \DescribeMacro{\evensidemargin}
% In a single sided document, the space between the top left corner of the page and the main
% text is (|1in + 36pt|, |1in + 36pt|); |36pt| are left for the header and the footer, along
% with |72pt| for the right and bottom margins. For A4 paper, the defaults are the following
% (values in inches and centimeters are rounded):
% \begin{verbatim}
% \textwidth       416pt [5.75in or 14.5cm]
% \textheight      630pt [8.75in or 22cm]
% \oddsidemargin   36pt  [.5in or 1.25cm]
% \evensidemargin  0pt
% \end{verbatim}
%
% \DescribeMacro{\titlehead}
% \DescribeMacro{\titletopheight}
% \DescribeMacro{\titlemidheight}
% \DescribeMacro{\titlebotheight}
% \DescribeMacro{\titlemargin}
% \DescribeMacro{\titlewidth}
% \DescribeMacro{\addressmargin}
% \DescribeMacro{\addresswidth}
% These values are used for the letterhead layout. They are related to the \TeX\ origin, which
% is (|1in|, |1in|) from the top left corner of the page. Please remember that |1in = 72.27pt|.
% |\titlehead| controls the vertical placement of the first baseline of the letterhead.
% |\titlemargin| and |\titlewidth| control the horizontal position and width of the letterhead.
% |\addressmargin| is where the title is split in two. |\addresswith| is the width of the right
% address fields. The title is built by opening a |letter| environment or by calling directly
% |\maketitle|. For A4 paper, the defaults are the following (values in inches and centimeters
% are rounded):
% \begin{verbatim}
% \titlehead       12pt [.16in or .4cm]
% \titletopheight  72pt [1in or 2.5cm]
% \titlemidheight  72pt [1in or 2.5cm]
% \titlebotheight  72pt [1in or 2.5cm]
% \titlemargin     0pt
% \titlewidth      452pt [6.25in or 16 cm]
% \addressmargin   262pt [3.625in or 9.25cm]
% \addresswidth    190pt [2.625in or 6.75cm]
% \end{verbatim}
%
% \begin{figure}
% \begin{picture}(595,842)(0,0)
% \fontsize{5}{5}\selectfont
% \thicklines
% \put(0,0){\framebox(596,842){}}
% \thinlines
% \put(74,758){|fromname|}
% \put(74,746){|fromaddress|}
% \put(336,758){|date|}
% \put(336,686){|toname|}
% \put(336,674){|toaddress|}
% \multiput(72,770)(0,-72){4}{\line(1,0){452}}
% \multiput(72,770)(262,0){2}{\line(0,-1){216}}
% \put(524,770){\line(0,-1){662}}
% \put(108,554){\line(0,-1){446}}
% \put(108,108){\line(1,0){416}}
% \put(110,542){|salutation|}
% \put(110,518){|text|}
% \put(110,494){|valediction|}
% \put(336,446){|signature|}
% \put(25,788){\vector(-1,0){25}}\put(47,788){\vector(1,0){25}}
% \put(0,788){\makebox(72,0){|1in|}}
% \put(170,788){\vector(-1,0){98}}\put(236,788){\vector(1,0){98}}
% \put(72,788){\makebox(262,0){|addressmargin|}}
% \put(398,788){\vector(-1,0){64}}\put(460,788){\vector(1,0){64}}
% \put(334,788){\makebox(190,0){|addresswidth|}}
% \put(272,806){\vector(-1,0){200}}\put(324,806){\vector(1,0){200}}
% \put(72,806){\makebox(452,0){|titlewidth|}}
% \put(560,800){\vector(0,-1){30}}\put(560,812){\vector(0,1){30}}
% \put(524,800){\makebox(72,12){|1in|}}
% \put(560,728){\vector(0,-1){30}}\put(560,740){\vector(0,1){30}}
% \put(524,728){\makebox(72,12){|titletopheight|}}
% \put(560,656){\vector(0,-1){30}}\put(560,668){\vector(0,1){30}}
% \put(524,656){\makebox(72,12){|titlemidheight|}}
% \put(560,584){\vector(0,-1){30}}\put(560,596){\vector(0,1){30}}
% \put(524,584){\makebox(72,12){|titlebotheight|}}
% \put(182,320){\vector(-1,0){74}}\put(260,320){\vector(1,0){74}}
% \put(108,320){\makebox(226,0){|longindentation|}}
% \put(396,320){\vector(-1,0){62}}\put(462,320){\vector(1,0){62}}
% \put(334,320){\makebox(190,0){|indentedwidth|}}
% \put(292,90){\vector(-1,0){184}}\put(340,90){\vector(1,0){184}}
% \put(108,90){\makebox(416,0){|textwidth|}}
% \end{picture}
% \caption{The default \textsf{chletter} layout.}
% \end{figure}
%
% \subsection{The \texttt{letter} environment}
%
% The |letter| environment performs some special actions in the scope of writing letters. At
% its beginning, it generates the letterhead according to its arguments and some previously
% defined values (see below). The |letter| environment takes in account some global options,
% for example |twocolumn|... so yes, it is possible to write two column letters! At its
% closing, the |letter| environment generates a cover page if needed (see below).\bigskip
% 
% \DescribeEnv{letter}
% The |letter| environment takes one `mandatory' argument : the recipient's address. The
% address should be formatted with newline markers (|\\|) as in the standard |letter| class.
% The argument is `tokenized' into |\toname| and |\toaddress|, which can be used in the
% letter body. The `token separator' is the first encountered |\\|\,. Please note that an
% invocation of the |letter| environment without argument will retrieve previously defined
% |\toname| and |\toaddress| values (empty by default).\medskip
%
% There is an optional argument to specify if the letter is to be indented |[i]| or not |[n]|
% where |[n]| is the default. Please note that this option will alter the formatting of general
% \LaTeX\ lists and \textsf{chletter} |\ps|, |\cc| and |\encl| commands (see below).\bigskip
%
% It is possible to open multiple |letter| environments within a single document. Global
% values may be shared between each letter (see next page). Please remember that environments
% involve some locality; for example a length value altered within a |letter| environment
% will recover its initial value outside of the environment.\medskip
%
% An ordinary usage would be:
% \begin{verbatim}
% \begin{letter}[i]{Toname\\ToAddressFirstLine\\...\\ToAddressLastLine}
% ...
% \end{letter}
% \end{verbatim}
%
% \subsubsection{Cover page}
%
% \DescribeMacro{\makelabels}
% Unlike the standard \textsf{letter} class, this macro doesn't involve a complex mecanism
% using the |.aux| file to build a labels page (the main reason why the standard class is
% fragile). Anyway, the \textsf{chletter} class provides a way to generate dedicated cover
% pages. The |\makelabels| command will set a flag which is checked at the closing of the
% |letter| environment. The default behaviour is to put the recipient's address and, as
% requested by the Swiss post, the return address above it, separated by a line. |\makelabels|
% doesn't take any argument.
%
% \subsubsection{Page breaking}
%
% These commands are intended to (try to) control the place where a page break occur.
% They may be used anywhere in a document.\medskip
%
% \DescribeMacro{\stopbreaks}
% |\stopbreaks| will try to prevent all page breaks after its invocation.\bigskip
%
% \DescribeMacro{\startbreaks}
% |\startbreaks| cancels the behaviour of |\stopbreaks|.
%
% \subsubsection{Letter counter}
%
% \DescribeMacro{\theletter}
% At each new |letter| environment opened, this counter is incremented. Please note that
% |thepage| and |thefootnote| counters are reset at the same time.
%
% \subsubsection{Letter markup}
%
% The commands described here are usually put in the preamble, but they may be called from
% anywhere in the document. They store their argument in associated values which will be
% retrieved by the |letter| environment, for example to build the letterhead. They are common
% to a bunch of letter classes.\medskip
%
% \DescribeMacro{\name}
% \DescribeMacro{\address}
% \DescribeMacro{\location}
% \DescribeMacro{\telephone}
% \DescribeMacro{\return}
% The values stored by these commands are respectively: |\fromname|, |\fromaddress|,
% |\fromlocation|, |\telephonenum| and |\returnaddress|. |\telephone| and |\return| will
% format their output (respectively small text and underlined superscript text). Please note
% that |\return| is not defined in the standard \textsf{letter} class. These values are used
% to build the expeditor's address fields:
% \begin{verbatim}
% \name{My Name}
% \address{My Street\\My City}
% \return{My Return Address}
% \end{verbatim}
%
% \DescribeMacro{\date}
% The date field (stored by kernel |\@date| value) can be customized by, for example:
% \begin{verbatim}
% \date{Here, \today}
% \end{verbatim}
%
% \DescribeMacro{\signature}
% The value stored by this macro is |\fromsig|, which is used by the |\closing| command to
% output the signature field (see below).\bigskip
%
% Please note that |\fromname| and |\fromsig| values default to |\@author| (initialized by
% \LaTeX, modified by the standard |\author| command). The |\@date| field defaults to
% |\today|, which will be localized by a linguistic package (\textsf{babel} or
% \textsf{polyglossia}).\medskip
%
% To prevent any value from appearing, it has to be emptied by the corresponding command,
% for example: |\date{}|.\medskip
%
% These macros can contain anything that fits in a |\parbox|, including some special stuff
% (using dedicated packages): |\location{\includegraphics{mylogo.pdf}}|\medskip
%
% Any of the values stored by these commands can be retrieved anywhere in the letter (given
% the corresponding value is accessible, |\@author| and |\@date| requiring a |\makeatletter|):
% |I, \fromname, declare...|
%
% \subsubsection{Letter body}
%
% These commands are mostly used within a letter environment, but they may be called at
% document level for special purpose. Their foremost intend is formatting, although they are
% able to retrieve or store their value at will.\medskip
%
% \DescribeMacro{\object}
% This command will simply output the text given in its argument, followed by a |\bigskip|.
% The |\object| command stores its argument in |\@title| and actually outputs it. If the
% argument is either empty or null, then the |\object| command will output the value of
% |\@title| previously set by a |\title| command. Remember that the default |\@title| value
% is an error (set by the \LaTeX\ kernel):
% \begin{verbatim}
% \title{Answer to your previous letter}
% ...
% \begin{document}
% \begin{letter}{...}
% \object
% \end{verbatim}
%
% Please note that the following code is functionally equivalent (the |\@title| value set by
% both methods is global (available outside of the current letter environment):
% \begin{verbatim}
% \begin{document}
% \begin{letter}{...}
% \object{Answer to your previous letter}
% \end{verbatim}
%
% \DescribeMacro{\opening}
% This command outputs the text given in its argument (adding a |\medskip| vertical space
% after it):
% \begin{verbatim}
% \opening{Dear Sir,}
% \end{verbatim}
%
% It stores its argument in |\salutation| for further use. |\salutation| can also be defined
% previously and be recalled by an |\opening| with an empty or null argument:
% \begin{verbatim}
% \renewcommand{\salutation}{Dear Sir,}
% ...
% \begin{document}
% \begin{letter}{...}
% \opening
% \end{verbatim}
%
% \DescribeMacro{\closing}
% This command issues a |\medskip|, outputs the text given in its argument and generates
% the signature field, which should provide its own vertical spacing (by default it is
% |4\bigskip| above the signature and |2\bigskip| below):
% \begin{verbatim}
% \closing{Yours sincerely,}
% \end{verbatim}
%
% The signature field placement can be altered by invocation of |leftsig| as a
% class option. The signature field will contain the value defined by:
% \begin{itemize}
% \item[---] |\fromsig|  (set by |\signature{...}|) in the first place;
% \item[---] |\fromname| (set by |\name{...}|) if no |\signature| given;
% \item[---] |\@author| (set by |\author{...}|) if no |\name| given (eventually empty).
% \end{itemize}
%
% The |\closing| macro stores its argument in |\valediction| for later use. As usual, the
% |\valediction| value can also be defined before and be output by an invocation of
% |\closing| with an empty or null argument:
% \begin{verbatim}
% \renewcommand{\valediction}{Yours sincerely,}
% \begin{document}
% \begin{letter}{...}
% ...
% \closing{}
% \end{verbatim}
%
% Depending on the class option |footfill|, an extra vertical glue will be added after the
% signature, in order to balance the appearance of the letter foot. |footfill| pushes the
% letter foot text against the document footer (usually the the letter foot is filled by the
% |\ps|, |\encl| and |\cc| commands). Please note that for a weaker balance a |\vfil| could
% be manually added after the |\closing| command.\bigskip
%
% Be aware of the locality of macros. |\salutation| and |\valediction| values are local to
% the current |letter| environment if defined within the environment (usually by |\opening|
% and |\closing| commands), global otherwise. Please look at the \LaTeX\ documentation for
% further explanations.
%
% \subsubsection{Letter foot}
%
% Some formatting commands are intended to be used at the end of the letter (although they
% can be used anywhere in the document, even outside of a letter environment---just as any
% formatting command provided by the \textsf{chletter} class).\bigskip
%
% \DescribeMacro{\ps}
% This command is generic in the sense that it is nothing but a shortcut for a \LaTeX\ list.
% It takes two mandatory arguments. The text contained in the arguments is output as an
% indented paragraph. The indentation margin is set by the standard \LaTeX\ |\leftmargin|
% value (which defaults to |18pt| at document level, |0pt| after the |\closing| of a default
% letter and |36pt| after the |\closing| of an indented |[i]| letter). Here is an example use:
% \begin{verbatim}
% \ps{P.S.}{This is a post scriptum}
% \end{verbatim}
%
% \DescribeMacro{\encl}
% This command is a shortcut for |\ps{\enclname}{...}| and takes one mandatory argument.
% Regular use is:
% \begin{verbatim}
% \encl{1. Your previous letter\\2. My Curriculum Vit\ae}
% \end{verbatim}
%
% \DescribeMacro{\cc}
% This command is a shortcut for |\ps{\ccname}{...}| and takes one mandatory argument.
% Regular use is:
% \begin{verbatim}
% \cc{1. First other recipient\\2. Second other recipient}
% \end{verbatim}
%
% |\enclname| and |\ccname| are set to |{encl}|, respectively |{cc}| by default.
% They will be adjusted by a linguistic package (\textsf{babel} or \textsf{polyglossia}).
%
% \subsection{Sectioning}
%
% \DescribeMacro{section}
% \DescribeMacro{subsection}
% \DescribeMacro{subsubsection}
% \DescribeMacro{paragraph}
% \DescribeMacro{subparagraph}
% The class is intended to output short documents (mainly letters!), so the sectioning mecanism
% is minimalist (no index nor table of contents generation). The stock sectioning commands are
% here: |section|, |subsection|, |subsubsection|, |paragraph|, |subparagraph|, but are merely
% formating commands which select some text style and vertical space. As usual, these commands
% take one mandatory argument.
%
% \subsection{Environments}
%
% \DescribeMacro{description}
% \DescribeMacro{verse}
% \DescribeMacro{quotation}
% \DescribeMacro{quote}
% These environments are available and behave as ordinary in the \textsf{chletter} class.
% The default list values (at document level) are:|\labelsep6pt|, |\labelwidth12pt|,
% |\leftmargin18pt|. Please note that |\labelwidth| and |\labelsep| are redefined by a
% |\closing| command to |\leftmargin2\parindent|, |\labelwidth3\labelwidth|.
%
% \subsection{Paragraphing}
%
% \DescribeMacro{\parindent}
% \DescribeMacro{\parskip}
%|\parindent| and |\parskip| respectively default to |18pt| and |9pt| at document level. If
% a |letter| environment is called with the |[i]| option, |\parindent| is kept at its previous
% value. With the default |[n]| option, |\parindent| is locally set to |0| (zero).\bigskip
%
% Please note that the actual value of |\parindent| while a |\closing| command is issued
% will alter the layout of \LaTeX\ lists (in fact |\ps|, |\encl| and |\cc| are lists): the
% |leftmargin| value (which defaults to |18pt|) is then defined as three times the value of
% |\parindent| (thus |0pt| for a default letter and |36pt| for an indented letter).
%
% \StopEventually
%
% \section{Implementation}
%
% The \textsf{chletter} code is fairly compact (less than 300 lines) and highly optimized
% (it relies on \TeX\ primitives wherever practical), dropping the obsolete legacy (namely
% \LaTeX\ 2.09) for the sake of efficiency.\bigskip
%
% Appart from the options described until now, it is possible (and allowed!) to `hook' into
% certain pieces of the class code. This enables a degree of customization and extensibility.
% It would be quite straightforward to add, for example, mail merging features through a
% dedicated package.
%
% \subsection{Initial code}
%
%    \begin{macrocode}
%<*chletter.cls>
%    \end{macrocode} 
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{chletter}[2010/10/10 v2.0 Swiss letter document class]
%    \end{macrocode}
%
% \subsubsection{Declaring options}
%
% \begin{macro}{leftwin}
% \begin{macro}{leftsig}
% \begin{macro}{foldmark}
% \begin{macro}{footfill}
% There are four specific options: |leftwin|, |leftsig|, |foldmark| and |footfill|,
% corresponding to the format of the letter (left envelope window, left signature, folding
% mark for C6/5 covers, letter foot balancing). The default is to not set any of these options.
% All other options are borrowed from the standard classes.
%
%    \begin{macrocode}
\DeclareOption{a4paper}{\paperheight297mm\paperwidth210mm}
\DeclareOption{a5paper}{\paperheight210mm\paperwidth148mm}
\DeclareOption{b5paper}{\paperheight250mm\paperwidth176mm}
\DeclareOption{letterpaper}{\paperheight11in\paperwidth8.5in}
\DeclareOption{legalpaper}{\paperheight14in\paperwidth8.5in}
\DeclareOption{executivepaper}{\paperheight10.5in\paperwidth7.25in}
\DeclareOption{landscape}
{\@tempdima\paperheight\paperheight\paperwidth\paperwidth\@tempdima}
\DeclareOption{10pt}{\def\@ptsize{0}}
\DeclareOption{11pt}{\def\@ptsize{1}}
\DeclareOption{12pt}{\def\@ptsize{2}}
\DeclareOption{oneside}{\@twosidefalse\@mparswitchfalse}
\DeclareOption{twoside}{\@twosidetrue\@mparswitchtrue}
\DeclareOption{draft}{\overfullrule5\p@}
\DeclareOption{final}{\overfullrule\z@}
\DeclareOption{leqno}{\input{leqno.clo}}
\DeclareOption{fleqn}{\input{fleqn.clo}}
\DeclareOption{onecolumn}{\@twocolumnfalse\@leftsigfalse}
\DeclareOption{twocolumn}{\@twocolumntrue\@leftsigtrue}
\DeclareOption{leftwin}{\@leftwintrue}
\DeclareOption{leftsig}{\@leftsigtrue}
\DeclareOption{foldmark}{\@foldmarktrue}
\DeclareOption{footfill}{\@footfilltrue}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% These booleans will be evaluated at the end of the class code. They are |false| until the
% associated option is selected.
%
%    \begin{macrocode}
\newif\if@leftwin
\newif\if@leftsig
\newif\if@foldmark
\newif\if@footfill
%    \end{macrocode}
%
% \subsubsection{Executing options}
%
% Swiss letters are written on A4 paper. Default font size is |10pt|, like in other standard
% classes. Other switches are set at kernel level.
%
%    \begin{macrocode}
\ExecuteOptions{a4paper,10pt}
\ProcessOptions\relax
%    \end{macrocode}
%
% Loading this |.clo| file leads to a lot of redundancy. But we want compatibility.
%
%    \begin{macrocode}
\input{size1\@ptsize.clo}
%    \end{macrocode}
%
% \subsubsection{Loading packages}
%
% The \textsf{chletter} class does not load additional packages.
%
% \subsection{Document layout}
%
% This class tries to provide quite a universal layout, not only suitable for letters, but
% also for other types of short documents. There are anyway some values specific to letters,
% principally the letterhead values.
%
% \subsubsection{Letter counter}
%
% \begin{macro}{theletter}
% Each time a letter is created by a |letter| environment, this counter is incremented.
%
%    \begin{macrocode}
\newcounter{letter}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Letter dimensions}
%
% These dimensions concern the letterhead, where |\titlehead| is the absolute position of
% its first baseline. The title matter is vertically stacked in three strips, each one with
% its  own height. |\titlemargin| is the absolute position of the letterhead margin, to which
% the letterhead matter is relative. |\longindentation| and |\indentedwidth| are to be used
% within a |letter| environment and will be computed on the fly by |\maketitle|, along with
% |\addressmargin| or |\addresswidth|.
%
%    \begin{macrocode}
\newdimen\titlehead
\newdimen\titletopheight
\newdimen\titlemidheight
\newdimen\titlebotheight
%    \end{macrocode}
%    \begin{macrocode}
\newdimen\titlemargin
\newdimen\titlewidth
\newdimen\addressmargin
\newdimen\addresswidth
%    \end{macrocode}
%    \begin{macrocode}
\newdimen\longindentation
\newdimen\indentedwidth
%    \end{macrocode}
%
% \subsubsection{Paragraphing}
%
% We prefer inter paragraph skips in a letter. Swiss letters are rarely  indented but the
% |letter| environement offers an option to do so. Indentation is still enabled at
% document level. Setting |\normallineskip| to zero prevents layout inconsistencies.
%
%    \begin{macrocode}
\parskip9\p@
\parindent18\p@
%    \end{macrocode}
%    \begin{macrocode}
\normallineskip\z@
%    \end{macrocode}
%
% \subsubsection{Page layout}
%
% All dimensions are measured from a point |1in| from the top left corner of the page.
% Remember that |1in = 72.27pt = 2.54cm| = |72bp| and |1pt| = |65536sp|.\medskip
%
% Regarding the header, |12pt| (more or less one line) are reserved, plus |24pt| spacing
% before the main text. The footer space is |36pt|, including body to footer gap.
%
%    \begin{macrocode}
\headheight12\p@
\headsep24\p@
%    \end{macrocode}
%    \begin{macrocode}
\footskip36\p@
%    \end{macrocode}
%
% Regarding the text dimensions, we remove approximately |1in| at each side, plus |36pt|
% horizontally (corresponding to the margin, see below) and |72pt| vertically
% (corresponding to the header and footer, see above). The trick in the definition
% of |\textwidth| and |\textheight| is to have integer values for A4 paper.
%
%    \begin{macrocode}
\textwidth\paperwidth
\advance\textwidth-9536004sp
\titlewidth\textwidth
\advance\textwidth-36\p@
%    \end{macrocode}
%    \begin{macrocode}
\textheight\paperheight
\advance\textheight-14093310sp
%    \end{macrocode}
%
% The left margin of the odd pages is set to |1in + 36pt| (more or less |4cm|). Sizes of the
% marginal notes are adapted to quite small margins. Top margin is set to zero.
%
%    \begin{macrocode}
\oddsidemargin36\p@
\evensidemargin\z@
%    \end{macrocode}
%    \begin{macrocode}
\marginparwidth48\p@
\marginparsep6\p@
\marginparpush6\p@
%    \end{macrocode}
%    \begin{macrocode}
\topmargin\z@
%    \end{macrocode}
%
% The footnotes values are somewhat larger than the default.
%
%    \begin{macrocode}
\footnotesep12\p@
\skip\footins12\p@
%    \end{macrocode}
%
% \subsubsection{Title layout}
%
% What we call `title' here is the letterhead, with the addresses fields and all this kind of
% stuff. Title is always placed on an odd page at an absolute position.
%
% \begin{macro}{\titlehead}
% The vertical position of the title is controled by the |\titlehead| value (by analogy with
% |\headheight| which sets the first baseline of the running head). Please note that
% letterhead position is not altered by anything but |\titlehead| (for example it is
% independant from the |\topmargin| value).
%
%    \begin{macrocode}
\titlehead12\p@
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\titletopheight}
% \begin{macro}{\titlemidheight}
% \begin{macro}{\titlebotheight}
% The title (letterhead or cover) field is divided into three strips, each one containing
% some material. For example, the first field could contain the sender's address, the second
% one the recipient's address and the third one the letter's date. Obviously the total
% letterhead height is the sum of these three values (|216pt| by default).
%
%    \begin{macrocode}
\titletopheight72\p@
\titlemidheight72\p@
\titlebotheight72\p@
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\titlemargin}
% \begin{macro}{\titlewidth}
% The horizontal position of the title is controlled by |\titlemargin| which is set to |0pt|
% by default. |\titlewidth| has already been set as |\textwidth + 36pt|. 
% \end{macro}
% \end{macro}
%
% \begin{macro}{\addressmargin}
% \begin{macro}{\addresswidth}
% These values are to be computed on the fly by |\maketitle| depending on user input and
% actual |\titlewidth| value. If |\addressmargin| is defined by the user, then the formula
% |\titlewidth = \addressmargin + \addresswidth| will be applied to |\addresswidth|, otherwise
% it will be applied to |\addressmargin|.
%
%    \begin{macrocode}
\addresswidth190\p@
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{Page styles}
%
% The default page styles are here, but their layout differ from the standard classes.
%
%    \begin{macrocode}
\def\ps@plain%
{\let\@oddhead\@empty
 \let\@evenhead\@empty
 \def\@oddfoot{\footnotesize\hfil\pagename~\thepage}
 \def\@evenfoot{\footnotesize\pagename~\thepage\hfil}}
%    \end{macrocode}
%    \begin{macrocode}
\def\ps@firstpage%
{\let\@oddhead\@empty
 \let\@evenhead\@empty
 \def\@oddfoot{\footnotesize\leftmark\hfil\rightmark}
 \def\@evenfoot{\footnotesize\rightmark\hfil\leftmark}}
%    \end{macrocode}
%    \begin{macrocode}
\def\ps@headings%
{\def\@oddhead{\footnotesize\headtoname~\toname\hfil\pagename~\thepage}
 \def\@evenhead{\footnotesize\pagename~\thepage\hfil}
 \def\@oddfoot{\footnotesize\leftmark\hfil\rightmark}
 \def\@evenfoot{\footnotesize\rightmark\hfil\leftmark}}
%    \end{macrocode}
%    \begin{macrocode}
\def\ps@myheadings%
{\def\@oddhead{\footnotesize\leftmark\hfil\rightmark}
 \def\@evenhead{\footnotesize\rightmark\hfil\leftmark}
 \def\@oddfoot{\footnotesize\hfil\pagename~\thepage}
 \def\@evenfoot{\footnotesize\pagename~\thepage\hfil}}
%    \end{macrocode}
%
% \subsection{Document markup}
%
% These user commands are common to all usual letter classes. 
%
% \subsubsection{Global declarations}
%
% \begin{macro}{\name}
% \begin{macro}{\signature}
% \begin{macro}{\address}
% \begin{macro}{\location}
% \begin{macro}{\telephone}
% \begin{macro}{\return}
% These macros work exactly the same way as with the standard \textsf{letter} class. They
% don't output anything, but just define an associated word containing their argument. The
% layout of |\telephonenum| (small text) and |\returnaddress| (underlined small text) is
% specific to this class and somewhat tricky, intended to manage the best possible appearance.
% Please note that the default contents of the associated words will be defined later.
%
%    \begin{macrocode}
\long\def\name#1{\def\fromname{#1}}
\long\def\signature#1{\def\fromsig{#1}}
\long\def\location#1{\def\fromlocation{#1}}
\long\def\address#1{\def\fromaddress{#1}}
\long\def\telephone#1{\def\telephonenum{\vtop{\footnotesize#1}}}
\long\def\return#1{\def\returnaddress{\underbar{\textsuperscript{#1}}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\makelabels}
% \begin{macro}{\startlabels}
% The |\makelabels| command defines a |\startlabels| macro, which causes cover pages to be
% added at the end of each letter. See next page for more information.
%
%    \begin{macrocode}
\def\makelabels%
{\def\startlabels%
 {\let\titletopmatter\@empty
  \let\titlebotmatter\@empty
  \let\foldmark\@empty}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\maketitle}
% This artful piece of code actually outputs the letterhead stuff. |\maketitle| is always
% called at the opening of the |letter| environment, and at its closing if the |\startlabels|
% flag is not |\@null|. It outputs the content of |\titletopmatter|, |\titlemidmatter|,
% |\titlebotmatter| in three horizontal strips stacked vertically. These strips have respective
% heights of |\titletopheight|, |\titlemidheight|, |\titlebotheight| and are always placed on
% a new odd page at an absolute position given by |\titlehead| and |\titlemargin|. The width of
% the  strips is given by |\titlewidth|. |\longindentation| and |\indentedwidth| are computed
% here, so are |\addressmargin| and |\addresswidth| which are used by |\splitfield|. Some
% dedicated mecanism deals with the |\twoside| and |\twocolumns| cases (the letterhead is
% always issued on a clear odd page), executing the |\@maketitle| auxiliary macro. The
% |\foldmark| macro is called at the end of the letterhead.
%
%    \begin{macrocode}
\def\maketitle%
{\ifdim\addressmargin=\z@
  \addressmargin\titlewidth
  \advance\addressmargin-\addresswidth
 \else
  \addresswidth\titlewidth
  \advance\addresswidth-\addressmargin\fi
 \longindentation\titlemargin
 \advance\longindentation-\oddsidemargin
 \clearpage
 \if@twoside\ifodd\c@page
 \else\thispagestyle{empty}\hb@xt@\z@{}\clearpage\fi\fi
 \if@twocolumn\twocolumn[\@maketitle\leavevmode\vskip-\topskip]
 \else\vbox{\@parboxrestore\@maketitle}\vskip-\parskip\fi
 \advance\longindentation\addressmargin
 \indentedwidth\textwidth
 \advance\indentedwidth-\longindentation}
%    \end{macrocode}
%    \begin{macrocode} 
\def\@maketitle%
{\vskip-\topmargin\vskip-\baselineskip
 \vskip\titlehead\vskip-\headheight\vskip-\headsep
 \leftskip\longindentation\rightskip\textwidth
 \advance\rightskip-\paperwidth
 \advance\rightskip-\titlemargin
 \parbox[t][\titletopheight]{\titlewidth}
 {\hb@xt@\z@{}\titletopmatter\strut}\par
 \parbox[t][\titlemidheight]{\titlewidth}
 {\hb@xt@\z@{}\titlemidmatter\strut}\par
 \parbox[t][\titlebotheight]{\titlewidth}
 {\hb@xt@\z@{}\titlebotmatter\strut}\par
 \leftskip-\oddsidemargin\advance\leftskip-1in
 \parbox[b][\z@]{\paperwidth}{\foldmark}\par}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The \texttt{letter} environment}
%
% \begin{environment}{letter}
% The |letter| environment is the foremost part of a letter. It takes the recipient's address
% as mandatory argument and |[i]| (default is |[n]|) as optional argument to set the
% |\parindent| value within the group represented by the environment. The first part of the
% code manages these arguments. It is sturdier than the standard \LaTeX\ |\newenvironment| in
% the sense that, for example, the mandatory argument is not... mandatory! At its opening,
% the |letter| environment tokenizes its mandatory argument into two fields, |\toname| and
% |\toaddress| (token separator is the first encountered |\\|). If the argument is null
% (|\begin{letter}{}| or |\begin{letter}|), these values won't be modified and thus may be
% defined before the opening of the environment, hence the easy mail merging extension. Then
% |\maketitle| is called to output the letterhead (the first page of the letter is always
% issued on a clear odd page, leaving a blank page if necessary in two sided documents). The
% |\pagestyle| of the first letter page is set to |firstpage| and the |letter| counter is
% incremented, while the |page| and |footnote| counters are reset.
%
%    \begin{macrocode}
\def\letter{\futurelet\@let@token\ch@let}\def\ch@let%
{\ifx\@let@token[\expandafter\@letter\else\expandafter\ch@lea\fi}
\long\def\ch@lea#1 {\@letter[n]{#1} }
%    \end{macrocode}
%    \begin{macrocode}
\long\def\@letter[#1]#2
{\ifx#1n\parindent\z@\fi\ifx\@null#2\else\@processto#2\\@@@
  \ifx\@empty\toaddress\else\@processto#2@@@\fi\fi
 \maketitle\thispagestyle{firstpage}
 \global\c@page\@ne\global\c@footnote\z@\global\advance\c@letter\@ne}
%    \end{macrocode}
%    \begin{macrocode}
\long\def\@processto#1\\#2@@@{\def\toname{#1}\def\toaddress{#2}}
%    \end{macrocode}
%
% At its closing, the |letter| environment removes the last skip, then checks for the
% definition of |\startlabels|. If undefined, nothing but a |\clearpage| happens. If defined,
% its contents is executed (usually a redefinition of |\titletopmatter|, |\titlemidmatter| and
% |\titlebotmatter|) and the |\maketitle| macro is called, taking the |\twoside| case in
% account (which may produce additional empty pages), then issuing a new page (intended to be
% a cover) followed by a |\clearpage|.
%
%    \begin{macrocode}
\def\endletter{\removelastskip\ifx\startlabels\undefined\else%
 \startlabels\maketitle\thispagestyle{empty}\fi\clearpage}
%    \end{macrocode}
% \end{environment}
%
% \subsubsection{Page breaking control}
%
% \begin{macro}{\stopbreaks}
% \begin{macro}{\startbreaks}
% When the command |\stopbreaks| is issued no page breaks should occur until |\startbreaks| is
% called. These macros are used by the |\closing| command.
%
%    \begin{macrocode}
\def\stopbreaks{\interlinepenalty\@M\def\par{\@@par\nobreak}}
\def\startbreaks{\interlinepenalty100\def\par{\@@par}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{The generic letter commands}
%
% \begin{macro}{\opening}
% Unlike the standard \textsf{letter} class, the |\opening| command doesn't generate the
% letterhead (this is done at the opening of the |letter| environment or by a direct call of
% |\maketitle|). The content of |\salutation| is either locally filled with the mandatory
% argument or recalled if the argument is null (either |\opening{}| or |\opening| without
% argument, look at the neat argument handling code), then output. The |\medskipamount| value
% controls the vertical spacing.
%
%    \begin{macrocode}
\def\opening{\futurelet\@let@token\ch@ope}\def\ch@ope%
{\ifx\@let@token\bgroup\expandafter\ch@opa\else\expandafter\@opening\fi}
\def\ch@opa#1{\ifx\@null#1\else\def\salutation{#1}\fi\@opening}
%    \end{macrocode}
%    \begin{macrocode}
\def\@opening{\par\salutation\par\medskip}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\closing}
% The |\closing| command is to be called at the end of the letter body. It generates the
% valediction and the signature. Much like the |\opening| command, its argument either fills
% or retrieve a value, here |\valediction|. A |\medskip| is issued, page breaking is prevented
% and |\closingmatter| is added. |\closingmatter| is defined according to the class option
% |leftsig| and could be completely customized.
%
%    \begin{macrocode}
\def\closing{\futurelet\@let@token\ch@clo}\def\ch@clo%
{\ifx\@let@token\bgroup\expandafter\ch@cla\else\expandafter\@closing\fi}
\def\ch@cla#1{\ifx\@null#1\else\def\valediction{#1}\fi\@closing}
%    \end{macrocode}
%    \begin{macrocode}
\def\@closing{\par\medskip\stopbreaks\valediction
 \samepage\par\closingmatter\par\startbreaks}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\object}
% The |\object| macro outputs the content of |\@title|, either previously defined by a
% |\title| command or filled by a non empty argument (see |\opening| for an explanation of
% this behaviour). The |\bigskipamount| value controls the vertical spacing. Styling is left
% to user's preference, for example: |\object{\textbf{...}}|.
%
%    \begin{macrocode}
\def\object{\futurelet\@let@token\ch@obj}\def\ch@obj%
{\ifx\@let@token\bgroup\expandafter\ch@oba\else\expandafter\@object\fi}
\def\ch@oba#1{\ifx\@null#1\else\title{#1}\fi\@object}
%    \end{macrocode}
%    \begin{macrocode}
\def\@object{\noindent\@title\par\bigskip}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ps}
% \begin{macro}{\cc}
% \begin{macro}{\encl}
% |\ps| is a shortcut for a simple \LaTeX\ list, with its first argument as item label and
% its second argument as a item contents. |\cc| and |\encl| are further shortcuts, using
% respectively |\ccname| and |\enclname| as label.  There is a trick involved here: the list
% behaviour is altered after a |\closing| command (see |\closingmatter|); by these means the
% letter foot benefit from the powerful list feature while the lists defaults are kept at
% convenient values for use within the letter body.\medskip
%
%    \begin{macrocode}
\long\def\ps#1#2{\begin{list}{}{}\item[#1]#2\end{list}}
\long\def\cc#1{\ps{\ccname}{#1}}
\long\def\encl#1{\ps{\enclname}{#1}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsubsection{Sections and paragraphs}
%
% Some sectioning commands are defined, but they are merely formatting commands. So there is
% no section numbering nor index and table of contents generation.
%
%    \begin{macrocode}
\long\def\subparagraph#1{\par\textbf{#1}\hskip\labelsep}
\long\def\paragraph#1{\par\noindent\textbf{#1}\hskip\labelsep}
\long\def\subsubsection#1{\par\noindent\textbf{#1}\par\nobreak}
\long\def\subsection#1{\smallskip\subsubsection{#1}}
\long\def\section#1{\medskip\subsubsection{#1}}
%    \end{macrocode}
%
% \subsubsection{Environments}
%
% This code is borrowed from the standard classes. Please look at the \LaTeXe\ documentation
% for further explanation. Remember that all these environments are lists which will be 
% formatted according following the general lists parameters.
%
%    \begin{macrocode}
\def\description
{\list{}
 {\labelwidth\z@
  \itemindent-\leftmargin
  \let\makelabel\descriptionlabel}}\def\enddescription{\endlist}
%    \end{macrocode}
%    \begin{macrocode}
\def\descriptionlabel#1{\hskip\labelsep\textbf{#1}}
%    \end{macrocode}
%    \begin{macrocode}
\def\verse
{\let\\\@centercr
 \list{}
 {\itemsep\z@
  \itemindent-\parindent
  \listparindent\itemindent
  \rightmargin\leftmargin
  \advance\leftmargin\parindent}
 \item\relax}\def\endverse{\endlist}
%    \end{macrocode}
%    \begin{macrocode}
\def\quotation
{\list{}
 {\listparindent\parindent
  \itemindent\listparindent
  \rightmargin\leftmargin}
 \item\relax}\def\endquotation{\endlist}
%    \end{macrocode}
%    \begin{macrocode}
\def\quote
{\list{}
 {\rightmargin\leftmargin}
 \item\relax}\def\endquote{\endlist}
%    \end{macrocode}
%
% \subsubsection{Lists}
%
% This code is borrowed from the standard classes. Please look at the \LaTeXe\ documentation
% for further explanation. Please also note that list nesting is limited to four levels
% (seems to be enough for a letter).
%
%    \begin{macrocode}
\def\@listI{}
\let\@listi\@listI
\let\@listii\@listI
\let\@listiii\@listI
\let\@listiv\@listI
%    \end{macrocode}
%    \begin{macrocode}
\def\theenumi{\@arabic\c@enumi}
\def\theenumii{\@alph\c@enumii}
\def\theenumiii{\@roman\c@enumiii}
\def\theenumiv{\@Alph\c@enumiv}
%    \end{macrocode}
%    \begin{macrocode}
\def\labelenumi{\theenumi.}
\def\labelenumii{(\theenumii)}
\def\labelenumiii{\theenumiii.}
\def\labelenumiv{\theenumiv.}
%    \end{macrocode}
%    \begin{macrocode}
\def\p@enumii{\theenumi}
\def\p@enumiii{\theenumi(\theenumii)}
\def\p@enumiv{\p@enumiii\theenumiii}
%    \end{macrocode}
%    \begin{macrocode}
\def\labelitemi{\textbullet}
\def\labelitemii{\textbf{\textendash}}
\def\labelitemiii{\textasteriskcentered}
\def\labelitemiv{\textperiodcentered}
%    \end{macrocode}
%
% \subsection{Default settings}
%
% As in other classes, some values are set here rather than at kernel level. The values used
% by the \textsf{chletter} class are as generic as possible.
%
% \subsubsection{Lists}
%
% \begin{macro}{\labelsep}
% \begin{macro}{\labelwith}
% \begin{macro}{\leftmargin}
% These default values are defined at document level and altered by |\closingmatter|
% (see next page) in the following manner: |\labelwidth3\labelsep| (usually |18pt|),
% |\leftmargin2\parindent| (|36pt| in an indented letter, |0pt| in a default letter).
%
%    \begin{macrocode}
\labelsep6\p@\labelwidth12\p@\leftmargin18\p@
%    \end{macrocode}
%    \begin{macrocode}
\topsep\z@\partopsep3\p@\itemsep\z@\parsep3\p@
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsubsection{Environments}
%
% Exactly as in the standard classes.
%    \begin{macrocode}
\arraycolsep5\p@
\tabcolsep6\p@
\arrayrulewidth.4\p@
\doublerulesep2\p@
\tabbingsep\labelsep
\skip\@mpfootins=\skip\footins
\def\theequation{\@arabic\c@equation}
%    \end{macrocode}
%
% \subsubsection{Framed boxes}
%
% \begin{macro}{\fboxsep}
% \begin{macro}{\fboxrule}
% Apart from their ordinary application, the values defined here are used by the default
% |\foldmark| macro defined by the |foldmark| class option.
%  
%    \begin{macrocode}
\fboxsep3\p@
\fboxrule.4\p@
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{Footnotes}
%
% Light is right! This definition is minimalist, at the same time sensible.
%    \begin{macrocode}
\long\def\@makefntext#1{\noindent\hb@xt@\z@{\hss\@makefnmark}#1}
%    \end{macrocode}
%
% \subsubsection{Letter}
%
% Some specific letter values are initialized here. 
%
% \begin{macro}{\fromname}
% \begin{macro}{\fromsig}
% \begin{macro}{\fromaddress}
% \begin{macro}{\fromlocation}
% \begin{macro}{\telephonenum}
% \begin{macro}{\returnaddress}
% |\fromname| is not empty by default, so is |\fromsig|: they contain the |\@author| value,
% which is defined at kernel level to output nothing but a warning message (no author given).
% |\@author| will be modified by the \LaTeX\ |\author| command. |\fromlocation| and 
% |\fromaddress| are somewhat redundant, but they may be used for special purpose.
% |\returnaddress| should also output nothing by default, but it has to leave an empty line,
% hence the |\null| trick (actually an empty |\hbox|).
%
%    \begin{macrocode}
\def\fromname{\@author}
\def\fromsig{\@author}
\let\fromlocation\@empty
\let\fromaddress\@empty
\let\telephonenum\@empty
\def\returnaddress{\null}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\toname}
% \begin{macro}{\toaddress}
% These values retrieved or adjusted at the opening of a |letter| environment.
% They are initialized here to prevent an error in certain condition.
%
%    \begin{macrocode}
\let\toname\@empty
\let\toaddress\@empty
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\salutation}
% \begin{macro}{\valediction}
% These values are retrieved or adjusted respectively by the |\opening| and |\closing|
% commands. They are initialized here to prevent an error in certain condition.
%
%    \begin{macrocode}
\let\salutation\@empty
\let\valediction\@empty
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \subsubsection{Words}
%
% \begin{macro}{\ccname}
% \begin{macro}{\enclname}
% \begin{macro}{\pagename}
% \begin{macro}{\headtoname}
% These words are common to the common \textsf{letter} classes. They will be adjusted by the
% linguistic packages (\textsf{babel} or \textsf{polyglossia}). |\ccname| and |\enclname| are
% used respectively by the |\cc| and |\encl| macros; while |\pagename| and |\headtoname| are
% used within |\pagestyle| layouts and some additional packages.
%
%    \begin{macrocode}
\def\ccname{cc}
\def\enclname{encl}
\def\pagename{Page}
\def\headtoname{To}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsubsection{Date}
%
% \begin{macro}{\today}
% The |\@date| field, which appears in the letterhead, defaults to |\today|. The |\today|
% value will be adjusted by the linguistic packages (\textsf{babel} or \textsf{polyglossia}).
%
%    \begin{macrocode}
\def\today
{\ifcase\month\or
 January\or February\or March\or April\or May\or June\or
 July\or August\or September\or October\or November\or December\fi
 \space\number\day, \number\year}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Two column mode}
%
% \begin{macro}{\columnsep}
% This is tricky! The idea is to align the columns with the addresses. In a default
% (A4) letter, the second column will align with the recipient's address and the date.
%
%    \begin{macrocode}
\columnsep36\p@
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The page style} 
%
% We have |\pagetyle{plain}| pages in this document class (except the letterhead
% page which has |\thispagestyle{firspage}|). We use arabic page numbers.
% 
%    \begin{macrocode}
\pagestyle{plain}
\pagenumbering{arabic}
%    \end{macrocode}
%
% \subsection{Later initializations}
%
% This code handles the class options |leftwin|, |leftsig|, |foldmark|, |footfill| and
% |twocolumn| (retrieved by the associated booleans). It defines the default layout of the
% letter and would be very interesting for those who wish to completely customize the letter
% appearance by redefining the relevant macros.
%
% \subsubsection{Letterhead layout}
%
% \begin{macro}{\titletopmatter}
% \begin{macro}{\titlemidmatter}
% \begin{macro}{\titlebotmatter}
% The default layout of the letterhead is defined here, taking in account the class option
% |leftwin|. |\titletopmatter|, |\titlemidmatter| and |\titlebotmatter| are three strips of
% |\titletopheight|, |\titlemidheight| and |\titlebotheight| respective heights. Please note
% the usage of |\splitfield{...}{...}| which cuts a strip in two columns of |\adressmargin|
% and |\addresswidth| respective widths.
%
%    \begin{macrocode}
\if@leftwin
 \def\titletopmatter%
 {\splitfield
  {}{\fromlocation\par\fromname\par\fromaddress\par\telephonenum}}
 \def\titlemidmatter%
 {\returnaddress\par\toname\par\toaddress}
 \def\titlebotmatter%
 {\splitfield
  {}{\@date}}
%    \end{macrocode}
%    \begin{macrocode}
\else
 \def\titletopmatter%
 {\splitfield
  {\fromlocation\par\fromname\par\fromaddress\par\telephonenum}{\@date}}
 \def\titlemidmatter%
 {\splitfield
  {}{\returnaddress\par\toname\par\toaddress}}
 \def\titlebotmatter%
 {}\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\splitfield}
% The letterhead is divided in three vertically stacked strips of |\titlewidth| width, named
% respectively |\titletopmatter|, |titlemidmatter| and |titlebotmatter| (see above). The
% purpose of this command is to divide a strip in two columns, the first one of |\addressmargin|
% width, the second one of |\addresswidth| width (computed on the fly by |\maketitle|, see
% above). The letterhead may contain graphics (a logo for example), so we have to cope with
% the relative vertical placement of text and imported pictures, hence the |\hbox| and |\strut|
% in the definitions of the parboxes.
%
%    \begin{macrocode}
\long\def\splitfield#1#2%
{\parbox[b][\baselineskip][t]{\addressmargin}{\hb@xt@\z@{}{#1}\strut}%
 \parbox[b][\baselineskip][t]{\addresswidth}{\hb@xt@\z@{}{#2}\strut}}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Signature layout}
%
% \begin{macro}{\closingmatter}
% |\closingmatter| is output by the |\closing| command and can contain any piece of text or
% code. |\fooftill| is an extra glue for better letter foot balancing (see below). Please
% note the crafty use of the |\ps| command. Also remember that |\leftmargin| and |\labelwidth|
% values are changed by this |\closingmatter|.
%
%    \begin{macrocode}
\if@leftsig
 \def\closingmatter%
 {\leftmargin2\parindent
  \vskip4\bigskipamount
  \ps{}{\fromsig}
  \vskip2\bigskipamount plus\footfill
  \labelwidth3\labelwidth
  \advance\labelwidth-\labelsep}
%    \end{macrocode}
%    \begin{macrocode}
\else
 \def\closingmatter%
 {\leftmargin\longindentation
  \vskip4\bigskipamount
  \ps{}{\fromsig}
  \vskip2\bigskipamount plus\footfill
  \leftmargin2\parindent
  \labelwidth3\labelwidth
  \advance\labelwidth-\labelsep}\fi
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Fold mark}
%
% \begin{macro}{\foldmark}
% The |foldmark| class option alters the |\foldmark| macro, which causes a line to be added
% between the letterhead and the main text. Default is |\@empty|.
%
%    \begin{macrocode}
\if@foldmark\def\foldmark{\hrule\@width6\fboxsep\@height\fboxrule}
\else\let\foldmark\@empty\fi
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Letter footer}
%
% \begin{macro}{\footfill}
% A conditionnal definition of |\footfill| will alter the layout of |\closingmatter|
% (see above), adding an extra vertical glue after the signature. Default is |\@empty|.
%
%    \begin{macrocode}
\if@footfill\def\footfill{1fill}
\else\let\footfill\z@\fi
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Two column mode}
%
% The column separator (|\columnsep|) is initialized earlier in the class code.
% Please note that in one column mode we reverse the position of the margin paragraphs.
%
%    \begin{macrocode}
\if@twocolumn\twocolumn\sloppy
\else\onecolumn\reversemarginpar\fi
%    \end{macrocode}
%
% \subsection{Legacy}
%
% Unfortunately some widely spread packages still relie on this!
%
%    \begin{macrocode}
\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit}
\DeclareOldFontCommand{\sl}{\normalfont\slshape}{\relax}
\DeclareOldFontCommand{\sc}{\normalfont\scshape}{\relax}
%    \end{macrocode}
%
%    \begin{macrocode}
%</chletter.cls>
%    \end{macrocode}
%
% \pagebreak
%
% \section{Letter template}
%
% \setcounter{CodelineNo}{0}
%
% The following \LaTeX\ document is intended to be used as a template. It will also
% compile with the standard \textsf{letter} class and the older version of the
% \textsf{chletter} class.\bigskip
%
% Please note that the \textsf{chextras} companion package will simplify the preparation of
% Swiss documents by setting up linguistic packages, font encoding and document layout.
% Look at \textsf{chextras} documentation for further information.
%
%    \begin{macrocode}
%<*chlettmp.tex>
%    \end{macrocode}
% 
%    \begin{macrocode}
\documentclass{chletter}

%%\usepackage[english,black]{chextras}

\author{My name}
\address{My address\\My City}
\telephone{My phone\\My email}
\date{My location, \today}

\begin{document}
\begin{letter}{Name\\Address\\City}

\opening{Dear \toname,}

Body text.

\closing{Yours truly,}

\encl{Enclosures}
\cc{Other recipients}

\end{letter}
\end{document}
%    \end{macrocode}
%    \begin{macrocode}
%</chlettmp.tex>
%    \end{macrocode}
%
% \pagebreak
%
% \Finale
% \PrintIndex
\endinput


