1
@c This file is included in makeinfo.texi.
4
@comment Here are some useful examples of the macro facility.
6
@c Simply insert the right version of the texinfo name.
16
@c Define a macro which expands to a pretty version of the name of the
22
@c Define a macro which is used to define other macros. This one makes
23
@c a macro which creates a node and gives it a sectioning command. Note
24
@c that the created macro uses the original definition within the
25
@c expansion text. This takes advantage of the non-recursion feature of
27
@macro node_define{orig-name}
28
@macro \orig-name\{title}
34
@c Now actually define a new set of sectioning commands.
35
@node_define {chapter}
36
@node_define {section}
37
@node_define {subsection}
40
@chapter The Macro Facility
42
This chapter describes the new macro facility.
44
A @dfn{macro} is a command that you define in terms of other commands.
45
It doesn't exist as a @texinfo{} command until you define it as part of
46
the input file to @makeinfo{}. Once the command exists, it behaves much
47
as any other @texinfo{} command. Macros are a useful way to ease the
48
details and tedium of writing a `correct' info file. The following
49
sections explain how to write and invoke macros.
52
* How to Use Macros in @texinfo{}::
53
How to use the macro facility.
55
* Using Macros Recursively::
56
How to write a macro which does (or doesn't) recurse.
58
* Using @texinfo{} Macros As Arguments::
59
Passing a macro as an argument.
62
@section How to Use Macros in @texinfo{}
64
Using macros in @texinfo{} is easy. First you define the macro. After
65
that, the macro command is available as a normal @texinfo{} command.
66
Here is what a definition looks like:
69
@@macro @var{name}@{@var{arg1}, @var{@dots{}} @var{argn}@}
70
@var{@texinfo{} commands@dots{}}
74
The arguments that you specify that the macro takes are expanded with
75
the actual parameters used when calling the macro if they are seen
76
surrounded by backslashes. For example, here is a definition of
77
@code{@@codeitem}, a macro which can be used wherever @code{@@item} can
78
be used, but which surrounds its argument with @code{@@code@{@dots{}@}}.
81
@@macro codeitem@{item@}
82
@@item @@code@{\item\@}
86
When the macro is expanded, all of the text between the @code{@@macro}
87
and @code{@@end macro} is inserted into the document at the expansion
88
point, with the actual parameters substituted for the named parameters.
89
So, a call to the above macro might look like:
95
and @makeinfo{} would execute the following code:
101
A special case is made for macros which only take a single argument, and
102
which are invoked without any brace characters (i.e.,
103
@samp{@{}@dots{}@samp{@}}) surrounding an argument; the rest of the line
104
is supplied as is as the sole argument to the macro. This special case
105
allows one to redefine some standard @texinfo{} commands without
106
modifying the input file. Along with the non-recursive action of macro
107
invocation, one can easily redefine the sectioning commands to also
108
provide index entries:
111
@@macro chapter@{name@}
130
@section Using Macros Recursively
132
Normally, while a particular macro is executing, any call to that macro
133
will be seen as a call to a builtin @texinfo{} command. This allows one
134
to redefine a builtin @texinfo{} command as a macro, and then use that
135
command within the definition of the macro itself. For example, one
136
might wish to make sure that whereever a term was defined with
137
@code{@@dfn@{@dots{}@}}, the location of the definition would appear
138
in the concept index for the manual. Here is a macro which redefines
139
@code{@@dfn} to do just that:
148
Note that we used the builtin @texinfo{} command @code{@@dfn} within our
149
overriding macro definition.
151
This behaviour itself can be overridden for macro execution by writing a
152
special @dfn{macro control command} in the definition of the macro. The
153
command is considered special because it doesn't affect the output text
154
directly, rather, it affects the way in which the macro is defined. One
155
such special command is @code{@@allow-recursion}.
164
Now @code{@@silly} is a macro that can be used within a call to itself:
167
This text @@silly@{@@silly@{some text@}@} is ``some text''.
170
@section Using @texinfo{} Macros As Arguments
173
How to use @texinfo{} macros as arguments to other @texinfo{} macros.