add tag
samcarter
Let's assume I have a given text: how can I colour this text in rainbow colours?

```
\documentclass[border=3mm,varwidth]{standalone}

\begin{document}

\Huge\sffamily
The rainbow beamer colour theme

\end{document}
```
Top Answer
samcarter
The following code is modified from the [gradient-text package](https://ctan.org/pkg/gradient-text). Out of the box, this package can shade a text with an RGB colour gradient, but with a couple of tweaks, it can also support other colours models:

```
\documentclass[border=3mm,varwidth]{standalone}

% rainbow text (based on the gradient-text package)
\makeatletter
\ExplSyntaxOn
\clist_new:N\l_gtext_First_clist
\clist_new:N\l_gtext_Last_clist
\int_new:N\l_gtext_MaxIndex_int
\int_new:N\l_gtext_Ratio_int
\newcommand{\gr@dient}[8]{
  \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{#8}{
          \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\gradient{mmmm}{{
  \clist_set:Nn\l_gtext_First_clist {#3}
  \clist_set:Nn\l_gtext_Last_clist {#4}
  \gr@dient{#2}
  {\clist_item:Nn\l_gtext_First_clist{1}}
  {\clist_item:Nn\l_gtext_First_clist{2}}
  {\clist_item:Nn\l_gtext_First_clist{3}}
  {\clist_item:Nn\l_gtext_Last_clist{1}}
  {\clist_item:Nn\l_gtext_Last_clist{2}}
  {\clist_item:Nn\l_gtext_Last_clist{3}}
  {#1}
}}
\ExplSyntaxOff
\makeatother

\begin{document}

\Huge\sffamily
\gradient{HSB}{The rainbow beamer colour theme}{0,240,200}{240,240,200}

\gradient{RGB}{The rainbow beamer colour theme}{255,0,0}{0,0,255}

\end{document}
```

![document-1.png](/image?hash=6dbac1c98996c24a1b8478f88a600148f572d09f80b84380e399f37c145aadd4)

(The code above works for colour models with 3 axis. With a bit more work, also colour models with more or less than 3 axis should be possible...)
Answer #2
Skillmon
With the help of the bestest package `chickenize` this becomes trivial in LuaTeX:

```
\documentclass[border=3mm,varwidth]{standalone}

\usepackage{chickenize}
% play with this value, the step is the reciprocal of the number of letters
% needed to get from red to yellow.
\chickenizesetup{rainbow_step=0.15}

\begin{document}

\Huge\sffamily
{\rainbowcolor The rainbow beamer colour theme}

\end{document}
```

![chickenrainbow-1.png](/image?hash=29d227ea5f5c34559bdd54f10ec5eb84370c1c84ccda4e248b8a2c9b8a6bb716)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.