グローブ演算

グローブ演算

算術演算に groff を使用できますか?
私が現在どのページにいるのかを計算したいと思い、現在2ページにあるとしましょう。次を使用して、次のページのページ番号を取得できます。

.PP
Next page is number \n[.pn]

としてコンパイルされますNext page is number 3

レンダリングのために算術演算を実行するにはどうすればよいですか?

.PP
Current page is ((\n[.pn]-1))

入力するCurrent page is 2

ベストアンサー1

現在のページ番号はです\n%

算術式の結果を挿入するには、まず数値レジスタに入れる必要があると思います。

これは式を引数として取り、その結果を(おそらく未使用の)レジスタに割り当ててから、レジスタ__の内容を挿入するマクロ(完全にテストされていません)です。

Current page is \n%.
.br
.\" EI - eval and interpolate
.\" $1 is an expression to evaluate
.\" $2 (optional) is a string to append to the interpolated expression,
.\"    without any intervening whitespace
.de EI
.nr __ \\$1
\&\\n(__\\$2
..
.nr x 4
4 times 3 minus 5 is
'EI (\nx*3-5)
\&.
.br
Here there's no space before the period:
'EI (\nx*3-5) .
.br

nroffを実行した後:

Current page is 1.
4 times 3 minus 5 is 7 .
Here there's no space before the period: 7.

これは一般的なもののようで、標準マクロパッケージにはすでに似たようなマクロがあるかもしれませんが、それについてはよくわかりません。

おすすめ記事