review 2.0.0.beta1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +66 -1
- data/.rubocop_todo.yml +617 -0
- data/.travis.yml +16 -1
- data/ChangeLog +48 -0
- data/Dockerfile +22 -0
- data/Gemfile +0 -1
- data/README.md +97 -0
- data/Rakefile +10 -11
- data/appveyor.yml +9 -0
- data/bin/review +46 -0
- data/bin/review-check +8 -21
- data/bin/review-compile +26 -43
- data/bin/review-index +9 -22
- data/bin/review-init +21 -25
- data/bin/review-preproc +9 -13
- data/bin/review-validate +1 -1
- data/bin/review-vol +3 -17
- data/bin/review-webmaker +15 -0
- data/doc/NEWS.ja.md +534 -0
- data/doc/NEWS.md +538 -0
- data/doc/catalog.ja.md +10 -18
- data/doc/catalog.md +5 -9
- data/doc/config.yml.sample +319 -0
- data/doc/customize_epub.ja.md +42 -0
- data/doc/format.ja.md +320 -288
- data/doc/format.md +277 -170
- data/doc/format_idg.ja.md +82 -175
- data/doc/pdfmaker.ja.md +61 -0
- data/doc/pdfmaker.md +65 -0
- data/doc/quickstart.ja.md +88 -98
- data/doc/quickstart.md +72 -110
- data/doc/sample.css +41 -0
- data/doc/writing_vertical.ja.md +55 -0
- data/doc/writing_vertical.md +5 -0
- data/lib/epubmaker/content.rb +3 -3
- data/lib/epubmaker/epubcommon.rb +173 -145
- data/lib/epubmaker/epubv2.rb +24 -77
- data/lib/epubmaker/epubv3.rb +72 -73
- data/lib/epubmaker/producer.rb +54 -30
- data/lib/lineinput.rb +48 -0
- data/lib/review/book.rb +0 -1
- data/lib/review/book/base.rb +47 -27
- data/lib/review/book/chapter.rb +48 -19
- data/lib/review/book/compilable.rb +10 -14
- data/lib/review/book/index.rb +10 -19
- data/lib/review/book/page_metric.rb +0 -10
- data/lib/review/book/part.rb +17 -3
- data/lib/review/builder.rb +84 -68
- data/lib/review/catalog.rb +5 -1
- data/lib/review/compiler.rb +327 -4657
- data/lib/review/configure.rb +84 -10
- data/lib/review/converter.rb +28 -0
- data/lib/review/epubbuilder.rb +1 -1
- data/lib/review/epubmaker.rb +142 -158
- data/lib/review/ewbbuilder.rb +5 -5
- data/lib/review/exception.rb +1 -1
- data/lib/review/extentions.rb +1 -1
- data/lib/review/extentions/hash.rb +15 -0
- data/lib/review/extentions/string.rb +2 -1
- data/lib/review/htmlbuilder.rb +364 -348
- data/lib/review/htmltoc.rb +44 -0
- data/lib/review/htmlutils.rb +12 -6
- data/lib/review/i18n.rb +78 -6
- data/lib/review/i18n.yml +7 -4
- data/lib/review/idgxmlbuilder.rb +226 -267
- data/lib/review/latexbuilder.rb +281 -274
- data/lib/review/latexutils.rb +56 -49
- data/lib/review/makerhelper.rb +8 -4
- data/lib/review/markdownbuilder.rb +80 -124
- data/lib/review/pdfmaker.rb +197 -138
- data/lib/review/preprocessor.rb +16 -67
- data/lib/review/template.rb +24 -0
- data/lib/review/textbuilder.rb +1 -1
- data/lib/review/textutils.rb +18 -24
- data/lib/review/tocparser.rb +51 -106
- data/lib/review/tocprinter.rb +61 -117
- data/lib/review/topbuilder.rb +119 -126
- data/lib/review/unfold.rb +2 -2
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +302 -0
- data/lib/review/webtocprinter.rb +48 -0
- data/lib/review/yamlloader.rb +47 -0
- data/review.gemspec +3 -3
- data/templates/html/layout-html5.html.erb +17 -0
- data/templates/html/layout-xhtml1.html.erb +20 -0
- data/{lib/review → templates/latex}/layout.tex.erb +107 -115
- data/templates/ncx/epubv2.ncx.erb +11 -0
- data/templates/opf/epubv2.opf.erb +21 -0
- data/templates/opf/epubv3.opf.erb +18 -0
- data/templates/web/html/layout-html5.html.erb +56 -0
- data/templates/web/html/layout-xhtml1.html.erb +20 -0
- data/templates/xml/container.xml.erb +6 -0
- data/test/assets/test.xml.erb +3 -0
- data/test/assets/test_template.tex +28 -71
- data/test/assets/test_template_backmatter.tex +1 -9
- data/test/sample-book/src/Rakefile +12 -3
- data/{doc/sample.yml → test/sample-book/src/config-epub2.yml} +92 -147
- data/test/sample-book/src/config.yml +40 -154
- data/test/sample-book/src/style-web.css +45 -0
- data/test/sample-book/src/style.css +23 -1
- data/test/test.re +1 -1
- data/test/test_book.rb +15 -17
- data/test/test_book_chapter.rb +2 -80
- data/test/test_book_part.rb +1 -1
- data/test/test_builder.rb +28 -6
- data/test/test_catalog.rb +17 -0
- data/test/test_compiler.rb +14 -59
- data/test/test_configure.rb +94 -0
- data/test/test_converter.rb +21 -0
- data/test/test_epub3maker.rb +155 -3
- data/test/test_epubmaker.rb +245 -30
- data/test/test_epubmaker_cmd.rb +2 -2
- data/test/test_extentions_hash.rb +60 -0
- data/test/test_helper.rb +4 -47
- data/test/test_htmlbuilder.rb +282 -175
- data/test/test_htmltoc.rb +33 -0
- data/test/test_i18n.rb +134 -70
- data/test/test_idgxmlbuilder.rb +58 -39
- data/test/test_latexbuilder.rb +132 -14
- data/test/test_lineinput.rb +5 -26
- data/test/test_makerhelper.rb +6 -4
- data/test/test_markdownbuilder.rb +23 -5
- data/test/test_pdfmaker.rb +86 -20
- data/test/test_pdfmaker_cmd.rb +1 -3
- data/test/test_review_ext.rb +1 -1
- data/test/test_template.rb +27 -0
- data/test/test_textutils.rb +36 -0
- data/test/test_tocparser.rb +25 -0
- data/test/test_topbuilder.rb +34 -2
- data/test/test_yamlloader.rb +188 -0
- metadata +71 -29
- data/README.rdoc +0 -81
- data/bin/review-epubmaker-legacy +0 -1024
- data/doc/ruby-uuid/README +0 -11
- data/doc/ruby-uuid/README.ja +0 -34
- data/lib/review/compiler/literals_1_8.kpeg +0 -19
- data/lib/review/compiler/literals_1_8.rb +0 -432
- data/lib/review/compiler/literals_1_9.kpeg +0 -22
- data/lib/review/compiler/literals_1_9.rb +0 -435
- data/lib/review/extentions/array.rb +0 -25
- data/lib/review/htmllayout.rb +0 -41
- data/lib/review/inaobuilder.rb +0 -357
- data/lib/review/location.rb +0 -24
- data/lib/review/node.rb +0 -267
- data/lib/review/review.kpeg +0 -724
- data/lib/uuid.rb +0 -312
- data/rubocop-todo.yml +0 -456
- data/test/test_inaobuilder.rb +0 -247
- data/test/test_uuid.rb +0 -157
data/lib/review/latexbuilder.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Copyright (c) 2002-2007 Minero Aoki
|
4
4
|
# 2008-2009 Minero Aoki, Kenshi Muto
|
5
|
-
# 2010 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi
|
5
|
+
# 2010-2016 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi
|
6
6
|
#
|
7
7
|
# This program is free software.
|
8
8
|
# You can distribute or modify this program under the terms of
|
@@ -25,7 +25,6 @@ module ReVIEW
|
|
25
25
|
Compiler.definline(e)
|
26
26
|
}
|
27
27
|
|
28
|
-
Compiler.defblock(:memo, 0..1)
|
29
28
|
Compiler.defsingle(:latextsize, 1)
|
30
29
|
|
31
30
|
def extname
|
@@ -39,6 +38,7 @@ module ReVIEW
|
|
39
38
|
@table_caption = nil
|
40
39
|
@ol_num = nil
|
41
40
|
@sec_counter = SecCounter.new(5, @chapter)
|
41
|
+
initialize_metachars(@book.config["texcommand"])
|
42
42
|
end
|
43
43
|
private :builder_init_file
|
44
44
|
|
@@ -47,10 +47,23 @@ module ReVIEW
|
|
47
47
|
end
|
48
48
|
private :blank
|
49
49
|
|
50
|
-
def
|
51
|
-
@blank_needed
|
50
|
+
def print(*s)
|
51
|
+
if @blank_needed
|
52
|
+
@output.puts
|
53
|
+
@blank_needed = false
|
54
|
+
end
|
55
|
+
super
|
52
56
|
end
|
53
|
-
private :
|
57
|
+
private :print
|
58
|
+
|
59
|
+
def puts(*s)
|
60
|
+
if @blank_needed
|
61
|
+
@output.puts
|
62
|
+
@blank_needed = false
|
63
|
+
end
|
64
|
+
super
|
65
|
+
end
|
66
|
+
private :puts
|
54
67
|
|
55
68
|
HEADLINE = {
|
56
69
|
1 => 'chapter',
|
@@ -62,7 +75,6 @@ module ReVIEW
|
|
62
75
|
}
|
63
76
|
|
64
77
|
def headline(level, label, caption)
|
65
|
-
buf = ""
|
66
78
|
_, anchor = headline_prefix(level)
|
67
79
|
headline_name = HEADLINE[level]
|
68
80
|
if @chapter.kind_of? ReVIEW::Book::Part
|
@@ -72,148 +84,157 @@ module ReVIEW
|
|
72
84
|
if level > @book.config["secnolevel"] || (@chapter.number.to_s.empty? && level > 1)
|
73
85
|
prefix = "*"
|
74
86
|
end
|
75
|
-
|
87
|
+
blank unless @output.pos == 0
|
88
|
+
puts macro(headline_name+prefix, compile_inline(caption))
|
76
89
|
if prefix == "*" && level <= @book.config["toclevel"].to_i
|
77
|
-
|
90
|
+
puts "\\addcontentsline{toc}{#{headline_name}}{#{compile_inline(caption)}}"
|
78
91
|
end
|
79
92
|
if level == 1
|
80
|
-
|
93
|
+
puts macro('label', chapter_label)
|
81
94
|
else
|
82
|
-
|
95
|
+
puts macro('label', sec_label(anchor))
|
83
96
|
end
|
84
|
-
buf
|
85
97
|
rescue
|
86
98
|
error "unknown level: #{level}"
|
87
99
|
end
|
88
100
|
|
89
101
|
def nonum_begin(level, label, caption)
|
90
|
-
|
102
|
+
blank unless @output.pos == 0
|
103
|
+
puts macro(HEADLINE[level]+"*", compile_inline(caption))
|
104
|
+
puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
|
91
105
|
end
|
92
106
|
|
93
107
|
def nonum_end(level)
|
94
108
|
end
|
95
109
|
|
110
|
+
def notoc_begin(level, label, caption)
|
111
|
+
blank unless @output.pos == 0
|
112
|
+
puts macro(HEADLINE[level]+"*", compile_inline(caption))
|
113
|
+
end
|
114
|
+
|
115
|
+
def notoc_end(level)
|
116
|
+
end
|
117
|
+
|
118
|
+
def nodisp_begin(level, label, caption)
|
119
|
+
blank unless @output.pos == 0
|
120
|
+
puts macro('clearpage') if @output.pos == 0
|
121
|
+
puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
|
122
|
+
# FIXME: headings
|
123
|
+
end
|
124
|
+
|
125
|
+
def nodisp_end(level)
|
126
|
+
end
|
127
|
+
|
96
128
|
def column_begin(level, label, caption)
|
97
|
-
buf = ""
|
98
129
|
blank
|
99
|
-
|
100
|
-
buf << "\n"
|
101
|
-
blank_reset
|
102
|
-
end
|
103
|
-
buf << "\\begin{reviewcolumn}\n"
|
130
|
+
puts "\\begin{reviewcolumn}\n"
|
104
131
|
if label
|
105
|
-
|
132
|
+
puts "\\hypertarget{#{column_label(label)}}{}"
|
106
133
|
else
|
107
|
-
|
134
|
+
puts "\\hypertarget{#{column_label(caption)}}{}"
|
108
135
|
end
|
109
|
-
|
136
|
+
puts macro('reviewcolumnhead', nil, compile_inline(caption))
|
110
137
|
if level <= @book.config["toclevel"].to_i
|
111
|
-
|
138
|
+
puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
|
112
139
|
end
|
113
|
-
buf
|
114
140
|
end
|
115
141
|
|
116
142
|
def column_end(level)
|
117
|
-
|
118
|
-
buf << "\\end{reviewcolumn}\n"
|
143
|
+
puts "\\end{reviewcolumn}\n"
|
119
144
|
blank
|
120
|
-
buf
|
121
145
|
end
|
122
146
|
|
123
147
|
def captionblock(type, lines, caption)
|
124
|
-
|
125
|
-
buf << "\\begin{reviewminicolumn}\n"
|
148
|
+
puts "\\begin{reviewminicolumn}\n"
|
126
149
|
unless caption.nil?
|
127
|
-
|
150
|
+
puts "\\reviewminicolumntitle{#{compile_inline(caption)}}\n"
|
128
151
|
end
|
129
152
|
|
130
|
-
|
131
|
-
|
132
|
-
else
|
133
|
-
error "deprecated-blocklines is obsoleted."
|
134
|
-
end
|
153
|
+
blocked_lines = split_paragraph(lines)
|
154
|
+
puts blocked_lines.join("\n\n")
|
135
155
|
|
136
|
-
|
137
|
-
buf
|
156
|
+
puts "\\end{reviewminicolumn}\n"
|
138
157
|
end
|
139
158
|
|
140
159
|
def box(lines, caption = nil)
|
141
|
-
|
160
|
+
blank
|
142
161
|
if caption
|
143
|
-
|
162
|
+
puts macro('reviewboxcaption', "#{compile_inline(caption)}")
|
144
163
|
end
|
145
|
-
|
164
|
+
puts '\begin{reviewbox}'
|
146
165
|
lines.each do |line|
|
147
|
-
|
148
|
-
end
|
149
|
-
|
166
|
+
puts detab(line)
|
167
|
+
end
|
168
|
+
puts '\end{reviewbox}'
|
169
|
+
blank
|
150
170
|
end
|
151
171
|
|
152
172
|
def ul_begin
|
153
|
-
|
154
|
-
|
155
|
-
buf
|
173
|
+
blank
|
174
|
+
puts '\begin{itemize}'
|
156
175
|
end
|
157
176
|
|
158
177
|
def ul_item(lines)
|
159
178
|
str = lines.join
|
160
179
|
str.sub!(/\A(\[)/){'\lbrack{}'}
|
161
|
-
'\item ' + str
|
180
|
+
puts '\item ' + str
|
162
181
|
end
|
163
182
|
|
164
183
|
def ul_end
|
165
|
-
'\end{itemize}'
|
184
|
+
puts '\end{itemize}'
|
185
|
+
blank
|
166
186
|
end
|
167
187
|
|
168
188
|
def ol_begin
|
169
|
-
|
170
|
-
|
189
|
+
blank
|
190
|
+
puts '\begin{enumerate}'
|
171
191
|
if @ol_num
|
172
|
-
|
192
|
+
puts "\\setcounter{enumi}{#{@ol_num - 1}}"
|
173
193
|
@ol_num = nil
|
174
194
|
end
|
175
|
-
buf
|
176
195
|
end
|
177
196
|
|
178
197
|
def ol_item(lines, num)
|
179
198
|
str = lines.join
|
180
199
|
str.sub!(/\A(\[)/){'\lbrack{}'}
|
181
|
-
'\item ' + str
|
200
|
+
puts '\item ' + str
|
182
201
|
end
|
183
202
|
|
184
203
|
def ol_end
|
185
|
-
'\end{enumerate}'
|
204
|
+
puts '\end{enumerate}'
|
205
|
+
blank
|
186
206
|
end
|
187
207
|
|
188
208
|
def dl_begin
|
189
|
-
|
209
|
+
blank
|
210
|
+
puts '\begin{description}'
|
190
211
|
end
|
191
212
|
|
192
213
|
def dt(str)
|
193
214
|
str.sub!(/\[/){'\lbrack{}'}
|
194
215
|
str.sub!(/\]/){'\rbrack{}'}
|
195
|
-
'\item[' + str + '] \mbox{} \\\\'
|
216
|
+
puts '\item[' + str + '] \mbox{} \\\\'
|
196
217
|
end
|
197
218
|
|
198
219
|
def dd(lines)
|
199
|
-
lines.join
|
220
|
+
puts lines.join
|
200
221
|
end
|
201
222
|
|
202
223
|
def dl_end
|
203
|
-
'\end{description}'
|
224
|
+
puts '\end{description}'
|
225
|
+
blank
|
204
226
|
end
|
205
227
|
|
206
228
|
def paragraph(lines)
|
207
|
-
|
229
|
+
blank
|
208
230
|
lines.each do |line|
|
209
|
-
|
231
|
+
puts line
|
210
232
|
end
|
211
|
-
|
212
|
-
buf
|
233
|
+
blank
|
213
234
|
end
|
214
235
|
|
215
236
|
def parasep
|
216
|
-
'\\parasep'
|
237
|
+
puts '\\parasep'
|
217
238
|
end
|
218
239
|
|
219
240
|
def read(lines)
|
@@ -228,100 +249,87 @@ module ReVIEW
|
|
228
249
|
private :highlight_listings?
|
229
250
|
|
230
251
|
def emlist(lines, caption = nil, lang = nil)
|
231
|
-
|
252
|
+
blank
|
232
253
|
if highlight_listings?
|
233
|
-
|
254
|
+
common_code_block_lst(nil, lines, 'reviewemlistlst', 'title', caption, lang)
|
234
255
|
else
|
235
|
-
|
256
|
+
common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx|
|
236
257
|
detab(line) + "\n"
|
237
258
|
end
|
238
259
|
end
|
239
|
-
buf
|
240
260
|
end
|
241
261
|
|
242
262
|
def emlistnum(lines, caption = nil, lang = nil)
|
243
|
-
|
263
|
+
blank
|
244
264
|
if highlight_listings?
|
245
|
-
|
265
|
+
common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang)
|
246
266
|
else
|
247
|
-
|
267
|
+
common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx|
|
248
268
|
detab((idx+1).to_s.rjust(2)+": " + line) + "\n"
|
249
269
|
end
|
250
270
|
end
|
251
|
-
buf
|
252
271
|
end
|
253
272
|
|
254
273
|
## override Builder#list
|
255
|
-
def list(lines, id, caption
|
256
|
-
buf = ""
|
274
|
+
def list(lines, id, caption, lang = nil)
|
257
275
|
if highlight_listings?
|
258
|
-
|
276
|
+
common_code_block_lst(id, lines, 'reviewlistlst', 'caption', caption, lang)
|
259
277
|
else
|
260
|
-
|
261
|
-
buf << macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{caption}") + "\n"
|
262
|
-
rescue KeyError
|
263
|
-
error "no such list: #{id}"
|
264
|
-
end
|
265
|
-
buf << common_code_block(lines, 'reviewlist', nil, lang) do |line, idx|
|
278
|
+
common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx|
|
266
279
|
detab(line) + "\n"
|
267
280
|
end
|
268
281
|
end
|
269
|
-
buf
|
270
282
|
end
|
271
283
|
|
272
|
-
|
273
284
|
## override Builder#listnum
|
274
|
-
def listnum(lines, id, caption
|
275
|
-
buf = ""
|
285
|
+
def listnum(lines, id, caption, lang = nil)
|
276
286
|
if highlight_listings?
|
277
|
-
|
287
|
+
common_code_block_lst(id, lines, 'reviewlistnumlst', 'caption', caption, lang)
|
278
288
|
else
|
279
|
-
|
280
|
-
buf << macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{caption}") + "\n"
|
281
|
-
rescue KeyError
|
282
|
-
error "no such list: #{id}"
|
283
|
-
end
|
284
|
-
buf << common_code_block(lines, 'reviewlist', caption, lang) do |line, idx|
|
289
|
+
common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx|
|
285
290
|
detab((idx+1).to_s.rjust(2)+": " + line) + "\n"
|
286
291
|
end
|
287
292
|
end
|
288
|
-
buf
|
289
293
|
end
|
290
294
|
|
291
295
|
def cmd(lines, caption = nil, lang = nil)
|
292
|
-
buf = ""
|
293
296
|
if highlight_listings?
|
294
|
-
|
297
|
+
common_code_block_lst(nil, lines, 'reviewcmdlst', 'title', caption, lang)
|
295
298
|
else
|
296
|
-
|
297
|
-
|
299
|
+
blank
|
300
|
+
common_code_block(nil, lines, 'reviewcmd', caption, lang) do |line, idx|
|
298
301
|
detab(line) + "\n"
|
299
302
|
end
|
300
303
|
end
|
301
|
-
buf
|
302
304
|
end
|
303
305
|
|
304
|
-
def common_code_block(lines, command, caption, lang)
|
305
|
-
buf = ""
|
306
|
+
def common_code_block(id, lines, command, caption, lang)
|
306
307
|
if caption
|
307
|
-
|
308
|
+
if command =~ /emlist/ || command =~ /cmd/
|
309
|
+
puts macro(command + 'caption', "#{compile_inline(caption)}")
|
310
|
+
else
|
311
|
+
begin
|
312
|
+
puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}")
|
313
|
+
rescue KeyError
|
314
|
+
error "no such list: #{id}"
|
315
|
+
end
|
316
|
+
end
|
308
317
|
end
|
309
318
|
body = ""
|
310
319
|
lines.each_with_index do |line, idx|
|
311
320
|
body.concat(yield(line, idx))
|
312
321
|
end
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
322
|
+
puts macro('begin' ,command)
|
323
|
+
print body
|
324
|
+
puts macro('end' ,command)
|
325
|
+
blank
|
317
326
|
end
|
318
327
|
|
319
|
-
def common_code_block_lst(lines, command, title, caption, lang)
|
320
|
-
|
321
|
-
caption_str = (caption || "")
|
328
|
+
def common_code_block_lst(id, lines, command, title, caption, lang)
|
329
|
+
caption_str = compile_inline((caption || ""))
|
322
330
|
if title == "title" && caption_str == ""
|
323
331
|
caption_str = "\\relax" ## dummy charactor to remove lstname
|
324
|
-
|
332
|
+
print "\\vspace{-1.5em}"
|
325
333
|
end
|
326
334
|
if @book.config["highlight"] && @book.config["highlight"]["lang"]
|
327
335
|
lexer = @book.config["highlight"]["lang"] # default setting
|
@@ -330,71 +338,67 @@ module ReVIEW
|
|
330
338
|
end
|
331
339
|
lexer = lang if lang.present?
|
332
340
|
body = lines.inject(''){|i, j| i + detab(unescape_latex(j)) + "\n"}
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
end
|
338
|
-
|
339
|
-
def source(lines, caption = nil)
|
340
|
-
buf = "\n"
|
341
|
-
buf << '\begin{reviewlist}' << "\n"
|
342
|
-
buf << source_header(caption)
|
343
|
-
buf << source_body(lines)
|
344
|
-
buf << '\end{reviewlist}' << "\n"
|
345
|
-
buf << "\n"
|
346
|
-
buf
|
347
|
-
end
|
348
|
-
|
349
|
-
def source_header(caption)
|
350
|
-
macro('reviewlistcaption', caption) + "\n"
|
341
|
+
puts "\\begin{"+command+"}["+title+"={"+caption_str+"},language={"+ lexer+"}]"
|
342
|
+
print body
|
343
|
+
puts "\\end{"+ command + "}"
|
344
|
+
blank
|
351
345
|
end
|
352
346
|
|
353
|
-
def
|
354
|
-
|
355
|
-
|
356
|
-
|
347
|
+
def source(lines, caption, lang = nil)
|
348
|
+
if highlight_listings?
|
349
|
+
common_code_block_lst(nil, lines, 'reviewlistlst', 'title', caption, lang)
|
350
|
+
else
|
351
|
+
puts '\begin{reviewlist}'
|
352
|
+
puts macro('reviewlistcaption', compile_inline(caption))
|
353
|
+
lines.each do |line|
|
354
|
+
puts detab(line)
|
355
|
+
end
|
356
|
+
puts '\end{reviewlist}'
|
357
|
+
puts ""
|
357
358
|
end
|
358
|
-
buf
|
359
359
|
end
|
360
360
|
|
361
361
|
|
362
362
|
def image_header(id, caption)
|
363
363
|
end
|
364
364
|
|
365
|
+
def handle_metric(str)
|
366
|
+
if @book.config["image_scale2width"] && str =~ /\Ascale=([\d.]+)\Z/
|
367
|
+
return "width=#{$1}\\maxwidth"
|
368
|
+
end
|
369
|
+
str
|
370
|
+
end
|
371
|
+
|
365
372
|
def result_metric(array)
|
366
373
|
"#{array.join(',')}"
|
367
374
|
end
|
368
375
|
|
369
376
|
def image_image(id, caption, metric)
|
370
|
-
buf = ""
|
371
377
|
metrics = parse_metric("latex", metric)
|
372
378
|
# image is always bound here
|
373
|
-
|
379
|
+
puts '\begin{reviewimage}'
|
374
380
|
if metrics.present?
|
375
|
-
|
381
|
+
puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
|
376
382
|
else
|
377
|
-
|
383
|
+
puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
|
378
384
|
end
|
379
385
|
if caption.present?
|
380
|
-
|
386
|
+
puts macro('caption', compile_inline(caption))
|
381
387
|
end
|
382
|
-
|
383
|
-
|
384
|
-
buf
|
388
|
+
puts macro('label', image_label(id))
|
389
|
+
puts '\end{reviewimage}'
|
385
390
|
end
|
386
391
|
|
387
392
|
def image_dummy(id, caption, lines)
|
388
|
-
|
393
|
+
puts '\begin{reviewdummyimage}'
|
389
394
|
path = @chapter.image(id).path
|
390
|
-
|
395
|
+
puts "--[[path = #{path} (#{existence(id)})]]--"
|
391
396
|
lines.each do |line|
|
392
|
-
|
397
|
+
puts detab(line.rstrip)
|
393
398
|
end
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
buf
|
399
|
+
puts macro('label', image_label(id))
|
400
|
+
puts compile_inline(caption)
|
401
|
+
puts '\end{reviewdummyimage}'
|
398
402
|
end
|
399
403
|
|
400
404
|
def existence(id)
|
@@ -437,26 +441,23 @@ module ReVIEW
|
|
437
441
|
private :column_label
|
438
442
|
|
439
443
|
def indepimage(id, caption=nil, metric=nil)
|
440
|
-
buf = ""
|
441
444
|
metrics = parse_metric("latex", metric)
|
442
|
-
|
445
|
+
puts '\begin{reviewimage}'
|
443
446
|
if metrics.present?
|
444
|
-
|
447
|
+
puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
|
445
448
|
else
|
446
|
-
|
449
|
+
puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
|
447
450
|
end
|
448
451
|
if caption.present?
|
449
|
-
|
450
|
-
%Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{caption}])
|
452
|
+
puts macro('reviewindepimagecaption',
|
453
|
+
%Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}])
|
451
454
|
end
|
452
|
-
|
453
|
-
buf
|
455
|
+
puts '\end{reviewimage}'
|
454
456
|
end
|
455
457
|
|
456
458
|
alias_method :numberlessimage, :indepimage
|
457
459
|
|
458
460
|
def table(lines, id = nil, caption = nil)
|
459
|
-
buf = ""
|
460
461
|
rows = []
|
461
462
|
sepidx = nil
|
462
463
|
lines.each_with_index do |line, idx|
|
@@ -471,54 +472,49 @@ module ReVIEW
|
|
471
472
|
rows = adjust_n_cols(rows)
|
472
473
|
|
473
474
|
begin
|
474
|
-
|
475
|
+
table_header id, caption unless caption.nil?
|
475
476
|
rescue KeyError
|
476
477
|
error "no such table: #{id}"
|
477
478
|
end
|
478
|
-
return
|
479
|
-
|
479
|
+
return if rows.empty?
|
480
|
+
table_begin rows.first.size
|
480
481
|
if sepidx
|
481
482
|
sepidx.times do
|
482
|
-
|
483
|
+
tr rows.shift.map {|s| th(s) }
|
483
484
|
end
|
484
485
|
rows.each do |cols|
|
485
|
-
|
486
|
+
tr cols.map {|s| td(s) }
|
486
487
|
end
|
487
488
|
else
|
488
489
|
rows.each do |cols|
|
489
490
|
h, *cs = *cols
|
490
|
-
|
491
|
+
tr [th(h)] + cs.map {|s| td(s) }
|
491
492
|
end
|
492
493
|
end
|
493
|
-
|
494
|
-
buf
|
494
|
+
table_end
|
495
495
|
end
|
496
496
|
|
497
497
|
def table_header(id, caption)
|
498
|
-
buf = ""
|
499
498
|
if caption.present?
|
500
499
|
@table_caption = true
|
501
|
-
|
502
|
-
|
500
|
+
puts '\begin{table}[h]'
|
501
|
+
puts macro('reviewtablecaption', compile_inline(caption))
|
503
502
|
end
|
504
|
-
|
505
|
-
buf
|
503
|
+
puts macro('label', table_label(id))
|
506
504
|
end
|
507
505
|
|
508
506
|
def table_begin(ncols)
|
509
|
-
buf = ""
|
510
507
|
if @latex_tsize
|
511
|
-
|
508
|
+
puts macro('begin', 'reviewtable', @latex_tsize)
|
512
509
|
elsif @tsize
|
513
510
|
cellwidth = @tsize.split(/\s*,\s*/)
|
514
|
-
|
511
|
+
puts macro('begin', 'reviewtable', '|'+cellwidth.collect{|i| "p{#{i}mm}"}.join('|')+'|')
|
515
512
|
else
|
516
|
-
|
513
|
+
puts macro('begin', 'reviewtable', (['|'] * (ncols + 1)).join('l'))
|
517
514
|
end
|
518
|
-
|
515
|
+
puts '\hline'
|
519
516
|
@tsize = nil
|
520
517
|
@latex_tsize = nil
|
521
|
-
buf
|
522
518
|
end
|
523
519
|
|
524
520
|
def table_separator
|
@@ -527,7 +523,7 @@ module ReVIEW
|
|
527
523
|
|
528
524
|
def th(s)
|
529
525
|
## use shortstack for @<br>
|
530
|
-
if
|
526
|
+
if /\\\\/i =~ s
|
531
527
|
macro('reviewth', macro('shortstack[l]', s))
|
532
528
|
else
|
533
529
|
macro('reviewth', s)
|
@@ -536,7 +532,7 @@ module ReVIEW
|
|
536
532
|
|
537
533
|
def td(s)
|
538
534
|
## use shortstack for @<br>
|
539
|
-
if
|
535
|
+
if /\\\\/ =~ s
|
540
536
|
macro('shortstack[l]', s)
|
541
537
|
else
|
542
538
|
s
|
@@ -544,21 +540,53 @@ module ReVIEW
|
|
544
540
|
end
|
545
541
|
|
546
542
|
def tr(rows)
|
547
|
-
|
548
|
-
|
549
|
-
buf << ' \\\\ \hline' << "\n"
|
550
|
-
buf
|
543
|
+
print rows.join(' & ')
|
544
|
+
puts ' \\\\ \hline'
|
551
545
|
end
|
552
546
|
|
553
547
|
def table_end
|
554
|
-
|
555
|
-
buf << macro('end', 'reviewtable') << "\n"
|
548
|
+
puts macro('end', 'reviewtable')
|
556
549
|
if @table_caption
|
557
|
-
|
550
|
+
puts '\end{table}'
|
551
|
+
end
|
552
|
+
@table_caption = nil
|
553
|
+
blank
|
554
|
+
end
|
555
|
+
|
556
|
+
def imgtable(lines, id, caption = nil, metric = nil)
|
557
|
+
if !@chapter.image(id).bound?
|
558
|
+
warn "image not bound: #{id}"
|
559
|
+
image_dummy id, caption, lines
|
560
|
+
return
|
558
561
|
end
|
562
|
+
|
563
|
+
begin
|
564
|
+
if caption.present?
|
565
|
+
@table_caption = true
|
566
|
+
puts '\begin{table}[h]'
|
567
|
+
puts macro('reviewimgtablecaption', compile_inline(caption))
|
568
|
+
end
|
569
|
+
puts macro('label', table_label(id))
|
570
|
+
rescue ReVIEW::KeyError
|
571
|
+
error "no such table: #{id}"
|
572
|
+
end
|
573
|
+
imgtable_image(id, caption, metric)
|
574
|
+
|
575
|
+
puts '\end{table}' if @table_caption
|
559
576
|
@table_caption = nil
|
560
|
-
|
561
|
-
|
577
|
+
blank
|
578
|
+
end
|
579
|
+
|
580
|
+
def imgtable_image(id, caption, metric)
|
581
|
+
metrics = parse_metric("latex", metric)
|
582
|
+
# image is always bound here
|
583
|
+
puts '\begin{reviewimage}'
|
584
|
+
if metrics.present?
|
585
|
+
puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
|
586
|
+
else
|
587
|
+
puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
|
588
|
+
end
|
589
|
+
puts '\end{reviewimage}'
|
562
590
|
end
|
563
591
|
|
564
592
|
def quote(lines)
|
@@ -576,72 +604,59 @@ module ReVIEW
|
|
576
604
|
end
|
577
605
|
|
578
606
|
def texequation(lines)
|
579
|
-
|
580
|
-
|
607
|
+
blank
|
608
|
+
puts macro('begin','equation*')
|
581
609
|
lines.each do |line|
|
582
|
-
|
610
|
+
puts unescape_latex(line)
|
583
611
|
end
|
584
|
-
|
585
|
-
|
586
|
-
buf
|
612
|
+
puts macro('end', 'equation*')
|
613
|
+
blank
|
587
614
|
end
|
588
615
|
|
589
616
|
def latex_block(type, lines)
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
end
|
597
|
-
buf << macro('end', type) << "\n"
|
598
|
-
buf
|
617
|
+
blank
|
618
|
+
puts macro('begin', type)
|
619
|
+
blocked_lines = split_paragraph(lines)
|
620
|
+
puts blocked_lines.join("\n\n")
|
621
|
+
puts macro('end', type)
|
622
|
+
blank
|
599
623
|
end
|
600
624
|
private :latex_block
|
601
625
|
|
602
626
|
def direct(lines, fmt)
|
603
|
-
|
604
|
-
return buf unless fmt == 'latex'
|
627
|
+
return unless fmt == 'latex'
|
605
628
|
lines.each do |line|
|
606
|
-
|
629
|
+
puts line
|
607
630
|
end
|
608
|
-
buf
|
609
631
|
end
|
610
632
|
|
611
633
|
def comment(lines, comment = nil)
|
612
|
-
buf = ""
|
613
634
|
lines ||= []
|
614
635
|
lines.unshift comment unless comment.blank?
|
615
636
|
if @book.config["draft"]
|
616
637
|
str = lines.join("")
|
617
|
-
|
638
|
+
puts macro('pdfcomment', escape(str))
|
618
639
|
end
|
619
|
-
buf
|
620
640
|
end
|
621
641
|
|
622
642
|
def hr
|
623
|
-
'\hrule'
|
643
|
+
puts '\hrule'
|
624
644
|
end
|
625
645
|
|
626
646
|
def label(id)
|
627
|
-
macro('label', id)
|
628
|
-
end
|
629
|
-
|
630
|
-
def node_label(node)
|
631
|
-
id = node.args[0].to_raw
|
632
|
-
macro('label', id) + "\n"
|
647
|
+
puts macro('label', id)
|
633
648
|
end
|
634
649
|
|
635
650
|
def pagebreak
|
636
|
-
'\pagebreak'
|
651
|
+
puts '\pagebreak'
|
637
652
|
end
|
638
653
|
|
639
654
|
def linebreak
|
640
|
-
'\\\\'
|
655
|
+
puts '\\\\'
|
641
656
|
end
|
642
657
|
|
643
658
|
def noindent
|
644
|
-
'\noindent'
|
659
|
+
print '\noindent'
|
645
660
|
end
|
646
661
|
|
647
662
|
def inline_chapref(id)
|
@@ -698,8 +713,8 @@ module ReVIEW
|
|
698
713
|
|
699
714
|
def footnote(id, content)
|
700
715
|
if @book.config["footnotetext"]
|
701
|
-
macro("footnotetext[#{@chapter.footnote(id).number}]",
|
702
|
-
content.strip)
|
716
|
+
puts macro("footnotetext[#{@chapter.footnote(id).number}]",
|
717
|
+
compile_inline(content.strip))
|
703
718
|
end
|
704
719
|
end
|
705
720
|
|
@@ -707,7 +722,7 @@ module ReVIEW
|
|
707
722
|
if @book.config["footnotetext"]
|
708
723
|
macro("footnotemark[#{@chapter.footnote(id).number}]", "")
|
709
724
|
else
|
710
|
-
macro('footnote',
|
725
|
+
macro('footnote', compile_inline(@chapter.footnote(id).content.strip))
|
711
726
|
end
|
712
727
|
end
|
713
728
|
|
@@ -718,16 +733,12 @@ module ReVIEW
|
|
718
733
|
end
|
719
734
|
|
720
735
|
def compile_ruby(base, ruby)
|
721
|
-
macro('ruby', base, ruby)
|
736
|
+
macro('ruby', escape(base), escape(ruby))
|
722
737
|
end
|
723
738
|
|
724
739
|
# math
|
725
|
-
|
726
|
-
|
727
|
-
# end
|
728
|
-
|
729
|
-
def node_inline_m(node)
|
730
|
-
" $#{node[0].to_raw}$ "
|
740
|
+
def inline_m(str)
|
741
|
+
" $#{str}$ "
|
731
742
|
end
|
732
743
|
|
733
744
|
# hidden index
|
@@ -737,7 +748,7 @@ module ReVIEW
|
|
737
748
|
|
738
749
|
# index -> italic
|
739
750
|
def inline_i(str)
|
740
|
-
macro('textit', str)
|
751
|
+
macro('textit', escape(str))
|
741
752
|
end
|
742
753
|
|
743
754
|
# index
|
@@ -745,24 +756,14 @@ module ReVIEW
|
|
745
756
|
escape(str) + index(str)
|
746
757
|
end
|
747
758
|
|
748
|
-
def node_inline_idx(nodelist)
|
749
|
-
content = nodelist[0].to_raw
|
750
|
-
escape(content) + index(content)
|
751
|
-
end
|
752
|
-
|
753
759
|
# hidden index??
|
754
760
|
def inline_hidx(str)
|
755
761
|
index(str)
|
756
762
|
end
|
757
763
|
|
758
|
-
def node_inline_hidx(nodelist)
|
759
|
-
content = nodelist[0].to_raw
|
760
|
-
index(content)
|
761
|
-
end
|
762
|
-
|
763
764
|
# bold
|
764
765
|
def inline_b(str)
|
765
|
-
macro('textbf', str)
|
766
|
+
macro('textbf', escape(str))
|
766
767
|
end
|
767
768
|
|
768
769
|
# line break
|
@@ -777,7 +778,7 @@ module ReVIEW
|
|
777
778
|
|
778
779
|
## @<code> is same as @<tt>
|
779
780
|
def inline_code(str)
|
780
|
-
macro('texttt', str)
|
781
|
+
macro('texttt', escape(str))
|
781
782
|
end
|
782
783
|
|
783
784
|
def nofunc_text(str)
|
@@ -785,19 +786,19 @@ module ReVIEW
|
|
785
786
|
end
|
786
787
|
|
787
788
|
def inline_tt(str)
|
788
|
-
macro('texttt', str)
|
789
|
+
macro('texttt', escape(str))
|
789
790
|
end
|
790
791
|
|
791
792
|
def inline_del(str)
|
792
|
-
macro('reviewstrike', str)
|
793
|
+
macro('reviewstrike', escape(str))
|
793
794
|
end
|
794
795
|
|
795
796
|
def inline_tti(str)
|
796
|
-
macro('texttt', macro('textit', str))
|
797
|
+
macro('texttt', macro('textit', escape(str)))
|
797
798
|
end
|
798
799
|
|
799
800
|
def inline_ttb(str)
|
800
|
-
macro('texttt', macro('textbf', str))
|
801
|
+
macro('texttt', macro('textbf', escape(str)))
|
801
802
|
end
|
802
803
|
|
803
804
|
def inline_bib(id)
|
@@ -807,20 +808,20 @@ module ReVIEW
|
|
807
808
|
def inline_hd_chap(chap, id)
|
808
809
|
n = chap.headline_index.number(id)
|
809
810
|
if chap.number and @book.config["secnolevel"] >= n.split('.').size
|
810
|
-
str = I18n.t("chapter_quote", "#{chap.headline_index.number(id)} #{chap.headline(id).caption}")
|
811
|
+
str = I18n.t("chapter_quote", "#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}")
|
811
812
|
else
|
812
|
-
str = I18n.t("chapter_quote", chap.headline(id).caption)
|
813
|
+
str = I18n.t("chapter_quote", compile_inline(chap.headline(id).caption))
|
813
814
|
end
|
814
815
|
if @book.config["chapterlink"]
|
815
816
|
anchor = n.gsub(/\./, "-")
|
816
|
-
macro('reviewsecref',
|
817
|
+
macro('reviewsecref', str, sec_label(anchor))
|
817
818
|
else
|
818
|
-
|
819
|
+
str
|
819
820
|
end
|
820
821
|
end
|
821
822
|
|
822
|
-
def
|
823
|
-
macro('reviewcolumnref', "#{
|
823
|
+
def inline_column_chap(chapter, id)
|
824
|
+
macro('reviewcolumnref', "#{chapter.column(id).caption}", column_label(id))
|
824
825
|
end
|
825
826
|
|
826
827
|
def inline_raw(str)
|
@@ -828,27 +829,27 @@ module ReVIEW
|
|
828
829
|
end
|
829
830
|
|
830
831
|
def inline_sub(str)
|
831
|
-
macro('textsubscript', str)
|
832
|
+
macro('textsubscript', escape(str))
|
832
833
|
end
|
833
834
|
|
834
835
|
def inline_sup(str)
|
835
|
-
macro('textsuperscript', str)
|
836
|
+
macro('textsuperscript', escape(str))
|
836
837
|
end
|
837
838
|
|
838
839
|
def inline_em(str)
|
839
|
-
macro('reviewem', str)
|
840
|
+
macro('reviewem', escape(str))
|
840
841
|
end
|
841
842
|
|
842
843
|
def inline_strong(str)
|
843
|
-
macro('reviewstrong', str)
|
844
|
+
macro('reviewstrong', escape(str))
|
844
845
|
end
|
845
846
|
|
846
847
|
def inline_u(str)
|
847
|
-
macro('
|
848
|
+
macro('reviewunderline', escape(str))
|
848
849
|
end
|
849
850
|
|
850
851
|
def inline_ami(str)
|
851
|
-
macro('reviewami', str)
|
852
|
+
macro('reviewami', escape(str))
|
852
853
|
end
|
853
854
|
|
854
855
|
def inline_icon(id)
|
@@ -857,7 +858,7 @@ module ReVIEW
|
|
857
858
|
|
858
859
|
def inline_uchar(str)
|
859
860
|
# with otf package
|
860
|
-
macro('UTF', str)
|
861
|
+
macro('UTF', escape(str))
|
861
862
|
end
|
862
863
|
|
863
864
|
def inline_comment(str)
|
@@ -868,44 +869,50 @@ module ReVIEW
|
|
868
869
|
end
|
869
870
|
end
|
870
871
|
|
871
|
-
def
|
872
|
-
|
873
|
-
buf << bibpaper_header(id, caption)
|
874
|
-
if lines.empty?
|
875
|
-
buf << "\n"
|
876
|
-
else
|
877
|
-
buf << "\n"
|
878
|
-
buf << bibpaper_bibpaper(id, caption, lines)
|
879
|
-
end
|
880
|
-
buf << "\n"
|
881
|
-
buf
|
872
|
+
def inline_tcy(str)
|
873
|
+
macro('rensuji', escape(str))
|
882
874
|
end
|
883
875
|
|
884
876
|
def bibpaper_header(id, caption)
|
885
|
-
"[#{@chapter.bibpaper(id).number}] #{caption}
|
886
|
-
|
877
|
+
puts "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}"
|
878
|
+
puts macro('label', bib_label(id))
|
887
879
|
end
|
888
880
|
|
889
881
|
def bibpaper_bibpaper(id, caption, lines)
|
890
|
-
lines.join("")
|
882
|
+
print split_paragraph(lines).join("")
|
883
|
+
puts ""
|
891
884
|
end
|
892
885
|
|
893
886
|
def index(str)
|
894
|
-
|
887
|
+
str.sub!(/\(\)/, '')
|
888
|
+
decl = ''
|
889
|
+
if /@\z/ =~ str
|
890
|
+
str.chop!
|
891
|
+
decl = '|IndexDecl'
|
892
|
+
end
|
893
|
+
unless /[^ -~]/ =~ str
|
894
|
+
if /\^/ =~ str
|
895
|
+
macro('index', escape_index(str.gsub(/\^/, '')) + '@' + escape_index(text(str)) + decl)
|
896
|
+
else
|
897
|
+
'\index{' + escape_index(text(str)) + decl + '}'
|
898
|
+
end
|
899
|
+
else
|
900
|
+
'\index{' + escape_index(@index_db[str]) + '@' + escape_index(text(str)) + '}'
|
901
|
+
end
|
895
902
|
end
|
896
903
|
|
897
904
|
def compile_kw(word, alt)
|
898
905
|
if alt
|
899
|
-
macro('reviewkw', word) + "(#{alt.strip})"
|
906
|
+
macro('reviewkw', escape(word)) + "(#{escape(alt.strip)})"
|
900
907
|
else
|
901
|
-
macro('reviewkw', word)
|
908
|
+
macro('reviewkw', escape(word))
|
902
909
|
end
|
903
910
|
end
|
904
911
|
|
905
912
|
def compile_href(url, label)
|
906
913
|
if /\A[a-z]+:/ =~ url
|
907
914
|
if label
|
908
|
-
macro("href", escape_url(url), label)
|
915
|
+
macro("href", escape_url(url), escape(label))
|
909
916
|
else
|
910
917
|
macro("url", escape_url(url))
|
911
918
|
end
|