##### 37.3.1.3 Invoking a macro variable

You invoke a macro variable like this:

    <$$varname>

Or like this:

    <$$varname as display-format>

where display-format is a C-language style printf() format. See §37.6.3 Displaying expression results in output.

You do not need the enclosing angle brackets when you use a macro variable inside a macro; for example, in an assignment such as <$$myvar = ($$othervar + 2)>.

An example

Suppose you want to use a macro that includes the following:

- an image, but with a different src attribute each time
- a heading, but with different text each time.

Rather than have two almost identical macros, you can use a macro variable for the src attribute and another for the heading, then set their values appropriately for each use.

You could define the macro like this:

    [TopStory]
    <img src="<$$Pic>" alt="Today’s top story" /><h2><$$Head></h2>

Call it like this one day:

    <$$Pic=lead000201.jpg><$$Head=No Survivors in Crash><$TopStory>

and like this the next day:

    <$$Pic=lead000202.jpg><$$Head=MS Embraces Linux><$TopStory>

Previous Topic: 37.3.1.2 Creating a macro variable

Next Topic: 37.3.2 Assigning values to macro variables

Parent Topic: 37.3.1 Creating and invoking macro variables

Sibling Topics:

37.3.1.1 Naming macro variables

37.3.1.2 Creating a macro variable