かんたんな説明
河口の鳥を2部に分けたポケット図鑑です。泥の茶色の部と、ヨシの緑の部があります。部ごとに色をひとつ決めるだけで、扉のページ、つめ見出し、ノンブル、目次の行に色がつく様子を見せます。
できあがり
『Birds of the Estuary』は、生息環境ごとに1部を立てた2部構成のポケット判の野外図鑑です。干潟の部は泥の茶色、ヨシ原の部はヨシの緑で刷り、それぞれの色は、その環境を開く:::partに一度だけ書きます。部扉は塗り足しまでの色面で、150ptのローマ数字と、その環境の種の一覧をクリーム色で置きます。扉の裏も同じ色で塗り、小口に部のつめ見出しを白抜きで入れます。種のページでは、つめ見出し、ノンブル、キッカー、学名の下の罫、太字の識別点、行頭記号、図版のラベルが部の色になります。目次は河口の風景の帯の下から始まり、部ごとに、その色の帯と部扉のページ番号を置きます。表紙、帯、4点の図版は拡散モデルで生成した画像で、JPEGのビットマップとして読み込んでいます。部のパレットは画像には届かないので、画像の色は元のままです。
このレシピが答える質問
- 本を部や節に分け、それぞれに専用の色と中扉を付けるには?
- 章扉や白ページで柱を隠したり、空白の偶数ページを部の色で塗ったりするには?
- 自動で更新される目次(リーダー、ノンブル、著者名、部の行)を追加するには?
- 本文や囲みの中で、キーワード(太字やイタリック)に色を付けるには?
手短な答え
// In the Markdown: :::part{number="I" title="The \\ Mudflats" palette="band=#8c5e24"}
// Every colour below that is linked to 'band' takes #8c5e24 until the next part.
const parts = { // passed to the config as `parts`
// A divider opens on a recto by default. The break after it goes to the next recto too, so
// the back of the leaf stays blank and versoDesign paints it (gotcha: verso-design-breakafter).
breakAfter: { parity: 'odd' },
margins: { top: mm(125) }, // the fence's text starts low, under the title
design: { elements: [ // the divider: its container is the whole trim
box('field', col('band'), { ...at('top-left', 0, 0, 'bleed'), ...fill }),
text('part', t({ en: 'Part', es: 'Parte' }), { ...label, fontSize: pt(10),
letterSpacing: pt(2.4), color: col('paper') },
at('top-left', MARGIN.inner, MARGIN.top)), // a recto: the inner margin is on the left
// Roman for the parts, Arabic for the species. {numberRoman} re-formats number="I" (or
// "1"); the species design prints {number}, from numberingTemplate '{1}'.
text('numeral', '{numberRoman}', { ...display, fontSize: pt(150), lineHeight: 0.9,
color: col('paper') }, below('part', 0)),
// The \\ in the title breaks the line here; the contents and the heads get one line.
text('title', '{titleText}', { ...display, fontSize: pt(46), lineHeight: 0.98,
color: col('paper') }, below('numeral', 2, { width: mm(MEASURE) })),
rule('rule', col('paper'), 1, below('title', 7, { width: mm(14) })),
] },
// The back of the leaf: the same band, edge to edge, the part's tab in reverse at the
// fore-edge (a verso's is on the left) and its name at the foot.
versoDesign: { elements: [
box('field', col('band'), { ...at('top-left', 0, 0, 'bleed'), ...fill }),
text('tab', '{partNumber}', { ...label, fontSize: pt(9), color: col('band'), align: 'center',
box: { backgroundColor: col('paper') } }, { ...at('top-left', 0, TAB.y), size: TAB.size }),
text('name', '{partTitle}', { ...label, fontSize: pt(9), letterSpacing: pt(2.4),
color: col('paper') }, at('bottom-left', MARGIN.outer, -MARGIN.bottom)),
] },
// The fence's list of species, in the paper colour on the band.
bodyStyle: { fontSize: pt(11), color: col('paper'), textAlign: 'left', numberColor: col('paper'),
orderedLists: { fontFamily: 'Barlow Condensed', separator: '', gap: mm(4) } },
};
材料
- 機能
- 部ごとの色部扉目次セマンティックカラーパレット太字・イタリックとその色裁ち落としの帯とツメページの役割ごとの柱柱とノンブルデザインした章扉見出しの属性番号付き見出し見出しスタイル番号のない章タイトル内の改行表紙、扉、奥付ページデザインの画像独自のリソースの種類その場に置く図固定位置の囲みとバッジ改ページと改段
- 併用する機能
- 囲み用紙の色段落スタイルリソースとしての図と表
- 種類
- Alegreya, Zilla Slab, Barlow Condensed (SIL OFL 1.1)
- 素材
cover-1152.jpgcurlew-1200.jpgredshank-1200.jpgreedling-1200.jpgstrip-1536.jpgwarbler-1200.jpg- The cover: a curlew on the estuary mud, reeds in front (Generated With Diffusion Models, オリジナル)
- The contents strip: a curlew and a redshank on the mud, the reedbed beyond (Generated With Diffusion Models, オリジナル)
- Plate 1: Eurasian curlew (Generated With Diffusion Models, オリジナル)
- Plate 2: common redshank (Generated With Diffusion Models, オリジナル)
- Plate 3: bearded reedling (Generated With Diffusion Models, オリジナル)
- Plate 4: common reed warbler (Generated With Diffusion Models, オリジナル)
作り方
#1 · 部が上書きするパレットの項目をひとつ用意する
const palette = {
ink: '#1f2624', // text: a green-tinted near-black
band: '#3c4b4f', // the house slate, before any part; each :::part brings its own
paper: '#f6f3ea', // the page, and the type set on a band
rule: '#d5d1c4', // hairlines
muted: '#61675f', // running heads, Latin names, the colophon
};
// The paletteId is the link a part's palette="band=#…" follows, in text and designs alike.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
// The engine's defaults link to 'main-color': point it at the ink, so nothing prints blue.
{ id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
部はパレットの項目をidで上書きします。そこで、環境とともに変わるべきものはすべてひとつの項目bandに結びつけます。この項目自身の値はスレート色で、部の外(表紙のキッカーと、目次の下の注記の題)にだけ刷られます。設定の中にほかに同じ16進値の色はありません。col()はどの色にもpaletteIdを付けます。部の上書きはこのidをたどって、テキストのスタイルにもデザイン要素にも同じように届きます。
#2 · 部扉、その裏、種の一覧
この手順のコードは上の手短な答えにあります。:::partは奇数ページに部扉を開き、parts.designがそれを仕上がり全体に組みます。:::partの中のMarkdownは、表題の下、紙の上端から125 mmのところから始まります。habitat段落スタイルでその環境について数行、続いてbodyStyleで種の一覧です。versoDesignが扉の裏(色面と白抜きのつめ見出し)を塗るのはそのページが白ページのときだけで、breakAfter: { parity: 'odd' }が最初の種を次の奇数ページへ送ることで、裏を白ページのまま保ちます。{numberRoman}は部のnumber="I"をローマ数字で印字し("1"でも同じIが出ます)、種のほうは1から4までアラビア数字で番号を振ります。表題の中の\\は部扉の上だけで改行します。目次と柱では表題を1行で組みます。
#3 · 本文のアクセントは部に従う
const bodyText = {
fontFamily: 'Alegreya', fontSize: pt(10.5), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('band'), // the field marks: **Bill**, **Voice.**
italicColor: col('ink'), referenceColor: col('ink'),
firstLineIndent: mm(4), indentAfterHeading: false,
// Tighter than the 0.6–2 defaults. runtMinCharacters counts word spaces, not letters:
// 45 are about 20 letters of Alegreya (the default 20, about 9); a shorter last line is a runt.
minWordSpacing: 0.75, maxWordSpacing: 1.7, runtMinCharacters: 45,
};
const unorderedLists = { bulletChar: '•', color: col('band'), // the field marks' bullets
marginTop: pt(0), marginBottom: pt(0) };
// The plates are numbered with the species, and their label is in the part's colour.
const resourceTypes = [{ id: 'plate', numberingTemplate: '{n}', resetOn: 'never',
counterFormat: 'decimal', ...t({
en: { name: 'Plate', namePlural: 'Plates', shortLabel: 'Pl.', captionPrefix: 'Plate' },
es: { name: 'Lámina', namePlural: 'Láminas', shortLabel: 'Lám.', captionPrefix: 'Lámina' },
}) }];
const captionStyle = { fontSize: pt(8.5), labelColor: col('band'), descriptionItalic: true,
gap: mm(1.8) };
ある:::partから次の部までのあいだ、band自身の値と等しい文字色はすべて部の値に置き換わります(:::partコンテナー)。ここでは太字の識別点、行頭記号、図版のラベルがそれにあたります。本文とイタリックは墨のままです。図版は専用のリソースの種類で、ラベルはPlate、番号はリセットしないので、種と歩調を合わせて1から4まで数えます。
#4 · 種の扉
const species = { enabled: true, slot: { elements: [
text('kicker', '{number} · {attr.status}', { ...label, fontSize: pt(8.5),
letterSpacing: pt(1.7), color: col('band') }, at('top-left', 0, 1, 'container')),
// 'cm' is a unit symbol: it keeps its lower case, so the size is not set in capitals.
text('size', '{attr.size}', { ...label, textTransform: 'none', fontSize: pt(8.5),
letterSpacing: pt(0.5), color: col('muted') }, at('top-right', 0, 1, 'container')),
text('name', '{titleText}', { ...display, fontSize: pt(22), lineHeight: 1.05,
color: col('ink') }, below('kicker', 1.5, { width: 'fill' })),
text('latin', '{attr.latin}', { fontFamily: 'Alegreya', italic: true, fontSize: pt(11.5),
color: col('ink') }, below('name', 0.8)),
rule('rule', col('band'), 0.75, below('latin', 2, { width: mm(MEASURE) })),
] } };
種の扉は見出しの属性を3つ印字します。statusはキッカーの番号の後、sizeはキッカーの右、latinは名前の下です。キッカーと学名の下の罫はbandに結びついているので、ひとつのデザインで両方の環境をまかなえます。見出し自体は改ページを設定しません。各種は:::pagebreakの後か、部の後の改ページの後から始まるので、そのページは本文のページとして数えられ、柱が入ります。大きさはラベルの大文字にせずに組みます。cmは単位記号だからです。
#5 · 目次に部ごとの帯を置く
const contents = {
levels: [{ level: 1, fontFamily: 'Zilla Slab', fontSize: pt(12), fontWeight: 600,
numberFontFamily: 'Barlow Condensed', numberFontWeight: 600, numberColor: col('muted'),
numberWidth: mm(5), numberGap: mm(3), marginTop: pt(4) }],
pageNumber: { fontFamily: 'Barlow Condensed', fontSize: pt(10), fontWeight: 600, width: mm(7) },
leader: { char: '. ' },
subtitle: { enabled: true, attr: 'latin', fontFamily: 'Alegreya', fontSize: pt(9.5),
color: col('muted') }, // the Latin name, in italic by default
// A part row lays out this design with the part's number, title, page and palette.
parts: { height: mm(8.5), marginTop: pt(LEAD), design: { elements: [
box('row', col('band'), { ...at('top-left', 0, 0, 'container'), ...fill }),
text('part', t({ en: 'Part {number}', es: 'Parte {number}' }), { ...label, fontSize: pt(8),
letterSpacing: pt(1.6), color: col('paper') }, at('left', 3, 0, 'container')),
text('title', '{titleText}', { ...display, fontSize: pt(12), color: col('paper') },
at('left', 20, 0, 'container')),
text('page', '{pageNumber}', { ...label, fontSize: pt(10), color: col('paper'),
align: 'right' }, at('right', -2.5, 0, 'container')),
] } },
};
:::tocは:::partごとに1行を設け、その中に、部の番号、表題、部扉のページ、パレットを使ってtoc.parts.designを組みます(目次)。そのため同じ囲みが、干潟では茶色、ヨシ原では緑で刷られます。帯の下の種の行には、番号、点線のリーダー、ページが並び、その下の行にlatin属性の学名が入ります。
#6 · 柱とつめ見出しに部を出す
const head = (id, content, parity, placement, style = {}) => ({ ...text(id, content, { ...label,
fontSize: pt(8), letterSpacing: pt(1.4), color: col('muted'), overflow: 'clip', ...style },
placement), parity, pages: 'body' }); // dividers are 'part' pages, their versos 'blank'
const folio = { fontSize: pt(9), fontWeight: 700, color: col('band') };
const tab = (parity, edge) => head(`tab-${parity}`, '{partNumber}', parity,
{ ...at(edge, 0, TAB.y), size: TAB.size },
{ fontSize: pt(9), color: col('paper'), align: 'center', box: { backgroundColor: col('band') } });
const header = { elements: [
head('verso-folio', '{pageNumber}', 'even', at('top-left', MARGIN.outer, HEAD.y), folio),
head('verso-title', '{title}', 'even', at('top-left', MARGIN.outer + HEAD.gap, HEAD.y)),
head('recto-title', '{partTitle}', 'odd', at('top-right', -(MARGIN.outer + HEAD.gap), HEAD.y)),
head('recto-folio', '{pageNumber}', 'odd', at('top-right', -MARGIN.outer, HEAD.y), folio),
tab('even', 'top-left'), tab('odd', 'top-right'), // on the fore-edge, left on a verso
] };
pages: 'body'にすると、柱は本文のページにだけ刷られます。部扉はpartページ、色を敷いたその裏はblankページです。表紙と目次はどちらもページ幅の見出しで始まるので、扉として扱われます。偶数ページの柱はfrontmatterにある書名{title}を印字するので、書名はMarkdownの側に残ります。奇数ページの柱は{partTitle}を1行で印字し、小口のつめ見出しは、背景色がbandに結びついた囲みに{partNumber}を印字します。
レシピの全体
// ═══ Postext Cookbook · Nº 019 · Parts in colour from one attribute ═══════════════════════
// https://postext.dev/en/cookbook/parts-in-colour
// Code: MIT · Text: original (CC BY 4.0) · Pictures: diffusion models
// Fonts: Alegreya, Zilla Slab, Barlow Condensed (SIL OFL 1.1) · Needs postext ≥ 1.57.0
// A pocket field guide to two habitats. Each :::part names its own 'band' colour, and every
// colour linked to 'band' takes it: the divider and its verso, the tab, the field marks.
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'parts-in-colour';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: 'band' is the entry the parts override; the others keep their value
const palette = {
ink: '#1f2624', // text: a green-tinted near-black
band: '#3c4b4f', // the house slate, before any part; each :::part brings its own
paper: '#f6f3ea', // the page, and the type set on a band
rule: '#d5d1c4', // hairlines
muted: '#61675f', // running heads, Latin names, the colophon
};
// The paletteId is the link a part's palette="band=#…" follows, in text and designs alike.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
// The engine's defaults link to 'main-color': point it at the ink, so nothing prints blue.
{ id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
// #endregion
const TRIM = { width: 150, height: 200 }; // a pocket guide
const MARGIN = { top: 22, bottom: 20, inner: 19, outer: 21 }; // mirrored; room for a thumb
const MEASURE = TRIM.width - MARGIN.inner - MARGIN.outer; // 110 mm, about 70 characters
const LEAD = 14.5; // body leading in pt: the baseline grid
const STRIP = 44; // the contents' picture strip, from the top edge (mm)
const HEAD = { y: 12, gap: 8 }; // running heads from the top edge; folio to title (mm)
const TAB = { y: 26, size: { width: mm(8), height: mm(24) } }; // the thumb tab, at the fore-edge
const TITLE_DROP = 6; // mm from the foot of the contents strip to the title's box
const BOOK = t({ en: 'Birds of the Estuary', es: 'Aves del estuario' });
const label = { fontFamily: 'Barlow Condensed', fontWeight: 600, textTransform: 'uppercase' };
const display = { fontFamily: 'Zilla Slab', fontWeight: 700 };
const at = (edge, x, y, to = 'page') => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const below = (id, y, size) => ({ ...at('below', 0, y, `#${id}`), ...(size && { size }) });
const fill = { size: { width: 'fill', height: 'fill' } };
const text = (id, content, style, placement) => ({ kind: 'text', id, content, overflow: 'wrap',
align: 'left', ...style, placement });
const box = (id, color, placement) => ({ kind: 'box', id, style: { backgroundColor: color },
placement });
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#3つ目の環境を加える
塩性湿地の最初の種の前に:::partを1つ置くと、部扉、色を敷いた裏、目次の行とともに3つ目の色が加わり、設定はそのままで済みます。目次の下の注記は外してください。3本目の帯とその種に、その場所が要ります。
+:::part{number="III" title="The \\ Saltmarsh" palette="band=#6b4a7a"}
+:::
+
+# Common Shelduck {latin="Tadorna tadorna" size="58–67 cm" status="Resident"}#種を部扉に向かい合わせる
次の奇数ページへの改ページをなくすと、最初の種は部扉の裏から始まるので、versoDesignが塗る白い偶数ページは残りません。
- breakAfter: { parity: 'odd' },よくあるつまずき
つまずき
parts.versoDesignにはparts.breakAfterのparity 'odd'が必要
部扉の裏が描かれるのは、parts.breakAfter { enabled: true, parity: 'odd' }によってその偶数ページが白のまま残るときだけです。 部扉 →
つまずき
1ページは奇数ページ。ページは物理的な番号で計画する
1ページは右ページで、2ページが最初の偶数ページです。見開きは物理的なページ番号で計画してください。偶数ページの章扉は、その次の奇数ページと向かい合います。 改ページと改段 →
- 部は値を比べて文字の色を変えます。
band自身の値と等しい文字色は、別の項目に結びついていても、どこにも結びついていなくても、部とともに切り替わります。その16進値はband専用にしてください。 - つめ見出しは
{partNumber}を印字しますが、これは部の外では空です。そのため最初の:::partより前の本文ページには、空のスレート色のつめ見出しが出ます。本文のページはすべて部の中に入れてください。 - 画像とインラインのスウォッチは、そこに書かれた色を保ちます。ここでの図版は環境の色をコードの
HABITATから取っているので、:::partに新しい色を書いたら、そちらにも書き加えてください。
クレジット
- 本文
- 書き下ろしの文章, CC BY 4.0
- 画像
- The cover: a curlew on the estuary mud, reeds in front · Generated With Diffusion Models · オリジナル
- The contents strip: a curlew and a redshank on the mud, the reedbed beyond · Generated With Diffusion Models · オリジナル
- Plate 1: Eurasian curlew · Generated With Diffusion Models · オリジナル
- Plate 2: common redshank · Generated With Diffusion Models · オリジナル
- Plate 3: bearded reedling · Generated With Diffusion Models · オリジナル
- Plate 4: common reed warbler · Generated With Diffusion Models · オリジナル
- フォント
- Alegreya (SIL OFL 1.1) · Zilla Slab (SIL OFL 1.1) · Barlow Condensed (SIL OFL 1.1)

