# Fill the background of functional groups in chemfig

I want to fill the background of some functional groups or atoms including bonds to emphasize them. For instance, to emphasize carbonyl group in a keton, fill the background of C=O like:

I'm using chemfig to draw chemistry equations, and I have a workaround which cover with overlay(chemmove):

\chemfig{R|_1-@{kc}C(=[:90]O)-R|_2}
\chemmove{
\node[fill=purple!20,anchor=text,inner sep=0.1em]
at (kc.text) {\chemfig{C(=[:90]O)}};
}


However, I need simpler and smarter way since, in this way, I have to write the same code twice(which could be very long if the atoms and bonds are long and complicated) and it does not work with wrong anchoring from time to time.

-
Welcome to TeX.sx! – clemens Jul 14 '13 at 12:47
@cgnieder Thanks! – xylosper Jul 14 '13 at 15:05

You could mark two nodes with the @{<name>} syntax and then draw a rectangle with fill opacity=.2 (or whatever suits you best):

\documentclass{article}
\usepackage{chemfig,tikz}
\begin{document}
\chemfig{R_1-@{C}C(=[:90]@{O}O)-R_2}
\chemmove{
\draw[
fill=purple,
draw=purple,
fill opacity=.2,
rounded corners=2pt
]
([xshift=-3pt,yshift=-1pt]C.south west)
rectangle
([xshift=3pt,yshift=3pt]O.north east) ;
}
\end{document}


-
This looks nice but it's another workaround, isn't it? Because the filled rectangle is laid over C=O, the fill opacity value shoulde be small otherwise it will paint out the below drawings. Although I think this is simple and very helpful, I want to wait for more general solution which does not cover the drawings. Thank you! – xylosper Jul 14 '13 at 15:04
“[...] it's another workaround, isn't it? ” - Well, that may be, but at least it saves you the trouble of typing the concerned molecule part twice :) – clemens Jul 14 '13 at 21:48
Yes, I agree with you. It is definitely better and I couldn't find any other solution. Thanks. – xylosper Jul 15 '13 at 1:00