Skip to content

Intermediate variables

In complex recipes, you often create sub-components (like a dough, a sauce, or a frosting) that are then used in later steps. Gram allows you to declare these sub-components as Intermediate Variables.

Once declared, an intermediate &variable acts exactly like an @ingredient, allowing you to reference it, measure it, or calculate percentages from it.

You can declare a &variable using the ->& syntax. There are two places you can declare them: at the end of a Step, or at the end of a Section Title.

When placed at the very end of a step (a paragraph), the &variable captures everything produced in that specific step.

[Add] @flour{200g} and @water{100ml}. Mix until combined. ->&dough

[Rest] Let the &dough rest for ~_{1h}.

When placed at the end of a ## Section title, the &variable captures the output of the entire section. This is perfect for components that take several steps to prepare.

## Puff Pastry ->&puff pastry{}

[Mix] @flour{250g}, @water{120ml}, and @salt{5g}.

[Rest] In the #fridge for ~_{1h}.

[Incorporate] The @butter{200g} by folding the dough multiple times.

// The `&puff pastry` variable now contains the final result of all the steps above!

To use a previously declared &variable, simply reference it with &.

Use the &puff pastry{} to line the tart tin.

You can also assign a quantity to it for display purposes in the rendered recipe:

Take &puff pastry{200g} and roll it out.

When a &variable is declared at the Section-level, it is registered in the Global Scope. This means you can declare a &variable in the first section of your recipe and safely reference it in the last section.

As detailed in the Relative Quantities documentation, you can calculate the mass of an ingredient based on the total mass of an intermediate variable.

[Mix] The ingredients to form the dough. ->&dough

[Add] @salt{2% &dough}.

The compiler helps you maintain clean and conflict-free code by emitting specific warnings:

  • Scope Conflict: If you accidentally declare the same &variable name twice in different ## Section blocks, the compiler will issue a SCOPE_CONFLICT warning.
  • Unused Variable: Any &variable that is declared using ->& must be used later in the recipe. If you declare a &variable but never reference it, the compiler will trigger a warning to help you keep your recipe code clean.