Ingredients
Ingredients are the core building blocks of any Gram recipe.
Basic declaration
Section titled “Basic declaration”To declare an @ingredient, use the @ symbol. If the @ingredient name contains spaces or requires a specific quantity, you must append the quantity inside {} braces. If it is a single word without a specific quantity, the braces are optional (the quantity defaults to 1).
To specify a unit of measurement (weight, volume, etc.), add it directly after the numeric value inside the braces, separated by an optional space.
A unit can be several words ({2 tablespoons}) and can contain dots or apostrophes ({1 c.à.s}, {1 c. à s.}). Common spellings of the same unit are recognized as equivalent: c.à.s, c.a.s and càs all mean tablespoon in French.
Scaling & fixed quantities
Section titled “Scaling & fixed quantities”By default, the Gram Compiler scales an @ingredient linearly based on the number of portions requested.
If you scale a recipe from 2 to 4 portions, an @ingredient with {100g} becomes {200g}.
Fixed quantities (=)
Section titled “Fixed quantities (=)”Some @ingredient items (like salt, yeast, or spices) should not scale linearly. You can lock their quantity using the = modifier.
This keeps the salt at 1 tsp regardless of how many portions the user calculates.
Ingredient modifiers
Section titled “Ingredient modifiers”Gram provides several modifiers to alter how an @ingredient behaves in the parser and the shopping list. Modifiers are placed immediately after the @ symbol.
| Modifier | Name | Effect |
|---|---|---|
& | Reference | References an @ingredient previously declared. Does NOT add it to the shopping list again. |
= | Fixed | Marks the quantity as fixed (it will not scale with portions). |
? | Optional | Marks the @ingredient as optional. |
- | Hidden | Hides the @ingredient from the generated shopping list. |
* | Baker’s % | Marks the @ingredient as the reference (100%) to calculate baker’s percentages. |
Optional and hidden modifiers (?, -)
Section titled “Optional and hidden modifiers (?, -)”Use ? to mark an @ingredient as optional — useful for garnishes or substitutions the cook may skip. Use - to hide an @ingredient from the generated shopping list entirely, e.g. something you always have on hand.
The reference modifier (&)
Section titled “The reference modifier (&)”The reference modifier is crucial for multi-step recipes. As a best practice, any time you mention an @ingredient after its initial declaration, you should use the & modifier.
The compiler’s behavior changes depending on whether you provide a new quantity with your reference:
- Pure Reference (No Quantity)
When instructing the user to use an already declared
@ingredient, use@&so it isn’t counted twice in the shopping list.
- Additive Reference (With Quantity)
Sometimes you need to use the same
@ingredientmultiple times with different additions throughout the recipe. Using@&ingredient{qty}tells the compiler: “This is the same@ingredient, please add this extra quantity to the total shopping list.”
Baker’s percentage (*)
Section titled “Baker’s percentage (*)”In baking, recipes are often built around the Baker’s Percentage, where the main @ingredient (usually flour) represents 100%, and all other items are expressed as a percentage of that weight.
Gram provides a dedicated modifier to mark the reference @ingredient. By placing a * after the @ symbol, you tell the Gram Compiler: “This is the 100% reference point”.
This allows tools (like the CLI or web renderers) to automatically calculate and display the baker’s percentages for all other items (e.g., Water: 70%, Salt: 2%) without you having to define them manually as relative quantities.
Advanced syntax
Section titled “Advanced syntax”Short-hand preparations
Section titled “Short-hand preparations”Often, an @ingredient requires preparation before use. You can define this directly within the declaration using parentheses ().
Component alias (renaming)
Section titled “Component alias (renaming)”You can rename an @ingredient for display purposes using a colon : immediately after the real name. This is useful for keeping the shopping list clean while using a colloquial name in the instructions.
Format: @Real Name:Display Name{Quantity}
The shopping list will aggregate this under “dry white wine”, but the rendered recipe will just say “wine”.
Alternatives (substitutions)
Section titled “Alternatives (substitutions)”You can define acceptable alternatives for an @ingredient using the pipe | operator.
This works with short-hand preparations as well:
Ranges
Section titled “Ranges”Recipes aren’t always exact. You can specify a range using a hyphen -.
Fractions
Section titled “Fractions”Quantities accept fractions in three forms — a plain fraction, a mixed number, or a Unicode fraction glyph — all normalized to the same decimal value.
Decimal numbers
Section titled “Decimal numbers”Decimals accept either a period or a comma: {1.5 kg} and {1,5 kg} mean the same thing. This applies to every number inside braces—ingredients, ranges ({0,5-0,75 l}), relative quantities ({12,5% &dough}), cookware, temperatures (^{37,5°C}), timers, and section anchors.
Sums of quantities
Section titled “Sums of quantities”When a measurement combines more than one unit, write it as a sum with +, or - for an amount subtracted:
Each term is a quantity (number, range, or fraction) with its unit. Gram preserves the sum as written in the unscaled recipe, and recomputes it into practical kitchen measures when scaling (for example, doubling {1 cup + 1 tbsp} gives 2 cup + 2 tbsp). Adding = locks the entire sum (@=salt{1,5 g + 1 pinch}).
In the shopping list, a sum behaves like separate mentions of the ingredient: compatible units add up (cups and spoons, grams and kilograms), while a volume and a weight ({1 cup + 20 g}) or unrecognized units stay side by side.
A few rules keep sums unambiguous:
- Every term needs a unit:
{1 + 1 cup}is rejected. - Plain quantities only: no percentages (
{100 g + 10%}) or multiplications ({2 x 100 g}). - Subtract within the same kind:
{1 cup - 2 tbsp}works,{1 cup - 20 g}does not, and the result must remain positive ({1 tbsp - 1 cup}is rejected). - No range after
-: put ranges on added terms ({1 cup + 1-2 tbsp}), never subtracted ones.
An invalid sum still compiles with an INVALID_QUANTITY warning explaining why, and is excluded from shopping list and nutrition totals. See Scaling sums of quantities for details.
Error handling
Section titled “Error handling”Some syntax errors stop parsing before compilation: an unreadable quantity in braces (such as @salt{1/2/3}) or an unclosed brace. The error points to the exact spot to fix.
The compiler checks for semantic errors in your @ingredient declarations and emits structured warnings:
- Invalid Modifier: Combining incompatible modifiers (like
?*) triggersINVALID_MODIFIER_COMBINATION. - Undefined Reference: Using a reference (
@&ingredient) before it has been declared triggersUNDEFINED_REFERENCE. - Database Missing: An
@ingredientmissing from the supplied database triggersMISSING_INGREDIENT. - Missing Macros: An entry without nutritional information triggers
MISSING_MACROS. - Unknown Mass: A volume or count that cannot be converted into grams triggers
UNKNOWN_MASS. - Invalid Quantity / Ambiguous Number: Malformed sums trigger
INVALID_QUANTITY, and a comma followed by three digits ({1,000 g}) triggersAMBIGUOUS_NUMBER.