Trema本を読もう!

はじめに

Interop2012 Open Router Competition (ORC)まとめサイト経由で資料をいくつか見ていたらこんなスライドを発見。

……これは読んでみなければなるまい、と。

yasuhito/trema-book ・ GitHub にもビルドの方法とか書いてあるのですが、TeX の用意 (texlive および ptexlive) のところだけちょっと変えてます。その他は同じ。

2012/10月中旬発売と言うことなのでそれまでの時限ネタですが、とりあえず読んでみたいという人向けにメモっておきます。

環境セットアップ

使っているのは Ubuntu/12.04 (x86_64) です。Trema のビルドを行っているテスト用のPC(VM)なので Ruby やらはすでに入っている状態です。

Ruby & rake
stereocat@pc02:~$ which ruby
/usr/bin/ruby
stereocat@pc02:~$ which rake
stereocat@pc02:~$ aptitude search rake
p   rake                            - ruby make-like utility
stereocat@pc02:~$

ruby はすでにインストール済み。rake が入っていないので入れます。

stereocat@pc02:~$ sudo aptitude install rake
review のダウンロードとインストール
stereocat@pc02:~$ git clone https://github.com/kmuto/review.git
Cloning into 'review'...
(略)

stereocat@pc02:~$ cd review
stereocat@pc02:~/review$ ls
COPYING    README.rdoc  VERSION  debian  lib             test
ChangeLog  Rakefile     bin      doc     review.gemspec
stereocat@pc02:~/review$

rake のターゲット出してみると…

stereocat@pc02:~/review$ rake -T
Jeweler (or a dependency) not available. Install it with: gem install jeweler
WARNING: 'require 'rake/rdoctask'' is deprecated.  Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
    at /usr/lib/ruby/vendor_ruby/rake/rdoctask.rb
rake clean         # Remove any temporary products.
rake clobber       # Remove any generated file.
rake clobber_rdoc  # Remove rdoc products
rake rdoc          # Build the rdoc HTML Files
rake rerdoc        # Force a rebuild of the RDOC files
rake test          # Run tests for test
stereocat@pc02:~/review$

Jeweler がないと言われているので入れます。

stereocat@pc02:~/review$ gem search -r jeweler

*** REMOTE GEMS ***

jeweler (1.8.3)
jeweler2 (2.0.9)
jeweler_style_versioning (1.0.0)
zomgjeweler (0.0.0)
stereocat@pc02:~/review$ sudo gem install jeweler
(略)

ビルドしてインストール。

stereocat@pc02:~/review$ rake build
  Successfully built RubyGem
  Name: review
  Version: 1.0.0
  File: review-1.0.0.gem
stereocat@pc02:~/review$ sudo rake install
  Successfully built RubyGem
  Name: review
  Version: 1.0.0
  File: review-1.0.0.gem
Executing "ruby1.8 -S gem install ./pkg/review-1.0.0.gem":
ruby1.8 -S gem install ./pkg/review-1.0.0.gem
Successfully installed review-1.0.0
1 gem installed
Installing ri documentation for review-1.0.0...
Installing RDoc documentation for review-1.0.0...
stereocat@pc02:~/review$
TeX 環境のセットアップ

[LaTeX]Debian squeezeにUTF-8なLaTeX環境を構築する | Tsutomu Onoda's Blog を参考にインストールしていきます。

ダウンロード(2.3GBとかあります)

stereocat@pc02:~$ wget -c http://ftp.jaist.ac.jp/pub/CTAN/systems/texlive/Images/texlive2011.iso

ダウンロードした iso image をマウントして作業開始。

stereocat@pc02:~$ sudo mount -t iso9660 texlive2011.iso /mnt/
[sudo] password for stereocat:
mount: warning: /mnt/ seems to be mounted read-only.stereocat@pc02:~$ cd /mnt/
stereocat@pc02:/mnt$ ls
LICENSE.CTAN       index.html               release-texlive.txt
LICENSE.TL         install-tl               source
README             install-tl-advanced.bat  texlive-doc
README.usergroups  install-tl.bat           tl-tray-menu.exe
archive            readme-html.dir          tlpkg
autorun.inf        readme-txt.dir
stereocat@pc02:/mnt$

インストールしていきます。

stereocat@pc02:/mnt$ sudo perl install-tl
Installing TeX Live 2011 from: /mnt
Platform: x86_64-linux => 'x86_64 with GNU/Linux'
Distribution: inst (compressed)
Directory for temporary files: /tmp
Loading /mnt/tlpkg/texlive.tlpdb

======================> TeX Live installation procedure <=====================

=======> Note: Letters/digits in <angle brackets> indicate menu items <=======
=======>       for commands or configurable options                   <=======

Detected platform: x86_64 with GNU/Linux

<B> platforms: 1 out of 19

<S> installation scheme (scheme-full)
     84 collections out of 85, disk space required: 2608 MB

Customizing installation scheme:
   <C> standard collections
   <L> language collections

<D> directories:
   TEXDIR (the main TeX directory):
     /usr/local/texlive/2011
   TEXMFLOCAL (directory for site-wide local files):
     /usr/local/texlive/texmf-local
   TEXMFSYSVAR (directory for variable and automatically generated data):
     /usr/local/texlive/2011/texmf-var
   TEXMFSYSCONFIG (directory for local config):
     /usr/local/texlive/2011/texmf-config
   TEXMFVAR (personal directory for variable and automatically generated data):
     ~/.texlive2011/texmf-var
   TEXMFCONFIG (personal directory for local config):
     ~/.texlive2011/texmf-config
   TEXMFHOME (directory for user-specific files):
     ~/texmf

<O> options:
   [ ] use letter size instead of A4 by default
   [X] allow execution of restricted list of programs via \write18
   [X] create all format files
   [X] install macro/font doc tree
   [X] install macro/font source tree

<V> set up for portable installation

Actions:
<I> start installation to hard disk
<H> help
<Q> quit

Enter command:

"I" でインストール開始。

(略)
done
pre-generating all format files (fmtutil-sys --all), be patient...done
running package specific postactions
finished with package specific postactions

See
   /usr/local/texlive/2011/index.html
for links to documentation.  The TeX Live web site
contains updates and corrections: http://tug.org/texlive.

TeX Live is a joint project of the TeX user groups around the world;
please consider supporting it by joining the group best for you. The
list of groups is available on the web at http://tug.org/usergroups.html.

Add /usr/local/texlive/2011/texmf/doc/man to MANPATH, if not dynamically determined.
Add /usr/local/texlive/2011/texmf/doc/info to INFOPATH.

Most importantly, add /usr/local/texlive/2011/bin/x86_64-linux
to your PATH for current and future sessions.

Welcome to TeX Live!
Logfile: /usr/local/texlive/2011/install-tl.log
stereocat@pc02:/mnt$

PATH, MANPATH, INFOPATH が最後に表示されるので、.bashrc とかに設定しておきます。

あと、sudo して作業するときのパスも設定しておきます。

stereocat@pc02:~$ sudo cat /etc/sudoers
(略)

Defaults        env_reset
Defaults        secure_path="/usr/local/texlive/2011/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
(略)
stereocat@pc02:~$ sudo which tlmgr
/usr/local/texlive/2011/bin/x86_64-linux/tlmgr
stereocat@pc02:~$

アップデートのためリポジトリを登録。

stereocat@pc02:~$ sudo tlmgr option repository http://mirror.ctan.org/systems/texlive/tlnet
tlmgr: setting default package repository to http://mirror.ctan.org/systems/texlive/tlnet
stereocat@pc02:~$

アップデート開始。

stereocat@pc02:~$ sudo tlmgr update -self -all
tlmgr: package repository http://ftp.yz.yamagata-u.ac.jp/pub/CTAN/systems/texlive/tlnet
TeX Live 2011 is frozen forever and will no
longer be updated.  This happens in preparation for a new release.

(略)

tlptexlive リポジトリからアップデート実行。

stereocat@pc02:~$ sudo tlmgr -repository http://www.tug.org/~preining/tlptexlive/ update -all
tlmgr: package repository http://www.tug.org/~preining/tlptexlive/
tlmgr: saving backups to /usr/local/texlive/2011/tlpkg/backups
[1/2, ??:??/??:??] update: dvipdfmx.x86_64-linux [317k] (22971 -> 26010) ... done
[2/2, 00:05/00:13] update: ptex.x86_64-linux [532k] (22971 -> 25500) ... done
(略)
stereocat@pc02:~$

pxdvi, pmetapost, uptex のインストール

stereocat@pc02:~$ sudo tlmgr -repository http://www.tug.org/~preining/tlptexlive/ install pmetapost pxdvi uptex
tlmgr: package repository http://www.tug.org/~preining/tlptexlive/
package adobemapping not present in package repository.
package hyph-utf8 not present in package repository.
package ipaex not present in package repository.
package japanese not present in package repository.
package japanese-otf not present in package repository.
package ptex not present in package repository.
(略)
stereocat@pc02:~$
Trema Book のダウンロードとビルド

github からダウンロード

stereocat@pc02:~$ git clone https://github.com/yasuhito/trema-book.git
Cloning into 'trema-book'...
(略)
stereocat@pc02:~$ cd trema-book/
stereocat@pc02:~/trema-book$ ls
CHAPS               migrating_openflow.re        sty
PART                openflow.re                  switch_monitoring_tool.re
README.md           openflow_framework_trema.re  tdd.re
Rakefile            openflow_merits.re           traffic_monitor.re
_cover.tex          openflow_projects.re         trema.css
cloud.re            patch_panel.re               trema.yaml
diy_switch.re       router_part1.re              tremashark.re
google.re           router_part2.re              whats_openflow.re
images              routing_switch.re
learning_switch.re  sliceable_switch.re
stereocat@pc02:~/trema-book$

epub でビルド

stereocat@pc02:~/trema-book$ rake epub
rm -f trema.epub
review-epubmaker trema.yaml

(略)

stereocat@pc02:~/trema-book$ ls *.epub
trema.epub
stereocat@pc02:~/trema-book$

pdf でビルド

stereocat@pc02:~/trema-book$ rake pdf
rm -f trema.pdf
review-pdfmaker trema.yaml
compiling whats_openflow.tex

(略)

book.dvi -> book.pdf
[1][2][3][4][5][6][7
** WARNING ** Object @page.1 already defined.
][8][9][10][11][12][13][14][15][16][17][18][19][20][21][22][23][24][25][26][27][28][29][30][31][32][33][34][35][36][37][38][39][40][41][42][43][44][45][46][47][48][49][50][51][52][53][54][55][56][57][58][59][60][61][62][63][64][65][66][67]
5368962 bytes written
stereocat@pc02:~/trema-book$ ls *.pdf
trema.pdf
stereocat@pc02:~/trema-book$

こんな感じでファイルができれば成功。

PDF 版

ePub版を iPad (iBooks) で開くとこんな感じ

追記 2013-01-24

いまさら感ただようけど追記しておく。出版されてます。

クラウド時代のネットワーク技術 OpenFlow実践入門 (Software Design plus)

クラウド時代のネットワーク技術 OpenFlow実践入門 (Software Design plus)