In short
The first entry of a 1909 diary that the poet Takuboku wrote in Japanese with Latin letters, with a reading in Japanese script under each paragraph.
What you'll build
Four pages of the Rōmaji nikki, the diary Ishikawa Takuboku kept in Tokyo in the spring of 1909 in Latin letters, so that his wife could not read it: the title lines of his notebook and the first entry, 7 April, to Kanasii koto da! The diary is set as a study edition on an A5 page: the rōmaji in Source Serif 4, justified and never hyphenated, and under each paragraph its reading in kana and kanji in Noto Serif JP, smaller, lighter and indented. Takuboku spells in the Nippon-shiki system, si, tu, hu, with circumflexes on long vowels, Tôkyô; the editor's lines use Hepburn with macrons, Rōmaji, and both reach the PDF.
This recipe answers
- How do I set Japanese written in rōmaji: which language tag, what hyphenation, and macrons in the PDF?
- Which fonts set Japanese, with kanji in their Japanese forms, on screen and in the PDF?
The short answer
// ja-Latn is Japanese written in Latin script (BCP 47). Its language is ja, so the kana
// under each paragraph get the Japanese rules (kinsoku, 、。 spacing, the space after !)
// and the built-in strings are Japanese; and Japanese has no hyphenation patterns, so the
// rōmaji is never divided at a line end. English patterns would divide tatinobotta or
// Surigarasu by English syllables, not by the morae a Japanese reader hears.
const language = { locale: 'ja-Latn' }; // spread into the config
const bodyText = {
fontFamily: SERIF, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
textAlign: 'justify', firstLineIndent: em(1.2), indentAfterHeading: false,
optimalLineBreaking: true, maxWordSpacing: 1.8, // no hyphens: the spaces take the slack
};
// The reading in kana, under its paragraph: smaller, a shade lighter, indented.
const kana = { id: 'kana', fontFamily: MINCHO, fontSize: pt(8.6), lineHeight: pt(LEAD),
color: col('kana'), textAlign: 'justify', indent: em(1.5), firstLineIndent: em(1),
marginTop: pt(LEAD / 4), marginBottom: pt(LEAD * 0.75) };
A Japanese text in Latin letters is tagged ja-Latn
Ingredients
- Features
- Kana, kanji and rōmajiHyphenation and document languageChinese, Japanese and Korean fontsJapanese punctuation spacing (yakumono)Japanese line breaking (kinsoku)Body typeDesigned openersHeading stylesHeading attributesParagraph stylesRunning heads and foliosHeads by page roleMirrored marginsPaper colourSemantic colour palettePDF exportFonts embedded in the PDF
- Type
- Source Serif 4, Source Sans 3, Noto Serif JP (SIL OFL 1.1)
- Assets
- None: every picture is drawn in code
Method
#1 · Tag the text ja-Latn
The code is the short answer above. ja-Latn is BCP 47 for Japanese written in Latin script. Its language is ja, so the reading under each paragraph gets the Japanese rules: kinsoku, 、。 spacing, and the em space the engine adds after ! inside a sentence, as in 「ええ! ええ!」. Japanese has no hyphenation patterns, so the rōmaji is never divided; with en, English patterns would divide words such as tatinobotta or Surigarasu by English syllables, not by the morae a Japanese reader hears. Without hyphens the spaces take the slack, so the measure is about 70 characters and maxWordSpacing is 1.8 (hyphenation).

#2 · Put the macrons in the PDF
// Fontsource keeps ō ū ā in a latin-ext file. cjkPdfProvider serves Noto Serif JP from its
// slices, and adds that file after the latin one for a Latin face whose text needs it.
offerPdf(() => renderToPdf(doc, { fontProvider: cjkPdfProvider }), `${RECIPE}.pdf`);
Fontsource keeps ō ū ā in a latin-ext file of their own. The screen loads it (loadFonts sees the ō in the sample), and the kit's cjkPdfProvider does the same for the PDF. It serves Noto Serif JP from its Japanese slices, and when a Latin face sets a letter that only latin-ext holds, it answers with two files, latin and then latin-ext; postext-pdf takes each glyph from the first file that has it. The kit's plain fontsourceProvider hands the PDF the latin file only: with it, the PDF would have no glyph for ō.
#3 · Open on the diary's own lines
const onField = { color: col('paper'), align: 'center', overflow: 'wrap' };
const title = {
id: 'title', numbered: false, toc: false, span: 'page', runningChapter: false,
breakBefore: { enabled: true, parity: 'any' }, // its page is an opener: no running heads
advancedDesign: { enabled: true, minHeight: mm(166), slot: { elements: [
{ kind: 'box', id: 'field', style: { backgroundColor: col('indigo') },
placement: { anchor: { to: 'bleed', edge: 'top-left' }, size: { width: 'fill',
height: 'fill' } } },
{ kind: 'text', id: 'lines', content: '{attr.lines}', ...onField, fontFamily: SERIF,
fontWeight: 600, fontSize: pt(20), lineHeight: 1.9, letterSpacing: pt(5),
placement: { anchor: { to: 'container', edge: 'top' }, offset: { y: mm(18) } } },
{ kind: 'rule', id: 'rule', thickness: pt(0.5), color: col('paper'),
placement: { anchor: { to: 'container', edge: 'top' }, offset: { y: mm(122) },
size: { width: mm(24) } } },
{ kind: 'text', id: 'note', content: '{attr.note}', inlineMarks: true, ...onField,
fontFamily: SANS, fontSize: pt(8.5), lineHeight: 1.5, placement: { anchor: { to:
'container', edge: 'top' }, offset: { y: mm(130) }, size: { width: mm(84) } } },
] } },
};
// The entry: its day as a heading, the address under it from an attribute.
const entry = {
level: 2, fontFamily: SANS, fontWeight: 600, fontSize: pt(10), letterSpacing: pt(2.5),
color: col('indigo'), marginTop: pt(LEAD), marginBottom: pt(LEAD), advancedDesign: {
enabled: true, minHeight: pt(2 * LEAD), slot: { elements: [
{ kind: 'text', id: 'day', content: '{titleText}', fontFamily: SANS, fontWeight: 600,
fontSize: pt(10), letterSpacing: pt(2.5), color: col('indigo'),
placement: { anchor: { to: 'container', edge: 'top-left' } } },
{ kind: 'text', id: 'place', content: '{attr.place}', fontFamily: SANS, fontSize: pt(7.5),
letterSpacing: pt(1), color: col('muted'), overflow: 'wrap', align: 'left',
placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: pt(LEAD) },
size: { width: 'fill' } } },
] } },
};
The notebook starts NIKKI. I. MEIDI 42 NEN. 1909. APRIL. TOKYO., one item to a line. The title heading takes them from an attribute, each \n a new line, and sets them in tracked capitals on an indigo field, the cloth of a notebook cover. Its page is an opener, so the running heads skip it.
#4 · Run heads by parity
const head = (id, content, parity, edge) => ({ kind: 'text', id, content, parity,
pages: 'body', fontFamily: SANS, fontSize: pt(7.5), letterSpacing: pt(1.5), color: col('muted'),
placement: { anchor: { to: 'page', edge }, offset: { y: mm(13), // 'top' centres on the page
x: mm(edge.endsWith('left') ? 16 : edge.endsWith('right') ? -16 : 0) } } });
const header = { elements: [
head('folio-even', '{pageNumber}', 'even', 'top-left'),
head('book', 'ROMAZI NIKKI · 1909', 'even', 'top'),
head('place', 'TOKYO · APRIL', 'odd', 'top'),
head('folio-odd', '{pageNumber}', 'odd', 'top-right'),
] };
The verso carries the diary's name and the recto the place and month, with the folios on the outer corners, in Source Sans 3 at 7.5 pt.
The whole recipe
// ═══ Postext Cookbook · Nº 130 · Japanese in Latin letters: Takuboku's Rōmaji Diary ════
// https://postext.dev/en/cookbook/romaji-nikki
// Code: MIT · Text: Ishikawa Takuboku, 1909 (public domain); transcription (CC BY 4.0)
// Fonts: Source Serif 4, Source Sans 3, Noto Serif JP (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// A diary written in Japanese with Latin letters, and its reading in kana under each paragraph.
import { buildDocument, withLoadedFonts, renderPageToCanvas } from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the note; the diary is Japanese in both editions
const RECIPE = 'romaji-nikki';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: diary ink, a faded indigo, the cream of a notebook
const palette = {
ink: '#22201d', // the rōmaji
indigo: '#34497a', // the date and the title (8.4:1 on the paper)
kana: '#5a554e', // the transcription, a step lighter than the text (7:1)
rule: '#c9c1b2',
muted: '#6f6a62', // running heads, folios, the note
paper: '#fcfaf4',
};
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: 'indigo (defaults)', value: { hex: palette.indigo, model: 'hex' } },
];
// #endregion
const SERIF = 'Source Serif 4'; // the rōmaji: ô û â ê in latin, ō ū in latin-ext
const SANS = 'Source Sans 3'; // labels, running heads, folios, the note
const MINCHO = 'Noto Serif JP'; // the kana: Noto Serif JP's Latin is Source Serif's
const [BODY, LEAD] = [10.5, 15]; // pt
// #region answer: a Japanese text in Latin letters is tagged ja-Latn
// ja-Latn is Japanese written in Latin script (BCP 47). Its language is ja, so the kana
// under each paragraph get the Japanese rules (kinsoku, 、。 spacing, the space after !)
// and the built-in strings are Japanese; and Japanese has no hyphenation patterns, so the
// rōmaji is never divided at a line end. English patterns would divide tatinobotta or
// Surigarasu by English syllables, not by the morae a Japanese reader hears.
const language = { locale: 'ja-Latn' }; // spread into the config
const bodyText = {
fontFamily: SERIF, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
textAlign: 'justify', firstLineIndent: em(1.2), indentAfterHeading: false,
optimalLineBreaking: true, maxWordSpacing: 1.8, // no hyphens: the spaces take the slack
};
// The reading in kana, under its paragraph: smaller, a shade lighter, indented.
const kana = { id: 'kana', fontFamily: MINCHO, fontSize: pt(8.6), lineHeight: pt(LEAD),
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
#Write the rōmaji in Hepburn
A modern edition may respell the diary in Hepburn with macrons, Tōkyō for Tôkyô. The PDF already carries ō, so only the text changes; keep a note that says the spelling is the editor's.
#Hyphenate between morae
If a narrow column needs hyphens, give the rōmaji soft hyphens (U+00AD) between morae, Su\u00adna-ho\u00adko\u00adri in code or a typed U+00AD in the text: a document tagged ja-Latn never hyphenates by itself, but it breaks at a soft hyphen when a word does not fit.
Pitfalls
Pitfall
Tag a Japanese text 'ja', never zh-Hans or LANG
A recipe's editions are en and es, but a Japanese sample is Japanese in both: `locale: LANG` would tag it English or Spanish, and a Chinese tag would set it by the Chinese rules (Kaiming punctuation, small kana free to start a line, 图 for 図, Chinese glyph forms in the PDF). From postext 1.30 the tag is also the language the text is shaped in (measured, painted and embedded), so any tag but 'ja' gives other glyph forms than the Japanese ones (the Chinese ones under a Chinese tag) and other line breaks. Write 'ja': it picks the Japan region (JLReq line breaking and punctuation, sesame emphasis marks, furigana spacing, 図 and 表 labels) and turns hyphenation off. The lint fails a text with kana under a zh or ko tag. Japanese line breaking (kinsoku) →
Pitfall
Set Japanese in a Japanese face
Noto Serif SC and TC have kana, but they draw the kanji in Chinese forms (直, 骨 and 角 differ) and the kana in a Chinese design. Set the text in Noto Serif JP or Shippori Mincho B1 and the heads in Noto Sans JP, loaded with loadCjkFonts. Fontsource's Japanese files hold no hentaigana or other historic kana (U+1B000–1B16F): loadCjkFonts fails on them and the PDF prints boxes, so write the modern kana or ship a face that has them in the recipe's assets. Shippori Mincho also lacks the macron vowels ō and ū: set rōmaji in a Latin face. Kana, kanji and rōmaji →
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 →
- Shippori Mincho has no ō or ū; Noto Serif JP and Source Serif 4 have them in their
latin-extfiles. Check the face before you choose it for Hepburn text. - Chinese written in Latin letters is pinyin, set as ruby over the characters in A first reader with pinyin over every character; Takuboku's rōmaji is the text itself, so it is set as Latin text with its own spacing, not as annotation.
Credits
- Recipe
- Ignacio Ferro
- Text
- Ishikawa Takuboku, ROMAZI NIKKI (the Rōmaji Diary), the entry of 7 April 1909 to “Kanasii koto da!”, in Latin letters as he wrote it, after the Iwanami Bunko edition (ed. Kuwabara Takeo, 1977) as transcribed on the blog 啄木の息 · Ishikawa Takuboku (1886–1912) · public domain
- The transcription into kana and kanji under each paragraph and the note on the text, written for this recipe · Postext Cookbook · CC BY 4.0
- Fonts
- Source Serif 4 (SIL OFL 1.1) · Source Sans 3 (SIL OFL 1.1) · Noto Serif JP (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


