% Copyright (C) 2022-2023 by Sicheng Du % This project is distributed under the LaTeX Project Public License, version 1.3c. %-------------------------% \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{gradient-text}[2023/1/17] \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 %---End of package code---%