AsciiChem
AsciiChem is an ASCII syntax for representing chemistry: atoms, molecules, bonds, reactions, electron configurations, and embedded mathematics. It parses to a semantic model and renders to MathML, HTML, LaTeX, and SVG.
Why
AsciiMath is insufficient for chemistry:
-
Prefix superscripts/subscripts have no atom to bind to — AsciiMath forces a phantom
{}carrier (e.g.{}^14C), which is semantically wrong: the isotope belongs to the atom, not to an empty element. -
No native syntax for stoichiometric coefficients, reaction arrows, conditions, or spectator ions.
-
No representation for electron configuration, term symbols, or bonds.
-
No structural diagrams.
AsciiChem closes these gaps.
Installation
Add to your Gemfile:
gem "asciichem"Or install directly:
$ gem install asciichemUsage
require "asciichem"
formula = AsciiChem.parse("H_2O")
formula.to_mathml # => "<math>...</math>"
formula.to_text # => "H_2O" (round trip)Conformance
The reference implementation of the AsciiChem contract. Every claim is gated by the shared corpus (asciichem-tests) in CI — a level without the green corpus run behind it does not ship.
| Level | Claim | Basis |
|---|---|---|
L0 notation |
yes |
parse/reject contract; every |
L1 semantics |
yes |
wire form validates against the v1 schemas and round-trips; the perception pass (implicit hydrogens, aromatic rings) is corpus-gated |
L2 render |
yes |
MathML byte-goldens, canonical text, and the wire form for every construct |
L3 stereo |
yes |
tetrahedral chirality, directional bonds, wedge/hash; parity-correct canonical SMILES including ring closures |
L4 identity |
partial |
opt-in InChI engine with stereo layers, OPSIN adapter, identifier cross-check, citation bibitems; CAS source decision pending |
TypeScript and Python claim the same levels they pass; see their READMEs and the levels document.
Design
See ARCHITECTURE.adoc and the specification at https://www.asciichem.org.
License
BSD-2-Clause. See LICENSE.