review 5.0.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-tex.yml +35 -0
  3. data/.github/workflows/ruby-win.yml +8 -4
  4. data/.github/workflows/ruby.yml +6 -2
  5. data/.rubocop.yml +24 -9
  6. data/NEWS.ja.md +215 -0
  7. data/NEWS.md +215 -1
  8. data/README.md +7 -6
  9. data/Rakefile +7 -2
  10. data/bin/review +2 -4
  11. data/bin/review-catalog-converter +3 -3
  12. data/bin/review-check +6 -8
  13. data/bin/review-checkdep +1 -4
  14. data/bin/review-compile +10 -20
  15. data/bin/review-epub2html +1 -4
  16. data/bin/review-epubmaker +3 -4
  17. data/bin/review-idgxmlmaker +1 -3
  18. data/bin/review-index +11 -5
  19. data/bin/review-init +1 -4
  20. data/bin/review-pdfmaker +1 -3
  21. data/bin/review-preproc +30 -38
  22. data/bin/review-textmaker +1 -3
  23. data/bin/review-update +1 -4
  24. data/bin/review-validate +3 -3
  25. data/bin/review-vol +1 -4
  26. data/bin/review-webmaker +1 -3
  27. data/doc/config.yml.sample +23 -5
  28. data/doc/config.yml.sample-simple +1 -1
  29. data/doc/format.ja.md +49 -12
  30. data/doc/format.md +52 -12
  31. data/doc/quickstart.ja.md +11 -1
  32. data/doc/quickstart.md +11 -2
  33. data/doc/writing_vertical.ja.md +6 -0
  34. data/lib/review/book/base.rb +4 -0
  35. data/lib/review/book/book_unit.rb +15 -2
  36. data/lib/review/book/chapter.rb +3 -0
  37. data/lib/review/book/index.rb +5 -1
  38. data/lib/review/book/volume.rb +1 -0
  39. data/lib/review/builder.rb +90 -54
  40. data/lib/review/call_hook.rb +20 -0
  41. data/lib/review/catalog.rb +2 -0
  42. data/lib/review/compiler.rb +88 -52
  43. data/lib/review/configure.rb +64 -7
  44. data/lib/review/epubmaker/content.rb +113 -0
  45. data/lib/review/epubmaker/epubcommon.rb +372 -0
  46. data/lib/review/epubmaker/epubv2.rb +178 -0
  47. data/lib/review/epubmaker/epubv3.rb +231 -0
  48. data/lib/review/epubmaker/producer.rb +167 -0
  49. data/lib/review/epubmaker/reviewheaderlistener.rb +12 -2
  50. data/lib/review/epubmaker/zip_exporter.rb +84 -0
  51. data/lib/review/epubmaker.rb +114 -129
  52. data/lib/review/exception.rb +13 -0
  53. data/lib/review/htmlbuilder.rb +109 -67
  54. data/lib/review/htmlutils.rb +1 -1
  55. data/lib/review/i18n.rb +1 -0
  56. data/lib/review/i18n.yml +6 -0
  57. data/lib/review/idgxmlbuilder.rb +72 -48
  58. data/lib/review/idgxmlmaker.rb +15 -14
  59. data/lib/review/img_math.rb +239 -0
  60. data/lib/review/index_builder.rb +90 -32
  61. data/lib/review/init.rb +4 -4
  62. data/lib/review/latexbox.rb +58 -0
  63. data/lib/review/latexbuilder.rb +79 -58
  64. data/lib/review/latexutils.rb +9 -1
  65. data/lib/review/lineinput.rb +112 -2
  66. data/lib/review/loggable.rb +27 -0
  67. data/lib/review/logger.rb +89 -2
  68. data/lib/review/makerhelper.rb +7 -206
  69. data/lib/review/markdownbuilder.rb +44 -4
  70. data/lib/review/pdfmaker.rb +70 -51
  71. data/lib/review/plaintextbuilder.rb +20 -11
  72. data/lib/review/preprocessor/directive.rb +35 -0
  73. data/lib/review/preprocessor/line.rb +34 -0
  74. data/lib/review/preprocessor/repository.rb +177 -0
  75. data/lib/review/preprocessor.rb +105 -301
  76. data/lib/review/rstbuilder.rb +13 -4
  77. data/lib/review/sec_counter.rb +1 -0
  78. data/lib/review/template.rb +11 -1
  79. data/lib/review/textmaker.rb +23 -20
  80. data/lib/review/textutils.rb +10 -17
  81. data/lib/review/tocprinter.rb +93 -71
  82. data/lib/review/topbuilder.rb +44 -19
  83. data/lib/review/update.rb +5 -6
  84. data/lib/review/version.rb +1 -1
  85. data/lib/review/volumeprinter.rb +11 -12
  86. data/lib/review/webmaker.rb +31 -27
  87. data/lib/review/webtocprinter.rb +10 -9
  88. data/lib/review/yamlloader.rb +2 -1
  89. data/lib/review.rb +1 -1
  90. data/review.gemspec +5 -3
  91. data/samples/sample-book/src/config-epub2.yml +1 -1
  92. data/samples/sample-book/src/config.yml +1 -1
  93. data/samples/sample-book/src/lib/tasks/review.rake +19 -1
  94. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +2 -1
  95. data/samples/syntax-book/ch01.re +1 -1
  96. data/samples/syntax-book/ch02.re +30 -6
  97. data/samples/syntax-book/ch03.re +1 -1
  98. data/samples/syntax-book/images/img3-2.png +0 -0
  99. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +2 -1
  100. data/templates/html/_colophon.html.erb +23 -0
  101. data/templates/html/_colophon_history.html.erb +9 -0
  102. data/templates/html/_cover.html.erb +10 -0
  103. data/templates/html/_part_body.html.erb +6 -0
  104. data/templates/html/_titlepage.html.erb +20 -0
  105. data/templates/html/layout-html5.html.erb +6 -0
  106. data/templates/html/layout-xhtml1.html.erb +6 -0
  107. data/templates/latex/config.erb +11 -0
  108. data/templates/latex/review-jlreq/review-base.sty +7 -9
  109. data/templates/latex/review-jlreq/review-jlreq.cls +48 -6
  110. data/templates/latex/review-jlreq/review-style.sty +6 -1
  111. data/templates/latex/review-jlreq/review-tcbox.sty +348 -0
  112. data/templates/latex/review-jlreq/reviewmacro.sty +5 -0
  113. data/templates/latex/review-jsbook/review-base.sty +13 -9
  114. data/templates/latex/review-jsbook/review-jsbook.cls +41 -6
  115. data/templates/latex/review-jsbook/review-style.sty +6 -1
  116. data/templates/latex/review-jsbook/review-tcbox.sty +348 -0
  117. data/templates/latex/review-jsbook/reviewmacro.sty +5 -0
  118. data/templates/opf/epubv2.opf.erb +7 -7
  119. data/templates/opf/epubv3.opf.erb +7 -7
  120. data/templates/opf/opf_manifest_epubv2.opf.erb +10 -0
  121. data/templates/opf/opf_manifest_epubv3.opf.erb +10 -0
  122. data/templates/opf/opf_metainfo_epubv2.opf.erb +17 -0
  123. data/templates/opf/opf_metainfo_epubv3.opf.erb +49 -0
  124. data/templates/opf/opf_tocx_epubv2.opf.erb +9 -0
  125. data/templates/opf/opf_tocx_epubv3.opf.erb +17 -0
  126. data/templates/web/html/layout-html5.html.erb +6 -5
  127. data/templates/web/html/layout-xhtml1.html.erb +6 -0
  128. data/test/assets/header_listener.html +35 -0
  129. data/test/assets/img_math/img1.png +0 -0
  130. data/test/assets/img_math/img2.png +0 -0
  131. data/test/assets/img_math/img3.png +0 -0
  132. data/test/assets/syntax_book_index_detail.txt +60 -0
  133. data/test/assets/test_template.tex +7 -1
  134. data/test/assets/test_template_backmatter.tex +7 -1
  135. data/test/run_test.rb +1 -1
  136. data/test/test_book_chapter.rb +27 -4
  137. data/test/test_builder.rb +10 -8
  138. data/test/test_catalog_converter_cmd.rb +1 -1
  139. data/test/test_epub3maker.rb +168 -124
  140. data/test/test_epubmaker.rb +248 -131
  141. data/test/test_epubmaker_cmd.rb +15 -4
  142. data/test/test_helper.rb +5 -4
  143. data/test/test_htmlbuilder.rb +170 -31
  144. data/test/test_idgxmlbuilder.rb +44 -23
  145. data/test/test_idgxmlmaker_cmd.rb +7 -3
  146. data/test/test_img_math.rb +111 -0
  147. data/test/test_index.rb +30 -4
  148. data/test/test_indexbuilder.rb +5 -5
  149. data/test/test_latexbuilder.rb +151 -26
  150. data/test/test_latexbuilder_v2.rb +18 -10
  151. data/test/test_lineinput.rb +20 -93
  152. data/test/test_markdownbuilder.rb +42 -0
  153. data/test/test_pdfmaker.rb +90 -0
  154. data/test/test_pdfmaker_cmd.rb +2 -2
  155. data/test/test_plaintextbuilder.rb +56 -40
  156. data/test/test_preprocessor.rb +188 -1
  157. data/test/test_reviewheaderlistener.rb +49 -0
  158. data/test/test_rstbuilder.rb +13 -0
  159. data/test/test_template.rb +12 -2
  160. data/test/test_textmaker_cmd.rb +5 -1
  161. data/test/test_tocprinter.rb +46 -0
  162. data/test/test_topbuilder.rb +50 -19
  163. data/test/test_update.rb +34 -34
  164. data/test/test_zip_exporter.rb +5 -6
  165. metadata +95 -17
  166. data/lib/epubmaker/content.rb +0 -111
  167. data/lib/epubmaker/epubcommon.rb +0 -449
  168. data/lib/epubmaker/epubv2.rb +0 -142
  169. data/lib/epubmaker/epubv3.rb +0 -235
  170. data/lib/epubmaker/producer.rb +0 -375
  171. data/lib/epubmaker/zip_exporter.rb +0 -81
  172. data/lib/epubmaker.rb +0 -23
  173. data/lib/lineinput.rb +0 -155
@@ -8,7 +8,6 @@
8
8
  require 'pathname'
9
9
  require 'fileutils'
10
10
  require 'yaml'
11
- require 'shellwords'
12
11
 
13
12
  begin
14
13
  require 'cgi/escape'
@@ -18,12 +17,6 @@ end
18
17
 
19
18
  module ReVIEW
20
19
  module MakerHelper
21
- # Return review/bin directory
22
- def bindir
23
- Pathname.new("#{Pathname.new(__FILE__).realpath.dirname}/../../bin").realpath
24
- end
25
- module_function :bindir
26
-
27
20
  def h(str)
28
21
  CGI.escapeHTML(str)
29
22
  end
@@ -51,6 +44,7 @@ module ReVIEW
51
44
  Dir.open(from_dir) do |dir|
52
45
  dir.each do |fname|
53
46
  next if fname =~ /^\./
47
+
54
48
  if FileTest.directory?("#{from_dir}/#{fname}")
55
49
  image_files += copy_images_to_dir("#{from_dir}/#{fname}", "#{to_dir}/#{fname}", options)
56
50
  else
@@ -59,6 +53,7 @@ module ReVIEW
59
53
  is_converted = false
60
54
  (options[:convert] || {}).each do |orig_type, conv_type|
61
55
  next unless /\.#{orig_type}$/ =~ fname
56
+
62
57
  is_converted = system("convert #{from_dir}/#{fname} #{to_dir}/#{fname}.#{conv_type}")
63
58
  image_files << "#{from_dir}/#{fname}.#{conv_type}"
64
59
  end
@@ -66,7 +61,11 @@ module ReVIEW
66
61
  exts = options[:exts] || %w[png gif jpg jpeg svg pdf eps ai tif psd]
67
62
  exts_str = exts.join('|')
68
63
  if !is_converted && fname =~ /\.(#{exts_str})$/i
69
- FileUtils.cp("#{from_dir}/#{fname}", to_dir)
64
+ if options[:use_symlink]
65
+ FileUtils.ln_s(File.realpath("#{from_dir}/#{fname}"), to_dir)
66
+ else
67
+ FileUtils.cp("#{from_dir}/#{fname}", to_dir)
68
+ end
70
69
  image_files << "#{from_dir}/#{fname}"
71
70
  end
72
71
  end
@@ -76,203 +75,5 @@ module ReVIEW
76
75
  image_files
77
76
  end
78
77
  module_function :copy_images_to_dir
79
-
80
- def cleanup_mathimg(path = '_review_math')
81
- math_dir = "./#{@config['imagedir']}/#{path}"
82
- if @config['imgmath'] && Dir.exist?(math_dir)
83
- FileUtils.rm_rf(math_dir)
84
- end
85
- end
86
-
87
- def default_imgmath_preamble
88
- <<-EOB
89
- \\documentclass[uplatex,a3paper,landscape]{jsarticle}
90
- \\usepackage[deluxe,uplatex]{otf}
91
- \\usepackage[T1]{fontenc}
92
- \\usepackage{textcomp}
93
- \\usepackage{lmodern}
94
- \\usepackage[dvipdfmx]{graphicx}
95
- \\usepackage[dvipdfmx,table]{xcolor}
96
- \\usepackage[utf8]{inputenc}
97
- \\usepackage{ascmac}
98
- \\usepackage{float}
99
- \\usepackage{alltt}
100
- \\usepackage{amsmath}
101
- \\usepackage{amssymb}
102
- \\usepackage{amsfonts}
103
- \\usepackage{anyfontsize}
104
- \\usepackage{bm}
105
- \\pagestyle{empty}
106
- % \\setpaperwidth{1000mm}
107
- EOB
108
- end
109
-
110
- def make_math_images(math_dir)
111
- fontsize = @config['imgmath_options']['fontsize'].to_f
112
- lineheight = @config['imgmath_options']['lineheight'].to_f
113
-
114
- texsrc = default_imgmath_preamble
115
- if @config['imgmath_options']['preamble_file'] && File.readable?(@config['imgmath_options']['preamble_file'])
116
- texsrc = File.read(@config['imgmath_options']['preamble_file'])
117
- end
118
-
119
- texsrc << <<-EOB
120
- \\begin{document}
121
- \\fontsize{#{fontsize}}{#{lineheight}}\\selectfont
122
- \\input{__IMGMATH_BODY__}
123
- \\end{document}
124
- EOB
125
-
126
- hashes = File.readlines(File.join(math_dir, '__IMGMATH_BODY__.map')).sort.uniq
127
- File.write(File.join(math_dir, '__IMGMATH_BODY__.map'), hashes.join)
128
-
129
- File.open(File.join(math_dir, '__IMGMATH_BODY__.tex'), 'w') do |f|
130
- File.open(File.join(math_dir, '__IMGMATH_BODY__.map')) do |map|
131
- map.each_line do |l|
132
- l.chomp!
133
- f.puts "% #{l}"
134
- f.puts File.read(File.join(math_dir, "__IMGMATH_BODY__#{l}.tex"))
135
- File.unlink(File.join(math_dir, "__IMGMATH_BODY__#{l}.tex"))
136
- f.puts '\\clearpage'
137
- f.puts
138
- end
139
- end
140
- end
141
-
142
- math_dir = File.realpath(math_dir)
143
- Dir.mktmpdir do |tmpdir|
144
- FileUtils.cp([File.join(math_dir, '__IMGMATH_BODY__.tex'),
145
- File.join(math_dir, '__IMGMATH_BODY__.map')],
146
- tmpdir)
147
- tex_path = File.join(tmpdir, '__IMGMATH__.tex')
148
- File.write(tex_path, texsrc)
149
-
150
- begin
151
- case @config['imgmath_options']['converter']
152
- when 'pdfcrop'
153
- make_math_images_pdfcrop(tmpdir, tex_path, math_dir)
154
- when 'dvipng'
155
- make_math_images_dvipng(tmpdir, tex_path, math_dir)
156
- else
157
- error "unknown math converter error. imgmath_options/converter parameter should be 'pdfcrop' or 'dvipng'."
158
- end
159
- rescue CompileError
160
- FileUtils.cp([tex_path,
161
- File.join(File.dirname(tex_path), '__IMGMATH__.log')],
162
- math_dir)
163
- error "LaTeX math compile error. See #{math_dir}/__IMGMATH__.log for details."
164
- end
165
- end
166
- FileUtils.rm_f([File.join(math_dir, '__IMGMATH_BODY__.tex'),
167
- File.join(math_dir, '__IMGMATH_BODY__.map')])
168
- end
169
- module_function :make_math_images
170
-
171
- def make_math_images_pdfcrop(dir, tex_path, math_dir)
172
- # rubocop:disable Metrics/BlockLength
173
- Dir.chdir(dir) do
174
- dvi_path = '__IMGMATH__.dvi'
175
- pdf_path = '__IMGMATH__.pdf'
176
- out, status = Open3.capture2e(*[@config['texcommand'], @config['texoptions'].shellsplit, tex_path].flatten.compact)
177
- if !status.success? || (!File.exist?(dvi_path) && !File.exist?(pdf_path))
178
- raise CompileError
179
- end
180
- if File.exist?(dvi_path)
181
- out, status = Open3.capture2e(*[@config['dvicommand'], @config['dvioptions'].shellsplit, dvi_path].flatten.compact)
182
- if !status.success? || !File.exist?(pdf_path)
183
- warn "error in #{@config['dvicommand']}. Error log:\n#{out}"
184
- raise CompileError
185
- end
186
- end
187
- args = @config['imgmath_options']['pdfcrop_cmd'].shellsplit
188
- args.map! do |m|
189
- m.sub('%i', pdf_path).
190
- sub('%o', '__IMGMATH__pdfcrop.pdf')
191
- end
192
- out, status = Open3.capture2e(*args)
193
- unless status.success?
194
- warn "error in pdfcrop. Error log:\n#{out}"
195
- raise CompileError
196
- end
197
- pdf_path = '__IMGMATH__pdfcrop.pdf'
198
- pdf_path2 = pdf_path
199
-
200
- File.open('__IMGMATH_BODY__.map') do |f|
201
- page = 0
202
- f.each_line do |key|
203
- page += 1
204
- key.chomp!
205
- if File.exist?(File.join(math_dir, "_gen_#{key}.#{@config['imgmath_options']['format']}"))
206
- # made already
207
- next
208
- end
209
-
210
- if @config['imgmath_options']['extract_singlepage']
211
- # if extract_singlepage = true, split each page
212
- args = @config['imgmath_options']['pdfextract_cmd'].shellsplit
213
-
214
- args.map! do |m|
215
- m.sub('%i', pdf_path).
216
- sub('%o', "__IMGMATH__pdfcrop_p#{page}.pdf").
217
- sub('%O', "__IMGMATH__pdfcrop_p#{page}").
218
- sub('%p', page.to_s)
219
- end
220
- out, status = Open3.capture2e(*args)
221
- unless status.success?
222
- warn "error in pdf extracting. Error log:\n#{out}"
223
- raise CompileError
224
- end
225
-
226
- pdf_path2 = "__IMGMATH__pdfcrop_p#{page}.pdf"
227
- end
228
-
229
- args = @config['imgmath_options']['pdfcrop_pixelize_cmd'].shellsplit
230
- args.map! do |m|
231
- m.sub('%i', pdf_path2).
232
- sub('%t', @config['imgmath_options']['format']).
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 pdf pixelizing. Error log:\n#{out}"
240
- raise CompileError
241
- end
242
- end
243
- end
244
- end
245
- # rubocop:enable Metrics/BlockLength
246
- end
247
-
248
- def make_math_images_dvipng(dir, tex_path, math_dir)
249
- Dir.chdir(dir) do
250
- dvi_path = '__IMGMATH__.dvi'
251
- out, status = Open3.capture2e(*[@config['texcommand'], @config['texoptions'].shellsplit, tex_path].flatten.compact)
252
- if !status.success? || !File.exist?(dvi_path)
253
- raise CompileError
254
- end
255
-
256
- File.open('__IMGMATH_BODY__.map') do |f|
257
- page = 0
258
- f.each_line do |key|
259
- page += 1
260
- key.chomp!
261
- args = @config['imgmath_options']['dvipng_cmd'].shellsplit
262
- args.map! do |m|
263
- m.sub('%i', dvi_path).
264
- sub('%o', File.join(math_dir, "_gen_#{key}.#{@config['imgmath_options']['format']}")).
265
- sub('%O', File.join(math_dir, "_gen_#{key}")).
266
- sub('%p', page.to_s)
267
- end
268
- out, status = Open3.capture2e(*args)
269
- unless status.success?
270
- warn "error in dvipng. Error log:\n#{out}"
271
- raise CompileError
272
- end
273
- end
274
- end
275
- end
276
- end
277
78
  end
278
79
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013-2019 KADO Masanori, Masayoshi Takahashi, Kenshi Muto
1
+ # Copyright (c) 2013-2021 KADO Masanori, Masayoshi Takahashi, Kenshi Muto
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -18,6 +18,7 @@ module ReVIEW
18
18
  end
19
19
 
20
20
  def builder_init_file
21
+ super
21
22
  @noindent = nil
22
23
  @blank_seen = nil
23
24
  @ul_indent = 0
@@ -97,7 +98,7 @@ module ReVIEW
97
98
  end
98
99
 
99
100
  def ul_item_begin(lines)
100
- puts ' ' * (@ul_indent - 1) + '* ' + join_lines_to_paragraph(lines)
101
+ puts (' ' * (@ul_indent - 1)) + '* ' + join_lines_to_paragraph(lines)
101
102
  end
102
103
 
103
104
  def ul_item_end
@@ -224,6 +225,14 @@ module ReVIEW
224
225
  "<u>#{str}</u>"
225
226
  end
226
227
 
228
+ def inline_ins(str)
229
+ "<ins>#{str}</ins>"
230
+ end
231
+
232
+ def inline_del(str)
233
+ "~~#{str}~~"
234
+ end
235
+
227
236
  def image_image(id, caption, _metric)
228
237
  blank
229
238
  puts "![#{compile_inline(caption)}](#{@chapter.image(id).path.sub(%r{\A\./}, '')})"
@@ -237,13 +246,35 @@ module ReVIEW
237
246
  def inline_img(id)
238
247
  "#{I18n.t('image')}#{@chapter.image(id).number}"
239
248
  rescue KeyError
240
- error "unknown image: #{id}"
249
+ app_error "unknown image: #{id}"
241
250
  end
242
251
 
243
252
  def inline_dtp(str)
244
253
  "<!-- DTP:#{str} -->"
245
254
  end
246
255
 
256
+ def inline_hd_chap(chap, id)
257
+ n = chap.headline_index.number(id)
258
+ if n.present? && chap.number && over_secnolevel?(n)
259
+ str = I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
260
+ else
261
+ str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
262
+ end
263
+ if @book.config['chapterlink']
264
+ if @chapter == chap
265
+ anchor = 'h' + n.tr('.', '-')
266
+ %Q(<a href="##{anchor}">#{str}</a>)
267
+ else
268
+ warn 'MARKDOWNBuilder does not support links to other chapters', location: location
269
+ str
270
+ end
271
+ else
272
+ str
273
+ end
274
+ rescue KeyError
275
+ app_error "unknown headline: #{id}"
276
+ end
277
+
247
278
  def indepimage(_lines, id, caption = '', _metric = nil)
248
279
  blank
249
280
  puts "![#{compile_inline(caption)}](#{@chapter.image(id).path.sub(%r{\A\./}, '')})"
@@ -330,6 +361,14 @@ module ReVIEW
330
361
  "[^#{id}]"
331
362
  end
332
363
 
364
+ def inline_endnote(id)
365
+ "<sup>#{I18n.t('html_endnote_refmark', @chapter.endnote(id).number)}</sup>"
366
+ end
367
+
368
+ def endnote_item(id)
369
+ puts "#{I18n.t('html_endnote_textmark', @chapter.endnote(id).number)}#{compile_inline(@chapter.endnote(id).content)}"
370
+ end
371
+
333
372
  def inline_br(_str)
334
373
  "\n"
335
374
  end
@@ -358,6 +397,7 @@ module ReVIEW
358
397
 
359
398
  def comment(lines, comment = nil)
360
399
  return unless @book.config['draft']
400
+
361
401
  lines ||= []
362
402
  unless comment.blank?
363
403
  lines.unshift(comment)
@@ -370,7 +410,7 @@ module ReVIEW
370
410
  begin
371
411
  "![](#{@chapter.image(id).path.sub(%r{\A\./}, '')})"
372
412
  rescue
373
- warn "image not bound: #{id}"
413
+ warn "image not bound: #{id}", location: location
374
414
  %Q(<pre>missing image: #{id}</pre>)
375
415
  end
376
416
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2020 Kenshi Muto and Masayoshi Takahashi
1
+ # Copyright (c) 2010-2021 Kenshi Muto and Masayoshi Takahashi
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -22,11 +22,15 @@ require 'review/yamlloader'
22
22
  require 'review/version'
23
23
  require 'review/makerhelper'
24
24
  require 'review/template'
25
+ require 'review/latexbox'
26
+ require 'review/call_hook'
27
+ require 'review/loggable'
25
28
 
26
29
  module ReVIEW
27
30
  class PDFMaker
28
- include FileUtils
29
31
  include ReVIEW::LaTeXUtils
32
+ include Loggable
33
+ include ReVIEW::CallHook
30
34
 
31
35
  attr_accessor :config, :basedir
32
36
 
@@ -35,13 +39,14 @@ module ReVIEW
35
39
  @logger = ReVIEW.logger
36
40
  @input_files = Hash.new { |h, key| h[key] = '' }
37
41
  @mastertex = '__REVIEW_BOOK__'
42
+ @compile_errors = nil
38
43
  end
39
44
 
40
45
  def system_with_info(*args)
41
46
  @logger.info args.join(' ')
42
47
  out, status = Open3.capture2e(*args)
43
48
  unless status.success?
44
- @logger.error "execution error\n\nError log:\n" + out
49
+ error "execution error\n\nError log:\n#{out}"
45
50
  end
46
51
  end
47
52
 
@@ -49,19 +54,10 @@ module ReVIEW
49
54
  @logger.info args.join(' ')
50
55
  out, status = Open3.capture2e(*args)
51
56
  unless status.success?
52
- error "failed to run command: #{args.join(' ')}\n\nError log:\n" + out
57
+ error! "failed to run command: #{args.join(' ')}\n\nError log:\n#{out}"
53
58
  end
54
59
  end
55
60
 
56
- def error(msg)
57
- @logger.error msg
58
- exit 1
59
- end
60
-
61
- def warn(msg)
62
- @logger.warn msg
63
- end
64
-
65
61
  def pdf_filepath
66
62
  File.join(@basedir, @config['bookname'] + '.pdf')
67
63
  end
@@ -89,7 +85,7 @@ module ReVIEW
89
85
  if ignore_errors
90
86
  @logger.info 'compile error, but try to generate PDF file'
91
87
  else
92
- error 'compile error, No PDF file output.'
88
+ error! 'compile error, No PDF file output.'
93
89
  end
94
90
  end
95
91
 
@@ -123,7 +119,7 @@ module ReVIEW
123
119
 
124
120
  def execute(*args)
125
121
  cmd_config, yamlfile = parse_opts(args)
126
- error "#{yamlfile} not found." unless File.exist?(yamlfile)
122
+ error! "#{yamlfile} not found." unless File.exist?(yamlfile)
127
123
 
128
124
  @config = ReVIEW::Configure.create(maker: 'pdfmaker',
129
125
  yamlfile: yamlfile,
@@ -151,7 +147,8 @@ module ReVIEW
151
147
  generate_pdf
152
148
  rescue ApplicationError => e
153
149
  raise if @config['debug']
154
- error(e.message)
150
+
151
+ error! e.message
155
152
  end
156
153
  end
157
154
 
@@ -198,7 +195,7 @@ module ReVIEW
198
195
  Dir.chdir(@path) do
199
196
  File.open("./#{@mastertex}.tex", 'wb') { |f| f.write template }
200
197
 
201
- call_hook('hook_beforetexcompile')
198
+ call_hook('hook_beforetexcompile', Dir.pwd, @basedir, base_dir: @basedir)
202
199
 
203
200
  ## do compile
204
201
  if ENV['REVIEW_SAFE_MODE'].to_i & 4 > 0
@@ -213,7 +210,7 @@ module ReVIEW
213
210
  makeindex_dic = ReVIEW::Configure.values['pdfmaker']['makeindex_dic']
214
211
  else
215
212
  unless @config['texcommand'].present?
216
- error "texcommand isn't defined."
213
+ error! "texcommand isn't defined."
217
214
  end
218
215
  texcommand = @config['texcommand']
219
216
  dvicommand = @config['dvicommand']
@@ -241,32 +238,32 @@ module ReVIEW
241
238
  system_or_raise(*[texcommand, texoptions, "#{@mastertex}.tex"].flatten.compact)
242
239
  end
243
240
 
244
- call_hook('hook_beforemakeindex')
241
+ call_hook('hook_beforemakeindex', Dir.pwd, @basedir, base_dir: @basedir)
245
242
  if @config['pdfmaker']['makeindex'] && File.size?("#{@mastertex}.idx")
246
243
  system_or_raise(*[makeindex_command, makeindex_options, @mastertex].flatten.compact)
244
+ call_hook('hook_aftermakeindex', Dir.pwd, @basedir, base_dir: @basedir)
247
245
  system_or_raise(*[texcommand, texoptions, "#{@mastertex}.tex"].flatten.compact)
248
246
  end
249
- call_hook('hook_aftermakeindex')
250
247
 
251
248
  system_or_raise(*[texcommand, texoptions, "#{@mastertex}.tex"].flatten.compact)
252
- call_hook('hook_aftertexcompile')
249
+ call_hook('hook_aftertexcompile', Dir.pwd, @basedir, base_dir: @basedir)
253
250
 
254
251
  if File.exist?("#{@mastertex}.dvi") && dvicommand.present?
255
252
  system_or_raise(*[dvicommand, dvioptions, "#{@mastertex}.dvi"].flatten.compact)
256
- call_hook('hook_afterdvipdf')
253
+ call_hook('hook_afterdvipdf', Dir.pwd, @basedir, base_dir: @basedir)
257
254
  end
258
255
  end
259
256
  end
260
257
 
261
258
  def generate_pdf
262
259
  remove_old_file
263
- erb_config
264
260
  @path = build_path
265
261
  begin
266
262
  @compile_errors = nil
267
263
 
268
264
  book = ReVIEW::Book::Base.new(@basedir, config: @config)
269
265
  @converter = ReVIEW::Converter.new(book, ReVIEW::LATEXBuilder.new)
266
+ erb_config
270
267
 
271
268
  @input_files = make_input_files(book)
272
269
 
@@ -276,6 +273,9 @@ module ReVIEW
276
273
  @config['usepackage'] = ''
277
274
  @config['usepackage'] = "\\usepackage{#{@config['texstyle']}}" if @config['texstyle']
278
275
 
276
+ if @config['pdfmaker']['use_symlink']
277
+ logger.info 'use symlink'
278
+ end
279
279
  copy_images(@config['imagedir'], File.join(@path, @config['imagedir']))
280
280
  copy_sty(File.join(Dir.pwd, 'sty'), @path)
281
281
  copy_sty(File.join(Dir.pwd, 'sty'), @path, 'fd')
@@ -287,8 +287,9 @@ module ReVIEW
287
287
  build_pdf
288
288
 
289
289
  FileUtils.cp(File.join(@path, "#{@mastertex}.pdf"), pdf_filepath)
290
+ @logger.success("built #{File.basename(pdf_filepath)}")
290
291
  ensure
291
- remove_entry_secure(@path) unless @config['debug']
292
+ FileUtils.remove_entry_secure(@path) unless @config['debug']
292
293
  end
293
294
  end
294
295
 
@@ -298,8 +299,8 @@ module ReVIEW
298
299
  @converter.convert(filename + '.re', File.join(@path, filename + '.tex'))
299
300
  rescue => e
300
301
  @compile_errors = true
301
- warn "compile error in #{filename}.tex (#{e.class})"
302
- warn e.message
302
+ error "compile error in #{filename}.tex (#{e.class})"
303
+ error e.message
303
304
  end
304
305
  end
305
306
 
@@ -307,16 +308,26 @@ module ReVIEW
307
308
  #
308
309
  def copy_images(from, to)
309
310
  return unless File.exist?(from)
311
+
310
312
  Dir.mkdir(to)
311
- ReVIEW::MakerHelper.copy_images_to_dir(from, to)
313
+ if @config['pdfmaker']['use_symlink']
314
+ ReVIEW::MakerHelper.copy_images_to_dir(from, to, use_symlink: true)
315
+ else
316
+ ReVIEW::MakerHelper.copy_images_to_dir(from, to)
317
+ end
312
318
  end
313
319
 
314
320
  def make_custom_page(file)
321
+ if file.nil?
322
+ return nil
323
+ end
324
+
315
325
  file_sty = file.to_s.sub(/\.[^.]+\Z/, '.tex')
316
326
  if File.exist?(file_sty)
317
- return File.read(file_sty)
327
+ File.read(file_sty)
328
+ else
329
+ warn "File #{file_sty} is not found."
318
330
  end
319
- nil
320
331
  end
321
332
 
322
333
  def join_with_separator(value, sep)
@@ -435,6 +446,10 @@ module ReVIEW
435
446
  end
436
447
  end
437
448
 
449
+ if @config['coverimage'] && !File.exist?(File.join(@config['imagedir'], @config['coverimage']))
450
+ raise ReVIEW::ConfigError, "coverimage #{@config['coverimage']} is not found."
451
+ end
452
+
438
453
  @locale_latex = {}
439
454
  part_tuple = I18n.get('part').split(/%[A-Za-z]{1,3}/, 2)
440
455
  chapter_tuple = I18n.get('chapter').split(/%[A-Za-z]{1,3}/, 2)
@@ -445,36 +460,47 @@ module ReVIEW
445
460
  @locale_latex['postchaptername'] = chapter_tuple[1].to_s
446
461
  @locale_latex['preappendixname'] = appendix_tuple[0].to_s
447
462
  @locale_latex['postappendixname'] = appendix_tuple[1].to_s
448
- end
449
463
 
450
- def erb_content(file)
451
- @texcompiler = File.basename(@config['texcommand'], '.*')
452
- erb = ReVIEW::Template.load(file, '-')
453
- @logger.debug("erb processes #{File.basename(file)}") if @config['debug']
454
- erb.result(binding)
464
+ if @config['pdfmaker']['boxsetting']
465
+ begin
466
+ @boxsetting = ReVIEW::LaTeXBox.new.tcbox(@config)
467
+ rescue ReVIEW::ConfigError => e
468
+ error! e
469
+ end
470
+ end
455
471
  end
456
472
 
457
473
  def latex_config
458
- result = erb_content(File.expand_path('./latex/config.erb', ReVIEW::Template::TEMPLATE_DIR))
474
+ result = ReVIEW::Template.generate(path: './latex/config.erb', mode: '-', binding: binding)
459
475
  local_config_file = File.join(@basedir, 'layouts', 'config-local.tex.erb')
460
476
  if File.exist?(local_config_file)
461
477
  result << "%% BEGIN: config-local.tex.erb\n"
462
- result << erb_content(local_config_file)
478
+ result << ReVIEW::Template.generate(path: 'layouts/config-local.tex.erb', mode: '-', binding: binding, template_dir: @basedir)
463
479
  result << "%% END: config-local.tex.erb\n"
464
480
  end
465
481
  result
466
482
  end
467
483
 
468
484
  def template_content
469
- template = File.expand_path('./latex/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
485
+ template_dir = ReVIEW::Template::TEMPLATE_DIR
470
486
  if @config.check_version('2', exception: false)
471
- template = File.expand_path('./latex-compat2/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
487
+ template_path = './latex-compat2/layout.tex.erb'
488
+ else
489
+ template_path = './latex/layout.tex.erb'
472
490
  end
473
491
  layout_file = File.join(@basedir, 'layouts', 'layout.tex.erb')
474
492
  if File.exist?(layout_file)
475
- template = layout_file
493
+ template_dir = @basedir
494
+ template_path = 'layouts/layout.tex.erb'
495
+ end
496
+ ReVIEW::Template.generate(path: template_path, mode: '-', binding: binding, template_dir: template_dir)
497
+ rescue => e
498
+ if defined?(e.full_message)
499
+ error! "template or configuration error: #{e.full_message(highlight: false)}"
500
+ else
501
+ # <= Ruby 2.4
502
+ error! "template or configuration error: #{e.message}"
476
503
  end
477
- erb_content(template)
478
504
  end
479
505
 
480
506
  def copy_sty(dirname, copybase, extname = 'sty')
@@ -486,26 +512,19 @@ module ReVIEW
486
512
  Dir.open(dirname) do |dir|
487
513
  dir.sort.each do |fname|
488
514
  next unless File.extname(fname).downcase == '.' + extname
515
+
489
516
  FileUtils.mkdir_p(copybase) unless Dir.exist?(copybase)
490
517
  if extname == 'erb'
491
518
  File.open(File.join(copybase, fname.sub(/\.erb\Z/, '')), 'w') do |f|
492
519
  f.print erb_content(File.join(dirname, fname))
493
520
  end
521
+ elsif @config['pdfmaker']['use_symlink']
522
+ FileUtils.ln_s(File.join(dirname, fname), copybase)
494
523
  else
495
524
  FileUtils.cp(File.join(dirname, fname), copybase)
496
525
  end
497
526
  end
498
527
  end
499
528
  end
500
-
501
- def call_hook(hookname)
502
- return if !@config['pdfmaker'].is_a?(Hash) || @config['pdfmaker'][hookname].nil?
503
- hook = File.absolute_path(@config['pdfmaker'][hookname], @basedir)
504
- if ENV['REVIEW_SAFE_MODE'].to_i & 1 > 0
505
- warn 'hook configuration is prohibited in safe mode. ignored.'
506
- else
507
- system_or_raise(hook, Dir.pwd, @basedir)
508
- end
509
- end
510
529
  end
511
530
  end