review 3.2.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-tex.yml +31 -0
- data/.github/workflows/ruby-win.yml +45 -0
- data/.github/workflows/ruby.yml +27 -0
- data/.rubocop.yml +167 -42
- data/.travis.yml +1 -1
- data/Dockerfile +21 -5
- data/NEWS.ja.md +428 -1
- data/NEWS.md +429 -2
- data/README.md +11 -7
- data/Rakefile +7 -2
- data/appveyor.yml +0 -20
- data/bin/review +2 -4
- data/bin/review-catalog-converter +5 -5
- data/bin/review-check +13 -17
- data/bin/review-checkdep +3 -6
- data/bin/review-compile +13 -22
- data/bin/review-epub2html +1 -4
- data/bin/review-epubmaker +3 -4
- data/bin/review-idgxmlmaker +14 -0
- data/bin/review-index +5 -86
- data/bin/review-init +1 -4
- data/bin/review-pdfmaker +1 -3
- data/bin/review-preproc +11 -13
- data/bin/review-textmaker +1 -3
- data/bin/review-update +1 -4
- data/bin/review-validate +7 -7
- data/bin/review-vol +5 -82
- data/bin/review-webmaker +1 -3
- data/doc/config.yml.sample +67 -16
- data/doc/config.yml.sample-simple +4 -3
- data/doc/format.ja.md +133 -21
- data/doc/format.md +135 -34
- data/doc/makeindex.ja.md +2 -2
- data/doc/pdfmaker.ja.md +43 -1
- data/doc/pdfmaker.md +42 -1
- data/doc/quickstart.ja.md +55 -25
- data/doc/quickstart.md +47 -17
- data/lib/review.rb +1 -1
- data/lib/review/book.rb +2 -2
- data/lib/review/book/base.rb +89 -90
- data/lib/review/book/bib.rb +21 -0
- data/lib/review/book/book_unit.rb +158 -0
- data/lib/review/book/chapter.rb +51 -29
- data/lib/review/book/index.rb +42 -248
- data/lib/review/book/index/item.rb +46 -0
- data/lib/review/book/page_metric.rb +7 -7
- data/lib/review/book/part.rb +45 -10
- data/lib/review/book/volume.rb +5 -5
- data/lib/review/builder.rb +171 -54
- data/lib/review/call_hook.rb +20 -0
- data/lib/review/catalog.rb +15 -17
- data/lib/review/compiler.rb +240 -102
- data/lib/review/configure.rb +101 -12
- data/lib/review/converter.rb +1 -1
- data/lib/review/epub2html.rb +6 -1
- data/lib/review/epubmaker.rb +120 -118
- data/lib/review/epubmaker/content.rb +113 -0
- data/lib/review/epubmaker/epubcommon.rb +372 -0
- data/lib/review/epubmaker/epubv2.rb +178 -0
- data/lib/review/epubmaker/epubv3.rb +231 -0
- data/lib/review/epubmaker/producer.rb +168 -0
- data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
- data/lib/review/epubmaker/zip_exporter.rb +84 -0
- data/lib/review/exception.rb +6 -0
- data/lib/review/extentions/string.rb +0 -4
- data/lib/review/htmlbuilder.rb +147 -149
- data/lib/review/htmlutils.rb +10 -14
- data/lib/review/i18n.rb +4 -3
- data/lib/review/idgxmlbuilder.rb +229 -103
- data/lib/review/idgxmlmaker.rb +188 -0
- data/lib/review/img_math.rb +245 -0
- data/lib/review/index_builder.rb +654 -0
- data/lib/review/init-web/finish.html +10 -0
- data/lib/review/init-web/index.html +190 -0
- data/lib/review/init-web/review-layout-design.js +691 -0
- data/lib/review/init.rb +124 -41
- data/lib/review/latexbox.rb +58 -0
- data/lib/review/latexbuilder.rb +249 -97
- data/lib/review/latexutils.rb +9 -1
- data/lib/review/lineinput.rb +113 -3
- data/lib/review/logger.rb +43 -8
- data/lib/review/makerhelper.rb +13 -186
- data/lib/review/markdownbuilder.rb +75 -39
- data/lib/review/md2inaobuilder.rb +3 -5
- data/lib/review/pdfmaker.rb +88 -83
- data/lib/review/plaintextbuilder.rb +158 -83
- data/lib/review/preprocessor.rb +30 -24
- data/lib/review/rstbuilder.rb +58 -39
- data/lib/review/sec_counter.rb +14 -0
- data/lib/review/template.rb +6 -0
- data/lib/review/textmaker.rb +29 -17
- data/lib/review/textutils.rb +68 -2
- data/lib/review/tocprinter.rb +242 -97
- data/lib/review/topbuilder.rb +147 -61
- data/lib/review/update.rb +27 -28
- data/lib/review/version.rb +1 -1
- data/lib/review/volumeprinter.rb +97 -0
- data/lib/review/webmaker.rb +36 -35
- data/lib/review/webtocprinter.rb +39 -35
- data/lib/review/yamlloader.rb +4 -0
- data/review.gemspec +8 -5
- data/samples/sample-book/README.md +7 -2
- data/samples/sample-book/src/.gitignore +154 -0
- data/samples/sample-book/src/config-ebook.yml +4 -0
- data/samples/sample-book/src/config-epub2.yml +1 -1
- data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
- data/samples/sample-book/src/config-jlreq.yml +6 -0
- data/samples/sample-book/src/config.yml +3 -3
- data/samples/sample-book/src/lib/tasks/review.rake +45 -14
- data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
- data/samples/syntax-book/Gemfile +1 -1
- data/samples/syntax-book/ch01.re +3 -1
- data/samples/syntax-book/ch02.re +28 -21
- data/samples/syntax-book/ch03.re +4 -7
- data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
- data/samples/syntax-book/config-jlreq.yml +5 -0
- data/samples/syntax-book/config-print.yml +3 -0
- data/samples/syntax-book/config.yml +1 -1
- data/samples/syntax-book/images/img3-2.png +0 -0
- data/samples/syntax-book/lib/tasks/review.rake +30 -15
- data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
- data/templates/html/_colophon.html.erb +23 -0
- data/templates/html/_colophon_history.html.erb +9 -0
- data/templates/html/_cover.html.erb +10 -0
- data/templates/html/_part_body.html.erb +6 -0
- data/templates/html/_titlepage.html.erb +20 -0
- data/templates/html/layout-html5.html.erb +6 -0
- data/templates/html/layout-xhtml1.html.erb +6 -0
- data/templates/latex/config.erb +45 -27
- data/templates/latex/layout.tex.erb +1 -0
- data/templates/latex/review-jlreq/README.md +3 -1
- data/templates/latex/review-jlreq/review-base.sty +124 -37
- data/templates/latex/review-jlreq/review-jlreq.cls +29 -22
- data/templates/latex/review-jlreq/review-style.sty +9 -1
- data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
- data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
- data/templates/latex/review-jsbook/README.md +46 -5
- data/templates/latex/review-jsbook/review-base.sty +111 -30
- data/templates/latex/review-jsbook/review-jsbook.cls +16 -2
- data/templates/latex/review-jsbook/review-style.sty +10 -2
- data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
- data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
- data/templates/opf/epubv2.opf.erb +7 -7
- data/templates/opf/epubv3.opf.erb +7 -7
- data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
- data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
- data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
- data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
- data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
- data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
- data/templates/web/html/layout-html5.html.erb +9 -8
- data/templates/web/html/layout-xhtml1.html.erb +6 -0
- data/test/assets/header_listener.html +35 -0
- data/test/assets/img_math/img1.png +0 -0
- data/test/assets/img_math/img2.png +0 -0
- data/test/assets/img_math/img3.png +0 -0
- data/test/assets/syntax_book_index_detail.txt +58 -0
- data/test/assets/test_template.tex +20 -9
- data/test/assets/test_template_backmatter.tex +20 -9
- data/test/book_test_helper.rb +11 -5
- data/test/run_test.rb +1 -1
- data/test/test_book.rb +123 -78
- data/test/test_book_chapter.rb +99 -56
- data/test/test_book_part.rb +3 -3
- data/test/test_builder.rb +24 -15
- data/test/test_catalog.rb +19 -42
- data/test/test_catalog_converter_cmd.rb +1 -1
- data/test/test_converter.rb +1 -0
- data/test/test_epub3maker.rb +170 -126
- data/test/test_epubmaker.rb +249 -129
- data/test/test_epubmaker_cmd.rb +16 -9
- data/test/test_helper.rb +23 -11
- data/test/test_htmlbuilder.rb +1083 -114
- data/test/test_htmlutils.rb +0 -12
- data/test/test_i18n.rb +37 -37
- data/test/test_idgxmlbuilder.rb +627 -27
- data/test/test_idgxmlmaker_cmd.rb +50 -0
- data/test/test_image_finder.rb +52 -70
- data/test/test_img_math.rb +111 -0
- data/test/test_index.rb +62 -52
- data/test/test_indexbuilder.rb +52 -0
- data/test/test_latexbuilder.rb +1189 -59
- data/test/test_latexbuilder_v2.rb +74 -34
- data/test/test_lineinput.rb +20 -93
- data/test/test_logger.rb +17 -4
- data/test/test_makerhelper.rb +2 -14
- data/test/test_markdownbuilder.rb +77 -4
- data/test/test_md2inaobuilder.rb +12 -2
- data/test/test_pdfmaker.rb +101 -12
- data/test/test_pdfmaker_cmd.rb +102 -8
- data/test/test_plaintextbuilder.rb +562 -31
- data/test/test_review_ext.rb +2 -1
- data/test/test_reviewheaderlistener.rb +49 -0
- data/test/test_rstbuilder.rb +58 -5
- data/test/test_sec_counter.rb +156 -0
- data/test/test_template.rb +12 -2
- data/test/test_textmaker_cmd.rb +58 -0
- data/test/test_textutils.rb +109 -2
- data/test/test_tocprinter.rb +46 -0
- data/test/test_topbuilder.rb +400 -17
- data/test/test_update.rb +53 -44
- data/test/test_webtocprinter.rb +75 -43
- data/test/test_yamlloader.rb +13 -0
- data/test/test_zip_exporter.rb +5 -6
- data/vendor/gentombow/LICENSE +1 -1
- data/vendor/gentombow/Makefile +0 -1
- data/vendor/gentombow/bounddvi-en.pdf +0 -0
- data/vendor/gentombow/bounddvi-en.tex +1 -0
- data/vendor/gentombow/bounddvi.pdf +0 -0
- data/vendor/gentombow/bounddvi.sty +30 -7
- data/vendor/gentombow/bounddvi.tex +1 -0
- data/vendor/gentombow/create_archive.sh +1 -0
- data/vendor/gentombow/gentombow-ja.pdf +0 -0
- data/vendor/gentombow/gentombow-ja.tex +9 -0
- data/vendor/gentombow/gentombow.pdf +0 -0
- data/vendor/gentombow/gentombow.sty +32 -10
- data/vendor/gentombow/gentombow.tex +8 -0
- data/vendor/gentombow/tests/gentombow-01-pdfx.tex +8 -0
- data/vendor/gentombow/tests/gentombow-02-pdfx.tex +8 -0
- data/vendor/jsclasses/LICENSE +1 -1
- data/vendor/jsclasses/Makefile +3 -2
- data/vendor/jsclasses/create_archive.sh +5 -5
- data/vendor/jsclasses/jis/Makefile +3 -2
- data/vendor/jsclasses/jis/jsarticle.cls +74 -31
- data/vendor/jsclasses/jis/jsbook.cls +74 -31
- data/vendor/jsclasses/jis/jsclasses.dtx +176 -36
- data/vendor/jsclasses/jis/jsclasses.ins +15 -5
- data/vendor/jsclasses/jis/jslogo.dtx +4 -4
- data/vendor/jsclasses/jis/jslogo.ins +9 -0
- data/vendor/jsclasses/jis/jslogo.sty +4 -16
- data/vendor/jsclasses/jis/jspf.cls +73 -30
- data/vendor/jsclasses/jis/jsreport.cls +74 -31
- data/vendor/jsclasses/jis/jsverb.ins +9 -0
- data/vendor/jsclasses/jis/jsverb.sty +1 -13
- data/vendor/jsclasses/jis/kiyou.cls +74 -31
- data/vendor/jsclasses/jis/minijs.sty +65 -22
- data/vendor/jsclasses/jis/okumacro.dtx +4 -5
- data/vendor/jsclasses/jis/okumacro.ins +9 -0
- data/vendor/jsclasses/jis/okumacro.sty +4 -17
- data/vendor/jsclasses/jis/okuverb.ins +9 -0
- data/vendor/jsclasses/jis/okuverb.sty +1 -13
- data/vendor/jsclasses/jis/winjis.sty +23 -19
- data/vendor/jsclasses/jsarticle.cls +74 -31
- data/vendor/jsclasses/jsbook.cls +74 -31
- data/vendor/jsclasses/jsclasses.dtx +176 -36
- data/vendor/jsclasses/jsclasses.ins +15 -5
- data/vendor/jsclasses/jsclasses.pdf +0 -0
- data/vendor/jsclasses/jslogo.dtx +4 -4
- data/vendor/jsclasses/jslogo.ins +9 -0
- data/vendor/jsclasses/jslogo.pdf +0 -0
- data/vendor/jsclasses/jslogo.sty +4 -16
- data/vendor/jsclasses/jspf.cls +73 -30
- data/vendor/jsclasses/jsreport.cls +74 -31
- data/vendor/jsclasses/jsverb.ins +9 -0
- data/vendor/jsclasses/jsverb.pdf +0 -0
- data/vendor/jsclasses/jsverb.sty +1 -13
- data/vendor/jsclasses/kiyou.cls +74 -31
- data/vendor/jsclasses/minijs.sty +68 -22
- data/vendor/jsclasses/okumacro.dtx +4 -5
- data/vendor/jsclasses/okumacro.ins +9 -0
- data/vendor/jsclasses/okumacro.pdf +0 -0
- data/vendor/jsclasses/okumacro.sty +4 -17
- data/vendor/jsclasses/okuverb.ins +9 -0
- data/vendor/jsclasses/okuverb.pdf +0 -0
- data/vendor/jsclasses/okuverb.sty +1 -13
- data/vendor/jsclasses/tests/relfont.tex +10 -0
- data/vendor/jsclasses/winjis.sty +23 -19
- metadata +136 -23
- data/.rubocop_todo.yml +0 -7
- data/lib/epubmaker.rb +0 -23
- data/lib/epubmaker/content.rb +0 -110
- data/lib/epubmaker/epubcommon.rb +0 -441
- data/lib/epubmaker/epubv2.rb +0 -143
- data/lib/epubmaker/epubv3.rb +0 -233
- data/lib/epubmaker/producer.rb +0 -375
- data/lib/epubmaker/zip_exporter.rb +0 -81
- data/lib/lineinput.rb +0 -155
- data/lib/review/book/compilable.rb +0 -173
- data/lib/review/tocparser.rb +0 -271
- data/samples/syntax-book/review-ext.rb +0 -14
- data/test/test_tocparser.rb +0 -25
data/lib/review/init.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2018-
|
2
|
+
# Copyright (c) 2018-2021 Masanori Kado, Masayoshi Takahashi, Kenshi Muto
|
3
3
|
#
|
4
4
|
# This program is free software.
|
5
5
|
# You can distribute or modify this program under the terms of
|
@@ -18,12 +18,12 @@ module ReVIEW
|
|
18
18
|
new.execute(*args)
|
19
19
|
end
|
20
20
|
|
21
|
-
TEX_DOCUMENTCLASS_OPTS = {
|
22
|
-
'review-jsbook' => 'media=print,paper=a5',
|
23
|
-
'review-jlreq' => 'media=print,paper=a5'
|
24
|
-
}
|
25
|
-
|
26
21
|
def initialize
|
22
|
+
@tex_documentclass_opts = {
|
23
|
+
'review-jsbook' => 'media=print,paper=a5',
|
24
|
+
'review-jlreq' => 'media=print,paper=a5'
|
25
|
+
}
|
26
|
+
|
27
27
|
@template = 'review-jsbook'
|
28
28
|
@logger = ReVIEW.logger
|
29
29
|
@review_dir = File.dirname(File.expand_path('..', __dir__))
|
@@ -32,15 +32,25 @@ module ReVIEW
|
|
32
32
|
def execute(*args)
|
33
33
|
initdir = parse_options(args)
|
34
34
|
|
35
|
+
if @webui
|
36
|
+
start_webui
|
37
|
+
unless @web_result
|
38
|
+
@logger.error 'Aborted.'
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
@template = @web_result[0]
|
42
|
+
@tex_documentclass_opts[@template] = @web_result[1]
|
43
|
+
end
|
44
|
+
|
35
45
|
generate_dir(initdir) do |dir|
|
36
46
|
generate_catalog_file(dir)
|
37
47
|
generate_sample(dir)
|
38
48
|
generate_images_dir(dir)
|
39
49
|
generate_cover_image(dir)
|
40
|
-
generate_layout(dir)
|
41
50
|
generate_style(dir)
|
42
51
|
generate_texmacro(dir)
|
43
52
|
generate_config(dir)
|
53
|
+
generate_gitignore(dir)
|
44
54
|
generate_locale(dir) if @locale
|
45
55
|
generate_rakefile(dir)
|
46
56
|
generate_gemfile(dir)
|
@@ -50,6 +60,9 @@ module ReVIEW
|
|
50
60
|
end
|
51
61
|
|
52
62
|
def parse_options(args)
|
63
|
+
@port = 18000
|
64
|
+
@bind = '0'
|
65
|
+
|
53
66
|
opts = OptionParser.new
|
54
67
|
opts.version = ReVIEW::VERSION
|
55
68
|
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [option] dirname"
|
@@ -63,18 +76,30 @@ module ReVIEW
|
|
63
76
|
opts.on('-l', '--locale', 'generate locale.yml file.') do
|
64
77
|
@locale = true
|
65
78
|
end
|
66
|
-
opts.on('--latex-template name', 'specify LaTeX template name. (default: review-jsbook)') do |tname|
|
79
|
+
opts.on('-t', '--latex-template name', 'specify LaTeX template name. (default: review-jsbook)') do |tname|
|
67
80
|
@template = tname
|
68
81
|
end
|
69
82
|
opts.on('', '--epub-version VERSION', 'define EPUB version.') do |version|
|
70
83
|
@epub_version = version
|
71
84
|
end
|
85
|
+
opts.on('', '--without-config-comment', "don't include comments in config.yml.") do
|
86
|
+
@without_config_comment = true
|
87
|
+
end
|
72
88
|
opts.on('', '--without-doc', "don't generate doc files.") do
|
73
89
|
@without_doc = true
|
74
90
|
end
|
75
91
|
opts.on('-p', '--package archivefile', 'extract from local or network archive.') do |archive|
|
76
92
|
@archive = archive
|
77
93
|
end
|
94
|
+
opts.on('-w', '--wizard', 'launch Web based layout configuration.') do
|
95
|
+
@webui = true
|
96
|
+
end
|
97
|
+
opts.on('', '--port port', 'port to use for Web based layout configuration. (default: 18000)') do |port|
|
98
|
+
@port = port
|
99
|
+
end
|
100
|
+
opts.on('', '--bind bindaddress', 'address to use for Web based layout configuration. (default: 0 (any))') do |bind|
|
101
|
+
@bind = bind
|
102
|
+
end
|
78
103
|
|
79
104
|
begin
|
80
105
|
opts.parse!(args)
|
@@ -89,9 +114,7 @@ module ReVIEW
|
|
89
114
|
exit 1
|
90
115
|
end
|
91
116
|
|
92
|
-
|
93
|
-
|
94
|
-
initdir
|
117
|
+
File.expand_path(args[0])
|
95
118
|
end
|
96
119
|
|
97
120
|
def generate_dir(dir)
|
@@ -99,7 +122,7 @@ module ReVIEW
|
|
99
122
|
@logger.error "#{dir} already exists."
|
100
123
|
exit 1
|
101
124
|
end
|
102
|
-
FileUtils.mkdir_p
|
125
|
+
FileUtils.mkdir_p(dir)
|
103
126
|
yield dir
|
104
127
|
end
|
105
128
|
|
@@ -109,13 +132,8 @@ module ReVIEW
|
|
109
132
|
end
|
110
133
|
end
|
111
134
|
|
112
|
-
def generate_layout(dir)
|
113
|
-
FileUtils.mkdir_p File.join(dir, 'layouts')
|
114
|
-
end
|
115
|
-
|
116
135
|
def generate_catalog_file(dir)
|
117
|
-
File.
|
118
|
-
file.write <<-EOS
|
136
|
+
File.write(File.join(dir, 'catalog.yml'), <<-EOS)
|
119
137
|
PREDEF:
|
120
138
|
|
121
139
|
CHAPS:
|
@@ -126,7 +144,6 @@ APPENDIX:
|
|
126
144
|
POSTDEF:
|
127
145
|
|
128
146
|
EOS
|
129
|
-
end
|
130
147
|
end
|
131
148
|
|
132
149
|
def generate_images_dir(dir)
|
@@ -154,64 +171,82 @@ EOS
|
|
154
171
|
content.gsub!(/^#.*htmlversion:.*$/, 'htmlversion: 4')
|
155
172
|
end
|
156
173
|
|
157
|
-
if
|
158
|
-
content.gsub!(/^#\s*texdocumentclass:.*$/, %Q(texdocumentclass: ["#{@template}", "#{
|
174
|
+
if @tex_documentclass_opts[@template]
|
175
|
+
content.gsub!(/^#\s*texdocumentclass:.*$/, %Q(texdocumentclass: ["#{@template}", "#{@tex_documentclass_opts[@template]}"]))
|
176
|
+
end
|
177
|
+
|
178
|
+
if @without_config_comment
|
179
|
+
content = content.split("\n").delete_if { |l| l.strip.start_with?('#') || l.strip.empty? }.join("\n")
|
180
|
+
end
|
181
|
+
|
182
|
+
File.open(File.join(dir, 'config.yml'), 'w') { |f| f.write content }
|
183
|
+
if @webui && !@web_result[2].empty?
|
184
|
+
File.open(File.join(dir, 'config-ebook.yml'), 'w') do |f|
|
185
|
+
f.puts <<EOT
|
186
|
+
# for ebook PDF
|
187
|
+
# REVIEW_CONFIG_FILE=config.yml rake pdf
|
188
|
+
inherit: ["config.yml"]
|
189
|
+
# bookname: book-ebook
|
190
|
+
texdocumentclass: ["#{@web_result[0]}", "#{@web_result[2]}"]
|
191
|
+
EOT
|
192
|
+
end
|
159
193
|
end
|
194
|
+
end
|
160
195
|
|
161
|
-
|
196
|
+
def generate_gitignore(dir)
|
197
|
+
FileUtils.cp(File.join(@review_dir, 'samples/sample-book/src/.gitignore'), dir)
|
162
198
|
end
|
163
199
|
|
164
200
|
def generate_style(dir)
|
165
|
-
FileUtils.cp
|
201
|
+
FileUtils.cp(File.join(@review_dir, 'samples/sample-book/src/style.css'), dir)
|
166
202
|
end
|
167
203
|
|
168
204
|
def generate_texmacro(dir)
|
169
205
|
texmacrodir = File.join(dir, 'sty')
|
170
|
-
FileUtils.mkdir_p
|
206
|
+
FileUtils.mkdir_p(texmacrodir)
|
171
207
|
tdir = File.join(@review_dir, 'templates/latex', @template)
|
172
208
|
@logger.error "#{tdir} not found." unless File.exist?(tdir)
|
173
|
-
FileUtils.cp
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
209
|
+
FileUtils.cp(Dir.glob(File.join(tdir, '*.*')), texmacrodir)
|
210
|
+
|
211
|
+
if @template == 'review-jsbook'
|
212
|
+
# provide jsbook from vendor/. current version is 2020/10/09
|
213
|
+
FileUtils.cp(File.join(@review_dir, 'vendor/jsclasses/jsbook.cls'), File.join(texmacrodir, 'jsbook.cls'))
|
214
|
+
# provide gentombow from vendor/. current version is 2019/07/21 v0.9k
|
215
|
+
FileUtils.cp(File.join(@review_dir, 'vendor/gentombow/gentombow.sty'), File.join(texmacrodir, 'gentombow.sty'))
|
216
|
+
end
|
178
217
|
end
|
179
218
|
|
180
219
|
def generate_rakefile(dir)
|
181
|
-
FileUtils.mkdir_p
|
220
|
+
FileUtils.mkdir_p(File.join(dir, 'lib/tasks'))
|
182
221
|
|
183
|
-
File.
|
184
|
-
file.write <<-EOS
|
222
|
+
File.write(File.join(dir, 'Rakefile'), <<-EOS)
|
185
223
|
Dir.glob('lib/tasks/*.rake').sort.each do |file|
|
186
224
|
load(file)
|
187
225
|
end
|
188
226
|
EOS
|
189
|
-
end
|
190
227
|
|
191
228
|
FileUtils.cp(File.join(@review_dir, 'samples/sample-book/src/lib/tasks/review.rake'),
|
192
229
|
File.join(dir, 'lib/tasks/review.rake'))
|
193
230
|
end
|
194
231
|
|
195
232
|
def generate_locale(dir)
|
196
|
-
FileUtils.cp
|
233
|
+
FileUtils.cp(File.join(@review_dir, 'lib/review/i18n.yml'), File.join(dir, 'locale.yml'))
|
197
234
|
end
|
198
235
|
|
199
236
|
def generate_gemfile(dir)
|
200
|
-
File.
|
201
|
-
file.write <<-EOS
|
237
|
+
File.write(File.join(dir, 'Gemfile'), <<-EOS)
|
202
238
|
source 'https://rubygems.org'
|
203
239
|
|
204
240
|
gem 'rake'
|
205
241
|
gem 'review', '#{ReVIEW::VERSION}'
|
206
242
|
EOS
|
207
|
-
end
|
208
243
|
end
|
209
244
|
|
210
245
|
def generate_doc(dir)
|
211
246
|
docdir = File.join(dir, 'doc')
|
212
|
-
FileUtils.mkdir_p
|
247
|
+
FileUtils.mkdir_p(docdir)
|
213
248
|
md_files = Dir.glob(File.join(@review_dir, 'doc/*.md')).map.to_a
|
214
|
-
FileUtils.cp
|
249
|
+
FileUtils.cp(md_files, docdir)
|
215
250
|
end
|
216
251
|
|
217
252
|
def download_and_extract_archive(dir, filename)
|
@@ -251,12 +286,12 @@ EOS
|
|
251
286
|
begin
|
252
287
|
Zip::File.open(filename) do |zip|
|
253
288
|
zip.each do |entry|
|
254
|
-
fname = entry.name.
|
289
|
+
fname = entry.name.tr('\\', '/')
|
255
290
|
if fname =~ /__MACOSX/ || fname =~ /\.DS_Store/
|
256
291
|
next
|
257
292
|
end
|
258
293
|
|
259
|
-
if fname
|
294
|
+
if fname.start_with?('/') || fname =~ /\.\./ # simple fool proof
|
260
295
|
made = nil
|
261
296
|
break
|
262
297
|
end
|
@@ -271,5 +306,53 @@ EOS
|
|
271
306
|
@logger.error "#{originalfilename} seems invalid or broken zip file: #{e.message}"
|
272
307
|
end
|
273
308
|
end
|
309
|
+
|
310
|
+
def start_webui
|
311
|
+
require 'webrick'
|
312
|
+
web_config = {
|
313
|
+
BindAddress: @bind,
|
314
|
+
Port: @port,
|
315
|
+
HTTPVersion: WEBrick::HTTPVersion.new('1.1'),
|
316
|
+
AccessLog: [[File.open(IO::NULL, 'w'), '']]
|
317
|
+
}
|
318
|
+
|
319
|
+
bind_address = (@bind == '0') ? '<thishost>' : @bind
|
320
|
+
puts "Please access http://#{bind_address}:#{web_config[:Port]} from Web browser."
|
321
|
+
begin
|
322
|
+
@web_server = WEBrick::HTTPServer.new(web_config)
|
323
|
+
rescue StandardError => e
|
324
|
+
@logger.error "Error: #{e}"
|
325
|
+
exit 1
|
326
|
+
end
|
327
|
+
|
328
|
+
@web_result = nil
|
329
|
+
web_mounts
|
330
|
+
|
331
|
+
trap(:INT) { @web_server.shutdown }
|
332
|
+
@web_server.start
|
333
|
+
|
334
|
+
# validation
|
335
|
+
if @web_result
|
336
|
+
@web_result.each do |s|
|
337
|
+
if s !~ /\A[a-z0-9=_,.-]*\Z/i
|
338
|
+
@web_result = nil
|
339
|
+
break
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
def web_mounts
|
346
|
+
htmldir = File.join(@review_dir, 'lib', 'review', 'init-web')
|
347
|
+
@web_server.mount('/', WEBrick::HTTPServlet::FileHandler, File.join(htmldir, 'index.html'))
|
348
|
+
@web_server.mount('/review-layout-design.js', WEBrick::HTTPServlet::FileHandler, File.join(htmldir, 'review-layout-design.js'))
|
349
|
+
|
350
|
+
@web_server.mount_proc('/finish') do |req, res|
|
351
|
+
@web_result = [req.query['cls'], req.query['result_print'], req.query['result_ebook']]
|
352
|
+
res.content_type = 'text/html'
|
353
|
+
res.body = File.read(File.join(htmldir, 'finish.html'))
|
354
|
+
@web_server.shutdown
|
355
|
+
end
|
356
|
+
end
|
274
357
|
end
|
275
358
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (c) 2021 Kenshi Muto
|
2
|
+
#
|
3
|
+
# This program is free software.
|
4
|
+
# You can distribute or modify this program under the terms of
|
5
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
6
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
7
|
+
#
|
8
|
+
require 'review/logger'
|
9
|
+
module ReVIEW
|
10
|
+
class LaTeXBox
|
11
|
+
def initialize
|
12
|
+
@logger = ReVIEW.logger
|
13
|
+
end
|
14
|
+
|
15
|
+
def tcbox(config)
|
16
|
+
ret = ''
|
17
|
+
|
18
|
+
%w[column note memo tip info warning important caution notice].each do |name|
|
19
|
+
if config['pdfmaker'].nil? || config['pdfmaker']['boxsetting'].nil? ||
|
20
|
+
config['pdfmaker']['boxsetting'][name].nil? ||
|
21
|
+
config['pdfmaker']['boxsetting'][name]['style'].nil?
|
22
|
+
next
|
23
|
+
end
|
24
|
+
|
25
|
+
options = '[]'
|
26
|
+
options_with_caption = '[]'
|
27
|
+
if config['pdfmaker']['boxsetting'][name]['options']
|
28
|
+
options = "[#{config['pdfmaker']['boxsetting'][name]['options']}]"
|
29
|
+
options_with_caption = options
|
30
|
+
end
|
31
|
+
|
32
|
+
if config['pdfmaker']['boxsetting'][name]['options_with_caption']
|
33
|
+
options_with_caption = "[#{config['pdfmaker']['boxsetting'][name]['options_with_caption']}]"
|
34
|
+
end
|
35
|
+
|
36
|
+
ret << <<EOT
|
37
|
+
\\renewenvironment{review#{name}}[1][]{%
|
38
|
+
\\csdef{rv@tmp@withcaption}{true}
|
39
|
+
\\notblank{##1}{
|
40
|
+
\\begin{rv@#{config['pdfmaker']['boxsetting'][name]['style']}@caption}{##1}#{options_with_caption}
|
41
|
+
}{
|
42
|
+
\\csundef{rv@tmp@withcaption}
|
43
|
+
\\begin{rv@#{config['pdfmaker']['boxsetting'][name]['style']}@nocaption}#{options}
|
44
|
+
}
|
45
|
+
}{
|
46
|
+
\\ifcsdef{rv@tmp@withcaption}{
|
47
|
+
\\end{rv@#{config['pdfmaker']['boxsetting'][name]['style']}@caption}
|
48
|
+
}{
|
49
|
+
\\end{rv@#{config['pdfmaker']['boxsetting'][name]['style']}@nocaption}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
EOT
|
53
|
+
end
|
54
|
+
|
55
|
+
ret
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/review/latexbuilder.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Copyright (c) 2002-2007 Minero Aoki
|
2
2
|
# 2008-2009 Minero Aoki, Kenshi Muto
|
3
|
-
# 2010-
|
3
|
+
# 2010-2021 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi
|
4
4
|
#
|
5
5
|
# This program is free software.
|
6
6
|
# You can distribute or modify this program under the terms of
|
@@ -32,7 +32,6 @@ module ReVIEW
|
|
32
32
|
@blank_needed = false
|
33
33
|
@latex_tsize = nil
|
34
34
|
@tsize = nil
|
35
|
-
@table_caption = nil
|
36
35
|
@cellwidth = nil
|
37
36
|
@ol_num = nil
|
38
37
|
@first_line_num = nil
|
@@ -52,6 +51,7 @@ module ReVIEW
|
|
52
51
|
@index_db = load_idxdb(@book.config['pdfmaker']['makeindex_dic'])
|
53
52
|
end
|
54
53
|
return true unless @book.config['pdfmaker']['makeindex_mecab']
|
54
|
+
|
55
55
|
begin
|
56
56
|
begin
|
57
57
|
require 'MeCab'
|
@@ -61,7 +61,7 @@ module ReVIEW
|
|
61
61
|
require 'nkf'
|
62
62
|
@index_mecab = MeCab::Tagger.new(@book.config['pdfmaker']['makeindex_mecab_opts'])
|
63
63
|
rescue LoadError
|
64
|
-
|
64
|
+
warn 'not found MeCab'
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -101,7 +101,21 @@ module ReVIEW
|
|
101
101
|
if @chapter.is_a?(ReVIEW::Book::Part) && !@book.config.check_version('2', exception: false)
|
102
102
|
puts '\end{reviewpart}'
|
103
103
|
end
|
104
|
-
@output.string
|
104
|
+
solve_nest(@output.string)
|
105
|
+
end
|
106
|
+
|
107
|
+
def solve_nest(s)
|
108
|
+
check_nest
|
109
|
+
s.gsub("\\end{description}\n\n\x01→dl←\x01\n", "\n").
|
110
|
+
gsub("\x01→/dl←\x01", "\\end{description}←END\x01").
|
111
|
+
gsub("\\end{itemize}\n\n\x01→ul←\x01\n", "\n").
|
112
|
+
gsub("\x01→/ul←\x01", "\\end{itemize}←END\x01").
|
113
|
+
gsub("\\end{enumerate}\n\n\x01→ol←\x01\n", "\n").
|
114
|
+
gsub("\x01→/ol←\x01", "\\end{enumerate}←END\x01").
|
115
|
+
gsub("\\end{description}←END\x01\n\n\\begin{description}", '').
|
116
|
+
gsub("\\end{itemize}←END\x01\n\n\\begin{itemize}", '').
|
117
|
+
gsub("\\end{enumerate}←END\x01\n\n\\begin{enumerate}", '').
|
118
|
+
gsub("←END\x01", '')
|
105
119
|
end
|
106
120
|
|
107
121
|
HEADLINE = {
|
@@ -167,10 +181,10 @@ module ReVIEW
|
|
167
181
|
end
|
168
182
|
|
169
183
|
def nodisp_begin(level, _label, caption)
|
170
|
-
if @output.pos
|
171
|
-
blank
|
172
|
-
else
|
184
|
+
if @output.pos == 0
|
173
185
|
puts macro('clearpage')
|
186
|
+
else
|
187
|
+
blank
|
174
188
|
end
|
175
189
|
puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
|
176
190
|
# FIXME: headings
|
@@ -213,7 +227,53 @@ module ReVIEW
|
|
213
227
|
@doc_status[:column] = nil
|
214
228
|
end
|
215
229
|
|
230
|
+
def common_block_begin(type, caption = nil)
|
231
|
+
check_nested_minicolumn
|
232
|
+
if @book.config.check_version('2', exception: false)
|
233
|
+
type = 'minicolumn'
|
234
|
+
end
|
235
|
+
|
236
|
+
@doc_status[:minicolumn] = type
|
237
|
+
print "\\begin{review#{type}}"
|
238
|
+
|
239
|
+
@doc_status[:caption] = true
|
240
|
+
if @book.config.check_version('2', exception: false)
|
241
|
+
puts
|
242
|
+
if caption.present?
|
243
|
+
puts "\\reviewminicolumntitle{#{compile_inline(caption)}}"
|
244
|
+
end
|
245
|
+
else
|
246
|
+
if caption.present?
|
247
|
+
print "[#{compile_inline(caption)}]"
|
248
|
+
end
|
249
|
+
puts
|
250
|
+
end
|
251
|
+
@doc_status[:caption] = nil
|
252
|
+
end
|
253
|
+
|
254
|
+
def common_block_end(type)
|
255
|
+
if @book.config.check_version('2', exception: false)
|
256
|
+
type = 'minicolumn'
|
257
|
+
end
|
258
|
+
|
259
|
+
puts "\\end{review#{type}}"
|
260
|
+
@doc_status[:minicolumn] = nil
|
261
|
+
end
|
262
|
+
|
263
|
+
CAPTION_TITLES.each do |name|
|
264
|
+
class_eval %Q(
|
265
|
+
def #{name}_begin(caption = nil)
|
266
|
+
common_block_begin('#{name}', caption)
|
267
|
+
end
|
268
|
+
|
269
|
+
def #{name}_end
|
270
|
+
common_block_end('#{name}')
|
271
|
+
end
|
272
|
+
), __FILE__, __LINE__ - 8
|
273
|
+
end
|
274
|
+
|
216
275
|
def captionblock(type, lines, caption)
|
276
|
+
check_nested_minicolumn
|
217
277
|
if @book.config.check_version('2', exception: false)
|
218
278
|
type = 'minicolumn'
|
219
279
|
end
|
@@ -257,7 +317,11 @@ module ReVIEW
|
|
257
317
|
end
|
258
318
|
|
259
319
|
def ul_item(lines)
|
260
|
-
str = lines
|
320
|
+
str = join_lines_to_paragraph(lines)
|
321
|
+
unless @book.config['join_lines_by_lang']
|
322
|
+
str = lines.map(&:chomp).join("\n")
|
323
|
+
end
|
324
|
+
|
261
325
|
str.sub!(/\A(\[)/) { '\lbrack{}' }
|
262
326
|
puts '\item ' + str
|
263
327
|
end
|
@@ -271,12 +335,17 @@ module ReVIEW
|
|
271
335
|
blank
|
272
336
|
puts '\begin{enumerate}'
|
273
337
|
return true unless @ol_num
|
338
|
+
|
274
339
|
puts "\\setcounter{enumi}{#{@ol_num - 1}}"
|
275
340
|
@ol_num = nil
|
276
341
|
end
|
277
342
|
|
278
343
|
def ol_item(lines, _num)
|
279
|
-
str = lines
|
344
|
+
str = join_lines_to_paragraph(lines)
|
345
|
+
unless @book.config['join_lines_by_lang']
|
346
|
+
str = lines.map(&:chomp).join("\n")
|
347
|
+
end
|
348
|
+
|
280
349
|
str.sub!(/\A(\[)/) { '\lbrack{}' }
|
281
350
|
puts '\item ' + str
|
282
351
|
end
|
@@ -292,13 +361,16 @@ module ReVIEW
|
|
292
361
|
end
|
293
362
|
|
294
363
|
def dt(str)
|
295
|
-
str.
|
296
|
-
str.sub!(/\]/) { '\rbrack{}' }
|
364
|
+
str = str.gsub('[', '\lbrack{}').gsub(']', '\rbrack{}')
|
297
365
|
puts '\item[' + str + '] \mbox{} \\\\'
|
298
366
|
end
|
299
367
|
|
300
368
|
def dd(lines)
|
301
|
-
|
369
|
+
if @book.config['join_lines_by_lang']
|
370
|
+
puts join_lines_to_paragraph(lines)
|
371
|
+
else
|
372
|
+
puts lines.map(&:chomp).join("\n")
|
373
|
+
end
|
302
374
|
end
|
303
375
|
|
304
376
|
def dl_end
|
@@ -308,8 +380,10 @@ module ReVIEW
|
|
308
380
|
|
309
381
|
def paragraph(lines)
|
310
382
|
blank
|
311
|
-
|
312
|
-
puts
|
383
|
+
if @book.config['join_lines_by_lang']
|
384
|
+
puts join_lines_to_paragraph(lines)
|
385
|
+
else
|
386
|
+
lines.each { |line| puts line }
|
313
387
|
end
|
314
388
|
blank
|
315
389
|
end
|
@@ -319,22 +393,35 @@ module ReVIEW
|
|
319
393
|
end
|
320
394
|
|
321
395
|
def read(lines)
|
322
|
-
latex_block
|
396
|
+
latex_block('quotation', lines)
|
323
397
|
end
|
324
398
|
|
325
399
|
alias_method :lead, :read
|
326
400
|
|
401
|
+
def highlight?
|
402
|
+
@book.config['highlight'] &&
|
403
|
+
@book.config['highlight']['latex']
|
404
|
+
end
|
405
|
+
|
327
406
|
def highlight_listings?
|
328
407
|
@book.config['highlight'] && @book.config['highlight']['latex'] == 'listings'
|
329
408
|
end
|
330
409
|
private :highlight_listings?
|
331
410
|
|
411
|
+
def code_line(_type, line, _idx, _id, _caption, _lang)
|
412
|
+
detab(line) + "\n"
|
413
|
+
end
|
414
|
+
|
415
|
+
def code_line_num(_type, line, first_line_num, idx, _id, _caption, _lang)
|
416
|
+
detab((idx + first_line_num).to_s.rjust(2) + ': ' + line) + "\n"
|
417
|
+
end
|
418
|
+
|
332
419
|
def emlist(lines, caption = nil, lang = nil)
|
333
420
|
blank
|
334
421
|
if highlight_listings?
|
335
422
|
common_code_block_lst(nil, lines, 'reviewemlistlst', 'title', caption, lang)
|
336
423
|
else
|
337
|
-
common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line,
|
424
|
+
common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, idx| code_line('emlist', line, idx, nil, caption, lang) }
|
338
425
|
end
|
339
426
|
end
|
340
427
|
|
@@ -344,7 +431,7 @@ module ReVIEW
|
|
344
431
|
if highlight_listings?
|
345
432
|
common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang, first_line_num: first_line_num)
|
346
433
|
else
|
347
|
-
common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, idx|
|
434
|
+
common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, idx| code_line_num('emlistnum', line, first_line_num, idx, nil, caption, lang) }
|
348
435
|
end
|
349
436
|
end
|
350
437
|
|
@@ -353,7 +440,7 @@ module ReVIEW
|
|
353
440
|
if highlight_listings?
|
354
441
|
common_code_block_lst(id, lines, 'reviewlistlst', 'caption', caption, lang)
|
355
442
|
else
|
356
|
-
common_code_block(id, lines, 'reviewlist', caption, lang) { |line,
|
443
|
+
common_code_block(id, lines, 'reviewlist', caption, lang) { |line, idx| code_line('list', line, idx, id, caption, lang) }
|
357
444
|
end
|
358
445
|
end
|
359
446
|
|
@@ -363,7 +450,7 @@ module ReVIEW
|
|
363
450
|
if highlight_listings?
|
364
451
|
common_code_block_lst(id, lines, 'reviewlistnumlst', 'caption', caption, lang, first_line_num: first_line_num)
|
365
452
|
else
|
366
|
-
common_code_block(id, lines, 'reviewlist', caption, lang) { |line, idx|
|
453
|
+
common_code_block(id, lines, 'reviewlist', caption, lang) { |line, idx| code_line_num('listnum', line, first_line_num, idx, id, caption, lang) }
|
367
454
|
end
|
368
455
|
end
|
369
456
|
|
@@ -372,24 +459,25 @@ module ReVIEW
|
|
372
459
|
common_code_block_lst(nil, lines, 'reviewcmdlst', 'title', caption, lang)
|
373
460
|
else
|
374
461
|
blank
|
375
|
-
common_code_block(nil, lines, 'reviewcmd', caption, lang) { |line,
|
462
|
+
common_code_block(nil, lines, 'reviewcmd', caption, lang) { |line, idx| code_line('cmd', line, idx, nil, caption, lang) }
|
376
463
|
end
|
377
464
|
end
|
378
465
|
|
379
466
|
def common_code_block(id, lines, command, caption, _lang)
|
380
467
|
@doc_status[:caption] = true
|
468
|
+
captionstr = nil
|
381
469
|
unless @book.config.check_version('2', exception: false)
|
382
470
|
puts '\\begin{reviewlistblock}'
|
383
471
|
end
|
384
472
|
if caption.present?
|
385
473
|
if command =~ /emlist/ || command =~ /cmd/ || command =~ /source/
|
386
|
-
|
474
|
+
captionstr = macro(command + 'caption', compile_inline(caption))
|
387
475
|
else
|
388
476
|
begin
|
389
477
|
if get_chap.nil?
|
390
|
-
|
478
|
+
captionstr = macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
|
391
479
|
else
|
392
|
-
|
480
|
+
captionstr = macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
|
393
481
|
end
|
394
482
|
rescue KeyError
|
395
483
|
error "no such list: #{id}"
|
@@ -397,6 +485,11 @@ module ReVIEW
|
|
397
485
|
end
|
398
486
|
end
|
399
487
|
@doc_status[:caption] = nil
|
488
|
+
|
489
|
+
if caption_top?('list') && captionstr
|
490
|
+
puts captionstr
|
491
|
+
end
|
492
|
+
|
400
493
|
body = ''
|
401
494
|
lines.each_with_index do |line, idx|
|
402
495
|
body.concat(yield(line, idx))
|
@@ -404,6 +497,11 @@ module ReVIEW
|
|
404
497
|
puts macro('begin', command)
|
405
498
|
print body
|
406
499
|
puts macro('end', command)
|
500
|
+
|
501
|
+
if !caption_top?('list') && captionstr
|
502
|
+
puts captionstr
|
503
|
+
end
|
504
|
+
|
407
505
|
unless @book.config.check_version('2', exception: false)
|
408
506
|
puts '\\end{reviewlistblock}'
|
409
507
|
end
|
@@ -414,7 +512,7 @@ module ReVIEW
|
|
414
512
|
if title == 'title' && caption.blank? && @book.config.check_version('2', exception: false)
|
415
513
|
print '\vspace{-1.5em}'
|
416
514
|
end
|
417
|
-
body = lines.inject('') { |i, j| i + detab(
|
515
|
+
body = lines.inject('') { |i, j| i + detab(j) + "\n" }
|
418
516
|
args = make_code_block_args(title, caption, lang, first_line_num: first_line_num)
|
419
517
|
puts %Q(\\begin{#{command}}[#{args}])
|
420
518
|
print body
|
@@ -449,17 +547,27 @@ module ReVIEW
|
|
449
547
|
if highlight_listings?
|
450
548
|
common_code_block_lst(nil, lines, 'reviewsourcelst', 'title', caption, lang)
|
451
549
|
else
|
452
|
-
common_code_block(nil, lines, 'reviewsource', caption, lang) { |line,
|
550
|
+
common_code_block(nil, lines, 'reviewsource', caption, lang) { |line, idx| code_line('source', line, idx, nil, caption, lang) }
|
453
551
|
end
|
454
552
|
end
|
455
553
|
|
456
554
|
def image_header(id, caption)
|
457
555
|
end
|
458
556
|
|
557
|
+
def parse_metric(type, metric)
|
558
|
+
s = super(type, metric)
|
559
|
+
if @book.config['pdfmaker']['use_original_image_size'] && s.empty? && !metric.present?
|
560
|
+
return ' ' # pass empty to \reviewincludegraphics
|
561
|
+
end
|
562
|
+
|
563
|
+
s
|
564
|
+
end
|
565
|
+
|
459
566
|
def handle_metric(str)
|
460
|
-
if @book.config['image_scale2width'] && str =~ /\Ascale=([\d.]+)\Z/
|
567
|
+
if @book.config['pdfmaker']['image_scale2width'] && str =~ /\Ascale=([\d.]+)\Z/
|
461
568
|
return "width=#{$1}\\maxwidth"
|
462
569
|
end
|
570
|
+
|
463
571
|
str
|
464
572
|
end
|
465
573
|
|
@@ -467,11 +575,25 @@ module ReVIEW
|
|
467
575
|
array.join(',')
|
468
576
|
end
|
469
577
|
|
470
|
-
def image_image(id, caption, metric)
|
578
|
+
def image_image(id, caption = '', metric = nil)
|
579
|
+
captionstr = nil
|
580
|
+
@doc_status[:caption] = true
|
581
|
+
if @book.config.check_version('2', exception: false)
|
582
|
+
captionstr = macro('caption', compile_inline(caption)) + "\n"
|
583
|
+
else
|
584
|
+
captionstr = macro('reviewimagecaption', compile_inline(caption)) + "\n"
|
585
|
+
end
|
586
|
+
captionstr << macro('label', image_label(id))
|
587
|
+
@doc_status[:caption] = nil
|
588
|
+
|
471
589
|
metrics = parse_metric('latex', metric)
|
472
590
|
# image is always bound here
|
473
591
|
puts "\\begin{reviewimage}%%#{id}"
|
474
592
|
|
593
|
+
if caption_top?('image')
|
594
|
+
puts captionstr
|
595
|
+
end
|
596
|
+
|
475
597
|
command = 'reviewincludegraphics'
|
476
598
|
if @book.config.check_version('2', exception: false)
|
477
599
|
command = 'includegraphics'
|
@@ -482,15 +604,11 @@ module ReVIEW
|
|
482
604
|
else
|
483
605
|
puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}"
|
484
606
|
end
|
485
|
-
@doc_status[:caption] = true
|
486
607
|
|
487
|
-
|
488
|
-
puts
|
489
|
-
else
|
490
|
-
puts macro('reviewimagecaption', compile_inline(caption)) if caption.present?
|
608
|
+
unless caption_top?('image')
|
609
|
+
puts captionstr
|
491
610
|
end
|
492
|
-
|
493
|
-
puts macro('label', image_label(id))
|
611
|
+
|
494
612
|
puts '\end{reviewimage}'
|
495
613
|
end
|
496
614
|
|
@@ -514,7 +632,7 @@ module ReVIEW
|
|
514
632
|
end
|
515
633
|
|
516
634
|
def existence(id)
|
517
|
-
@chapter.
|
635
|
+
@chapter.image_bound?(id) ? 'exist' : 'not exist'
|
518
636
|
end
|
519
637
|
private :existence
|
520
638
|
|
@@ -545,7 +663,8 @@ module ReVIEW
|
|
545
663
|
end
|
546
664
|
private :bib_label
|
547
665
|
|
548
|
-
def column_label(id, chapter =
|
666
|
+
def column_label(id, chapter = nil)
|
667
|
+
chapter ||= @chapter
|
549
668
|
filename = chapter.id
|
550
669
|
num = chapter.column(id).number
|
551
670
|
"column:#{filename}:#{num}"
|
@@ -555,9 +674,21 @@ module ReVIEW
|
|
555
674
|
def indepimage(lines, id, caption = nil, metric = nil)
|
556
675
|
metrics = parse_metric('latex', metric)
|
557
676
|
|
677
|
+
captionstr = nil
|
678
|
+
if caption.present?
|
679
|
+
@doc_status[:caption] = true
|
680
|
+
captionstr = macro('reviewindepimagecaption',
|
681
|
+
%Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)}))
|
682
|
+
@doc_status[:caption] = nil
|
683
|
+
end
|
684
|
+
|
558
685
|
if @chapter.image(id).path
|
559
686
|
puts "\\begin{reviewimage}%%#{id}"
|
560
687
|
|
688
|
+
if caption_top?('image') && captionstr
|
689
|
+
puts captionstr
|
690
|
+
end
|
691
|
+
|
561
692
|
command = 'reviewincludegraphics'
|
562
693
|
if @book.config.check_version('2', exception: false)
|
563
694
|
command = 'includegraphics'
|
@@ -571,18 +702,15 @@ module ReVIEW
|
|
571
702
|
else
|
572
703
|
warn "image not bound: #{id}"
|
573
704
|
puts '\begin{reviewdummyimage}'
|
574
|
-
puts "--[[path = #{id} (#{existence(id)})]]--"
|
705
|
+
puts "--[[path = #{escape(id)} (#{existence(id)})]]--"
|
575
706
|
lines.each do |line|
|
576
707
|
puts detab(line.rstrip)
|
577
708
|
end
|
578
709
|
end
|
579
710
|
|
580
|
-
|
581
|
-
|
582
|
-
puts macro('reviewindepimagecaption',
|
583
|
-
%Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)}))
|
711
|
+
if !caption_top?('image') && captionstr
|
712
|
+
puts captionstr
|
584
713
|
end
|
585
|
-
@doc_status[:caption] = nil
|
586
714
|
|
587
715
|
if @chapter.image(id).path
|
588
716
|
puts '\end{reviewimage}'
|
@@ -594,26 +722,35 @@ module ReVIEW
|
|
594
722
|
alias_method :numberlessimage, :indepimage
|
595
723
|
|
596
724
|
def table(lines, id = nil, caption = nil)
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
# error "too many table separator" if sepidx
|
603
|
-
sepidx ||= idx
|
604
|
-
next
|
725
|
+
if caption.present?
|
726
|
+
if @book.config.check_version('2', exception: false)
|
727
|
+
puts "\\begin{table}[h]%%#{id}"
|
728
|
+
else
|
729
|
+
puts "\\begin{table}%%#{id}"
|
605
730
|
end
|
606
|
-
rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
|
607
731
|
end
|
608
|
-
rows = adjust_n_cols(rows)
|
609
|
-
error 'no rows in the table' if rows.empty?
|
610
732
|
|
733
|
+
sepidx, rows = parse_table_rows(lines)
|
611
734
|
begin
|
612
|
-
|
735
|
+
if caption_top?('table') && caption.present?
|
736
|
+
table_header(id, caption)
|
737
|
+
end
|
613
738
|
rescue KeyError
|
614
739
|
error "no such table: #{id}"
|
615
740
|
end
|
616
741
|
table_begin(rows.first.size)
|
742
|
+
table_rows(sepidx, rows)
|
743
|
+
table_end
|
744
|
+
if caption.present?
|
745
|
+
unless caption_top?('table')
|
746
|
+
table_header(id, caption)
|
747
|
+
end
|
748
|
+
puts '\end{table}'
|
749
|
+
end
|
750
|
+
blank
|
751
|
+
end
|
752
|
+
|
753
|
+
def table_rows(sepidx, rows)
|
617
754
|
if sepidx
|
618
755
|
sepidx.times do
|
619
756
|
cno = -1
|
@@ -640,31 +777,18 @@ module ReVIEW
|
|
640
777
|
end)
|
641
778
|
end
|
642
779
|
end
|
643
|
-
table_end
|
644
780
|
end
|
645
781
|
|
646
782
|
def table_header(id, caption)
|
647
783
|
if id.nil?
|
648
784
|
if caption.present?
|
649
|
-
@table_caption = true
|
650
785
|
@doc_status[:caption] = true
|
651
|
-
if @book.config.check_version('2', exception: false)
|
652
|
-
puts "\\begin{table}[h]%%#{id}"
|
653
|
-
else
|
654
|
-
puts "\\begin{table}%%#{id}"
|
655
|
-
end
|
656
786
|
puts macro('reviewtablecaption*', compile_inline(caption))
|
657
787
|
@doc_status[:caption] = nil
|
658
788
|
end
|
659
789
|
else
|
660
790
|
if caption.present?
|
661
|
-
@table_caption = true
|
662
791
|
@doc_status[:caption] = true
|
663
|
-
if @book.config.check_version('2', exception: false)
|
664
|
-
puts "\\begin{table}[h]%%#{id}"
|
665
|
-
else
|
666
|
-
puts "\\begin{table}%%#{id}"
|
667
|
-
end
|
668
792
|
puts macro('reviewtablecaption', compile_inline(caption))
|
669
793
|
@doc_status[:caption] = nil
|
670
794
|
end
|
@@ -767,12 +891,9 @@ module ReVIEW
|
|
767
891
|
|
768
892
|
def table_end
|
769
893
|
puts macro('end', 'reviewtable')
|
770
|
-
puts '\end{table}' if @table_caption
|
771
|
-
@table_caption = nil
|
772
894
|
@tsize = nil
|
773
895
|
@latex_tsize = nil
|
774
896
|
@cellwidth = nil
|
775
|
-
blank
|
776
897
|
end
|
777
898
|
|
778
899
|
def emtable(lines, caption = nil)
|
@@ -780,19 +901,22 @@ module ReVIEW
|
|
780
901
|
end
|
781
902
|
|
782
903
|
def imgtable(lines, id, caption = nil, metric = nil)
|
783
|
-
unless @chapter.
|
904
|
+
unless @chapter.image_bound?(id)
|
784
905
|
warn "image not bound: #{id}"
|
785
|
-
image_dummy
|
906
|
+
image_dummy(id, caption, lines)
|
786
907
|
return
|
787
908
|
end
|
788
909
|
|
910
|
+
captionstr = nil
|
789
911
|
begin
|
790
912
|
if caption.present?
|
791
|
-
@table_caption = true
|
792
|
-
@doc_status[:caption] = true
|
793
913
|
puts "\\begin{table}[h]%%#{id}"
|
794
|
-
|
914
|
+
@doc_status[:caption] = true
|
915
|
+
captionstr = macro('reviewimgtablecaption', compile_inline(caption))
|
795
916
|
@doc_status[:caption] = nil
|
917
|
+
if caption_top?('table')
|
918
|
+
puts captionstr
|
919
|
+
end
|
796
920
|
end
|
797
921
|
puts macro('label', table_label(id))
|
798
922
|
rescue ReVIEW::KeyError
|
@@ -800,8 +924,12 @@ module ReVIEW
|
|
800
924
|
end
|
801
925
|
imgtable_image(id, caption, metric)
|
802
926
|
|
803
|
-
|
804
|
-
|
927
|
+
if caption.present?
|
928
|
+
unless caption_top?('table')
|
929
|
+
puts captionstr
|
930
|
+
end
|
931
|
+
puts '\end{table}'
|
932
|
+
end
|
805
933
|
blank
|
806
934
|
end
|
807
935
|
|
@@ -824,37 +952,46 @@ module ReVIEW
|
|
824
952
|
end
|
825
953
|
|
826
954
|
def quote(lines)
|
827
|
-
latex_block
|
955
|
+
latex_block('quote', lines)
|
828
956
|
end
|
829
957
|
|
830
958
|
def center(lines)
|
831
|
-
latex_block
|
959
|
+
latex_block('center', lines)
|
832
960
|
end
|
833
961
|
|
834
962
|
alias_method :centering, :center
|
835
963
|
|
836
964
|
def flushright(lines)
|
837
|
-
latex_block
|
965
|
+
latex_block('flushright', lines)
|
838
966
|
end
|
839
967
|
|
840
968
|
def texequation(lines, id = nil, caption = '')
|
841
969
|
blank
|
970
|
+
captionstr = nil
|
842
971
|
|
843
972
|
if id
|
844
973
|
puts macro('begin', 'reviewequationblock')
|
845
974
|
if get_chap.nil?
|
846
|
-
|
975
|
+
captionstr = macro('reviewequationcaption', "#{I18n.t('equation')}#{I18n.t('format_number_header_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
|
847
976
|
else
|
848
|
-
|
977
|
+
captionstr = macro('reviewequationcaption', "#{I18n.t('equation')}#{I18n.t('format_number_header', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
|
849
978
|
end
|
850
979
|
end
|
851
980
|
|
981
|
+
if caption_top?('equation') && captionstr
|
982
|
+
puts captionstr
|
983
|
+
end
|
984
|
+
|
852
985
|
puts macro('begin', 'equation*')
|
853
986
|
lines.each do |line|
|
854
|
-
puts
|
987
|
+
puts line
|
855
988
|
end
|
856
989
|
puts macro('end', 'equation*')
|
857
990
|
|
991
|
+
if !caption_top?('equation') && captionstr
|
992
|
+
puts captionstr
|
993
|
+
end
|
994
|
+
|
858
995
|
if id
|
859
996
|
puts macro('end', 'reviewequationblock')
|
860
997
|
end
|
@@ -874,6 +1011,7 @@ module ReVIEW
|
|
874
1011
|
|
875
1012
|
def direct(lines, fmt)
|
876
1013
|
return unless fmt == 'latex'
|
1014
|
+
|
877
1015
|
lines.each do |line|
|
878
1016
|
puts line
|
879
1017
|
end
|
@@ -881,9 +1019,10 @@ module ReVIEW
|
|
881
1019
|
|
882
1020
|
def comment(lines, comment = nil)
|
883
1021
|
return true unless @book.config['draft']
|
1022
|
+
|
884
1023
|
lines ||= []
|
885
1024
|
unless comment.blank?
|
886
|
-
lines.unshift
|
1025
|
+
lines.unshift(escape(comment))
|
887
1026
|
end
|
888
1027
|
str = lines.join('\par ')
|
889
1028
|
puts macro('pdfcomment', str)
|
@@ -912,7 +1051,7 @@ module ReVIEW
|
|
912
1051
|
def inline_chapref(id)
|
913
1052
|
title = super
|
914
1053
|
if @book.config['chapterlink']
|
915
|
-
"\\
|
1054
|
+
"\\reviewchapref{#{title}}{chap:#{id}}"
|
916
1055
|
else
|
917
1056
|
title
|
918
1057
|
end
|
@@ -923,7 +1062,7 @@ module ReVIEW
|
|
923
1062
|
|
924
1063
|
def inline_chap(id)
|
925
1064
|
if @book.config['chapterlink']
|
926
|
-
"\\
|
1065
|
+
"\\reviewchapref{#{@book.chapter_index.number(id)}}{chap:#{id}}"
|
927
1066
|
else
|
928
1067
|
@book.chapter_index.number(id)
|
929
1068
|
end
|
@@ -935,7 +1074,7 @@ module ReVIEW
|
|
935
1074
|
def inline_title(id)
|
936
1075
|
title = super
|
937
1076
|
if @book.config['chapterlink']
|
938
|
-
"\\
|
1077
|
+
"\\reviewchapref{#{title}}{chap:#{id}}"
|
939
1078
|
else
|
940
1079
|
title
|
941
1080
|
end
|
@@ -995,6 +1134,9 @@ module ReVIEW
|
|
995
1134
|
|
996
1135
|
def footnote(id, content)
|
997
1136
|
if @book.config['footnotetext'] || @foottext[id]
|
1137
|
+
if @doc_status[:column]
|
1138
|
+
warn "//footnote[#{id}] is in the column block. It is recommended to move out of the column block."
|
1139
|
+
end
|
998
1140
|
puts macro("footnotetext[#{@chapter.footnote(id).number}]", compile_inline(content.strip))
|
999
1141
|
end
|
1000
1142
|
end
|
@@ -1002,7 +1144,7 @@ module ReVIEW
|
|
1002
1144
|
def inline_fn(id)
|
1003
1145
|
if @book.config['footnotetext']
|
1004
1146
|
macro("footnotemark[#{@chapter.footnote(id).number}]", '')
|
1005
|
-
elsif @doc_status[:caption] || @doc_status[:table] || @doc_status[:column]
|
1147
|
+
elsif @doc_status[:caption] || @doc_status[:table] || @doc_status[:column] || @doc_status[:dt]
|
1006
1148
|
@foottext[id] = @chapter.footnote(id).number
|
1007
1149
|
macro('protect\\footnotemark', '')
|
1008
1150
|
else
|
@@ -1095,6 +1237,10 @@ module ReVIEW
|
|
1095
1237
|
end
|
1096
1238
|
end
|
1097
1239
|
|
1240
|
+
def inline_ins(str)
|
1241
|
+
macro('reviewinsert', escape(str))
|
1242
|
+
end
|
1243
|
+
|
1098
1244
|
def inline_del(str)
|
1099
1245
|
macro('reviewstrike', escape(str))
|
1100
1246
|
end
|
@@ -1127,7 +1273,7 @@ module ReVIEW
|
|
1127
1273
|
str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
|
1128
1274
|
end
|
1129
1275
|
if @book.config['chapterlink']
|
1130
|
-
anchor = n.
|
1276
|
+
anchor = n.tr('.', '-')
|
1131
1277
|
macro('reviewsecref', str, sec_label(anchor))
|
1132
1278
|
else
|
1133
1279
|
str
|
@@ -1142,7 +1288,7 @@ module ReVIEW
|
|
1142
1288
|
error "unknown column: #{id}"
|
1143
1289
|
end
|
1144
1290
|
|
1145
|
-
def inline_raw(str)
|
1291
|
+
def inline_raw(str) # rubocop:disable Lint/UselessMethodDefinition
|
1146
1292
|
super(str)
|
1147
1293
|
end
|
1148
1294
|
|
@@ -1215,27 +1361,33 @@ module ReVIEW
|
|
1215
1361
|
end
|
1216
1362
|
|
1217
1363
|
def bibpaper_bibpaper(_id, _caption, lines)
|
1218
|
-
|
1364
|
+
if @book.config['join_lines_by_lang']
|
1365
|
+
print split_paragraph(lines).join("\n\n")
|
1366
|
+
else
|
1367
|
+
print split_paragraph(lines).map(&:chomp).join("\n")
|
1368
|
+
end
|
1369
|
+
|
1219
1370
|
puts ''
|
1220
1371
|
end
|
1221
1372
|
|
1222
1373
|
def index(str)
|
1374
|
+
# XXX: mendex/upmendex specific
|
1223
1375
|
sa = str.split('<<>>')
|
1224
1376
|
|
1225
1377
|
sa.map! do |item|
|
1226
1378
|
if @index_db[item]
|
1227
|
-
escape_index(
|
1379
|
+
escape_mendex_key(escape_index(@index_db[item])) + '@' + escape_mendex_display(escape_index(escape(item)))
|
1228
1380
|
else
|
1229
1381
|
if item =~ /\A[[:ascii:]]+\Z/ || @index_mecab.nil?
|
1230
|
-
esc_item = escape_index(escape(item))
|
1231
|
-
if esc_item
|
1232
|
-
"#{escape_index(item)}@#{esc_item}"
|
1233
|
-
else
|
1382
|
+
esc_item = escape_mendex_display(escape_index(escape(item)))
|
1383
|
+
if esc_item == item
|
1234
1384
|
esc_item
|
1385
|
+
else
|
1386
|
+
"#{escape_mendex_key(escape_index(item))}@#{esc_item}"
|
1235
1387
|
end
|
1236
1388
|
else
|
1237
1389
|
yomi = NKF.nkf('-w --hiragana', @index_mecab.parse(item).force_encoding('UTF-8').chomp)
|
1238
|
-
escape_index(
|
1390
|
+
escape_mendex_key(escape_index(yomi)) + '@' + escape_mendex_display(escape_index(escape(item)))
|
1239
1391
|
end
|
1240
1392
|
end
|
1241
1393
|
end
|