This is a complement of my last question Apply command on nth character of a word,
I need to color a range of characters like this \ColorRgChar{2-5}{examination}
which color from second to the fifth character of the word.
If the first number is greater then the length of word no coloring is done.
Coloring of characters should be done at one time with a single \textcolor
command not with \textcolor
for every char. @David Carlisle
\documentclass{article}
\usepackage{xcolor}
\begin{document}
\makeatletter
\def\ColorRgChar#1#2{\xColorRgChar{#1}#2\@empty}
\def\xColorRgChar#1#2{\ifnum\ifx\@empty#21\else#1\fi=1 \textcolor{red}{#2}\expandafter\@gobbletwo
\else#2\fi\xColorRgChar{\numexpr#1-1\relax}}
\makeatother
\ColorRgChar{2}{examination}
%\ColorRgChar{2-5}{examination} % desired macro
\end{document}