Skip to content

Citing substances

A molecule in a standards document is a substance with identity, not glyphs. AsciiChem closes that loop: resolve an identifier, then emit a dataset-type Relaton bibitem for the source you choose to cite.

substance = AsciiChem::Resolver.resolve(value: "50-78-2", convention: "cas")
xml = AsciiChem::Citation.to_xml(substance) # Relaton <bibitem type="dataset">

From the CLI:

Terminal window
asciichem cite --cas 50-78-2

A bibitem can only be built from a resolved substance — the resolver’s provenance (source, retrieved-at, attribution) is what the citation is made of. Ask a hand-built substance for a bibitem and the builder tells you to resolve it first.

Attach the citation intent to the molecule itself. The @cite property annotation names the source you want to cite, and the molecule’s other identifiers say who to resolve it as:

Source Rendered
CC(=O)OC1=CC=CC=C1C(=O)O @cas("50-78-2") @cite("pubchem")
Install the asciichem gem to see this rendered.

Then the bibitem is a function of the parse tree:

molecule = AsciiChem.parse(source).nodes.first
AsciiChem::Citation.for_molecule(molecule)
# => [["pubchem", #<Relaton::Bibitem ...>]]

for_molecule resolves via the strongest identifier available (@cas, @inchikey, @inchi/@smiles, then names) and returns one [source, bibitem] pair per cited source. Annotate once, cite anywhere — the citation follows the molecule through every format.

This is the real output for aspirin resolved from PubChem (whitespace as emitted):

<bibitem id="PubChemCID2244" type="dataset">
<title type="main">2-acetyloxybenzoic acid - PubChem, U.S.
National Library of Medicine substance record</title>
<uri type="src">https://pubchem.ncbi.nlm.nih.gov/compound/2244</uri>
<docidentifier type="pubchem">PubChem CID 2244</docidentifier>
<date type="accessed">
<on>2026-11-03</on>
</date>
<contributor>
<role type="publisher"/>
<organization>
<name>PubChem, U.S. National Library of Medicine</name>
</organization>
</contributor>
<keyword><vocab>pubchem-cid=2244</vocab></keyword>
<keyword><vocab>inchikey=BSYNRYMUTXBXSQ-UHFFFAOYSA-N</vocab></keyword>
<keyword><vocab>inchi=InChI=1S/C9H8O4/...</vocab></keyword>
<keyword><vocab>canonical-smiles=CC(=O)OC1=CC=CC=C1C(=O)O</vocab></keyword>
</bibitem>

Every field answers a data-citation question (who published this, what exactly, where, as of when) — and the keywords carry every identifier the source returned, so a citation stays machine-checkable against its InChIKey long after a URL changes.

Per source, the fields differ the way two documents about one substance differ:

FieldPubChemCAS Common Chemistry
PublisherPubChem, U.S. National Library of MedicineCAS Common Chemistry
Titlename - PubChem, U.S. National Library of Medicine substance recordname - CAS Common Chemistry substance record
DocidentifierPubChem CID 2244CAS RN 50-78-2
Source linkpubchem.ncbi.nlm.nih.gov/compound/{cid}commonchemistry.cas.org/detail?cas_rn={rn}
Versionaccessed date, from the record’s provenanceaccessed date, from the record’s provenance
Extra identifiersCID, InChIKey, InChI, canonical SMILESCAS RN, InChIKey, canonical SMILES, InChI, IUPAC name

Adding a source means adding one citation profile next to its resolver adapter — the builder itself never changes.

Two databases agreeing on a substance are still two different documents. Resolution is multi-source; citation is per-source — pick the sources you trust, cite each once. The same substance cited twice from one source yields one deduplicated entry; the same substance cited from two sources yields two entries, both describing the same molecule.

Deduplication and cross-referencing anchor on the InChIKey — the fixed-length, structure-derived identifier that plays the role for substances that the DOI plays for literature. In Metanorma documents the plugin rewrites each bibitem’s anchor to its InChIKey (BSYNRYMUTXBXSQ-UHFFFAOYSA-N above), so <<BSYNRYMUTXBXSQ-UHFFFAOYSA-N>> cross-references work regardless of which source was cited, and two documents citing the same substance from different databases still link to the same identity.

Every resolved record carries its provenance — source, retrieved-at timestamp, license attribution — and the bibitem’s accessed date comes straight from that provenance. Resolution caches records in your user cache directory (never inside the gem), with a 7-day TTL; --refresh bypasses it.

That makes document builds reproducible: point a Metanorma document at a seeded cache (:asciichem-cache-dir:, see Chemistry in Metanorma) and every rebuild emits byte-identical bibitems — the accessed dates come from the cached records, not from the wall clock.

Which source you cite is also a licensing decision:

  • PubChem and OPSIN are on by default: keyless access, permissive terms.
  • CAS Common Chemistry is also on by default (maintainer decision, 2026-11-11): its data is CC BY-NC 4.0 — non-commercial reuse with attribution — judged acceptable as a default, with the obligation carried automatically and an escape hatch for documents that must stay NC-free:
# all shipped sources (PubChem, OPSIN, Common Chemistry) are registered
AsciiChem::Resolver.resolve(value: '50-78-2', convention: 'cas')
# limit the set when your use requires it
AsciiChem::Resolver.resolve(value: '50-78-2', convention: 'cas',
sources: [:pubchem, :opsin])

Live availability. CAS key-gated the Common Chemistry API: anonymous calls answer 401 Unauthorized. The token is the user’s to provide — request one at cas.org/services/commonchemistry-api (valid 12 months; CAS emails a renewal notice) and either export it as COMMON_CHEMISTRY_API_KEY or store it at ~/.config/cas-common-chemistry-api.key (asciichem 0.31.15 sends it as the X-API-KEY header on the /direct-api endpoint, exactly as CAS’s access email specifies). Without a token, live lookups against common_chemistry return no record: the resolver skips the source (a failing source never poisons the others), documents warn and emit no bibitem, and seeded-cache records keep resolving offline. Resolution continues against PubChem and OPSIN. There is no bulk-download or GitHub copy of the Common Chemistry dataset — the API and the web UI are CAS’s only distribution channels, and the CC-derived records PubChem mirrors resolve key-free through PubChem itself, with PubChem provenance.

The obligations ride with the data, and the gem is built so you can meet them: the required attribution (CAS Common Chemistry (CC BY-NC 4.0)) rides in every record’s provenance — including cached records — and into every emitted bibitem as a type="provenance" note, so whatever you publish downstream still carries it. Keep that attribution intact when you redistribute. If the NC terms don’t fit your use, limit sources (in Ruby with sources:, or in Metanorma documents with the :asciichem-sources: attribute — see Chemistry in Metanorma); PubChem’s record for the same substance remains available either way.

Results are cached in your user cache directory (TTL’d, attribution included); --refresh bypasses the cache.

In a Metanorma document

@cite-annotated molecules become bibliography entries automatically — Chemistry in Metanorma.

Try it live

Paste a database SMILES and see the model — the playground parses SMILES and molfile in your browser.

Play