style.dart
2.93 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
part of '../functions.dart';
EncodeResult _styleEncoder(GreenNode node) {
final styleNode = node as StyleNode;
return _optionsDiffEncode(styleNode.optionsDiff, styleNode.children);
}
EncodeResult _optionsDiffEncode(OptionsDiff diff, List<dynamic> children) {
EncodeResult res = TransparentTexEncodeResult(children);
if (diff.size != null) {
final sizeCommand = _sizeCommands[diff.size];
res = TexModeCommandEncodeResult(
command: sizeCommand ?? '\\tiny',
children: <dynamic>[res],
);
if (sizeCommand == null) {
res = NonStrictEncodeResult(
'imprecise size',
'Non-strict MethSize encountered during TeX encoding: '
'${diff.size}',
res,
);
}
}
if (diff.style != null) {
final styleCommand = _styleCommands[diff.style];
res = TexModeCommandEncodeResult(
command: styleCommand ?? _styleCommands[diff.style!.uncramp()]!,
children: <dynamic>[res],
);
if (styleCommand == null) {
NonStrictEncodeResult(
'imprecise style',
'Non-strict MathStyle encountered during TeX encoding: '
'${diff.style}',
res,
);
}
}
if (diff.textFontOptions != null) {
final command = texTextFontOptions.entries
.firstWhereOrNull((entry) => entry.value == diff.textFontOptions)
?.key;
if (command == null) {
res = NonStrictEncodeResult(
'unknown font',
'Unrecognized text font encountered during TeX encoding: '
'${diff.textFontOptions}',
res,
);
} else {
res = TexCommandEncodeResult(
command: command,
args: <dynamic>[res],
);
}
}
if (diff.mathFontOptions != null) {
final command = texMathFontOptions.entries
.firstWhereOrNull((entry) => entry.value == diff.mathFontOptions)
?.key;
if (command == null) {
res = NonStrictEncodeResult(
'unknown font',
'Unrecognized math font encountered during TeX encoding: '
'${diff.mathFontOptions}',
res,
);
} else {
res = TexCommandEncodeResult(
command: command,
args: <dynamic>[res],
);
}
}
if (diff.color != null) {
res = TexCommandEncodeResult(
command: '\\textcolor',
args: <dynamic>[
'#${diff.color!.value.toRadixString(16).padLeft(6, '0')}',
res,
],
);
}
return res;
}
const _styleCommands = {
MathStyle.display: '\\displaystyle',
MathStyle.text: '\\textstyle',
MathStyle.script: '\\scriptstyle',
MathStyle.scriptscript: '\\scriptscriptstyle'
};
const _sizeCommands = {
MathSize.tiny: '\\tiny',
MathSize.size2: '\\tiny',
MathSize.scriptsize: '\\scriptsize',
MathSize.footnotesize: '\\footnotesize',
MathSize.small: '\\small',
MathSize.normalsize: '\\normalsize',
MathSize.large: '\\large',
MathSize.Large: '\\Large',
MathSize.LARGE: '\\LARGE',
MathSize.huge: '\\huge',
MathSize.HUGE: '\\HUGE',
};