Skip to contentSkip to conversation

How to set URLs in man pages

DISCUSSION G. Branden Robinson 2 participants 2 messages Dec 19, 2024 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

Alex raised an issue that I suspect a lot of people don't know how to cope with:

How do we avoid warnings from the formatter and/or bad typography in a man page when huge URLs or file names must occur in the document?

The mechanism for doing so has been in groff for decades, but practical advice to man page authors has been locking. A few years we hashed the matter out of the groff list, and you can find guidance in the groff_man_style(7) page.

groff_man_style(7):
Prepare arguments to .MR, .MT, and .UR for typesetting; they can appear in the output. Use special character escape sequences to encode Unicode basic Latin characters where necessary, particularly the hyphen‐minus. (See section “Portability” below.) URIs can be lengthy; rendering them can result in jarring adjustment or variations in line length, or troff warnings when one is longer than an output line. The application of non‐printing break point escape sequences \: after each slash (or series thereof), and before each dot (or series thereof) is recommended as a rule of thumb. The former practice avoids forcing a trailing slash in a URI onto a separate output line, and the latter helps the reader to avoid mistakenly interpreting a dot at the end of a line as a period (or multiple dots as an ellipsis). Thus,
.UR http://\:example\:.com/\:fb8afcfbaebc74e\:.cc
has several potential break points in the URI shown. Consider adding break points before or after at signs in email addresses, and question marks, ampersands, and number signs in HTTP(S) URIs.

Here's the exhibit Alex handled recently:

Quoted 18 lines · Alejandro Colomar

I've had to amend the patch again. I didn't notice that it caused many warnings in -Tutf8, -Thtml, -Tps, and -Tpdf output. I've applied the following diff.

man/man3/getopt.3 +1 -1
index 3b0025528..cb946355a 100644
@@ -384,7 +384,7 @@ .SH HISTORY
 .IR <stdio.h> .
 .P
 Very old versions of glibc were affected by a
-.UR https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=bf079e19f50d64aa5e05b5e17ec29afab9aabb20
+.UR https://\:sourceware.org/\:git/\:?p=glibc.git;a=commitdiff;h=bf079e19f50d64aa5e05
 .BI _ PID _GNU_nonoption_argv_flags_
 environment variable
 .UE .
Quoted 2 lines

That adds break points, and also reduces the hash by half (which should hold without clashes forever, hopefully).

I observe that break points could also be added after semicolons.

Also, you can escape a newline to keep the input line length short.

.UR https://\:sourceware.org/\:git/\:?p=glibc.git;a=commitdiff;\
h=bf079e19f50d64aa5e05

groff_man_style(7):
\newline Join the next input line to the current one. Except for
the update of the input line counter (used for diagnostic messages and related purposes), a series of lines ending in backslash‐newline appears to groff as a single input line. Use this escape sequence to split excessively long input lines for document maintenance.

Regards,
Branden

#1 lore raw

Hi Branden,

Quoted 21 lines · G. Branden Robinson

Here's the exhibit Alex handled recently:

Quoted 18 lines · Alejandro Colomar

I've had to amend the patch again. I didn't notice that it caused many warnings in -Tutf8, -Thtml, -Tps, and -Tpdf output. I've applied the following diff.

man/man3/getopt.3 +1 -1
index 3b0025528..cb946355a 100644
@@ -384,7 +384,7 @@ .SH HISTORY
 .IR <stdio.h> .
 .P
 Very old versions of glibc were affected by a
-.UR https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=bf079e19f50d64aa5e05b5e17ec29afab9aabb20
+.UR https://\:sourceware.org/\:git/\:?p=glibc.git;a=commitdiff;h=bf079e19f50d64aa5e05
 .BI _ PID _GNU_nonoption_argv_flags_
 environment variable
 .UE .
Quoted 4 lines
Quoted 2 lines

That adds break points, and also reduces the hash by half (which should hold without clashes forever, hopefully).

I observe that break points could also be added after semicolons.

I would have done that if there was another warning. But I prefer to keep that part as a single token, if not necessary.

Quoted 2 lines

Also, you can escape a newline to keep the input line length short.

I prefer to keep the input line unbroken. It makes it easier to sed(1) stuff later.

It keeps the language simpler.

Have a lovely night!
Alex

Quoted 13 lines

.UR https://\:sourceware.org/\:git/\:?p=glibc.git;a=commitdiff;\
h=bf079e19f50d64aa5e05

groff_man_style(7):
\newline Join the next input line to the current one. Except for
the update of the input line counter (used for diagnostic messages and related purposes), a series of lines ending in backslash‐newline appears to groff as a single input line. Use this escape sequence to split excessively long input lines for document maintenance.

Regards,
Branden

Signature · 1 line
<https://www.alejandro-colomar.es/>