#### 37.3.2 Assigning values to macro variables

You can initialize the value of a macro variable in your configuration file, and you can assign a value to a macro variable in the body of a macro definition:

Assign a starting value

Assign a value in a macro

Assign a character literal.

Assign a starting value

Assign starting values to macro variables in configuration section [MacroVariables]. Omit the leading $$ when you specify the name. For example:

    [MacroVariables]
    ; varname = value to use as literal replacement, can be in Macro Ini
    ; can also be set in any macro with <$$name=value>, settings persist
    ;  until the end of the file, but are not stored in the .ini file.
    HdgCount = 000
    HdgColor = blue

You can assign only literal values; you cannot assign a value that specifies a macro or another macro variable.

Place section [MacroVariables] in one (or more) of the following files, after any macro definitions:

- your project configuration file
- a configuration template
- a separate macro file or macro library file.

Assign a value in a macro

Use any of the following forms to assign values to variables inside DITA2Go macros:

    <$$varname = $$othername>
    <$$varname = (expr)>  (See §37.6  Using expressions in macros)
    <$$varname = "quoted string even with \"double quotes\" in it">
    <$$varname = 'quoted string using "single" quotes'>
    <$$varname = string with no quotes>
    <$$varname = 'x'>     (Character literal)

Assign a character literal

The value of a character literal assigned to a macro variable is the ASCII value of the character. A character literal can be a character enclosed in single quotes, or any of the special cases listed in Table 37-4.

Table 37-4 Character literals for macro variables

Character literal | Name | Decimal ASCII value
    '\r'
| return |
    13
    '\n'
| newline |
    10
    ''
| empty |
    0
    \'
| single quote |
    39
    \\
| backslash |
    92

Characters other than ' and \ that are preceded by a backslash are themselves. However, ' and \, without a backslash, are not themselves:

''' | would be an empty string followed by an out-of-place ', thus 0 (zero)
'\' | is invalid, and would probably become a string with a single quote, equivalent to "\'"

When a string between single quotes contains more than two characters (or more than one when the first character is not a backslash), you do not have to escape double quotes within the string, a common JavaScript and HTML technique.

Display an assignment

Assigning a value to a macro variable does not cause the value to appear in output. To display the value of an assignment, use as and a printf() format. For example, if the value of <$$myvar> is 0 (zero), the following expression displays the value 0001:

    <$$myvar = ($$myvar + 1) as %0.4d>

See §37.6.3 Displaying expression results in output.

Assign a value indirectly

You can assign a value to a variable indirectly:

    <$$myvar = "$$other">
    <*$$myvar = 10>

This sequence results in assigning the value 10 to $$other rather than to $$myvar. See §37.6.7 Using indirection in expressions.

Nest macro variables

You can nest macro variables:

    [Macros]
    ; MacroVarNesting = Yes (default, vars contain <>)
    ;  or No (first > ends var)
    MacroVarNesting=Yes

This setting is provided solely to support old syntax in assignments. You used to use:

    <$$myvar=<$$othervar>>

to get what is now simply:

    <$$myvar = $$othervar>

You need MacroVarNesting=Yes only if your macro variable assignments use the old syntax; the new syntax is always valid. Either way, you get the contents of the referenced right-hand variable, rather than its name.

Note: Macro variables cannot contain macros.

See also:

§37.4.2 Assigning a value to a list-variable item

§42.2.4 Assigning values to configuration variables

Previous Topic: 37.3.1.3 Invoking a macro variable

Next Topic: 37.3.3 Incrementing and decrementing macro variables

Parent Topic: 37.3 Using macro variables

Sibling Topics:

37.3.1 Creating and invoking macro variables

37.3.3 Incrementing and decrementing macro variables

37.3.4 Using predefined macro variables

37.3.5 Creating macro variables from paragraph content

Table of Contents • Index