groff -mandoc creating "ESC[1m" versus overstriking with backspace for bold text

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 todayn.Sh NAMEn" | 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 todayn.Sh NAMEn" | 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 todayn.Sh NAMEn" | GROFF_SGR=y groff -mandoc -Tutf8
Asked By: Jens


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 todayn.Sh NAMEn" | 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.

Answered By: egmont

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

script --return --quiet -c "printf '.Dd todayn.Sh NAMEn' | groff -mandoc -Tutf8 | less" /dev/null | od -c

0000200   1   m   N   A   M   E 033   [   0   m 033   [   m  r  n
Answered By: Chris Davies