Skip to content

Getting started

AsciiChem is a language for chemistry. It has four implementations — Rust (the authoritative one), Ruby, TypeScript, and Python — that parse through the same parsanol engine over the same PARG artifact and pass the same shared corpus. Pick the one that ships in your stack; the syntax and the model are identical everywhere.

  1. Install the gem

    Terminal window
    gem install asciichem
  2. Parse and render

    require "asciichem"
    formula = AsciiChem.parse("H_2O")
    formula.to_mathml # => "<math>...</math>"
    formula.to_text # => "H_2O" (round trip)
    formula.to_structural_svg # 2D diagram
  3. Use the CLI

    Terminal window
    asciichem convert -i "2H_2 + O_2 -> 2H_2O" -t mathml
    asciichem lint -i "H_2 + O_2 -> H_2O"
    asciichem resolve --cas 50-78-2
    asciichem cite --cas 50-78-2

Full reference: Ruby API.

Ruby
asciichem
gem install asciichemReference implementation.
TypeScript
asciichem
npm install asciichemPowers this page.
Python
asciichem
pip install asciichemZero runtime deps.

AsciiChem parses text into a model tree. Each node has typed fields — chemistry semantics, not just typography. The tree is the same whether you parsed in Rust, Ruby, TypeScript, or Python.

SourceModel
H_2OMolecule[Atom(H, sub:"2"), Atom(O)]
^14CMolecule[Atom(C, isotope:"14")]
Ca^2+Molecule[Atom(Ca, charge:"2+")]
Ca(OH)_2Molecule[Atom(Ca), Group(...,mult:"2")]
2H_2+O_2 -> 2H_2OReaction(reactants:[...], products:[...], arrow::forward)
Play