本文へスキップ
レシピ番号30

レシピ集 · 第5章 · 本の構成

著者名入りのアンソロジー

歩くことをめぐる3編の随筆。見出しに著者・年・掲載誌を書き、章扉はその3つを、偶数ページの柱と目次は著者名を印字します。

このページの内容
出力
Canvas
レベル
中級
Postext
Postext 1.65.0で検証済み
1.25.0以上が必要
ライセンス
2026年10月10日更新
コードMIT · 本文CC BY 4.0

2〜3ページ(全9ページ)

  • 英語の見本:日本語版はまだありません
  • 仕上がり135 × 180 mm
  • 1段
  • Spectral 10/14
  • Gloock
  • Hanken Grotesk
  • 9ページ
  • レベル
  • Postext 1.57.1
  • 組版時間64 ms
  • コード175行

かんたんな説明

歩くことについての随筆3編を集めた小さな本です。各随筆の著者と年は一度書くだけで、目次など本の必要な場所に現れます。

できあがり

『Afoot』の9ページです。歩くことをめぐる3編の随筆、ハズリット(1822年)、ソロー(1862年)、スティーヴンソン(1876年)を収めたポケット版のアンソロジーです。表紙いっぱいに夕暮れの荒野の画像があり、これは拡散モデルで生成したJPEGです。目次では各随筆に錆色の番号、Gloockで組んだ題、ノンブルまで字間を空けたリーダー、その下にヘザー色のイタリックで著者名が付きます。各随筆は番号と題で始まり、字間を空けた大文字の署名と、初出の雑誌名と年を記した行が続きます。偶数ページには著者名、奇数ページには随筆の題が入ります。各随筆の見出しが著者・年・出典を属性として持ち、章扉、柱、目次はそこから印字するので、4編目を加えても設定は変えずにすみます。

このレシピが答える質問

  • 自動で更新される目次(リーダー、ノンブル、著者名、部の行)を追加するには?
  • 章扉に著者名の行、リード文、ドロップキャップ付きの導入文を加えるには?
  • 柱を設定するには(左ページに書名、右ページに章タイトル、ノンブルは小口側)?

手短な答え

script.js · 44〜64行コード全体で見る
// Each essay's heading carries its credits, and every {attr.…} below reads them:
//   # Walking {author="Henry David Thoreau" year="1862" source="The Atlantic Monthly"}
// (a value cannot hold { or }, and one with " goes in single quotes; gotcha: attr-values)
// 1 · The opener: inside a heading's design, {attr.author} is that heading's attribute.
const byline = [
  text('byline', '{attr.author}', { ...label, fontSize: pt(8), letterSpacing: pt(1.6),
    color: col('heather') }, below('title', 5)),
  text('dateline', '{attr.source}, {attr.year}', { fontFamily: 'Spectral', italic: true,
    fontSize: pt(9.5), color: col('muted'), align: 'left' }, below('byline', 1.2)),
];
// 2 · The verso running head (head() is in the running-heads region): in the page header,
//     {attr.author} is the attribute of the essay the page belongs to.
const versoAuthor = head('verso-author', '{attr.author}', 'even',
  at('page', 'top-left', MARGIN.outer + HEAD.gap, HEAD.y));
// 3 · The contents: toc.subtitle prints the attribute it names as a line under each title.
//     'author' and italic are the defaults; attr is written out so it can become 'source'.
const authorLine = { enabled: true, attr: 'author', fontFamily: 'Spectral', fontSize: pt(10),
  color: col('heather') };
// Hooked up below: byline → the opener, versoAuthor → header, authorLine → toc.subtitle.
// A heading without author="…" gets an empty byline and running head and no line in the
// contents, and the build gives no warning: check every heading.

材料

種類
Spectral, Gloock, Hanken Grotesk (SIL OFL 1.1)
素材
  • cover-1200.jpg
  • The cover: a heath and hills at dusk, a painting (Generated With Diffusion Models, オリジナル)

作り方

#1 · 随筆に番号を付け、本文を下げる

script.js · 68〜85行コード全体で見る
const opener = { enabled: true,
  // The hairline ends 7 mm above the foot of this reserve, so the text starts on the same grid
  // line under every opener whose title fits on one line (SINK = 14 holds a two-line title).
  minHeight: pt(SINK * LEAD),
  slot: { elements: [
    // {number} prints the essay's number as numberingTemplate '{1:I}' writes it: I, II, III.
    text('number', '{number}', { ...gloock, fontSize: pt(34), lineHeight: 1, color: col('rust') },
      at('container', 'top-left', 0, 8)),
    text('title', '{titleText}', { ...gloock, fontSize: pt(26), lineHeight: 1.08,
      color: col('ink') }, below('number', 3, { width: 'fill' })),
    ...byline,
    { kind: 'rule', id: 'rule', thickness: pt(0.5), color: col('rule'),
      placement: below('dateline', 6) }, // a horizontal rule runs to the column's edge
  ] } };
const essays = { level: 1, numberingTemplate: '{1:I}', advancedDesign: opener,
  marginBottom: pt(0), // the heading's default margin would add to minHeight
  // The cover and contents styles inherit this break (gotcha: style-inherits-break).
  breakBefore: { enabled: true, parity: 'any' } }; // 'any': each piece opens on the next page

レベルのnumberingTemplate: '{1:I}'で随筆にI、II、IIIと番号を振り、{number}がその数字を題の上に印字します(幅と詳細デザイン)。minHeightは14ptの行を12行分確保し、ヘアラインはその7mm上で終わります。そのため1行の題の下では、どの章扉でも本文が天の縁から79mmの位置で始まります。26ptの題が2行目に入ると9.9mm増え、本文がグリッド1行分下がりますが、SINK = 14にしておけば、1行の題でも2行の題でも本文は同じ行から始まります。marginBottom: pt(0)は、見出しの既定のアキがこの確保分に加わるのを防ぎます。

#2 · 目次を自動で埋める

script.js · 89〜99行コード全体で見る
const ENTRY = 15; // pt: the essay titles in the contents
const contents = { // passed to the config as `toc`
  // An entry's numeral takes the title's face and size and stands on its baseline.
  levels: [{ level: 1, fontFamily: 'Gloock', fontSize: pt(ENTRY), color: col('ink'),
    numberFontWeight: 400, // Gloock has one weight
    numberColor: col('rust'), numberWidth: mm(8), numberGap: mm(3), marginBottom: pt(LEAD) }],
  pageNumber: { fontFamily: 'Hanken Grotesk', fontSize: pt(8.5), fontWeight: 600,
    color: col('muted'), width: mm(6) }, // the leader dots take this face and colour too
  leader: { char: '. ', gap: mm(2) }, // spaced dots, right-aligned so they line up
  subtitle: authorLine,
};

Markdownに書いた:::tocは、対象の見出しごとに1項目を印字します。番号、題、リーダー、ページラベル、そしてsubtitleを通じて著者名です。buildDocumentはページラベルが変わらなくなるまで本を組み直すので、随筆の題を変えたり長くしたりすれば目次も更新されます(目次)。項目の番号は、numberFontFamilyやnumberFontSizeで指定しないかぎり題と同じ書体とサイズになり、どのサイズでも題の1行目のベースラインに乗ります。部のある本では、:::partごとにtoc.parts.designで描く行も加わります。色で分ける部を参照してください。

#3 · 偶数ページに著者、奇数ページに随筆

script.js · 103〜119行コード全体で見る
// Each head: the label face, the pages of its parity, never an opener (pages: 'body'), where
// the byline names the author. A function declaration, so the answer above can call it.
function head(id, content, parity, placement, look = {}) {
  return { ...text(id, content, { ...label, fontSize: pt(7.5), letterSpacing: pt(1.3),
    color: col('muted'), ...look }, placement), parity, pages: 'body' };
}
const folio = { color: col('ink') };
const header = { elements: [
  head('verso-folio', '{pageNumber}', 'even', at('page', 'top-left', MARGIN.outer, HEAD.y), folio),
  versoAuthor,
  head('recto-title', '{chapterTitle}', 'odd',
    at('page', 'top-right', -(MARGIN.outer + HEAD.gap), HEAD.y), { align: 'right' }),
  head('recto-folio', '{pageNumber}', 'odd', at('page', 'top-right', -MARGIN.outer, HEAD.y),
    { ...folio, align: 'right' }),
] };
const footer = { elements: [{ ...head('drop-folio', '{pageNumber}', 'all', // an opener's folio
  at('container', 'top', 0, 9), { ...folio, align: 'center' }), pages: 'opener' }] };

各柱はページに固定し、天の縁から11mmに置きます。どちら側に出すかはparityが決めます。ノンブルは本文の小口側の端にそろえ、著者名や題はそこから7mm内側に置きます。head()の中のpages: 'body'は、署名がすでに著者を示している章扉に柱を出さないためのもので、代わりにフッターのpages: 'opener'がそこに下がりノンブルを印字します(テキスト要素)。{chapterTitle}は随筆の題を番号なしで印字します。

#4 · 表紙と目次を数に入れない

script.js · 123〜146行コード全体で見る
// Unnumbered, so the first essay is I; unlisted; and with no running heads or folio. They
// inherit the level's page break, 'any' (gotcha: style-inherits-break).
const bare = { numbered: false, toc: false, header: { elements: [] }, footer: { elements: [] } };
const cover = { enabled: true, slot: { elements: [
  { kind: 'image', id: 'art', resourceId: 'cover',
    placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: 'fill' } } },
  text('title', '{titleText}', { ...gloock, fontSize: pt(80), lineHeight: 1, color: col('ink') },
    at('page', 'top-left', MARGIN.inner, 22)), // page 1 is a recto: the inner margin is left
  text('subtitle', '{subtitle}', { fontFamily: 'Spectral', italic: true, fontSize: pt(14),
    color: col('ink'), align: 'left' }, below('title', 1)),
  text('authors', '{attr.authors}', { ...label, fontSize: pt(8.5), letterSpacing: pt(2),
    color: col('heather') }, below('subtitle', 5)),
  text('imprint', '{attr.imprint}', { ...label, fontSize: pt(7.5), letterSpacing: pt(1.8),
    color: col('paper') }, at('page', 'bottom-left', MARGIN.inner, -12)),
] } };
// span: 'page' in a one-column book: a design kept in its column is cut at the column's foot,
// which would leave a band of paper under the dusk.
const coverStyle = { id: 'cover', ...bare, span: 'page', advancedDesign: cover };
const contentsOpener = { enabled: true, slot: { elements: [ // {title}, {subtitle}: frontmatter
  text('kicker', '{title} · {subtitle}', { ...label, fontSize: pt(8), letterSpacing: pt(1.6),
    color: col('heather') }, at('container', 'top-left', 0, 8)),
  text('title', '{titleText}', { ...gloock, fontSize: pt(26), color: col('ink') },
    below('kicker', 2.5)),
] } };

numbered: falseにすると表紙と目次はカウンターを進めないので、ハズリットがIになります。toc: falseはこの2つを目次の一覧から外します(見出しスタイル)。どちらのスタイルもレベルのbreakBefore(parityは'any')を受け継ぐので、:::pagebreakなしで目次が表紙に続いて2ページ目に来ます。1段組みの本で表紙スタイルがページ全体にまたがっているのは、段の中にとどめたデザインは段の下端で切り取られ、風景の下に22mmの紙が残ってしまうからです。

#5 · どの色もパレットへのリンクとともに書く

script.js · 14〜28行コード全体で見る
const palette = {
  ink: '#241f26', // text: a plum-tinted near-black
  paper: '#f7f2e8', // the page
  heather: '#6b4468', // the bylines and the authors in the contents
  rust: '#a4502a', // the essay numbers
  rule: '#d5cabd', // hairlines
  muted: '#6d6570', // running heads, datelines, page numbers in the contents
};
// col() links a colour to its palette entry; the hex is the value the entry holds.
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' } },
];

col()は各色のhexをpaletteIdと並べて書き、エンジンはこのリンクをたどります。署名、柱、表紙はcolorPaletteでそのidに割り当てられた色で塗られるので、同じidのある別のパレットに差し替えれば本全体の色が変わります。main-colorをインキの色に向けておけば、設定で書き直していない既定値もすべてカバーできます。そうしないと、エンジンの青#295AA3で印字されます。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 030 · Anthology with bylines ═══════════════════════════════
// https://postext.dev/en/cookbook/anthology-with-bylines
// Code: MIT · Text: Hazlitt, Thoreau, Stevenson (public domain) · Cover: diffusion models
// Fonts: Spectral, Gloock, Hanken Grotesk (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'anthology-with-bylines';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: heather for the credits, rust for the numbers, plum ink on warm paper
const palette = {
  ink: '#241f26', // text: a plum-tinted near-black
  paper: '#f7f2e8', // the page
  heather: '#6b4468', // the bylines and the authors in the contents
  rust: '#a4502a', // the essay numbers
  rule: '#d5cabd', // hairlines
  muted: '#6d6570', // running heads, datelines, page numbers in the contents
};
// col() links a colour to its palette entry; the hex is the value the entry holds.
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: 135, height: 180 }; // a pocket book, 3 : 4
const MARGIN = { top: 20, bottom: 22, inner: 19, outer: 15 }; // mirrored
const LEAD = 14; // body leading in pt: the baseline grid
const SINK = 12; // grid lines an essay opener reserves above its first line of text
const HEAD = { y: 11, gap: 7 }; // running heads: mm from the top edge, folio to words
const label = { fontFamily: 'Hanken Grotesk', fontWeight: 600, textTransform: 'uppercase',
  align: 'left' }; // design text is centred by default
// One weight, no italic; 'wrap' breaks a long title onto a second line.
const gloock = { fontFamily: 'Gloock', overflow: 'wrap', align: 'left' };
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const below = (id, y, size) => ({ ...at(`#${id}`, 'below', 0, y), ...(size && { size }) });
const text = (id, content, look, placement) => ({ kind: 'text', id, content, ...look, placement });

// #region answer: one set of heading attributes, read in three places
// Each essay's heading carries its credits, and every {attr.…} below reads them:
//   # Walking {author="Henry David Thoreau" year="1862" source="The Atlantic Monthly"}
// (a value cannot hold { or }, and one with " goes in single quotes; gotcha: attr-values)
// 1 · The opener: inside a heading's design, {attr.author} is that heading's attribute.
const byline = [

組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)

アレンジ

#各随筆の初出を載せる

toc.subtitleは見出しのどの属性でも印字できるので、同じMarkdownのまま、題の下に各随筆が最初に載った雑誌を並べられます。

-const authorLine = { enabled: true, attr: 'author', fontFamily: 'Spectral', fontSize: pt(10),
+const authorLine = { enabled: true, attr: 'source', fontFamily: 'Spectral', fontSize: pt(10),

#偶数ページに書名を入れる

偶数ページに書名、奇数ページに章名を入れる本も多くあります。{title}はMarkdownのフロントマターから書名を取り、AFOOTと印字します。

-const versoAuthor = head('verso-author', '{attr.author}', 'even',
+const versoAuthor = head('verso-author', '{title}', 'even',

#どの随筆も奇数ページから始める

parityを'odd'にすると、スティーヴンソンは8ページを白ページにして9ページに移ります。このとき前付けの2つのスタイルには専用の'any'が必要です。そうしないと目次が'odd'を受け継ぎ、偶数ページを白ページにして3ページから始まります。

-  breakBefore: { enabled: true, parity: 'any' } }; // 'any': each piece opens on the next page
+  breakBefore: { enabled: true, parity: 'odd' } };
-const bare = { numbered: false, toc: false, header: { elements: [] }, footer: { elements: [] } };
+const bare = { numbered: false, toc: false, breakBefore: { enabled: true, parity: 'any' },
+  header: { elements: [] }, footer: { elements: [] } };

よくあるつまずき

つまずき

属性値には{も}も書けない。"を含む値は一重引用符で囲む

属性値は閉じ波かっこで終わるため、{や}を含められません。二重引用符を含む値は一重引用符で囲みます。ドル記号は問題ありません。 見出しの属性 →

つまずき

見出しスタイルはその階層の改ページを受け継ぐ

headingStylesの項目は、指定しなかったフィールドをすべて見出しの階層から受け継ぎ、breakBeforeも例外ではありません。:::pagebreakのあとのH1に付けた目次や奥付のスタイルはparity 'odd'を受け継ぎ、白ページの後ろに置かれます。こうしたスタイルにはbreakBefore: { enabled: false }を指定してください。 見出しスタイル →

  • ハズリットは文の途中で詩を引用します。詩は:::verse{style="verse" align=start}ブロックに入れ、Markdownの1行を詩の1行として8 mm下げて組み、そのあとに再開する文は字下げなしのrunonスタイルに入れます。Markdownの引用ブロックはここでは使えません。行が段落と同じようにつながるので、詩が散文のように続けて組まれてしまいます。
  • 見出しにない属性は何も印字せず、警告も出ません。author="…"がないと、その随筆の署名と偶数ページの柱は空になり、目次の題の下の行も消えます。

クレジット

レシピ
Ignacio Ferro
本文
画像
  • The cover: a heath and hills at dusk, a painting · Generated With Diffusion Models · オリジナル
フォント
Spectral (SIL OFL 1.1) · Gloock (SIL OFL 1.1) · Hanken Grotesk (SIL OFL 1.1)
Sandbox