Skip to main content
Recipe number 81

Cookbook · Chapter 1 · Page & grid

Dates and acronyms upright in vertical text

Two founding documents of 1912 set vertically, bound on the right: two-digit numbers stand upright in one cell unaided, and :tcy and :upright mark the rest.

On this page
Output
Canvas · PDF
Postext
Tested with Postext 1.65.0
Needs ≥ 1.25.0 · postext-pdf ≥ 1.25.0
Licence
Updated 10 Oct 2026
Code MIT · Text CC BY 4.0

p. 一 · 1 of 7

  • Trim 184 × 260 mm
  • 1 column
  • Noto Serif TC 12/21
  • LXGW WenKai TC
  • Noto Sans TC
  • 7 pages
  • Level
  • Postext 1.65.0
  • Laid out in 59 ms
  • 181 lines of code

In short

Two Chinese documents from 1912, printed in top-to-bottom columns. It shows how to set dates, numbers and Latin letters so they read well inside the vertical text.

What you'll build

A seven-page reader of two founding texts of the Republic of China: Sun Wen's proclamation on taking office on 1 January 1912, and the first two chapters of the Provisional Constitution of 11 March. The pages are set vertically on a 184 × 260 mm page bound on the right. The documents keep their own Chinese numerals, 民國元年三月十一日. The headnotes and notes, in a Kai face, give dates of the Western calendar, counts and issue numbers in Arabic figures, and those figures are what the recipe sets: 10月10日 stands upright one number to a cell, 1912 and Sun Yat-sen are turned on their side, 民國115年 fits three digits into one cell and ROC stacks its letters. A vermilion cover inside a double rule, a vermilion band where each document opens and fore-edge heads with folios in Chinese numerals frame the text.

This recipe answers

  • How do I set dates and numbers upright inside vertical text?
  • How do I set a Chinese book vertically, bound on the right?
  • How do I set the type area in characters, so many to the line and so many lines to the page?

The short answer

script.js · lines 41–50in full code
const layout = { layoutType: 'single', writingMode: 'vertical-rl' }; // binding 'auto': right
const cjk = {
  // 10月10日: each number of up to two digits stands upright in one cell (tate-chu-yoko);
  // 1912 and Sun Yat-sen stay on their side, as clreq sets long numbers and Latin words.
  uprightDigits: 2,
  // The type area in characters: 44 down each line, 19 lines to the page.
  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: 19 },
};
// By hand, in the Markdown: 民國:tcy[115]年 puts three digits in one cell, :upright[ROC]
// stands each letter of an acronym upright, :sideways[…] turns any run with the line.

Vertical text where numbers of one or two digits stand upright

Ingredients

Type
Noto Serif TC, Noto Sans TC, LXGW WenKai TC (SIL OFL 1.1)
Assets
None: every picture is drawn in code

Method

#1 · Let the setting take the short numbers

The code is the short answer above. With cjk.uprightDigits: 2 every run of one or two digits in vertical text stands upright in a cell of one em, the two digits side by side: 10月10日, 第35號 and 7章56條 need no markup. A longer number is set whole on its side, like a Latin word, which is how clreq sets numbers of four digits, so 1912 and 1644 read down the line turned a quarter. A three-digit number that should stand upright takes a mark: 民國:tcy[115]年 squeezes 115 into the em. :upright[ROC] stands each letter in a cell of its own, one under the other, and the line never breaks inside it (numbers in vertical text).

Page 4, the notes: 10月10日 and 2月12日 upright, 1911 and Sun Yat-sen on their side, 268 and 115 squeezed by :tcy, ROC stacked by :upright.

The texts of 1912 stay as printed. The editor's notes follow Taiwan's rules for numbers, the Executive Yuan's 公文書橫式書寫數字使用原則 of 2004: dates, serial numbers and counts take Arabic figures (1912年3月8日, 第35號, 7章56條), while proper names, set phrases and round figures keep Chinese numerals (東三省, 四萬萬, 四億), and so does the lunar date, 辛亥年八月十九日. Where a note quotes a heading or a term of the documents it keeps their form, 第一章 and 二十二行省. Those rules were written for horizontal documents; set vertically, their figures are the ones the recipe has to stand upright.

#2 · Open each document with a band on the right

script.js · lines 54–78in full code
// The margins are minimums: the grid centres the 44 characters (186.3 mm) between them,
// so the type area starts HEAD mm down the sheet. The band's title starts there too.
const HEAD = MARGIN.top + (TRIM.h - MARGIN.top - MARGIN.bottom - LINE) / 2;
const BAND = 42; // mm from the right trim edge: where a reader of vertical text starts
const onBand = { color: col('paper'), overflow: 'wrap' };
// In the flow of a vertical page x runs down the sheet and y leftward from its right edge.
const at = (x, y, extra = {}) => ({ anchor: { to: 'page', edge: 'top-left' },
  offset: { x: mm(x), y: mm(y) }, ...extra });
const opener = {
  enabled: true,
  minHeight: mm(BAND - 15), // past the side margin (21.6 mm), 6 mm of paper before the text
  slot: { elements: [
    { kind: 'box', id: 'band', style: { backgroundColor: col('seal') },
      placement: { anchor: { to: 'bleed', edge: 'top-left' }, size: { height: mm(BAND) } } },
    { kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: HEI,
      fontWeight: 700, fontSize: pt(34), lineHeight: 1.2, letterSpacing: pt(4), align: 'left',
      placement: at(HEAD, 8) },
    { kind: 'text', id: 'latin', content: '{attr.latin}', ...onBand, fontFamily: HEI,
      fontSize: pt(9), lineHeight: 1.6, align: 'left', placement: at(HEAD, 25) },
    // The date ends where the lines of text end: align 'right' is the foot of a vertical line.
    { kind: 'text', id: 'date', content: '{attr.date}', ...onBand, fontFamily: HEI,
      fontWeight: 500, fontSize: pt(13), lineHeight: 1.2, align: 'right',
      placement: at(HEAD, 24, { size: { width: mm(LINE) } }) },
  ] },
};

In a vertical flow the top of the page is the sheet's right edge, where reading starts. A heading design anchored to the top of the bleed is therefore a band down the right edge, and its size.height is its width on the sheet. Offsets turn with the flow: x measures down the sheet, y leftward. The grid centres the type area between the margins, and HEAD repeats that sum, so the title starts level with the first character of every line. align: 'right' puts the date at the foot of its line, where the lines of text end, and cjk.uprightDigits reaches the design's text too: the 11 of 3月11日 stands in one cell, as in the body. The band is the one of Chapter opener on a full-bleed band, turned a quarter.

A heading design has no parity, so the band always runs down the sheet's right edge. On page 2, a right-hand page, that edge is the fore-edge; on page 5, a left-hand page of a book bound on the right, it is the spine, and the title starts 8 mm from the fold, inside the 21.6 mm inner margin. A stapled reader opens flat enough for that. For a sewn or glued book, open each document on a right-hand page with breakBefore.parity: 'even', which leaves page 5 blank.

Page 2: the title from the head of the type area, the date at the foot of the band, 10 of 晚上10時 and 29 of 同月29日 upright in the headnote.

#3 · Put the running heads on the fore-edge

script.js · lines 82–90in full code
const foreEdge = (id, content, edge, y) => ({
  kind: 'text', id, content, writingMode: 'vertical-rl', pages: 'body', align: 'left',
  fontFamily: HEI, fontSize: pt(9.6), color: col('muted'), overflow: 'clip',
  placement: { anchor: { to: 'outer', edge }, offset: { y: em(y) } },
});
const header = { elements: [
  foreEdge('head', '{chapterTitle}', 'top', 4), // four characters below the type area
  foreEdge('folio', '{pageNumber}', 'bottom', -5), // ends five characters above its foot
] };

anchor.to: 'outer' is the margin away from the spine, so in a book bound on the right the heads run down the left edge of a recto and the right edge of a verso. The title stands four characters below the head of the type area and the folio ends five above its foot, both set vertically at 80 % of the body size (vertical text elements). pageNumbering.format: 'trad-chinese-informal' prints the folios 三, 四, 六 and 七, and pages: 'body' keeps them off the two openers.

#4 · Bleed the cover from a page-wide design

script.js · lines 94–119in full code
const frame = (id, inset, width) => ({ kind: 'box', id,
  style: { borderColor: col('tint'), borderWidth: pt(width) },
  placement: at(inset, inset, { size: { width: mm(TRIM.h - 2 * inset),
    height: mm(TRIM.w - 2 * inset) } }) });
const coverLine = (id, content, y, align) => ({ kind: 'text', id, content, ...onBand,
  fontFamily: HEI, fontWeight: 500, fontSize: pt(18), lineHeight: 1.2, align,
  placement: at(HEAD, y, { size: { width: mm(LINE) } }) });
const cover = {
  id: 'cover', numbered: false, toc: false, runningChapter: false,
  span: 'page', // a page-wide design is not cut at the foot of the column: the field bleeds
  header: { elements: [] }, footer: { elements: [] },
  advancedDesign: { enabled: true, slot: { elements: [
    { kind: 'box', id: 'field', style: { backgroundColor: col('seal') },
      placement: { anchor: { to: 'bleed', edge: 'top-left' }, size: { height: mm(TRIM.w) } } },
    frame('rule-outer', 11, 1.6), frame('rule-inner', 13, 0.5), // 文武線: thick, then thin
    { kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: HEI,
      fontWeight: 700, fontSize: pt(56), lineHeight: 1.1, letterSpacing: pt(5.6), align: 'left',
      placement: at(HEAD, 26) },
    { kind: 'text', id: 'latin', content: '{attr.latin}', ...onBand, fontFamily: HEI,
      fontSize: pt(11), lineHeight: 1.4, align: 'left', placement: at(HEAD, 51) },
    coverLine('first', '臨時大總統宣言書', 104, 'left'),
    coverLine('first-date', '1912年1月1日', 104, 'right'),
    coverLine('second', '中華民國臨時約法', 118, 'left'),
    coverLine('second-date', '1912年3月11日', 118, 'right'),
  ] } },
};

A heading design in a column is cut at the foot of the column, and on a vertical page that foot is the left margin: a field anchored to the bleed stopped 21.6 mm short of the left trim edge. With span: 'page' the heading is laid out as a page band, which is not cut, and the field reaches both edges. The two frames draw the thick-and-thin double rule of Chinese printed books, 1.6 pt and 0.5 pt, 2 mm apart.

#5 · Load each voice with the text it sets

script.js · lines 317–322in full code
const voice = (styles) => (markdown.match(
  new RegExp(`:::paragraphs\\{style="(?:${styles})"\\}[\\s\\S]*?:::`, 'g')) ?? []).join('');
const kaiText = voice('headnote|note');
// Hei: headings and their attributes, seals, colophon, the cover's lines, folios 一 to 十.
const heiText = (markdown.match(/^#.*$/gm) ?? []).join('') + voice('seal|colophon')
  + '臨時大總統宣言書1912年1月1日中華民國臨時約法1912年3月11日一二三四五六七八九十';

Fontsource serves each weight of these faces as about a hundred files, each covering a range of characters, and loadCjkFonts loads the files that a text touches. Given only the headings, seal notices, colophon, cover lines and folios, each weight of Noto Sans TC loads 10 files; given the whole sample, it would load 35, and there are three weights. LXGW WenKai TC gets the headnotes and notes and loads 16. A face given too little text fails the capture (C12) and names the characters it had to borrow from a fallback face.

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 081 · Dates and acronyms upright in vertical text ═══════
// https://postext.dev/en/cookbook/chinese-dates-upright
// Code: MIT · Text: 1912 documents, zh.wikisource (CC BY-SA 4.0); notes (CC BY 4.0)
// Fonts: Noto Serif TC, Noto Sans TC, LXGW WenKai TC (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// Two founding documents of the Republic of China, 1912, set vertically as a reader.
import {
  buildDocument, withLoadedFonts, renderPageToCanvas, loadVerticalAlternates,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'chinese-dates-upright';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink, the vermilion of a seal, and the paper of a gazette
const palette = {
  ink: '#1e1a17', // text: a warm near-black
  seal: '#b1291f', // the one accent: the bands, the seal notes, the chapter heads
  tint: '#f6dccf', // the cover's double rule, a pale vermilion
  muted: '#6d645b', // fore-edge heads, the colophon
  paper: '#fffdf8',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
  { id: 'main-color', name: 'seal (defaults)', value: { hex: palette.seal, model: 'hex' } },
];
// #endregion

const SONG = 'Noto Serif TC'; // 宋/明: the documents
const HEI = 'Noto Sans TC'; // 黑: titles, heads, labels
const KAI = 'LXGW WenKai TC'; // 楷: the editor's headnotes and notes
const BODY = 12; // pt, 小四
const LEAD = 21; // pt: a line gap of 0.75 em
const CHARS = 44; // characters to a line
const LINE = (CHARS * BODY * 25.4) / 72; // mm: the length of a line, 186.3
const TRIM = { w: 184, h: 260 }; // mm, 16开
const MARGIN = { top: 30, bottom: 22, side: 20 }; // mm, minimums: 天头 deeper than 地脚

// #region answer: vertical text where numbers of one or two digits stand upright
const layout = { layoutType: 'single', writingMode: 'vertical-rl' }; // binding 'auto': right
const cjk = {
  // 10月10日: each number of up to two digits stands upright in one cell (tate-chu-yoko);
  // 1912 and Sun Yat-sen stay on their side, as clreq sets long numbers and Latin words.
  uprightDigits: 2,
  // The type area in characters: 44 down each line, 19 lines to the page.
  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: 19 },
};

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

#Stand numbers of three digits upright too

With 3, the 268 and 115 of the notes take their cell without markup, and so would any article or page number up to 999; 1912 stays on its side.

-  uprightDigits: 2,
+  uprightDigits: 3,

#Turn every number on its side

With 0 no number stands upright by itself: 10月10日 turns like 1912, and only the marked 268, 115 and ROC still stand.

-  uprightDigits: 2,
+  uprightDigits: 0,

Pitfalls

Pitfall

Chinese faces load by slices, through the cjk block

Fontsource serves a Chinese, Japanese or Korean family as about a hundred files per weight, each covering a range of characters. loadFonts fetches only the latin file, so on screen the Han characters come from a system face and measure wrong, and fontsourceProvider hands the PDF that latin file, which prints them as empty boxes. List the cjk kit block, call loadCjkFonts(FONTS, markdown) after loadFonts (once per voice, with the text it sets, when the book uses several CJK faces) and give renderToPdf fontProvider: cjkPdfProvider: both take the files that hold the text's characters. Chinese, Japanese and Korean fonts →

Pitfall

Tag the document zh-Hans or zh-Hant, not with LANG

A recipe's editions are en and es, but a Chinese sample is Chinese in both: `locale: LANG` would tag it English or Spanish, hyphenate its Latin words, label its figures Figure or Figura and give the PDF the wrong language. From postext 1.30 the tag is also the language the text is shaped in (measured, painted and embedded), so under an English or Spanish tag a Chinese face sets its digits and the punctuation it shares with Latin text in other forms, and the lines break elsewhere. Write the tag yourself: 'zh-Hans' (mainland conventions: GB line breaking, Kaiming punctuation) or 'zh-Hant' (Taiwan: full-width centred punctuation); 'zh-HK' for Hong Kong. A bare 'zh' reads as Simplified, mainland. A Japanese sample takes 'ja' (gotcha ja-locale-tag). Chinese line breaking →

Pitfall

A right-bound book shows its spreads with showBook

In a book bound on the right (Arabic, Hebrew or Persian text, vertical Chinese, or page.binding 'right') page 1 is still the recto, but it lies on the left of the spine, and the pairs read [3 | 2]. showPages lays every book out left-bound; showBook from the book block (the cjk block carries the same function) reads doc.binding and mirrors the pairs. capture.hero still names a spread in reading order, [verso, recto]: [2, 3]. Books bound on the right →

  • Noto Serif TC, as Fontsource serves it, has no 爲 or 敎: its stylesheet lists both, but no file holds a glyph for them. The 1912 printing of the constitution writes 為 and 教 in those forms. The canvas drew 敎 in a system face and the PDF had no glyph for it, which the capture reported (C25). The reader sets 為 and 教, brings 靑 and 决 to 青 and 決 with them, and its headnote says so.
  • LXGW WenKai TC, as Fontsource serves it, draws 即, 為, 青 and 教 in the older forms 卽, 爲, 靑 and 敎, which sit oddly beside the same characters in the Song text. The notes are worded without those four; only the headnote that lists the constitution's old forms wants them. Read the Kai text of your own notes at full size.
  • A number set sideways is spaced from the Chinese beside it like a Latin word, a quarter em on each side (cjk.latinSpacing), so the headnotes read 1912 年; a number in one cell takes no space, like a Chinese character.

Credits

Text
Fonts
Noto Serif TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1)
SandboxPDF