かんたんな説明
家庭料理の本の2ページで、1ページに1品ずつ載せています。材料と調理の手順を1枚のカードの上に左右に並べる方法を示します。
できあがり
架空のスペイン家庭料理の本『Salt & Olive Oil』の見開き2ページです。仕上がりは190×250mmで、1ページに1品を載せます。拡散モデルで生成し、JPEGとして読み込んだ写真が上部104mmに裁ち落としで入ります。サフラン色のテーブルにひと切れ取り分けたトルティージャ、セージ色のテーブルにガスパチョのボウルです。写真の上には、見出し前置き、42ptのYoung Serifの題、所要時間・難易度・季節を示す角丸のラベル、料理を指すCaveatの手書き風のメモが載ります。イタリックのリード文の下には白いカードがあり、右上の角にトマトの赤の人数のタブが付きます。カードの左の段には材料がオリーブ色のダッシュとタグのチップとともに並び、トルティージャの材料の下ではボウル、フライパン、皿の線画がチェックリストの頭に付きます。作り方は右の段を埋め、各手順の頭には26ptのオールドスタイル数字が付きます。
このレシピが答える質問
- 囲みの中を2段にするには(本文の段と図の段を並べる)?
- 番号付きのタブ(「BOX 1-1」)、角のアイコン、罫線付きの余白のアイコンを加えるには?
- リストをカスタマイズするには(レベルごとの記号、(a)/(i)の番号、タスクのチェックボックス、グリッドに乗る間隔)?
- キーボードのキー、タグ、練習問題の語群などのインラインのチップを作るには?
- 章扉に著者名の行、リード文、ドロップキャップ付きの導入文を加えるには?
手短な答え
// In the Markdown, :::callout{type="card" label="SERVES 4"} holds a :::columns{count=2} group
// of two nested boxes, :::callout{type="column" title="Ingredients"} and one for the method.
// The group levels its columns by cutting between blocks or lines, so loose lists would run
// the method on under the ingredients. A nested box is one block that never splits, so the
// only cut left is between the two.
const TAB = 5.6; // mm: the tab's height, and how far it rises above the card
const card = { id: 'card', background: col('card'),
padding: { top: mm(4.5), right: mm(6), bottom: mm(5), left: mm(6) },
// No space of its own above: the tab starts on the first grid line under the opener.
columnGap: mm(7), marginTop: mm(0),
// label="…" on the fence prints here: a tab on the top-right corner, a cutlery pictogram
// beside it and a rule from the far corner that makes the tab part of the card.
label: { fontFamily: TEXT, fontSize: pt(8), color: col('card'), // bold by default
background: col('tomato'), height: mm(TAB), offset: mm(TAB), paddingX: mm(2.6),
icon: { resourceId: 'cutlery', width: mm(TAB * 6 / 8), gap: mm(1.6) }, // as tall as the tab
rule: { enabled: true, color: col('tomato'), width: pt(1.2) } } };
// The two columns: frameless boxes whose only device is a tracked title.
const NONE = { top: mm(0), right: mm(0), bottom: mm(0), left: mm(0) };
const column = { id: 'column', backgroundEnabled: false, padding: NONE,
lists: { gap: mm(2.2), itemSpacing: pt(3.5) }, // for the steps as well as the dashes
titleStyle: { fontFamily: TEXT, fontSize: pt(8), color: col('tomato'), // bold by default
textTransform: 'uppercase', letterSpacing: pt(1.5), gap: mm(2.4) } };
// config() plugs them in: calloutStyles: [card, column, prep].
材料
- 機能
- 囲みの中や本文中の段組み番号付きの囲みのタブ番号付きリスト入れ子の囲み囲みのアイコンと角のバッジインラインのチップ箇条書きとチェックリスト囲みデザインした章扉段抜きの章見出し帯見出しスタイル見出しの属性ページデザインのテキスト・罫・ボックスページデザインの画像タイトル内の改行用紙の色柱とノンブルセマンティックカラーパレット段落スタイルリソースとしての図と表
- 種類
- Young Serif, Figtree, Caveat (SIL OFL 1.1)
- 素材
gazpacho-1520.jpgtortilla-1520.jpg- The tortilla on its plate, a photograph (Generated With Diffusion Models, オリジナル)
- The bowl of gazpacho, a photograph (Generated With Diffusion Models, オリジナル)
- The note’s arrow and the pictograms, drawn in code in the page’s palette (Ignacio Ferro, CC BY 4.0)
作り方
#1 · 段ごとに専用の囲みを与える
リストをそのまま並べると、囲みの中の段組みは段の高さがいちばんそろう位置で切ります。ブロックの間でも、1つのブロックの行の間でも切るので、ガスパチョの最初の手順が段間をまたいで分かれてしまいます。1行目が材料の段の最後に入り、残りが作り方の段の頭に来るのです。前に掲げた手短な答えのように入れ子にした囲みは1つのブロックなので、段組みがその中で切れることはありません。入れ子の囲みの中に置く画像には、placementを'here'にした::resourceが必要です。それ以外のplacementではフロートになり、囲みを離れて、引用されたほかの図と同じように配置されます。カードのスタイルのlabelが、囲みの記述にあるlabel="SERVES 4"をタブにします。heightと同じoffsetでタブをカードの上辺に立たせ、ruleが反対側の角からフォークとナイフまで伸びます(囲みスタイル)。
#2 · 手順番号を2行の中央に置く
// Young Serif has old-style figures: 1 and 2 stand 0.56 em, a little above its 0.50 em
// x-height, so 5.1 mm at STEP. A list number is centred 0.3 em (of the text) above the item's
// first baseline, with the canvas 'middle' baseline, which Chrome puts 0.24 em above Young
// Serif's own (gotcha: list-number-centred). DROP centres the figures on the step's first two
// lines, from the cap height of the first to the baseline of the second.
const [STEP, FIGURE, MIDDLE, CAP] = [26, 0.56, 0.24, 0.7]; // pt; em of each face
const DROP = (LEAD - CAP * BODY) / 2 + 0.3 * BODY + (FIGURE / 2 - MIDDLE) * STEP; // pt
const orderedLists = { fontFamily: DISPLAY, fontWeight: 400, // Young Serif ships 400 only
numberFontSize: pt(STEP), color: col('tomato'),
separatorColor: col('olive'), separatorGap: pt(0.6), // the default '.' as its own run
numberVerticalOffset: pt(DROP) };
リストの番号は、項目の1行目のベースラインより少し上を中心にして描かれます。そのためnumberFontSizeだけでは26ptの数字が1行目と同じ高さになります。numberVerticalOffsetで2.5mm下げ、1行目の大文字の上端から2行目のベースラインまでの帯の中央に置きます。Young Serifの数字はオールドスタイルで、3、4、5は1と2が載るベースラインより下に突き出ます。separatorColorを設定すると区切りは独立した文字列として描かれ、既定のピリオドは赤い数字の横でオリーブ色に印刷されます(番号付きリスト)。
#3 · 線画の帯をチェックリストの頭に置く
// :::callout{type="prep" title="Before you start"}, closed at once, is a header: a box that
// holds only its title and icon. The icon is one picture of three drawings; a width KIT times
// its size makes its box a strip, and the picture is fitted into width × size, left of the
// title. Tasks set inside the box would start after that column, 21 mm in, so the '- [ ]'
// items follow the box, where they print the default task box, '☐'.
const [STRIP, KIT] = [5, 30 / 8]; // mm: the strip's height; the drawing's width over height
const prep = { id: 'prep', backgroundEnabled: false, padding: NONE,
marginTop: pt(LEAD), marginBottom: column.titleStyle.gap, // the tasks follow at this gap
icon: { kind: 'resource', resourceId: 'kit', size: mm(STRIP), width: mm(STRIP * KIT),
align: 'center' }, // the title centred on the strip
titleStyle: { ...column.titleStyle, color: col('olive') } };
prepの囲みには題とアイコンしかないので、見出しとして働きます。アイコンのwidthをsizeの3.75倍にすると、アイコンの正方形が18.75×5mmの帯に伸び、3つの線画が題の左を埋めます(囲みスタイル)。アイコンは囲みの中のすべての内容の横に専用の列を取ります。そこで作業項目は囲みの後に置き、21mm内側から始まるのではなく、材料のダッシュとそろうようにします。- [ ]の項目は既定のチェックボックスを印刷し、unorderedLists.marginTop: 0で、項目は見出しのmarginBottom、つまり段の題と同じ2.4mmの間隔で続きます(箇条書きリスト)。
#4 · タグをチップにする
const chipStyles = [{ id: 'tag', fontSize: em(0.86), bold: true, background: col('tint'),
borderWidth: pt(0), borderRadius: em(1), // no outline; a radius past half the height: a pill
paddingX: em(0.7), paddingY: em(0.18), gap: em(0.3) }];
:chip[Vegetarian]{style="tag"}は語を行をまたいで分かれることのない箱に入れます。箱の高さの半分より大きいborderRadiusはその半分に切り詰められ、両端が半円になります。borderWidth: 0なら、角丸の形は地色だけで描かれます。箱の高さは11.4ptで、カードの行送り12.8ptより小さいので、タグが2行目に回っても1行目に触れません(チップスタイル)。
#5 · デザインはひとつ、写真はレシピごと
const BAND = 104; // mm: the photo's foot; the pills sit 13 mm above it, the lead 6 mm below
const NOTE = { x: 18, y: 24, w: 70 }; // mm on the page: the box ends 2 mm before the arrow
const at = (x, y, size) => ({ anchor: { to: 'container', edge: 'top-left' },
offset: { x: mm(x), y: mm(y - PAGE.top) }, size }); // y in mm from the top of the page
const text = (id, content, family, size, placement, extra) => ({ kind: 'text', id, content,
fontFamily: family, fontSize: pt(size), color: col('ink'), align: 'left',
overflow: 'wrap', placement, ...extra }); // a foot wraps too, where the default is '…'
const tracked = { fontWeight: 700, textTransform: 'uppercase', letterSpacing: pt(1.6) };
// Pills are text boxes chained right-of each other; each prints one heading attribute.
const pill = (id, after) => text(id, `{attr.${id}}`, TEXT, 8.4, after ? { anchor:
{ to: `#${after}`, edge: 'right-of' }, offset: { x: mm(1.8) } } : at(0, BAND - 13), {
fontWeight: 600, box: { backgroundColor: col('card'), borderRadius: mm(3),
padding: { top: mm(1.1), right: mm(2.8), bottom: mm(1.1), left: mm(2.8) } } });
// One heading style for every recipe; each heading names its photo: art="tortilla".
const opener = { id: 'receta', advancedDesign: { enabled: true, slot: { elements: [
{ kind: 'image', id: 'art', resourceId: '{attr.art}', // filled in per heading, like a text
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: mm(PAGE.w), height: mm(BAND) } } },
{ kind: 'image', id: 'arrow', resourceId: 'arrow', // the note's arrow, over the photo
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: mm(PAGE.w), height: mm(BAND) } } },
text('note', '{attr.note}', HAND, 19, { anchor: { to: 'page', edge: 'top-left' },
offset: { x: mm(NOTE.x), y: mm(NOTE.y) }, size: { width: mm(NOTE.w) } },
{ fontWeight: 600, align: 'right' }), // on the page, like the arrow and the photo
pill('time'), pill('level', 'time'), pill('season', 'level'),
text('title', '{titleText}', DISPLAY, 42, { anchor: { to: '#time', edge: 'above' },
offset: { y: mm(-3.2) }, size: { width: mm(96) } }, // two lines: the \\ in the heading
{ lineHeight: 1 }), // set solid: 42 pt from line to line
text('kicker', '{attr.kicker}', TEXT, 8.2, { anchor: { to: '#title', edge: 'above' },
offset: { y: mm(-2.4) }, size: { width: mm(96) } }, tracked),
// The lead is the design's lowest element: the opener reserves down to its last line, and
// the card starts under it without a minHeight.
text('lead', '{attr.lead}', TEXT, 10.5, at(0, BAND + 6, { width: mm(122) }),
{ italic: true, lineHeight: 1.45 }),
] } } };
# Tortilla \\ de patatas {style="receta" art="tortilla" kicker="…" lead="…"}は見出しスタイルを選び、属性からスロットを埋めます。イタリックのリード文もその1つです(見出しの属性)。画像要素のresourceIdは'{attr.art}'で、テキストと同じプレースホルダーです。そのため2つのレシピは1つのスタイルを共有し、それぞれの見出しが自分の写真を指定します(画像要素)。角丸のラベルはそれぞれ前のラベルのright-ofに、題は最初のラベルのaboveに、見出し前置きは題の上に固定してあります。題が長くなると見出し前置きが押し上げられ、ラベルは同じ行にとどまります。リード文はデザインのいちばん下の要素なので、章扉はその最終行までを確保し、minHeightがなくてもカードはリード文の下から始まります。メモは写真や矢印と同じくページに固定してあります。矢印はコードで描いた2つ目の画像要素です。奇数ページではのどと小口の余白が左右反転して版面が2mm右へずれますが、メモはどちらのページでも矢印の2mm手前で終わります。
#6 · 絵をリソースとして登録する
// The opener's image elements and both icons name a resource id; the resource names the file
// the canvas paints (loadImage or loadSvg registers it). No :ref cites them, so none is numbered.
const photo = (id, altText) => ({ id, typeId: 'figure', kind: 'bitmap', createdAt: 0, updatedAt: 0,
altText, bitmap: { fileId: `${id}-1520.jpg`, format: 'jpeg', width: 1520, height: 832 } });
const ART = { // markup, width and height in mm, and the alt text
arrow: [arrow, PAGE.w, BAND, t({ en: 'An arrow to the dish', es: 'Una flecha al plato' })],
cutlery: [cutlery, 6, 8, t({ en: 'Fork and knife', es: 'Tenedor y cuchillo' })],
kit: [kit, 8 * KIT, 8, t({ en: 'A bowl with two eggs, a frying pan and a plate',
es: 'Un bol con dos huevos, una sartén y un plato' })] };
const resources = [
photo('tortilla', t({ en: 'A potato omelette with a slice pulled out, on a blue-rimmed plate '
+ 'and a red-checked napkin', es: 'Una tortilla de patatas con una porción separada, en un '
+ 'plato de borde azul sobre una servilleta de cuadros rojos' })),
photo('gazpacho', t({ en: 'A bowl of gazpacho with diced vegetables and a spoon, on a '
+ 'blue-checked napkin beside a tomato', es: 'Un cuenco de gazpacho con dados de verdura '
+ 'y una cuchara, sobre una servilleta de cuadros azules junto a un tomate' })),
...Object.entries(ART).map(([id, [, w, h, altText]]) => ({ id, typeId: 'figure',
kind: 'svg', createdAt: 0, updatedAt: 0, altText, svg: { fileId: `${id}.svg`, width: w * 10,
height: h * 10 } })), // 10 px a millimetre: the sizes only set the aspect ratio here
];
const photos = resources.filter((r) => r.kind === 'bitmap').map((r) => r.bitmap.fileId);
await Promise.all([...photos.map((file) => loadImage(file, asset(file))),
...Object.entries(ART).map(([id, [svg]]) => loadSvg(`${id}.svg`, svg))]);
扉の2つの画像要素、タブのアイコン、チェックリストの見出しのアイコンは、それぞれリソースを指定しており、CanvasはloadImageまたはloadSvgがそのリソースに登録したファイルを描きます。これらのリソースを引用する:refはないので、番号付きの図にはなりません。画像には文字を入れていません。手書き風のメモは画像の上に組んだデザインのテキストです。
レシピの全体
// ═══ Postext Cookbook · Nº 033 · Recipe card: ingredients beside the method ═══════
// https://postext.dev/en/cookbook/recipe-card
// Code: MIT · Text: original (CC BY 4.0) · Photos: diffusion models · Pictograms: CC BY 4.0
// Fonts: Young Serif, Figtree, Caveat (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'es'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'recipe-card';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { ink: '#2b2118', muted: '#76634e', // text; folios and the colophon
paper: '#f7eddb', card: '#fffdf8', // the cream page; the white recipe card on it
tomato: '#bf3d29', olive: '#6b7a3a', tint: '#f6e3c1' }; // numbers and tab; dashes; tags
// Each colour names its palette entry and carries its hex.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color': point it at the tomato, so nothing prints blue.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.tomato })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [TEXT, DISPLAY, HAND] = ['Figtree', 'Young Serif', 'Caveat'];
const PAGE = { w: 190, h: 250, top: 22, inner: 18, outer: 16 }; // mm, mirrored margins
const [BODY, LEAD] = [9.4, 12.8]; // pt: the text of the cards and the notes under them
// #region answer: a white card with a servings tab, two columns inside it
// In the Markdown, :::callout{type="card" label="SERVES 4"} holds a :::columns{count=2} group
// of two nested boxes, :::callout{type="column" title="Ingredients"} and one for the method.
// The group levels its columns by cutting between blocks or lines, so loose lists would run
// the method on under the ingredients. A nested box is one block that never splits, so the
// only cut left is between the two.
const TAB = 5.6; // mm: the tab's height, and how far it rises above the card
const card = { id: 'card', background: col('card'),
padding: { top: mm(4.5), right: mm(6), bottom: mm(5), left: mm(6) },
// No space of its own above: the tab starts on the first grid line under the opener.
columnGap: mm(7), marginTop: mm(0),
// label="…" on the fence prints here: a tab on the top-right corner, a cutlery pictogram
// beside it and a rule from the far corner that makes the tab part of the card.
label: { fontFamily: TEXT, fontSize: pt(8), color: col('card'), // bold by default
background: col('tomato'), height: mm(TAB), offset: mm(TAB), paddingX: mm(2.6),
icon: { resourceId: 'cutlery', width: mm(TAB * 6 / 8), gap: mm(1.6) }, // as tall as the tab
rule: { enabled: true, color: col('tomato'), width: pt(1.2) } } };
// The two columns: frameless boxes whose only device is a tracked title.
const NONE = { top: mm(0), right: mm(0), bottom: mm(0), left: mm(0) };
const column = { id: 'column', backgroundEnabled: false, padding: NONE,
lists: { gap: mm(2.2), itemSpacing: pt(3.5) }, // for the steps as well as the dashes
titleStyle: { fontFamily: TEXT, fontSize: pt(8), color: col('tomato'), // bold by default
textTransform: 'uppercase', letterSpacing: pt(1.5), gap: mm(2.4) } };
// config() plugs them in: calloutStyles: [card, column, prep].
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#段を囲みに入れず、ブロックを数える
段ごとの囲みをなくすと、breaksで右の段を始める子ブロックを指定します。リストの項目、タグの行、チェックリストの見出しはそれぞれ1つと数えます。ガスパチョはbreaks="10"(8つの材料とタグが先に来る)、トルティージャはbreaks="11"です。段の題と、段のスタイルによる手順の間のスペースも一緒になくなります。
:::callout{type="card" label="SERVES 6"}
-:::columns{count=2}
-:::callout{type="column" title="Ingredients"}
+:::columns{count=2 breaks="10"}
- **1.5 kg** ripe plum tomatoes
@@ seven more ingredients and a blank line @@
:chip[Vegan]{style="tag"} :chip[No-cook]{style="tag"} :chip[Make ahead]{style="tag"}
-:::
-:::callout{type="column" title="Method"}
+
1. Chop the tomatoes, seeded pepper, peeled cucumber and garlic.
@@ steps 2 to 5 @@
:::
-:::
:::#タブを左の角に立てる
'top-left'でラベルが左右反転します。タブは左の角へ移り、フォークとナイフはその右に、罫は右から伸びてきます。
background: col('tomato'), height: mm(TAB), offset: mm(TAB), paddingX: mm(2.6),
+ position: 'top-left', // 'top-right' by defaultよくあるつまずき
つまずき
リストの番号はベースラインではなく1行目の中央に置かれる
番号付きリストの番号はCanvasの'middle'ベースラインで描かれ、項目の1行目のベースラインからテキストの0.3 em上が基準になります。そのため、別の書体やより大きなnumberFontSizeの番号は、行の上に立つのではなく、そこから上下に広がります。ディスプレイ書体は浮き、大きな手順番号は1行目にかぶさります。orderedLists.numberVerticalOffsetで位置を調整し、結果を原寸で確認してください。目次の番号はpostext 1.5からベースラインに載りますが、リストの番号は今も中央に置かれます。 番号付きリスト →
つまずき
囲みのlists.colorはリストの番号の色も変える
囲みのスタイルのlists.colorは、スタイルがそれを設定していればかならず、囲みの行頭記号と番号付きリストの番号の両方に色を付けます。この方法で囲みの行頭記号をオリーブ色にすると、手順番号もオリーブ色になります。(postext 1.4までは、番号にまで色が及ぶのは、unorderedLists.colorと異なるときだけでした。)囲みの行頭記号だけに色を付けるには、文書のunorderedLists.colorを設定し、囲みのスタイルからはlists.colorを外してください。そうすれば番号はorderedLists.colorのままです。 囲み →
つまずき
行送りより高いチップは次の行に触れる
箱が行送りより高いチップは、次の行のチップに触れます(chipOverlap警告)。上下のパディング、枠線、サイズを小さくするか、行送りを広げてください。 インラインのチップ →
- ラベルには
textTransformもletterSpacingもないので、SERVES 4とPARA 4は囲みの記述の中で大文字で入力しています。
クレジット
- 本文
- 書き下ろしの文章, CC BY 4.0
- 画像
- The tortilla on its plate, a photograph · Generated With Diffusion Models · オリジナル
- The bowl of gazpacho, a photograph · Generated With Diffusion Models · オリジナル
- The note’s arrow and the pictograms, drawn in code in the page’s palette · Ignacio Ferro · CC BY 4.0
- フォント
- Young Serif (SIL OFL 1.1) · Figtree (SIL OFL 1.1) · Caveat (SIL OFL 1.1)


