0

I have groff file to generate a pdf in the format:

.TL
Article title
.AU
Author name
.AI
Publication title
.SH
.LP
First paragraph
.PP
More paragraphs

I'm then running groff -ms a.ms -T pdf > a.pdf to generate a pdf. I like how groff makes formatting easy but I'm wondering if it would be possible to include an ascii diagram.

For example the following:

 +-------------------------+             +-----------------+
 |                         |             |                 |
 |      Hello              |             |                 |
 |                         +-------------+                 |
 |                         |             |                 |
 +-------------------------+             +-----------------+

If input as a normal paragraph turns into:

enter image description here

Is there anyway I can insert a section into groff that will preserve the spaces so these kind of diagrams can be used?

Looking at the manual for groff_ms I see:

.PS and .PE Denotes a graphic, to be processed by the pic preprocessor. You can create a pic file by hand, using the AT&T pic manual available on the Web as a reference, or by using a graphics program such as xfig.

But this seems to only accept pic language markup.

Is there anyway I can insert assci drawings into groff?

  • 1
    you have to choose monospaced font for the ascii art – jsotola Nov 12 '18 at 22:45
3

Groff supports a CW (constant width) font, and you can select it with .ft CW or \f(CW.

To turn off filling, use a display, .DS - .DE, or a .nf - .fi pair.

.TL
Two boxes, two ways
.LP
ASCII drawing
.DS C
.ft CW
 +-------------------------+             +-----------------+
 |                         |             |                 |
 |      Hello              |             |                 |
 |                         +-------------+                 |
 |                         |             |                 |
 +-------------------------+             +-----------------+
.ft
.DE
.LP
Pic drawing
.PS
box width 2 "\f(CWHello\fP"
line 1.5
box width 1.5
.PE

troff postscript output

  • Very nice. Don't see much *roff formatting in the public eye these days – roaima Nov 14 '18 at 16:27
  • The nice thing is that nroff manages to draw the pic boxes fairly nicely in ASCII too. – Kusalananda Nov 14 '18 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.