-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradient.sty
33 lines (33 loc) · 1.3 KB
/
gradient.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
% Stolen from https://www.ctan.org/pkg/gradient-text :)
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gradient}
\ExplSyntaxOn
\clist_new:N\l_gtext_FirstRGB_clist
\clist_new:N\l_gtext_LastRGB_clist
\int_new:N\l_gtext_MaxIndex_int
\int_new:N\l_gtext_Ratio_int
\newcommand{\gr@dientRGB}[7]{
\int_set:Nn\l_gtext_MaxIndex_int{\int_eval:n{\str_count:n{#1}}}
\int_step_inline:nnn{1}{\l_gtext_MaxIndex_int}{
\exp_args:Ne\str_if_eq:nnTF{\str_item:Nn{#1}{##1}}{~}{}{
\int_set:Nn\l_gtext_Ratio_int{\int_eval:n{\l_gtext_Ratio_int+1}}
}
\color_select:nn{RGB}{
\int_eval:n{(\int_use:N\l_gtext_Ratio_int*#5+(\l_gtext_MaxIndex_int-##1)*#2)/\l_gtext_MaxIndex_int},
\int_eval:n{(\int_use:N\l_gtext_Ratio_int*#6+(\l_gtext_MaxIndex_int-##1)*#3)/\l_gtext_MaxIndex_int},
\int_eval:n{(\int_use:N\l_gtext_Ratio_int*#7+(\l_gtext_MaxIndex_int-##1)*#4)/\l_gtext_MaxIndex_int}
}\str_item:Nn{#1}{##1}
}
}
\NewDocumentCommand\gradientRGB{mmm}{{
\clist_set:Nn\l_gtext_FirstRGB_clist {#2}
\clist_set:Nn\l_gtext_LastRGB_clist {#3}
\gr@dientRGB{#1}
{\clist_item:Nn\l_gtext_FirstRGB_clist{1}}
{\clist_item:Nn\l_gtext_FirstRGB_clist{2}}
{\clist_item:Nn\l_gtext_FirstRGB_clist{3}}
{\clist_item:Nn\l_gtext_LastRGB_clist{1}}
{\clist_item:Nn\l_gtext_LastRGB_clist{2}}
{\clist_item:Nn\l_gtext_LastRGB_clist{3}}
}}
\ExplSyntaxOff