groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [idea] troff -Troff


From: G. Branden Robinson
Subject: Re: [idea] troff -Troff
Date: Mon, 19 Feb 2024 22:32:02 -0600

At 2024-02-19T22:12:53-0500, Douglas McIlroy wrote:
> > The question is whether or not man macros can be expanded
> > to their groff equivalents.
> 
> If you'd consider a preprocessor based on groff, there's a
> notionally simple way to get a copy of the input with macros
> and strings expanded: Provide a groff option that has the
> side effect of sending post-expansion input to a file, but
> otherwise behaves exactly like groff.
> 
> This scheme may have trouble with diversions and groff-only
> requests. However some of the latter may be approximated
> by appropriate macro definitions.

This sounds to me approximately as hard what I mused about in response
to Alex in the first place.

By the time the formatter is done processing an input line, what it has
to work with is a series of "nodes".  These are each converted to one or
more device-independent output commands.  At this point what we have
doesn't look much like *roff anymore.

One of my introspectability notions is to add yet another debugging
request (I've added a few other less ambitious ones lately).[1]  The
name I have in mind for it is `pout`, for `print (to stderr) the pending
output`.

To do this usefully will require adding a self-describing member
function to every node class in the formatter, and there are a few
dozen.  That's the main reason I haven't done it yet.

But once I've done it, I can implement what I have in mind for expanded
function of the `pm` request, such that it will dump you the contents of
a macro, string, or diversion named in its argument.  Since a diversion
can contain nodes, the work done above will be useful.

Straw man follows.

.ds s1 \" empty
.ds s2 foobar

.de xx
.sp 1
.ft B
..

.box dd
.ft B
blah
.ft
.br
.box

.pm s1
.pm s2
 foobar
.pm xx
 .sp 1
newline
 .ft B
newline
.pm dd
node glyph character="f" font=3
node glyph character="o" font=3
node glyph character="o" font=3
node glyph character="b" font=3
node glyph character="a" font=3
node glyph character="r" font=3
node break

I have some confidence in my expectations for string and macro dumping,
but my ideas about dumped diversions are pretty inchoate.  As far as I
know, no *roff has ever documented this aspect of its implementation--
not in detail, at any rate.

I reckon `pout` output would look similar to that for `pm` of a
diversion.

To tie this in with other recent discussions (and commits), dumping a
diversion or the pending output could also show things like this.

node device-control content="ps:exec [/Dest /pdf:bm1 /Title (Attack...) /Level 
1 /OUT pdfmark"

As one might infer from the syntax I'm proposing on the back of this
napkin, I would like this output to be relatively easy to split into
words and parse.

Regards,
Branden

[1] NEWS:

o A new request, `pcolor`, reports to the standard error stream the
  current list of defined colors.  (A device's default stroke and/or
  fill colors, "default", are not listed since they are immutable and
  their details unknown to the formatter.)

o A new request, `pcomposite`, reports to the standard error stream the
  current list of defined composite characters.

o A new request, `phw`, reports to the standard error stream the current
  list of hyphenation exceptions.

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]