In general, DITA2Go macro expressions produce output. The exceptions are as follows:
To display (that is, to include in HTML output) the result of evaluating an expression, enclose the expression in parentheses, as follows:
<$(... expr ...)>
You can also specify a display format to use, with as plus a C-language-style format string:
<$(... expr ...) as format-string>
A format string starts with “%” (percent sign) and is composed as follows, where any component enclosed in [] is optional:
%[flag(s)][width][.precision]format-code
The components of the format string can have any of the values listed in Table 37-7.
Suppose you wish to display the integer value of user variable $$myint, which you have set to internal value 5:
<$$myint = 5>
When you use a format string to display the value, the default integer precision is 1, as you can determine by comparing the results of the following expressions:
<$$myint as %0d> <$$myint as %0.1d> <$$myint as %0.3d>
The first two yield identical results, 5, while the third yields 005. However, when you do not use the “as %” construct, there is no precision; you get the internal string representation, which has three digits, unless you initialized it otherwise.
For more information about C-language format strings and for additional components and format codes, see the following reference:
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.12.html#printf
You can use any C-language format codes except those for floating-point values (e, f, g) or for pointers (p). It is best not to use the h or l (lowercase L) modifiers; however, if you ignore this advice, l is at least harmless.
As an example, this macro generates an ASCII table:
[Charset] <$$cval = ' '> <$_while ($$cval < '~')>\ <p><$$cval = ($$cval + 1) as %0.3d> \ 0x<$$cval as %02X> \ <$$cval as %c></p>
In an expression, hexadecimal numbers beginning with 0x or 0X are understood as numeric values. But if you have a hexadecimal number stored in a variable, and try to display it like this:
<$$myvar as %d> (or “as %c”, or even “as %x”)
you get 0 (zero) as output—for any hexadecimal number. Use the default (“as %s”), or just plain <$$myvar>.