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.

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?

share|improve this question
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 at 22:33

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
    
Thank you very much, I would have never guessed the ungrouping internal routine! –  Andreï Kostyrka Mar 1 at 22:42

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.