Math Operations

The theme language supports basic math operations to calculate key values.

Operators

The following table lists the supported operations and the corresponding operator for each.

Operation Operator

multiply

*

divide

/

add

+

subtract

-

Like programming languages, the multiply and divide operators take precedence over the add and subtract operators.

Expressions

Here’s an example of a math expression with fixed values.

conum:
  line-height: 4 / 3
Operators must always be surrounded by a space on either side (e.g., 2 + 2, not 2+2).

Variables may be used in place of numbers anywhere in the expression:

base:
  font-size: 12
  font-size-large: $base-font-size * 1.25

Values used in a math expression are automatically coerced to a float value before the operation. If the result of the expression is an integer, the value is coerced to an integer afterwards.

Numeric values less than 1 must have a 0 before the decimal point (e.g., 0.85).

Functions

The theme language also supports several functions for rounding the result of a math expression. The following functions may be used if they surround the whole value or expression for a key.

round(…​)

Rounds the number to the nearest half integer.

floor(…​)

Rounds the number up to the next integer.

ceil(…​)

Rounds the number down the previous integer.

You might use these functions in font size calculations so that you get more exact values.

base:
  font-size: 12.5
  font-size-large: ceil($base-font-size * 1.25)