%        File: rainbowtext.ltx
%      Author: H.A.Trujillo
%     Created: Thu Nov 06 10:00 PM 2014 E
% Last Change:      7 Nov 2014

% Prints text in rainbow colors (letter-by-letter)

\documentclass[10pt]{article}
\usepackage{color}

\makeatletter
% Substitute call to desired font for "\em" in \colors command below
\newcommand{\colors} [1] {%
    \count255=0%		 	\count255 = position in color cycle
    {\em\@colors#1@}%
}

    % #1 = first letter; #2 = remaining letters
\def\@colors#1#2@{%
    \def\next@arg{#2}%
    %	If more colors are added, change "4" to number of colors in the cycle
    \ifnum\count255=4 \advance\count255 -4 \fi
    \ifcase\count255 
	\textcolor{red}\bgroup\or
	\textcolor{green}\bgroup\or
	\textcolor{blue}\bgroup\or
	\textcolor{cyan}\bgroup%
    \fi
    #1\egroup%
    \advance\count255 1
    \ifx\next@arg\empty \else
	\@colors#2@%
    \fi%
}
\makeatother

\begin{document}

Previous Text
\colors{abcdefghij}
Subsequent Text


\end{document}
