.\"	MACROES FOR SECTIONS (file tmac.q1)
.\"
.\"		Th.A. Zoethout
.\"
.de RP			\" SET TO REPORT MODE
.\"	.RP
.			\" The initial mode is manual ( \n(RP=1 ).
.nr RP 0
.nr M1 1
.nr M2 1
.nr M3 1
.nr M4 1
.nr M5 1
.nr TP 0
.if \\n(nl<0 .Pn
.rm RP
..
.de SN			\" SET SECTION NUMBERS
.\"	.SN [ $1 [ $2 [ $3 [ $4 [$5] ] ] ] ]
.			\" $1 = first section number level 1
.			\" $2 = first section number level 2
.			\" $3 = first section number level 3
.			\" $4 = first section number level 4
.			\" $4 = first appendix number
.nr S1 0
.if \\n(.$>0 .nr S1 \\$1
.nr S2 0
.if \\n(.$>1 .nr S2 \\$2
.nr S3 0
.if \\n(.$>2 .nr S3 \\$3
.nr S4 0
.if \\n(.$>3 .nr S4 \\$4
.nr S5 0
.if \\n(.$>4 .nr S5 \\$5
.if \\n(.$>0 .nr S\\n(.$ -1
..
.de SM			\" SET MODE FOR SECTION TITLES
.\"	.SM [ Sn [ $2 ... ] ]
.			\" Sn = section level S1 S2 S3 S4 AP
.			\" $2 ... = Capital, Bold, Underlined.
.			\" $2 = absent resets, C, B and U are accumulative
.nr SM 0
.if \&\\$1\&S1\& .nr SM 1
.if \&\\$1\&S2\& .nr SM 2
.if \&\\$1\&S3\& .nr SM 3
.if \&\\$1\&S4\& .nr SM 4
.if \&\\$1\&AP\& .nr SM 5
.if \\n(SM=0 \{\
.Er W ".SM: unknown section level \\$1
.nr SM 4 \}
.nr M\\n(SM 0
.if \\n(.$>1 .So \\$2
.if \\n(.$>2 .So \\$3
.if \\n(.$>3 .So \\$4
.if \\n(.$>4 .So \\$5
.rr SM
..
.de S1			\" START SECTION AT LEVEL 1
.\"	.S1 [ $1 ... ]
.			\" $1 ... = heading of section
.			\" Report mode headings need 9 lines on the page.
.Ct \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
.if \&\\*(St\&\& .ds St Chapter
.Ss 1 1
.Se 1 2 4
.Ca 0
.ie \\n(RP=0 .Sh 1 1
.el .Sc 1 2
..
.de S2			\" START SECTION AT LEVEL 2
.\"	.S2 [ $1 ... ]
.			\" $1 ... = heading of section
.			\" Needs 7 lines on the page
.Ct \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
.Ss 2 1
.Se 0 1 3
.if !\&\\*(St\&\& .Ca 2
.Si 2 0
..
.de S3			\" START SECTION AT LEVEL 3
.\"	.S3 [ $1 ... ]
.			\" $1 ... = heading of section
.			\" Needs 6 lines on the page
.Ct \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
.Ss 3 1
.Se 0 0 3
.if !\&\\*(St\&\& .Ca 4
.Si 3 0
..
.de S4			\" START SECTION AT LEVEL 4
.\"	.S4 [ $1 ... ]
.			\" $1 ... = heading of section
.			\" needs 6 lines on the page
.Ct \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
.Ss 4 1
.Se 0 0 3
.if !\&\\*(St\&\& .Ca 6
.Si 4 0
..
.de AP			\" START APPENDIX
.\"	.AP [ $1 ... ]
.			\" $1 ... = heading of appendix
.			\" Report mode appendices are level 1 sections
.Ct \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
.if \&\\*(St\&\& .ds St Appendix
.Ss 5 A
.Se 2 2 4
.Ca 0
.ie \\n(RP=0 .Sh 1 1
.el .Sc 5 2
..
.de CT			\" OUTPUT TABLE OF CONTENTS
.\"	.CT
.ti \\n(.iu
.Cc
.rm Cc
..
.de So			\" decode section mode options
.\"	.So $1
.			\" $1 = Capital, Bold, Underlined, larger Size
.if \&\\$1\&S\& .nr M\\n(SM +8
.if \&\\$1\&C\& .nr M\\n(SM +4
.if \&\\$1\&B\& .nr M\\n(SM +2
.if \&\\$1\&U\& .nr M\\n(SM +1
..
.de Ss			\" compose section number
.			\" $1 = section level
.			\" $2 = format for heading
.ie \\$1=5 .nr Ss 0
.el .nr Ss \\$1
.if \\n(Ss=0 .nr S5 +1
.ie \\n(Ss=1 .nr S1 +1
.el .if \\n(Ss<1 .nr S1 \\n(S5
.ie \\n(Ss=2 .nr S2 +1
.el .if \\n(Ss<2 .nr S2 0
.ie \\n(Ss=3 .nr S3 +1
.el .if \\n(Ss<3 .nr S3 0
.ie \\n(Ss=4 .nr S4 +1
.el .if \\n(Ss<4 .nr S4 0
.if \\n(Ss=0 .nr Ss 1
.af S\\n(Ss \\$2
.ie \&\\*(St\&\& .ds Sn "\\n(S\\n(Ss.
.el \{\
.ds Sn "\\n(S1.
.if \\n(Ss>1 .as Sn "\\n(S2
.if \\n(Ss>2 .as Sn ".\\n(S3
.if \\n(Ss>3 .as Sn ".\\n(S4\}
.rr Ss
..
.de Se			\" end previous section
.			\" $1 = next section: 0 - Sub, 1 - Main, 2 - Appendix
.			\" $2 = extra vertical spacing ending previous section
.			\" $3 = extra need next section
.if \\$1=1 .if \\n(S5>0 \
.	Er F ".S1: sections cannot follow an appendix
.ch Id
.Cr
.if \\n(TP>0 .rs
.ie (\\n(RP=1)&(\\$1>0)&(\\n(nl>=0) .bp
.el \{\
.if \\n(NS>0 .sp \\$2v
.if \\n(NS=0 .sp \\$2v+\\n(VSu
.ne \\$3v+\\n(NDv \}
.if \\$1=1 .if \\n(RP>0 .nr FN 1
.in 0
.ti \\n(.iu
.ll \\n(LLu
.rs
..
.de Ca			\" append to table of contents
.			\" $1 = initial indent of line
.da Cc
.if \\$1=0 \!.sp \\\\n(VSu
.if \\$1=0 \!.ne 2u*\\\\n(NDv
\!.ti \\\n(.iu
\!\l\&\\$1n\ \&\\*(Sn\ \\*(St\ \l\&|\\\\n(.lu-\w\&\ \\n%\&u.\&\ \\n%
\!.br
.da
..
.de Sm			\" apply section title modes
.			\" $1 = level of section: 1 2 3 4 5 (=AP)
.nr Sm \\n(M\\$1
.if \\n(Sm>=8 \{\
.if !\&\\*(St\&\& .ds St \s+2\\*(St\s0
.ds Sn \s+2\\*(Sn\s0
.nr Sm -8 \}
.if \\n(Sm>=4 \{\
.tr aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ
.nr Sm -4 \}
.if \\n(Sm>=2 \{\
.if !\&\\*(St\&\& .ds St \f3\\*(St\fP
.ds Sn \f3\\*(Sn\fP
.nr Sm -2 \}
.if \\n(Sm=1 \{\
.if !\&\\*(St\&\& .ds St \f2\\*(St\fP
.ds Sn \f2\\*(Sn\fP \}
.rr Sm
..
.de Si			\" sub-section heading
.			\" $1 = level of section
.			\" $2 = extra vertical spacing succeding heading
.ie !\&\\*(St\&\& .Sh \\$1 \\$2
.el \{\
.Sm \\$1
.ne 3v
\&\\*(Sn\ \ \c
.nr Id \w\&\\*(Sn\ \ \&
.wh \\n(nlu+1v Id
.tr aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz
.rm Sn \}
..
.de Sh			\" left adjusted section heading
.			\" $1 = level of section
.			\" $2 = extra vertical spacing succeeding heading
.Sm \\$1
\\*(Sn\ \ \\*(St
.if \\n(NS>0 .if \\$2>0 .sp \\$2v
.if \\n(NS=0 .if (\\$2v+\\n(VS)>0 .sp \\$2v+\\n(VSu
.nr NS 0
.ti \\n(INu
.tr aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz
.rm Sn
.rm St
..
.de Id			\" trap macro for indented section headings
\\*(Ncti \\n(.iu+\\n(Idu \" This calls ti
.if \&\\n(.z\&\& .ch Id
..
.de Sc			\" centered section heading
.			\" $1 = level of section
.			\" $2 = extra vertical spacing succeeding heading
.if \\$1=1 \{.af S1 I
.ds Sn "\\n(S1\ 
.af S1 1
.if \\n(S1=0 .ds Sn "\}
.Sm \\$1
\h#\\n(.lu-\\n(.iu-\w\&\\*(St\&u/2u-\w\&\\*(Sn\ \&u#\\*(Sn\ \\*(St
.if \\n(NS>0 .if \\$2>0 .sp \\$2v
.if \\n(NS=0 .if (\\$2v+\\n(VS)>0 .sp \\$2v+\\n(VSu
.nr NS 0
.ti \\n(INu
.tr aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz
.rm Sn
.rm St
..
.			\" INITIALISATION
.nr S1 0
.nr S2 0
.nr S3 0
.nr S4 0
.nr S5 0
.nr M1 4
.nr M2 1
.nr M3 1
.nr M4 1
.nr M5 4
.nr TP 1
.nr RP 1
.\*($0
.rm $0
