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
Jens
  • 1,752
  • 4
  • 18
  • 36

2 Answers2

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.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
egmont
  • 5,866
  • 1
    grotty(1), if only I had looked there. Thanks, accepted! – Jens Nov 07 '23 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 07 '23 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

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
  • Turns out, printf ".Dd today\n.Sh NAME\n" | GROFF_SGR=y groff -mandoc -Tutf8 can work around Debian's hack. – Jens Nov 07 '23 at 17:52