Model-driven
Every parse produces a semantic tree. Render to MathML, HTML, LaTeX, or SVG without round-tripping through text.
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.
Type chemistry on any keyboard. AsciiChem parses it into a semantic model and renders it as MathML — no LaTeX, no Unicode, no special software.
H_2O2H_2 + O_2 -> 2H_2ON_2 + 3H_2 <=>[Fe][400C] 2NH_3^14CCa^2+AsciiMath’s data model assumes math typography, not chemistry semantics. Chemistry routinely needs things AsciiMath cannot express cleanly:
^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.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.
gem install asciichemrequire "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.