Macros in style sheets help you avoid repeating the same piece of code over and over again. Parameters allow you to use the same code, but with certain specified values for each time you use it.

For example, one CartoType client used macros wth parameters to display traffic density for all permutations of density and road type by means of highlights of varying color, width, and distance from the main line.

A macro with three parameters was used:

<!-- define the macro -->
<macro id='highlight-macro'>
<highlight width='~width~' distance='~distance~' fill='~fill~'>
<repeatedSymbol path='#arrow' gap='2000' fill='black'/>
<!-- use the macro -->
<macro ref='highlight-macro' width='80%' distance='10%' fill='green'/>

The rules are: when you define the macro, parameters have ~ before and after their names in the macro code; and when you use the macro, define all the parameters as attributes.

Parameters are not necessary for all macros. The standard style sheets contain some macros for things like minor road labels, and these do not have parameters.

See also style sheet variables.