|
83 | 83 | /// could be found, a real number with `digits` digits is used. |
84 | 84 | /// - digits (int): Number of digits to use for rounding |
85 | 85 | /// - eps (number): Epsilon used for comparison |
| 86 | +/// - prefix (content): Content to prefix |
| 87 | +/// - suffix (content): Content to append |
86 | 88 | /// -> Content if a matching fraction could be found or none |
87 | | -#let multiple-of(value, factor: calc.pi, symbol: $pi$, fraction: true, digits: 2, eps: 1e-6) = { |
| 89 | +#let multiple-of(value, factor: calc.pi, symbol: $pi$, fraction: true, digits: 2, eps: 1e-6, prefix: [], suffix: []) = { |
88 | 90 | if _compare(value, 0, eps: eps) { |
89 | 91 | return _block-eq($0$) |
90 | 92 | } |
91 | 93 |
|
92 | 94 | let a = value / factor |
93 | 95 | if _compare(a, 1, eps: eps) { |
94 | | - return _block-eq(symbol) |
| 96 | + return _block-eq(prefix + symbol + suffix) |
95 | 97 | } else if _compare(a, -1, eps: eps) { |
96 | | - return _block-eq($-$ + symbol) |
| 98 | + return _block-eq(prefix + $-$ + symbol + suffix) |
97 | 99 | } |
98 | 100 |
|
99 | 101 | if fraction != none { |
100 | 102 | let frac = _find-fraction(a, denom: if fraction == true { auto } else { fraction }) |
101 | 103 | if frac != none { |
102 | | - return _block-eq(frac + symbol) |
| 104 | + return _block-eq(prefix + frac + symbol + suffix) |
103 | 105 | } |
104 | 106 | } |
105 | 107 |
|
106 | | - return _block-eq($#calc.round(a, digits: digits)$ + symbol) |
| 108 | + return _block-eq(prefix + $#calc.round(a, digits: digits)$ + symbol + suffix) |
107 | 109 | } |
108 | 110 |
|
109 | 111 | /// Scientific notation tick formatter |
|
119 | 121 | /// |
120 | 122 | /// - value (number): Value to format |
121 | 123 | /// - digits (int): Number of digits for rounding the factor |
| 124 | +/// - prefix (content): Content to prefix |
| 125 | +/// - suffix (content): Content to append |
122 | 126 | /// -> Content |
123 | | -#let sci(value, digits: 2) = { |
| 127 | +#let sci(value, digits: 2, prefix: [], suffix: []) = { |
124 | 128 | let exponent = if value != 0 { |
125 | 129 | calc.floor(calc.log(calc.abs(value), base: 10)) |
126 | 130 | } else { |
|
136 | 140 |
|
137 | 141 | value = calc.round(value, digits: digits) |
138 | 142 | if exponent <= -1 or exponent >= 1 { |
139 | | - return _block-eq($#value times 10^#exponent$) |
| 143 | + return _block-eq(prefix + $#value times 10^#exponent$ + suffix) |
140 | 144 | } |
141 | 145 |
|
142 | | - return _block-eq($#value$) |
| 146 | + return _block-eq(prefix + $#value$ + suffix) |
143 | 147 | } |
144 | 148 |
|
145 | 149 | /// Rounded decimal number formatter |
|
155 | 159 | /// |
156 | 160 | /// - value (number): Value to format |
157 | 161 | /// - digits (int): Number of digits to round to |
| 162 | +/// - prefix (content): Content to prefix |
| 163 | +/// - suffix (content): Content to append |
158 | 164 | /// -> Content |
159 | | -#let decimal(value, digits: 2) = { |
160 | | - _block-eq($#calc.round(value, digits: digits)$) |
| 165 | +#let decimal(value, digits: 2, prefix: [], suffix: []) = { |
| 166 | + _block-eq(prefix + $#calc.round(value, digits: digits)$ + suffix) |
161 | 167 | } |
0 commit comments