Coloring the characters of a ligature, without breaking the ligature

The TeX file

\documentclass[12pt]{article}
\begin{document}
ffi
\end{document}


produces the following ligature when compiled to PDF:

Note that ffi is represented by a single special character.

However, when I try to color each character in a different color, the characters won't translated to a ligature anymore. For example, when I type

\documentclass[12pt]{article}
\usepackage{color}
\begin{document}
\textcolor{red}{f}\textcolor{blue}{f}\textcolor{green}{i}
\end{document}


the produced PDF looks as follows:

Note that ffi is now represented by three individual characters.

Is there any possibility to color the characters without breaking ligatures apart, i.e.: to produce a ligature like in the first example but with colored characters?

• A ligature is, by definition, a single glyph. – egreg Aug 28 '19 at 15:24
• not really: you could convert the outline of the ligature back to paths (pstricks can do that forexample) and then colour the parts separately. or colour the ligature character but then clip to show each part, doing that three times – David Carlisle Aug 28 '19 at 15:24
• @egreg: Good point :-) – seakey Aug 28 '19 at 15:33

You can try with \llap command:
\documentclass[12pt]{article}