我正在尝试为软件编写手册页,并希望包含一些代码片段。我目前正在使用.RS和。关于宏作为定制的一部分。样本宏,但由于某种原因不起作用。这是手册页:
.TH MYMANPAGE 1
.de SAMPLE
.br
.RS
.nf
.nh
..
.de ESAMPLE
.hy
.fi
.RE
..
.SH TEST SECTION HEADING
This is a test section heading.
.TP
.B Test Paragraph Label
This is some test paragraph text. This is some test paragraph text. This
is some test paragraph text. This is some indented test code:
.SAMPLE
int main(void) {
return 42;
}
.ESAMPLE
This is more text after the test code. This is more text after the test
code.
最终发生的是后面的文字.E样本缩进量没有段落文本那么多。相反,它与段落标签对齐。什么是正确的.[E]样本宏定义让它们更好地使用.TP?
答案1
恢复.RE
默认缩进级别,而不是当前.TP
缩进级别。您需要做的就是保存并恢复调用时实际的缩进.RS
。下面的修复假设您不会将SAMPLE
s 嵌套在SAMPLE
s 中:
.de SAMPLE
.br
.nr saveIN \\n(.i \" double the backslash when defining a macro
.RS
.nf
.nh
..
.de ESAMPLE
.hy
.fi
.RE
.in \\n[saveIN]u \" 'u' means 'units': do not scale this number
..
$ man ./i
[...]
Test Paragraph Label
This is some test paragraph text. This is some test paragraph
text. This is some test paragraph text. This is some indented
test code:
int main(void) {
return 42;
}
This is more text after the test code. This is more text after
the test code.