At 2026-05-12T22:49:37-0400, Larry Kollar wrote:
> Sebastien Peterson-Boudreau <[email protected]>
> wrote:
> > I am not expert on microtypography, so I could totally be in the
> > wrong here, but this approach (adjusting punctuation before all line
> > breaks) seems maybe a bit naïve? It would also adjust punctuation at
> > the ends of lines when left justified or centered. Perhaps because
> > the adjustment is so small (_micro_typography) this isn't
> > significant.
> 
> Given a right margin, any line that doesn’t reach the right margin
> should be passed through unchanged.
> 
> > With this in mind, though, I believe the hangpunc program could
> > possibly be written in ~5 lines of sed(1), ~2 lines of awk(1) or 1
> > line of perl* :p
> 
> I was working in awk[1], and it was a lot more than 2 lines. First, it
> has to check the resolution[2]. The plan was to buffer an entire line,
> determine whether it ended in a “favored” punctuation mark at the
> right margin, then add interword spacing as needed (or pass it through
> in most cases). If it ended up as 10, or even 20 lines of awk, I’d be
> thrilled.

Another thing that might help is to have the source document record
where the right margin is by having the formatter compute it and then
issue it as a "trout" comment for collection and interpretation by your
filter.  This could be more reliable than doing it yourself in AWK, and
almost certainly preferable to doing arithmetic in sed(1).[A]

Sketch:

$ printf '.po 1i\n.in 2i\n.ll 3i\n.nr right-margin 
\\n[.o]+\\n[.i]+\\n[.l]\n\\!# right-margin=\\n[right-margin]\n' \
  | groff -Z
x T ps
x res 72000 1 1
x init
p1
# right-margin=432000
x trailer
V792000
x stop

> [2] As I mentioned earlier, groff has a 1/1000 pt resolution,

On the "ps" and "pdf" devices, yet.  Others vary.

$ find font -name DESC -or -name DESC.in | sort | xargs grep -w res
font/devX100-12/DESC:res 100
font/devX100/DESC:res 100
font/devX75-12/DESC:res 75
font/devX75/DESC:res 75
font/devdvi/DESC.in:res 57816
font/devlbp/DESC.in:res 300
font/devpdf/DESC.in:res 72000
font/devps/DESC.in:res 72000

Regards,
Branden

[A] apologies to Greg Ubben

Attachment: signature.asc
Description: PGP signature

Reply via email to