summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/xpackages/xhead/xhead.dtx
blob: 11f23376a6e485839430565f890edd6e6820ab57 (plain)
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
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
% \iffalse
%% File xhead.dtx (C) Copyright 2010 Frank Mittelbach, LaTeX3 Project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version.  The latest version
%% of this license is in the file
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% This file is part of the ``xhead bundle'' (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -----------------------------------------------------------------------
%%
%% The development version of the bundle can be found at
%%
%%    http://www.latex-project.org/svnroot/experimental/trunk/
%%
%% for those people who are interested.
%%
%%%%%%%%%%%
%% NOTE: %% 
%%%%%%%%%%%
%%
%%   Snapshots taken from the repository represent work in progress and may
%%   not work or may contain conflicting material!  We therefore ask
%%   people _not_ to put them into distributions, archives, etc. without
%%   prior consultation with the LaTeX Project Team.
%%
%% -----------------------------------------------------------------------
%%
%<*driver|package>
\RequirePackage{expl3}
\GetIdInfo$Id: xhead.dtx 1914 2010-05-21 16:18:46Z schoepf $
          {Templates heading commands}
%</driver|package>
%<*driver>
%\fi
\ProvidesFile{\filename.\filenameext}
  [\filedate\space v\fileversion\space\filedescription]
%\iffalse
\documentclass{l3doc}


% next three definitions are big hacks to run the file
% without the above packages
%
\makeatother

\newcommand\key[1]{\textbf{#1}}

 \begin{document}
 \DocInput{xhead.dtx}
 \end{document}
%</driver>
% \fi
%
% ^^A\CheckSum{343}
%
%
% \title{The \textsf{xhead} package\thanks{This file
%         has version number \fileversion, last
%         revised \filedate.}}
% \author{FMi}
% \date{\filedate}
% \maketitle
%
% \tableofcontents
%
% \bigskip
%
% \begin{abstract}
%   This module contains basic templates generating typical headings for
%   various levels. This is very much work in progress and none of its content
%   should be considered stable.  Concepts and implementation are still under
%   development.
% \end{abstract}
% 
%
% \newcommand\NOVALUE{\texttt{\string\NoValue}}
% \newcommand\EMPTY{\textit{<empty>}}
% \newcommand\STRING{\textit{<string>}}
% \newcommand\TRUE{\texttt{true}}
% \newcommand\FALSE{\texttt{false}}
% \newcommand\KEYVALS{\textit{<key/value list>}}
% \newcommand\HASH[1]{\texttt{\##1}}
%
% \makeatletter
% \renewenvironment{TemplateInterfaceDescription}[1]
%   {\subsection{The~object~type~`#1'}%
%    \begingroup
%    \@beginparpenalty\@M
%    \description
%    \def\TemplateArgument##1##2{\item[Arg:~##1 (##2)]}^^A
%    \def\TemplateSemantics{\enddescription\endgroup
%        \subsubsection*{Semantics:}}^^A
%   }
%   {\par\bigskip}
% \makeatother
%
% \section{Introduction}
%
%
% \section{Interfaces}
%
% \begin{TemplateInterfaceDescription}{heading}
%
%
%   \TemplateArgument{1}{boolean}
%     If \TRUE{} generate an unnumbered heading, otherwise a number is
%    generated up to a certain heading level. If \TRUE{} TOC entries and
%    running headers are suppressed unless explicitly forced by other
%    arguments below.
%
%   \TemplateArgument{2}
%       {\STRING/\NOVALUE/\EMPTY}
%     Specifies an alternate heading text for the TOC if one is produced. If
%     \NOVALUE{} or \EMPTY{} the TOC receives the  the main title text.
%
%   \TemplateArgument{3}
%       {boolean}
%     If \TRUE{} a TOC entry is forced (i.e., generated even if normally supressed).
%
%   \TemplateArgument{4}
%       {\STRING/\NOVALUE/\EMPTY}
%     Specifies an alternate heading text for the running header if one is
%    produced. If \NOVALUE{} or \EMPTY{} the running header receives the the
%    main title text.
%
%   \TemplateArgument{5}
%       {boolean}
%     If \TRUE{} a running header is forced (i.e., generated even if normally
%    supressed).
%
%   \TemplateArgument{6}
%       {\STRING}
%    The title of the heading in the document. Also used for the TOC entry and
%     running header (if produced) unless overwritten by other arguments.
%
%   \TemplateArgument{7}
%       {\KEYVALS}
%   Extension argument to receive less use key value pairs to manipulate the
%     heading. Exact syntax and semantics still need to be defined.
%
%   \TemplateSemantics
%     This template type defines the basic interface for headings both display
%     headings as well as run-in headings.
%
%    A TOC entry is generated if \HASH{1} is \FALSE{} or \HASH{3} being
%    \TRUE{}. The heading title for the TOC entry is \HASH{6} unless
%    overwritten by a non-empty HASH{2}.  Whether or not this TOC entry
%    actually appears in the TOC depends on settings for the TOC
%    generation. (However, if not generated if will obviously not appear.)
%
%    A running header is generated if \HASH{1} is \FALSE{} or \HASH{5} or
%    \TRUE{}. The heading title for the determined as follows: if \HASH{4} is
%    non-empty it will be used, otherwise if \HASH{2} is non-empty it will be
%    used, otherwise HASH{6} will be used.
%
%    \HASH{7} will hold additional key/value pairs that define more specific
%    semantics. This isn't implemented yet.
%
%    The above describes my current thinking about how those arguments should
%    interact. In simpler templates (based on 2e semantics) the arguments
%    \HASH{3} to \HASH{5} and \HASH{7} will get ignored.
%
%
% \end{TemplateInterfaceDescription}
%
%
% \begin{TemplateDescription}{heading}{2e-vertical}
%
%
%   \TemplateKey{name}{tokenlist}
%      {Name of the heading. Used to refer to parts of its data structure,
%     e.g., the counter associated with the heading will have this name. Must
%     be set to a suitable string like ``section''}
%      {none}
%
%   \TemplateKey{level}{integer}
%      {The level of the heading in the hierarchy. Required.}
%      {none}
%
%   \TemplateKey{break-penalty}{penalty}
%      {Penlty to break in front of the heading unless it is immediately
%     preceeded a higher-level heading in which case breaking is prohibited.}
%      {-300}
%
%   \TemplateKey{indent}{length}
%      {Indentation of the heading from the left margin.}
%      {0pt}
%
%   \TemplateKey{above-skip}{skip}
%      {Vertical space above the heading.}
%      {0pt}
%
%   \TemplateKey{below-skip}{skip}
%      {Vertical space below the heading.}
%      {0pt}
%
%   \TemplateKey{title-decl}{function 0}
%      {Declarations to format the heading, e.g., font changes.}
%      {\EMPTY}
%
%   \TemplateKey{number-format}{function 1}
%      {Formatting instruction for the heading number (if present), receiving
%    the heading counter representation as an argument.}
%      {\cs{xhead_default_number_format:n}}
%
%   \TemplateKey{indent-after}{boolean}
%      {Should the first paragraph after the heading be indented?}
%      {\FALSE}
%
%   \TemplateSemantics
%
%      This is, or should be, a reimplementation of the 2e |\@startsection|
%      command for generating vertical headings. |\@startsection| is also able
%      to produce run-in headings, but this is not covered by the current
%      template.
%
% \end{TemplateDescription}
%
%
%
%
%
% \StopEventually{}
% 
% \section{Implementation}
%
%    \begin{macrocode}
%<*package>
\RequirePackage{expl3,xtemplate}
%    \end{macrocode}
%    
%    \begin{macrocode}
\GetIdInfo$Id: xhead.dtx 1914 2010-05-21 16:18:46Z schoepf $
  {heading module}
\ProvidesExplPackage
  {\filename}{\filedate}{\fileversion}{\filedescription}
%    \end{macrocode}
%
%
% \subsection{The heading object type}
%
% Arguments:
%\begin{verbatim}
%   #1 (boolean)                : produce no number
%   #2 (string/\NoValue/empty)  : toc-title  if different from title
%   #3 (boolean)                : force toc entry
%   #4 (string/\NoValue/empty)  : mark-title if different from toc-title
%   #5 (Boolean)                : force mark entry
%   #6 (string)                 : title
%   #7 (extra key vals)
%\end{verbatim}
%
%    \begin{macrocode}
\DeclareObjectType {heading} {7}
%    \end{macrocode}
%
%
% \subsection{Interfaces to other components}
%
% This section holds code that is (or should be) common between different
% heading templates, for example, code for passing a title to the TOC system
% will always use the same TOC interface so it is encapsulated
% here. Effectively this means that this section should be the only part that
% needs modification if we update these other components and intorduce new
% interfaces for them.
%
% At the moment everything is set up to use the old 2e interfaces, but this
% will change over time.
%
%
%
% \subsubsection{Generating TOC and mark entries}
%
%
%  \begin{macro}{\xhead_generate_toc:NNNNN}
%  \begin{macro}{\xhead_generate_toc:NNNNo}
%    This command provides the interface to the TOC system (currently the 2e
%   one). It uses its first two arguments to decide if a TOC entry should be produced
%   and if so generates the entry from the remaining arguments.
%
%     Arguments:
%\begin{verbatim}
%   #1 (boolean)       : produce no number
%   #2 (boolean)       : force toc entry
%   #3 (string)        : heading name (\l_xhead_name_tl)
%   #4 (string)        : heading number if any (\l_xhead_number_tl)
%   #5 (string)        : toc-title (\l_xhead_toc_title_tl)
%\end{verbatim}
%
%    \begin{macrocode}
\cs_new:Npn \xhead_generate_toc:NNNNN #1#2#3#4#5 {
%<*trace>
   \typeout{xhead_generate_toc:NNNNN=#1:#2:#3:#4:#5}
%</trace>
%    \end{macrocode}
%    A TOC entry is produced if the heading number was not suppressed (|!#1|)
%    or it is forced (|#2|).
%    \begin{macrocode}
   \bool_if:nT
    { #2 || ! #1 }
    {
     \group_begin:
%    \end{macrocode}
%    Guard against use of mark commands in the heading title (from old sources).
%    \begin{macrocode}
      \cs_set_eq:NN \@mkboth \use_none:nn
      \cs_set_eq:NN \markboth \use_none:nn
      \cs_set_eq:NN \markright \use_none:n
%    \end{macrocode}
%    Use the old 2e |\addcontentsline| interface:
%    \begin{macrocode}
      \addcontentsline{toc}{#3}
         {
          \tl_if_empty:NF #4
              { \protect\numberline{ #4 } }
          #5
         }
    \group_end:
   }
}
%    \end{macrocode}
%    In the templates we really want to make sure that the title in the last
%    argument is passed and not a tokenlist in which it is saved. After all,
%    this text will get passed around over long distances. We therefore
%    provide the following variant for use in templates:
%    \begin{macrocode}
\cs_generate_variant:Nn \xhead_generate_toc:NNNNN {NNNNo}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%
%
%
%  \begin{macro}{\xhead_generate_mark:NNNNN}
%  \begin{macro}{\xhead_generate_mark:NNNNo}
%    This command provides the interface to the mark system for running
%    headers(currently the 2e one). It uses its first two arguments to decide
%    if a mark entry should be produced and if so generates the entry from the
%    remaining arguments.
%
%    Arguments:
%\begin{verbatim}
%   #1 (boolean)       : produce no number
%   #2 (boolean)       : force running header  entry
%   #3 (string)        : heading name (\l_xhead_name_tl)
%   #4 (string)        : heading number if any (\l_xhead_number_tl)
%   #5 (string)        : mark-title (\l_xhead_mark_title_tl)
%\end{verbatim}
%
%    \begin{macrocode}
\cs_new:Npn \xhead_generate_mark:NNNNN #1#2#3#4#5 {
%<*trace>
   \typeout{xhead_generate_mark:NNNNN=#1:#2:#3:#4:#5}
%</trace>
%    \end{macrocode}
%    A running header entry is produced if the heading number was not
%    suppressed (|!#1|) or it is forced (|#2|).
%    \begin{macrocode}
   \bool_if:nT
    { #2 || ! #1 }
    {
     \group_begin:
%    \end{macrocode}
%    Guard against use of mark command in heading titles (from old
%    sources)\footnote{This is wrong here, needs thought.}
%    \begin{macrocode}
       \cs_set_eq:NN \@mkboth \use_none:nn
%    \end{macrocode}
%    Again we use the original 2e interface.  |\markright|, etc.\ currently adds
%    the section number so we do not add it here---for now.
%    \begin{macrocode}
       \use:c {#3 mark} {#5}
     \group_end:
    }
}
%    \end{macrocode}
%    In the templates we really want to make sure that the title in the last
%    argument is passed and not a tokenlist in which it is saved. After all,
%    this text will get passed around over long distances. We therefore
%    provide the following variant for use in templates:
%    \begin{macrocode}
\cs_generate_variant:Nn \xhead_generate_mark:NNNNN {NNNNo}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%
%
%
%  \begin{macro}{\xhead_generate_toc_and_mark:NNNNNNN}
%
%   This is just putting it all together, may not be worth having.
%    
%    Arguments:
%\begin{verbatim}
%   #1 (boolean)       : produce no number
%   #2 (boolean)       : force toc entry
%   #3 (boolean)       : force running header entry
%   #4 (string)        : heading name (\l_xhead_name_tl)
%   #5 (string)        : heading number or empty (\l_xhead_number_tl)
%   #6 (string)        : toc-title (\l_xhead_toc_title_tl)
%   #7 (string)        : mark-title (\l_xhead_mark_title_tl)
%\end{verbatim}
%
%    \begin{macrocode}
\cs_new:Npn \xhead_generate_toc_and_mark:NNNNNNN #1#2#3#4#5#6#7 {
     \xhead_generate_toc:NNNNo  
          #1 #2 #4 #5 #6
     \xhead_generate_mark:NNNNo 
          #1 #3 #4 #5 #7
}
%    \end{macrocode}
%  \end{macro}
%
%
%
%
% \subsubsection{Prepare heading number}
%
%
%
%  \begin{macro}{\xhead_update_prepare_number:N}
%
%    This command checks if a number should be produced and if so increments
%    the corresponding counter and stores the number in
%    |\l_xhead_number_tl|. Otherwise |\l_xhead_number_tl| will be set to empty
%    to indicate that no number should be displayed.
%
%    Arguments:
%\begin{verbatim}
%   #1 (boolean)       : produce no number
%\end{verbatim}

%    Assumptions:
%\begin{verbatim}
%   \l_xhead_name_tl        : holds heading name
%   \l_xhead_level_int      : holds heading level
%\end{verbatim}
%
%   Outputs:
%\begin{verbatim}
%   \l_xhead_number_tl : holds heading number or returns empty
%\end{verbatim}
%
%    \begin{macrocode}
\cs_new:Npn \xhead_update_prepare_number:N #1 {
   \bool_if:nTF
     { #1 || \intexpr_compare_p:n { \l_xhead_level_int > \c@secnumdepth } }
     { \tl_clear:N \l_xhead_number_tl }
     {
       \refstepcounter \l_xhead_name_tl
       \tl_set:Nx \l_xhead_number_tl { \use:c {the \l_xhead_name_tl} }
     }
}
%    \end{macrocode}
%  \end{macro}
%
%
%
%
% \subsubsection{Prepare indentation after heading}
%
%  To set the paragraph indentation after a heading we need to interact with
%  the galley mechanism, which at one point will be \texttt{xgalley}. Right
%  now we use the 2e interface.
%
%  \begin{macro}{\xhead_set_after_indention:N}
%    Here we set the 2e flag depending
%    \begin{macrocode}
\cs_new:Npn \xhead_set_after_indention:N  #1 {
   \bool_if:NTF #1 \@afterindenttrue \@afterindentfalse 
}
%    \end{macrocode}
%  \end{macro}
%
%
%
%
%
% \subsubsection{Evaluating the title arguments}
%
%  According to the heading object type spec the title text for the toc and
%  running header may differ from the main title in dependence of the
%  arguments passed to the template.
%  The code below implements the documented logic.
%
%  \begin{macro}{\xhead_set_titles:nnn}
%
%    Arguments:
%\begin{verbatim}
%   #1 (string/\NoValue/empty)  : toc-title  if different from title
%   #2 (string/\NoValue/empty)  : mark-title if different from toc-title
%   #3 (string)                 : title
%\end{verbatim}
%
%    \begin{macrocode}
\cs_new:Npn \xhead_set_titles:nnn #1#2#3 {
%    \end{macrocode}
%    Determine title for toc:
%    If \HASH{1} is \NOVALUE{} or \EMPTY{} use \HASH{3} for the toc-title.
%    Otherwise use \HASH{1}.
%    \begin{macrocode}
   \IfNoValueTF{#1}
         { \tl_set:Nn \l_xhead_toc_title_tl {#3} }
         { \tl_if_empty:nTF {#1}
                { \tl_set:Nn \l_xhead_toc_title_tl {#3} }
                { \tl_set:Nn \l_xhead_toc_title_tl {#1} }
         }
%    \end{macrocode}
%    Determine title for mark: If \HASH{2} is \NOVALUE{} then use whatever was
%    determined for the toc-title as value (i.e., if a special toc-title was
%    used this will be also used for the running header, if not the main title
%    is used). Otherwise, if \HASH{2} is \EMPTY{} use \HASH{3}.  Otherwise use
%    \HASH{2} (i.e., a special title was passed for the running header).
%    \begin{macrocode}
   \IfNoValueTF{#2}
         { \tl_set_eq:NN \l_xhead_mark_title_tl \l_xhead_toc_title_tl }
         { \tl_if_empty:nTF {#2}
                { \tl_set:Nn \l_xhead_mark_title_tl {#3} }
                { \tl_set:Nn \l_xhead_mark_title_tl {#2} }
         }
}
%    \end{macrocode}
%  \end{macro}
%
%
%
%
% \subsection{Support variables for template code}
%
%
%    \begin{macrocode}
\dim_new:N  \l_xhead_indent_dim
%    \end{macrocode}
%
%
%
%    \begin{macrocode}
\skip_new:N \l_xhead_above_skip
\skip_new:N \l_xhead_below_skip
%    \end{macrocode}
%
%
%
%    \begin{macrocode}
\int_new:N  \l_xhead_level_int
\int_new:N  \l_xhead_break_penalty_int
%    \end{macrocode}
%    
%    \begin{macrocode}
\tl_new:N   \l_xhead_name_tl
\tl_new:N   \l_xhead_number_tl
\tl_new:N   \l_xhead_toc_title_tl
\tl_new:N   \l_xhead_mark_title_tl
%    \end{macrocode}
%    
%    \begin{macrocode}
\bool_new:N \l_xhead_indent_after_bool

\cs_new:Npn \xhead_title_decl: {}

\cs_new:Npn \xhead_number_format:n #1 {}

\cs_new:Npn \xhead_default_number_format:n #1 { #1 \quad}
%    \end{macrocode}
%
%
%
%
% \subsection{The template \texttt{2e-vertical}}
%
%    \begin{macrocode}
\DeclareTemplateInterface {heading} {2e-vertical} {7}
  {
    name         : tokenlist    = ???   ,
    level        : integer      = 0     ,
    break-penalty: integer      = -300  ,
    indent       : length       = 0pt   ,
    above-skip   : skip         = 0pt   ,
    below-skip   : skip         = 0pt   ,
    title-decl   : function {0} =       ,
    number-format: function {1} = \xhead_default_number_format:n {#1}  ,
    indent-after : boolean      = false ,
  }
%    \end{macrocode}
%    
%    \begin{macrocode}
\DeclareTemplateCode {heading} {2e-vertical} {7}
  {
    name          = \l_xhead_name_tl           ,
    level         = \l_xhead_level_int         ,
    break-penalty = \l_xhead_break_penalty_int ,
    indent        = \l_xhead_indent_dim        ,
    above-skip    = \l_xhead_above_skip        ,
    below-skip    = \l_xhead_below_skip        ,
    title-decl    = \xhead_title_decl:         ,
    number-format = \xhead_number_format:n     ,
    indent-after  = \l_xhead_indent_after_bool ,
  }
  {
   \AssignTemplateKeys
%    \end{macrocode}
%    Determine title for toc and mark using the 2e logic: Do not generate
%    them if the star-form of the heading is used and always use the same text
%    for TOC and mark:
%    \begin{macrocode}
   \bool_if:NF #1
    {
      \IfNoValueTF{#2}
         { \tl_set:Nn \l_xhead_toc_title_tl {#6} }
         { \tl_set:Nn \l_xhead_toc_title_tl {#2} }
      \tl_set_eq:NN \l_xhead_mark_title_tl \l_xhead_toc_title_tl
    }
%    \end{macrocode}
%    If heading number increment counter and set |\l_xhead_number_tl|
%    \begin{macrocode}
   \xhead_update_prepare_number:N #1
%    \end{macrocode}
%    Indent after heading if requested (use old mechanism):
%    \begin{macrocode}
   \xhead_set_after_indention:N \l_xhead_indent_after_bool
%    \end{macrocode}
%    Produce the space above the heading (using old 2e methods):
%    \begin{macrocode}
   \if@noskipsec \leavevmode \fi
   \par
   \if@nobreak
     \everypar{}
   \else:
     \addpenalty \l_xhead_break_penalty_int
     \addvspace  \l_xhead_above_skip
   \fi:
%    \end{macrocode}
%    Produce the title of the heading (using old 2e methods)
%    \begin{macrocode}
   \group_begin:
     \xhead_title_decl:
       {
        \@hangfrom{\hskip \l_xhead_indent_dim \scan_stop:
                   \tl_if_empty:NF \l_xhead_number_tl
                      { \xhead_number_format:n \l_xhead_number_tl }
                  }
        \interlinepenalty \@M #6\@@par
       }
   \group_end:
%    \end{macrocode}
%    Generate toc entry and mark if required:
%    \begin{macrocode}
   \xhead_generate_toc_and_mark:NNNNNNN 
          #1 \BooleanFalse \BooleanFalse     % no forcing in 2e
          \l_xhead_name_tl 
          \l_xhead_number_tl 
          \l_xhead_toc_title_tl 
          \l_xhead_mark_title_tl
%    \end{macrocode}
%    Produce the space below the heading and the handling of following
%    paragraph (using old 2e methods):
%    \begin{macrocode}
   \par \nobreak
   \vspace \l_xhead_below_skip
   \@afterheading
   \ignorespaces
 }
%    \end{macrocode}
%
%
%
%
% \subsection{The template \texttt{3a-vertical}}
%
%    Right now this template is more or less equal to \texttt{2e-vertical}
%    except that it supports the extended heading arguments with the exception
%    of \HASH{7}.
%
%    \begin{macrocode}
\DeclareTemplateInterface {heading} {3a-vertical} {7}
  {
    name                : tokenlist                = ???   ,
    level               : integer                  = 0     ,
    break-penalty       : integer                  = -300  ,
    indent              : length                   = 0pt   ,
    above-skip          : skip                     = 0pt   ,
    below-skip          : skip                     = 0pt   ,
    format              : tokenlist                = indent-by-number   ,
    parshape            : instance {parshape}      = plain  ,
    justification       : instance {justification} = flush-left ,
    font                : tokenlist                =       ,
    number-format       : function {1}             = \xhead_default_number_format:n {#1}  ,
    indent-after        : boolean                  = false ,
  }
%    \end{macrocode}
%

%  \begin{macro}{\l_xhead_title_format_tl}
%    
%    \begin{macrocode}
\tl_new:N \l_xhead_title_format_tl
\tl_new:N \l_xhead_title_font_tl

\cs_new:Npn \xhead_title_parshape:      {}
\cs_new:Npn \xhead_title_justification: {}

%    \end{macrocode}
%  \end{macro}
%
%
%    \begin{macrocode}
\DeclareTemplateCode {heading} {3a-vertical} {7}
  {
    name                = \l_xhead_name_tl            ,
    level               = \l_xhead_level_int          ,
    break-penalty       = \l_xhead_break_penalty_int  ,
    indent              = \l_xhead_indent_dim         ,
    above-skip          = \l_xhead_above_skip         ,
    below-skip          = \l_xhead_below_skip         ,
    format              = \l_xhead_title_format_tl    ,
    parshape            = \xhead_title_parshape:      ,
    justification       = \xhead_title_justification: ,
    font                = \l_xhead_title_font_tl      ,
    number-format       = \xhead_number_format:n      ,
    indent-after        = \l_xhead_indent_after_bool  ,
  }
  {
   \AssignTemplateKeys
%    \end{macrocode}
%    Set title text for TOC and mark entry:
%    \begin{macrocode}
   \xhead_set_titles:nnn {#2} {#4} {#6}
%    \end{macrocode}
%    If heading gets a number, increment counter and set
%    |\l_xhead_number_tl|.
%    \begin{macrocode}
   \xhead_update_prepare_number:N #1
%    \end{macrocode}
%    Indent after heading if requested (use old mechanism)
%    \begin{macrocode}
   \xhead_set_after_indention:N \l_xhead_indent_after_bool
%    \end{macrocode}
%
%    Produce the space above the heading (using old 2e methods)
%
%    \begin{macrocode}
   \if@noskipsec \leavevmode \fi
   \par
   \if@nobreak
     \everypar{}
   \else:
     \addpenalty \l_xhead_break_penalty_int
     \addvspace  \l_xhead_above_skip
   \fi:
%    \end{macrocode}
%
%    Produce the title of the heading
%
%    \begin{macrocode}
   \xhead_use_title_format:nn \l_xhead_title_format_tl  {#6}

%    \end{macrocode}
%    Generate toc entry and mark:
%    \begin{macrocode}
   \xhead_generate_toc_and_mark:NNNNNNN 
          #1 #3 #5 
          \l_xhead_name_tl 
          \l_xhead_number_tl 
          \l_xhead_toc_title_tl 
          \l_xhead_mark_title_tl
%    \end{macrocode}
%    Produce the space below the heading and the handling of following
%    paragraph (using old 2e methods)
%    \begin{macrocode}
   \par \nobreak
   \vspace \l_xhead_below_skip
   \@afterheading
   \ignorespaces
 }
%    \end{macrocode}
%
%
%
%  \begin{macro}{\xhead_use_title_format:nn}
%    Select a formatting command (based on first arg string) and use it to
%    format the title (second arg). 
%
%    The formatting command makes a bunch of
%    assumptions with respect to the variable names used by the templates (it
%    might ignore some of them):
%\begin{verbatim}
%   \l_xhead_title_font_tl       : font declarations for title text
%   \l_xhead_indent_dim          : indentation from the left of title
%   \xhead_title_parshape:       : parshape instance to use for title
%   \xhead_title_justification:  : justification instance to use for title
%   \l_xhead_number_tl           : raw title number or empty
%   \xhead_number_format:n       : formatting command for title number
%\end{verbatim}
%    In addition it takes a single mandatory argument holding the title text.
%
%    \begin{macrocode}
\cs_new:Npn \xhead_use_title_format:nn #1 {
  \cs_if_exist:cTF {xhead_format_ #1:n}
     { \use:c{xhead_format_ #1:n} }
     { \ERROR xhead format not defined }
}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\xhead_format_indent-by-number:n}
%    Implementing vertical version of |\@startsection| \ldots
%    \begin{macrocode}
\cs_new:cpn {xhead_format_indent-by-number:n} #1 {
   \group_begin:
      \l_xhead_title_font_tl 
      \hbox_set:Nn \l_tmpa_box 
                   {
                     \tl_if_empty:NF \l_xhead_number_tl
                         { \xhead_number_format:n \l_xhead_number_tl }
                   }

      \UseInstance{measure}{fullwidth} 
                  {\l_xhead_indent_dim + \box_wd:N \l_tmpa_box }

      \xhead_title_parshape: 
      \xhead_title_justification:
      \interlinepenalty \@M

      \noindent \hbox_overlap_left:n { \box_use:N \l_tmpa_box } 
       #1\@@par
   \group_end:
}
%    \end{macrocode}
%  \end{macro}
%
%
%
%
%  \begin{macro}{\xhead_format_number-above-text:n}
%    
%    \begin{macrocode}
\cs_new:cpn {xhead_format_number-above-text:n} #1 {
   \group_begin:
      \l_xhead_title_font_tl 
      \xhead_title_parshape: 
      \xhead_title_justification:
      \interlinepenalty \@M

      \tl_if_empty:NF \l_xhead_number_tl
          { 
            \xhead_number_format:n \l_xhead_number_tl
          }

       #1\@@par
   \group_end:
}
%    \end{macrocode}
%  \end{macro}
%
%    
%    \begin{macrocode}

\input{xtextblock.sty}


\DeclareTemplateInterface {heading} {3b-vertical} {7}
  {
    name                : tokenlist                = ???   ,
    level               : integer                  = 0     ,
    break-penalty       : integer                  = -300  ,
    indent              : length                   = 0pt   ,
    above-skip          : skip                     = 0pt   ,
    below-skip          : skip                     = 0pt   ,
    title-format        : instance {textblock-2}   = heading  ,
    number-format       : function {1}             = \xhead_default_number_format:n {#1}  ,
    indent-after        : boolean                  = false ,
  }

\cs_new:Npn \xhead_title_format:nn #1#2 {}

\DeclareTemplateCode {heading} {3b-vertical} {7}
  {
    name                = \l_xhead_name_tl            ,
    level               = \l_xhead_level_int          ,
    break-penalty       = \l_xhead_break_penalty_int  ,
    indent              = \l_xhead_indent_dim         ,
    above-skip          = \l_xhead_above_skip         ,
    below-skip          = \l_xhead_below_skip         ,
    title-format        = \xhead_title_format:nn      ,
    number-format       = \xhead_number_format:n      ,
    indent-after        = \l_xhead_indent_after_bool  ,
  }
  {
   \AssignTemplateKeys

   \xhead_set_titles:nnn {#2} {#4} {#6}

   \xhead_update_prepare_number:N #1

   \xhead_set_after_indention:N \l_xhead_indent_after_bool

   \if@noskipsec \leavevmode \fi
   \par
   \if@nobreak
     \everypar{}
   \else:
     \addpenalty \l_xhead_break_penalty_int
     \addvspace  \l_xhead_above_skip
   \fi:

   \xhead_title_format:nn \l_xhead_number_tl {#6}

   \xhead_generate_toc_and_mark:NNNNNNN 
          #1 #3 #5 
          \l_xhead_name_tl 
          \l_xhead_number_tl 
          \l_xhead_toc_title_tl 
          \l_xhead_mark_title_tl

   \par \nobreak
   \vspace \l_xhead_below_skip
   \@afterheading
   \ignorespaces
 }


%    \end{macrocode}
%
% \Finale
%
%    
%    \begin{macrocode}
\endinput
%</package>
%    \end{macrocode}
%
% \endinput
%
%
%
%
% \begin{TemplateInterfaceDescription}{}
%
%   \TemplateArgument{1}
%       {}
%
%   \TemplateSemantics
%
% \end{TemplateInterfaceDescription}
%
%


  - motto/quote text to display alongside the heading title
  - flag to number heading
  -label name for cross-reference

%
% \begin{InstanceDescription}[\textbf{no-page-break-boolean}xx]
%       {pshape}{staggered}{cutout}
%
%   \InstanceKey{no-page-break-boolean}{true}
%
%   \InstanceKey{left-side-boolean}{true}
%
%   \InstanceKey{normal-lines-int}{1}
%
%   \InstanceKey{parshape-list}{20pt,40pt,60pt}
%
%   \InstanceSemantics
%   This instance will indent each line by an additional 20pt (up to
%   the fourth line). A possible application would be a heading text
%   (with a maximum number of four lines).
%   This should then perhaps be combined with a special justification
%   instance which does ragged right except for the last line which is
%   set to full measure.
%
% \end{InstanceDescription}
%
%