Unit Conversion & Measurement

Convert between unit systems, handle ambiguous units, and use measurement conventions.

CalcMark knows about physical units — length, mass, volume, temperature, speed, energy, power, area, data sizes, force, impulse, pressure, acceleration, and frequency. You can convert between them with the in keyword, declare document-wide measurement conventions, and use inline qualifiers to be explicit about which definition you mean.

Try it now: Open the Unit Conversion example in Lark or run cm remote unit-conversion in the editor.


Key Features for This Domain #

FeatureWhat It DoesReference
in keyword10 meters in feet32.81 feetUnits
measurement: frontmatterDeclare which gallon, ounce, or ton you meanUnits
Inline qualifiers10 troy oz, 1 imp gal, 5 short tonUnits
Strict annotationOutput shows 2 us oz so readers know which definition is activeLanguage Reference
convert_to: si / imperialConvert all quantities in the document to a target systemFrontmatter
number()Strip units for dimensionless ratios: number(10 kg) / number(5 kg)2Language Reference

The Ambiguity Problem #

Some unit names have different definitions depending on country or domain:

UnitUS CustomaryImperial (UK)Difference
gallon3.785 L4.546 L~20%
pint473 mL568 mL~20%
fluid ounce29.6 mL28.4 mL~4%
cup240 mL284 mL~18%
UnitStandard (avoirdupois)Troy (precious metals)Difference
ounce28.35 g31.10 g~10%
pound453.6 g373.2 g~18%
UnitShort (US)Long (Imperial)Metric
ton907 kg1,016 kg1,000 kg

By default, CalcMark uses US Customary. A 4% error on fluid ounces compounds across a recipe. A 20% error on gallons is the difference between a full tank and running out of fuel.


Declaring Your Convention #

Use measurement: in frontmatter to declare what you mean:

---
measurement:
  volume: imperial    # gallon, pint, fl oz → UK definitions
  mass: troy          # ounce, pound → precious metals
  ton: long           # ton → 2240 lb (Imperial)
---

Only specify axes that differ from US defaults. Each axis is independent — a UK jeweler might use volume: imperial with mass: troy.

What is “standard” mass? Standard means avoirdupois — the everyday weight system (1 oz = 28.35g, 1 lb = 16 oz). This is what your grocery store and bathroom scale use. Troy weight is only for precious metals and gemstones (1 troy oz = 31.10g, 1 troy lb = 12 troy oz).


Inline Qualifiers #

Override the document convention for a single expression:

gold = 10 troy oz in grams
milk = 2 imp pt in ml
cargo = 5 short ton in kg
us_milk = 1 us gal in liters
Results
gold = 10 troy oz in grams311 grams
milk = 2 imp pt in ml1,137 ml
cargo = 5 short ton in kg4,536 kg
us_milk = 1 us gal in liters3.79 liters

Prefixes: us, imp/imperial, troy, short, long, metric. These work regardless of frontmatter — always available.


How Directives Compose #

All three directives compose cleanly. Here’s how 1 gallon flows through each combination:

DirectivesResultWhat happened
(none)1 galUS gallon, default display
measurement: { volume: imperial }1 imperial gallonResolved as imperial
convert_to: si3.79 lUS gallon → liters
measurement: { volume: imperial } + convert_to: si4.55 lImperial gallon → liters
measurement: { volume: imperial } + scale: 3 + convert_to: si13.6 lImperial × 3 → liters
1 us gal (inline) + measurement: { volume: imperial }3.79 lInline overrides convention

Pipeline order: measurement (resolve names) → evaluatescale (multiply) → convert_to (change system) → annotate (strict mode display).