1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.0.3, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- This manual documents GNU troff version 1.23.0.
Copyright 1994-2023 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
copy of the license is included in the section entitled "GNU Free
Documentation License". -->
<title>Setting Registers (The GNU Troff Manual)</title>
<meta name="description" content="Setting Registers (The GNU Troff Manual)">
<meta name="keywords" content="Setting Registers (The GNU Troff Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Request-Index.html" rel="index" title="Request Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Registers.html" rel="up" title="Registers">
<link href="Interpolating-Registers.html" rel="next" title="Interpolating Registers">
<link href="Registers.html" rel="prev" title="Registers">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span.r {font-family: initial; font-weight: normal; font-style: normal}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
</head>
<body lang="en">
<div class="subsection-level-extent" id="Setting-Registers">
<div class="nav-panel">
<p>
Next: <a href="Interpolating-Registers.html" accesskey="n" rel="next">Interpolating Registers</a>, Previous: <a href="Registers.html" accesskey="p" rel="prev">Registers</a>, Up: <a href="Registers.html" accesskey="u" rel="up">Registers</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Request-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Setting-Registers-1">5.8.1 Setting Registers</h4>
<a class="index-entry-id" id="index-setting-registers-_0028nr_002c-_005cR_0029"></a>
<a class="index-entry-id" id="index-registers_002c-setting-_0028nr_002c-_005cR_0029"></a>
<p>Define registers and update their values with the <code class="code">nr</code> request or
the <code class="code">\R</code> escape sequence.
</p>
<dl class="first-deffn">
<dt class="deffn" id="index-_002enr-1"><span class="category-def">Request: </span><span><strong class="def-name"><code class="t">.nr</code></strong> <var class="def-var-arguments">ident value</var><a class="copiable-link" href='#index-_002enr-1'> ¶</a></span></dt>
<dd><a class="index-entry-id" id="index-nr-1"></a>
</dd><dt class="deffnx def-cmd-deffn" id="index-_005cR_0027ident-value_0027"><span class="category-def">Escape sequence: </span><span><strong class="def-name"><code class="t">\R<code class="code">'</code></code><span class="r"><i class="slanted">ident value</i></span><code class="t"><code class="code">'</code></code></strong><a class="copiable-link" href='#index-_005cR_0027ident-value_0027'> ¶</a></span></dt>
<dd><a class="index-entry-id" id="index-_005cR"></a>
<p>Set register <var class="var">ident</var> to <var class="var">value</var>. If <var class="var">ident</var> doesn’t exist,
GNU <code class="code">troff</code> creates it. In the <code class="code">\R</code> escape sequence, the
delimiter need not be a neutral apostrophe; see <a class="ref" href="Delimiters.html">Delimiters</a>. It
also does not produce an input token in GNU <code class="code">troff</code>. See <a class="xref" href="Gtroff-Internals.html"><code class="code">gtroff</code> Internals</a>.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">.nr a (((17 + (3 * 4))) % 4)
\n[a]
.\R'a (((17 + (3 * 4))) % 4)'
\n[a]
⇒ 1 1
</pre></div></div>
<p>(Later, we will discuss additional forms of <code class="code">nr</code> and <code class="code">\R</code> that
can change a register’s value after it is dereferenced but before it is
interpolated. See <a class="xref" href="Auto_002dincrement.html">Auto-increment</a>.)
</p>
<p>The complete transparency of <code class="code">\R</code> can cause surprising effects if
you use registers like <code class="code">.k</code>, which get evaluated at the time they
are accessed.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">.ll 1.6i
.
aaa bbb ccc ddd eee fff ggg hhh\R':k \n[.k]'
.tm :k == \n[:k]
⇒ :k == 126950
.
.br
.
aaa bbb ccc ddd eee fff ggg hhh\h'0'\R':k \n[.k]'
.tm :k == \n[:k]
⇒ :k == 15000
</pre></div></div>
<p>If you process this with the PostScript device (<code class="code">-Tps</code>), there will
be a line break eventually after <code class="code">ggg</code> in both input lines.
However, after processing the space after <code class="code">ggg</code>, the partially
collected line is not overfull yet, so GNU <code class="code">troff</code> continues to
collect input until it sees the space (or in this case, the newline)
after <code class="code">hhh</code>. At this point, the line is longer than the line
length, and the line gets broken.
</p>
<p>In the first input line, since the <code class="code">\R</code> escape sequence leaves no
traces, the check for the overfull line hasn’t been done yet at the
point where <code class="code">\R</code> gets handled, and you get a value for the
<code class="code">.k</code> register that is even greater than the current line length.
</p>
<p>In the second input line, the insertion of <code class="code">\h'0'</code> to cause a
zero-width motion forces GNU <code class="code">troff</code> to check the line length,
which in turn causes the start of a new output line. Now <code class="code">.k</code>
returns the expected value.
</p></dd></dl>
<p><code class="code">nr</code> and <code class="code">\R</code> each have two additional special forms to
increment or decrement a register.
</p>
<dl class="first-deffn">
<dt class="deffn" id="index-_002enr-2"><span class="category-def">Request: </span><span><strong class="def-name"><code class="t">.nr</code></strong> <var class="def-var-arguments">ident <code class="t">+</code><span class="r"><i class="slanted">value</i></span></var><a class="copiable-link" href='#index-_002enr-2'> ¶</a></span></dt>
<dd><a class="index-entry-id" id="index-nr-2"></a>
</dd><dt class="deffnx def-cmd-deffn" id="index-_002enr-3"><span class="category-def">Request: </span><span><strong class="def-name"><code class="t">.nr</code></strong> <var class="def-var-arguments">ident <code class="t">-</code><span class="r"><i class="slanted">value</i></span></var><a class="copiable-link" href='#index-_002enr-3'> ¶</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-_005cR_0027ident-_002bvalue_0027"><span class="category-def">Escape sequence: </span><span><strong class="def-name"><code class="t">\R<code class="code">'</code></code><span class="r"><i class="slanted">ident <code class="t">+</code>value</i></span><code class="t"><code class="code">'</code></code></strong><a class="copiable-link" href='#index-_005cR_0027ident-_002bvalue_0027'> ¶</a></span></dt>
<dd><a class="index-entry-id" id="index-_005cR-1"></a>
</dd><dt class="deffnx def-cmd-deffn" id="index-_005cR_0027ident-_002dvalue_0027"><span class="category-def">Escape sequence: </span><span><strong class="def-name"><code class="t">\R<code class="code">'</code></code><span class="r"><i class="slanted">ident <code class="t">-</code>value</i></span><code class="t"><code class="code">'</code></code></strong><a class="copiable-link" href='#index-_005cR_0027ident-_002dvalue_0027'> ¶</a></span></dt>
<dd><p>Increment (decrement) register <var class="var">ident</var> by <var class="var">value</var>. In the
<code class="code">\R</code> escape sequence, the delimiter need not be a neutral
apostrophe; see <a class="ref" href="Delimiters.html">Delimiters</a>.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">.nr a 1
.nr a +1
\na
⇒ 2
</pre></div></div>
<a class="index-entry-id" id="index-negating-register-values"></a>
<p>A leading minus sign in <var class="var">value</var> is always interpreted as a
decrementation operator, not an algebraic sign. To assign a register a
negative value or the negated value of another register, you can
force GNU <code class="code">troff</code> to interpret ‘<samp class="samp">-</samp>’ as a negation or minus,
rather than decrementation, operator: enclose it with its operand in
parentheses or subtract it from zero.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">.nr a 7
.nr b 3
.nr a -\nb
\na
⇒ 4
.nr a (-\nb)
\na
⇒ -3
.nr a 0-\nb
\na
⇒ -3
</pre></div></div>
<p>If a register’s prior value does not exist (the register was undefined),
an increment or decrement is applied as if to 0.
</p></dd></dl>
<dl class="first-deffn">
<dt class="deffn" id="index-_002err"><span class="category-def">Request: </span><span><strong class="def-name"><code class="t">.rr</code></strong> <var class="def-var-arguments">ident</var><a class="copiable-link" href='#index-_002err'> ¶</a></span></dt>
<dd><a class="index-entry-id" id="index-rr"></a>
<a class="index-entry-id" id="index-removing-a-register-_0028rr_0029"></a>
<a class="index-entry-id" id="index-register_002c-removing-_0028rr_0029"></a>
<p>Remove register <var class="var">ident</var>. If <var class="var">ident</var> doesn’t exist, the request
is ignored. Technically, only the name is removed; the register’s
contents are still accessible under aliases created with <code class="code">aln</code>, if
any.
</p></dd></dl>
<dl class="first-deffn">
<dt class="deffn" id="index-_002ernn"><span class="category-def">Request: </span><span><strong class="def-name"><code class="t">.rnn</code></strong> <var class="def-var-arguments">ident1 ident2</var><a class="copiable-link" href='#index-_002ernn'> ¶</a></span></dt>
<dd><a class="index-entry-id" id="index-rnn"></a>
<a class="index-entry-id" id="index-renaming-a-register-_0028rnn_0029"></a>
<a class="index-entry-id" id="index-register_002c-renaming-_0028rnn_0029"></a>
<p>Rename register <var class="var">ident1</var> to <var class="var">ident2</var>. If <var class="var">ident1</var> doesn’t
exist, the request is ignored. Renaming a built-in register does not
otherwise alter its properties.
</p></dd></dl>
<dl class="first-deffn">
<dt class="deffn" id="index-_002ealn"><span class="category-def">Request: </span><span><strong class="def-name"><code class="t">.aln</code></strong> <var class="def-var-arguments">new old</var><a class="copiable-link" href='#index-_002ealn'> ¶</a></span></dt>
<dd><a class="index-entry-id" id="index-aln"></a>
<a class="index-entry-id" id="index-alias_002c-register_002c-creating-_0028aln_0029"></a>
<a class="index-entry-id" id="index-creating-alias-for-register-_0028aln_0029"></a>
<a class="index-entry-id" id="index-register_002c-creating-alias-for-_0028aln_0029"></a>
<p>Create an alias <var class="var">new</var> for an existing register <var class="var">old</var>, causing
the names to refer to the same stored object. If <var class="var">old</var> is
undefined, a warning in category ‘<samp class="samp">reg</samp>’ is produced and the request
is ignored. See <a class="xref" href="Warnings.html">Warnings</a>, for information about the enablement and
suppression of warnings.
</p>
<a class="index-entry-id" id="index-alias_002c-register_002c-removing-_0028rr_0029"></a>
<a class="index-entry-id" id="index-removing-alias-for-register-_0028rr_0029"></a>
<a class="index-entry-id" id="index-register_002c-removing-alias-for-_0028rr_0029"></a>
<p>To remove a register alias, invoke <code class="code">rr</code> on its name. A register’s
contents do not become inaccessible until it has no more names.
</p></dd></dl>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Interpolating-Registers.html">Interpolating Registers</a>, Previous: <a href="Registers.html">Registers</a>, Up: <a href="Registers.html">Registers</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Request-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|