0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AsciiDocで書いてVivliostyleで組版する

Last updated at Posted at 2024-07-03

2025/02/12 追記

Vivliostyle CLIでVFM以外のunified Processorを使用できるように拡張されたため、現在ではそちらを利用したほうがシームレスに行えます。

過去の情報

ある程度詳細を指定してHTMLを出力できるマークアップ言語であれば何でもVivliostyleによるCSS組版フローに組み込めます。一例として、AsciiDocで書いてVivliostyleで組版する手順を紹介します。

AsciiDoctorではAsciiDocから直接PDFを出力することもできますが、HTMLを出力してVivliostyleを通せばさらに詳細な組版を行うこともできます。

> cmd /c ver
Microsoft Windows [Version 10.0.22631.3737]

> wsl tree .
.
├── Makefile
├── manuscript.adoc
├── manuscript.pdf
└── style.css

0 directories, 5 files

AsciiDocter、Vivliostyle CLIの他に、watchdogに付属するwatchmedoを使用しています。pipxでインストールしておくのがよいでしょう。

Makefile
MANUSCRIPT=manuscript
STYLESHEET=style.css

ifeq ($(OS),Windows_NT)
    ifeq ($(SHELL),/bin/sh)
        # MSYS2 make
        RM=rm -f
        BACKGROUND_PREVIEW=vivliostyle preview $(MANUSCRIPT).html &
	else
        # GnuWin32 make
        RM=del /Q
		# Press ctrl+c once (or twice), then y followed by enter to quit.
        BACKGROUND_PREVIEW=powershell -Command "Start-Process -FilePath vivliostyle.cmd -ArgumentList 'preview $(MANUSCRIPT).html' -NoNewWindow"
    endif
else
    RM=rm -f
    BACKGROUND_PREVIEW=vivliostyle preview $(MANUSCRIPT).html &
endif

.PHONY: all build-html build preview watch clean

all: build

$(MANUSCRIPT).html: $(MANUSCRIPT).adoc
	asciidoctor \
	    --verbose \
	    --attribute stylesheet=$(STYLESHEET) \
	    --attribute last-update-label! \
	    --attribute lang=ja \
	    $<

$(MANUSCRIPT).pdf: $(MANUSCRIPT).html
	vivliostyle build $< --output $@

build-html: $(MANUSCRIPT).html
build: $(MANUSCRIPT).pdf

preview: $(MANUSCRIPT).html
	$(BACKGROUND_PREVIEW)
	watchmedo shell-command \
	    --drop \
	    --patterns="*.adoc" \
	    --command="make build-html" \
	    .

clean:
	$(RM) $(MANUSCRIPT).html $(MANUSCRIPT).pdf

make previewを立ち上げておけば、おおもとのAsciiDocの変更に応じてVivliostyleのプレビューが更新されます。

GnuWin32 makeでのプレビューのバックグラウンド実行についてよい方法を知っていたら教えてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?