CLI reference
The asciichem CLI provides conversion, linting, identity, resolution,
citation, and round-trip verification. The same eleven-command surface
ships twice: with the Ruby gem (gem install asciichem) and as the
Rust crate’s asciichem binary (asciichem-rs —
crates.io publication pending; build from source today). The exit
codes are identical by contract.
The full command list is also one keystroke away:
asciichem help # the command listasciichem help convert # options for one commandasciichem tree # compact command treeconvert
Section titled “convert”Convert AsciiChem source to an output format.
asciichem convert -i "H_2O" -t mathmlasciichem convert -i "2Na+ + SO_4^2- -> Na_2SO_4" -t cmlasciichem convert -f input.asciichem -t htmlecho "H_2O" | asciichem convert -i - -t latexOptions
Section titled “Options”| Flag | Description |
|---|---|
-i, --input | Source text (or - for stdin) |
-f, --file | Read source from a file |
-t, --format | Output format: mathml (default), text, html, latex, svg, structural-svg, model-json, cml, smiles, molfile |
--from | Input grammar: asciichem (default), smiles, molfile |
Parsing runs on the one engine everywhere: parsanol over the
checksummed PARG artifact of the grammar. The engine-selection
machinery is gone from the Ruby CLI — the --engine flag, the
ASCIICHEM_ENGINE variable, and the legacy engines themselves (the
Ruby parslet parser, the TS peggy port, the Python rd port) are
deleted. The Rust binary still accepts --engine parsanol as a
compatibility no-op; any other value exits 6.
Input grammars
Section titled “Input grammars”Since 0.22.0, convert selects the input grammar with --from asciichem|smiles|molfile,
and the output targets include model-json, smiles, molfile, and structural-svg:
asciichem convert -i "CCO" --from smiles -t structural-svgasciichem convert -f ethanol.mol --from molfile -t model-jsonasciichem convert -i "CC(=O)OC1=CC=CC=C1C(=O)O" --from smiles -t smiles # canonical re-emissionEvery grammar funnels into the one semantic model, so every output
format works regardless of input language. Molfile input may be a
file path (multiline text via -f).
resolve
Section titled “resolve”Resolves an identifier into a substance record from one resolver
source (networked; cached in your user cache directory with a 7-day
TTL). Give exactly one of --cas, --name, --cid, --inchikey,
or --smiles:
asciichem resolve --name aspirin --source pubchem -t model-jsonasciichem resolve --cas 50-78-2 --refresh # bypass the cacheasciichem resolve --cas 50-78-2 --source common_chemistry -t smiles--source picks the source (pubchem is the default; opsin
answers IUPAC names, common_chemistry answers CAS numbers), and
-t picks the output (model-json, text, or smiles). Every
result carries per-identifier provenance including the source’s
required attribution. In the library, all shipped sources are on by
default and resolved together — see
Structures and resolution.
Resolves an identifier and emits a dataset-type Relaton bibitem (XML) for the source it was resolved from — the same code path the Metanorma plugin uses, so a document and the command line can never disagree:
asciichem cite --cas 50-78-2# <bibitem id="PubChemCID2244" type="dataset"> …Options match resolve (--cas/--name/--cid/--inchikey/--smiles,
--source, --refresh). One bibitem per (substance, source); the
field-by-field shape is on
Citing substances.
validate
Section titled “validate”Offline validation of identifier annotations in a formula:
asciichem validate -i 'H_2O @cas("7732-18-5")'# cas 7732-18-5 okidentity
Section titled “identity”Derives InChI and InChIKey from the structure itself — offline, via
the configured InChI engine (the IUPAC inchi-1 binary or the
native Rust engine; the InChI algorithm is never reimplemented):
asciichem identity -i "CC(=O)OC1=CC=CC=C1C(=O)O" --from smiles# InChI=1S/C9H8O4/c1-6(10)13-8-5-3-2-4-7(8)9(11)12/h2-5H,1H3,(H,11,12)# BSYNRYMUTXBXSQ-UHFFFAOYSA-N
asciichem identity -i "..." --engine-bin /usr/local/bin/inchi-1--from selects the input grammar (asciichem, smiles, or
molfile); the formula must contain exactly one molecule.
--engine-bin points at an inchi-1 binary for this invocation.
Without any engine the command exits 5 with install guidance — see
Local identity for every engine option,
including the native Rust engine driven through CHEMOMER_LIB. In
Ruby, register one globally:
AsciiChem::Inchi.engine = AsciiChem::Inchi::BinaryEngine.newAsciiChem::Inchi.identity_for(molecule)With an engine configured, asciichem lint cross-checks @inchi and
@inchikey annotations against the drawn structure
(IdentityCrossCheck).
Run chemistry validation checks. Exits 1 if any errors found.
asciichem lint -i "H_2 + O_2 -> H_2O"asciichem lint -i "crystal[x](a=-1){Na@f(0,0,0)}" -f jsonOptions
Section titled “Options”| Flag | Description |
|---|---|
-i, --input | AsciiChem source text |
-f, --format | Output format: text (default) or json |
JSON output is an array of {severity, message, node} objects. The
checks behind it are on the Linter page.
roundtrip
Section titled “roundtrip”Parse and re-emit text; exit non-zero if output differs from input.
asciichem roundtrip -i "H_2O"parse-cml
Section titled “parse-cml”Parse CML XML and emit AsciiChem text.
asciichem parse-cml -i "<cml xmlns=\"http://www.xml-cml.org/schema\">...</cml>"version
Section titled “version”asciichem versionasciichem --version # or -vExit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
| 0 | Success (also: lint clean, validate with no invalid identifiers) |
| 1 | Parse error; lint found errors; roundtrip mismatched; validate found an invalid identifier |
| 2 | Unknown output format (convert -t) |
| 3 | Resolve error (unknown source, no answer) |
| 4 | Cite error |
| 5 | Identity error (including no engine configured) |
| 6 | Parsing-engine value rejected (Rust binary only; --engine other than parsanol) |