Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
We’ll need a minimal working example (MWE). What are monomers? –  Qrrbrbirlbel Mar 3 '13 at 5:31
    
I found an example of what I'm trying to do. A monomers is a small molecule that link up to form long chains, or polymers. –  Anthony Mar 3 '13 at 5:37
1  
You can color the entire molecule by using the optional argument of \chemfig. I am not aware of a way of coloring parts of molecules other than using the optional arguments of each bond, though. –  cgnieder Mar 3 '13 at 7:11
    
@Anthony, can you post or link to the example that you found? –  alfC Jun 21 '13 at 6:44
    
I don't remember if I ever found a chemfig example; I think I might have been referring to the image in the question. –  Anthony Jun 22 '13 at 19:26

2 Answers 2

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

share|improve this answer

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...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.