かんたんな説明
タイポグラフィーについての同じ2段落を、同じ出典とともに4回印刷します。ページごとに出典の示し方が異なり、引用も末尾の一覧もそれに合わせて変わりますが、本文は一度書いただけです。
できあがり
よいタイポグラフィーがなぜ気づかれないのかを論じる2段落のエッセイで、出典は6つです。叙述的な引用、ページ付きの引用、文中で名前を挙げているため著者を省く引用、2つの著作をまとめた引用が含まれます。テキストを155 × 235 mmのページに4回組み、4つのビルドのあいだで変わるのはcitations.styleだけです。APA 7、Chicagoの著者・年方式、IEEE、ISO 690です。各ページは独自の色の帯にスタイル名を掲げるので、並べると比較表として読めます。引用は形、順序、句読点が変わり、一覧は並べ方と名前の書き方が変わりますが、エッセイそのものは同じファイルです。
このレシピが答える質問
- 本文に手を加えずに、本の引用スタイルを切り替えるには?
- APA、IEEEなどの引用スタイルで、文献を引用し参考文献を作るには?
手短な答え
// Citations are written once, Pandoc's way: [@key], [@a; @b], [-@key] without the author,
// @key [p. 17] inside the sentence. citeproc-js writes them, and the list, in the style named.
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const SHOWN = [ // the same text, built once per entry
{ style: 'apa', band: 'apa', name: 'APA 7', system: t({ en: 'author-date', es: 'autor-año' }) },
{ style: 'chicago-author-date', band: 'chicago', name: 'Chicago',
system: t({ en: 'author-date', es: 'autor-año' }) },
{ style: 'ieee', band: 'ieee', name: 'IEEE', system: t({ en: 'numbered', es: 'numérico' }) },
{ style: t({ en: 'iso690-author-date-en', es: 'iso690-author-date-es' }), band: 'iso',
name: 'ISO 690', system: t({ en: 'author-date', es: 'autor-año' }) },
];
const citations = (style) => ({
style, // 'apa' → '(Warde, 1955)'; 'ieee' → '[1]'; the list is sorted and set to match
link: true,
// The authors' names stay whole in the citations, the text and the list: the APA build
// set '(Lup-' | 'ton, 2010)'.
hyphenateNames: false,
bibliography: { fontSize: em(0.85), lineHeight: pt(11.2), hangingIndent: mm(6),
entrySpacing: pt(2), labelWidth: mm(6), doi: 'hide' },
});
材料
- 併用する機能
- 見出しの属性
- 種類
- Source Serif 4, Source Sans 3 (SIL OFL 1.1)
- 素材
- なし:画像はすべてコードで描画
作り方
#1 · 設定は1つ
コードは上の手短な答えにあります。引用は本文の中にPandocの記法で一度だけ書き、文献は末尾のBibTeXブロックに置きます。citations.styleがCSLのスタイルを指定し、citeproc-jsがそれに従ってすべての引用とすべての項目を書きます。APAは年の前にコンマを置いて2つの著作を著者順に並べ、Chicagoは書かれた順を保ち、IEEEは最初に引用された順に番号へ置き換え、ISO 690は一覧の姓を大文字で組みます。執筆中の本なら、変更はこれだけです。設定の値を1つ変えるだけで、本文には触れません。
#2 · 4つのビルド、2つの見開き
// The style is set for the whole document, so each style is a build of its own.
const docs = [];
for (at = 0; at < SHOWN.length; at++) {
// pageIndexOffset makes each page the next one of a book, so the desk pairs them:
// APA beside Chicago, IEEE beside ISO 690.
const content = { markdown, continuation: { pageIndexOffset: at + 1 } };
docs.push(await buildDocumentWithFonts(content, config(), kitFonts(FONTS)));
}
スタイルは文書全体に効くので、4つの版は同じMarkdownの4回のビルドです。それぞれpageIndexOffsetを1つずつ増やすので、各ページは架空の本の次のページになります。デスクはそれらを2つの見開きに組み合わせ、違いの最も小さい2つの著者・年方式を隣り合わせに置きます。
#3 · 帯にスタイル名を掲げる
// The kicker names the build's citation style: a label of the design (#849).
const kicker = (s, i) => `${t({ en: 'Citation style', es: 'Estilo de cita' })}`
+ ` · ${i + 1} / ${SHOWN.length} · ${s.system}`;
const opener = (s, i) => ({
enabled: true,
minHeight: mm(41), // from the top margin to under the title, 63 mm from the trim
slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col(s.band) },
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: 'fill', height: mm(44) } } },
{ kind: 'text', id: 'kicker', content: kicker(s, i), fontFamily: SANS, fontSize: pt(8),
fontWeight: 600, letterSpacing: pt(1.4), textTransform: 'uppercase', color: col('paper'),
align: 'left',
placement: { anchor: { to: 'page', edge: 'top-left' }, offset: { x: mm(18), y: mm(12) } } },
{ kind: 'text', id: 'name', content: s.name, fontFamily: SERIF, fontSize: pt(54),
fontWeight: 600, lineHeight: 1, color: col('paper'), align: 'left', overflow: 'clip',
placement: { anchor: { to: '#kicker', edge: 'below' }, offset: { x: mm(0), y: mm(5) },
size: { width: mm(119), height: 'auto' } } },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: SERIF, fontSize: pt(20),
fontWeight: 600, lineHeight: 1.15, color: col('ink'), align: 'left', overflow: 'wrap',
placement: { anchor: { to: 'page', edge: 'top-left' }, offset: { x: mm(18), y: mm(52) },
size: { width: mm(119), height: 'auto' } } },
] },
});
見出しのデザインが、仕上がり線から始まる帯、スタイルの番号と方式を示す肩書き、54 ptの名前を描きます。名前と方式はMarkdownからではなくスクリプトから取ります。テキストは4つの文書すべてで同じだからです。
const palette = {
ink: '#1d1b19', muted: '#66605a', rule: '#cfc8bf', paper: '#ffffff',
apa: '#2f5d8a', chicago: '#8c2f2b', ieee: '#24476b', iso: '#3c6b4f', // the four bands
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// Each document points main-color at its own band, so any default left follows it.
const colorPalette = (band) => Object.entries({ ...palette, 'main-color': palette[band] })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
各文書はmain-colorを自分の帯の色に向けるので、4つの色はリンクされたパレットの項目になります。設定が指定していない既定値は、どれもそのページの帯の色に従います。
レシピの全体
// ═══ Postext Cookbook · Nº 093 · One text in four citation styles ════════════════
// https://postext.dev/en/cookbook/one-text-four-citation-styles
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Source Serif 4, Source Sans 3 (SIL OFL 1.1) · Needs postext ≥ 1.34.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerCitationEngine,
} from 'https://esm.sh/postext';
import { createCiteprocEngine, STYLES, LOCALES } from 'https://esm.sh/postext-citeproc';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'one-text-four-citation-styles';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one ink, and a colour for each style's band
const palette = {
ink: '#1d1b19', muted: '#66605a', rule: '#cfc8bf', paper: '#ffffff',
apa: '#2f5d8a', chicago: '#8c2f2b', ieee: '#24476b', iso: '#3c6b4f', // the four bands
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// Each document points main-color at its own band, so any default left follows it.
const colorPalette = (band) => Object.entries({ ...palette, 'main-color': palette[band] })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const [SERIF, SANS] = ['Source Serif 4', 'Source Sans 3'];
const LEAD = 14; // pt
// #region answer: the style is one setting; everything else stays the same
// Citations are written once, Pandoc's way: [@key], [@a; @b], [-@key] without the author,
// @key [p. 17] inside the sentence. citeproc-js writes them, and the list, in the style named.
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const SHOWN = [ // the same text, built once per entry
{ style: 'apa', band: 'apa', name: 'APA 7', system: t({ en: 'author-date', es: 'autor-año' }) },
{ style: 'chicago-author-date', band: 'chicago', name: 'Chicago',
system: t({ en: 'author-date', es: 'autor-año' }) },
{ style: 'ieee', band: 'ieee', name: 'IEEE', system: t({ en: 'numbered', es: 'numérico' }) },
{ style: t({ en: 'iso690-author-date-en', es: 'iso690-author-date-es' }), band: 'iso',
name: 'ISO 690', system: t({ en: 'author-date', es: 'autor-año' }) },
];
const citations = (style) => ({
style, // 'apa' → '(Warde, 1955)'; 'ieee' → '[1]'; the list is sorted and set to match
link: true,
// The authors' names stay whole in the citations, the text and the list: the APA build
// set '(Lup-' | 'ton, 2010)'.
hyphenateNames: false,
bibliography: { fontSize: em(0.85), lineHeight: pt(11.2), hangingIndent: mm(6),
entrySpacing: pt(2), labelWidth: mm(6), doi: 'hide' },
});
// #endregion
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#注方式のスタイルを試す
Chicagoの注と参考文献の方式では、引用はそれぞれ脚注になり、一覧は参考文献になります。この場合も本文は変わりません。
- { style: 'apa', band: 'apa', name: 'APA 7', system: t({ en: 'author-date', es: 'autor-año' }) },
+ { style: 'chicago-notes-bibliography', band: 'apa', name: 'Chicago', system: 'notes' },#番号を上付きで書く
番号方式のスタイルは、一覧はそのままに、NatureやVancouverのように引用を上付きの番号で印刷することもできます。
- link: true,
+ link: true, marker: 'superscript',よくあるつまずき
- 位置指定子は一度だけ書き、各スタイルがそれぞれの語で印刷します。ここでは4つとも「p. 17」です。同梱されているISO 690のスペイン語スタイルは、節や章を含めどの種類の位置指定子にも「p.」を印刷するので、このテキストではページを引用しています。
- 版の番号はBibTeXに数値で書きます(
edition = {3})。そうすれば各スタイルが「3rd ed.」「3.ª ed.」「3.」とそれぞれの形で書きます。「3rd」と書くと、その語がそのまま印刷され、スタイル独自の形が失われます。
クレジット
- 本文
- 書き下ろしの文章, CC BY 4.0
- フォント
- Source Serif 4 (SIL OFL 1.1) · Source Sans 3 (SIL OFL 1.1)


