Sebastien Peterson-Boudreau <[email protected]> wrote:
> Oftentimes when writing documents with numbered headings (using ms), I
> have no need of the top level heading -- at least, not to display it --
> but still want the automatic numbering for deeper headings.
> 
> For example, I will oftentimes settle for something like this:
> 
>       \" ms input
>       .NH 1
>       .NH 2
>       foo
>       .NH 2
>       bar
>       .NH 1
>       .NH 2
>       baz
>       
>       \" output...
>       1.
>       1.1. foo
>       1.2. bar
>       2.
>       2.1. baz
> 
> ...when really I'd like to only have the headings with `foo', `bar', and
> `baz', if that all makes sense.
> 
> So, I was wondering if there was any option to suppress the output of
> the `.NH 1' while still having it increment the number of headings.
> Otherwise, I will have to look into fiddling with whatever internal
> registers NH uses...
> 
> Thanks :D

This is a first attempt. I am sure it can be improved.

.als ONH @NH
.rm @NH
.
.de @NH
.if '\\$1'S' \{\
.  if '\\$2'1' \{\
.    nr nh*hl 1
.    nr H1 \\$3
.    return
.  \}
.\}
.if '\\$1'1' \{\
.  nr nh*hl 1
.  nr H1 \\n[H1]+1
.  return
.\}
.ONH \\$*
..
.\" if cov*ab-init has not been called yet
.als NH @NH
\" ms input
.NH 1
.NH 2
foo
.NH 2
bar
.NH 1
.NH 2
baz
.NH S 1 1
.NH 2
New list
.NH 3
Another heading level

% nroff -c -ms example.ms | col -bx

1.1.  foo

1.2.  bar

2.1.  baz

1.1.  New list

1.1.1.  Another heading level

Reply via email to