8

I have a molecule (in this case a copolymer) where I would like to hilight the monomers by colouring a number of atoms. Is there a more efficient way to do this than colouring each atom and bond individually? chemfig syntax can get rather verbose.

A Google search for "copolymer" turns up this, which is essentially what I'm trying to achieve.

enter image description here

Anthony
  • 1,000

2 Answers2

4

Here is a method to color both all atoms and bonds:

\documentclass{article}
\usepackage{chemfig}
\begin{document}
\def\ZZ#1{\global\setbondstyle{thick,color=#1}\gdef\printatom##1{\color{#1}\ensuremath{\mathrm{##1}}}}
\def\paren#1{\rlap{\kern-.75em$\left(\vrule height1ex width0pt depth1ex\vrule height0pt width2.5em depth0pt\right)_{\!#1}$}}
\definesubmol\NN{-[,,,,draw=none]}
\definesubmol\Red{(!\NN\ZZ{red})}
\definesubmol\Green{(!\NN\ZZ{green!40!black})}
\definesubmol\Purple{(!\NN\ZZ{purple})}
\setatomsep{2em}\setbondstyle{thick}
\chemfig{[:30]!\Purple EtO-([,.75]=[2]S)-[:-30]S-[,,,,,black]!\Green(-[6,0.25]\paren n)
    ([,.75]-[2]O-(=[2]O)-[:-30])-[:-30,1.25]-[,1.25,,,,black]!\Red(-[6,0.25]\paren m)
    ([,.75]-[2]O-(=[2]O)-[:-30]tBu)-[:-30,1.25]-[,1.25]R}
\end{document}

enter image description here

unbonpetit
  • 6,190
  • 1
  • 20
  • 26
2

Here's a simple solution. It still needs some tweaking but the idea, how to proceed is the following:

enter image description here

\documentclass{article}

\usepackage{chemfig}

\definecolor{col1}{RGB}{0,102,153}
\definecolor{col2}{RGB}{0,252,0} 
\definecolor{col3}{RGB}{150,0,0} 

\newcommand\setpolymerdelim[2]{\def\delimleft{#1}\def\delimright{#2}}
\def\makebraces[#1,#2]#3#4#5{%
\edef\delimhalfdim{\the\dimexpr(#1+#2)/2}%
\edef\delimvshift{\the\dimexpr(#1-#2)/2}%
\chemmove{%
\node[at=(#4),yshift=(\delimvshift)]
{$\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim
width0pt\right.$};%
\node[at=(#5),yshift=(\delimvshift)]
{$\left.\vrule height\delimhalfdim depth\delimhalfdim
width0pt\right\delimright_{\rlap{\tiny$#3$}}$};}}
\setpolymerdelim() 

\begin{document}

\chemfig{
\textcolor{col1}{EtO}-[:30,,,,col1](=[:90,,,,col1]\textcolor{col1}{S})-[:-30,,,,col1]\textcolor{col1}{S}
-[@{left}:30](-[:90,,,,col2]\textcolor{col2}{O})-[:-30,,,,col2]-[@{right}:30,0.5]-[@{lleft}:30,0.5](-[:90,,,,col3]\textcolor{col3}{O})-[:-30,,,,col3]-[@{rright}:30,,,,col3]
}
{\color{col2}\makebraces[5pt,12pt]{m}{left}{right}}
{\color{col3}\makebraces[5pt,12pt]{n}{lleft}{rright}}

\end{document}

But as cgnieder mentioned, you have to probably color "manually" each bond separately...

Peter Grill
  • 223,288
pisoir
  • 882