Skip to content

Ruby

Rubyyou are here
asciichem
gem install asciichemReference implementation.
TypeScript
asciichem
npm install asciichemPowers this page.
Python
asciichem
pip install asciichemZero runtime deps.
Terminal window
gem install asciichem
require "asciichem"
formula = AsciiChem.parse("2H_2 + O_2 ->[heat] 2H_2O")
formula.to_mathml # presentation MathML (L2 goldens)
formula.to_text # canonical AsciiChem text (round-trip)
formula.to_structural_svg # 2D structural diagram
# Structures from databases, straight into the same model
AsciiChem.parse_smiles("CC(=O)OC1=CC=CC=C1C(=O)O").to_structural_svg
mol = AsciiChem.parse_molfile(File.read("ethanol.mol")) # coordinates preserved
# Resolution: identifiers → substance records with provenance
substance = AsciiChem::Resolver.resolve(value: "50-78-2", convention: "cas")
substance.identifier_value("inchikey") # => "BSYNRYMUTXBXSQ-UHFFFAOYSA-N"
# Canonical wire form (asciichem-model v1)
AsciiChem.parse("H_2O").to_model_json

Parse / reject · L0 emission · L1 text · L2 MathML · SMILES · molfile · CML · linter — 100% of the shared corpus. See the Implementations matrix for the full table.

The gem carries the long tail of features that make the contract concrete, on the same parse engine as every other runtime:

  • All formatters — MathML, Text (the canonicaliser), HTML, LaTeX, SVG (typographic), StructuralSvg (2D layout), CML via the chemicalml gem, SMILES and molfile writers, and the canonical wire JSON.

  • The one parse engine — the gem parses on the PARG artifact engine: parsanol runs the checksummed artifact the Rust crate embeds, the TypeScript wasm engine consumes, and the Python engine loads. The legacy engines are gone (0.31.16, asciichem-ruby#161): the parslet parser and transform, the engine selector, the --engine flag, and the parslet gem dependency are deleted — there is no engine left to select.

    AsciiChem.parse("H_2O") # parsed by parsanol over the PARG artifact
  • Citations — AsciiChem::Citation.to_xml(substance) emits a dataset-type Relaton bibitem per resolved source. CLI: asciichem cite --cas 50-78-2. See Citing substances.

  • Resolution — AsciiChem::Resolver resolves identifiers into substance records against PubChem, OPSIN, and CAS Common Chemistry (all on by default; sources: limits the set; resolve! cross-checks InChIKeys). See Structures and resolution.

  • InChI identity — opt-in engines: the IUPAC inchi-1 binary (BinaryEngine) or the native Rust engine (NativeEngine over CHEMOMER_LIB), plus RInChI for reactions and the IdentityCrossCheck linter. CLI: asciichem identity -i .... See Local identity.

  • Beyond formulas — crystals, spectra, computational results, Z-matrices, reaction mechanisms all parse into the semantic model and round-trip.

  • The CLI — convert, lint, validate, resolve, cite, identity, roundtrip, parse-cml, version. The Rust crate ships the same eleven-command surface as the asciichem binary. See CLI reference.

The authoritative implementation is asciichem-rs; the gem is the Ruby doorway to the same contract — and the path into Metanorma publishing.

github.com/asciichem/asciichem-ruby — releases flow through trusted publishing (RubyGems OIDC, no stored credentials).

Play