28.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 starting values to macro variables in configuration section [MacroVariables]. Omit the leading $$ when you specify the name. For example:
; 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.
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 separate macro file or macro library file.
Use any of the following forms to assign values to variables inside Mif2Go macros:
<$$varname = (expr)> (See §28.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)
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 28-2.
Table 28-2 Character literals for macro variables
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.
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 §28.6.3 Displaying expression results in output.
You can assign a value to a variable indirectly:
This sequence results in assigning the value 10 to $$other rather than to $$myvar. See §28.6.7 Using indirection in expressions.
; MacroVarNesting = Yes (default, vars contain <>)
This setting is provided solely to support old syntax in assignments. You used to use:
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.
§28.4.2 Assigning a value to a list-variable item
§33.2.4 Assigning values to configuration variables
> 28 Working with macros > 28.3 Using macro variables > 28.3.2 Assigning values to macro variables