Thomas Dickey has one correct (and portable) solution but like you, I find it a bit unprepossessing due to the font selection escape sequences. I much prefer man(7)'s font styling macros.
Further, the \
(backslash-space) escape sequence can also be ugly because its unbreakable space is fixed-width; on a line that undergoes adjustment, this can be noticeable and jarring.
I therefore recommend using the output line continuation escape sequence \c
to permit an input line to end without causing the insertion of a breakable space, and the \~
escape sequence for an unbreakable, but adjustable space.
You've turned off adjustment in your example, but that is not necessary as I will show. By using \~
, adjustment can be done evenly across the lines of the synopsis without causing problems. This escape sequence is portable to all currently-maintained troff projects except that in Illumos. groff has had it since 1991 (at least), Heirloom Doctools since September 2005, mandoc (which isn't a troff but does parse man pages) since September 2009, neatroff since September 2016, and Plan 9 from User Space troff as of August 2022.
In your example, you used the groff register .hy
and groff's extended interpolation syntax to get at it. If you're using groff, you might want to consider its SY
/YS
extensions to the man(7) macro package for setting your command synopses.2 (These macros also save and restore the hyphenation mode for you.)
.TH FOOBAR-DEMO 8 2022-03-16 "Charlie Brown" "System Administration"
.\"
.SH NAME
foobar-demo \- demonstration of manual formatting
.\"
.SH SYNOPSIS
.B foobar\-demo123 \" I escaped this hyphen as well.
.RB [ \-a\~\c
.IR match_spec ]
.RB [ \-\-resource-agent\~\c
.IR match_spec ]
.RB [ \-v\~\c
.IR version ]
.RB [ \-\-version\~\c
.IR version ]
.\"
.SH DESCRIPTION
[-v
to the next so it's kept adjacent to--version]
?