How can I write chemical equations with oxidation numbers?

You can use math.attach() to write the oxidation numbers on top of the elements. Two comments to explain the code below:

  • Wrapping the base in math.limits() is required to force the attachment to actually be on top. Otherwise the attachments would be formatted like an exponent.
  • You can use strings in math mode to get regular (upright) text. As far as I know the chemical elements should be formatted upright?
#let ox(base, attachement) = {
  math.attach(math.limits(base), t: math.upright(attachement))
}

$ ox("Zn", 0) + 2 ox("Na", I) ox("O", -"II") ox("H", I) -> ox("Na"_2, I) ox("Zn", "II") ox("O"_2, -"II") + ox("H"_2, 0) $

There are also two chemistry packages (that I know of) available in the Typst universe, namely whalogen and typsium. The whalogen manual even mentions oxidation states but they are formatted as exponents there. I don’t know if there is an easy way to modify this.

In any case I would recommend you to check out those packages if you are writing chemical formulas. The features you need might already be implemented there.

2 Likes