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

レシピ集 · 第2章 · 文字と本文

引用番号と統計値を行頭・行末に残さない

二段組の臨床論文を二度組む。初校は行頭・行末に来た引用番号や演算記号を報告して印をつけ、再校はその改行をコストに加えて別の改行を選ぶ。

このページの内容
  • 英語の見本:日本語版はまだありません
  • 仕上がり170 × 240 mm
  • 2段, 段間6 mm
  • STIX Two Text 9.5/12.8
  • IBM Plex Sans
  • IBM Plex Sans Condensed
  • 6ページ
  • レベル
  • Postext 1.79.0
  • 組版時間153 ms
  • コード180行

かんたんな説明

狭い両端揃えの段では、[2, 3] のような引用番号が行頭にひとりで来たり、p < 0.05 が記号のあとで分かれたりします。この論文は二度組みます。一度目はそれが起きる場所を示し、二度目はほとんど起きないように行を分けます。

できあがり

170 × 240 mm の小児科学術誌の3ページを、66 mm の段二つの両端揃えにして STIX Two Text で組みます。中身は小児肺炎の肺エコーについての原著論文で、参考文献はバンクーバー方式の番号つきです。段がこれだけ狭いと改行の選択肢が少なく、英語の本文は三か所でまずい位置で改行されます。引用番号 [2, 3] が、それを添えた語から離れて行頭にひとりで来ます。陰性尤度比 LR− = 0.09 は二度、等号のあとで分かれます。初校は citationBreaks と operatorBreaks を 'warn' にして組みます。改行は一つも変えず、それぞれに淡い琥珀色の帯をつけ、参考文献のあとの校正票に並べます。再校は 'avoid' で組み、三つのうち一つが残ります。スペイン語版は同じ論文を小数点にコンマを使って組みます。

このレシピが答える質問

  • 引用番号や p < 0.05 のような統計量が行末で分かれないようにするには?
  • 医学雑誌のように、引用番号を上付きにし、DOIを有効なリンクにするには?

手短な答え

script.js · 27〜42行コード全体で見る
const bodyText = {
  fontFamily: SERIF, fontSize: pt(9.5), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
  referenceBold: false, textAlign: 'justify', firstLineIndent: mm(3.5),
  indentAfterHeading: false, hyphenation: { enabled: true },
  optimalLineBreaking: true, // the rules price breaks in the Knuth–Plass breaker
  avoidWidows: true, avoidOrphans: true, avoidRunts: true,
  // A line that opens on a citation, "[8, 9]" (citationBreak), or ends or opens on a sign
  // set between spaces, "p <" / "0.05" (operatorBreak). 'warn' reports each one and changes
  // nothing; 'avoid' adds the penalty to the demerits of those breaks and reports the ones
  // it keeps. The first proof sets 'warn' (see proofs).
  citationBreaks: 'avoid', operatorBreaks: 'avoid',
  // 10000 by default, what a line spaced to the limit costs. A 66 mm column offers few other
  // breaks; at 30000 the breaker takes looser lines, never past maxWordSpacing.
  citationBreakPenalty: 30000, operatorBreakPenalty: 30000,
};

材料

種類
STIX Two Text, IBM Plex Sans, IBM Plex Sans Condensed (SIL OFL 1.1)
素材
なし:画像はすべてコードで描画

作り方

#1 · 二種類の改行に値段をつける

コードは上の手短な答えにあります。番号つきの引用で始まる行、または [4, のあとの 5] のように引用の後半で始まる行を、引用の改行と呼びます。前後にスペースのある記号(=、<、±、×、マイナス)で終わるか始まる行を、演算記号の改行と呼びます。'warn' はどちらも報告するだけで、行はそのままにします。'avoid' はそうした改行のコストにペナルティを加え、Knuth–Plass の改行処理は段落の別の分け方を探します。optimalLineBreaking が必要です。一行ずつ決める改行処理には、加えるべきコストがありません。

既定のペナルティ 10000 は、語間の上限いっぱいまで引き伸ばした行のコストと同じです。そのため改行処理は、引用番号を語のそばに置くために上限を超えて行を広げることはしません。この段幅では、10000 だと各版に二つずつ残りました。30000 にすると、maxWordSpacing の範囲内でもっと緩い行を受け入れ、各版に一つずつ残ります。それより上げても何も変わりませんでした。最後の一つには、上限の範囲で別の分け方がありません。

#2 · 本文の改行に印をつける

script.js · 254〜279行コード全体で見る
// The word before the citation and the citation, or the sign and the number on its other
// side, wrapped in :mark[…]: a band under ordinary text, so the breaks stay where they were.
const wordEnd = (s, i) => i + s.slice(i).search(/[\s;)]|[,.](?!\d)|$/); // 0.09, not 0
function sides(source, w, a, b) { // a warning names line a, before the break, by its source
  if (w.kind === 'citationBreak') { // "colleagues [@simel1991]"
    const cite = source.lastIndexOf('[@', b.sourceStart + 2);
    return [source.lastIndexOf(' ', cite - 2) + 1, source.indexOf(']', cite) + 1];
  }
  if (w.edge === 'end') { // "LR− = 0.09": the sign ends line a, the number opens line b
    const from = source.lastIndexOf(` ${w.text} `, a.sourceEnd) + 1;
    return [from, wordEnd(source, from + w.text.length + 1)];
  }
  const sign = source.indexOf(` ${w.text} `, b.sourceStart - 1); // the sign opens line b
  return [source.lastIndexOf(' ', sign - 1) + 1, sign + 1 + w.text.length];
}
function markBreaks(source, doc, found) {
  const pairs = doc.blocks.flatMap((b) => b.lines.map((line, i) => [line, b.lines[i + 1]]));
  const spans = new Map();
  for (const w of found) {
    const [a, b] = pairs.find(([line]) => line.sourceStart === w.sourceStart) ?? [];
    const [from, to] = b ? sides(source, w, a, b) : [];
    if (from > a?.sourceStart && to > from && to <= b.sourceEnd) spans.set(from, to);
  }
  return [...spans].sort(([x], [y]) => y - x).reduce((md, [from, to]) => `${md.slice(0, from)}`
    + `:mark[${md.slice(from, to)}]{style="edge"}${md.slice(to)}`, source);
}

警告にはそれぞれ、種類、引用番号か記号、二行の文字列、一行目の原稿上の位置、ページが入っています。スクリプトは組み上がった文書でその二行を探し、改行の部分を :mark[…] で囲みます。囲むのは引用番号とその前の語、または記号と反対側の数値です。マークは文字の下に帯を塗るだけで、改行は動かしません。帯は引用スタイルが生成する番号までは届かないので、ページで印がつくのは前の語だけです。

初校211ページ。抄録で分かれた LR− = 0.09 と、次の行が [2, 3] で始まる行末の first。

#3 · 二つの校正刷りと疑問票

script.js · 283〜303行コード全体で見る
const KIND = { citationBreak: t({ en: 'citation', es: 'cita' }),
  operatorBreak: t({ en: 'sign', es: 'signo' }) };
const edge = (s, end) => (end ? s.trim().split(/\s+/).slice(-2) : s.trim().split(/\s+/)
  .slice(0, 2)).join('\u00a0').replace(/[.,;]$/, ''); // no-break spaces: no breaks of its own
const query = (doc, w) => `${t({ en: 'p.', es: 'pág.' })}\u00a0${doc.pages[w.pageIndex]
  .pageLabel}, ${KIND[w.kind]}: …${edge(w.lines[0], true)}\u00a0/ ${edge(w.lines[1])}…`;
const slip = (mode, doc, found) => ['', `:::callout{type="slip" title="${mode === 'warn'
  ? t({ en: 'First proof: queries', es: 'Primeras pruebas: consultas' })
  : t({ en: 'Second proof: queries', es: 'Segundas pruebas: consultas' })}"}`,
`citationBreaks / operatorBreaks: '${mode}' · ${found.length} ${found.length === 1
  ? t({ en: 'break', es: 'corte' }) : t({ en: 'breaks', es: 'cortes' })}.`,
...found.flatMap((w) => ['', query(doc, w)]), ':::', ''].join('\n');
const build = (md, mode) => buildDocumentWithFonts({ markdown: md }, { ...config,
  bodyText: { ...bodyText, citationBreaks: mode, operatorBreaks: mode } }, kitFonts(FONTS));
async function proof(mode) {
  const plain = await build(markdown, mode); // pass 1: where the breaks are
  const found = (plain.contentWarnings ?? []).filter((w) => /^(citation|operator)Break$/
    .test(w.kind));
  return build(markBreaks(markdown, plain, found) + slip(mode, plain, found), mode); // pass 2
}
const docs = { warn: await proof('warn'), avoid: await proof('avoid') };

校正刷りはそれぞれ二回組みます。一回目で改行を見つけ、二回目で論文に印をつけ、参考文献のあとに校正票を加えて組みます。校正票は最終ページに来ます。組版所が疑問を添えて校正刷りを返すときと同じやり方です。校正票の行は語と語をノーブレークスペースでつなぐので、校正票自身が改行を増やすことはありません。capture.doc は印のある二回分 [1, 3] を公開します。

再校213ページ。校正票には論文全体で残る改行が一つ並ぶ。

英語版に残るのは、211ページの first の下の [2, 3] です。スペイン語版の初校では四つ見つかり、CP+ の下の = 19,19 や、引用番号そのものが分かれる [4, の下の 5] が含まれます。再校では anteriores [4, の下の 5] が一つ残ります。

#4 · 角括弧の番号つき引用

script.js · 46〜50行コード全体で見る
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const citations = { style: 'elsevier-vancouver', locale: t({ en: 'en-GB', es: 'es-ES' }),
  marker: 'brackets', collapseRanges: true, // [8, 9] and [4–6], set after a word space
  bibliography: { fontSize: em(0.8), lineHeight: pt(9.6), entrySpacing: pt(1),
    labelWidth: mm(6), labelAlign: 'right', doi: 'hide' } };

引用処理は [@key] をそれぞれ、語間スペースのあとに角括弧で囲んだ番号として組み、[4–6] のように連番をまとめます。括弧の前のスペースと、括弧内のコンマのあとのスペースは、どちらも行が分かれうる位置です。引用の多い狭い段にこの規則が要るのはそのためです。

#5 · 誌名の帯と論文の冒頭

script.js · 54〜78行コード全体で見る
const text = (id, content, family, size, extra) => ({ kind: 'text', id, content, align: 'left',
  fontFamily: family, fontSize: pt(size), color: col('ink'), overflow: 'wrap', ...extra });
const at = (to, edge, x, y, width) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) },
  ...(width && { size: { width: mm(width), height: 'auto' } }) });
const caps = { fontFamily: COND, fontWeight: 600, letterSpacing: pt(1.2),
  textTransform: 'uppercase' };
const JOURNAL = t({ en: 'Ribera Paediatric Journal', es: 'Revista Pediátrica de la Ribera' });
const white = { ...caps, color: col('paper') };
const titleBlock = { enabled: true, minHeight: mm(58), slot: { elements: [
  { kind: 'box', id: 'band', style: { backgroundColor: col('accent') }, placement: {
    anchor: { to: 'page', edge: 'top-left' }, size: { width: 'fill', height: mm(13) } } },
  text('journal', JOURNAL, COND, 9, { ...white, placement: at('page', 'top-left', INNER, 5) }),
  text('issue', '{attr.issue}', COND, 9, { ...white, align: 'right',
    placement: at('page', 'top-right', -OUTER, 5, 60) }),
  text('kind', '{attr.kind}', COND, 8.5, { ...caps, color: col('accent'),
    placement: at('container', 'top-left', 0, 0, MEASURE) }),
  text('title', '{titleText}', SANS, 16, { fontWeight: 600, lineHeight: 1.18,
    placement: at('#kind', 'below', 0, 2.5, MEASURE - 6) }),
  text('authors', '{attr.authors}', SERIF, 10, { inlineMarks: true, // ^1^ → ¹
    placement: at('#title', 'below', 0, 3.5, MEASURE) }),
  text('affiliations', '{attr.affiliations}', SANS, 7.2, { inlineMarks: true, lineHeight: 1.35,
    color: col('muted'), placement: at('#authors', 'below', 0, 1.6, MEASURE) }),
  text('note', '{attr.note}', SANS, 7.2, { color: col('muted'),
    placement: at('#affiliations', 'below', 0, 2.4, MEASURE) }),
] } };

見出しスタイルが、誌名の帯、論文の種類、題名、所属番号つきの著者名、注記を描きます。どれも H1 の属性から取ります。二つの版は同じスタイルを使い、文章は Markdown に残ります。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 186 · Citations and statistics off the line edges ═══════════
// https://postext.dev/en/cookbook/clinical-paper-line-edges
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: STIX Two Text, IBM Plex Sans and Sans Condensed (SIL OFL 1.1) · Needs postext ≥ 1.79.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 = 'clinical-paper-line-edges';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: an indigo journal, a pale amber band for the proof marks
const palette = { ink: '#1b1e26', accent: '#2c4a7c', tint: '#e9eef6', mark: '#f7dfa9',
  muted: '#596173', paper: '#ffffff' };
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.accent })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const [SERIF, SANS, COND] = ['STIX Two Text', 'IBM Plex Sans', 'IBM Plex Sans Condensed'];
const [TRIM_W, TRIM_H, TOP, BOTTOM, INNER, OUTER, GUTTER] = [170, 240, 20, 22, 17, 15, 6];
const MEASURE = TRIM_W - INNER - OUTER; // 138 mm: two columns of 66 mm, about 45 characters
const LEAD = 12.8; // pt, for 9.5 pt type

// #region answer: no line opens on a citation, no line ends or opens on a lone sign
const bodyText = {
  fontFamily: SERIF, fontSize: pt(9.5), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
  referenceBold: false, textAlign: 'justify', firstLineIndent: mm(3.5),
  indentAfterHeading: false, hyphenation: { enabled: true },
  optimalLineBreaking: true, // the rules price breaks in the Knuth–Plass breaker
  avoidWidows: true, avoidOrphans: true, avoidRunts: true,
  // A line that opens on a citation, "[8, 9]" (citationBreak), or ends or opens on a sign
  // set between spaces, "p <" / "0.05" (operatorBreak). 'warn' reports each one and changes
  // nothing; 'avoid' adds the penalty to the demerits of those breaks and reports the ones
  // it keeps. The first proof sets 'warn' (see proofs).
  citationBreaks: 'avoid', operatorBreaks: 'avoid',
  // 10000 by default, what a line spaced to the limit costs. A 66 mm column offers few other
  // breaks; at 30000 the breaker takes looser lines, never past maxWordSpacing.
  citationBreakPenalty: 30000, operatorBreakPenalty: 30000,
};
// #endregion

// #region citations: numbered references in brackets, the list in the Vancouver order
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const citations = { style: 'elsevier-vancouver', locale: t({ en: 'en-GB', es: 'es-ES' }),
  marker: 'brackets', collapseRanges: true, // [8, 9] and [4–6], set after a word space

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

アレンジ

#改行を報告するだけにする

校正刷りを人の目で確かめる雑誌なら、規則を 'warn' のままにできます。Sandbox は警告の中に改行を一つずつ並べ、行は改行処理が組んだままになります。

-  citationBreaks: 'avoid', operatorBreaks: 'avoid',
+  citationBreaks: 'warn', operatorBreaks: 'warn',

#既定のペナルティのままにする

10000 では語間がやや詰まり、各版に残る改行は一つではなく二つになります。

-  citationBreakPenalty: 30000, operatorBreakPenalty: 30000,

よくあるつまずき

レイアウト警告 · citationBreak

行頭の引用番号

原因. 段落の行が、語のあとに置かれた番号付き引用またはその一部で始まっています。ある行の末尾が「authors」で次の行の頭が「[12]」の場合や、「[14,」の下に「16]」が来る場合です。数字のあとの括弧内の数字(「2016 (3)」)や括弧内の語は引用とみなしません。右から左へ書く文字と中国語・日本語・韓国語の文はそのままにします。bodyText.citationBreaksが'warn'ならすべての改行を報告し、'avoid'なら改行処理が残したもの、つまり語間の範囲内でbodyText.citationBreakPenaltyより安く避ける組み方がなかったものを報告します。エンジンは各改行を、引用、2行の文字列、ページとともにdoc.contentWarningsに記録します。

対処. bodyText.citationBreaksを'avoid'にします。改行処理は引用の前や引用の中での改行に値段を付け、語間の許す範囲で段落を組み直します。その空白はほかの空白と同じように伸びます。残った改行は、避けるコストがbodyText.citationBreakPenaltyより高いもので、引用が行長に対して幅広いことがよくあります。ペナルティを上げて行の緩みと引き換えにするか、語と引用のあいだにノーブレークスペース(U+00A0)を書いて、規則にかかわらずその組をつなげます。既存の本の移植では'warn'のままにします。移植は原本の改行を再現するためです。 ドキュメント →

レイアウト警告 · operatorBreak

行頭・行末の記号

原因. 段落の行が、前後に空白を置いた単独の記号(= < > ≤ ≥ ± × ≈ ≠ ÷ − + · → のいずれか)で終わるか始まっています。行末が「LR+ =」で次の行に「18.29」が来る場合や、行頭が「± 0.03」の場合です。語と語のあいだのハイフンは記号とみなしません。右から左へ書く文字と中国語・日本語・韓国語の文はそのままにします。bodyText.operatorBreaksが'warn'ならすべての改行を1件ずつ報告し(記号で始まり記号で終わる行は2件)、'avoid'なら改行処理が残したもの、つまり語間の範囲内でbodyText.operatorBreakPenaltyより安く避ける組み方がなかったものを報告します。エンジンは各改行を、記号、端(行末か行頭)、2行の文字列、ページとともにdoc.contentWarningsに記録します。

対処. bodyText.operatorBreaksを'avoid'にします。改行処理は記号の両側の空白での改行に値段を付け、語間の許す範囲で段落を組み直します。残った改行は、避けるコストがbodyText.operatorBreakPenaltyより高いもので、記号と前後の項が幅広い狭い段でよく起こります。ペナルティを上げて行の緩みと引き換えにするか、記号の両側にノーブレークスペース(U+00A0、細いものはU+202F)を書いて、規則にかかわらずつなげます。既存の本の移植では'warn'のままにします。移植は原本の改行を再現するためです。 ドキュメント →

  • 改行は、分け終わった行の中で探します。判型や文字サイズ、文章を変えると位置が動きます。組むたびに警告を読み、前の組版の位置を写さないでください。
  • ある引用をどの段幅でも語のそばに置きたいときは、Markdown でその前にノーブレークスペースを入れます。論文の残りは規則に任せます。

クレジット

レシピ
Ignacio Ferro
本文
書き下ろしの文章, CC BY 4.0
フォント
STIX Two Text (SIL OFL 1.1) · IBM Plex Sans (SIL OFL 1.1) · IBM Plex Sans Condensed (SIL OFL 1.1)
Sandbox