#Creating a cooking recipe

9 messages · Page 1 of 1 (latest)

neat coral
#

I am trying to write a cooking receipe with Typst.

= Slow-Cooker Brisket
#figure(
    table(
        align: (auto, auto, left, auto),
        columns: (auto, auto, auto, auto),
        [*Ingredient*], [*Amount*], [*Unit*], [*Optional?*],
        [Bourbon], [0.25], [cups], [False],
        [Dijon Mustard], [2], [tablespoons], [False],
        [Chilli Powder], [1], [tablespoons], [False],
        [Vegetable Oil], [1], [tablespoons], [True],
    ),
)

I want to write code so that I don't have to write the same preamble over and over. However the code below fails on one_ingredient, saying unexpected comma.

#let one_ingredient(str_ingredient, float_amount, str_unit, bool_isoptional) = {
    [#str_ingredient], [#float_amount], [#str_unit], [#bool_isoptional],
}

#let onerecipe(ingredient_array) = {
    figure(
        table(
            align: (auto, auto, left, auto),
            columns: (auto, auto, auto, auto),
            [*Ingredient*], [*Amount*], [*Unit*], [*Optional?*],
            for each_ingredient in ingredient_array {
                one_ingredient(each_ingredient.at(0), each_ingredient.at(1), each_ingredient.at(2), each_ingredient.at(3))
            }
        )
    )
}

= Slow-Cooker Brisket
onerecipe((("Bourbon", 0.25, "cups", False), ("Dijon Mustard", 2, "tablespoons", False), ("Chilli Powder", 1, "tablespoons", False), ("Vegetable Oil", 1, "tablespoons", True)))

Following that I rewrote my code eliminating one_ingredient but still got the same error.

#let onerecipe(ingredient_array) = {
    figure(
        table(
            align: (auto, auto, left, auto),
            columns: (auto, auto, auto, auto),
            [*Ingredient*], [*Amount*], [*Unit*], [*Optional?*],
            for each_ingredient in ingredient_array {
                [each_ingredient.at(0)], [each_ingredient.at(1)], [each_ingredient.at(2)], [each_ingredient.at(3))]
            }
        )
    )
}

How should I fix my code?

#

?r

= Slow-Cooker Brisket
#figure(
    table(
        align: (auto, auto, left, auto),
        columns: (auto, auto, auto, auto),
        [*Ingredient*], [*Amount*], [*Unit*], [*Optional?*],
        [Bourbon], [0.25], [cups], [False],
        [Dijon Mustard], [2], [tablespoons], [False],
        [Chilli Powder], [1], [tablespoons], [False],
        [Vegetable Oil], [1], [tablespoons], [True],
    ),
)
toxic skiff
#

?r ```
#let one_ingredient(str_ingredient, float_amount, str_unit, bool_isoptional) = {
([#str_ingredient], [#float_amount], [#str_unit], [#bool_isoptional],)
}

#let onerecipe(ingredient_array) = {
figure(
table(
align: (auto, auto, left, auto),
columns: (auto, auto, auto, auto),
[Ingredient], [Amount], [Unit], [Optional?],
..for each_ingredient in ingredient_array {
one_ingredient(each_ingredient.at(0), each_ingredient.at(1), each_ingredient.at(2), each_ingredient.at(3))
}
)
)
}

= Slow-Cooker Brisket
#onerecipe((("Bourbon", 0.25, "cups", false), ("Dijon Mustard", 2, "tablespoons", false), ("Chilli Powder", 1, "tablespoons", false), ("Vegetable Oil", 1, "tablespoons", true)))

toxic skiff
#

What this does is construct one array in the for loop then deconstruct it into arguments to table with the ..

neat coral
#

Thank you so much! One extra question: how do you override global align so that "Unit" is centered like the other items in the same row?

toxic skiff
#

align(center)[*Unit*] ?

neat coral
#

thank you!