2

I would like to change the color of the oxidation numbers in some reactions like:

\documentclass{article}

\usepackage{chemformula}
\usepackage{chemmacros}
\usepackage[spanish]{babel}
\usepackage[version=3]{mhchem}

\let\chold\ch % necesario para que ch ponga bien las flechas
\renewcommand\ch[1]{%
    \catcode`<=12
    \catcode`>=12
    \chold{#1}%
    \catcode`<=\active
    \catcode`>=\active
}
\chemsetup{
  formula = {chemformula} ,
  modules = {redox} 
}
\chemsetup[redox]{
roman = false ,
explicit-sign = true ,
pos = top
}
\begin{document}
\ch{"\ox{5,N}" O3^- + 1 e- + 2 H+ <=> "\ox{4,N}" O2 + H2O}
\end{document}

The reaction i want to change color of the oxidation numbers

I use chemmacros (ox) to write the oxidation numbers, but there is no color option. Is there any way to change only the oxidations numbers? Thanks in advance

  • I need \catcode to write the arrows, in spanish "<" and ">" are inactive – tioguilly Mar 02 '20 at 12:36
  • Maybe this helps: https://tex.stackexchange.com/a/196515 – Ross Mar 02 '20 at 13:02
  • Thanks Ross. That link works fine if you want to change color of the arrows of "OX", they connect oxidant and reductant semiequations, but it not use diferent colors for the oxidation numbers – tioguilly Mar 02 '20 at 13:20
  • If you disable parsing you should be able to use \color{+5} or similar. (I guess this is worth a feature request on chemmacros' github) – cgnieder Mar 02 '20 at 13:36
  • disable parsing ? Sorry but i am newcomer in latex and i dont know how to do it. I tried with \textcolor{red}{5} , but it doesnt work. – tioguilly Mar 02 '20 at 23:42

1 Answers1

2

update 2020/03/09

Using the newest versions of chemmacros and chemformula you

  1. can use the option redox/format to add the color and
  2. don't need your workaround any more:
\documentclass{article}
\usepackage[spanish]{babel}

\usepackage{chemmacros}[2020/03/07]
\usepackage{chemformula}[2020/03/07]

\chemsetup{
  formula = chemformula ,
  modules = redox ,
  redox/roman = false ,
  redox/explicit-sign = true ,
  redox/pos = top ,
  redox/format = \textcolor{red}
}
\begin{document}

\ch{"\ox{5,N}" O3^- + 1 e- + 2 H+ <=> "\ox{4,N}" O2 + H2O}

<<Test>>

\end{document}

enter image description here

Original Answer, 2020/03/06

For the time being the only viable possibility is to disable the parsing of the oxidation numbers (note that then the option redox/roman and redox/explicit-sign don't have any effect…). When the parsing is disabled you can just use \textcolor:

\documentclass{article}
\usepackage{chemmacros}

\chemsetup{
  formula = chemformula ,
  modules = redox ,
  redox/parse = false ,
  redox/pos = top
}

\begin{document}

\ch{"\ox{\textcolor{red}{+5},N}" O3^-}

\end{document}

enter image description here

cgnieder
  • 66,645