0

I found that groff uses different ways to indicate bold text for the utf8 output format.

On FreeBSD 14, groff emits escape codes for a terminal (ESC, [1m):

$ printf ".Dd today\n.Sh NAME\n" | groff -mandoc -Tutf8 | od -c
0000000   \n 033   [   1   m   N   A   M   E 033   [   0   m  \n
[...]

On Linux (debian Bookworm) is uses backspaces and overstriking:

$ printf ".Dd today\n.Sh NAME\n" | groff -mandoc -Tutf8 | od -c
[...]
0000120   N  \b   N   A  \b   A   M  \b   M   E  \b   E  \n

Why is it so and is there a way to make Linux groff also use ESC codes for the terminal? I have read the groff man page from top to bottom but can't find an option to change this behavior.

(I need to post-process the result and ESC codes make that much easier and flexible.)

EDIT: The solution (thanks go to @egmont) was to read Debian's grotty(1) manual and then force the SGR behavior with

printf ".Dd today\n.Sh NAME\n" | GROFF_SGR=y groff -mandoc -Tutf8
1

2 Answers 2

2

Debian Bookworm configures groff 1.22 for the old backspace-overwrite behavior you see there, and documents it in their patched grotty manual page along with how to revert to the newer SGR (\e[1m-like) behavior:

printf ".Dd today\n.Sh NAME\n" | GROFF_SGR=y groff -mandoc -Tutf8

It seems that the given configuration and patch is no longer there in their groff 1.23 package in unstable, as well as in Ubuntu 23.04. So it's probably the last Debian version you see with this old behavior, they're switching to the new SGR method, following upstream groff's defaults.

2
  • 1
    grotty(1), if only I had looked there. Thanks, accepted!
    – Jens
    Nov 7, 2023 at 17:50
  • 2
    Don't blame yourself, haha, it would have never occurred to me either. I just knew Debian had this config or patch, I looked at their package to see how it went exactly and found the manpage patch :)
    – egmont
    Nov 7, 2023 at 18:44
1

You can abuse script and less to convert the backspace sequences:

script --return --quiet -c "printf '.Dd today\n.Sh NAME\n' | groff -mandoc -Tutf8 | less" /dev/null | od -c

…
0000200   1   m   N   A   M   E 033   [   0   m 033   [   m  \r  \n
1
  • Turns out, printf ".Dd today\n.Sh NAME\n" | GROFF_SGR=y groff -mandoc -Tutf8 can work around Debian's hack.
    – Jens
    Nov 7, 2023 at 17:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .