Project

asciichem

0.0
The project is in a healthy, maintained state
AsciiChem is an ASCII syntax for representing chemical formulae, reactions, electron configurations, bonds, crystals, spectra, calculations, Z-matrices, and reaction mechanisms. It parses to a semantic model and renders to MathML, HTML, LaTeX, SVG, and CML. Math embedding uses Plurimath. Round-trips to native CML via chemicalml.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

Runtime

~> 2.0
~> 1.3
~> 2.3
~> 0.5
~> 0.11
~> 2.0
 Project Readme

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 asciichem

Usage

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 roundTrip fixture returns its input

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.