Man
在手冊頁中正確插入程式碼範例
我正在嘗試為軟體編寫手冊頁,並希望包含一些程式碼片段。我目前正在使用**.RS和.RE宏作為定制.SAMPLE**宏的一部分,但由於某種原因這不起作用。這是手冊頁:
.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.
最終發生的是**.ESAMPLE之後的文本沒有像段落文本那樣縮進。相反,它與段落標籤對齊。什麼是正確的。$$ E $$SAMPLE宏定義讓它們與.TP**配合得很好?
恢復預設縮進級別,而
.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.