2

Some strange behaviour which contradicts the documentation was encountered when creating a figure of 5-cafeoylquinic acid with chemfig. It is stated in the manual that

The atoms are displayed in tikz nodes which behaves like boxes of TeX and it is as if these atoms were put in a group. Therefore, the color change remains local to the atom.

An example is given why writing O\color{red}H doesn't work and why O{\color{red}H} should be used instead. A remark says,

The same effect can be obtained with \textcolor.

The following code yields the desired output (Win7 TeXLive 2013 with chemfig 1.0g, rev. 32270):

\chemfig{
    [:30]HO-*6(-=-(-=[::-60]-[::60](=[2]O)-[:-30]{\color{red}O}>
    *6(--(([6]<OH)-(-[:30]OH)=[6]
    \textcolor{red}{O}
    )--(<:OH)-(<HO)-)
    )=-(-HO)=)
    }

5-cafeoylquinic acid

However, when I try to invoke an equivalent colouring with simple {\color{red}O}, something odd occurs (line 4):

\chemfig{
    [:30]HO-*6(-=-(-=[::-60]-[::60](=[2]O)-[:-30]{\color{red}O}>
    *6(--(([6]<OH)-(-[:30]OH)=[6]
    {\color{red}O}
    )--(<:OH)-(<HO)-)
    )=-(-HO)=)
    }

5-cafeoylquinic acid with misplaced O

It had worked with the middle “O” but failed with the last one! Why does the presumably equivalent function act the ape?

  • 1
    You can also write \color{red}{o}. It is important to put O inside braces to avoid two atoms, the first \color{red} and the second O. – unbonpetit Mar 1 '14 at 22:33
5

It works with two set of curly braces (changed the color to blue):

\documentclass{article}
\usepackage{color}
\usepackage{chemfig}
\begin{document}
\chemfig{
    [:30]HO-*6(-=-(-=[::-60]-[::60](=[2]O)-[:-30]{\color{red}O}>
    *6(--(([6]<OH)-(-[:30]OH)=[6]
    {{\color{blue}O}}
    )--(<:OH)-(<HO)-)
    )=-(-HO)=)
    }
\end{document}

Result

Probably the first set of curly braces is removed, when the atom is read as argument. Then TeX automatically removes one pair of braces.

  • Thank you very much, I would have never guessed the ungrouping internal routine! – Andreï Kostyrka Mar 1 '14 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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