かんたんな説明
生理学の教科書の2章と、巻末の索引です。本文の言葉に印を付けておくと、本がページ番号を自分で見つけるので、手で打ち込む番号はひとつもありません。
できあがり
『Principles of Human Physiology』という、210 × 277 mm判の教科書の第4部です。第14章「The heart as a pump」と第15章「Vessels and blood pressure」は赤い帯の下で奇数ページから始まり、臨床メモとキャプションは外側の欄に組みます。部の最後には、医学教科書の流儀で2段組みにした索引が付きます。項目は約90、下位項目は約30で、項目は小文字、見出し文字はアクセント色、下位項目は1em字下げ、定義のあるページは太字、「see」と「see also」はイタリックです。索引のページ番号はひとつも手で打っていません。各用語には、本文がそれを解説している章の中で印を付けてあり、索引はその印が落ちたページ、ノンブルでいえば297から304を読み取ります。
このレシピが答える質問
- 本文が動くと自動でノンブルが変わる索引を作るには?
手短な答え
// The chapters mark each term where the text discusses it:
// the :index[stroke volume]{main} prints the words, files them, bold page
// mitral:index{term="heart!valves!mitral"} prints nothing, files the word before it
// ## Venous return :index{term="venous return" range="start" main} … range="end"
// :index{term="inotropy" see="contractility"} a cross-reference, no page
// The last chapter is `# Index {style="index"}` and `:::index`. buildBundle hands it every
// chapter's marks with the pages they landed on, and lays the book out again until those
// pages stop moving.
const indexStyle = {
id: 'index', numbered: false, toc: false, // not counted: no chapter 16
layout: { layoutType: 'double', gutterWidth: mm(6) }, // two columns in this section only
advancedDesign: opener(INDEX_BAND), // the chapters' band, shallower and with no number
header: runningHeads(t({ en: 'Index', es: 'Índice analítico' })),
};
const index = {
fontFamily: SERIF, fontSize: pt(8.6), lineHeight: pt(11.4),
indent: em(1), turnoverIndent: em(2), // sub-entries step in 1 em; wrapped lines hang 2 em
// English: Chicago's short ranges (301–3; 298–300 keeps the digit that changes). Spanish
// writes both numbers in full and joins them with a hyphen (301-303).
rangeFormat: t({ en: 'chicago', es: 'full' }), rangeSeparator: t({ en: '–', es: '-' }),
main: { bold: true }, // the defining page in bold
see: { italic: true }, // See / See also, Véase / Véase también by the document's locale
groups: { ...label, fontSize: pt(9.5), letterSpacing: pt(0), color: col('accent') },
};
材料
- 機能
- 索引章ごとに組む本見出しスタイルデザインした章扉見出しの属性番号付き見出し柱とノンブルページの役割ごとの柱見開きの余白フロート用の余白段欄外の注横置きのキャプション番号のない章フロートする囲み囲み番号付きキャプションPDFの書き出し
- 併用する機能
- 1段半組み図を配置する参照「図」と「表」を文書の言語で段抜きの章見出し帯段落スタイルPDFに埋め込むフォント独自のリソースの種類リソースとしての図と表ローマ数字の前付け節ごとのページ構成節ごとの柱上付きと下付き
- 種類
- Literata, Libre Franklin (SIL OFL 1.1)
- 素材
- なし:画像はすべてコードで描画
作り方
#1 · 語ではなく箇所に印を付ける
// The chapters mark each term where the text discusses it:
// the :index[stroke volume]{main} prints the words, files them, bold page
// mitral:index{term="heart!valves!mitral"} prints nothing, files the word before it
// ## Venous return :index{term="venous return" range="start" main} … range="end"
// :index{term="inotropy" see="contractility"} a cross-reference, no page
// The last chapter is `# Index {style="index"}` and `:::index`. buildBundle hands it every
// chapter's marks with the pages they landed on, and lays the book out again until those
// pages stop moving.
const indexStyle = {
id: 'index', numbered: false, toc: false, // not counted: no chapter 16
layout: { layoutType: 'double', gutterWidth: mm(6) }, // two columns in this section only
advancedDesign: opener(INDEX_BAND), // the chapters' band, shallower and with no number
header: runningHeads(t({ en: 'Index', es: 'Índice analítico' })),
};
const index = {
fontFamily: SERIF, fontSize: pt(8.6), lineHeight: pt(11.4),
indent: em(1), turnoverIndent: em(2), // sub-entries step in 1 em; wrapped lines hang 2 em
// English: Chicago's short ranges (301–3; 298–300 keeps the digit that changes). Spanish
// writes both numbers in full and joins them with a hyphen (301-303).
rangeFormat: t({ en: 'chicago', es: 'full' }), rangeSeparator: t({ en: '–', es: '-' }),
main: { bold: true }, // the defining page in bold
see: { italic: true }, // See / See also, Véase / Véase también by the document's locale
groups: { ...label, fontSize: pt(9.5), letterSpacing: pt(0), color: col('accent') },
};
索引を作る人が印を付けるのは、用語が解説されている箇所であって、その語が現れるすべての箇所ではありません。2つの章には「stroke volume」が12回出てきますが、索引が読者を送る先は2か所です。用語を定義している298ページと、何がそれを調節するかを説明している299–300ページです。見える印:index[cardiac output]{main}は、その語を印刷したうえで索引に登録します。見えない印mitral:index{term="heart!valves!mitral"}は何も印刷せず、直前の語のページを取ります。4つの弁を扱う段落は、この方法で文を書き換えずに「mitral」「tricuspid」「aortic」「pulmonary」を「heart」の下に登録しています。!は階層を区切るので、「heart」は3階層になります。valves、その下に個々の弁です。印は見出しの中でも使え(14.1と15.6の範囲は見出しから始まります)、囲みの中でも使えます(「heart failure」は300ページの傍注で定義されています)。
#2 · 主要ページ、範囲、相互参照
// The chapters mark each term where the text discusses it:
// the :index[stroke volume]{main} prints the words, files them, bold page
// mitral:index{term="heart!valves!mitral"} prints nothing, files the word before it
// ## Venous return :index{term="venous return" range="start" main} … range="end"
// :index{term="inotropy" see="contractility"} a cross-reference, no page
// The last chapter is `# Index {style="index"}` and `:::index`. buildBundle hands it every
// chapter's marks with the pages they landed on, and lays the book out again until those
// pages stop moving.
const indexStyle = {
id: 'index', numbered: false, toc: false, // not counted: no chapter 16
layout: { layoutType: 'double', gutterWidth: mm(6) }, // two columns in this section only
advancedDesign: opener(INDEX_BAND), // the chapters' band, shallower and with no number
header: runningHeads(t({ en: 'Index', es: 'Índice analítico' })),
};
const index = {
fontFamily: SERIF, fontSize: pt(8.6), lineHeight: pt(11.4),
indent: em(1), turnoverIndent: em(2), // sub-entries step in 1 em; wrapped lines hang 2 em
// English: Chicago's short ranges (301–3; 298–300 keeps the digit that changes). Spanish
// writes both numbers in full and joins them with a hyphen (301-303).
rangeFormat: t({ en: 'chicago', es: 'full' }), rangeSeparator: t({ en: '–', es: '-' }),
main: { bold: true }, // the defining page in bold
see: { italic: true }, // See / See also, Véase / Véase también by the document's locale
groups: { ...label, fontSize: pt(9.5), letterSpacing: pt(0), color: col('accent') },
};
mainは用語を定義しているページを太字にします。学生が「preload」を引くと、まず299ページへ向かいます。同じ用語にrange="start"とrange="end"を付けると、改ページをまたぐ記述を範囲として囲めます。「stroke volume, regulation, 299–300」「baroreceptor reflex, 303–4」のようになります。開始側にmainを付けると範囲全体が太字になります。範囲の内側で同じページにもう一度印を付けると範囲に吸収され、そこにmainがあれば範囲が太字になります。seeはページ番号の代わりに置かれ(「inotropy. See contractility」)、seealsoはページ番号の後に続きます(「heart failure, 300. See also ejection fraction」)。階層のある参照先は!で書き、印刷ではコロンになります。「See blood pressure: mean arterial」です。
#3 · 2段組みの索引の章
// The chapters mark each term where the text discusses it:
// the :index[stroke volume]{main} prints the words, files them, bold page
// mitral:index{term="heart!valves!mitral"} prints nothing, files the word before it
// ## Venous return :index{term="venous return" range="start" main} … range="end"
// :index{term="inotropy" see="contractility"} a cross-reference, no page
// The last chapter is `# Index {style="index"}` and `:::index`. buildBundle hands it every
// chapter's marks with the pages they landed on, and lays the book out again until those
// pages stop moving.
const indexStyle = {
id: 'index', numbered: false, toc: false, // not counted: no chapter 16
layout: { layoutType: 'double', gutterWidth: mm(6) }, // two columns in this section only
advancedDesign: opener(INDEX_BAND), // the chapters' band, shallower and with no number
header: runningHeads(t({ en: 'Index', es: 'Índice analítico' })),
};
const index = {
fontFamily: SERIF, fontSize: pt(8.6), lineHeight: pt(11.4),
indent: em(1), turnoverIndent: em(2), // sub-entries step in 1 em; wrapped lines hang 2 em
// English: Chicago's short ranges (301–3; 298–300 keeps the digit that changes). Spanish
// writes both numbers in full and joins them with a hyphen (301-303).
rangeFormat: t({ en: 'chicago', es: 'full' }), rangeSeparator: t({ en: '–', es: '-' }),
main: { bold: true }, // the defining page in bold
see: { italic: true }, // See / See also, Véase / Véase también by the document's locale
groups: { ...label, fontSize: pt(9.5), letterSpacing: pt(0), color: col('accent') },
};
索引は本の最後のMarkdown文書で、# Index {style="index"}の後に:::indexを置きます。この見出しスタイルは、章で使っている1段半の段組みを、段間6 mmの2段組みに置き換えます。置き換えはその節の中だけで、索引には専用の章扉と柱が付きます。索引は本文書体の8.6/11.4 ptで組み、下位の階層ごとに1em字下げし、折り返した行は2em下げます。これで折り返し行が下位項目と同じ位置にそろうことはありません。rangeFormat: 'chicago'は範囲の中で繰り返される桁を省きます(「303–4」、ただし「299–300」)。スペイン語版は、スペイン語の本の慣習どおり、範囲をハイフンで省略せずに書きます(「303-304」)。
#4 · 番号が本文に追従するしくみ
const text = chapters.map((chapter) => chapter.markdown).join('\n');
await loadSvg('pv-loop.svg', pvLoop());
await prepareFonts(text, config, kitFonts(FONTS));
const docs = await withLoadedFonts(() => buildBundle({ chapters, config, resources }),
{ ...kitFonts(FONTS), text });
showPages(docs, { title: t({ en: 'Principles of Human Physiology',
es: 'Principios de fisiología humana' }) });
offerPdf(() => renderToPdf(docs, { fontProvider: fontsourceProvider, resourceBytes: imageBytes }),
`${RECIPE}.pdf`);
buildBundleは章を順に組み、3番目の章に:::indexがあることを見つけます。1回目のパスの後、すべての章のすべての印を、それが落ちたページとともに集め、その一覧をアウトラインとして索引の章に渡します。それから本をもう一度組み、ページ番号が動かなくなるまで最大3パス繰り返します。第14章の段落を書き直しても、判型や本文の文字サイズを変えても、索引は新しいページで刷り直されます。PDFでは、どのページ番号もそのページへのリンクになります。
#5 · 章扉と柱
function opener(band = BAND, kicker = '') {
const onBand = { color: col('paper'), align: 'left', overflow: 'wrap' }; // wrap: never '…'
const inBand = band - MARGIN.top - 8; // the title's box: it stands on a line 8 mm above the foot
return { enabled: true, minHeight: mm(inBand + 8 + 31), slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('accent') },
placement: { ...at('bleed', 'top-left', 0, 0), size: { height: mm(band) } } },
{ kind: 'text', id: 'kicker', content: kicker, ...label, ...onBand, fontSize: pt(8.5),
placement: at('container', 'top-left', 0, -6) },
{ kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: SANS,
fontWeight: 800, fontSize: pt(30), lineHeight: 1.05, // a multiple, never pt()
verticalAlign: 'bottom', // one line or two, the title sits on the same line
placement: { ...at('container', 'top-left', 0, 0),
size: { width: mm(170), height: mm(inBand) } } },
{ kind: 'text', id: 'lead', content: '{attr.lead}', fontFamily: SERIF, italic: true,
fontSize: pt(10.5), lineHeight: 1.4, color: col('ink'), align: 'left', overflow: 'wrap',
inlineMarks: true, // *See* in the index's lead
placement: { ...at('container', 'top-left', 0, inBand + 15),
size: { width: mm(118) } } },
] } };
}
章と索引は同じ章扉を共有します。仕上がり線から62 mm(索引は46 mm)までの帯で、タイトルは下そろえのボックスで帯の下端に置くので、2行のタイトルも1行のタイトルも同じ行で終わります。キッカーには{chapterNumber}が印刷され、見出し属性{startAt=14}がそれを14にします。page.pageNumbering.startAt: 297は、この部を本の中で本来あるべき位置に置きます。索引のスタイルはnumbered: falseなので、第16章にはなりません。
レシピの全体
// ═══ Postext Cookbook · Nº 072 · A textbook index that follows the text ═══════════════
// https://postext.dev/en/cookbook/back-of-book-index
// Code: MIT · Text: original (CC BY 4.0) · Drawing: generated in code (CC BY 4.0)
// Fonts: Literata, Libre Franklin (SIL OFL 1.1) · Needs postext ≥ 1.28.0
// Two chapters of a physiology textbook and the index that closes them, laid out by
// buildBundle as one book: the terms are marked where the text discusses them, and the
// index chapter prints them with the pages they land on.
import {
buildBundle, prepareFonts, withLoadedFonts, renderPageToCanvas, registerResourceImage,
defaultResourceTypes,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'back-of-book-index';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { // every colour in the config links to one of these ids
ink: '#1f1a1c', // text: a warm near-black
accent: '#9e1b32', // the one accent (7.4:1 on paper): bands, letter heads, numbers, labels
tint: '#f7ebe9', // the loop in Figure 14.1
rule: '#d9c6c3', // hairlines
muted: '#6b5f61', // running heads, notes, the colophon
paper: '#ffffff', // type on the bands
};
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 accent, so nothing prints blue.
{ id: 'main-color', name: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];
// A textbook trim, mirrored, in mm. The body is a column and a half: text in the main column,
// figures' captions and clinical notes in the outer channel.
const TRIM = { width: 210, height: 277 };
const MARGIN = { top: 24, bottom: 22, inner: 20, outer: 14 };
const LEAD = 13.6; // body leading in pt: the baseline grid
const [SERIF, SANS] = ['Literata', 'Libre Franklin'];
const [BAND, INDEX_BAND] = [62, 46]; // mm from the trim to the foot of the opener bands
const HEAD_Y = 13; // mm from the top trim to the running heads
const at = (to, edge, x, y) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const label = { fontFamily: SANS, fontSize: pt(7.5), fontWeight: 700, letterSpacing: pt(1.3),
textTransform: 'uppercase' };
// #region answer: marks in the chapters, and an index chapter set in two columns
// The chapters mark each term where the text discusses it:
// the :index[stroke volume]{main} prints the words, files them, bold page
// mitral:index{term="heart!valves!mitral"} prints nothing, files the word before it
// ## Venous return :index{term="venous return" range="start" main} … range="end"
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#範囲をすべて省略せずに書く
ハウススタイルによっては、範囲の2つの番号を両方とも省略せずに印刷します。
- rangeFormat: t({ en: 'chicago', es: 'full' }), rangeSeparator: t({ en: '–', es: '-' }),
+ rangeFormat: 'full', rangeSeparator: t({ en: '–', es: '-' }),#見出し文字のない索引
短い索引では、グループを空行だけで区切って続けて組むことがよくあります。
- groups: { ...label, fontSize: pt(9.5), letterSpacing: pt(0), color: col('accent') },
+ groups: { enabled: false },よくあるつまずき
- このレシピのキャプチャーでは
indexSeeUnknownが報告されません。参照先の綴りが項目と違う相互参照(「Reynolds number」と「number, Reynolds」)は、何の警告もなく印刷されます。できあがった索引の「See」は、すべて参照先と突き合わせて読んでください。 - 段をまたいで分かれた下位項目の並びは、「heart (cont.)」のような行で主項目を繰り返しません。自分のページ番号がない項目は常に最初の下位項目と一緒に置かれるので、見出しが単独で段の最後に残ることはありません。
クレジット
- 本文
- 書き下ろしの文章, CC BY 4.0
- フォント
- Literata (SIL OFL 1.1) · Libre Franklin (SIL OFL 1.1)


