Source

letter / files / default.nli

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
%D \module
%D   [       file=default,
%D        version=2011.02.07,
%D          title=\CONTEXT\ Letter Interface,
%D       subtitle=Default Interface,
%D         author=Wolfgang Schuster,
%D           date=\currentdate,
%D      copyright=Wolfgang Schuster,
%D          email=schuster.wolfgang@googlemail.com,
%D        license=Public Domain]

\unprotect

%D \subject{Reference line}
%D 
%D Dimen value to save the height of the reference line.

\ifdefined\letter!height!reference \else \newdimen\letter!height!reference \fi

%D We come now to the new macros defined in this file, they are meant to place the
%D information about date, phone number and more information. You could select on of
%D the alternatives with \type{\setupletter[alternative=...]}.
%D 
%D I define here only what I need myself but you're free to define your own
%D alternatives but try to avoid to use the same names as I do. You could also send
%D me your alternatives and I will include them.
%D 
%D This is the first alternative a, it use the values from the style file without any
%D change, this is the normal layout for a DIN letter.

\long\def\doformatreferencelista#1%
  {\def\\{\egroup\hbox\bgroup}%
   \setupinterlinespace\hbox\bgroup#1\egroup\par}

\long\def\formatreferencelista#1%
  {\bgroup
   \convertargument#1\to\ascii
   \vbox
     {\vbox{\doattributes{\????ld\ascii}\c!titlestyle\c!titlecolor
        {\doformatreferencelista{\labeltext{\v!letter:\ascii}}}}
      \vtop{\doattributes{\????ld\ascii}\c!textstyle\c!textcolor
        {\doformatreferencelista{\lettervalue\ascii}}}}%
   \egroup
   \hfill}

% \defineletterelement[\v!reference][\v!a]
%   {\setbox\scratchbox\hbox\!!to\hsize
%      {\getcommacommandsize[\@@@@lsreferencelist]% \@@@@ldreference?
%       \ifnum\commalistsize<\plustwo\hfill\fi
%       \processcommacommand[\@@@@lsreferencelist]\formatreferencelista\unskip}%
%    \global\letter!height!reference\htdp\scratchbox
%    \box\scratchbox}

\defineletterelement[\v!reference][\v!a]
  {\setbox\scratchbox\hbox\!!to\hsize
     {\getcommacommandsize[\letterstylevalue\currentcorrespondenceelement\c!list]%
      \ifnum\commalistsize<\plustwo\hfill\fi
      \processcommacommand[\letterstylevalue\currentcorrespondenceelement\c!list]\formatreferencelista\unskip}%
   \ifx\currentcorrespondenceelement\v!reference\global\letter!height!reference\htdp\scratchbox\fi
   \box\scratchbox}

\startsetups[\v!letter:\v!reference:\v!a]

\setupletterstyle
  [\v!reference]
  [\c!hoffset=\backspace,
   \c!voffset=\dimexpr\letterstylevalue{\v!address\v!layer}\c!voffset+\letterstylevalue{\v!address\v!frame}\c!height+\plusthree\c!mm\relax,
   \c!width=\textwidth]

\setupletterstyle
  [\v!firstpage]
  [\c!topspace=\dimexpr\letterstylevalue{\v!reference\v!layer}\c!voffset+\letterstylevalue\v!reference\c!spaceafter+\letter!height!reference\relax]

\stopsetups

%D This is the alternative b, you could use it if you want to place the information
%D in a infoblock not just a simple line, it is also better suited if you want to
%D place more infomration.

\long\def\formatreferencelistb#1%
  {\bgroup
   \doifelse{#1}\v!line
     {\blank[\v!line]}
     {\hbox
        {\doattributes{\????ld#1}\c!titlestyle\c!titlecolor
           {\labeltext{\v!letter:#1}\lettervalue{#1\c!separator}}%
         \doattributes{\????ld#1}\c!textstyle\c!textcolor
           {\lettervalue{#1}}}}%
   \egroup}

% \defineletterelement[\v!reference][\v!b]
%   {\vtop % why not \vbox?
%      {\processcommacommand[\@@@@lsreferencelist]\formatreferencelistb}}

\defineletterelement[\v!reference][\v!b]
  {\vtop{\processcommacommand[\letterstylevalue\currentcorrespondenceelement\c!list]\formatreferencelistb}}

\startsetups[\v!letter:\v!reference:\v!b]

\setupletterstyle
  [\v!reference]
  [\v!layer]
  [\c!hoffset=125.7mm,
   \c!voffset=\letterstylevalue{\v!address\v!layer}\c!voffset]

\setupletterstyle
  [\v!reference]
  [\v!frame]
  [\c!width=\dimexpr\paperwidth-\letterstylevalue{\v!reference\v!layer}\c!hoffset-\cutspace\relax,
   \c!height=\v!fit]

\stopsetups

%D The third alternative c could used, if you want to place just a single line
%D with text and nothing more, like your place and the date. You need only the
%D following two lines in your document.
%D 
%D \starttyping
%D \setupletter[alternative=c,list=reference]
%D \setupletter[reference=\rightaligned{Place, \currentdate}]
%D \stoptyping

\long\def\formatreferencelistc#1%
  {\bgroup
   \convertargument#1\to\ascii
   \doattributes{\????ld\ascii}\c!textstyle\c!textcolor
     {\lettervalue\ascii}%
   \egroup}

% \defineletterelement[\v!reference][\v!c]
%   {\hbox\!!to\hsize
%      {\processcommacommand[\@@@@lsreferencelist]\formatreferencelistc}}

\defineletterelement[\v!reference][\v!c]
  {\hbox\!!to\hsize
     {\processcommacommand[\letterstylevalue\currentcorrespondenceelement\c!list]\formatreferencelistc}}

\startsetups[\v!letter:\v!reference:\v!c]

\setups[\v!letter:\v!reference:\v!a]

\stopsetups

%D Alternative d, text is placed in a block like alternative bit the text
%D is put in a table.

\long\def\doformatreferencelistd#1%
  {\doifelse{#1}\v!line
     {\NC\NC\NC\NR} % why did \TB not work?
     {\NC \doattributes{\????ld#1}\c!titlestyle\c!titlecolor
            {\labeltext{\v!letter:#1}\lettervalue{#1\c!separator}}%
      \NC\doattributes{\????ld#1}\c!textstyle\c!textcolor{\lettervalue{#1}}
      \NC\NR}}

\def\formatreferencelistd#1%
  {\appendtoks\doformatreferencelistd{#1}\to\scratchtoks}

% \defineletterelement[\v!reference][\v!d]
%   {\vtop % why not \vbox?
%      {\scratchtoks\emptytoks
%       \processcommacommand[\@@@@lsreferencelist]\formatreferencelistd
%       \setuptabulate[\c!before=,\c!after=]%
%       \starttabulate[|l|l|]
%       \the\scratchtoks
%       \stoptabulate}}

\defineletterelement[\v!reference][\v!d]
  {\vtop
     {\scratchtoks\emptytoks
      \processcommacommand[\letterstylevalue\currentcorrespondenceelement\c!list]\formatreferencelistd
      \setuptabulate[\c!before=,\c!after=]%
      \starttabulate[|l|l|]
      \the\scratchtoks
      \stoptabulate}}

\startsetups[\v!letter:\v!reference:\v!d]

\setupletterstyle
  [\v!reference]
  [\v!layer]
  [\c!hoffset=125.7mm,
   \c!voffset=\letterstylevalue{\v!address\v!layer}\c!voffset]

\setupletterstyle
  [\v!reference]
  [\v!frame]
  [\c!width=\dimexpr\paperwidth-\letterstylevalue{\v!reference\v!layer}\c!hoffset-\cutspace\relax,
   \c!height=\v!fit]

\stopsetups

%D Alternative e, nearly the same as a but you can control the width of the
%D fields with the width key for \tex{setupletter}.

\long\def\doformatreferenceliste#1%
  {\def\\{\egroup\hbox\bgroup}%
   \setupinterlinespace\hbox\bgroup#1\egroup\par}

\long\def\formatreferenceliste#1%
  {\bgroup
   \convertargument#1\to\ascii
   \doifelselettervalue{\ascii\c!width}
     {\hbox\!!to\lettervalue{\ascii\c!width}}
     {\hbox}
     {\vbox
        {\vbox{\doattributes{\????ld\ascii}\c!titlestyle\c!titlecolor
           {\doformatreferenceliste{\labeltext{\v!letter:\ascii}}}}
         \vtop{\doattributes{\????ld\ascii}\c!textstyle\c!textcolor
           {\doformatreferenceliste{\lettervalue\ascii}}}}}%
   \egroup}

% \defineletterelement[\v!reference][\v!e]
%   {\hbox\!!to\hsize
%      {\processcommacommand[\@@@@lsreferencelist]\formatreferenceliste\hss}}

\defineletterelement[\v!reference][\v!e]
  {\hbox\!!to\hsize
     {\processcommacommand[\letterstylevalue\currentcorrespondenceelement\c!list]\formatreferenceliste\hss}}

\startsetups[\v!letter:\v!reference:\v!e]

\setups[\v!letter:\v!reference:\v!a]

\stopsetups

%D The alternative \mono{none} could be used to disable the reference.
%D 
%D The advantage is to change only the list alternative to nothing, another
%D method to get this result to use alternative c and remove all values from
%D the reference but the none key is better.

\resetletterelement[\v!reference][\v!none]

\startsetups[\v!letter:\v!reference:\v!none]

  % Use the topspace value from the style file

\stopsetups

%D \subject{Letter environment}
%D 
%D \macros
%D   {startletter}
%D 
%D The main macro in this file, it is used to write the letter content.
%D It is also possible to set the address and a few other values like
%D the opening and closing with the optional argument, the values are
%D local in this case and not global like the values you could set with
%D \tex{setupletter}.

\newtoks\letter!local!commands
\newtoks\letter!local!setups

\chardef\letterenvironmentmode\zerocount

\def\startletter
  {\autostarttext
   \begingroup
   \dodoubleempty\dostartletter}

\def\dostartletter[#1][#2]%
  {\doifelse\@@@@lsoptionmethod\v!buffer\dostartbufferletter\dostartcontentletter[#1][#2]}

\long\def\dostartcontentletter[#1][#2]#3\stopletter
  {\ifsecondargument
     \getparameters[\????ld][#1]%
     \letter!local!setups{#1}%
     \doifundefinedelse{\????ld\????ld#2}
       {\setvalue{\????ld\c!toaddress}{#2}}
       {\setvalue{\????ld\c!toaddress}{\getvalue{\????ld\????ld#2}}}%
   \else\iffirstargument
     \doifassignmentelse{#1}
       {\getparameters[\????ld][#1]%
        \letter!local!setups{#1}}
       {\doifundefinedelse{\????ld\????ld#1}
          {\setvalue{\????ld\c!toaddress}{#1}}
          {\setvalue{\????ld\c!toaddress}{\getvalue{\????ld\????ld#1}}}}%
   \fi\fi
   \setbuffer[lettercontent]#3\endbuffer
   \processlettervalues
   \directsetup{\v!letter:\v!place}%
   \endgroup
   \autostoptext}

\def\dostartbufferletter[#1][#2]%
  {\def\stopletter
     {\processlettervalues
      \directsetup{\v!letter:\v!place}%
      \endgroup
      \autostoptext}
   \ifsecondargument
     \getparameters[\????ld][#1]%
     \letter!local!setups{#1}%
     \doifundefinedelse{\????ld\????ld#2}
       {\setvalue{\????ld\c!toaddress}{#2}}
       {\setvalue{\????ld\c!toaddress}{\getvalue{\????ld\????ld#2}}}%
   \else\iffirstargument
     \doifassignmentelse{#1}
       {\getparameters[\????ld][#1]%
        \letter!local!setups{#1}}
       {\doifundefinedelse{\????ld\????ld#1}
          {\setvalue{\????ld\c!toaddress}{#1}}
          {\setvalue{\????ld\c!toaddress}{\getvalue{\????ld\????ld#1}}}}%
   \fi\fi
   \dostartbuffer[lettercontent][startletter][stopletter]}

\def\processlettersetups#1#2%
  {\ifcsname\????ld:#1:\v!setups\endcsname
     \appendtocommalist{#1}\letter!list!descriptions
   \fi}

\letvalueempty{\????ld:\c!postscript:\v!setups}
\letvalueempty{\????ld:\c!copy      :\v!setups}
\letvalueempty{\????ld:\c!enclosure :\v!setups}

\def\processlettervalues
  {\globalletempty\letter!list!descriptions
   \global\letter!local!commands\emptytoks
   \def\opening##1{\doglobal\appendtoks\setvalue{\????ld\c!opening   }{##1}\to\letter!local!commands}%
   \def\closing##1{\doglobal\appendtoks\setvalue{\????ld\c!closing   }{##1}\to\letter!local!commands}%
   \def\ps     ##1{\doglobal\appendtoks\setvalue{\????ld\c!postscript}{##1}\to\letter!local!commands\doglobal\appendtocommalist\c!postscript\letter!list!descriptions}%
   \def\cc     ##1{\doglobal\appendtoks\setvalue{\????ld\c!copy      }{##1}\to\letter!local!commands\doglobal\appendtocommalist\c!copy      \letter!list!descriptions}%
   \def\encl   ##1{\doglobal\appendtoks\setvalue{\????ld\c!enclosure }{##1}\to\letter!local!commands\doglobal\appendtocommalist\c!enclosure \letter!list!descriptions}%
   \setbox\scratchbox\vbox{\doifmodeelse\s!mkiv\settrialtypesetting\trialtypesettingtrue\getbuffer[lettercontent]}%
   \doifmode{mkiv}{\processassignmentcommand[\dotoks\letter!local!setups]\processlettersetups}% only available in mkiv
   \flushtoks\letter!local!commands}

\def\gobblelettervalues
  {\def\dogobblelettervalues##1{\letcsnamecs\csname##1\endcsname\gobbleoneargument}%
   \processcommalist[\c!opening,\c!closing,\c!ps,\c!cc,\c!encl]\dogobblelettervalues}

%D \macros
%D   {startlettercontent}
%D 
%D The letter content is saved in the value content, although I could
%D place it in the corresponding I prefer this solution because you could
%D now use it in your own macros and redefine the content setups to your
%D own wishes.

\setupletter
  [\c!content={\getbuffer[lettercontent]}]

\def\startlettercontent
  {\dostartbuffer[lettercontent][startlettercontent][stoplettercontent]}

%D After the definition of all macros I could now put the content
%D in the corresponding setups, this is only important if you want
%D to define your own layout for header, address etc.

\defineletterelement[\v!head][\v!a]
  {\lettervalue\c!fromname
   \doiflettervalue\c!fromname\\
   \lettervalue\c!fromaddress}

\setvalue{@@head@@\c!rule\v!no    }{\!!doneafalse\!!donebfalse}
\setvalue{@@head@@\c!rule\v!none  }{\!!doneafalse\!!donebfalse}
\setvalue{@@head@@\c!rule\v!off   }{\!!doneafalse\!!donebfalse}
\setvalue{@@head@@\c!rule\v!top   }{\!!doneatrue              }
\setvalue{@@head@@\c!rule\v!before}{\!!doneatrue              }
\setvalue{@@head@@\c!rule\v!bottom}{\!!donebtrue              }
\setvalue{@@head@@\c!rule\v!after }{\!!donebtrue              }
\setvalue{@@head@@\c!rule\v!yes   }{\!!donebtrue              }
\setvalue{@@head@@\c!rule\v!on    }{\!!donebtrue              }

\def\doletterelementheadrule
  {\!!doneafalse
   \!!donebfalse
   \def\dodoletterelementheadrule##1{\csname @@head@@\c!rule##1\endcsname}%
   \processcommacommand[\letterstylevalue\v!head\c!fromrule]\dodoletterelementheadrule}

\defineletterelement[\v!head][\v!left]
  {\normalhbox
     {\framed[frame=off,location=bottom,align=right,width=\hsize]
        {\doletterelementheadrule
         \dostartattributes{\????ld\c!fromname}\c!style\c!color
         \lettervalue\c!fromname
         \if!!donea
           \doifelselettervalue\c!fromlogo
             {\setbox\scratchbox\hbox{\lettervalue\c!fromlogo}%
              \scratchdimen\dimexpr\letterstylevalue\v!head\c!rulewidth-\wd\scratchbox\relax}
             {\scratchdimen\letterstylevalue\v!head\c!rulewidth}%
           \vskip-.5\lineheight\blackrule
             [\c!width=\scratchdimen,
              \c!height=\letterstylevalue\v!head\c!rulethickness,
              \c!color=\letterstylevalue\v!head\c!rulecolor]%
         \fi
         \dostopattributes
         \\
         \dostartattributes{\????ld\c!fromaddress}\c!style\c!color
         \lettervalue\c!fromaddress
         \doiflettervalue\c!fromphone{\\\lettervalue\c!fromphone}%
         \doiflettervalue\c!fromfax  {\\\lettervalue\c!fromfax  }%
         \doiflettervalue\c!frommail {\\\lettervalue\c!frommail }%
         \doiflettervalue\c!fromurl  {\\\lettervalue\c!fromurl  }%
         \if!!doneb
           \ifzeropt\letterstylevalue\v!head\c!rulewidth
             \scratchdimen\hsize
           \else
             \scratchdimen\letterstylevalue\v!head\c!rulewidth
           \fi
           \vskip-.5\lineheight\blackrule
             [\c!width=\scratchdimen,
              \c!height=\letterstylevalue\v!head\c!rulethickness,
              \c!color=\letterstylevalue\v!head\c!rulecolor]%
         \fi
         \dostopattributes}%
      \doiflettervalue\c!fromlogo{\llap{\lettervalue\c!fromlogo}}}}%

\defineletterelement[\v!head][\v!middle]
  {\normalhbox
     {\framed[frame=off,location=bottom,align=middle,width=\hsize]
        {\doletterelementheadrule
         \dostartattributes{\????ld\c!fromname}\c!style\c!color
         \lettervalue\c!fromname
         \if!!donea
           \ifzeropt\letterstylevalue\v!head\c!rulewidth
             \scratchdimen\hsize
           \else
             \scratchdimen\letterstylevalue\v!head\c!rulewidth
           \fi
           \vskip-.5\lineheight\blackrule
             [\c!width=\scratchdimen,
              \c!height=\letterstylevalue\v!head\c!rulethickness,
              \c!color=\letterstylevalue\v!head\c!rulecolor]%
         \fi
         \dostopattributes
         \\
         \dostartattributes{\????ld\c!fromaddress}\c!style\c!color
         \lettervalue\c!fromaddress
         \doiflettervalue\c!fromphone{\\\lettervalue\c!fromphone}%
         \doiflettervalue\c!fromfax  {\\\lettervalue\c!fromfax  }%
         \doiflettervalue\c!frommail {\\\lettervalue\c!frommail }%
         \doiflettervalue\c!fromurl  {\\\lettervalue\c!fromurl  }%
         \if!!doneb
           \ifzeropt\letterstylevalue\v!head\c!rulewidth
             \scratchdimen\hsize
           \else
             \scratchdimen\letterstylevalue\v!head\c!rulewidth
           \fi
           \vskip-.5\lineheight\blackrule
             [\c!width=\scratchdimen,
              \c!height=\letterstylevalue\v!head\c!rulethickness,
              \c!color=\letterstylevalue\v!head\c!rulecolor]%
         \fi
         \dostopattributes}}}

\defineletterelement[\v!head][\v!right]
  {\normalhbox
     {\doiflettervalue\c!fromlogo{\rlap{\lettervalue\c!fromlogo}}%
      \framed[frame=off,location=bottom,align=left,width=\hsize]
        {\doletterelementheadrule
         \dostartattributes{\????ld\c!fromname}\c!style\c!color
         \lettervalue\c!fromname
         \if!!donea
           \ifzeropt\letterstylevalue\v!head\c!rulewidth
             \scratchdimen\hsize
           \else
             \doifelselettervalue\c!fromlogo
               {\setbox\scratchbox\hbox{\lettervalue\c!fromlogo}%
                \scratchdimen\dimexpr\letterstylevalue\v!head\c!rulewidth-\wd\scratchbox\relax}
               {\scratchdimen\letterstylevalue\v!head\c!rulewidth}%
           \fi
           \vskip-.5\lineheight\blackrule
             [\c!width=\scratchdimen,
              \c!height=\letterstylevalue\v!head\c!rulethickness,
              \c!color=\letterstylevalue\v!head\c!rulecolor]%
         \fi
         \dostopattributes
         \\
         \dostartattributes{\????ld\c!fromaddress}\c!style\c!color
         \\\lettervalue\c!fromaddress
         \doiflettervalue\c!fromphone{\\\lettervalue\c!fromphone}%
         \doiflettervalue\c!fromfax  {\\\lettervalue\c!fromfax  }%
         \doiflettervalue\c!frommail {\\\lettervalue\c!frommail }%
         \doiflettervalue\c!fromurl  {\\\lettervalue\c!fromurl  }%
         \if!!doneb
           \ifzeropt\letterstylevalue\v!head\c!rulewidth
             \scratchdimen\hsize
           \else
             \scratchdimen\letterstylevalue\v!head\c!rulewidth
           \fi
           \vskip-.5\lineheight\blackrule
             [\c!width=\scratchdimen,
              \c!height=\letterstylevalue\v!head\c!rulethickness,
              \c!color=\letterstylevalue\v!head\c!rulecolor]%
         \fi
         \dostopattributes}}}

\startsetups[\v!letter:\v!head]
\def\\{\letterstylevalue\v!head\c!separator}
\executeifdefined{\v!letter:\v!head:\@@@@lsheadalternative}{\getvalue{\v!letter:\v!head:\v!a}}
\stopsetups

\startsetups[\v!letter:\v!foot]
\executeifdefined{\v!letter:\v!foot:\@@@@lsfootalternative}\donothing
\stopsetups

\startsetups[\v!letter:\v!nexthead]
\executeifdefined{\v!letter:\v!nexthead:\@@@@lsnextheadalternative}\donothing
\stopsetups

\startsetups[\v!letter:\v!nextfoot]
\executeifdefined{\v!letter:\v!nextfoot:\@@@@lsnextfootalternative}\donothing
\stopsetups

\defineletterelement[\v!nexthead][\v!fullblock]
  {\hbox\!!to\hsize
     {\rlap{\lettervalue\c!toname}%
      \midaligned{\pagenumber}%
      \llap{\framed[\c!frame=\v!off,\c!location=\v!top,\c!align=\v!left]
        {\lettervalue\c!date   \\
         \lettervalue\c!reference}}}}

\defineletterelement[\v!nexthead][\v!hanging]
  {\hbox\!!to\hsize
     {\framed[\c!frame=\v!off,\c!location=\v!top,\c!align=v!right]
       {\lettervalue\c!toname    \\
        \lettervalue\c!date      \\
        \lettervalue\c!reference \\
        \labeltext\c!page\pagenumber}}\hss}

\defineletterelement[\v!nexthead][\v!semiblock]
  {\hbox\!!to\hsize
     {\rlap{\lettervalue\c!toname}%
      \midaligned{\pagenumber}%
      \llap{\lettervalue\c!date}}}

\copyletterelement[\v!nexthead][\v!simplified][\v!fullblock]
\copyletterelement[\v!nexthead][\v!modified  ][\v!hanging  ]

%D \subject{Addressee field}
%D 
%D The address field is separated into two different fields.
%D The upper field is meant for dispatch information, the official height
%D in germany is 3 lines but this would lead to different heights dependent
%D of the font size and the fonts own height. The lower field contains the
%D name and address of the receiver and has a height of 6 lines in germany.
%D This value will lead to the same problem as the upper field, because the
%D whole address field has a fixed height and both field should fit into
%D this space. I solved this problem by assinging the upper field 1/3 of the
%D address height and the lower field 2/3 of the address height.
%D 
%D If you hace problem to put all information in the limited space you could
%D try to reduce the font size or reduce the interlinespace in the field.

\presetlocalframed[\????ls\v!dispatch ]
\presetlocalframed[\????ls\v!addressee]

\startsetups[\v!letter:\v!place:\v!dispatch]

  \localframed
    [\????ls\v!dispatch]
    {\doadaptleftskip {\letterstylevalue\v!dispatch\c!leftmargin }%
     \doadaptrightskip{\letterstylevalue\v!dispatch\c!rightmargin}%
     \doattributes{\????ls\v!dispatch}\c!style\c!color{\directsetup{\v!letter:\v!address:\v!dispatch}}}

\stopsetups

\startsetups[\v!letter:\v!place:\v!addressee]

  \localframed
    [\????ls\v!addressee]
    {\doadaptleftskip {\letterstylevalue\v!addressee\c!leftmargin }%
     \doadaptrightskip{\letterstylevalue\v!addressee\c!rightmargin}%
     \doattributes{\????ls\v!addressee}\c!style\c!color{\directsetup{\v!letter:\v!address:\v!content}}}

\stopsetups

\defineletterelement[\v!address][\v!a]
  {\doif\@@@@lsoptiondispatch \v!yes{\directsetup{\v!letter:\v!place:\v!dispatch }}%
   \doif\@@@@lsoptionaddressee\v!yes{\directsetup{\v!letter:\v!place:\v!addressee}}}

\startsetups[\v!letter:\v!address]
\offinterlineskip\endgraf
\executeifdefined{\v!letter:\v!address:\@@@@lsaddressalternative}{\getvalue{\v!letter:\v!address:\v!a}}
\stopsetups

\startsetups[\v!letter:\v!address:\v!dispatch]
\lettervalue\c!dispatch
\stopsetups

\startsetups[\v!letter:\v!address:\v!content]
\def\\{\letterstylevalue\v!address\c!separator}%
\lettervalue\c!toname
\doiflettervalue\c!toname\\
\lettervalue\c!toaddress
\stopsetups

%D The following setups shouldn't be changed ar you will loose information
%D in the output.
%D 
%D The reference line is choosen with the alternative key or if you set
%D a not defined alternative the definition a is choosen.

\startsetups[\v!letter:\v!reference]
\executeifdefined{\v!letter:\v!reference:\@@@@lsreferencealternative}{\getvalue{\v!letter:\v!reference:\v!a}}
\stopsetups

\resetletterelement[\v!location][\v!a]

\setvalue{\v!letter:\v!location:\v!french}%
  {\lettervalue\c!place
   \doiflettervalue\c!place{\lettervalue{\c!place\c!separator}}%
   \lettervalue\c!date}

\startsetups[\v!letter:\v!location]
\executeifdefined{\v!letter:\v!location:\@@@@lslocationalternative}{\getvalue{\v!letter:\v!location:\v!a}}
\stopsetups

\startsetups[\v!letter:\v!title]
\doifelselettervalue\c!title
  {\lettervalue\c!title}
  {\doiflettervalue\c!attention
     {\labeltext{\v!letter:\c!attention}\lettervalue\c!attention}}
\stopsetups

\startsetups[\v!letter:\v!subject]
\def\\{\letterstylevalue\v!subject\c!separator}%
\labeltext{\v!letter:\c!subject}\lettervalue\c!subject
\stopsetups

\defineletterelement[\v!opening][\v!a]
  {\doifelselettervalue\c!opening
     {\lettervalue\c!opening}
     {\doiflettervalue\c!salutation
        {\lettervalue\c!salutation}}}

\startmode[\s!mkii]
\defineletterelement[\v!opening][\v!french]
  {\ExpandSecondAfter\doifsomething{\letterstylevalue\v!option\c!indenting}
     {\setupindenting[\@@@@lsoptionindenting]}%
   \letterelement[\v!opening][\v!a]}
\stopmode

\startmode[\s!mkiv]
\defineletterelement[\v!opening][\v!french]
  {\doifsomething{\letterstylevalue\v!option\c!indenting}{\setupindenting[\@@@@lsoptionindenting]}%
   \letterelement[\v!opening][\v!a]}
\stopmode

\startsetups[\v!letter:\v!opening]
\executeifdefined{\v!letter:\v!opening:\@@@@lsopeningalternative}{\getvalue{\v!letter:\v!opening:\v!a}}
\stopsetups

\startsetups[\v!letter:\v!content]
\gobblelettervalues\lettervalue\c!content
\stopsetups

%D \subject{Closing and appendices}
%D 
%D It is possible to attach a signature to the closing command, before the signature
%D a skip is inserted but only if the the signature key has a value. The height of the
%D closing environment itself has a height of 4 lines to provide a free space for your
%D own handwritten signature and to have a little bit space between the closing text
%D and the appendices.

\defineletterelement[\v!closing][\v!a]
  {\lettervalue\c!closing
   \doiflettervalue\c!signature{\letterstylevalue\v!closing\c!inbetween}%
   \lettervalue\c!signature}

\startmode[\s!mkii]
\defineletterelement[\v!closing][\v!french]
  {\ExpandSecondAfter\doifsomething{\letterstylevalue\v!option\c!indenting}
     {\setupindenting[\@@@@lsoptionindenting,\v!first]}%
   \lettervalue\c!closing
   \doiflettervalue\c!signature{\letterstylevalue\v!closing\c!inbetween}%
   \raggedcenter\doadaptleftskip{.5\textwidth}% quick and dirty
   \lettervalue\c!signature\endgraf}
\stopmode

\startmode[\s!mkiv]
\defineletterelement[\v!closing][\v!french]
  {\doifsomething{\letterstylevalue\v!option\c!indenting}{\setupindenting[\@@@@lsoptionindenting,\v!first]}%
   \lettervalue\c!closing
   \doiflettervalue\c!signature{\letterstylevalue\v!closing\c!inbetween}%
   \raggedcenter\doadaptleftskip{.5\textwidth}% quick and dirty
   \lettervalue\c!signature\endgraf}
\stopmode

\defineletterelement[\v!closing][\v!simplified]
  {\doiflettervalue\c!signature{\letterstylevalue\v!closing\c!inbetween}%
   \lettervalue\c!signature}

\startsetups[\v!letter:\v!closing]
\def\\{\letterstylevalue\v!closing\c!separator}
\executeifdefined{\v!letter:\v!closing:\@@@@lsclosingalternative}{\getvalue{\v!letter:\v!closing:\v!a}}
\stopsetups

\startsetups[\v!letter:\v!appendices]
\let\\\crlf
\doflushletterdescription
\stopsetups

\dodefineletterdescription[\v!enclosure]

\startsetups[\v!letter:\v!enclosure]
\lettervalue\c!enclosure
\stopsetups

\dodefineletterdescription[\v!copy]

\startsetups[\v!letter:\v!copy]
\lettervalue\c!copy
\stopsetups

\dodefineletterdescription[\v!postscript]

\startsetups[\v!letter:\v!postscript]
\lettervalue\c!postscript
\stopsetups

\defineletterelement[\v!backaddress][\v!yes]
  {\lettervalue\c!fromname
   \doiflettervalue\c!fromaddress\\
   \lettervalue\c!fromaddress}

\resetletterelement[\v!backaddress][\v!no]

\defineletterelement[\v!backaddress][\v!auto]
  {\doifelselettervalue\c!backaddress
     {\lettervalue\c!backaddress}
     {\lettervalue\c!fromname
      \doiflettervalue\c!fromaddress\\
      \lettervalue\c!fromaddress}}

\startsetups[\v!letter:\v!backaddress]
\def\\{\letterstylevalue\c!backaddress\c!separator}
\executeifdefined{\v!letter:\v!backaddress:\@@@@lsbackaddressalternative}{\getvalue{\v!letter:\v!backaddress:\v!no}}
\stopsetups

%D To prevent a pagebreak between the last line of the text and
%D the siganture a nonbreakable vertical space is necessary.
%D The vertical space is inserted in the style file with the normal
%D before and after commands where we control the distance between
%D the elements.

\doifmodeelse{mkii}
  {\defineblankmethod[\v!nobreak]{\penalty\!!tenthousand}}
  {\definevspacing   [\v!nobreak][\v!samepage           ]}

%D \subject{Additional settings}
%D 
%D I set alternative a as default value for alternative, the only content
%D is the date with a label. f you dont want a label choose alternative c
%D or change the label.

\startsetups[\v!letter:\v!optimize]

  \startnointerference % trial typesetting to get the heigth of the reference line
    \dontcomplain
    \let\currentcorrespondenceelement\v!reference
    \executeifdefined{\v!letter:\v!reference:\@@@@lsreferencealternative}\donothing
  \stopnointerference

  \doif\@@@@lsoptionposition\v!yes{\setups[\v!letter:\v!reference:\@@@@lsreferencealternative]}

\stopsetups

%D We have at the moment only the values from the core module, I use the settings
%D from the dinb file as default settings, you could replace them in your own
%D document but I won't change the default style.
%D 
%D The labels are stored in a common file, you could use them in your own interface
%D but you have to live with my names.

\useletterstyle    [dinb]      % layout
\useletterextension[label]     % labels
\useletterextension[addrentry] % database

\protect \endinput