review 3.0.0.preview2 → 3.0.0.preview3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -1
- data/NEWS.ja.md +49 -0
- data/NEWS.md +49 -0
- data/README.md +8 -2
- data/doc/LICENSE +20 -0
- data/doc/config.yml.sample +9 -2
- data/doc/customize_epub.ja.md +23 -0
- data/doc/customize_epub.md +23 -0
- data/doc/format.ja.md +98 -4
- data/doc/format.md +98 -1
- data/doc/makeindex.ja.md +2 -2
- data/doc/pdfmaker.ja.md +12 -3
- data/doc/pdfmaker.md +2 -2
- data/doc/preproc.ja.md +2 -2
- data/doc/quickstart.ja.md +1 -1
- data/doc/quickstart.md +1 -1
- data/lib/review/compiler.rb +1 -1
- data/lib/review/configure.rb +13 -1
- data/lib/review/epubmaker.rb +10 -4
- data/lib/review/htmlbuilder.rb +31 -9
- data/lib/review/init.rb +72 -3
- data/lib/review/makerhelper.rb +180 -1
- data/lib/review/pdfmaker.rb +23 -4
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +14 -4
- data/review.gemspec +1 -1
- data/samples/sample-book/src/Rakefile +20 -0
- data/samples/sample-book/src/config.yml +3 -2
- data/samples/sample-book/src/images/cover-a5.ai +5836 -16
- data/samples/sample-book/src/images/cover-b5.ai +5735 -15
- data/samples/syntax-book/config.yml +1 -1
- data/templates/LICENSE +1 -1
- data/templates/latex/config.erb +24 -11
- data/templates/latex/layout.tex.erb +15 -5
- data/templates/latex/review-jlreq/README.md +2 -1
- data/templates/latex/review-jlreq/review-base.sty +165 -22
- data/templates/latex/review-jlreq/review-jlreq.cls +180 -110
- data/templates/latex/review-jlreq/review-style.sty +13 -125
- data/templates/latex/review-jlreq/reviewmacro.sty +7 -0
- data/templates/latex/review-jsbook/README.md +129 -0
- data/templates/latex/review-jsbook/review-base.sty +33 -20
- data/templates/latex/review-jsbook/review-jsbook.cls +545 -0
- data/templates/latex/review-jsbook/reviewmacro.sty +7 -0
- data/test/assets/test_template.tex +27 -8
- data/test/assets/test_template_backmatter.tex +27 -8
- data/test/test_helper.rb +3 -0
- data/test/test_htmlbuilder.rb +3 -1
- data/test/test_pdfmaker.rb +2 -0
- data/vendor/gentombow/.gitignore +163 -0
- data/vendor/gentombow/LICENSE +27 -0
- data/vendor/gentombow/Makefile +36 -0
- data/vendor/gentombow/README.md +49 -0
- data/vendor/gentombow/bounddvi-en.pdf +0 -0
- data/vendor/gentombow/bounddvi-en.tex +135 -0
- data/vendor/gentombow/bounddvi.pdf +0 -0
- data/vendor/gentombow/bounddvi.sty +87 -0
- data/vendor/gentombow/bounddvi.tex +148 -0
- data/vendor/gentombow/create_archive.sh +24 -0
- data/vendor/gentombow/gentombow-ja.pdf +0 -0
- data/vendor/gentombow/gentombow-ja.tex +449 -0
- data/vendor/gentombow/gentombow.pdf +0 -0
- data/vendor/gentombow/gentombow.sty +747 -0
- data/vendor/gentombow/gentombow.tex +298 -0
- data/vendor/gentombow/pxgentombow.pdf +0 -0
- data/vendor/gentombow/pxgentombow.sty +16 -0
- data/vendor/gentombow/pxgentombow.tex +25 -0
- data/vendor/gentombow/tests/bounddvi-01-usage.tex +7 -0
- data/vendor/gentombow/tests/bounddvi-02-jstombow.tex +7 -0
- data/vendor/gentombow/tests/bounddvi-03-grfdvips.tex +9 -0
- data/vendor/gentombow/tests/bounddvi-04-grfdvipdfmx.tex +9 -0
- data/vendor/gentombow/tests/bounddvi-05-geodvips.tex +8 -0
- data/vendor/gentombow/tests/bounddvi-05a-geodvips.tex +9 -0
- data/vendor/gentombow/tests/bounddvi-06-geodvipdfmx.tex +8 -0
- data/vendor/gentombow/tests/bounddvi-06a-geodvipdfmx.tex +9 -0
- data/vendor/gentombow/tests/pxgentombow-01-usage.tex +6 -0
- data/vendor/gentombow/tests/pxgentombow-02-js.tex +6 -0
- data/vendor/gentombow/tests/pxgentombow-02a-js-error.tex +6 -0
- data/vendor/gentombow/tests/pxgentombow-03-notombowdate.tex +8 -0
- data/vendor/gentombow/tests/pxgentombow-04-pkgoption.tex +8 -0
- data/vendor/gentombow/tests/pxgentombow-05-tatecls.tex +6 -0
- metadata +40 -3
data/doc/makeindex.ja.md
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
|
4
4
|
## 注意
|
5
5
|
* LaTeX の mendex コマンドの実装に依存しているため、 現時点では英語または日本語以外の挙動は不明です。
|
6
|
-
* 形態素解析は、外部ソフトウェアの MeCab (http://taku910.github.io/mecab/)、その辞書である IPA 辞書、MeCab の Ruby バインドである mecab に依存しています。
|
6
|
+
* 形態素解析は、外部ソフトウェアの MeCab (http://taku910.github.io/mecab/) 、その辞書である IPA 辞書、MeCab の Ruby バインドである mecab に依存しています。
|
7
7
|
* LaTeX ビルダ以外のビルダでは、埋め込んだ索引を利用する手法を提供していません。後述のヒントを参照してください。
|
8
8
|
* LaTeX ビルダでの索引生成機能は、デフォルトで無効にしています。設定 YAML ファイルで明示的に有効にする必要があります。
|
9
9
|
|
10
10
|
## MeCab のセットアップ
|
11
|
-
形態素解析による自動読みを使用する場合、MeCab
|
11
|
+
形態素解析による自動読みを使用する場合、MeCab (http://taku910.github.io/mecab/) およびその辞書、Ruby バインドライブラリの mecab をインストールしておく必要があります。
|
12
12
|
|
13
13
|
Debian GNU/Linux あるいは Ubuntu の環境では、次のようにパッケージをインストールします。
|
14
14
|
|
data/doc/pdfmaker.ja.md
CHANGED
@@ -7,11 +7,20 @@ Re:VIEW の review-pdfmaker は、フリーソフトウェアの簡易 DTP シ
|
|
7
7
|
* https://texwiki.texjp.org/?TeX入手法
|
8
8
|
|
9
9
|
## Re:VIEW バージョンによる変化についての注意
|
10
|
+
* Re:VIEW 3.0 より、使用するデフォルトのクラスファイルを jsbook.cls から review-jsbook.cls に変更しました。以下の「review-jsbook.cls について」を参照してください。
|
10
11
|
* Re:VIEW 2.0 より、LaTeX コンパイラのデフォルトが pLaTeX から upLaTeX になりました。以下の「upLaTeX について」を参照してください。
|
11
12
|
* Re:VIEW 2.0 より、image タグに `scale` オプションを使って倍率数値を定義していた場合の挙動が変わりました。以下の「scale オプションの挙動について」を参照してください。
|
12
13
|
* Re:VIEW 2.0 より、config.yml 等の設定ファイルで使われる `prt` のデフォルトが「発行所」ではなく「印刷所」になりました。「発行所」には `pbl` のほうをお使いください。
|
13
14
|
|
14
|
-
##
|
15
|
+
## review-jsbook.cls について
|
16
|
+
|
17
|
+
★TBD
|
18
|
+
|
19
|
+
`texdocumentclass` で明示的な設定をしていない場合は、config.yml の `review_version` の値に基づいて切り替えられ、2.0 の場合は従来の jsbook.cls が使われるようになっています。
|
20
|
+
|
21
|
+
## Re:VIEW 2.0 以前の情報
|
22
|
+
|
23
|
+
### upLaTeX について
|
15
24
|
|
16
25
|
2016年4月リリースの Re:VIEW 2.0 より、LaTeX のコンパイラのデフォルトが、「pLaTeX」から「upLaTeX」に切り替わりました。upLaTeX は pLaTeX の内部文字処理を Unicode 対応にしたもので、丸数字(①②…)のように pLaTeXでは otf パッケージが必要だった文字、あるいは韓国語や中国語との混植などを、直接扱うことができます。
|
17
26
|
|
@@ -27,7 +36,7 @@ dvicommand: dvipdfmx
|
|
27
36
|
dvioptions: "-d 5"
|
28
37
|
```
|
29
38
|
|
30
|
-
|
39
|
+
### 旧来の pLaTeX を使用するには(Re:VIEW 1.0)
|
31
40
|
|
32
41
|
既存のドキュメントについて、利用しているマクロやパッケージが upLaTeX でうまく動かない、あるいはこれまでと異なる紙面ができてしまう場合は、pLaTeX に戻したいと思うかもしれません。
|
33
42
|
|
@@ -51,7 +60,7 @@ dvioptions: "-d 5"
|
|
51
60
|
<% end %>
|
52
61
|
```
|
53
62
|
|
54
|
-
|
63
|
+
### scale オプションの挙動について
|
55
64
|
Re:VIEW 2.0 より、``//image`` タグの第3オプションに ``scale=倍率`` で数値のみで倍率を指定していたときの挙動が変わりました。以前は「画像ファイルに対する倍率」でしたが、「紙面横幅に対する倍率」となります(もともと数値以外の文字も scale の値に含めていた場合には、変化はありません)。
|
56
65
|
|
57
66
|
旧来の「画像ファイルに対する倍率」に戻したいときには、config.yml にパラメータ ``image_scale2width: false`` を指定してください(デフォルトは true)。
|
data/doc/pdfmaker.md
CHANGED
@@ -13,7 +13,7 @@ To use the command, you need to set up LaTeX system.
|
|
13
13
|
|
14
14
|
## about upLaTeX
|
15
15
|
|
16
|
-
In Re:VIEW 2.0 released at April 2016, default LaTeX compiler became upLaTeX from pLaTeX. The upLaTeX support Unicode and you can use unicode characters
|
16
|
+
In Re:VIEW 2.0 released at April 2016, default LaTeX compiler became upLaTeX from pLaTeX. The upLaTeX support Unicode and you can use unicode characters and other characters without otf package.
|
17
17
|
|
18
18
|
Almost packages in pLaTeX can be supported in upLaTeX, but some package (such as jsbook class and otf package) need `uplatex` option.
|
19
19
|
|
@@ -22,7 +22,7 @@ Default settings of Re:VIEW is below:
|
|
22
22
|
```yaml
|
23
23
|
texcommand: uplatex
|
24
24
|
texoptions: "-interaction=nonstopmode -file-line-error"
|
25
|
-
texdocumentclass: ["jsbook", "uplatex,
|
25
|
+
texdocumentclass: ["review-jsbook", "uplatex,twoside"]
|
26
26
|
dvicommand: dvipdfmx
|
27
27
|
dvioptions: "-d 5"
|
28
28
|
```
|
data/doc/preproc.ja.md
CHANGED
@@ -25,7 +25,7 @@ end
|
|
25
25
|
```
|
26
26
|
「`#@mapfile(ファイル名)`」から「`#@end`」は、指定したファイル名のファイル全体を本文中に埋め込むための記法です。埋め込む際には、`review-preproc`コマンドを実行します。
|
27
27
|
|
28
|
-
まず、以下のように、引用したい部分に「`#@mapfile()`」と「`#@end`」だけを書きます。ここでは`//list
|
28
|
+
まず、以下のように、引用したい部分に「`#@mapfile()`」と「`#@end`」だけを書きます。ここでは`//list`ブロック内にこの2行だけを記述しています。
|
29
29
|
|
30
30
|
```review
|
31
31
|
//list[hello.rb.1][hello.re]{
|
@@ -82,7 +82,7 @@ if __FILE__ == $0
|
|
82
82
|
Hello.new.hello("world")
|
83
83
|
end
|
84
84
|
```
|
85
|
-
*.re
|
85
|
+
*.reファイルのほうには、「`#@mapfile(ファイル名)`」ではなく「`#@maprange(ファイル名,ID)`」を記述します。
|
86
86
|
|
87
87
|
```review
|
88
88
|
//list[range.rb][range.rb(抜粋)]{
|
data/doc/quickstart.ja.md
CHANGED
@@ -206,7 +206,7 @@ $ review-index --level 掘り下げる見出しレベル数 -a
|
|
206
206
|
|
207
207
|
## クレジット
|
208
208
|
|
209
|
-
Re:VIEW は、青木峰郎によって最初に作成されました。武藤健志がこの開発・保守を引き継ぎ、
|
209
|
+
Re:VIEW は、青木峰郎によって最初に作成されました。武藤健志がこの開発・保守を引き継ぎ、2018年9月時点では、武藤健志、高橋征義、角征典が開発・保守を継続しています。
|
210
210
|
|
211
211
|
バグ・パッチの報告、開発者用メーリングリストなどについての情報は、
|
212
212
|
|
data/doc/quickstart.md
CHANGED
@@ -209,7 +209,7 @@ $ review-index --level <heading level> -a
|
|
209
209
|
|
210
210
|
## Copyright
|
211
211
|
|
212
|
-
The original author of Re:VIEW is Minero Aoki. The current maintainer is Kenshi Muto(@kmuto), and committers are Masayoshi Takahashi and Masanori Kado (
|
212
|
+
The original author of Re:VIEW is Minero Aoki. The current maintainer is Kenshi Muto(@kmuto), and committers are Masayoshi Takahashi and Masanori Kado (September 2018).
|
213
213
|
|
214
214
|
If you want to report bugs and patches, or to get more information, see:
|
215
215
|
|
data/lib/review/compiler.rb
CHANGED
data/lib/review/configure.rb
CHANGED
@@ -77,7 +77,7 @@ module ReVIEW
|
|
77
77
|
'footnotetext' => nil,
|
78
78
|
'texcommand' => 'uplatex',
|
79
79
|
'texoptions' => '-interaction=nonstopmode -file-line-error',
|
80
|
-
'
|
80
|
+
'_texdocumentclass' => ['review-jsbook', ''],
|
81
81
|
'dvicommand' => 'dvipdfmx',
|
82
82
|
'dvioptions' => '-d 5 -z 9',
|
83
83
|
# for PDFMaker
|
@@ -89,6 +89,18 @@ module ReVIEW
|
|
89
89
|
'makeindex_dic' => nil,
|
90
90
|
'makeindex_mecab' => true,
|
91
91
|
'makeindex_mecab_opts' => '-Oyomi'
|
92
|
+
},
|
93
|
+
'imgmath_options' => {
|
94
|
+
'format' => 'png',
|
95
|
+
'converter' => 'pdfcrop', # dvipng | pdfcrop
|
96
|
+
'pdfcrop_cmd' => 'pdfcrop --hires %i %o',
|
97
|
+
'extract_singlepage' => nil,
|
98
|
+
'pdfextract_cmd' => 'pdfjam -q --outfile %o %i %p',
|
99
|
+
'preamble_file' => nil,
|
100
|
+
'fontsize' => 10,
|
101
|
+
'lineheight' => 10 * 1.2,
|
102
|
+
'pdfcrop_pixelize_cmd' => 'pdftocairo -png -r 90 -f %p -l %p -singlefile %i %O',
|
103
|
+
'dvipng_cmd' => 'dvipng -T tight -z 9 -p %p -l %p -o %o %i'
|
92
104
|
}
|
93
105
|
]
|
94
106
|
conf.maker = nil
|
data/lib/review/epubmaker.rb
CHANGED
@@ -23,11 +23,13 @@ require 'rexml/document'
|
|
23
23
|
require 'rexml/streamlistener'
|
24
24
|
require 'epubmaker'
|
25
25
|
require 'review/epubmaker/reviewheaderlistener'
|
26
|
+
require 'review/makerhelper'
|
26
27
|
|
27
28
|
module ReVIEW
|
28
29
|
class EPUBMaker
|
29
30
|
include ::EPUBMaker
|
30
31
|
include REXML
|
32
|
+
include MakerHelper
|
31
33
|
|
32
34
|
def initialize
|
33
35
|
@producer = nil
|
@@ -103,10 +105,8 @@ module ReVIEW
|
|
103
105
|
if @config['debug']
|
104
106
|
FileUtils.rm_rf(booktmpname)
|
105
107
|
end
|
106
|
-
|
107
|
-
|
108
|
-
FileUtils.rm_rf(math_dir)
|
109
|
-
end
|
108
|
+
|
109
|
+
cleanup_mathimg
|
110
110
|
|
111
111
|
basetmpdir = build_path
|
112
112
|
begin
|
@@ -125,6 +125,11 @@ module ReVIEW
|
|
125
125
|
call_hook('hook_afterbody', basetmpdir)
|
126
126
|
|
127
127
|
copy_backmatter(basetmpdir)
|
128
|
+
|
129
|
+
math_dir = "./#{@config['imagedir']}/_review_math"
|
130
|
+
if @config['imgmath'] && File.exist?("#{math_dir}/__IMGMATH_BODY__.tex")
|
131
|
+
make_math_images(math_dir)
|
132
|
+
end
|
128
133
|
call_hook('hook_afterbackmatter', basetmpdir)
|
129
134
|
|
130
135
|
## push contents in basetmpdir into @producer
|
@@ -267,6 +272,7 @@ module ReVIEW
|
|
267
272
|
book.config = @config
|
268
273
|
@converter = ReVIEW::Converter.new(book, ReVIEW::HTMLBuilder.new)
|
269
274
|
@compile_errors = nil
|
275
|
+
|
270
276
|
book.parts.each do |part|
|
271
277
|
if part.name.present?
|
272
278
|
if part.file?
|
data/lib/review/htmlbuilder.rb
CHANGED
@@ -549,14 +549,19 @@ module ReVIEW
|
|
549
549
|
elsif @book.config['imgmath']
|
550
550
|
math_str = "\\begin{equation*}\n" + unescape(lines.join("\n")) + "\n\\end{equation*}\n"
|
551
551
|
key = Digest::SHA256.hexdigest(math_str)
|
552
|
-
math_dir =
|
552
|
+
math_dir = File.join(@book.config['imagedir'], '_review_math')
|
553
553
|
Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
|
554
|
-
img_path = "
|
555
|
-
|
556
|
-
|
554
|
+
img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
|
555
|
+
if @book.config.check_version('2', exception: false)
|
556
|
+
make_math_image(math_str, img_path)
|
557
|
+
puts %Q(<img src="#{img_path}" />)
|
558
|
+
else
|
559
|
+
defer_math_image(math_str, img_path, key)
|
560
|
+
puts %Q(<img src="#{img_path}" class="math_gen_#{key}" alt="#{escape(lines.join(' '))}" />)
|
561
|
+
end
|
557
562
|
else
|
558
563
|
print '<pre>'
|
559
|
-
puts lines.join("\n")
|
564
|
+
puts escape(lines.join("\n"))
|
560
565
|
puts '</pre>'
|
561
566
|
end
|
562
567
|
puts '</div>'
|
@@ -924,11 +929,16 @@ module ReVIEW
|
|
924
929
|
elsif @book.config['imgmath']
|
925
930
|
math_str = '$' + str + '$'
|
926
931
|
key = Digest::SHA256.hexdigest(str)
|
927
|
-
math_dir =
|
932
|
+
math_dir = File.join(@book.config['imagedir'], '_review_math')
|
928
933
|
Dir.mkdir(math_dir) unless Dir.exist?(math_dir)
|
929
|
-
img_path = "
|
930
|
-
|
931
|
-
|
934
|
+
img_path = File.join(math_dir, "_gen_#{key}.#{@book.config['imgmath_options']['format']}")
|
935
|
+
if @book.config.check_version('2', exception: false)
|
936
|
+
make_math_image(math_str, img_path)
|
937
|
+
%Q(<span class="equation"><img src="#{img_path}" /></span>)
|
938
|
+
else
|
939
|
+
defer_math_image(math_str, img_path, key)
|
940
|
+
%Q(<span class="equation"><img src="#{img_path}" class="math_gen_#{key}" alt="#{escape(str)}" /></span>)
|
941
|
+
end
|
932
942
|
else
|
933
943
|
%Q(<span class="equation">#{escape(str)}</span>)
|
934
944
|
end
|
@@ -1192,7 +1202,19 @@ module ReVIEW
|
|
1192
1202
|
@ol_num = num.to_i
|
1193
1203
|
end
|
1194
1204
|
|
1205
|
+
def defer_math_image(str, path, key)
|
1206
|
+
# for Re:VIEW >3
|
1207
|
+
File.open(File.join(File.dirname(path), '__IMGMATH_BODY__.tex'), 'a+') do |f|
|
1208
|
+
f.puts str
|
1209
|
+
f.puts '\\clearpage'
|
1210
|
+
end
|
1211
|
+
File.open(File.join(File.dirname(path), '__IMGMATH_BODY__.map'), 'a+') do |f|
|
1212
|
+
f.puts key
|
1213
|
+
end
|
1214
|
+
end
|
1215
|
+
|
1195
1216
|
def make_math_image(str, path, fontsize = 12)
|
1217
|
+
# Re:VIEW 2 compatibility
|
1196
1218
|
fontsize2 = (fontsize * 1.2).round.to_i
|
1197
1219
|
texsrc = <<-EOB
|
1198
1220
|
\\documentclass[12pt]{article}
|
data/lib/review/init.rb
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
require 'fileutils'
|
10
10
|
require 'optparse'
|
11
|
+
require 'net/http'
|
12
|
+
require 'tempfile'
|
11
13
|
require 'review'
|
12
14
|
|
13
15
|
module ReVIEW
|
@@ -38,6 +40,7 @@ module ReVIEW
|
|
38
40
|
generate_rakefile(dir)
|
39
41
|
generate_gemfile(dir)
|
40
42
|
generate_doc(dir) unless @without_doc
|
43
|
+
download_and_extract_archive(dir, @archive) if @archive
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
@@ -58,12 +61,15 @@ module ReVIEW
|
|
58
61
|
opts.on('--latex-template name', 'specify LaTeX template name. (default: review-jsbook)') do |tname|
|
59
62
|
@template = tname
|
60
63
|
end
|
61
|
-
opts.on('', '--epub-version VERSION', 'define EPUB version') do |version|
|
64
|
+
opts.on('', '--epub-version VERSION', 'define EPUB version.') do |version|
|
62
65
|
@epub_version = version
|
63
66
|
end
|
64
|
-
opts.on('', '--without-doc', "don't generate doc files") do
|
67
|
+
opts.on('', '--without-doc', "don't generate doc files.") do
|
65
68
|
@without_doc = true
|
66
69
|
end
|
70
|
+
opts.on('-p', '--package archivefile', 'extract from local or network archive.') do |archive|
|
71
|
+
@archive = archive
|
72
|
+
end
|
67
73
|
|
68
74
|
begin
|
69
75
|
opts.parse!(args)
|
@@ -125,15 +131,18 @@ EOS
|
|
125
131
|
def generate_cover_image(dir)
|
126
132
|
FileUtils.cp(@review_dir + '/samples/sample-book/src/images/cover.jpg',
|
127
133
|
dir + '/images/')
|
134
|
+
FileUtils.cp(@review_dir + '/samples/sample-book/src/images/cover-a5.ai',
|
135
|
+
dir + '/images/')
|
128
136
|
end
|
129
137
|
|
130
138
|
def generate_config(dir)
|
131
139
|
today = Time.now.strftime('%Y-%m-%d')
|
132
140
|
content = File.read(@review_dir + '/doc/config.yml.sample', encoding: 'utf-8')
|
133
141
|
content.gsub!(/^#\s*coverimage:.*$/, 'coverimage: cover.jpg')
|
142
|
+
content.gsub!(/^ #\s*coverimage:.*$/, ' coverimage: cover-a5.ai')
|
134
143
|
content.gsub!(/^#\s*date:.*$/, "date: #{today}")
|
135
144
|
content.gsub!(/^#\s*history:.*$/, %Q(history: [["#{today}"]]))
|
136
|
-
content.gsub!(/^#\s*texstyle:.*$/, 'texstyle: reviewmacro')
|
145
|
+
content.gsub!(/^#\s*texstyle:.*$/, 'texstyle: ["reviewmacro"]')
|
137
146
|
content.gsub!(/^(#\s*)?stylesheet:.*$/, %Q(stylesheet: ["style.css"]))
|
138
147
|
if @epub_version.to_i == 2
|
139
148
|
content.gsub!(/^#.*epubversion:.*$/, 'epubversion: 2')
|
@@ -152,6 +161,8 @@ EOS
|
|
152
161
|
tdir = File.join(@review_dir, '/templates/latex', @template)
|
153
162
|
@logger.error "#{tdir} not found." unless File.exist?(tdir)
|
154
163
|
FileUtils.cp Dir.glob(tdir + '/*.*'), texmacrodir
|
164
|
+
# provide gentombow from vendor/. current version is 2018/08/30 v0.9j
|
165
|
+
FileUtils.cp File.join(@review_dir, '/vendor/gentombow/gentombow.sty'), File.join(texmacrodir, 'gentombow09j.sty')
|
155
166
|
end
|
156
167
|
|
157
168
|
def generate_rakefile(dir)
|
@@ -190,5 +201,63 @@ EOS
|
|
190
201
|
md_files = Dir.glob(@review_dir + '/doc/*.md').map.to_a
|
191
202
|
FileUtils.cp md_files, docdir
|
192
203
|
end
|
204
|
+
|
205
|
+
def download_and_extract_archive(dir, filename)
|
206
|
+
begin
|
207
|
+
require 'zip'
|
208
|
+
rescue LoadError
|
209
|
+
@logger.error 'extracting needs rubyzip.'
|
210
|
+
exit 1
|
211
|
+
end
|
212
|
+
|
213
|
+
if filename =~ %r{\Ahttps?://}
|
214
|
+
begin
|
215
|
+
@logger.info "Downloading from #{filename}"
|
216
|
+
zipdata = Net::HTTP.get(URI.parse(filename))
|
217
|
+
rescue StandardError => err
|
218
|
+
@logger.error "Failed to download #{filename}: #{err.message}"
|
219
|
+
exit 1
|
220
|
+
end
|
221
|
+
|
222
|
+
Tempfile.create('reviewinit') do |f|
|
223
|
+
zipfilename = f.path
|
224
|
+
f.write zipdata
|
225
|
+
|
226
|
+
extract_archive(dir, zipfilename, filename)
|
227
|
+
end
|
228
|
+
else
|
229
|
+
unless File.readable?(filename)
|
230
|
+
@logger.error "Failed to open #{filename}"
|
231
|
+
exit 1
|
232
|
+
end
|
233
|
+
extract_archive(dir, filename, filename)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def extract_archive(dir, filename, originalfilename)
|
238
|
+
made = nil
|
239
|
+
begin
|
240
|
+
Zip::File.open(filename) do |zip|
|
241
|
+
zip.each do |entry|
|
242
|
+
fname = entry.name.gsub('\\', '/')
|
243
|
+
if fname =~ /__MACOSX/ || fname =~ /\.DS_Store/
|
244
|
+
next
|
245
|
+
end
|
246
|
+
|
247
|
+
if fname =~ %r{\A/} || fname =~ /\.\./ # simple fool proof
|
248
|
+
made = nil
|
249
|
+
break
|
250
|
+
end
|
251
|
+
|
252
|
+
# `true' means override
|
253
|
+
entry.extract(File.join(dir, fname)) { true }
|
254
|
+
end
|
255
|
+
made = true
|
256
|
+
end
|
257
|
+
raise Zip::Error unless made
|
258
|
+
rescue Zip::Error => err
|
259
|
+
@logger.error "#{originalfilename} seems invalid or broken zip file: #{err.message}"
|
260
|
+
end
|
261
|
+
end
|
193
262
|
end
|
194
263
|
end
|
data/lib/review/makerhelper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2012-
|
1
|
+
# Copyright (c) 2012-2018 Yuto HAYAMIZU, Kenshi Muto
|
2
2
|
#
|
3
3
|
# This program is free software.
|
4
4
|
# You can distribute or modify this program under the terms of
|
@@ -8,6 +8,7 @@
|
|
8
8
|
require 'pathname'
|
9
9
|
require 'fileutils'
|
10
10
|
require 'yaml'
|
11
|
+
require 'shellwords'
|
11
12
|
|
12
13
|
module ReVIEW
|
13
14
|
module MakerHelper
|
@@ -64,5 +65,183 @@ module ReVIEW
|
|
64
65
|
image_files
|
65
66
|
end
|
66
67
|
module_function :copy_images_to_dir
|
68
|
+
|
69
|
+
def cleanup_mathimg
|
70
|
+
math_dir = "./#{@config['imagedir']}/_review_math"
|
71
|
+
if @config['imgmath'] && Dir.exist?(math_dir)
|
72
|
+
FileUtils.rm_rf(math_dir)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def default_imgmath_preamble
|
77
|
+
<<-EOB
|
78
|
+
\\documentclass[uplatex]{jsarticle}
|
79
|
+
\\usepackage[deluxe,uplatex]{otf}
|
80
|
+
\\usepackage[T1]{fontenc}
|
81
|
+
\\usepackage{textcomp}
|
82
|
+
\\usepackage{lmodern}
|
83
|
+
\\usepackage[dvipdfmx]{graphicx}
|
84
|
+
\\usepackage[dvipdfmx,table]{xcolor}
|
85
|
+
\\usepackage[utf8]{inputenc}
|
86
|
+
\\usepackage{ascmac}
|
87
|
+
\\usepackage{float}
|
88
|
+
\\usepackage{alltt}
|
89
|
+
\\usepackage{amsmath}
|
90
|
+
\\usepackage{amssymb}
|
91
|
+
\\usepackage{amsfonts}
|
92
|
+
\\usepackage{anyfontsize}
|
93
|
+
\\usepackage{bm}
|
94
|
+
\\pagestyle{empty}
|
95
|
+
EOB
|
96
|
+
end
|
97
|
+
|
98
|
+
def make_math_images(math_dir)
|
99
|
+
fontsize = @config['imgmath_options']['fontsize'].to_f
|
100
|
+
lineheight = @config['imgmath_options']['lineheight'].to_f
|
101
|
+
|
102
|
+
texsrc = default_imgmath_preamble
|
103
|
+
if @config['imgmath_options']['preamble_file'] && File.readable?(@config['imgmath_options']['preamble_file'])
|
104
|
+
texsrc = File.read(@config['imgmath_options']['preamble_file'])
|
105
|
+
end
|
106
|
+
|
107
|
+
texsrc << <<-EOB
|
108
|
+
\\begin{document}
|
109
|
+
\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont
|
110
|
+
\\input{__IMGMATH_BODY__}
|
111
|
+
\\end{document}
|
112
|
+
EOB
|
113
|
+
|
114
|
+
math_dir = File.realpath(math_dir)
|
115
|
+
Dir.mktmpdir do |tmpdir|
|
116
|
+
FileUtils.cp([File.join(math_dir, '__IMGMATH_BODY__.tex'),
|
117
|
+
File.join(math_dir, '__IMGMATH_BODY__.map')],
|
118
|
+
tmpdir)
|
119
|
+
tex_path = File.join(tmpdir, '__IMGMATH__.tex')
|
120
|
+
File.write(tex_path, texsrc)
|
121
|
+
|
122
|
+
begin
|
123
|
+
case @config['imgmath_options']['converter']
|
124
|
+
when 'pdfcrop'
|
125
|
+
make_math_images_pdfcrop(tmpdir, tex_path, math_dir)
|
126
|
+
when 'dvipng'
|
127
|
+
make_math_images_dvipng(tmpdir, tex_path, math_dir)
|
128
|
+
else
|
129
|
+
error "unknown math converter error. imgmath_options/converter parameter should be 'pdfcrop' or 'dvipng'."
|
130
|
+
end
|
131
|
+
rescue CompileError
|
132
|
+
FileUtils.cp([tex_path,
|
133
|
+
File.join(File.dirname(tex_path), '__IMGMATH__.log')],
|
134
|
+
math_dir)
|
135
|
+
error "LaTeX math compile error. See #{math_dir}/__IMGMATH__.log for details."
|
136
|
+
end
|
137
|
+
end
|
138
|
+
FileUtils.rm_f([File.join(math_dir, '__IMGMATH_BODY__.tex'),
|
139
|
+
File.join(math_dir, '__IMGMATH_BODY__.map')])
|
140
|
+
end
|
141
|
+
|
142
|
+
def make_math_images_pdfcrop(dir, tex_path, math_dir)
|
143
|
+
Dir.chdir(dir) do
|
144
|
+
dvi_path = '__IMGMATH__.dvi'
|
145
|
+
pdf_path = '__IMGMATH__.pdf'
|
146
|
+
out, status = Open3.capture2e(*[@config['texcommand'], @config['texoptions'].shellsplit, tex_path].flatten.compact)
|
147
|
+
if !status.success? || (!File.exist?(dvi_path) && !File.exist?(pdf_path))
|
148
|
+
raise CompileError
|
149
|
+
end
|
150
|
+
if File.exist?(dvi_path)
|
151
|
+
out, status = Open3.capture2e(*[@config['dvicommand'], @config['dvioptions'].shellsplit, dvi_path].flatten.compact)
|
152
|
+
if !status.success? || !File.exist?(pdf_path)
|
153
|
+
warn "error in #{@config['dvicommand']}. Error log:\n#{out}"
|
154
|
+
raise CompileError
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
args = @config['imgmath_options']['pdfcrop_cmd'].shellsplit
|
159
|
+
args.map! do |m|
|
160
|
+
m.sub('%i', pdf_path).
|
161
|
+
sub('%o', '__IMGMATH__pdfcrop.pdf')
|
162
|
+
end
|
163
|
+
out, status = Open3.capture2e(*args)
|
164
|
+
unless status.success?
|
165
|
+
warn "error in pdfcrop. Error log:\n#{out}"
|
166
|
+
raise CompileError
|
167
|
+
end
|
168
|
+
pdf_path = '__IMGMATH__pdfcrop.pdf'
|
169
|
+
pdf_path2 = pdf_path
|
170
|
+
|
171
|
+
File.open('__IMGMATH_BODY__.map') do |f|
|
172
|
+
page = 0
|
173
|
+
f.each_line do |key|
|
174
|
+
page += 1
|
175
|
+
key.chomp!
|
176
|
+
if File.exist?(File.join(math_dir, "_gen_#{key}.#{@config['imgmath_options']['format']}"))
|
177
|
+
# made already
|
178
|
+
next
|
179
|
+
end
|
180
|
+
|
181
|
+
if @config['imgmath_options']['extract_singlepage']
|
182
|
+
# if extract_singlepage = true, split each page
|
183
|
+
args = @config['imgmath_options']['pdfextract_cmd'].shellsplit
|
184
|
+
|
185
|
+
args.map! do |m|
|
186
|
+
m.sub('%i', pdf_path).
|
187
|
+
sub('%o', "__IMGMATH__pdfcrop_p#{page}.pdf").
|
188
|
+
sub('%O', "__IMGMATH__pdfcrop_p#{page}").
|
189
|
+
sub('%p', page.to_s)
|
190
|
+
end
|
191
|
+
out, status = Open3.capture2e(*args)
|
192
|
+
unless status.success?
|
193
|
+
warn "error in pdf extracting. Error log:\n#{out}"
|
194
|
+
raise CompileError
|
195
|
+
end
|
196
|
+
|
197
|
+
pdf_path2 = "__IMGMATH__pdfcrop_p#{page}.pdf"
|
198
|
+
end
|
199
|
+
|
200
|
+
args = @config['imgmath_options']['pdfcrop_pixelize_cmd'].shellsplit
|
201
|
+
args.map! do |m|
|
202
|
+
m.sub('%i', pdf_path2).
|
203
|
+
sub('%o', File.join(math_dir, "_gen_#{key}.#{@config['imgmath_options']['format']}")).
|
204
|
+
sub('%O', File.join(math_dir, "_gen_#{key}")).
|
205
|
+
sub('%p', page.to_s)
|
206
|
+
end
|
207
|
+
out, status = Open3.capture2e(*args)
|
208
|
+
unless status.success?
|
209
|
+
warn "error in pdf pixelizing. Error log:\n#{out}"
|
210
|
+
raise CompileError
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def make_math_images_dvipng(dir, tex_path, math_dir)
|
218
|
+
Dir.chdir(dir) do
|
219
|
+
dvi_path = '__IMGMATH__.dvi'
|
220
|
+
out, status = Open3.capture2e(*[@config['texcommand'], @config['texoptions'].shellsplit, tex_path].flatten.compact)
|
221
|
+
if !status.success? || !File.exist?(dvi_path)
|
222
|
+
raise CompileError
|
223
|
+
end
|
224
|
+
|
225
|
+
File.open('__IMGMATH_BODY__.map') do |f|
|
226
|
+
page = 0
|
227
|
+
f.each_line do |key|
|
228
|
+
page += 1
|
229
|
+
key.chomp!
|
230
|
+
args = @config['imgmath_options']['dvipng_cmd'].shellsplit
|
231
|
+
args.map! do |m|
|
232
|
+
m.sub('%i', dvi_path).
|
233
|
+
sub('%o', File.join(math_dir, "_gen_#{key}.#{@config['imgmath_options']['format']}")).
|
234
|
+
sub('%O', File.join(math_dir, "_gen_#{key}")).
|
235
|
+
sub('%p', page.to_s)
|
236
|
+
end
|
237
|
+
out, status = Open3.capture2e(*args)
|
238
|
+
unless status.success?
|
239
|
+
warn "error in dvipng. Error log:\n#{out}"
|
240
|
+
raise CompileError
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
67
246
|
end
|
68
247
|
end
|