かんたんな説明
ツーリング自転車の短い取扱説明書です。本文が別の節を案内するときは、その節の番号と載っているページを示し、どちらもリンクになっています。
できあがり
架空のツーリング自転車Ardena T3の取扱説明書です。Archivoで組んだA5判の4ページで、1ページ目の紺の帯に機種名が入ります。取扱説明書は順番どおりには読まれないので、ほかの指示を前提にする指示は、その指示がどこにあるかを書き添えます。「see section 3.2 on page 3」のようにです。書き手は見出し、段落、手順の中の語句に識別子で名前を付け、本文がそれを指すところに:refと書きます。Postextは番号、題、ページのいずれかを印字し、それをリンクにします。表紙の目次も同じ書き方なので、節を移しても、説明書を翻訳して組み直しても、古い番号が残ることはありません。
このレシピが答える質問
- 節とそのページを参照し、本が変わっても両方を正しく保つには?
手短な答え
// In the Markdown, `## Brakes {#sec-brakes}` names a heading, `:anchor{#warn-pressure}`
// a point in a paragraph and `[close the lever]{#step-close-lever}` a phrase in a step.
// `:ref{id="sec-pad-wear"}` prints "section 3.2", `style=page` "page 3", `style=title`
// the heading's words and `style=pageNumber` the bare 3. The page numbers come from the
// previous layout pass: the engine lays the manual out again until they hold.
const crossRefs = {
section: t({ en: 'section {n}', es: 'apartado {n}' }), // H2 and H3: "section 3.2"
page: t({ en: 'page {n}', es: 'página {n}' }), // spelt out: a manual is read by anyone
};
// Every reference is a link in the PDF and on screen; this makes it look like one.
const references = { referenceColor: col('orange'), referenceBold: true };
材料
- 種類
- Archivo, Archivo Narrow (SIL OFL 1.1)
- 素材
- なし:画像はすべてコードで描画
作り方
#1 · 本文が指すものに名前を付ける
コードは上の手短な答えにあります。見出しにはPandocの識別子を付けます(### Checking pad wear {#sec-pad-wear})。タイヤの空気圧についての警告は、目に見えない印:anchor{#warn-pressure}で始まります。車輪を取り付ける最後の手順は[close the lever so that it points backwards]{#step-close-lever}と書き、語句はそのまま残して、それに名前を付けます。囲みは:::callout{#box-wet type="note" title="Wet weather"}で始まります。手順への参照はその手順の語句を、囲みへの参照は囲みの題を印字します。
#2 · 1つの参照先に4つの呼び方
:ref{id="sec-pad-wear"}はcrossRefs.sectionの語を使って「section 3.2」と印字します。style=pageはcrossRefs.pageの語で「page 3」、style=titleは「Checking pad wear」、style=pageNumberは数字だけの「3」を印字します。表紙の目次は、数字だけの番号、題、数字だけのページを組み合わせるので、目次らしく読めます。スペイン語版では同じ参照が「apartado 3.2」「página 3」と印字されます。テンプレートが版の言語に従うからです。
#3 · ページは自然に決まる
ページ番号は、説明書を組んではじめてわかります。エンジンは説明書を組み、各参照先が収まったページを読み取り、どの参照も変わらなくなるまで組み直します。目次を埋めるのと同じループです。翻訳で長くなったテキストや前に移した節がページを変えても、参照は前方にも後方にもそれに従います。
#4 · 番号はレベル2のカウンターから
const H2 = { level: 2, numberingTemplate: '{2}', numberSeparator: ' ', fontFamily: DISPLAY,
fontWeight: 700, fontSize: pt(15), lineHeight: pt(LEAD * 1.5), color: col('navy'),
marginTop: pt(LEAD), marginBottom: pt(LEAD / 3) };
const H3 = { level: 3, numberingTemplate: '{2}.{3}', numberSeparator: ' ', fontFamily: DISPLAY,
fontWeight: 700, fontSize: pt(10.5), lineHeight: pt(LEAD), color: col('ink'),
marginTop: pt(LEAD / 2), marginBottom: pt(LEAD / 4) };
説明書のレベル1の見出しは表紙の機種名の1つだけなので、節はレベル2から番号を振ります。{2}は1から5を、{2}.{3}は1.1、1.2を出します。
#5 · 表紙はその見出しの章扉
const BAND = 104; // mm from the trim's top
const label = { fontFamily: DISPLAY, fontWeight: 700, textTransform: 'uppercase',
letterSpacing: pt(1.6), align: 'left' };
const cover = {
enabled: true,
minHeight: mm(BAND - PAGE.top + 8), // the contents start 8 mm under the band
slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('navy') },
placement: { ...at('page', 'top-left'), size: { width: 'fill', height: mm(BAND) } } },
{ kind: 'box', id: 'stripe', style: { backgroundColor: col('orange') },
placement: { ...at('page', 'top-left', 0, BAND), size: { width: 'fill', height: mm(2.5) } } },
{ kind: 'text', id: 'kicker', content: '{attr.kicker}', ...label, fontSize: pt(9),
color: col('tint'), placement: at('container', 'top-left', 0, 6) },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY, fontWeight: 700,
fontSize: pt(58), lineHeight: 1, color: col('paper'), align: 'left',
placement: at('container', 'top-left', -1, 30) },
{ kind: 'text', id: 'subtitle', content: '{attr.subtitle}', fontFamily: TEXT,
fontSize: pt(11), color: col('paper'), align: 'left',
placement: at('container', 'top-left', 0, 55) },
{ kind: 'text', id: 'edition', content: '{attr.edition}', ...label, fontSize: pt(7.5),
color: col('tint'), placement: at('container', 'top-left', 0, 74) },
] },
};
帯の高さはページの半分の104mmで、オレンジの線がそれを閉じます。キッカー、副題、版の行は見出しの属性なので、スペイン語版はそれを自分のテキストの中で変えられます。
const palette = {
ink: '#1b1f24', navy: '#1d2c3c', orange: '#b8471b', tint: '#f7e7de', rule: '#d5cfc8',
muted: '#5c636b', paper: '#ffffff',
};
// Each colour carries its hex and the palette entry it follows.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.orange })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
レシピの全体
// ═══ Postext Cookbook · Nº 092 · A manual whose references point to pages ══════════
// https://postext.dev/en/cookbook/manual-see-page-references
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Archivo, Archivo Narrow (SIL OFL 1.1) · Needs postext ≥ 1.28.0
import { buildDocumentWithFonts, renderPageToCanvas } 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 = 'manual-see-page-references';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a navy cover band and one signal orange for numbers and references
const palette = {
ink: '#1b1f24', navy: '#1d2c3c', orange: '#b8471b', tint: '#f7e7de', rule: '#d5cfc8',
muted: '#5c636b', paper: '#ffffff',
};
// Each colour carries its hex and the palette entry it follows.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.orange })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const TEXT = 'Archivo', DISPLAY = 'Archivo Narrow';
const PAGE = { w: 148, h: 210, top: 20, bottom: 20, inner: 18, outer: 15 }; // mm: A5, mirrored
const LEAD = 13; // pt
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
// #region answer: the words a reference prints, and references that are links
// In the Markdown, `## Brakes {#sec-brakes}` names a heading, `:anchor{#warn-pressure}`
// a point in a paragraph and `[close the lever]{#step-close-lever}` a phrase in a step.
// `:ref{id="sec-pad-wear"}` prints "section 3.2", `style=page` "page 3", `style=title`
// the heading's words and `style=pageNumber` the bare 3. The page numbers come from the
// previous layout pass: the engine lays the manual out again until they hold.
const crossRefs = {
section: t({ en: 'section {n}', es: 'apartado {n}' }), // H2 and H3: "section 3.2"
page: t({ en: 'page {n}', es: 'página {n}' }), // spelt out: a manual is read by anyone
};
// Every reference is a link in the PDF and on screen; this makes it look like one.
const references = { referenceColor: col('orange'), referenceBold: true };
// #endregion
// #region numbers: sections 1–5 and 1.1, 1.2… under the one level-1 heading
const H2 = { level: 2, numberingTemplate: '{2}', numberSeparator: ' ', fontFamily: DISPLAY,
fontWeight: 700, fontSize: pt(15), lineHeight: pt(LEAD * 1.5), color: col('navy'),
marginTop: pt(LEAD), marginBottom: pt(LEAD / 3) };
const H3 = { level: 3, numberingTemplate: '{2}.{3}', numberSeparator: ' ', fontFamily: DISPLAY,
fontWeight: 700, fontSize: pt(10.5), lineHeight: pt(LEAD), color: col('ink'),
marginTop: pt(LEAD / 2), marginBottom: pt(LEAD / 4) };
// #endregion
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#参照に「p.」と書く
ページ参照の多い参考書では、略記で紙面を節約します。
- page: t({ en: 'page {n}', es: 'página {n}' }), // spelt out: a manual is read by anyone
+ page: t({ en: 'p. {n}', es: 'pág. {n}' }),#参照を墨のままにする
ページの大半が参照なら、本文の色の太字にとどめます。PDFでも画面でもリンクであることは変わりません。
-const references = { referenceColor: col('orange'), referenceBold: true };
+const references = { referenceColor: col('ink'), referenceBold: true };よくあるつまずき
- スタイルを指定しない
:anchorへの参照はページを印字します。目に見えないアンカーには自分の語句がないからです。参照に本文の語句を引かせたいときは[words]{#id}を使います。 - 識別子は本の中で一意でなければなりません。参照は最初の
{#sec-brakes}に届き、Sandboxの検査パネルは2つ目をduplicateAnchorとして示します。
クレジット
- 本文
- 書き下ろしの文章, CC BY 4.0
- フォント
- Archivo (SIL OFL 1.1) · Archivo Narrow (SIL OFL 1.1)


