跳到主要内容
食谱编号140

排版食谱 · 第7章 · 图与图片

数据图横跨页顶的物理快报

以双栏重排GW150914的发现快报:第1页横跨用开放数据重绘的信号,[1]式编号引用,带编号的公式和表I。

本页内容
  • 英文样例:尚无中文版本
  • 成品尺寸215.9 × 279.4 mm
  • 2栏, 栏间距7 mm
  • Gelasio 9.3/12.4
  • Albert Sans
  • 5页
  • 难度
  • Postext 1.65.0
  • 排版用时209 ms
  • 189行代码

简单来说

2016年宣布首次探测到引力波的那篇快报,经过删节后用美国信纸开本重新排版。两台探测器的信号用公开数据重新绘制,横跨第1页;参考文献按方括号编号。

成品一览

宣布首次探测到引力波的那篇快报《Observation of Gravitational Waves from a Binary Black Hole Merger》(Abbott et al., 2016)的五页删节重排本,美国信纸开本,双栏。第1页以证据开篇:Hanford和Livingston记录到的应变,用引力波开放科学中心(GWOSC)的开放数据文件重新绘制,在标题下横跨两栏。下面是合作组署名及其脚注、通栏摘要和正文,引用按APS期刊的习惯编号为[1,2]和[25–27]。啁啾质量是公式(1)。表I把非对称误差排成上下叠放的上标和下标,在单元格里直接写成公式,题注也印出快报原有的公式。换上你自己的BibTeX和数据文件,同一个脚本就能排出你的快报。

这道食谱解答

  • 怎样排物理快报:合作组署名、横跨两栏的摘要,以及顶部通栏的数据图?
  • 怎样控制图的位置:页面顶部、横跨两栏、就放在这里,还是放在边栏里?
  • 怎样排数学公式(行内、行间、编号公式),并在PDF中保持矢量?
  • 怎样用Postext重新排版arXiv或PubMed Central上的开放获取论文,并保留引用、图和许可声明?

简短回答

script.js · 第32–60行在完整代码中
// [@key] numbers works by first citation. APS journals print [1,2] and [2–4] in one pair of
// brackets and list "A. Einstein, Sitzungsber. K. Preuss. Akad. Wiss. 1, 688 (1916).": no
// title, volume bold. No APS style is bundled: four edits turn the IEEE file into one.
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const ARTICLE = '<group delimiter=" "><text variable="container-title"/><text '
  + 'variable="volume" font-weight="bold" suffix=","/><text variable="page"/><date '
  + 'variable="issued" prefix="(" suffix=")"><date-part name="year"/></date></group>';
const BOOK = '<group delimiter=" "><group delimiter=", "><choose><if type="chapter"><text '
  + 'variable="container-title" prefix="in " font-style="italic"/></if><else><text variable='
  + '"title" font-style="italic"/></else></choose><names variable="editor" prefix="edited by ">'
  + '<name and="text" initialize-with=". "/></names><text variable="collection-title"/><text '
  + 'variable="volume" prefix="Vol. "/></group><group prefix="(" suffix=")" delimiter=", ">'
  + '<text variable="publisher"/><text variable="publisher-place"/><date variable="issued">'
  + '<date-part name="year"/></date></group></group><text variable="page" prefix="pp. "/>';
const aps = STYLES.ieee
  .replace('<citation>', '<citation collapse="citation-number">') // [2–4], not [2], [3], [4]
  .replace(/<layout delimiter=", ">\s*<group prefix="\[" suffix="\]" delimiter=", ">/,
    '<layout prefix="[" suffix="]" delimiter=","><group delimiter=", ">') // [1,2]
  .replace('et-al-min="7"', 'et-al-min="11"') // ten authors are listed, as in the letter
  .replace(/<bibliography[\s\S]*<\/bibliography>/, '<bibliography second-field-align="flush">'
    + '<layout suffix="."><text variable="citation-number" prefix="[" suffix="]"/><text '
    + 'macro="author"/><choose><if type="manuscript"><text variable="note" prefix=" "/></if>'
    + `<else><group prefix=", " delimiter=", "><choose><if type="article-journal">${ARTICLE}`
    + `</if><else-if type="book chapter" match="any">${BOOK}</else-if><else><text variable=`
    + '"URL"/><text variable="note"/></else></choose></group></else></choose></layout>'
    + '</bibliography>');
const citations = { style: 'custom', customStyle: aps, link: true,
  bibliography: { fontSize: em(0.84), lineHeight: pt(9.5), entrySpacing: pt(0.4),
    labelWidth: mm(6.2) } }; // the [64] column: turnovers line up after the widest label

用料

类型
Gelasio, Albert Sans(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 从IEEE样式改出物理学的编号引用

代码就是上面的简短回答。postext-citeproc没有附带APS样式,附带样式中最接近的是ieee:按引用顺序编号,数字放在方括号里,名字缩写在姓之前。对STYLES.ieee做四处字符串替换就能补上差别。collapse="citation-number"合并连续的编号([25–27]),在layout上只放一对方括号,印出*[1,2];et-al-min提高到十一,十位作者的名单可以完整列出;新的<bibliography>块按Physical Review的写法印出参考文献:刊名、粗体卷号、页码和年份,如Phys. Rev. Lett.* 74, 3515 (1995)。43条文献放在单独的:::references{format=bibtex}块中;用双层花括号写的名字,如{{J. Aasi et al.}},会照原样印出,快报引用本合作组那些极长的作者名单时就是这样写的。参见引用与参考文献。

#2 · 标题下横跨两栏的图1

script.js · 第64–89行在完整代码中
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 = (size) => ({ fontWeight: 700, letterSpacing: pt(size * 0.2),
  textTransform: 'uppercase', color: col('accent') });
const letter = { id: 'letter', numbered: false, span: 'page', marginBottom: pt(0),
  advancedDesign: { enabled: true, minHeight: mm(21), slot: { elements: [
    text('kicker', '{attr.kicker}', SANS, 7.5, { ...caps(7.5),
      placement: at('container', 'top-left', 0, 2, MEASURE) }),
    text('title', '{titleText}', SANS, 23, { fontWeight: 700, lineHeight: 1.08,
      placement: at('#kicker', 'below', 0, 2.2, MEASURE) }),
  ] } } };
const box = { padding: { top: mm(2.6), right: mm(12), bottom: mm(2.4), left: mm(12) },
  background: col('tint'), marginTop: pt(0), marginBottom: pt(LEAD), span: 'page',
  body: { fontSize: pt(9.3), lineHeight: pt(12.6), firstLineIndent: pt(0) } };
// ::resource{id="fig1"} right under the title, placed { position: 'here', span: 'page' }:
// it spans both columns on page 1, where a float could only follow its citation.
const paragraphStyles = [
  { id: 'byline', fontFamily: SANS, fontSize: pt(10), lineHeight: pt(12.6), fontWeight: 600,
    textAlign: 'center', firstLineIndent: pt(0) },
  { id: 'dates', fontFamily: SANS, fontSize: pt(7.6), lineHeight: pt(12.6), textAlign: 'center',
    color: col('muted'), firstLineIndent: pt(0) },
  { id: 'colophon', fontFamily: SANS, fontSize: pt(7), lineHeight: pt(9.4), color: col('muted'),
    textAlign: 'left', firstLineIndent: pt(0), marginTop: pt(LEAD) },
];

浮动体不会出现在引用它的那一行之上,而正文第一次引用图1是在第II节,所以作为浮动体它到不了第1页。这篇快报直接把它放在那里:::resource{id="fig1"}紧跟在标题之后,其放置方式{ position: 'here', span: 'page' }让它在这一位置横跨两栏,两栏正文在它下方继续。署名和摘要随后放在通栏框front中,框里的:::paragraphs块把署名居中,并用小字号排日期。*et al.*后面的脚注标记把注文送到第一栏底部,APS期刊的作者说明就印在那里;footnotes.numberFormat: 'lower-alpha'用字母给脚注编号,读者不会把它们误认为参考文献。参见块级嵌入和脚注。

#3 · 单元格里有公式的表I

script.js · 第346–354行在完整代码中
// A cell sets $…$ in the line, at the table's size: the errors stack over and under the value.
const VALUES = [['Primary black hole mass', '$36^{+5}_{-4}\\,M_\\odot$'],
  ['Secondary black hole mass', '$29^{+4}_{-4}\\,M_\\odot$'],
  ['Final black hole mass', '$62^{+4}_{-4}\\,M_\\odot$'],
  ['Final black hole spin', '$0.67^{+0.05}_{-0.07}$'],
  ['Luminosity distance', '$410^{+160}_{-180}$ Mpc'],
  ['Source redshift $z$', '$0.09^{+0.03}_{-0.04}$']];
const table = { model: { columnWidths: [1.3, 1], rows: VALUES.map(([label, value]) =>
  [{ content: label, verticalAlign: 'middle' }, { content: value }]) } };

从postext 1.19起,单元格和正文一样排$…$公式,所以每个数值都写成TeX,如$36^{+5}_{-4}\,M_\odot$,两个误差叠放在数字的上方和下方,并缩放到单元格的行高之内;若用Markdown的^+5^~−4~,两个误差会一前一后地印出来。题注和附注也支持同样的公式:图2写$R_S = 2GM/c^2$,图4写$5.1\sigma$,用的是MathJax的字形,其中有两款正文字体都没有的希腊字母,PDF把它们保留为矢量路径。资源类型在题注中印出FIG. 1和TABLE I,在正文中印出Fig. 1和Table I:靠的是captionPrefix,表格再加上counterFormat: 'upper-roman'。参见数学公式。

#4 · 用开放数据绘制的图

script.js · 第17–22行在完整代码中
const palette = { ink: '#171a21', accent: '#25578a', tint: '#eef2f6', rule: '#b7c0ca',
  muted: '#5a636e', paper: '#ffffff' };
const data = { hanford: '#cf5f24', livingston: palette.accent, purple: '#74519c' }; // figures
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' } }));

四幅图都用代码绘制,数据来自GWOSC随这篇快报发布的数据文件,许可证为CC BY 4.0。每条曲线每八个采样点保留一个,图1的0.21秒共430个点;每个点以一个base-64字符记录它相对前一个点的变化,五条曲线在脚本里不到3 KB。残差一行是数据减去波形,与原文相同。所有图中Hanford用橙色、Livingston用蓝色,正文只用页面的墨色和一种蓝色。标注是MathJax无衬线字体(\textsf)的路径,坐标轴上的指数和符号因此与正文公式的排法相同;PDF中每条线和每个标注都保持为矢量。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 140 · A physics letter with a data figure across the top ═══
// https://postext.dev/en/cookbook/physics-letter-two-columns
// Code: MIT · Text: Abbott et al., PRL 116, 061102 (CC BY 3.0) · Data: GWOSC (CC BY 4.0)
// Fonts: Gelasio, Albert Sans (SIL OFL 1.1) · Needs postext ≥ 1.34.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, registerCitationEngine,
  defaultResourceTypes, initMathEngine, renderMath,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
import { createCiteprocEngine, STYLES, LOCALES } from 'https://esm.sh/postext-citeproc';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'physics-letter-two-columns';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink and one blue for the text; the detectors' colours for the data
const palette = { ink: '#171a21', accent: '#25578a', tint: '#eef2f6', rule: '#b7c0ca',
  muted: '#5a636e', paper: '#ffffff' };
const data = { hanford: '#cf5f24', livingston: palette.accent, purple: '#74519c' }; // figures
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] = ['Gelasio', 'Albert Sans'];
// mm: US Letter, head, foot and side margins, gutter; then the measure and one column
const [TRIM_W, TRIM_H, TOP, BOTTOM, SIDE, GUTTER] = [215.9, 279.4, 21, 21, 16, 7];
const MEASURE = TRIM_W - 2 * SIDE;
const COLUMN = (MEASURE - GUTTER) / 2;
const [BODY, LEAD] = [9.3, 12.4]; // pt: a letter journal's density, two columns of 88 mm

// #region answer: physics citations [1] and [2–4], from the bundled IEEE style
// [@key] numbers works by first citation. APS journals print [1,2] and [2–4] in one pair of
// brackets and list "A. Einstein, Sitzungsber. K. Preuss. Akad. Wiss. 1, 688 (1916).": no
// title, volume bold. No APS style is bundled: four edits turn the IEEE file into one.
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
const ARTICLE = '<group delimiter=" "><text variable="container-title"/><text '
  + 'variable="volume" font-weight="bold" suffix=","/><text variable="page"/><date '
  + 'variable="issued" prefix="(" suffix=")"><date-part name="year"/></date></group>';
const BOOK = '<group delimiter=" "><group delimiter=", "><choose><if type="chapter"><text '
  + 'variable="container-title" prefix="in " font-style="italic"/></if><else><text variable='
  + '"title" font-style="italic"/></else></choose><names variable="editor" prefix="edited by ">'
  + '<name and="text" initialize-with=". "/></names><text variable="collection-title"/><text '
  + 'variable="volume" prefix="Vol. "/></group><group prefix="(" suffix=")" delimiter=", ">'
  + '<text variable="publisher"/><text variable="publisher-place"/><date variable="issued">'
  + '<date-part name="year"/></date></group></group><text variable="page" prefix="pp. "/>';
const aps = STYLES.ieee
  .replace('<citation>', '<citation collapse="citation-number">') // [2–4], not [2], [3], [4]
  .replace(/<layout delimiter=", ">\s*<group prefix="\[" suffix="\]" delimiter=", ">/,

组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)

变化

#直接用附带的IEEE样式

去掉这些替换,正文会印成*[2], [3], [4],参考文献表印成A. Einstein, “title”, journal…*。

-const citations = { style: 'custom', customStyle: aps, link: true,
+const citations = { style: 'ieee', link: true,

#像Nature那样用上标

Nature样式用上标数字,并列出文献标题;它是附带样式之一。

-const citations = { style: 'custom', customStyle: aps, link: true,
+const citations = { style: 'nature', link: true,

#改排A4开本

改动成品尺寸;版心、栏和所有图都随之变化。

-const [TRIM_W, TRIM_H, TOP, BOTTOM, SIDE, GUTTER] = [215.9, 279.4, 21, 21, 16, 7];
+const [TRIM_W, TRIM_H, TOP, BOTTOM, SIDE, GUTTER] = [210, 297, 22, 22, 15, 7];

常见问题

易错点

数学公式需要在首次构建前await initMathEngine()

在数学引擎运行之前排版的公式是灰色的占位方框。从https://esm.sh/postext连同其他符号一起导入initMathEngine,并在首次构建前await它;含有数学公式的文档不经这一步就构建时,控制台会打印一条警告。从postext 1.5起,MathJax作为一个模块随包发布,由initMathEngine去获取,所以从CDN直接导入就能用,不需要?bundle(1.4及以前,所有符号都必须来自https://esm.sh/postext?bundle)。只从一个URL导入:两个URL会加载两个引擎。 数学 →

  • 在postext 1.18及更早版本中,双栏排版里带span: 'page'的'here'资源只有一栏宽,题注或单元格里的$也照原样印出。请指定1.19或更高版本。
  • 在题注或单元格里直接键入的希腊字母、⊙或≃在屏幕上会落到系统字体,在PDF中则会缺字,因为PDF只嵌入每款字体的拉丁字符文件。把它写成公式,如$\sigma$或$M_\odot$,在图中则把它画出来。
  • 数百位作者的名单不适合写进BibTeX文件。按期刊印出的样子写名字,并用双层花括号括起:author={{B. Abbott et al.}}。
  • 保留论文和数据的许可证说明。这里由一条脚注和版权页说明删去了哪些内容,每个题注的说明行写明数据来源以及重绘图省略的部分。

致谢

文本
  • Text: B. P. Abbott et al. (LIGO Scientific Collaboration and Virgo Collaboration), “Observation of Gravitational Waves from a Binary Black Hole Merger”, Phys. Rev. Lett. 116, 061102 (2016), doi:10.1103/PhysRevLett.116.061102. Abridged from the published letter (Sections IV and VII, parts of Sections I, III, V and VI and most of the acknowledgments cut; sections and references renumbered); figures redrawn; figure captions shortened. Licence: CC BY 3.0, https://creativecommons.org/licenses/by/3.0/ · LIGO Scientific Collaboration and Virgo Collaboration · CC BY 3.0
  • Data for Figures 1, 2 and 4: the GW150914 data files released by the Gravitational Wave Open Science Center (gwosc.org), a service of the LIGO Scientific Collaboration, the Virgo Collaboration and KAGRA; redrawn in code · LIGO Scientific Collaboration and Virgo Collaboration, GWOSC · CC BY 4.0
字体
Gelasio (SIL OFL 1.1) · Albert Sans (SIL OFL 1.1)
沙盒PDF