adjusting colors in Manim when using the chemmacros package in LaTeX

Viewed 90

I am trying to include some chemistry in an explanation and want to highlight portions of a chemical formula from LaTeX. The chemmacros package makes formatting of chemical formulas and equations quite simple in LaTeX. For example \ch{C6H12O6} automatically gets formatted appropriately for chemistry purposes. However, if I want to change the colors to highlight the subscripts or the element symbols, none of the techniques described in the Manim documentation seem to work.

For example, to change the color of the 6 subscript on the carbon atom, I tried several variations of

chemTemplate = TexTemplate()
chemTemplate.add_to_preamble(r"\usepackage{chemmacros}")
chemTemplate.add_to_preamble(r"\usechemmodule{all}")
text = Tex(r"\ch{C{6}H12O6}", tex_template=chemTemplate)
text.set_color_by_tex('{6}')

I've tried several other variations, but the result either has no effect on the color, or turns the entire formula red. I tried to follow the Manim documentation in the "Using Text" tutorial and several variations from the "substrings" part of that tutorial. I'm using version 0.9.0 of Manim (community edition).

I don't know if the way chemmacros makes use of chemformulas and tikz just complicates the system too much for Manim to work around or if I'm just missing something.

0 Answers
Related