Formatting Guidelines

Formatting general output, numeric output, character and string output, and matrices.


Templex writes text to the specified output stream exactly as it appears in the template.

For example:
What is X + 2?
The answer is: {X + 2}
appears as:
What is X + 2?
The answer is: 5

Templex uses standard C format descriptors to format numeric and string output. Format descriptors reserve a specific amount of space in the output text for the value. If more space is reserved than the value requires, the output text is padded with spaces. Numerical values are right justified. String values are left justified.

If no format is specified, each data type uses the default format associated with each variable type or the default template format and the output is not padded. A default template format is created using the Templex format statement.

Format descriptors are placed at the end of an expression. They are separated from the expression by a comma and preceded by a percent sign, %. The following examples illustrate the syntax:
{sqrt(100), %5d}
{cos(t) + sin(3.1415/phi), %12.5f}

Of the twelve spaces in the second example, five spaces are used to display the values to the right of the decimal point. One space is reserved for the decimal point. The six remaining spaces appear to the left of the decimal point as a blank and a zero.

Extra space does not need to be reserved for the leading plus/minus sign. Some operating systems display a blank instead of a plus sign.

Numeric Output

Integer and real values can be displayed in six output formats: integeroctal, hexadecimal, floating point, scientific notation, and value dependent. Descriptors for these formats and examples of their use are given in the following table.
Data Format Descriptor Example Output
Integer d or i
  • {sqrt(10000), %5d}
  • {sin(PI/4), %5i}
  • ••100
  • ••••0
Octal o {100, %4o} •144
Hexadecimal x or X {100, %4X} ••64
Floating point f {sin(PI/4), %6.3f} •0.707
Scientific notation e or E
  • {sin(PI/4), %10.3e}
  • {sin(PI/4), %10.3E}
  • +0.707e+00
  • +0.707E+00
Value-dependent g or G
  • {sin(PI/4), %10.3g}
  • {100, %7.3f}
  • •••••0.707
  • 100.000
Note: The • in the output column indicates blank spaces which are used to pad the output if the reserved space is not completely used. The • does not appear in your output.
The g and G descriptors automatically determine whether a fixed decimal or exponential notation format should be used, depending on the magnitude of the result. If the magnitude of the value is large, the G descriptor uses a capital E in the exponent, depending on your operating system’s defaults.

Character and String Output

Character and string values can be displayed in two output formats, as single characters or as strings. Descriptors for these formats and examples of their use are given in the following table:
Data Format Descriptor Example Output
single character c {65, %c} A
character string s {"This is a string", %.12s} This is a st
Templex now supports foreign characters with a new registry key, templex.hichar. Setting the registry key to 0 ignores foreign characters while setting the registry key to 1 supports them. You must restart Templex to see the change as it only checks this registry key at start up.


Matrices can be displayed in three output formats: as a comma-separated list, as a list of elements inside braces, and as rows and columns of numbers. The parameters for these three formats and examples of each are given in the following table:
Data Format Descriptor Example Output
comma-separated lists list
{format, %i, list}
{square1 =
{ {1.3, 2.9},
   {3.1, 4.2} } }
{1, 2},
{3, 4}
elements inside of braces array
{format, %i, array}
{square1 =
{ {1.3, 2.9},
{3.1, 4.2} } }
{ {1, 2}, {3, 4} }
rows and columns matrix
{format, %3.1f, matrix}
{square1 =
{ {1.3, 2.9},
{3.1, 4.2} } }
| 1.3 2.9 |
|         |
| 3.1 4.2 |