Skip to content

Commit d85280d

Browse files
committed
Silence "warning: cannot select font 'C'" with GNU roff 1.23
It's difficult to portably ask the man(7) macro package for a monospaced font (whether it's referred to as C, CW or CR) without any extra configuration. That's what leads to: warning: cannot select font 'C' This can be reproduced on Fedora 39, which has GNU roff 1.23, with: $ man crun >/dev/null troff:<standard input>:25: warning: cannot select font 'C' troff:<standard input>:134: warning: cannot select font 'C' ... $ man podman >/dev/null troff:<standard input>:15: warning: cannot select font 'C' troff:<standard input>:25: warning: cannot select font 'C' ... $ man toolbox >/dev/null troff:<standard input>:33: warning: cannot select font 'C' troff:<standard input>:43: warning: cannot select font 'C' ... These may look like odd uses of man(1), but it's used by the Toolbx [1] test suite to ensure that 'toolbox help' and 'toolbox --help' do render the toolbox(1) manual, which, like crun(1) and podman(1), is generated by go-md2man(1). The warnings come from the current \\fB\\fC sequence for inline code enclosed in single backticks (ie., `) that uses 'C' to ask for a monospace font. Other than the difficulties with portably asking the man(7) macro package for a monospace font, the \\fB\\fC sequence has some oddities. If a monospace font does get selected by \\fC, then the request for bold with \\fB gets masked, with the possible surprise that switching back to the 'previous font' with \\fP will result in bold. This is what happens when the manual is rendered in HyperText Markup Language or PostScript: $ man --troff-device html <manual> > foo.html $ man --troff-device ps <manual> > foo.ps If the manual is displayed on a terminal device, \\fC is a NOP because terminals are always monospaced and can't change the font family. So, only \\fB is in effect. Therefore, the use of \\fC is only relevant for non-terminal outputs, like HTML and PS. Since HTML and PS use serif fonts by default, an inline switch to monospace looks visually jarring. This is different from other common uses of monospace for inline code, such as on GitLab and GitHub, where sans-serif fonts are used by default. Hence, just don't attempt to use monospace for inline code enclosed in single backticks (ie., `) and stick to bold everywhere. As suggested by G. Branden Robinson. [1] https://containertoolbx.org/ https://github.com/containers/toolbox #99 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1049968
1 parent e8098c3 commit d85280d

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

md2man/roff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const (
3535
hruleTag = "\n.ti 0\n\\l'\\n(.lu'\n"
3636
linkTag = "\n\\[la]"
3737
linkCloseTag = "\\[ra]"
38-
codespanTag = "\\fB\\fC"
38+
codespanTag = "\\fB"
3939
codespanCloseTag = "\\fR"
4040
codeTag = "\n.EX\n"
4141
codeCloseTag = "\n.EE\n"

md2man/roff_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ func TestStrong(t *testing.T) {
128128
".nh\n\n.PP\nmix of **markers__\n",
129129

130130
"**`/usr`** : this folder is named `usr`\n",
131-
".nh\n\n.PP\n\\fB\\fB\\fC/usr\\fR\\fP : this folder is named \\fB\\fCusr\\fR\n",
131+
".nh\n\n.PP\n\\fB\\fB/usr\\fR\\fP : this folder is named \\fBusr\\fR\n",
132132

133133
"**`/usr`** :\n\n this folder is named `usr`\n",
134-
".nh\n\n.PP\n\\fB\\fB\\fC/usr\\fR\\fP :\n\n.PP\nthis folder is named \\fB\\fCusr\\fR\n",
134+
".nh\n\n.PP\n\\fB\\fB/usr\\fR\\fP :\n\n.PP\nthis folder is named \\fBusr\\fR\n",
135135
}
136136
doTestsInline(t, tests)
137137
}
@@ -168,13 +168,13 @@ func TestEmphasisMix(t *testing.T) {
168168
func TestCodeSpan(t *testing.T) {
169169
tests := []string{
170170
"`source code`\n",
171-
".nh\n\n.PP\n\\fB\\fCsource code\\fR\n",
171+
".nh\n\n.PP\n\\fBsource code\\fR\n",
172172

173173
"` source code with spaces `\n",
174-
".nh\n\n.PP\n\\fB\\fCsource code with spaces\\fR\n",
174+
".nh\n\n.PP\n\\fBsource code with spaces\\fR\n",
175175

176176
"` source code with spaces `not here\n",
177-
".nh\n\n.PP\n\\fB\\fCsource code with spaces\\fRnot here\n",
177+
".nh\n\n.PP\n\\fBsource code with spaces\\fRnot here\n",
178178

179179
"a `single marker\n",
180180
".nh\n\n.PP\na `single marker\n",
@@ -186,19 +186,19 @@ func TestCodeSpan(t *testing.T) {
186186
".nh\n\n.PP\nmarkers with a space\n",
187187

188188
"`source code` and a `stray\n",
189-
".nh\n\n.PP\n\\fB\\fCsource code\\fR and a `stray\n",
189+
".nh\n\n.PP\n\\fBsource code\\fR and a `stray\n",
190190

191191
"`source *with* _awkward characters_ in it`\n",
192-
".nh\n\n.PP\n\\fB\\fCsource *with* _awkward characters_ in it\\fR\n",
192+
".nh\n\n.PP\n\\fBsource *with* _awkward characters_ in it\\fR\n",
193193

194194
"`split over\ntwo lines`\n",
195-
".nh\n\n.PP\n\\fB\\fCsplit over\ntwo lines\\fR\n",
195+
".nh\n\n.PP\n\\fBsplit over\ntwo lines\\fR\n",
196196

197197
"```multiple ticks``` for the marker\n",
198-
".nh\n\n.PP\n\\fB\\fCmultiple ticks\\fR for the marker\n",
198+
".nh\n\n.PP\n\\fBmultiple ticks\\fR for the marker\n",
199199

200200
"```multiple ticks `with` ticks inside```\n",
201-
".nh\n\n.PP\n\\fB\\fCmultiple ticks `with` ticks inside\\fR\n",
201+
".nh\n\n.PP\n\\fBmultiple ticks `with` ticks inside\\fR\n",
202202
}
203203
doTestsInline(t, tests)
204204
}
@@ -331,9 +331,9 @@ row one This is a short line.
331331
row|two Col1 should not wrap.
332332
row three no|wrap
333333
row four Inline \fIcursive\fP should not wrap.
334-
row five Inline \fB\fCcode markup\fR should not wrap.
334+
row five Inline \fBcode markup\fR should not wrap.
335335
row six T{
336-
A line that's longer than 30 characters with inline \fB\fCcode markup\fR or \fIcursive\fP should not wrap.
336+
A line that's longer than 30 characters with inline \fBcode markup\fR or \fIcursive\fP should not wrap.
337337
T}
338338
row seven T{
339339
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu ipsum eget tortor aliquam accumsan. Quisque ac turpis convallis, sagittis urna ac, tempor est. Mauris nibh arcu, hendrerit id eros sed, sodales lacinia ex. Suspendisse sed condimentum urna, vitae mattis lectus. Mauris imperdiet magna vel purus pretium, id interdum libero.

0 commit comments

Comments
 (0)