本文へスキップ
レシピ番号109

レシピ集 · 第2章 · 文字と本文

ヨーロッパ数字で組むアラビア語のマグレブ版

モロッコ向けに印刷したアラビア語の章。ロケール'ar-MA'は本文を右から左・右綴じのまま保ち、生成する数字をすべて1、2、3で書きます。

このページの内容
出力
Canvas · PDF
レベル
初級
Postext
Postext 1.65.0で検証済み
1.65.0以上が必要 · postext-pdf ≥ 1.65.0
ライセンス
2026年10月31日更新
コードMIT · 本文CC BY 4.0
  • 英語の見本:日本語版はまだありません
  • 仕上がり135 × 210 mm
  • 1段
  • Noto Naskh Arabic 12.5/20.5
  • Noto Kufi Arabic
  • 4ページ
  • レベル
  • Postext 1.65.0
  • 組版時間106 ms
  • コード88行

かんたんな説明

モロッコ、アルジェリア、チュニジアのアラビア語の本は、数字を١، ٢، ٣ではなく、ヨーロッパと同じ1、2、3で印刷します。文書の言語と国を指定する設定ひとつで、本全体がその数字になります。

できあがり

モロッコの旧市街を案内する本の、フェズの門を扱った章です。モロッコの出版社が印刷するとおりに組みます。判型は13.5×21cm、本文はNoto Naskh Arabicの12.5pt、見出しはNoto Kufi Arabicで、フェズのタイル細工の緑を使います。本文は右から左へ流れ、ほかのアラビア語の本と同じく右綴じですが、ページ上の数字はすべて1、2、3で書かれます。ノンブル41から44、الفصل 3、節番号3-1と3-2、門のリストの1-から5-、注の合印(1)、図番号شكل 3-1です。これはモロッコからチュニジアまでのマグレブ地域の慣習で、このページはそれを設定ひとつで示します。右綴じのアラビア語の小説では、同じ本をマシュリクの١٢で組んでいます。

このレシピが答える質問

  • マグリブ向けの版で、アラビア語の本にヨーロッパ式の数字(1、2、3)を印字するには?

手短な答え

script.js · 40〜67行コード全体で見る
const config = () => ({
  // Written out, never LANG (gotcha: arabic-locale-tag). The Moroccan tag keeps the text right
  // to left and the binding on the right, and sets numerals: 'auto' to European digits: the
  // folios, the chapter and section numbers, the list, the notes and the figure number.
  locale: 'ar-MA',
  colorPalette,
  page: { width: mm(135), height: mm(210), dpi: 150, pageNumbering: { startAt: 41 },
    margins: { top: mm(22), bottom: mm(22), left: mm(19), right: mm(16), mirror: true } },
  layout: { layoutType: 'single' },
  bodyText: { fontFamily: TEXT, fontSize: pt(12.5), lineHeight: pt(20.5), color: col('ink'),
    boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
    textAlign: 'justify', firstLineIndent: em(1.5), indentAfterHeading: false },
  headings: { fontFamily: LABEL, fontWeight: 700, color: col('green'), levels: [
    // A chapter opens on an odd page, with no blank page forced before it.
    { level: 1, fontSize: pt(26), lineHeight: pt(41), numberingTemplate: 'الفصل {1}',
      numberSeparator: ': ', breakBefore: { enabled: true, parity: 'odd' },
      marginTop: pt(0), marginBottom: pt(10) },
    { level: 2, fontSize: pt(13), lineHeight: pt(20.5), numberingTemplate: '{1}-{2}',
      numberSeparator: '  ', marginTop: pt(20.5), marginBottom: pt(0) },
  ] },
  orderedLists, footnotes, captionStyle,
  paragraphStyles: [{ id: 'colophon', fontFamily: TEXT, fontSize: pt(8.5), lineHeight: pt(11),
    color: col('muted'), textAlign: 'left', firstLineIndent: pt(0), marginTop: pt(20.5) }],
  header: { elements: [] },
  footer: { elements: [{ kind: 'text', id: 'folio', content: '{pageNumber}', fontFamily: LABEL,
    fontSize: pt(9), color: col('muted'), align: 'center',
    placement: { anchor: { to: 'page', edge: 'bottom' }, offset: { y: mm(-12) } } }] },
});

材料

種類
Noto Naskh Arabic, Noto Kufi Arabic (SIL OFL 1.1)
素材
なし:画像はすべてコードで描画

作り方

#1 · 国が数字を決める

コードは前に掲げた手短な答えです。numeralsは'auto'のままにしておき、エンジンはタグから数字を読み取ります。ar-MA、ar-DZ、ar-TN、ar-LY、ar-MR、ar-EHはヨーロッパ数字、地域のないarとマシュリクの地域は١٢٣になります(数字と番号の書式)。変わるのはエンジンが書く数字だけです。ノンブル、見出しのカウンター、リストの番号、注の合印、図番号です。本文中の年号789と1913は著者が版の数字で入力したもので、エンジンが書き換えることはありません。見出しの{startAt=3}は3と同じく٣も読むので、同じMarkdownで両方の版に使えます。

#2 · 数字のまわりの記号

script.js · 29〜36行コード全体で見る
// «1-» and «(1)», as Arabic books write them; the number itself follows numerals.
const orderedLists = { color: col('green'), fontWeight: 700, marginTop: pt(0),
  marginBottom: pt(0), levels: [{ level: 1, numberFormat: 'arabic', separator: '-' }] };
const footnotes = { markerTemplate: '({n})', numbering: 'page', noteNumberPosition: 'inline',
  fontSize: pt(10), lineHeight: pt(15), separator: { width: 0.3, color: col('green') } };
// A colon after the label: a full stop after a number reads as a decimal point.
const captionStyle = { fontFamily: TEXT, fontSize: pt(10), color: col('ink'), labelBold: true,
  labelColor: col('green'), labelSeparator: ': ', note: { color: col('muted') } };

アラビア語の本では、リストの番号の後にハイフンを付けて1-と書き、注の合印を括弧で囲んで(1)と書きます。どちらのテンプレートも文書の数字を使うので、マシュリク版は同じ設定から١-と(١)を印刷します(脚注)。キャプションのラベルはشكل 3-1:とコロンで終えます。数字の後のピリオドは小数点に読めてしまうからです。注は多くのアラビア語の本と同じく、ページごとに(1)から振り直します。

#3 · コードで描いたタイルの帯

script.js · 120〜148行コード全体で見る
// The star is two squares turned 45°; between four stars a small square. Paths only.
const star = (cx, cy, r) => {
  const pts = [];
  for (let k = 0; k < 16; k++) {
    const a = (k * Math.PI) / 8;
    const d = k % 2 ? r * 0.7654 : r; // where the two squares' sides cross
    pts.push(`${(cx + d * Math.sin(a)).toFixed(2)} ${(cy - d * Math.cos(a)).toFixed(2)}`);
  }
  return `M${pts.join('L')}Z`;
};
function zellige(W, H, S) {
  let stars = '';
  let inner = '';
  let squares = '';
  for (let y = 0; y <= H + S; y += S) {
    for (let x = 0; x <= W + S; x += S) {
      stars += star(x, y, S * 0.47);
      inner += star(x, y, S * 0.2);
      squares += `M${x + S / 2} ${y + S / 2 - S * 0.17}l${S * 0.17} ${S * 0.17}`
        + `l${-S * 0.17} ${S * 0.17}l${-S * 0.17} ${-S * 0.17}Z`;
    }
  }
  return `<svg xmlns="http://www.w3.org/2000/svg" width="${W * 10}" height="${H * 10}" `
    + `viewBox="0 0 ${W} ${H}"><rect width="${W}" height="${H}" fill="${palette.green}"/>`
    + `<path d="${stars}" fill="${palette.cobalt}" stroke="${palette.paper}" stroke-width="0.5"/>`
    + `<path d="${inner}" fill="${palette.paper}"/>`
    + `<path d="${squares}" fill="${palette.ochre}" stroke="${palette.paper}" stroke-width="0.4"/>`
    + '</svg>';
}

図はCodePenのサンプルの中で生成したSVGです。2つの正方形を45°回して重ねた八芒星と、その間の小さな正方形を、パレットの緑、コバルト、黄土色で描きます。キャプションはどちらの版でもアラビア語で、アラビア語のリソースタイプが図に番号を振るのと同じく、章ごとに{h1}-{n}で番号を振ります。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 109 · A Maghreb edition of an Arabic text, with European digits ═══
// https://postext.dev/en/cookbook/maghreb-edition-european-digits
// Code: MIT · Text: original Arabic prose (CC BY 4.0) · Pattern: drawn in code
// Fonts: Noto Naskh Arabic, Noto Kufi Arabic (SIL OFL 1.1) · Needs postext ≥ 1.65.0
import {
  buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the frame; the chapter is Arabic in both editions
const RECIPE = 'maghreb-edition-european-digits';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// The green and cobalt of Fes tilework, on a white book paper.
const palette = {
  ink: '#1c1d1b', // text
  green: '#1d6650', // the accent: headings, the list numbers, the notes' rule
  cobalt: '#25488a', // the tile's second colour
  ochre: '#c99a3e', // the tile's third colour
  muted: '#62655f', // folios, captions' notes, the colophon
  paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.green })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [TEXT, LABEL] = ['Noto Naskh Arabic', 'Noto Kufi Arabic'];

// #region marks: list numbers, note markers and figure numbers in the same digits
// «1-» and «(1)», as Arabic books write them; the number itself follows numerals.
const orderedLists = { color: col('green'), fontWeight: 700, marginTop: pt(0),
  marginBottom: pt(0), levels: [{ level: 1, numberFormat: 'arabic', separator: '-' }] };
const footnotes = { markerTemplate: '({n})', numbering: 'page', noteNumberPosition: 'inline',
  fontSize: pt(10), lineHeight: pt(15), separator: { width: 0.3, color: col('green') } };
// A colon after the label: a full stop after a number reads as a decimal point.
const captionStyle = { fontFamily: TEXT, fontSize: pt(10), color: col('ink'), labelBold: true,
  labelColor: col('green'), labelSeparator: ': ', note: { color: col('muted') } };
// #endregion

// #region answer: ar-MA prints 1, 2, 3 in every number the engine writes
const config = () => ({
  // Written out, never LANG (gotcha: arabic-locale-tag). The Moroccan tag keeps the text right
  // to left and the binding on the right, and sets numerals: 'auto' to European digits: the
  // folios, the chapter and section numbers, the list, the notes and the figure number.
  locale: 'ar-MA',
  colorPalette,
  page: { width: mm(135), height: mm(210), dpi: 150, pageNumbering: { startAt: 41 },
    margins: { top: mm(22), bottom: mm(22), left: mm(19), right: mm(16), mirror: true } },
  layout: { layoutType: 'single' },

組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)

アレンジ

#マシュリクの数字で印刷する

同じ章のエジプト版やレバント版です。変わるのはタグで、Markdownは変わりません。

-  locale: 'ar-MA',
+  locale: 'ar-EG',

#モロッコのロケールのまま١٢٣で印刷する

明示した設定は地域の既定値に優先します。

   locale: 'ar-MA',
+  numerals: 'arab',

よくあるつまずき

つまずき

アラビア語の本のタグはLANGではなく'ar'にする

レシピの版はenとesですが、アラビア語のサンプルはどちらの版でもアラビア語です。`locale: LANG`では左から右に組まれ、左綴じになり、ページ番号は1 2 3となり、図のキャプションにはFigureやFiguraが付きます。postext 1.30以降、このタグはテキストを組む言語(計測、描画、埋め込みに使う言語)でもあるので、英語やスペイン語のタグでは、Markazi Textのようなフォントがギュメ(« »)や終止符をアラビア語の字形で描かず、改行の位置も変わります。タグは自分で書いてください。'ar'(アラビア・インド数字、マシュリク地域の慣習)、'ar-EG'や'ar-SA'のような地域付きのタグ、ヨーロッパ式数字を使うマグレブ版なら'ar-MA'、'ar-DZ'、'ar-TN'です。アラビア語を引用するだけのラテン文字のページは、自分のロケールのままにします。 右から左のテキスト →

つまずき

アラビア語の書体にはarabicブロックを通じてarabicファイルが必要

FontsourceはAmiri、Noto Naskh Arabic、Scheherazade Newをサブセットごとに1ファイルとして配信し、アラビア文字はarabicファイルに入っています。loadFontsが取得するのはlatin(とlatin-ext)だけなので、画面ではアラビア文字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、空の四角が印字されます。キットのarabicブロックを挙げ、loadFontsのあとにloadArabicFonts(FONTS, markdown)を呼び(ページでアラビア文字に使うすべてのウェイトをFONTSに挙げておきます)、renderToPdfにfontProvider: arabicPdfProviderを渡してください。 アラビア語のフォント →

つまずき

段落の頭の'1998. 'や'- 'はリストになる

数字、ピリオド、スペースで始まる段落や、ハイフンとスペースで始まる段落はリスト項目になります。数字の前にワードジョイナー(U+2060)を入れ、会話文はemダッシュで書いてください。 エスケープとそのままの文字 →

クレジット

レシピ
Ignacio Ferro
本文
  • “The gates of Fes”, a chapter written in Arabic for the recipe, from an invented book on the old cities of Morocco · Postext Cookbook · オリジナル
フォント
Noto Naskh Arabic (SIL OFL 1.1) · Noto Kufi Arabic (SIL OFL 1.1)
SandboxPDF