-
Notifications
You must be signed in to change notification settings - Fork 2
/
cu-kruk.sty
224 lines (218 loc) · 7.48 KB
/
cu-kruk.sty
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
\NeedsTeXFormat{LaTeX2e}%
\RequirePackage{xkeyval}%
\RequirePackage{ifluatex}%
\RequirePackage{cu-kinovar}%
\ProvidesPackage{cu-kruk}[2024/09/18 v0.3 support for kruk music notations]%
%
%% 'autocolormarks' and noautocolormarks options
\newif\ifcu@autocolormarks
\ifluatex
\cu@autocolormarkstrue
\else
\cu@autocolormarksfalse
\fi
\DeclareOption{autocolormarks}{
\cu@autocolormarkstrue
\ifluatex\relax\else\message{WARNING: autocolormarks option may not work correctly with this TeX engine. See documentation for more details.}\fi
}
\DeclareOption{noautocolormarks}{
\cu@autocolormarksfalse
}
\ProcessOptions\relax
\let\cuKrukFont\relax %% to be defined by the user
%
\newlength{\cuKrukSylSpace} %% spacing around kruk syllable
\newlength{\cuKrukTopMargin} %% top margin ensures that lines are nicely separated
\newlength{\cuKrukSylRuleHeight} %% how thick placeholder rule is
\newlength{\cuKrukRaise} %% distance between text and kruk baselines
%
\setlength{\cuKrukSylSpace}{0.2em}
\setlength{\cuKrukTopMargin}{0.3em}
\setlength{\cuKrukSylRuleHeight}{0.08em}
\setlength{\cuKrukRaise}{1em}
\define@key{cuKruk}{krukFont}{\def\cuKrukFont{#1}}%
\define@key{cuKruk}{sylSpace}{\setlength{\cuKrukSylSpace}{#1}}%
\define@key{cuKruk}{topMargin}{\setlength{\cuKrukTopMargin}{#1}}%
\define@key{cuKruk}{sylRuleHeight}{\setlength{\cuKrukSylRuleHeight}{#1}}%
\define@key{cuKruk}{krukRaise}{\setlength{\cuKrukRaise}{#1}}%
\define@boolkey{cuKruk}{invertColor}[true]{}%
\newcommand{\cuKruk}[3][]{%
\bgroup
\setkeys{cuKruk}{#1}%
\cu@@Kruk{#2}{#3}%
\egroup
}%
\def\cu@@Kruk#1#2{{%
\edef\cu@tmp{\csname \detokenize{#2}cu@@@\endcsname}%
\setbox1=\hbox{{%
\ifKV@cuKruk@invertColor
\colorlet{tmp}{.}\color{kinovar}\colorlet{kinovar}{tmp}%
\fi
\cuKrukFont#1%
}}%
\dimen0=\ht1\advance\dimen0 by \cuKrukTopMargin\ht1=\dimen0%
\if\relax\detokenize{#2}\relax
\setbox2=\hbox{\vrule height \cuKrukSylRuleHeight width \wd1}%
\else
\ifx\cu@tmp\cu@Tilda
\setbox2=\hbox{\vrule height \cuKrukSylRuleHeight width \wd1}%
\else
\setbox2=\hbox{#2}%
\fi
\fi
\ifdim\wd1>\wd2%
\setbox2=\hbox to \wd1{\hss\box2\hss}%
\fi
%\discretionary{}{}{}%
\hskip\cuKrukSylSpace\penalty5000\hbox to \wd2{%
\hskip0.5\wd2\hskip-0.5\wd1\raise\cuKrukRaise\copy1\kern-0.5\wd2\kern-0.5\wd1\copy2\hss
}\penalty10000\hskip\cuKrukSylSpace
}}%
%
\newlength{\cuSupRaise} %% controls extra vertical space between Sup and Base
\setlength{\cuSupRaise}{0ex}
\define@key{cuSup}{raise}{\setlength{\cuSupRaise}{#1}}%
\newcommand{\cuSup}[3][]{%
\bgroup
\setkeys{cuSup}{#1}%
\cu@@Sup{#2}{#3}%
\egroup
}%
\def\cu@@Sup#1#2{{%
\leavevmode
\setbox1=\hbox{#1}%
\setbox2=\hbox{#2}%
\dimen0=\ht2%
\advance\dimen0 by \dp1%
\message{\the\dimen0}%
\advance\dimen0 by \cuSupRaise
\advance\dimen0 by -0.25\ht1%
\hbox to \wd2{%
\hskip0.5\wd2\hskip-0.5\wd1\raise\dimen0\copy1\kern-0.5\wd2\kern-0.5\wd1\copy2\hss
}%
}}
%
\newcounter{cu@KrukPos}%
\newcounter{cu@SylPos}%
%
\newcommand{\cuKrukPara}[2][]{%
\cu@KrukPara[#1]#2\cu@End
}%
%
\def\cu@KrukPara[#1]#2\\#3\cu@End{%
\bgroup
\setkeys{cuKruk}{#1}%
\setcounter{cu@KrukPos}{0}%
\setcounter{cu@SylPos}{0}%
\cu@Kruk #2 \cu@EndKruk
\cu@Text #3 \cu@EndText
\ifnum\thecu@SylPos<\thecu@KrukPos\errmessage{Too many kruk groups. Seen {\thecu@KrukPos} kruk groups and {\thecu@SylPos} text groups}\fi
\egroup
}%
%
\def\cu@Kruk#1 #2\cu@EndKruk{%
\if\relax\detokenize{#1}\relax\else
\cu@KrukAction{#1}%
\fi
\if\relax\detokenize{#2}\relax\else
\cu@Kruk#2\cu@EndKruk
\fi
}%
%
\def\cu@KrukAction#1{%
\edef\cu@tmp{\csname \detokenize{#1}cu@@@\endcsname}%
\ifx\cu@tmp\cu@Tilda
\expandafter\edef\csname cu@@\thecu@KrukPos\endcsname{}%
\else
\expandafter\def\csname cu@@\thecu@KrukPos\endcsname{#1}%
\fi
\stepcounter{cu@KrukPos}%
}
%
\edef\cu@Tilda{\csname \detokenize{~}cu@@@\endcsname}%
\edef\cu@Empty{\csname \detokenize{}cu@@@\endcsname}%
%
\def\cu@Text#1 #2\cu@EndText{%
\if\relax\detokenize{#1}\relax\else
\cu@TextDash#1-\cu@EndText\space
\fi
\if\relax\detokenize{#2}\relax\else
\cu@Text#2\cu@EndText
\fi
}%
%
\def\cu@TextDash#1-#2\cu@EndText{%
\cu@TextAction{#1}%
\if\relax\detokenize{#2}\relax\else
\cu@TextDash#2\cu@EndText
\fi
}%
%
\def\cu@TextAction#1{%
\ifnum\thecu@SylPos>\thecu@KrukPos
\errmessage{Too few kruk groups. Seen {\thecu@KrukPos} kruk groups and {\thecu@SylPos} text groups}%
\fi
\edef\cu@tmp{\csname \detokenize{#1}cu@@@\endcsname}%
\ifx\cu@tmp\cu@Empty
\expandafter\cuKruk\expandafter{\csname cu@@\thecu@SylPos\endcsname}{}%
\else
\ifx\cu@tmp\cu@Tilda
\expandafter\cuKruk\expandafter{\csname cu@@\thecu@SylPos\endcsname}{}%
\else
\expandafter\cuKruk\expandafter{\csname cu@@\thecu@SylPos\endcsname}{#1}%
\fi
\fi
\stepcounter{cu@SylPos}%
}%
%
% Automatic coloring of kruk marks (pomety)
\ifcu@autocolormarks
\catcode`𜼀\active\def𜼀{\cuKinovar{\detokenize{𜼀}}}%
\catcode`𜼁\active\def𜼁{\cuKinovar{\detokenize{𜼁}}}%
\catcode`𜼂\active\def𜼂{\cuKinovar{\detokenize{𜼂}}}%
\catcode`𜼃\active\def𜼃{\cuKinovar{\detokenize{𜼃}}}%
\catcode`𜼄\active\def𜼄{\cuKinovar{\detokenize{𜼄}}}%
\catcode`𜼅\active\def𜼅{\cuKinovar{\detokenize{𜼅}}}%
\catcode`𜼆\active\def𜼆{\cuKinovar{\detokenize{𜼆}}}%
\catcode`𜼇\active\def𜼇{\cuKinovar{\detokenize{𜼇}}}%
\catcode`𜼈\active\def𜼈{\cuKinovar{\detokenize{𜼈}}}%
\catcode`𜼉\active\def𜼉{\cuKinovar{\detokenize{𜼉}}}%
\catcode`𜼊\active\def𜼊{\cuKinovar{\detokenize{𜼊}}}%
\catcode`𜼋\active\def𜼋{\cuKinovar{\detokenize{𜼋}}}%
\catcode`𜼌\active\def𜼌{\cuKinovar{\detokenize{𜼌}}}%
\catcode`𜼍\active\def𜼍{\cuKinovar{\detokenize{𜼍}}}%
\catcode`𜼎\active\def𜼎{\cuKinovar{\detokenize{𜼎}}}%
\catcode`𜼏\active\def𜼏{\cuKinovar{\detokenize{𜼏}}}%
\catcode`𜼐\active\def𜼐{\cuKinovar{\detokenize{𜼐}}}%
\catcode`𜼑\active\def𜼑{\cuKinovar{\detokenize{𜼑}}}%
\catcode`𜼒\active\def𜼒{\cuKinovar{\detokenize{𜼒}}}%
\catcode`𜼓\active\def𜼓{\cuKinovar{\detokenize{𜼓}}}%
\catcode`𜼔\active\def𜼔{\cuKinovar{\detokenize{𜼔}}}%
\catcode`𜼕\active\def𜼕{\cuKinovar{\detokenize{𜼕}}}%
\catcode`𜼖\active\def𜼖{\cuKinovar{\detokenize{𜼖}}}%
\catcode`𜼗\active\def𜼗{\cuKinovar{\detokenize{𜼗}}}%
\catcode`𜼘\active\def𜼘{\cuKinovar{\detokenize{𜼘}}}%
\catcode`𜼙\active\def𜼙{\cuKinovar{\detokenize{𜼙}}}%
\catcode`𜼚\active\def𜼚{\cuKinovar{\detokenize{𜼚}}}%
\catcode`𜼛\active\def𜼛{\cuKinovar{\detokenize{𜼛}}}%
\catcode`𜼜\active\def𜼜{\cuKinovar{\detokenize{𜼜}}}%
\catcode`𜼝\active\def𜼝{\cuKinovar{\detokenize{𜼝}}}%
\catcode`𜼞\active\def𜼞{\cuKinovar{\detokenize{𜼞}}}%
\catcode`𜼟\active\def𜼟{\cuKinovar{\detokenize{𜼟}}}%
\catcode`𜼠\active\def𜼠{\cuKinovar{\detokenize{𜼠}}}%
\catcode`𜼡\active\def𜼡{\cuKinovar{\detokenize{𜼡}}}%
\catcode`𜼢\active\def𜼢{\cuKinovar{\detokenize{𜼢}}}%
\catcode`𜼣\active\def𜼣{\cuKinovar{\detokenize{𜼣}}}%
\catcode`𜼤\active\def𜼤{\cuKinovar{\detokenize{𜼤}}}%
\catcode`𜼥\active\def𜼥{\cuKinovar{\detokenize{𜼥}}}%
\catcode`𜼦\active\def𜼦{\cuKinovar{\detokenize{𜼦}}}%
\catcode`𜼧\active\def𜼧{\cuKinovar{\detokenize{𜼧}}}%
\catcode`𜼨\active\def𜼨{\cuKinovar{\detokenize{𜼨}}}%
\catcode`𜼩\active\def𜼩{\cuKinovar{\detokenize{𜼩}}}%
\catcode`𜼪\active\def𜼪{\cuKinovar{\detokenize{𜼪}}}%
\catcode`𜼫\active\def𜼫{\cuKinovar{\detokenize{𜼫}}}%
\catcode`𜼬\active\def𜼬{\cuKinovar{\detokenize{𜼬}}}%
\catcode`𜼭\active\def𜼭{\cuKinovar{\detokenize{𜼭}}}%
\fi
%
\endinput%