# TikZ: Changing color within a character

While working on some graphics in TikZ, I encountered some special need (which I could of course achieve with some image manipulation programs, but I wonder whether there's a (La)TeXy way): I want to change the color of a character within the character (best at the intersection with some lines).

That's what I'm able to achieve (I know it's pretty much nothing):

That's what I want:

If you need a MWE, here's a test object:

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
\node[color=gray] {A};
\draw[thin] (2pt,-4pt) circle (3pt);
\end{tikzpicture}

\end{document}


I'll put this as an answer, although i'm not sure it's sufficient long enough. As long as you do not want to do this repeatedly with different areas of the letter, you can just clip things in tikz:

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
\node[color=gray] {A};
\draw[thin] (2pt,-4pt) circle (3pt);
\end{tikzpicture}
\begin{tikzpicture}
\node[color=gray] {A};
\clip (2pt,-4pt) circle (3pt);
\node[color=blue] {A};
\end{tikzpicture}

\end{document}


The probably better variant would be to define a macro, at least if you want this multiple times (like capitalised chapter beginnings):

\newcommand{\coloredletter}[1]{\tikz{\node[color=gray] at (0, 0) {#1}; \clip (2pt,-4pt) circle (3pt); \node[color=blue] at (0, 0) {#1};}}

\coloredletter{A}
\coloredletter{B}


The result then looks like this:

Clipping does what you want.

# Code

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
\node[color=gray] {A};