Skip to content

AsciiChem

ASCII in, chemistry out.

AsciiChem is an ASCII syntax for representing chemistry — atoms, molecules, bonds, reactions, electron configurations, and the embedded mathematics that chemistry publications rely on.

It is to chemistry what AsciiMath is to mathematics.

AsciiMath’s data model assumes math typography, not chemistry semantics. Chemistry routinely needs things AsciiMath cannot express cleanly:

  • Prefix isotopes like ^14C. AsciiMath forces a phantom {} carrier ({}^14C) — the isotope ends up bound to an empty element, semantically wrong. AsciiChem binds it to the atom directly.
  • Reactions with stoichiometric coefficients, equilibrium arrows, and catalyst conditions above and below the arrow.
  • Electron configurations, term symbols, and bonds (single, double, triple, wedge, hash, dative).
  • Embedded mathematics via Plurimath, so equilibrium constants and rate laws sit naturally inside chemistry.

Model-driven

Every parse produces a semantic tree. Render to MathML, HTML, LaTeX, or SVG without round-tripping through text.

Round-trippable

parse(s).to_text == s for any canonical input. The formatter is the canonicaliser.

IUPAC-aligned

Constructs map to the IUPAC Green Book conventions; numbers-then-sign charges, Roman numeral oxidation states, and equilibrium arrows.

OCP / MECE

Add new constructs as model classes; add new outputs as formatters. No edits to existing code.

Terminal window
gem install asciichem
require "asciichem"
formula = AsciiChem.parse("2H_2 + O_2 -> 2H_2O")
formula.to_mathml # => "<math>...</math>"
formula.to_text # => "2H_2 + O_2 -> 2H_2O"

Continue to the Getting started guide.