Skip to main content
Recipe number 95

Cookbook · Chapter 5 · Book structure

A medical article in Vancouver style

A clinical trial report on A4 in two columns: raised citation numbers, a numbered Vancouver reference list and DOIs that open as links in the PDF.

On this page

p. 181 · 1 of 3

  • Trim 210 × 297 mm
  • 2 columns, 6 mm gutter
  • PT Serif 9.3/12.8
  • Fira Sans
  • Fira Sans Condensed
  • Fira Sans@tnum
  • 3 pages
  • Level
  • Postext 1.65.0
  • Laid out in 298 ms
  • 180 lines of code

In short

A short medical research article, laid out like a journal page. The authors cite with codes; Postext prints small raised numbers in the text and builds the numbered list of references at the end, with each DOI as a link.

What you'll build

Three pages of a clinical journal: an original article reporting a pilot trial, set on A4 in two columns the way the ICMJE journals print them. A teal masthead runs across the top of the first page, over the article type, a three-line title, the authors with raised affiliation numbers and a structured abstract on a pale tint. The authors cite with BibTeX keys, and the pages show what a medical editor expects: small raised numbers after the full stop, consecutive works joined as 6–8, two others set close as 6,9, and a numbered reference list in the NLM form, Lancet 2016;387(10022):957–67, closing with each work's DOI. In the PDF every number jumps to its reference and every DOI opens the article. The trial is invented; the eleven works it cites are real.

This recipe answers

  • How do I set citation numbers as superscripts and make DOIs live links, as medical journals do?
  • How do I cite works and build the bibliography in APA, IEEE or another citation style?

The short answer

script.js · lines 29–49in full code
// [@key] prints a raised number in order of first citation. English journals set it after
// the full stop, "control.[@ncdrisc2021]"; Spanish ones before it, "controlada[@ncdrisc2021].".
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
// elsevier-vancouver is the bundled NLM/Vancouver style (citation-sequence). Two edits bring
// its list to the NLM sample references: "1." instead of "[1]", and the issue after the
// volume, 2015;373(22):2103-16.
const vancouver = STYLES['elsevier-vancouver']
  .replace('<text variable="citation-number" prefix="[" suffix="]"/>',
    '<text variable="citation-number" suffix="."/>')
  .replace('<text variable="volume"/>',
    '<group><text variable="volume"/><text variable="issue" prefix="(" suffix=")"/></group>');
const citations = {
  style: 'custom', customStyle: vancouver,
  marker: 'superscript', collapseRanges: true, // raised 1 and 6–8, not [1] and [6–8]
  link: true, // each number jumps to its reference, in the PDF and on screen
  // 7.8 pt: the eleven societies of reference 5, ACC/AHA/…/PCNA, fit one line whole
  bibliography: { fontSize: em(0.84), lineHeight: pt(10.4), entrySpacing: pt(1.6),
    labelWidth: mm(5.5), labelAlign: 'right', // a column for the numbers: 9. and 10. end
    // together, and every entry's text starts at one x, first line and turnovers alike
    doi: 'link' }, // https://doi.org/… printed whole and clickable
};

Vancouver numbers as superscripts, a "1." list and DOIs that are links

Ingredients

Type
PT Serif, Fira Sans, Fira Sans Condensed (SIL OFL 1.1)
Assets
None: every picture is drawn in code

Method

#1 · Vancouver, raised and linked

The code is the short answer above. Of the bundled styles, elsevier-vancouver is the one that follows the NLM's Citing Medicine (citation order, authors as Ettehad D, Emdin CA, six names then et al., abbreviated journal titles), so it is the file to start from. Two string replacements bring its list to the NLM sample references: the number reads 1. instead of [1], and the issue follows the volume. marker: 'superscript' sets the citations as raised numbers whatever the style writes, and doi: 'link' keeps each https://doi.org/ address as a link. Two works apart print close, 6,9: a space after the comma would stretch on a justified line. In the list, labelWidth gives the numbers a column of their own and labelAlign: 'right' ends 9. and 10. together, so every entry's text starts at one x, on its first line as on its turnovers. The AMA style is also bundled and raises its numbers by itself, but its list differs from Vancouver in punctuation and page ranges.

#2 · A title block across both columns

script.js · lines 53–83in full code
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.3),
  textTransform: 'uppercase' };
const JOURNAL = t({ en: 'Almenara Medical Journal', es: 'Revista Médica de Almenara' });
const titleBlock = { enabled: true,
  minHeight: mm(62), // the abstract and the text start under the note, on both columns
  slot: { elements: [
    { kind: 'box', id: 'band', style: { backgroundColor: col('accent') },
      placement: { anchor: { to: 'page', edge: 'top-left' },
        size: { width: 'fill', height: mm(15) } } },
    text('journal', JOURNAL, COND, 9.5, { ...caps, color: col('paper'),
      placement: at('page', 'top-left', INNER, 6) }),
    text('issue', '{attr.issue}', COND, 9.5, { ...caps, color: col('paper'),
      align: 'right', placement: at('page', 'top-right', -OUTER, 6, 60) }),
    text('kind', '{attr.kind}', COND, 9, { ...caps, color: col('accent'),
      placement: at('container', 'top-left', 0, 0, MEASURE) }),
    text('title', '{titleText}', SANS, 19.5, { fontWeight: 600, lineHeight: 1.16,
      placement: at('#kind', 'below', 0, 3, MEASURE - 20) }),
    text('authors', '{attr.authors}', SERIF, 10.5, { inlineMarks: true, // ^1^ → ¹
      placement: at('#title', 'below', 0, 4.5, MEASURE) }),
    text('affiliations', '{attr.affiliations}', SANS, 7.4, { inlineMarks: true,
      lineHeight: 1.35, color: col('muted'), placement: at('#authors', 'below', 0, 2, MEASURE) }),
    { kind: 'rule', id: 'rule', thickness: pt(0.5), color: col('rule'),
      placement: at('#affiliations', 'below', 0, 3, MEASURE) },
    text('note', '{attr.note}', SANS, 7.4, { color: col('muted'),
      placement: at('#rule', 'below', 0, 1.6, MEASURE) }),
  ] },
};

The article title is the only level-1 heading, with the style article, which spans the page and draws it from its design. The article type, the authors, the affiliations and the note come from heading attributes. inlineMarks turns ^1^ in the attribute into a raised affiliation number, and the \n in the affiliations starts a line for each institution. The band is anchored to the trim, so it reaches the top edge of the paper.

#3 · A structured abstract and a key points box

script.js · lines 87–97in full code
const box = (id, bold, more) => ({ id, border: { enabled: false }, snapToGrid: false,
  marginTop: pt(LEAD), marginBottom: pt(LEAD),
  titleStyle: { ...caps, fontSize: pt(8.5), color: col('accent') }, // run-in labels in bold
  body: { fontFamily: SANS, fontSize: pt(8.3), lineHeight: pt(11.2), textAlign: 'left',
    firstLineIndent: pt(0), paragraphSpacing: true, boldColor: col(bold) }, ...more });
const calloutStyles = [
  box('abstract', 'accent', { background: col('tint'), padding: mm(3.5), marginTop: pt(0) }),
  box('keypoints', 'ink', { backgroundEnabled: false, padding: { top: mm(2.5), right: mm(0),
    bottom: mm(1), left: mm(0) }, stripe: { enabled: true, side: 'top', width: pt(2.5),
    color: col('accent') } }),
];

Both boxes share one text style: Fira Sans at 8.3 pt with bold run-in labels, the voice a reader expects for summary matter. The abstract carries a tint and its labels in teal; the key points sit under a 2.5 pt stripe with the labels in ink. snapToGrid: false keeps the padding exact, so the abstract box hugs its text.

#4 · Table 1 and Figure 1 at the head of a column

script.js · lines 300–319in full code
const resources = () => [
  { id: 'tbl-baseline', typeId: 'table', kind: 'table', createdAt: 0, updatedAt: 0,
    placement: { position: 'top' },
    caption: t({ en: 'Characteristics of the patients at baseline.',
      es: 'Características de los pacientes al inicio.' }),
    note: t({ en: 'Values are mean (SD) or number (%). BP, blood pressure, in mm Hg.',
      es: 'Valores en media (DE) o número (%). PA, presión arterial, en mm Hg.' }),
    table: { model: { headerRowCount: 1, columnWidths: [2.2, 1.1, 1.1],
      rows: parseTSV(baseline).rows.map((row, r) => row.map(({ content }, c) => ({ content,
        ...(r === 0 && { isHeader: true }), ...(c > 0 && { align: 'center' }) }))) } } },
  { id: 'fig-home', typeId: 'figure', kind: 'svg', createdAt: 0, updatedAt: 0,
    placement: { position: 'top' }, svg: { fileId: 'home.svg', width: 850, height: 520 },
    caption: t({ en: 'Mean home systolic pressure by week in the telemonitoring group, with its '
      + '95% confidence interval. The dashed line is the home target of 135\u00a0mm\u00a0Hg.',
    es: 'Presión sistólica domiciliaria media por semana en el grupo de telemonitorización, con '
      + 'su intervalo de confianza del 95\u00a0%. La línea discontinua es el objetivo de '
      + '135\u00a0mm\u00a0Hg.' }),
    altText: t({ en: 'A line falling from 158 mm Hg in week 1 to 135 mm Hg in week 12.',
      es: 'Una línea que baja de 158 mm Hg en la semana 1 a 135 mm Hg en la semana 12.' }) },
];

The table is read from tab-separated text, as a spreadsheet exports it, and its header row is filled in teal with white bold labels. Both resources float to the head of a column after the paragraph that cites them. With shortLabel set to the type's full name, :ref prints (Table 1) as journals write it, and the numbered: false on the title keeps the count at 1 rather than 1.1. Its cells set Fira Sans with figureStyle: 'tabular', so every digit takes the same width and the means and counts of the two arms line up.

script.js · lines 17–21in full code
const palette = { ink: '#1a1d21', accent: '#0d5c63', tint: '#e5eff0', rule: '#9fb4b6',
  muted: '#566065', 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' } }));

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 095 · A medical article in Vancouver style ══════════════
// https://postext.dev/en/cookbook/medical-article-vancouver
// Code: MIT · Text: original (CC BY 4.0) · Chart: generated in code (CC BY 4.0)
// Fonts: PT Serif, Fira Sans, Fira Sans Condensed (SIL OFL 1.1) · Needs postext ≥ 1.65.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerCitationEngine, registerResourceImage,
  defaultResourceTypes, parseTSV, 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 = 'medical-article-vancouver';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: black text, one clinical teal for the journal's own marks
const palette = { ink: '#1a1d21', accent: '#0d5c63', tint: '#e5eff0', rule: '#9fb4b6',
  muted: '#566065', 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] = ['PT Serif', 'Fira Sans', 'Fira Sans Condensed'];
const [TRIM_W, TRIM_H, TOP, BOTTOM, INNER, OUTER, GUTTER] = [210, 297, 24, 22, 17, 17, 6];
const MEASURE = TRIM_W - INNER - OUTER;
const LEAD = 12.8; // pt: 9.3 pt type, as journals set two columns of A4

// #region answer: Vancouver numbers as superscripts, a "1." list and DOIs that are links
// [@key] prints a raised number in order of first citation. English journals set it after
// the full stop, "control.[@ncdrisc2021]"; Spanish ones before it, "controlada[@ncdrisc2021].".
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
// elsevier-vancouver is the bundled NLM/Vancouver style (citation-sequence). Two edits bring
// its list to the NLM sample references: "1." instead of "[1]", and the issue after the
// volume, 2015;373(22):2103-16.
const vancouver = STYLES['elsevier-vancouver']
  .replace('<text variable="citation-number" prefix="[" suffix="]"/>',
    '<text variable="citation-number" suffix="."/>')
  .replace('<text variable="volume"/>',
    '<group><text variable="volume"/><text variable="issue" prefix="(" suffix=")"/></group>');
const citations = {
  style: 'custom', customStyle: vancouver,
  marker: 'superscript', collapseRanges: true, // raised 1 and 6–8, not [1] and [6–8]
  link: true, // each number jumps to its reference, in the PDF and on screen
  // 7.8 pt: the eleven societies of reference 5, ACC/AHA/…/PCNA, fit one line whole
  bibliography: { fontSize: em(0.84), lineHeight: pt(10.4), entrySpacing: pt(1.6),
    labelWidth: mm(5.5), labelAlign: 'right', // a column for the numbers: 9. and 10. end
    // together, and every entry's text starts at one x, first line and turnovers alike
    doi: 'link' }, // https://doi.org/… printed whole and clickable

The composed script.js runs as it is: paste it into any page’s module script, or open the recipe on CodePen. Recipe folder on GitHub ↗ (opens in a new tab)

Variations

#Use the AMA style

The AMA style raises its numbers itself and lists works with doi:10.1056/…; drop the edits and the marker.

-  style: 'custom', customStyle: vancouver,
-  marker: 'superscript', collapseRanges: true, // raised 1 and 6–8, not [1] and [6–8]
+  style: 'american-medical-association',

For a print-only PDF, keep the addresses as plain black text.

-    doi: 'link' }, // https://doi.org/… printed whole and clickable
+    doi: 'text' },

#Numbers in brackets

Some Vancouver journals write the numbers on the line, in square brackets.

-  marker: 'superscript', collapseRanges: true, // raised 1 and 6–8, not [1] and [6–8]
+  marker: 'brackets', collapseRanges: true,

Pitfalls

Pitfall

A heading style's header holds for its whole section

header: { elements: [] } on a title's style removes the running heads up to the next styled heading, not only on the opener. To keep them off the first page alone, give the header elements pages: 'body'. Running heads and folios →

  • A heading style's header holds for the whole section that heading opens, so header: { elements: [] } on the title would remove the running heads from every page up to the next styled heading. pages: 'body' on the running heads is enough to keep them off the first page.

Credits

Text
Original prose, CC BY 4.0
Fonts
PT Serif (SIL OFL 1.1) · Fira Sans (SIL OFL 1.1) · Fira Sans Condensed (SIL OFL 1.1)
SandboxPDF