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

レシピ集 · 第6章 · 囲みと注

後注を独立したページに2段で組む

短いプリプロセッサーが[^1]の注に番号を振り、Notesの見出しの下に集めます。その見出しのスタイルが、注を独立したページに2段で組みます。

このページの内容

18〜19ページ · 4〜5/5

  • 英語の見本:日本語版はまだありません
  • 仕上がり156 × 234 mm
  • 1段
  • Libre Bodoni 10/13.8
  • Archivo Narrow
  • Besley
  • 5ページ
  • レベル
  • Postext 1.57.1
  • 組版時間74 ms
  • コード185行

かんたんな説明

ろうそくを題材にした有名な科学講演を、小さな本に組みます。注を各ページの下ではなく最後にまとめ、独立したページに2段で並べる方法を示します。

できあがり

マイケル・ファラデーの『ロウソクの科学』(The Chemical History of a Candle)の第1講を、156 × 234 mmのページに小さな読者向けの版として組みます。講演は煤の色の地で始まり、その下端に火の灯ったろうそくが立っています。拡散モデルで生成した写真で、黒が煤の色とそろっています。本文はLibre Bodoniの両端そろえの1段です。本なら脚注を置くところに、濃いオレンジの小さな上付き数字があり、読者を講演の最後へ導きます。注は独立したページに続きます。ろうそくが吹き消された煤の色の帯の下に、8.2 ptの行末不ぞろいの2段で組まれ、太字の番号が字下げの中にぶら下がります。6つの注のうち3つは、ウィリアム・クルックスによる1861年の版の1908年の刷りからとったものです。残りの3つは新しく書いたもので、「Ed.」の署名があります。2つの段は同じ行で終わり、2段目は奥付で閉じます。

このレシピが答える質問

  • 脚注を付けるには?
  • 参考文献や用語集を組むには(ぶら下げインデント、小さめの文字)?
  • 数式を使わずに、上付き文字、下付き文字、化学式を書くには?

手短な答え

script.js · 29〜56行コード全体で見る
// Use: buildDocument({ markdown: endnotes(markdown) }, config()), with a 'note' paragraph style.
// [^label] in the text → **^n^**, numbered by first citation; bold, so it takes bodyText.boldColor.
// The [^label]: definitions (one line each) print where the first stood, a 'note' paragraph each:
// '**n** text', never '1. text', which would open a numbered list (gotcha: digit-period-list).
function endnotes(markdown, style = 'note') {
  const notes = new Map(); // label → text
  const HOLE = '\u0000'; // marks where a definition stood: the first becomes the notes
  const text = markdown.replace(/^\[\^([^\]\s]+)\]:[ \t]*(.+)\n?/gm,
    (_, label, note) => { notes.set(label, note.trim()); return HOLE; });
  const cited = []; // labels in order of first citation
  const number = (label) => {
    if (!notes.has(label)) throw new Error(`The note [^${label}] has no definition`);
    if (!cited.includes(label)) cited.push(label);
    return cited.indexOf(label) + 1;
  };
  // Markers side by side share one superscript, [^a][^b] → **^1,2^**, never 12 raised (note 12).
  // A word joiner (U+2060, no width) opens each one: after an italic, '*Royal George*' and the
  // bold's ** would make '***', which the parser reads as a bold run, and print the asterisks.
  const marked = text.replace(/(?:\[\^[^\]\s]+\])+/g, (run) => {
    const numbers = [...run.matchAll(/\[\^([^\]\s]+)\]/g)].map(([, label]) => number(label));
    return `⁠**^${numbers.join(',')}^**`;
  });
  const unused = [...notes.keys()].filter((label) => !cited.includes(label));
  if (unused.length) console.warn(`Notes never cited: ${unused.join(', ')}`);
  const entries = cited.map((label, i) => `**${i + 1}** ${notes.get(label)}`);
  const section = `:::paragraphs{style="${style}"}\n${entries.join('\n\n')}\n:::\n`;
  return marked.replace(HOLE, () => section).replaceAll(HOLE, ''); // () =>: '$&' stays text
}

材料

種類
Libre Bodoni, Besley, Archivo Narrow (SIL OFL 1.1)
素材
  • candle-640.jpg
  • snuffed-600.jpg
  • The lit candle on the lecture’s opener, a photograph (Generated With Diffusion Models, オリジナル)
  • The snuffed candle on the notes’ band, a photograph (Generated With Diffusion Models, オリジナル)
  • Figure 1, the flame as seen and in section, drawn in code in the page’s palette (Ignacio Ferro, CC BY 4.0)

作り方

#1 · ビルドの前に脚注を後注に変える

プリプロセッサーは上の手短な答えにあります。Postextは[^1]の注を自分で組みます(脚注)。置き場所は引用した段の下、またはplacement: 'chapterEnd'なら章の最後のブロックのあとです。どちらの場合も注は章の段の中にとどまり、本文の書体で、短い罫の下に組まれます。この版では注に見出し、帯、2段組みのページを与えますが、見出しスタイルがそれを行えるのはMarkdownに書かれた見出しだけです。そこでCodePenのサンプルはbuildDocumentを呼ぶ前にMarkdownを書き換え、エンジンが[^1]を目にすることはありません。プリプロセッサーは本文で最初に引用された順に合印へ番号を振り、すべての定義をその順で、最初の定義があった位置の## Notesの下にまとめます。1. と書くと番号付きリストが始まってしまうので、各注は**1**で始めます。各合印の先頭には単語結合子(U+2060)を置きます。これがないと、*Royal George*のあとの合印の**がイタリックの閉じのアスタリスクとつながって***になり、アスタリスクが印字されてしまいます。

#2 · ボールドを合印専用にする

script.js · 60〜61行コード全体で見る
const markers = { boldColor: col('ember'), // **^n^**: a superscript at 58 % of the text size
  referenceBold: false }; // [Fig. 1] follows the bold colour, set roman

プリプロセッサーは各合印を**^n^**と書きます。キャレットは数字を本文サイズの58 %にし、その3分の1だけ上げます(インライン書式)。太字にするとbodyText.boldColorの色が付きます。ファラデーは太字を使わないので、この色を合印に回せます。5.8 ptの数字には用紙に対して4.5:1のコントラストが必要ですが、炎の色は2.6:1しかないので、合印にはもっと暗い熾火の色を使います。17ページの参照[Fig. 1]も同じ色のローマン体で印字されます。referenceColorの既定値は太字の色で、referenceBold: falseで太字を外しているためです。

#3 · 注は小さく、番号はぶら下げに

script.js · 65〜79行コード全体で見る
const NOTE = 8.2; // pt: the notes' size, about four fifths of the text
// The hang is a bold number and an en space, measured in the notes' face once the fonts are in:
// a bold 5 matches 2, 3 and 6 within 0.02 em (the 4 is 0.05 em wider, the 1 0.14 em narrower).
function hang(label = '5') { // from ten notes on, pass the widest label: hang('10')
  const ctx = new OffscreenCanvas(1, 1).getContext('2d');
  const width = (w, s) => { ctx.font = `${w} 100px "${TEXT}"`; return ctx.measureText(s).width; };
  return em((width(700, label) + width(400, ' ')) / 100);
}
// Ragged, as justifying would stretch the en space after each number.
const noteStyles = () => [{ id: 'note', fontSize: pt(NOTE), lineHeight: pt(NOTE * 1.3),
  textAlign: 'left', hangingIndent: hang() },
  // 22 pt above the colophon is copy-fitted: its last line and the first column's share a line.
  { id: 'colophon', fontFamily: LABEL, fontSize: pt(7), lineHeight: pt(9.2), color: col('muted'),
    textAlign: 'left', firstLineIndent: pt(0), marginTop: pt(22) },
];

注は8.2 pt、行送り10.7 ptで、本文サイズのおよそ5分の4です。CodePenのサンプルは、フォントの読み込みが済んでから、スタイルのhangingIndentをLibre Bodoniで測ります。太字の5とエンスペースで1.12 emになり、各注の最初の語が折り返し行の頭とそろいます(段落スタイル)。番号をぶら下げに出しておけば、注と注のあいだにあきは要りません。行末不ぞろいで組むのは、両端そろえにするとそのエンスペースが伸び、8.2 ptで幅55 mmの段を両端そろえにすると行がゆるくなるからです。キャレットが上付きを作るように、チルダは下付きを作ります。注4のC~25~H~52~や注5のH~2~Oがその例です。

#4 · 注に2段組みのページを与える

script.js · 116〜130行コード全体で見る
const BAND = 82; // mm from the trim's top: level with the foot of Figure 1 across the spread
// The band sets the reserve too, but the first grid line clear of it lies 3 mm under the soot:
const BAND_GAP = 5; // mm more of minHeight moves the notes down a line
const notesSection = { id: 'notes', // an opener page: the drop folio, no running heads
  breakBefore: { enabled: true, parity: 'any' }, span: 'page', // the next page, either side
  layout: { layoutType: 'double', gutterWidth: mm(6), // two columns of about 40 characters
    columnRule: { enabled: true, color: col('rule') } }, // and a hairline between them
  advancedDesign: { enabled: true, minHeight: mm(BAND - TOP + BAND_GAP), slot: { elements: [
    soot(BAND), art('snuffed', 32, 64, BAND, 12), series,
    text('kicker', '{attr.kicker}', LABEL, 9.5, 'flame', at('container', 'top-left', 0, 16),
      caps(9.5)),
    text('title', '{titleText}', DISPLAY, 52, 'wax', below('kicker', 0.5, 80), display),
    text('intro', '{attr.intro}', LABEL, 8.4, 'rule', below('title', 2.5, 92),
      { lineHeight: 1.3 }),
  ] } } };

見出し## Notes {style="notes" …}が始める節のページには、そのスタイルのレイアウトとデザインが適用されます。parity: 'any'で節は奇偶を問わず次のページから始まり、span: 'page'で帯が両方の段にまたがるので、帯は仕上がりの端まで届き、2段目はその下から始まります(見出しスタイル)。見出しが確保する高さは帯で決まりますが、帯にかからない最初のグリッド線は煤の色の地のわずか3 mm下にあるので、BAND_GAPでminHeightに5 mmを足し、注を1行下から始めています。段間の細罫はスタイル自身のlayoutにあるcolumnRuleなので、注のページだけに引かれます。段末そろえは初期設定で有効で、最後のページを切り分けて2つの段を同じ行で終わらせます(段末そろえ)。

#5 · 講演を煤の色の地で始める

script.js · 101〜112行コード全体で見る
const FIELD = 112; // mm from the trim's top
// The field reaches below the heading, so it sets the reserve (gotcha: opener-reserves-anchored);
// the H1's default bottom margin (0.5 em of 18 pt) rides on it: the text starts a grid line lower.
const opener = { enabled: true,
  slot: { elements: [soot(FIELD), art('candle', 40, 100, FIELD, 10), series,
    text('kicker', '{attr.kicker}', LABEL, 9.5, 'flame', below('series', 17, 60), caps(9.5)),
    text('title', '{titleText}', DISPLAY, 48, 'wax', below('kicker', 1.5, 96), display),
    // 86 mm wide, so the subtitle breaks after a dash, never before one
    text('subtitle', '{attr.subtitle}', DISPLAY, 11.5, 'rule', below('title', 3.5, 86),
      { fontWeight: 500, italic: true, lineHeight: 1.3 }),
    text('byline', '{attr.byline}', LABEL, 7.6, 'rule', below('subtitle', 7, 84), caps(7.6)),
  ] } };

地はページに固定したボックスで、その下端に、JPEGを収めた画像要素のろうそくが立っています。講演は1段組みです。段の中に置いたデザインも、各要素を固定した位置に描かれるので、地は仕上がりの端から始まり、天と左右の余白にかかります。キッカー、副題、署名は見出しの行# A Candle {kicker="Lecture I" subtitle="…" byline="…"}から取るので、第2講を組むときに新しいコードは要りません。地は見出しより下まで届くので、見出しが確保する高さは地で決まります。そこに見出しの既定の下余白0.5 emが加わり、本文は煤の色にかからない最初の行の1グリッド行下から始まります。副題の幅を86 mmにしてあるのは、ダッシュの前ではなく、あとで改行させるためです。

#6 · 煤の上には炎の色、紙の上には熾火の色

script.js · 14〜23行コード全体で見る
const palette = {
  ink: '#1f1c19', paper: '#fffdf8', // text and the soot of the fields; a warm white page
  flame: '#e08a1e', ember: '#a9560c', // kickers on soot (6:1); markers and numbers (5.1:1)
  wax: '#f6efe1', rule: '#d4c6ad', // type on soot; hairlines and small type on soot (10:1)
  muted: '#6d6356', blue: '#4f7cae', // running heads, colophon (5.8:1); a flame's blue foot
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color': point it at the ember, so nothing prints blue.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.ember })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));

炎のオレンジは、煤の色の上では6:1のコントラストがありますが、用紙の上では2.6:1しかありません。そこで炎の色は暗い帯の上のキッカーと図1に使います。用紙の上にオレンジで印字する小さなもの(合印、注の番号、図のラベル)には、5.1:1のもっと暗い熾火の色を使います。main-colorが熾火の色を指しているので、設定で指定し直していない既定値も青で印字されず、デザインに従います。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 020 · Endnotes on a page of their own, in two columns ═════
// https://postext.dev/en/cookbook/endnotes-instead-of-footnotes
// Code: MIT · Text: Faraday, ed. Crookes (PD) · Notes, figure: CC BY 4.0 · Photos: diffusion models
// Fonts: Libre Bodoni, Besley, Archivo Narrow (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'endnotes-instead-of-footnotes';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: soot, wax and a flame; the ember is the flame dark enough for small type
const palette = {
  ink: '#1f1c19', paper: '#fffdf8', // text and the soot of the fields; a warm white page
  flame: '#e08a1e', ember: '#a9560c', // kickers on soot (6:1); markers and numbers (5.1:1)
  wax: '#f6efe1', rule: '#d4c6ad', // type on soot; hairlines and small type on soot (10:1)
  muted: '#6d6356', blue: '#4f7cae', // running heads, colophon (5.8:1); a flame's blue foot
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color': point it at the ember, so nothing prints blue.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.ember })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const TEXT = 'Libre Bodoni', DISPLAY = 'Besley', LABEL = 'Archivo Narrow'; // text; titles; labels
const TOP = 22, INNER = 18, OUTER = 22; // mm: margins, and a 116 mm measure of 74 characters

// #region answer: Markdown footnotes become raised markers and a Notes section
// Use: buildDocument({ markdown: endnotes(markdown) }, config()), with a 'note' paragraph style.
// [^label] in the text → **^n^**, numbered by first citation; bold, so it takes bodyText.boldColor.
// The [^label]: definitions (one line each) print where the first stood, a 'note' paragraph each:
// '**n** text', never '1. text', which would open a numbered list (gotcha: digit-period-list).
function endnotes(markdown, style = 'note') {
  const notes = new Map(); // label → text
  const HOLE = '\u0000'; // marks where a definition stood: the first becomes the notes
  const text = markdown.replace(/^\[\^([^\]\s]+)\]:[ \t]*(.+)\n?/gm,
    (_, label, note) => { notes.set(label, note.trim()); return HOLE; });
  const cited = []; // labels in order of first citation
  const number = (label) => {
    if (!notes.has(label)) throw new Error(`The note [^${label}] has no definition`);
    if (!cited.includes(label)) cited.push(label);
    return cited.indexOf(label) + 1;
  };
  // Markers side by side share one superscript, [^a][^b] → **^1,2^**, never 12 raised (note 12).
  // A word joiner (U+2060, no width) opens each one: after an italic, '*Royal George*' and the
  // bold's ** would make '***', which the parser reads as a bold run, and print the asterisks.
  const marked = text.replace(/(?:\[\^[^\]\s]+\])+/g, (run) => {
    const numbers = [...run.matchAll(/\[\^([^\]\s]+)\]/g)].map(([, label]) => number(label));

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

アレンジ

#注をPostextに組ませる

endnotes()と## Notesの見出しを外し、定義のあいだに空行を入れ(エンジンは次の空行までを1つの定義として読みます)、設定にfootnotes: { placement: 'chapterEnd' }を加えます。エンジンが合印に番号を振り、注を講演の最後、奥付のあとに、1段のまま組みます。エンジンが組む注のスタイルは、引用した段の地に置く脚注で扱っています。

#合印を墨で印字する

本文が自分の強調に太字を使うなら、合印は墨で印字します。boldColorは合印にも太字のすべての語にも同じ色を付けるからです。

-const markers = { boldColor: col('ember'), // **^n^**: a superscript at 58 % of the text size
+const markers = { boldColor: col('ink'), // **^n^**: a superscript at 58 % of the text size

#注の段をそろえずに流す

最後のページの段末そろえを切ると、1段目が下端まで埋まってから2段目が始まります。

-  headings: { fontFamily: DISPLAY, color: col('ink'), levels: [
+  headings: { fontFamily: DISPLAY, color: col('ink'), balancing: { trailing: false }, levels: [

よくあるつまずき

つまずき

段落の頭の'1998. 'や'- 'はリストになる

数字、ピリオド、スペースで始まる段落や、ハイフンとスペースで始まる段落はリスト項目になります。数字の前にワードジョイナー(U+2060)を入れ、会話文はemダッシュで書いてください。 エスケープとそのままの文字 →

つまずき

'top'のフロートは参照ページの先頭を許さない限り次のページに置かれる

既定では、フロートが自分の参照より上に置かれることはありません。そのため、Nページで参照したページ幅の'top'フロートはN+1ページの頭に置かれます。リソースまたはその種類のdefaultPlacementにplacement.citingPage: trueを設定すると(本全体ならlayout.floatsAtCitingPage、postext 1.25から)、layout.maxTopFraction以内に収まり参照行がそのページに残る場合は代わりにNページの先頭に置かれ、参照より前の本文はその下に送られます。章の最初のページと強制改ページの後のページの先頭には置かれません。その場合は次のページに置かれ、'auto'または'bottom'なら参照したページの下端に入れられます。 図の配置 →

つまずき

章扉はページに固定した要素のうち最も下のものまで高さを確保する

詳細デザインの章扉は、最も下にある要素までの高さを確保します。見出しより下にあるページや裁ち落としに固定した要素もこれに含まれるため、ページの下端に置いた装飾があると本文が次のページへ押し出されます。こうした要素にはreserve: falseを与えてください(postext 1.5から)。固定した位置に描かれ、高さは何も確保しません。帯そのものに従う要素(帯の下端に固定したものや、高さが'fill'のもの)が帯の高さを決めることはありません。 デザインした章扉 →

つまずき

SVGの図に<marker>やフィルターを使わない(ラスターにフォールバックする)

SVGの図がPDFでベクターのまま残るのは、<marker>、フィルター、マスクを使っていない場合だけです。使っているとラスターにフォールバックし、深く入れ子にしたフィルターはChromeで図を真っ白にすることがあります。矢じりはパスで描いてください。 リソースとしての図と表 →

つまずき

1ページは奇数ページ。ページは物理的な番号で計画する

1ページは右ページで、2ページが最初の偶数ページです。見開きは物理的なページ番号で計画してください。偶数ページの章扉は、その次の奇数ページと向かい合います。 改ページと改段 →

クレジット

レシピ
Ignacio Ferro
本文
画像
  • The lit candle on the lecture’s opener, a photograph · Generated With Diffusion Models · オリジナル
  • The snuffed candle on the notes’ band, a photograph · Generated With Diffusion Models · オリジナル
  • Figure 1, the flame as seen and in section, drawn in code in the page’s palette · Ignacio Ferro · CC BY 4.0
フォント
Libre Bodoni (SIL OFL 1.1) · Besley (SIL OFL 1.1) · Archivo Narrow (SIL OFL 1.1)
Sandbox