mochikoAsTechのdig日記

当方好きなコマンドはdigです!お友達から!!よろしくお願いします!!!

Dockerを使ってRe:VIEWで本が書きたい!~ステップ3:vvakameさんのDockerイメージで環境構築~

これは何をやりたい人向けのエントリ?

前提

  • 既にDockerが動く環境があること
  • TechBoosterのテンプレートを使った原稿リポジトリがあること

「ステップ3:vvakameさんのDockerイメージで環境構築」の手順

1. Re:VIEWのバージョンを確認しよう

Re:VIEWのGitリポジトリで最新バージョンを確認しよう

ReVIEW-Templateの対象バージョンを確認

一式セットアップ済みのdockerイメージを用意してあるので使ってください。 Dockerがうまく動くようになっている場合、以下のコマンドで細かい準備なしにビルドを行うことができます。
$ docker pull vvakame/review:3.1
  • TechBoosterのひつじさん曰く「動作確認は3.1でしたけど、たぶん3.2でも動く」ということなので 3.2 でも大丈夫そう

config.ymlでバージョンを確認

  • ステップ2で作った原稿リポジトリで、articles フォルダの下にある config.yml を開く
    • 私の場合は C:\Users\mochikoAsTech\Documents\startDNS\articles\config.yml
  • config.yml に書いてある review_version を確認する
    • review_version: 3.0 とあるので「これはRe:VIEW3系に対応した設定ファイルなんだな」と分かる
# この設定ファイルでサポートするRe:VIEWのバージョン番号。
# major versionが違うときにはエラーを出す。
review_version: 3.0

どのバージョンのRe:VIEWを使うか決める

  • ここまで確認したことから、本エントリではRe:VIEW3.2 を使うこととする!

2. vvakameさんのDockerイメージを連れてこよう

Dockerイメージを連れてくる

>docker images vvakame/review
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
>docker pull vvakame/review:3.2
3.2: Pulling from vvakame/review
f5d23c7fed46: Pull complete
021db6e5dcda: Pull complete
771bbc40d6be: Pull complete
1738d9462c97: Pull complete
9c09143aac1c: Pull complete
97ee0730c016: Pull complete
1086092c9acc: Pull complete
a40dfd0b3ecf: Pull complete
8f9d5bd5651d: Pull complete
48e10854c260: Pull complete
7a338c0510db: Pull complete
752184f974ea: Pull complete
Digest: sha256:296a3eb7427d70f1dc581fa6566c1d2a3d45dbc8e0935b6672155b2049769bcf
Status: Downloaded newer image for vvakame/review:3.2
  • 再び docker images vvakame/review を叩く
    • Dockerイメージがいる!
>docker images vvakame/review
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
vvakame/review      3.2                 3168b41bd37d        2 weeks ago         2.04GB

3. Dockerコンテナを使ってPDFを吐き出す

docker-compose.ymlを用意する

  • ステップ2で作った原稿リポジトリで、articles フォルダの下に docker-compose.yml を作る
    • 私の場合は C:\Users\mochikoAsTech\Documents\startDNS\articles\docker-compose.yml
  • 中身はこんな感じ
    • startDNS のところは自分の原稿リポジトリ名に書き換えてね
version: '3'
services:
  review:
    image: vvakame/review:3.2
    volumes:
      - .:/startDNS
    build: .
    working_dir: /startDNS

コマンドを叩いてPDFを吐き出す

  • コマンドプロンプトcd C:\Users\%USERPROFILE%\Documents\原稿リポジトリ名\articles を叩いて、原稿リポジトリarticles フォルダの下に移動する
    • 私だったらこんな感じ
>cd C:\Users\mochikoAsTech\Documents\startDNS\articles
>docker-compose run --rm review rake pdf
review-pdfmaker config.yml
INFO: compiling preface.tex
INFO: compiling article.tex
INFO: compiling contributors.tex
INFO: uplatex -interaction=nonstopmode -file-line-error __REVIEW_BOOK__.tex
INFO: uplatex -interaction=nonstopmode -file-line-error __REVIEW_BOOK__.tex
INFO: uplatex -interaction=nonstopmode -file-line-error __REVIEW_BOOK__.tex
INFO: dvipdfmx -d 5 -z 9 __REVIEW_BOOK__.dvi
  • articles フォルダの下に ReVIEW-Template.pdf が生まれる f:id:mochikoAsTech:20190808135602p:plain

4. 自分の本に合わせて色々カスタマイズする

印刷用PDFか電子書籍用PDFか?B5かA5か?を設定する

  • いま、トンボ付きのPDFが出力されているのは、デフォルトが「B5で印刷用のPDFを出力する」という設定になっているからです
  • 原稿リポジトリarticles フォルダの下にある config.yml を見てみましょう
# B5の設定(10pt 40文字×35行) - 紙版
texdocumentclass: ["review-jsbook", "media=print,paper=b5,serial_pagination=true,hiddenfolio=nikko-pc,openany,fontsize=10pt,baselineskip=15.4pt,line_length=40zw,number_of_lines=35,head_space=30mm,headsep=10mm,headheight=5mm,footskip=10mm"]
# B5の設定(10pt 40文字×35行) - 電子版
# texdocumentclass: ["review-jsbook", "media=ebook,paper=b5,serial_pagination=true,openany,fontsize=10pt,baselineskip=15.4pt,line_length=40zw,number_of_lines=35,head_space=30mm,headsep=10mm,headheight=5mm,footskip=10mm"]
# A5の設定(9pt 38文字×37行) - 紙版
# texdocumentclass: ["review-jsbook", "media=print,paper=a5,serial_pagination=true,hiddenfolio=nikko-pc,openany,fontsize=9pt,baselineskip=13pt,line_length=38zw,number_of_lines=37,head_space=15mm,headsep=3mm,headheight=5mm,footskip=10mm"]
# A5の設定(9pt 38文字×37行) - 電子版
# texdocumentclass: ["review-jsbook", "media=ebook,paper=a5,serial_pagination=true,openany,fontsize=9pt,baselineskip=13pt,line_length=38zw,number_of_lines=37,head_space=15mm,headsep=3mm,headheight=5mm,footskip=10mm"]
  • たとえば次のようにコメントアウトの場所を変更して「B5で電子用のPDFを出力する」という設定にした上で、再度コマンドプロンプトdocker-compose run --rm review rake pdf を叩いてみましょう
# B5の設定(10pt 40文字×35行) - 紙版
# texdocumentclass: ["review-jsbook", "media=print,paper=b5,serial_pagination=true,hiddenfolio=nikko-pc,openany,fontsize=10pt,baselineskip=15.4pt,line_length=40zw,number_of_lines=35,head_space=30mm,headsep=10mm,headheight=5mm,footskip=10mm"]
# B5の設定(10pt 40文字×35行) - 電子版
texdocumentclass: ["review-jsbook", "media=ebook,paper=b5,serial_pagination=true,openany,fontsize=10pt,baselineskip=15.4pt,line_length=40zw,number_of_lines=35,head_space=30mm,headsep=10mm,headheight=5mm,footskip=10mm"]
# A5の設定(9pt 38文字×37行) - 紙版
# texdocumentclass: ["review-jsbook", "media=print,paper=a5,serial_pagination=true,hiddenfolio=nikko-pc,openany,fontsize=9pt,baselineskip=13pt,line_length=38zw,number_of_lines=37,head_space=15mm,headsep=3mm,headheight=5mm,footskip=10mm"]
# A5の設定(9pt 38文字×37行) - 電子版
# texdocumentclass: ["review-jsbook", "media=ebook,paper=a5,serial_pagination=true,openany,fontsize=9pt,baselineskip=13pt,line_length=38zw,number_of_lines=37,head_space=15mm,headsep=3mm,headheight=5mm,footskip=10mm"]
  • トンボが消えて、電子書籍用のPDFが出力されました!
  • もし docker-compose run --rm review rake pdf を叩いたときにこんなエラーが出たら、PDFを開いたまま出力しようとしているのが原因です!一度PDFを閉じてからやりなおしましょう
>docker-compose run --rm review rake pdf
review-pdfmaker config.yml
INFO: compiling preface.tex
INFO: compiling article.tex
INFO: compiling contributors.tex
INFO: uplatex -interaction=nonstopmode -file-line-error __REVIEW_BOOK__.tex
INFO: uplatex -interaction=nonstopmode -file-line-error __REVIEW_BOOK__.tex
INFO: uplatex -interaction=nonstopmode -file-line-error __REVIEW_BOOK__.tex
INFO: dvipdfmx -d 5 -z 9 __REVIEW_BOOK__.dvi
Traceback (most recent call last):
        16: from /usr/local/bin/review-pdfmaker:23:in `<main>'
        15: from /usr/local/bin/review-pdfmaker:23:in `load'
        14: from /var/lib/gems/2.5.0/gems/review-3.2.0/bin/review-pdfmaker:16:in `<top (required)>'
        13: from /var/lib/gems/2.5.0/gems/review-3.2.0/lib/review/pdfmaker.rb:97:in `execute'
        12: from /var/lib/gems/2.5.0/gems/review-3.2.0/lib/review/pdfmaker.rb:156:in `execute'
        11: from /var/lib/gems/2.5.0/gems/review-3.2.0/lib/review/pdfmaker.rb:282:in `generate_pdf'
        10: from /usr/lib/ruby/2.5.0/fileutils.rb:358:in `cp'
         9: from /usr/lib/ruby/2.5.0/fileutils.rb:1461:in `fu_each_src_dest'
         8: from /usr/lib/ruby/2.5.0/fileutils.rb:1479:in `fu_each_src_dest0'
         7: from /usr/lib/ruby/2.5.0/fileutils.rb:1463:in `block in fu_each_src_dest'
         6: from /usr/lib/ruby/2.5.0/fileutils.rb:359:in `block in cp'
         5: from /usr/lib/ruby/2.5.0/fileutils.rb:432:in `copy_file'
         4: from /usr/lib/ruby/2.5.0/fileutils.rb:1291:in `copy_file'
         3: from /usr/lib/ruby/2.5.0/fileutils.rb:1291:in `open'
         2: from /usr/lib/ruby/2.5.0/fileutils.rb:1292:in `block in copy_file'
         1: from /usr/lib/ruby/2.5.0/fileutils.rb:1292:in `open'
/usr/lib/ruby/2.5.0/fileutils.rb:1292:in `initialize': Device or resource busy @ rb_sysopen - /startDNS/ReVIEW-Template.pdf (Errno::EBUSY)
rake aborted!
Command failed with status (1): [review-pdfmaker config.yml...]
lib/tasks/review.rake:96:in `block in <top (required)>'
/var/lib/gems/2.5.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
Tasks: TOP => pdf => book.pdf
(See full trace by running task with --trace)

色々カスタマイズする

  • PDFをどんなファイル名で出力するか、書名や著者名は何にするか、などはすべて articles フォルダの下にある config.yml で設定します
    • 書いてあるコメントを見ながら直す→PDFを出力して確認、をくり返せば設定項目は分かると思うので詳細は解説しません f:id:mochikoAsTech:20190808232811p:plain

原稿を書いてみる

  • articles フォルダの下にある preface.re で前書きを書き足してみましょう
  • 「ねこはかわいい!」と書いてみました f:id:mochikoAsTech:20190808233127p:plain
  • コマンドプロンプトdocker-compose run --rm review rake pdf を叩いてみると、ちゃんと反映されています f:id:mochikoAsTech:20190808233237p:plain
  • なぜ preface.re に書くと反映されるのか?というと、catalog.yml というカタログファイルでそう設定されているからです

さいごに

  • 技術書典のたびに「リポジトリ!環境構築!どうやるんだっけ?!」と困っていた頭弱い自分のために書きました
    • そんなにおられないと思いますが、私と同じように環境構築でつまづいていた誰かのお役に立てば幸いです。素敵な新刊を書いてください!私はまだ見ぬあなたの新刊を楽しみにしています!

参考文献・ウェブサイト