summaryrefslogtreecommitdiff
path: root/docs/modules/theme/pages/math-operations.adoc
blob: 70d06d1d94d66e0ddc7871d3598616a76b9d3c22 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
= Math Operations
:description: The theming language supports basic math operations and rounding functions to calculate key values.

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.

[width=25%]
|===
|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.

[,yaml]
----
conum:
  line-height: 4 / 3
----

IMPORTANT: 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:

[,yaml]
----
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.

IMPORTANT: 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.

[,yaml]
----
base:
  font-size: 12.5
  font-size-large: ceil($base-font-size * 1.25)
----