| <!DOCTYPE html> |
| <html> |
| <!-- Created by Texinfo 6.8dev+dev, http://www.gnu.org/software/texinfo/ --> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| <!-- This manual is for GNU Texinfo (version 6.8dev, 23 February 2022), |
| a documentation system that can produce both online information and a |
| printed manual from a single source using semantic markup. |
| |
| Copyright (C) 1988, 1990-1993, 1995-1999, 2001-2022 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, with no Front-Cover Texts, and with no Back-Cover |
| Texts. A copy of the license is included in the section entitled |
| "GNU Free Documentation License". --> |
| <title>Invoking Macros (GNU Texinfo 6.8dev)</title> |
| |
| <meta name="description" content="Invoking Macros (GNU Texinfo 6.8dev)"> |
| <meta name="keywords" content="Invoking Macros (GNU Texinfo 6.8dev)"> |
| <meta name="resource-type" content="document"> |
| <meta name="distribution" content="global"> |
| <meta name="Generator" content="texi2any"> |
| <meta name="viewport" content="width=device-width,initial-scale=1"> |
| |
| <link href="index.html" rel="start" title="Top"> |
| <link href="Command-and-Variable-Index.html" rel="index" title="Command and Variable Index"> |
| <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| <link href="Defining-New-Texinfo-Commands.html" rel="up" title="Defining New Texinfo Commands"> |
| <link href="Macro-Details.html" rel="next" title="Macro Details"> |
| <link href="Defining-Macros.html" rel="prev" title="Defining Macros"> |
| <style type="text/css"> |
| <!-- |
| div.display {margin-left: 3.2em} |
| div.example {margin-left: 3.2em} |
| pre.display-preformatted {font-family: inherit} |
| --> |
| </style> |
| |
| |
| </head> |
| |
| <body lang="en"> |
| <div class="section-level-extent" id="Invoking-Macros"> |
| <div class="nav-panel"> |
| <p> |
| Next: <a href="Macro-Details.html" accesskey="n" rel="next">Macro Details and Caveats</a>, Previous: <a href="Defining-Macros.html" accesskey="p" rel="prev">Defining Macros</a>, Up: <a href="Defining-New-Texinfo-Commands.html" accesskey="u" rel="up">Defining New Texinfo Commands</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Command-and-Variable-Index.html" title="Index" rel="index">Index</a>]</p> |
| </div> |
| <hr> |
| <h3 class="section" id="Invoking-Macros-1">16.2 Invoking Macros</h3> |
| |
| <a class="index-entry-id" id="index-Invoking-macros"></a> |
| <a class="index-entry-id" id="index-Expanding-macros"></a> |
| <a class="index-entry-id" id="index-Running-macros"></a> |
| <a class="index-entry-id" id="index-Macro-invocation"></a> |
| |
| <p>After a macro is defined (see the previous section), you can |
| <em class="dfn">invoke</em> (use) it in your document like this: |
| </p> |
| <div class="example"> |
| <pre class="example-preformatted">@<var class="var">macroname</var> {<var class="var">arg1</var>, <var class="var">arg2</var>, …} |
| </pre></div> |
| |
| <p>and the result will be more or less as if you typed the body of |
| <var class="var">macroname</var> at that spot. For example: |
| </p> |
| <div class="example"> |
| <pre class="example-preformatted">@macro foo {p, q} |
| Together: \p\ & \q\. |
| @end macro |
| @foo{a, b} |
| </pre></div> |
| |
| <p>produces: |
| </p> |
| <div class="display"> |
| <pre class="display-preformatted">Together: a & b. |
| </pre></div> |
| |
| <a class="index-entry-id" id="index-Backslash_002c-and-macros"></a> |
| <p>Thus, the arguments and parameters are separated by commas and |
| delimited by braces; any whitespace after (but not before) a comma is |
| ignored. The braces are required in the invocation even when the |
| macro takes no arguments, consistent with other Texinfo commands. For |
| example: |
| </p> |
| <div class="example"> |
| <pre class="example-preformatted">@macro argless {} |
| No arguments here. |
| @end macro |
| @argless{} |
| </pre></div> |
| |
| <p>produces: |
| </p> |
| <div class="display"> |
| <pre class="display-preformatted">No arguments here. |
| </pre></div> |
| |
| <a class="index-entry-id" id="index-Comma_002c-in-macro-arguments"></a> |
| <p>Passing macro arguments containing commas requires care, since |
| commas also separate the arguments. To include a comma character in |
| an argument, the most reliable method is to use the <code class="code">@comma{}</code> |
| command. For <code class="code">makeinfo</code>, you can also prepend a backslash |
| character, as in ‘<samp class="samp">\,</samp>’, but this does not work with TeX. |
| </p> |
| <a class="index-entry-id" id="index-Automatic-quoting-of-commas-for-some-macros"></a> |
| <a class="index-entry-id" id="index-Quoting_002c-automatic-for-some-macros"></a> |
| <p>It’s not always necessary to worry about commas. To facilitate use of |
| macros, <code class="command">makeinfo</code> implements two rules for <em class="dfn">automatic |
| quoting</em> in some circumstances: |
| </p> |
| <ol class="enumerate"> |
| <li> If a macro takes only one argument, all commas in its invocation |
| are quoted by default. For example: |
| |
| <div class="example"> |
| <div class="group"><pre class="example-preformatted">@macro TRYME{text} |
| @strong{TRYME: \text\} |
| @end macro |
| |
| @TRYME{A nice feature, though it can be dangerous.} |
| </pre></div></div> |
| |
| <p>will produce the following output |
| </p> |
| <div class="example"> |
| <pre class="example-preformatted"><strong class="strong">TRYME: A nice feature, though it can be dangerous.</strong> |
| </pre></div> |
| |
| <p>And indeed, it can. Namely, <code class="command">makeinfo</code> does not control the |
| number of arguments passed to one-argument macros, so be careful when |
| you invoke them. |
| </p> |
| </li><li> If a macro invocation includes another command (including a |
| recursive invocation of itself), any commas in the nested command |
| invocation(s) are quoted by default. For example, in |
| |
| <div class="example"> |
| <pre class="example-preformatted">@say{@strong{Yes, I do}, person one} |
| </pre></div> |
| |
| <p>the comma after ‘<samp class="samp">Yes</samp>’ is implicitly quoted. Here’s another |
| example, with a recursive macro: |
| </p> |
| <div class="example"> |
| <div class="group"><pre class="example-preformatted">@rmacro cat{a,b} |
| \a\\b\ |
| @end rmacro |
| |
| @cat{@cat{foo, bar}, baz} |
| </pre></div></div> |
| |
| <p>will produce the string ‘<samp class="samp">foobarbaz</samp>’. |
| </p> |
| </li><li> Otherwise, a comma should be explicitly quoted, as above, for it |
| to be treated as a part of an argument. |
| </li></ol> |
| |
| <a class="index-entry-id" id="index-Backslash_002c-in-macro-arguments"></a> |
| <a class="index-entry-id" id="index-Braces_002c-in-macro-arguments"></a> |
| <p>The backslash itself can be quoted in macro arguments with another |
| backslash. For example: |
| </p> |
| <div class="example"> |
| <pre class="example-preformatted">@<var class="var">macname</var> {\\bleh} |
| </pre></div> |
| |
| <p>will pass the argument ‘<samp class="samp">\bleh</samp>’ to <var class="var">macname</var>. |
| </p> |
| <p><code class="command">makeinfo</code> also recognizes ‘<samp class="samp">\{</samp>’ and ‘<samp class="samp">\}</samp>’ sequences |
| for curly braces, but these are not recognized by the implementation in |
| TeX. There should, however, rarely be a need for these, as they are |
| only needed when a macro argument contains unbalanced braces. |
| </p> |
| <p>If a macro is defined to take exactly one argument, it can be |
| invoked without any braces, taking all of the line after the macro name |
| as the argument. For example: |
| </p> |
| <div class="example"> |
| <pre class="example-preformatted">@macro bar {p} |
| Twice: \p\ & \p\. |
| @end macro |
| @bar aah |
| </pre></div> |
| |
| <p>produces: |
| </p> |
| <div class="display"> |
| <pre class="display-preformatted">Twice: aah & aah. |
| </pre></div> |
| |
| <p>In these arguments, there is no escaping of special characters, so each |
| ‘<samp class="samp">\</samp>’ stands for itself. |
| </p> |
| <p>If a macro is defined to take more than one argument, but is called |
| with only one (in braces), the remaining arguments are set to the |
| empty string, and no error is given. For example: |
| </p> |
| <div class="example"> |
| <pre class="example-preformatted">@macro addtwo {p, q} |
| Both: \p\\q\. |
| @end macro |
| @addtwo{a} |
| </pre></div> |
| |
| <p>produces simply: |
| </p> |
| <div class="display"> |
| <pre class="display-preformatted">Both: a. |
| </pre></div> |
| |
| |
| </div> |
| <hr> |
| <div class="nav-panel"> |
| <p> |
| Next: <a href="Macro-Details.html">Macro Details and Caveats</a>, Previous: <a href="Defining-Macros.html">Defining Macros</a>, Up: <a href="Defining-New-Texinfo-Commands.html">Defining New Texinfo Commands</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Command-and-Variable-Index.html" title="Index" rel="index">Index</a>]</p> |
| </div> |
| |
| |
| |
| </body> |
| </html> |