1

In the description of the manpage of groff_ms, it is written:

The ms macros are suitable for reports, letters, books, and technical documentation.

However, I don't see any command to right align text (in this case the second address).

.LP
Jane Doe
.br
Somewhere

.LP
John Doe
.br
Somewhere

.PP
Dear Jane,
.PP
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
4

The ms macros have displays which are sets of lines with no fill, so each input line is one output line, and which can all be indented by some amount, or be right justified. This indents by 12cm:

.DS I 12c
John Doe
Somewhere
Else
.DE

and this aligns the right end of the text:

.DS R
John Doe
Somewhere
Else
.DE

There are also base troff commands to indent text, or to align its right side to the right edge of the paper. The simplest is .in X where X is the amount to indent by, given as a number and a unit such as 5i for 5 inches or 12c for 12 cm. It applies until another .in with no X, which restores the previous indent. Eg:

.in 12c
 John Doe
 Somewhere
 Else
.in

Note, each text line begins with a space. This forces a new output line, so you don't need .br (but you do get the space in the output). An alternative is to ask for "no fill" with .nf, then each input line is one output line. You return to fill mode with .fi:

.in 12c
.nf
John Doe
Somewhere
Else
.fi
.in

The above give you a block that is indented from the left. To actually align the right side of the text to be all the same you need to use .ad r to ask for right alignment (which applies only in fill mode), and return to normal with .ad b to adjust both sides:

.ad r
 John Doe
 Somewhere
 Else
.br
.ad b

Finally, an often used technique for quick centre or right alignment is to use the .tl title command with takes a 3 part string: 'left'centre'right'. By just providing the right part, you get a right adjusted line:

.tl '''John Doe'
.tl '''Somewhere'
.tl '''Else'
  • Thank you very much! Should I use .LP before the code you gave? – Blincer Jul 18 '19 at 14:58
  • 1
    You shouldn't need a .LP before any of these unless perhaps you have used some other macro that has, say, set up an indent that expects to be cleared by the next "paragraph". It will probably have no effect if you use it unnecessarily though; perhaps it will leave some vertical blank space. – meuh Jul 18 '19 at 15:50
  • So if I understand correctly, it's cleaner but optional. – Blincer Jul 18 '19 at 16:06
  • The groff ms macro definition of .LP is more complicated than I can understand easily, so it is wiser to use it and so avoid any potential problems. – meuh Jul 18 '19 at 16:17
  • 1
    I browsed through more of the ms macros documentation, and found a method was provided to do what you wanted, without resorting to base troff. I've added this to the start of the answer. You won't need .LP for these macros of course. – meuh Jul 18 '19 at 16:51

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.