Reaction
A reaction captures a chemical transformation: reactants, an arrow type, products, and optional conditions rendered above and below the arrow per IUPAC.
Fields
Section titled “Fields”| Field | Type | Source | Example |
|---|---|---|---|
reactants | Array of Molecule | left of arrow | 2H_2 + O_2 |
products | Array of Molecule | right of arrow | 2H_2O |
arrow | Symbol | arrow token | :forward, :equilibrium, … |
conditions | Conditions struct | [above][below] | Conditions(above: "Fe", below: "400°C") |
Arrow kinds
Section titled “Arrow kinds”| Symbol | ASCII | Unicode | Use |
|---|---|---|---|
:forward | -> | → | Net forward |
:reverse | <- | ← | Net reverse |
:equilibrium | <=> | ⇌ | Equilibrium (Haber, acid/base) |
:resonance | <-> | ↔ | Resonance structures |
Diagram
Section titled “Diagram” ┌───────────────┐ │ Reaction │ │ │ reactants[0] ─┐ │ reactants[1] ─┤── left │ above ... ─┘ │ ▲ ──────────►│ ──── ⇌ ──── │ ▼ products[0] ─┐ │ below products[1] ─┤── right │ ... ─┘ │ └───────────────┘Conditions
Section titled “Conditions”Conditions sit in bracketed groups immediately after the arrow. The first bracket is the above condition (catalyst), the second is the below condition (temperature / pressure / solvent).
N_2 + 3H_2 <=>[Fe][400°C] 2NH_3asciichem gem to see this rendered.
produces Conditions(above: "Fe", below: "400°C").
Structured role entries
Section titled “Structured role entries”A condition entry may name its role explicitly — the bracket text stays verbatim, and the model derives typed entries from it:
C_6H_5Br + C_6H_5B(OH)_2 ->[cat: Pd; base: Na_2CO_3][solv: THF] C_12H_10asciichem gem to see this rendered.
- Recognised prefixes:
cat/catalyst,solv/solvent,reag/reagent. ;separates entries inside one bracket; an entry without a recognised prefix stays free text (base: Na_2CO_3above keeps its full text as a free entry).Conditions#entriesreturnsEntry(role:, value:, side:); the bracket text itself remains the canonical round-trip source, so the wire form is unchanged.ReactionRoles.roles_forprefers explicit roles and falls back to the above/below convention only for free text.
Stoichiometry
Section titled “Stoichiometry”Coefficients are model data: Reaction#stoichiometry returns the
normalized per-side mapping of coefficient-free species text to
integer coefficient (2H_2 + O_2 -> 2H_2O →
{ reactants: { "H_2" => 2, "O_2" => 1 }, products: { "H_2O" => 2 } }).
Molecule#stoichiometric_coefficient is the single coefficient rule
shared by the reaction, the balance check, and composition counting.
Grammar production
Section titled “Grammar production”reaction := terms arrow termsterms := molecule ("+" molecule)*arrow := "<=>" | "<->" | "->" | "<-" (with optional [above] and [below] conditions)Formatter behaviour
Section titled “Formatter behaviour”| Formatter | Arrow rendering | Conditions |
|---|---|---|
| MathML | <mo>⇌</mo> (or <mover>/<munderover> with conditions) | <mtext> |
| Text | ASCII spelling | [above][below] |
| HTML | Unicode arrow | <sup> / <sub> around the arrow |
| LaTeX | mhchem arrow | [above][below] (mhchem native) |
| SVG | ASCII arrow | [above][below] |
Round-trip
Section titled “Round-trip”AsciiChem.parse("2H_2 + O_2 -> 2H_2O").to_text # => "2H_2 + O_2 -> 2H_2O"AsciiChem.parse("N_2 + 3H_2 <=>[Fe][400°C] 2NH_3").to_text # => sameAsciiChem.parse("HAc <=> Ac^- + H^+").to_text # => sameLinter checks
Section titled “Linter checks”- BalanceCheck — atom counts must match on both sides, respecting coefficients and group multiplicities.
Cascade promotion
Section titled “Cascade promotion”Single-step reactions stay as Reaction. Two or more reactions
chained (A -> B -> C) promote to a
ReactionCascade.