asciichemRuby
asciichemasciichemgem install asciichemQuick start
Section titled “Quick start”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 modelAsciiChem.parse_smiles("CC(=O)OC1=CC=CC=C1C(=O)O").to_structural_svgmol = AsciiChem.parse_molfile(File.read("ethanol.mol")) # coordinates preserved
# Resolution: identifiers → substance records with provenancesubstance = 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_jsonClaimed levels
Section titled “Claimed levels”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.
What you get here
Section titled “What you get here”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
--engineflag, 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::Resolverresolves 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-1binary (BinaryEngine) or the native Rust engine (NativeEngineoverCHEMOMER_LIB), plus RInChI for reactions and theIdentityCrossChecklinter. 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 theasciichembinary. 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.
Repository
Section titled “Repository”github.com/asciichem/asciichem-ruby — releases flow through trusted publishing (RubyGems OIDC, no stored credentials).