3 ms·
In the documentations sections describing the REPL, I wanted to nicely typeset keystroke sequences with <kbd>...</kbd>. The result is that there two macros:
by kazinator 4y ago
In the documentations sections describing the REPL, I wanted to nicely typeset keystroke sequences with <kbd>...</kbd>. The result is that there two macros:
.key foo
foo will be typeset as a keycap, with spaces around it, and:
.keyn foo bar
foo typeset as keycap, immediately followed by bar (no intervening space) by regular bar.
The macros are defined in three ways: one for man2html, one for nroff, and one for groff:
.\" keystrokes
.ie \n(M2 \{\
.de key
.M2HT <kbd>\\$1</kbd>
..
.de keyn
.M2HT <kbd>\\$1</kbd>\\$2
..
.\}
That's for man2html, detected by the M2 variable being nonzero. (This elicits a warning out of groff, due to that variable not existing.) We use the .M2HT macro for inline HTML. I think that didn't exist in man2html; another thing I added.
.el \{\
. ie n \{\
. de key
[\\$1]
. .
. de keyn
[\\$1]\\$2
. .
. \}
Else, for the other two: first nroff for man page viewing. Here the
strategy is to use square brackets, so .key Ctrl becomes [Ctrl].
. el \{\
. \" Box macro from Groff manual with $2 added
. de box
. nr @wd \w'\\$1'
\h'.2m'\
\h'-.2m'\v'(.2m - \\n[rsb]u)'\
\D'l 0 -(\\n[rst]u - \\n[rsb]u + .4m)'\
\D'l (\\n[@wd]u + .4m) 0'\
\D'l 0 (\\n[rst]u - \\n[rsb]u + .4m)'\
\D'l -(\\n[@wd]u + .4m) 0'\
\h'.2m'\v'-(.2m - \\n[rsb]u)'\
\\$1\
\h'.2m'\\$2
. .
. de key
. box "\\$1" ""
. .
. de keyn
. box "\\$1" "\\$2"
. .
. \}
.\}
For groff PDF output we use a .box macro to put a box around the keycap material. The macro is based on something in the manual.
Not sure why the box invocations are indented funny.