マニュアルページにコード例を正しく挿入してください。

マニュアルページにコード例を正しく挿入してください。

私はソフトウェアのマニュアルページを書こうとしていますが、いくつかのコードスニペットを含めたいと思います。私は現在使用しています.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。以下の修正は、sSAMPLE内にsを入れ子にしないと仮定しています。SAMPLE

.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.

おすすめ記事