Style Functions
Part of the process of generating a rendering expression for any expression is getting and applying the styles for the expression.
The BuildRendering function is the heart of the rendering system. It's called each time on expression needs to be rendered on the screen. It takes an expression and the current display settings for the module (which include the edit mode, the notation and the module type) and it returns a rendering expression.
As part of the processing in the BuildRendering function, both the GetStyles and ApplyStyles functions are called. The GetStyles function determines the colors, parenthesizing, and background for each object as it is being rendered. It takes the expression that is going to be rendered and the current display settings for the module and returns a list of zero or more styles that should be applied to the rendering.
The ApplyStyles function applies styles to a rendering expression. It takes a rendering expression and a list of zero or more styles (which typically are provided by the GetStyles function) and returns a rendering expression that includes the style settings provided.
Note that parentheses appear only in the renderings of objects and are not part of the expression. In some cases, we may parenthesize an object differently depending on how it's rendered. For example, when the Div object is rendered horizontally we need parentheses if either the numerator or denominator is, for example, an Add object.
Parentheses are part of the styles for an expression. For example, if the current expression has two parameters and the second parameter should be parenthesized, the styles returned by the GetStyles function will include parentheses: 2 and the ApplyStyles function will use this information to insert parentheses around the second parameter. Note that the parameter of the Parentheses object can be a List of numbers. In this case, more than one parameter will be parenthesized.