productToTex function
A product: \numproduct{1 x 2 x 3}, \qtyproduct{1 x 2}{\metre}.
Implementation
String productToTex(String items, {String? unit, SiOptions? options}) {
final o = options ?? const SiOptions();
final parts = items
.split('x')
.map((s) => s.trim())
.where((s) => s.isNotEmpty)
.toList();
final sep = o['product-mode'] == 'phrase'
? _textSetting(o, 'product-phrase')
: o['product-symbol'];
String join(List<String> p) => p.join(sep);
final mode = o['product-units'];
if (unit != null &&
unit.trim().isNotEmpty &&
(mode == 'power' ||
mode == 'brackets-power' ||
mode == 'bracket-power')) {
final uo = o._forUnit(unit);
final u = _unitToTex(unit, uo, parts.length);
final numbers = join([for (final n in parts) numToTex(n, options: o)]);
return _quantityParts(
mode == 'power'
? numbers
: '${o['product-open-bracket']}$numbers${o['product-close-bracket']}',
unit,
u,
uo,
);
}
return _withUnits(
parts,
unit,
o,
mode,
join,
open: o['product-open-bracket'],
close: o['product-close-bracket'],
);
}