Skip to content

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:

Terminal window
asciichem help # the command list
asciichem help convert # options for one command
asciichem tree # compact command tree

Convert AsciiChem source to an output format.

Terminal window
asciichem convert -i "H_2O" -t mathml
asciichem convert -i "2Na+ + SO_4^2- -> Na_2SO_4" -t cml
asciichem convert -f input.asciichem -t html
echo "H_2O" | asciichem convert -i - -t latex
FlagDescription
-i, --inputSource text (or - for stdin)
-f, --fileRead source from a file
-t, --formatOutput format: mathml (default), text, html, latex, svg, structural-svg, model-json, cml, smiles, molfile
--fromInput 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.

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:

Terminal window
asciichem convert -i "CCO" --from smiles -t structural-svg
asciichem convert -f ethanol.mol --from molfile -t model-json
asciichem convert -i "CC(=O)OC1=CC=CC=C1C(=O)O" --from smiles -t smiles # canonical re-emission

Every 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).

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:

Terminal window
asciichem resolve --name aspirin --source pubchem -t model-json
asciichem resolve --cas 50-78-2 --refresh # bypass the cache
asciichem 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:

Terminal window
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.

Offline validation of identifier annotations in a formula:

Terminal window
asciichem validate -i 'H_2O @cas("7732-18-5")'
# cas 7732-18-5 ok

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):

Terminal window
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.new
AsciiChem::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.

Terminal window
asciichem lint -i "H_2 + O_2 -> H_2O"
asciichem lint -i "crystal[x](a=-1){Na@f(0,0,0)}" -f json
FlagDescription
-i, --inputAsciiChem source text
-f, --formatOutput format: text (default) or json

JSON output is an array of {severity, message, node} objects. The checks behind it are on the Linter page.

Parse and re-emit text; exit non-zero if output differs from input.

Terminal window
asciichem roundtrip -i "H_2O"

Parse CML XML and emit AsciiChem text.

Terminal window
asciichem parse-cml -i "<cml xmlns=\"http://www.xml-cml.org/schema\">...</cml>"
Terminal window
asciichem version
asciichem --version # or -v
CodeMeaning
0Success (also: lint clean, validate with no invalid identifiers)
1Parse error; lint found errors; roundtrip mismatched; validate found an invalid identifier
2Unknown output format (convert -t)
3Resolve error (unknown source, no answer)
4Cite error
5Identity error (including no engine configured)
6Parsing-engine value rejected (Rust binary only; --engine other than parsanol)
Play