简单来说
一篇著名的人工智能论文,删节后重新排版。示例提示词和模型的回答放在带页签的框里,左右并排,每个回答旁有对勾或叉号;图表按论文自己的数字绘制。
成品一览
一篇机器学习预印本,共七页,美国信纸开本:Wei等人的Chain-of-Thought Prompting Elicits Reasoning in Large Language Models,依据其arXiv版本删节,许可证为CC BY 4.0。第一页是这篇论文最有名的图,用框排出来,而不是贴一张图片:左边是标准提示,右边是思维链提示;每段提示放在页签为Model Input的框里,每个回答放在页签为Model Output的框里,示例用IBM Plex Mono,思维链用彩色粗体,错误的回答带叉号,正确的带对勾。正文按NeurIPS论文的方式引用,(Brown et al., 2020),文献数据取自论文自己的参考文献表,重建为BibTeX。表2和两幅图表按论文公布的数字重绘。
这道食谱解答
- 怎样把AI论文中的提示词和模型输出示例并排排在框里?
- 怎样用Postext重新排版arXiv或PubMed Central上的开放获取论文,并保留引用、图和许可声明?
- 怎样按APA、IEEE或其他引用样式引用文献并生成参考文献表?
简短回答
// :::columns{count=2 breaks="4"} inside the "figure" box opens the right column at its fourth
// block; each nested box counts as one block.
const tab = (fill) => ({ fontFamily: SANS, fontSize: pt(7), fontWeight: 600,
color: col('paper'), background: col(fill), position: 'top-left', inset: mm(3),
height: mm(4.2), offset: mm(2.1), paddingX: mm(2.2) }); // straddles the top edge
const exemplar = (id, fill, ink, extra) => ({ id, background: col(fill),
border: { enabled: true, color: col('rule'), width: pt(0.6) }, borderRadius: mm(2.4),
padding: { top: mm(4.4), right: mm(3), bottom: mm(2.6), left: mm(3) },
marginTop: mm(4.2), marginBottom: ZERO, label: tab(ink),
body: { fontFamily: MONO, fontSize: pt(7.8), lineHeight: pt(10.4), color: col('ink'),
boldColor: col(ink), // **…** marks the chain of thought: the highlight of the original
textAlign: 'left', hyphenation: false, paragraphSpacing: true, firstLineIndent: ZERO },
...extra });
const mark = (id) => ({ icon: { kind: 'resource', resourceId: id, size: mm(5.6),
position: 'corner', cornerSide: 'right' } }); // a badge on the top-right corner
const promptBoxes = [
{ id: 'figure', span: 'page', backgroundEnabled: false, border: { enabled: false },
padding: mm(0), columnGap: mm(6), marginTop: ZERO, marginBottom: pt(LEAD),
body: { fontFamily: SANS, fontSize: pt(8.4), lineHeight: pt(11.4), color: col('ink'),
boldColor: col('accent'), textAlign: 'left', paragraphSpacing: true,
firstLineIndent: ZERO } },
exemplar('input', 'tint', 'accent'),
exemplar('right', 'mint', 'green', mark('mark-right')),
exemplar('wrong', 'mint', 'green', mark('mark-wrong')),
];
用料
做法
#1 · 图1由三种框样式组成
代码就是上面的简短回答。整幅图是一个通栏的框,自身没有边框;框内的:::columns{count=2 breaks="4"}让右栏从第四个块开始,每个嵌套框算作一个块。提示框和回答框出自同一个样式函数,区别只在底色、页签颜色和角上的徽标:icon设为position: 'corner'时可以用SVG资源,文档字体里没有的对勾和叉号就是这样上了页面。排你自己的论文时,把每个示例写成框内的普通段落,用**…**标出推理部分,框样式的boldColor就把它变成高亮。
#2 · natbib式的作者–年份引用
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
// Chicago author-date writes (Brown et al. 2020); ML venues put a comma before the year.
const AUTHOR_YEAR = '<group delimiter=" ">\n <text macro="author-inline"/>';
const natbib = STYLES['chicago-author-date']
.replace(AUTHOR_YEAR, AUTHOR_YEAR.replace('" "', '", "'));
const citations = { style: 'custom', customStyle: natbib, link: true,
bibliography: { fontSize: em(0.8), lineHeight: pt(10.2), entrySpacing: pt(1.8),
hangingIndent: mm(4), doi: 'text' } };
// The text's two web addresses are links: clickable in the PDF, printed in parentheses on
// paper, `[name census data](https://namecensus.com/)` as "name census data (namecensus.com)".
const links = { print: 'inline', urlDisplay: 'short' };
机器学习会议采用natbib的作者–年份样式:姓名和年份之间加逗号,三位作者以上写et al.。引擎自带的样式中最接近的是Chicago author-date,所以本例把其CSL中连接作者和年份的那一组,从空格改成逗号。你的.bib文件可以原样带来:粘贴进:::references{format=bibtex}块,用[@key]得到*(Brown et al., 2020),用@key得到Brown et al. (2020)*。后缀保留前面写的逗号和其中的强调,所以[@brown2020language, *inter alia*]印成(Brown et al., 2020, inter alia),与原文一致。题注的引用写法相同:图4的题注写@jie2022learning和@lan2021mwptoolkit,这两部文献不用nocite也会进入参考文献表。
正文里的两个网址,第5节的人名普查数据和版权说明里的许可证,都写成链接:[name census data](https://namecensus.com/)。设置 links: { print: 'inline', urlDisplay: 'short' } 后,纸面在链接文字后面用括号印出地址,去掉 https://,PDF 里的链接照样可以点击。直接把地址当普通文字写进去,印出来一样,点击却打不开。
#3 · 标题区
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, y, width = MEASURE) => ({ anchor: { to, edge },
offset: { x: ZERO, y: mm(y) }, size: { width: mm(width), height: 'auto' } });
const titleBlock = { enabled: true, minHeight: mm(58), slot: { elements: [
text('venue', '{attr.venue}', MONO, 7.5, { fontWeight: 500, letterSpacing: pt(0.6),
color: col('accent'), placement: at('container', 'top-left', 0) }),
text('title', '{titleText}', SERIF, 23, { fontWeight: 600, lineHeight: 1.1,
placement: at('#venue', 'below', 5) }),
text('authors', '{attr.authors}', SANS, 9.6, { fontWeight: 500, lineHeight: 1.45,
placement: at('#title', 'below', 6) }),
text('affiliation', '{attr.affiliation}', SANS, 8.6, { color: col('muted'),
placement: at('#authors', 'below', 1.2) }),
{ kind: 'rule', id: 'rule', thickness: pt(0.5), color: col('rule'),
placement: at('#affiliation', 'below', 4) },
text('note', '{attr.note}', SERIF, 8.2, { lineHeight: 1.35,
color: col('muted'), placement: at('#rule', 'below', 2) }),
] } };
标题是文档中唯一的一级标题,所用样式横跨两栏,绘制一个设计好的标题区:会议信息、标题、分两行的作者、单位和删节说明。作者和说明都是标题属性,属性里的\n另起一行,相当于LaTeX \author中的\\。排你自己的论文时,改属性即可,设计不用动。
#4 · 与原文一致的图号
// Figure 1 is boxes, which the figure counter does not see: number the charts by type.
const numbered = (id, word, n, extra) => ({ id, name: `${word} ${n}`,
shortLabel: `${word} ${n}`, captionPrefix: `${word} ${n}`, numberingTemplate: '',
resetOn: 'never', counterFormat: 'decimal', ...extra });
const resourceTypes = [numbered('mark', 'Mark', ''), numbered('fig2', 'Figure', 2),
numbered('fig4', 'Figure', 4),
numbered('tab2', 'Table', 2, { captionStyle: { position: 'above' } })];
const ACROSS = { position: 'top', span: 'page' }; // a float over both columns
const svg = (id, typeId, file, [width, height], caption, note, altText, placement) => ({
id, typeId, kind: 'svg', createdAt: 0, updatedAt: 0,
placement: placement ?? { position: 'top' }, svg: { fileId: file, width, height },
caption, note, altText });
引擎按首次引用的顺序给图编号,但这里的图1是框,计数器看不到它。所以每幅重绘的图表都有自己的资源类型,编号直接写在标签里,numberingTemplate留空,从而保留arXiv版本的编号:图2、图4和表2。在你自己的论文中,所有图都是资源,一个numberingTemplate: '{n}'的figure类型就能完成编号。
#5 · 用论文数据排表2
const SETS = ['GSM8K', 'SVAMP', 'ASDiv', 'AQuA', 'MAWPS'];
const RESULTS = [ // model, size, then standard / CoT pairs per benchmark; * CoT beats standard
['UL2', '20B', '4.1 4.4* 10.1 12.5* 16.0 16.9* 20.5 23.6* 16.6 19.1*'],
['LaMDA', '420M', '2.6 0.4 2.5 1.6 3.2 0.8 23.5 8.3 3.2 0.9'],
['', '2B', '3.6 1.9 3.3 2.4 4.1 3.8 22.9 17.7 3.9 3.1'],
['', '8B', '3.2 1.6 4.3 3.4 5.9 5.0 22.8 18.6 5.3 4.8'],
['', '68B', '5.7 8.2* 13.6 18.8* 21.8 23.1* 22.3 20.2 21.6 30.6*'],
['', '137B', '6.5 14.3* 29.5 37.5* 40.1 46.6* 25.5 20.6 43.2 57.9*'],
['GPT', '350M', '2.2 0.5 1.4 0.8 2.1 0.8 18.1 8.7 2.4 1.1'],
['', '1.3B', '2.4 0.5 1.5 1.7 2.6 1.4 12.6 4.3 3.1 1.7'],
['', '6.7B', '4.0 2.4 6.1 3.1 8.6 3.6 15.4 13.4 8.8 3.5'],
['', '175B', '15.6 46.9* 65.7 68.9* 70.3 71.3* 24.8 35.8* 72.7 87.1*'],
['Codex', '–', '19.7 63.1* 69.9 76.4* 74.0 80.4* 29.5 45.3* 78.7 92.6*'],
['PaLM', '8B', '4.9 4.1 15.1 16.8* 23.7 25.2* 19.3 21.7* 26.2 30.5*'],
['', '62B', '9.6 29.9* 48.2 46.7 58.7 61.9* 25.6 22.4 61.8 80.3*'],
['', '540B', '17.9 56.9* 69.4 79.0* 72.1 73.9* 25.2 35.8* 79.2 93.3*'],
];
const cell = (content, extra) => ({ content, align: 'right', ...extra });
const tableRows = () => [
[cell('Model', { isHeader: true, align: 'left', colSpan: 2 }), { content: '',
hiddenBy: { row: 0, col: 0 } }, // gotcha: merged-cells-hiddenby
...SETS.flatMap((set, i) => [cell(set, { isHeader: true, align: 'center', colSpan: 2 }),
{ content: '', hiddenBy: { row: 0, col: 2 + 2 * i } }])],
[cell('', { isHeader: true }), cell('', { isHeader: true }),
...SETS.flatMap(() => [cell('standard', { isHeader: true }), cell('CoT', { isHeader: true })])],
...RESULTS.map(([model, size, values]) => [cell(model ? `**${model}**` : '', { align: 'left' }),
cell(size, { align: 'left' }),
...values.split(' ').map((v) => cell(v.endsWith('*') ? `**${v.slice(0, -1)}**` : v))]),
];
结果只录入一次,与LaTeX源文件中的一致,同时供表2和图4使用,图表因此不会与表格不符。每个基准名称跨两列;合并单元格在其延伸的位置需要标有hiddenBy的占位单元格。粗体标出思维链胜过标准提示的单元格,相当于原文中的绿色单元格。
完整食谱
// ═══ Postext Cookbook · Nº 137 · An AI preprint with prompt exemplars in boxes ═══════
// https://postext.dev/en/cookbook/ai-preprint-prompt-exemplars
// Code: MIT · Text: Wei et al. 2022, arXiv:2201.11903 (CC BY 4.0) · Charts: drawn in code
// Fonts: Newsreader, IBM Plex Sans, IBM Plex Mono (SIL OFL 1.1) · Needs postext ≥ 1.65.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerCitationEngine, registerResourceImage,
inlineSvgFonts,
} 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 = 'ai-preprint-prompt-exemplars';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a cool ink, a prompt blue, an answer green and a red for the wrong answer
const palette = { ink: '#1b1e24', accent: '#1f5fa6', green: '#21744a', red: '#b3362d',
tint: '#e9f0f8', mint: '#e6f2eb', rule: '#b4bcc8', muted: '#5b6270', 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, MONO] = ['Newsreader', 'IBM Plex Sans', 'IBM Plex Mono'];
// US letter, two columns of 85.5 mm as ML venues print.
const [TRIM_W, TRIM_H, TOP, BOTTOM, SIDE, GUTTER] = [215.9, 279.4, 22, 22, 19, 7];
const MEASURE = TRIM_W - 2 * SIDE;
const COLUMN = (MEASURE - GUTTER) / 2;
const LEAD = 12.8; // pt
const ZERO = pt(0);
// #region answer: Figure 1 as boxes: two columns, a tab on each box, a ✓ or ✗ in the corner
// :::columns{count=2 breaks="4"} inside the "figure" box opens the right column at its fourth
// block; each nested box counts as one block.
const tab = (fill) => ({ fontFamily: SANS, fontSize: pt(7), fontWeight: 600,
color: col('paper'), background: col(fill), position: 'top-left', inset: mm(3),
height: mm(4.2), offset: mm(2.1), paddingX: mm(2.2) }); // straddles the top edge
const exemplar = (id, fill, ink, extra) => ({ id, background: col(fill),
border: { enabled: true, color: col('rule'), width: pt(0.6) }, borderRadius: mm(2.4),
padding: { top: mm(4.4), right: mm(3), bottom: mm(2.6), left: mm(3) },
marginTop: mm(4.2), marginBottom: ZERO, label: tab(ink),
body: { fontFamily: MONO, fontSize: pt(7.8), lineHeight: pt(10.4), color: col('ink'),
boldColor: col(ink), // **…** marks the chain of thought: the highlight of the original
textAlign: 'left', hyphenation: false, paragraphSpacing: true, firstLineIndent: ZERO },
...extra });
const mark = (id) => ({ icon: { kind: 'resource', resourceId: id, size: mm(5.6),
position: 'corner', cornerSide: 'right' } }); // a badge on the top-right corner
const promptBoxes = [
{ id: 'figure', span: 'page', backgroundEnabled: false, border: { enabled: false },
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#改用APA引用
APA写作*(Roy & Roth, 2015)*,并列出多达二十位作者,大模型论文的参考文献很少需要这样。
-const citations = { style: 'custom', customStyle: natbib, link: true,
+const citations = { style: 'apa', link: true,#单栏排版
NeurIPS式的单栏需要更宽的左右页边距,才能保持易读的行长;通栏的框随之占满这一栏。
-const [TRIM_W, TRIM_H, TOP, BOTTOM, SIDE, GUTTER] = [215.9, 279.4, 22, 22, 19, 7];
+const [TRIM_W, TRIM_H, TOP, BOTTOM, SIDE, GUTTER] = [215.9, 279.4, 24, 24, 38, 7];
- layout: { layoutType: 'double', gutterWidth: mm(GUTTER) },
+ layout: { layoutType: 'single' },#框中的代码清单
如果提示词里有代码,代码清单与按键中的清单框用粗体和斜体片段给语法着色。
常见问题
易错点
嵌套框忽略span、placement和snapToGrid
嵌套在另一个标注框中的标注框会忽略自己的span、placement、snapToGrid和floatBarrier:它总是在父框内部排,宽度为父框的内宽。 嵌套框 →
- 双栏版式中,通栏框只有在放得下、且下方至少还能排两行正文时,才留在当前页。图1之所以在第1页,是因为摘要用9.3 pt、内边距较紧;摘要再长一些,图就会移到第2页。
致谢
- 文本
- “Chain-of-Thought Prompting Elicits Reasoning in Large Language Models”, NeurIPS 2022, arXiv:2201.11903v6, abridged (sections 3.3, 3.4, 7 and the appendices cut, pointers to omitted figures and appendices removed); Figures 2 and 4 redrawn in code from the paper’s numbers, Figure 1 set as boxes, Table 2 reset · Jason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma, Brian Ichter, Fei Xia, Ed H. Chi, Quoc V. Le, Denny Zhou · CC BY 4.0
- 字体
- Newsreader (SIL OFL 1.1) · IBM Plex Sans (SIL OFL 1.1) · IBM Plex Mono (SIL OFL 1.1)


