n-t-roff / heirloom-doctools

The Heirloom Documentation Tools: troff, nroff, and related utilities
http://n-t-roff.github.io/heirloom/doctools.html
Other
127 stars 23 forks source link

relative indent indents within box and before it #80

Open ljrk0 opened 5 years ago

ljrk0 commented 5 years ago

I'm trying to achieve

foo bar
       | foo bar |
       | baz     |

however this code:

.LP
foo bar
.RS
.B1
.DS L
foo bar
baz
.DE
.B2
.RE

rather creates

foo bar
   |     foo bar |
   |     baz     |

This is consistent with my tests on original Solaris' troff however, groff though creates

foo bar
       | foo bar                         |
       | baz                             |

Which is more close to the expected behavior and also makes the box end on the right "edge" of the output, rather than after the last character (which I'd like to have as well, but I have no idea how).

I formerly tried using

foo bar
.B1
.DS I
foo bar
baz
.DE
.B2

but while this creates this (also good looking) on groff:

foo bar
|        foo bar                          |
|        baz                              | 

it creates this on heirloom/original roff:

foo bar
|        foo bar |
|        baz     |

which does not look good, because the vertical borders are not symmetrical to the respective paper edges/margins.

n-t-roff commented 5 years ago

Thank you for reporting. Have you tried DWB3.3? Solaris had been forked from an earlier DWB version.

Unlike the MM or ME package the MS package is not suited for many kinds of today's documents. Hence it is unlikely that this will be addressed in the short-term. But patches are welcome of course.

reffort commented 5 years ago

You can obtain the result you describe by generating the boxed text in a diversion and then shifting the indent before playing it back. If you need to use boxed text more than once, it would probably be worth while to create a couple of wrapper macros around .B1 and .B2, something like this:

.de Bs
.br
.nr Bf \\n(.u
.di Bd
.B1
..
.de Be
.B2 4
.di
.RS
.nf
.Bd
.RE
.rm Bd
.fi \\n(Bf
..
.
.\" Text, etc.
.
.LP
foo bar
.Bs
.nf
foo bar
baz
.Be
.LP
This
is the next
line.

If the boxed text will always be unfilled text, as in your example, you can delete the .nf from the text and add it to the .Bs macro.

The .B2 4 line inserts 4 ens of space on each side of the boxed text using an undocumented option for .B2. There is also an undocumented option C to .B1 that centers the text, .B1 C. When both undocumented options are used at the same time, there is, at no additional charge, an undocumented feature.

ljrk0 commented 5 years ago

Sorry for taking so long.

On DWB the output of my examples is the same, however what @reffort posted doesn't even compile for me on heirloom while it does on DWB.

@reffort You're code's almost perfect, thank you! Sadly it reaches a bit too far over the right line of the text when it's long, ie. if the text within the box is too long, I get:

    | Here begins the left part of the text, and here it ends on the right : |
    | foo bar                                                                |
    |    ||    foo bar and very long text, reaching over the right border of> <the text ||

Side note: Also DWB doesn't seem to support .AM whereas at least my Illumos does, and I'm pretty sure this is also the case for eg. Oracle Solaris 11.3. It's kinda cool though, that .XS automatically generate headings too.

reffort commented 5 years ago

I haven't been able to reproduce what you are showing, but if you want the lines to wrap you will need to use fill mode .fi instead of no-fill mode .nf. See attached PDF: box2.pdf

I'll recommend the book Unix Text Processing if you don't already have a copy (you can get a scanned copy in PDF form from O'Reilly's web site at https://www.oreilly.com/openbook/utp/). It is one of the best books on troff I know of, written in the 1980s using an expanded version of the ms macros on an SVR2 system. A large portion of the book is devoted to expanding the ms package.

On page 451 is an example of boxed text that looks like it was done with .B1/.B2, and on pages 453-454 is a lightly modified version of .B1 and .B2, named .BS and .BE. An example is shown on page 454 that clearly (and probably unintentionally) demonstrates the obvious bug in .B2 (the off-center centered boxed text when a .B2 indent is in effect).

The book itself uses a lot of boxed text in several forms, and most of it was probably generated by custom routines. There are also examples generated with tbl and pic. The book describes how all of them work, and provides code for some of the custom macros.