summaryrefslogtreecommitdiffstats
path: root/doc/groff.html.node/Punning-Names.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/groff.html.node/Punning-Names.html')
-rw-r--r--doc/groff.html.node/Punning-Names.html190
1 files changed, 190 insertions, 0 deletions
diff --git a/doc/groff.html.node/Punning-Names.html b/doc/groff.html.node/Punning-Names.html
new file mode 100644
index 0000000..dde1a20
--- /dev/null
+++ b/doc/groff.html.node/Punning-Names.html
@@ -0,0 +1,190 @@
+<!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>Punning Names (The GNU Troff Manual)</title>
+
+<meta name="description" content="Punning Names (The GNU Troff Manual)">
+<meta name="keywords" content="Punning Names (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="GNU-troff-Reference.html" rel="up" title="GNU troff Reference">
+<link href="Environments.html" rel="next" title="Environments">
+<link href="Diversions.html" rel="prev" title="Diversions">
+<style type="text/css">
+<!--
+div.example {margin-left: 3.2em}
+kbd.key {font-style: normal}
+-->
+</style>
+
+
+</head>
+
+<body lang="en">
+<div class="section-level-extent" id="Punning-Names">
+<div class="nav-panel">
+<p>
+Next: <a href="Environments.html" accesskey="n" rel="next">Environments</a>, Previous: <a href="Diversions.html" accesskey="p" rel="prev">Diversions</a>, Up: <a href="GNU-troff-Reference.html" accesskey="u" rel="up">GNU <code class="code">troff</code> Reference</a> &nbsp; [<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>
+<h3 class="section" id="Punning-Names-1">5.30 Punning Names</h3>
+<a class="index-entry-id" id="index-diversions-1"></a>
+
+<p>Macros, strings, and diversions share a name space; recall
+<a class="ref" href="Identifiers.html">Identifiers</a>. Internally, the same mechanism is used to store
+them. You can thus call a macro with string interpolation syntax and
+vice versa.
+</p>
+<div class="example">
+<div class="group"><pre class="example-preformatted">.de subject
+Typesetting
+..
+.de predicate
+rewards attention to detail
+..
+\*[subject] \*[predicate].
+Truly.
+ &rArr; Typesetting
+ &rArr; rewards attention to detail Truly.
+</pre></div></div>
+
+<p>What went wrong? Strings don&rsquo;t contain newlines, but macros do. String
+interpolation placed a newline at the end of &lsquo;<samp class="samp">\*[subject]</samp>&rsquo;, and the
+next thing on the input was a space. Then when &lsquo;<samp class="samp">\*[predicate]</samp>&rsquo; was
+interpolated, it was followed by the empty request &lsquo;<samp class="samp">.</samp>&rsquo; on a line by
+itself. If we want to use macros as strings, we must take interpolation
+behavior into account.
+</p>
+<div class="example">
+<div class="group"><pre class="example-preformatted">.de subject
+Typesetting\\
+..
+.de predicate
+rewards attention to detail\\
+..
+\*[subject] \*[predicate].
+Truly.
+ &rArr; Typesetting rewards attention to detail. Truly.
+</pre></div></div>
+
+<p>By ending each text line of the macros with an escaped
+<code class="code">\<kbd class="key">RET</kbd></code>, we get the desired effect (see <a class="pxref" href="Line-Continuation.html">Line Continuation</a>).<a class="footnote" id="DOCF114" href="groff.html_fot.html#FOOT114"><sup>114</sup></a>
+What would have happened if we had used only one backslash at a time
+instead?
+</p>
+<p>Interpolating a string does not hide existing macro arguments. We can
+also place the escaped newline outside the string interpolation instead
+of within the string definition. Thus, in a macro, a more efficient way
+of doing
+</p>
+<div class="example">
+<div class="group"><pre class="example-preformatted">.xx \\$@
+</pre></div></div>
+
+<p>is
+</p>
+<div class="example">
+<div class="group"><pre class="example-preformatted">\\*[xx]\\
+</pre></div></div>
+
+<p>The latter calling syntax doesn&rsquo;t change the value of <code class="code">\$0</code>, which
+is then inherited from the calling macro (see <a class="pxref" href="Parameters.html">Parameters</a>).
+</p>
+<p>Diversions can be also called with string syntax. It is sometimes
+convenient to copy one-line diversions to a string.
+</p>
+<div class="example">
+<div class="group"><pre class="example-preformatted">.di xx
+the
+.ft I
+interpolation system
+.ft
+.br
+.di
+.ds yy This is a test of \*(xx\c
+\*(yy.
+ &rArr; This is a test of the <i class="i">interpolation system</i>.
+</pre></div></div>
+
+<p>As the previous example shows, it is possible to store formatted output
+in strings. The <code class="code">\c</code> escape sequence prevents the subsequent
+newline from being interpreted as a break (again,
+see <a class="pxref" href="Line-Continuation.html">Line Continuation</a>).
+</p>
+<p>Copying multi-output line diversions produces unexpected results.
+</p>
+<div class="example">
+<div class="group"><pre class="example-preformatted">.di xxx
+a funny
+.br
+test
+.br
+.di
+.ds yyy This is \*[xxx]\c
+\*[yyy].
+ &rArr; test This is a funny.
+</pre></div></div>
+
+<p>Usually, it is not predictable whether a diversion contains one or more
+output lines, so this mechanism should be avoided. With <abbr class="acronym">AT&amp;T</abbr>
+<code class="code">troff</code>, this was the only solution to strip off a final newline
+from a diversion. Another disadvantage is that the spaces in the copied
+string are already formatted, preventing their adjustment. This can
+cause ugly results.
+</p>
+<a class="index-entry-id" id="index-stripping-final-newline-in-diversions"></a>
+<a class="index-entry-id" id="index-diversion_002c-stripping-final-newline"></a>
+<a class="index-entry-id" id="index-final-newline_002c-stripping-in-diversions"></a>
+<a class="index-entry-id" id="index-newline_002c-final_002c-stripping-in-diversions"></a>
+<a class="index-entry-id" id="index-horizontal-space_002c-unformatting"></a>
+<a class="index-entry-id" id="index-space_002c-horizontal_002c-unformatting"></a>
+<a class="index-entry-id" id="index-unformatting-horizontal-space"></a>
+<p>A clean solution to this problem is available in GNU <code class="code">troff</code>, using
+the requests <code class="code">chop</code> to remove the final newline of a diversion, and
+<code class="code">unformat</code> to make the horizontal spaces adjustable again.
+</p>
+<div class="example">
+<div class="group"><pre class="example-preformatted">.box xxx
+a funny
+.br
+test
+.br
+.box
+.chop xxx
+.unformat xxx
+This is \*[xxx].
+ &rArr; This is a funny test.
+</pre></div></div>
+
+<p>See <a class="xref" href="Gtroff-Internals.html"><code class="code">gtroff</code> Internals</a>.
+</p>
+
+</div>
+<hr>
+<div class="nav-panel">
+<p>
+Next: <a href="Environments.html">Environments</a>, Previous: <a href="Diversions.html">Diversions</a>, Up: <a href="GNU-troff-Reference.html">GNU <code class="code">troff</code> Reference</a> &nbsp; [<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>