メインコンテンツまでスキップ

Quickstart

This builds a short vertical novel with a cover, ruby, emphasis dots and an illustration. It is the repository's examples/hello.php, which is run on every change.

<?php

require __DIR__ . '/vendor/autoload.php';

use MejiroEPUB\Document;
use MejiroEPUB\DocumentInfo;
use MejiroEPUB\Text\Notation;
use MejiroEPUB\Text\Paragraph;
use MejiroEPUB\Text\WritingMode;

$book = new Document(
new DocumentInfo(
title: '吾輩は猫である',
language: 'ja',
author: '夏目漱石',
// A stable identifier lets reading systems recognise a regenerated
// file as the same book. Derive it from your own record.
identifier: 'urn:uuid:5d7d2c1e-3f4a-4b6c-8d9e-0a1b2c3d4e5f',
),
writingMode: WritingMode::VERTICAL_RL, // pages then turn right to left
notation: Notation::novel(), // read ruby the way novel sites write it
);

// The cover first: the output is a stream, and the cover page opens the book.
$book->cover(__DIR__ . '/cover.jpg', alt: '表紙');

// An image is written when given, and placed by putting it in a body.
$illustration = $book->image(__DIR__ . '/illustration.png', alt: '挿絵');

$book->section('一', <<<'TEXT'
 |吾輩《わがはい》は猫である。名前はまだ無い。

 どこで生れたかとんと見当(けんとう)がつかぬ。何でも薄暗いじめじめした所で《《ニャーニャー》》泣いていた事だけは記憶している。
TEXT);

// A body may also be any iterable, and may mix strings with images and with
// paragraphs built from parts (which are never read as notation).
$book->section('二', [
' 吾輩はここで始めて人間というものを見た。',
$illustration,
Paragraph::of()->text(' それは')->tcy('12')->text('月のことで、')->ruby('書生', 'しょせい')->text('という人間であった。'),
]);

$book->save(__DIR__ . '/neko.epub');

What happened:

  • Every line became a paragraph, and the blank line in section 一 became a blank paragraph. The leading full-width space is the indent, kept as written.
  • |吾輩《わがはい》 and 見当(けんとう) became ruby; 《《ニャーニャー》》 became emphasis dots.
  • 12 in section 二 sits upright in one character cell (tate-chu-yoko). A body string would have done the same automatically for any two-digit number.
  • Each section is listed in the table of contents under its title.

Open neko.epub in any EPUB 3 reader. Reading systems lists what has been checked where.

Next​