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_3produces Conditions(above: "Fe", below: "400°C").
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.