Class: ReVIEW::LATEXBuilder
Constant Summary
collapse
- HEADLINE =
{
1 => 'chapter',
2 => 'section',
3 => 'subsection',
4 => 'subsubsection',
5 => 'paragraph',
6 => 'subparagraph'
}.freeze
- BOUTEN =
'・'.freeze
Constants inherited
from Builder
Builder::CAPTION_TITLES
Instance Attribute Summary
Attributes inherited from Builder
#doc_status, #location
Attributes included from Loggable
#logger
Instance Method Summary
collapse
-
#bibpaper_bibpaper(_id, _caption, lines) ⇒ Object
-
#bibpaper_header(id, caption) ⇒ Object
-
#blankline ⇒ Object
-
#box(lines, caption = nil) ⇒ Object
-
#captionblock(type, lines, caption) ⇒ Object
-
#center(lines) ⇒ Object
(also: #centering)
-
#cmd(lines, caption = nil, lang = nil) ⇒ Object
-
#code_line(_type, line, _idx, _id, _caption, _lang) ⇒ Object
-
#code_line_num(_type, line, first_line_num, idx, _id, _caption, _lang) ⇒ Object
-
#column_begin(level, label, caption) ⇒ Object
-
#column_end(_level) ⇒ Object
-
#comment(lines, comment = nil) ⇒ Object
-
#common_block_begin(type, caption = nil) ⇒ Object
-
#common_block_end(type) ⇒ Object
-
#common_code_block(id, lines, command, caption, _lang) ⇒ Object
-
#common_code_block_lst(_id, lines, command, title, caption, lang, first_line_num: 1) ⇒ Object
-
#compile_href(url, label) ⇒ Object
-
#compile_kw(word, alt) ⇒ Object
-
#compile_ruby(base, ruby) ⇒ Object
-
#dd(lines) ⇒ Object
-
#direct(lines, fmt) ⇒ Object
-
#dl_begin ⇒ Object
-
#dl_end ⇒ Object
-
#dt(str) ⇒ Object
-
#emlist(lines, caption = nil, lang = nil) ⇒ Object
-
#emlistnum(lines, caption = nil, lang = nil) ⇒ Object
-
#emtable(lines, caption = nil) ⇒ Object
-
#extname ⇒ Object
-
#flushright(lines) ⇒ Object
-
#footnote(id, content) ⇒ Object
-
#handle_metric(str) ⇒ Object
-
#headline(level, label, caption) ⇒ Object
-
#highlight? ⇒ Boolean
-
#hr ⇒ Object
-
#image_dummy(id, caption, lines) ⇒ Object
-
#image_ext ⇒ Object
-
#image_header(id, caption) ⇒ Object
-
#image_image(id, caption = '', metric = nil) ⇒ Object
-
#imgtable(lines, id, caption = nil, metric = nil) ⇒ Object
-
#imgtable_image(id, _caption, metric) ⇒ Object
-
#indepimage(lines, id, caption = nil, metric = nil) ⇒ Object
(also: #numberlessimage)
-
#index(str) ⇒ Object
-
#inline_ami(str) ⇒ Object
-
#inline_b(str) ⇒ Object
-
#inline_balloon(str) ⇒ Object
-
#inline_bib(id) ⇒ Object
-
#inline_bou(str) ⇒ Object
-
#inline_br(_str) ⇒ Object
-
#inline_chap(id) ⇒ Object
-
#inline_chapref(id) ⇒ Object
-
#inline_code(str) ⇒ Object
@<code> is same as @<tt>.
-
#inline_column_chap(chapter, id) ⇒ Object
-
#inline_comment(str) ⇒ Object
-
#inline_del(str) ⇒ Object
-
#inline_dtp(_str) ⇒ Object
-
#inline_em(str) ⇒ Object
-
#inline_endnote(id) ⇒ Object
-
#inline_eq(id) ⇒ Object
-
#inline_fn(id) ⇒ Object
-
#inline_hd_chap(chap, id) ⇒ Object
-
#inline_hi(str) ⇒ Object
-
#inline_hidx(str) ⇒ Object
-
#inline_i(str) ⇒ Object
-
#inline_icon(id) ⇒ Object
-
#inline_idx(str) ⇒ Object
-
#inline_img(id) ⇒ Object
-
#inline_ins(str) ⇒ Object
-
#inline_list(id) ⇒ Object
FIXME: use TeX native label/ref.
-
#inline_m(str) ⇒ Object
-
#inline_pageref(id) ⇒ Object
-
#inline_raw(str) ⇒ Object
rubocop:disable Lint/UselessMethodDefinition.
-
#inline_strong(str) ⇒ Object
-
#inline_sub(str) ⇒ Object
-
#inline_sup(str) ⇒ Object
-
#inline_table(id) ⇒ Object
-
#inline_tcy(str) ⇒ Object
-
#inline_title(id) ⇒ Object
-
#inline_tt(str) ⇒ Object
-
#inline_ttb(str) ⇒ Object
-
#inline_tti(str) ⇒ Object
-
#inline_u(str) ⇒ Object
-
#inline_uchar(str) ⇒ Object
-
#label(id) ⇒ Object
-
#latextsize(str) ⇒ Object
-
#list(lines, id, caption, lang = nil) ⇒ Object
-
#listnum(lines, id, caption, lang = nil) ⇒ Object
override Builder#listnum.
-
#load_idxdb(file) ⇒ Object
-
#make_code_block_args(title, caption, lang, first_line_num: 1) ⇒ Object
-
#nodisp_begin(level, _label, caption) ⇒ Object
-
#nodisp_end(level) ⇒ Object
-
#nofunc_text(str) ⇒ Object
-
#noindent ⇒ Object
-
#nonum_begin(level, _label, caption) ⇒ Object
-
#nonum_end(level) ⇒ Object
-
#notoc_begin(level, _label, caption) ⇒ Object
-
#notoc_end(level) ⇒ Object
-
#ol_begin ⇒ Object
-
#ol_end ⇒ Object
-
#ol_item(lines, _num) ⇒ Object
-
#olnum(num) ⇒ Object
-
#pagebreak ⇒ Object
-
#paragraph(lines) ⇒ Object
-
#parasep ⇒ Object
-
#parse_metric(type, metric) ⇒ Object
-
#printendnotes ⇒ Object
-
#quote(lines) ⇒ Object
-
#read(lines) ⇒ Object
(also: #lead)
-
#result ⇒ Object
-
#result_metric(array) ⇒ Object
-
#separate_tsize(size) ⇒ Object
-
#setup_index ⇒ Object
-
#solve_nest(s) ⇒ Object
-
#source(lines, caption = nil, lang = nil) ⇒ Object
-
#table(lines, id = nil, caption = nil) ⇒ Object
-
#table_begin(ncols) ⇒ Object
-
#table_end ⇒ Object
-
#table_header(id, caption) ⇒ Object
-
#table_rows(sepidx, rows) ⇒ Object
-
#table_separator ⇒ Object
-
#td(s, cellwidth = 'l') ⇒ Object
-
#texequation(lines, id = nil, caption = '') ⇒ Object
-
#th(s, cellwidth = 'l') ⇒ Object
-
#tr(rows) ⇒ Object
-
#ul_begin ⇒ Object
-
#ul_end ⇒ Object
-
#ul_item(lines) ⇒ Object
Methods included from TextUtils
#add_space?, #detab, #join_lines_to_paragraph, #split_paragraph
Methods included from LaTeXUtils
#escape, #escape_index, #escape_mendex_display, #escape_mendex_key, #escape_url, #initialize_metachars, #macro, #unescape
Methods inherited from Builder
#beginchild, #bibpaper, #bind, #caption_top?, #check_nest, #check_nested_minicolumn, #check_printendnotes, #compile_inline, #detab, #embed, #endchild, #endnote, #endnote_begin, #endnote_end, #endnote_item, #escape, #extract_chapter_id, #firstlinenum, #get_chap, #graph, #graph_aafigure, #graph_blockdiag, #graph_gnuplot, #graph_graphviz, #graph_plantuml, #image, #in_minicolumn?, #initialize, #inline_column, #inline_embed, #inline_hd, #inline_href, #inline_imgref, #inline_include, #inline_kw, #inline_ruby, #inline_w, #inline_wb, #line_num, #load_words, #minicolumn_block_name?, #over_secnolevel?, #parse_table_rows, #post_paragraph, #pre_paragraph, #previous_list_type, #raw, #system_graph, #table_row_separator_regexp, #target_name, #text, #tsize, #ul_item_begin, #ul_item_end
Methods included from Loggable
#app_error, #debug, #error, #error!, #warn
Instance Method Details
#bibpaper_bibpaper(_id, _caption, lines) ⇒ Object
1375
1376
1377
1378
1379
1380
1381
1382
1383
|
# File 'lib/review/latexbuilder.rb', line 1375
def bibpaper_bibpaper(_id, _caption, lines)
if @book.config['join_lines_by_lang']
print split_paragraph(lines).join("\n\n")
else
print split_paragraph(lines).map(&:chomp).join("\n")
end
puts ''
end
|
1370
1371
1372
1373
|
# File 'lib/review/latexbuilder.rb', line 1370
def (id, caption)
puts "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}"
puts macro('label', bib_label(id))
end
|
#blankline ⇒ Object
1042
1043
1044
|
# File 'lib/review/latexbuilder.rb', line 1042
def blankline
puts '\vspace*{\baselineskip}'
end
|
#box(lines, caption = nil) ⇒ Object
305
306
307
308
309
310
311
312
313
314
|
# File 'lib/review/latexbuilder.rb', line 305
def box(lines, caption = nil)
blank
puts macro('reviewboxcaption', compile_inline(caption)) if caption.present?
puts '\begin{reviewbox}'
lines.each do |line|
puts detab(line)
end
puts '\end{reviewbox}'
blank
end
|
#captionblock(type, lines, caption) ⇒ Object
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
# File 'lib/review/latexbuilder.rb', line 277
def captionblock(type, lines, caption)
check_nested_minicolumn
if @book.config.check_version('2', exception: false)
type = 'minicolumn'
end
print "\\begin{review#{type}}"
@doc_status[:caption] = true
if @book.config.check_version('2', exception: false)
puts
if caption.present?
puts "\\reviewminicolumntitle{#{compile_inline(caption)}}"
end
else
if caption.present?
print "[#{compile_inline(caption)}]"
end
puts
end
@doc_status[:caption] = nil
blocked_lines = split_paragraph(lines)
puts blocked_lines.join("\n\n")
puts "\\end{review#{type}}"
end
|
#center(lines) ⇒ Object
Also known as:
centering
957
958
959
|
# File 'lib/review/latexbuilder.rb', line 957
def center(lines)
latex_block('center', lines)
end
|
#cmd(lines, caption = nil, lang = nil) ⇒ Object
459
460
461
462
463
464
465
466
|
# File 'lib/review/latexbuilder.rb', line 459
def cmd(lines, caption = nil, lang = nil)
if highlight_listings?
common_code_block_lst(nil, lines, 'reviewcmdlst', 'title', caption, lang)
else
blank
common_code_block(nil, lines, 'reviewcmd', caption, lang) { |line, idx| code_line('cmd', line, idx, nil, caption, lang) }
end
end
|
#code_line(_type, line, _idx, _id, _caption, _lang) ⇒ Object
413
414
415
|
# File 'lib/review/latexbuilder.rb', line 413
def code_line(_type, line, _idx, _id, _caption, _lang)
detab(line) + "\n"
end
|
#code_line_num(_type, line, first_line_num, idx, _id, _caption, _lang) ⇒ Object
417
418
419
|
# File 'lib/review/latexbuilder.rb', line 417
def code_line_num(_type, line, first_line_num, idx, _id, _caption, _lang)
detab((idx + first_line_num).to_s.rjust(2) + ': ' + line) + "\n"
end
|
#column_begin(level, label, caption) ⇒ Object
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/review/latexbuilder.rb', line 198
def column_begin(level, label, caption)
blank
@doc_status[:column] = true
target = nil
if label
target = "\\hypertarget{#{column_label(label)}}{}"
else
target = "\\hypertarget{#{column_label(caption)}}{}"
end
@doc_status[:caption] = true
if @book.config.check_version('2', exception: false)
puts '\\begin{reviewcolumn}'
puts target
puts macro('reviewcolumnhead', nil, compile_inline(caption))
else
print '\\begin{reviewcolumn}'
puts "[#{compile_inline(caption)}#{target}]"
end
@doc_status[:caption] = nil
if level <= @book.config['toclevel'].to_i
puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
end
end
|
#column_end(_level) ⇒ Object
226
227
228
229
230
|
# File 'lib/review/latexbuilder.rb', line 226
def column_end(_level)
puts '\\end{reviewcolumn}'
blank
@doc_status[:column] = nil
end
|
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
|
# File 'lib/review/latexbuilder.rb', line 1019
def (lines, = nil)
return true unless @book.config['draft']
lines ||= []
unless .blank?
lines.unshift(escape())
end
str = lines.join('\par ')
puts macro('pdfcomment', str)
end
|
#common_block_begin(type, caption = nil) ⇒ Object
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/review/latexbuilder.rb', line 232
def common_block_begin(type, caption = nil)
check_nested_minicolumn
if @book.config.check_version('2', exception: false)
type = 'minicolumn'
end
@doc_status[:minicolumn] = type
print "\\begin{review#{type}}"
@doc_status[:caption] = true
if @book.config.check_version('2', exception: false)
puts
if caption.present?
puts "\\reviewminicolumntitle{#{compile_inline(caption)}}"
end
else
if caption.present?
print "[#{compile_inline(caption)}]"
end
puts
end
@doc_status[:caption] = nil
end
|
#common_block_end(type) ⇒ Object
256
257
258
259
260
261
262
263
|
# File 'lib/review/latexbuilder.rb', line 256
def common_block_end(type)
if @book.config.check_version('2', exception: false)
type = 'minicolumn'
end
puts "\\end{review#{type}}"
@doc_status[:minicolumn] = nil
end
|
#common_code_block(id, lines, command, caption, _lang) ⇒ Object
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
|
# File 'lib/review/latexbuilder.rb', line 468
def common_code_block(id, lines, command, caption, _lang)
@doc_status[:caption] = true
captionstr = nil
unless @book.config.check_version('2', exception: false)
puts '\\begin{reviewlistblock}'
end
if caption.present?
if command =~ /emlist/ || command =~ /cmd/ || command =~ /source/
captionstr = macro(command + 'caption', compile_inline(caption))
else
begin
if get_chap.nil?
captionstr = macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
else
captionstr = macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
end
rescue KeyError
app_error "no such list: #{id}"
end
end
end
@doc_status[:caption] = nil
if caption_top?('list') && captionstr
puts captionstr
end
body = ''
lines.each_with_index do |line, idx|
body.concat(yield(line, idx))
end
puts macro('begin', command)
print body
puts macro('end', command)
if !caption_top?('list') && captionstr
puts captionstr
end
unless @book.config.check_version('2', exception: false)
puts '\\end{reviewlistblock}'
end
blank
end
|
#common_code_block_lst(_id, lines, command, title, caption, lang, first_line_num: 1) ⇒ Object
513
514
515
516
517
518
519
520
521
522
523
|
# File 'lib/review/latexbuilder.rb', line 513
def common_code_block_lst(_id, lines, command, title, caption, lang, first_line_num: 1)
if title == 'title' && caption.blank? && @book.config.check_version('2', exception: false)
print '\vspace{-1.5em}'
end
body = lines.inject('') { |i, j| i + detab(j) + "\n" }
args = make_code_block_args(title, caption, lang, first_line_num: first_line_num)
puts %Q(\\begin{#{command}}[#{args}])
print body
puts %Q(\\end{#{command}})
blank
end
|
#compile_href(url, label) ⇒ Object
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
|
# File 'lib/review/latexbuilder.rb', line 1416
def compile_href(url, label)
if /\A[a-z]+:/ =~ url
if label
macro('href', escape_url(url), escape(label))
else
macro('url', escape_url(url))
end
else
macro('ref', url)
end
end
|
#compile_kw(word, alt) ⇒ Object
1408
1409
1410
1411
1412
1413
1414
|
# File 'lib/review/latexbuilder.rb', line 1408
def compile_kw(word, alt)
if alt
macro('reviewkw', escape(word)) + "(#{escape(alt.strip)})"
else
macro('reviewkw', escape(word))
end
end
|
#compile_ruby(base, ruby) ⇒ Object
1175
1176
1177
|
# File 'lib/review/latexbuilder.rb', line 1175
def compile_ruby(base, ruby)
macro('ruby', escape(base), escape(ruby).gsub('\\textbar{}', '|'))
end
|
#dd(lines) ⇒ Object
370
371
372
373
374
375
376
|
# File 'lib/review/latexbuilder.rb', line 370
def dd(lines)
if @book.config['join_lines_by_lang']
puts join_lines_to_paragraph(lines)
else
puts lines.map(&:chomp).join("\n")
end
end
|
#direct(lines, fmt) ⇒ Object
1011
1012
1013
1014
1015
1016
1017
|
# File 'lib/review/latexbuilder.rb', line 1011
def direct(lines, fmt)
return unless fmt == 'latex'
lines.each do |line|
puts line
end
end
|
360
361
362
363
|
# File 'lib/review/latexbuilder.rb', line 360
def dl_begin
blank
puts '\begin{description}'
end
|
378
379
380
381
|
# File 'lib/review/latexbuilder.rb', line 378
def dl_end
puts '\end{description}'
blank
end
|
365
366
367
368
|
# File 'lib/review/latexbuilder.rb', line 365
def dt(str)
str = str.gsub('[', '\lbrack{}').gsub(']', '\rbrack{}')
puts '\item[' + str + '] \mbox{} \\\\'
end
|
#emlist(lines, caption = nil, lang = nil) ⇒ Object
421
422
423
424
425
426
427
428
|
# File 'lib/review/latexbuilder.rb', line 421
def emlist(lines, caption = nil, lang = nil)
blank
if highlight_listings?
common_code_block_lst(nil, lines, 'reviewemlistlst', 'title', caption, lang)
else
common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, idx| code_line('emlist', line, idx, nil, caption, lang) }
end
end
|
#emlistnum(lines, caption = nil, lang = nil) ⇒ Object
430
431
432
433
434
435
436
437
438
|
# File 'lib/review/latexbuilder.rb', line 430
def emlistnum(lines, caption = nil, lang = nil)
blank
first_line_num = line_num
if highlight_listings?
common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang, first_line_num: first_line_num)
else
common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, idx| code_line_num('emlistnum', line, first_line_num, idx, nil, caption, lang) }
end
end
|
#emtable(lines, caption = nil) ⇒ Object
898
899
900
|
# File 'lib/review/latexbuilder.rb', line 898
def emtable(lines, caption = nil)
table(lines, nil, caption)
end
|
26
27
28
|
# File 'lib/review/latexbuilder.rb', line 26
def extname
'.tex'
end
|
#flushright(lines) ⇒ Object
963
964
965
|
# File 'lib/review/latexbuilder.rb', line 963
def flushright(lines)
latex_block('flushright', lines)
end
|
1134
1135
1136
1137
1138
1139
1140
1141
|
# File 'lib/review/latexbuilder.rb', line 1134
def (id, content)
if @book.config['footnotetext'] || @foottext[id]
if @doc_status[:column]
warn "//footnote[#{id}] is in the column block. It is recommended to move out of the column block.", location: location
end
puts macro("footnotetext[#{@chapter.(id).number}]", compile_inline(content.strip))
end
end
|
#handle_metric(str) ⇒ Object
568
569
570
571
572
573
574
|
# File 'lib/review/latexbuilder.rb', line 568
def handle_metric(str)
if @book.config['pdfmaker']['image_scale2width'] && str =~ /\Ascale=([\d.]+)\Z/
return "width=#{$1}\\maxwidth"
end
str
end
|
#headline(level, label, caption) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/review/latexbuilder.rb', line 132
def headline(level, label, caption)
_, anchor = headline_prefix(level)
headline_name = HEADLINE[level]
if @chapter.is_a?(ReVIEW::Book::Part)
if @book.config.check_version('2', exception: false)
headline_name = 'part'
elsif level == 1
headline_name = 'part'
puts '\begin{reviewpart}'
end
end
prefix = ''
if level > @book.config['secnolevel'] || (@chapter.number.to_s.empty? && level > 1)
prefix = '*'
end
blank unless @output.pos == 0
@doc_status[:caption] = true
puts macro(headline_name + prefix, compile_inline(caption))
@doc_status[:caption] = nil
if prefix == '*' && level <= @book.config['toclevel'].to_i
puts "\\addcontentsline{toc}{#{headline_name}}{#{compile_inline(caption)}}"
end
if level == 1
puts macro('label', chapter_label)
else
puts macro('label', sec_label(anchor))
puts macro('label', label) if label
end
rescue
app_error "unknown level: #{level}"
end
|
#highlight? ⇒ Boolean
403
404
405
406
|
# File 'lib/review/latexbuilder.rb', line 403
def highlight?
@book.config['highlight'] &&
@book.config['highlight']['latex']
end
|
1030
1031
1032
|
# File 'lib/review/latexbuilder.rb', line 1030
def hr
puts '\hrule'
end
|
#image_dummy(id, caption, lines) ⇒ Object
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
|
# File 'lib/review/latexbuilder.rb', line 617
def image_dummy(id, caption, lines)
warn "image not bound: #{id}", location: location
puts '\begin{reviewdummyimage}'
puts escape("--[[path = #{id} (#{existence(id)})]]--")
lines.each do |line|
puts "\n"
puts detab(line.rstrip)
end
puts macro('label', image_label(id))
@doc_status[:caption] = true
if @book.config.check_version('2', exception: false)
puts macro('caption', compile_inline(caption)) if caption.present?
elsif caption.present?
puts macro('reviewimagecaption', compile_inline(caption))
end
@doc_status[:caption] = nil
puts '\end{reviewdummyimage}'
end
|
#image_ext ⇒ Object
1432
1433
1434
|
# File 'lib/review/latexbuilder.rb', line 1432
def image_ext
'pdf'
end
|
556
557
|
# File 'lib/review/latexbuilder.rb', line 556
def (id, caption)
end
|
#image_image(id, caption = '', metric = nil) ⇒ Object
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
|
# File 'lib/review/latexbuilder.rb', line 580
def image_image(id, caption = '', metric = nil)
captionstr = nil
@doc_status[:caption] = true
if @book.config.check_version('2', exception: false)
captionstr = macro('caption', compile_inline(caption)) + "\n"
else
captionstr = macro('reviewimagecaption', compile_inline(caption)) + "\n"
end
captionstr << macro('label', image_label(id))
@doc_status[:caption] = nil
metrics = parse_metric('latex', metric)
puts "\\begin{reviewimage}%%#{id}"
if caption_top?('image')
puts captionstr
end
command = 'reviewincludegraphics'
if @book.config.check_version('2', exception: false)
command = 'includegraphics'
end
if metrics.present?
puts "\\#{command}[#{metrics}]{#{@chapter.image(id).path}}"
else
puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}"
end
unless caption_top?('image')
puts captionstr
end
puts '\end{reviewimage}'
end
|
#imgtable(lines, id, caption = nil, metric = nil) ⇒ Object
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
|
# File 'lib/review/latexbuilder.rb', line 902
def imgtable(lines, id, caption = nil, metric = nil)
unless @chapter.image_bound?(id)
warn "image not bound: #{id}", location: location
image_dummy(id, caption, lines)
return
end
captionstr = nil
begin
if caption.present?
puts "\\begin{table}[h]%%#{id}"
@doc_status[:caption] = true
captionstr = macro('reviewimgtablecaption', compile_inline(caption))
@doc_status[:caption] = nil
if caption_top?('table')
puts captionstr
end
end
puts macro('label', table_label(id))
rescue ReVIEW::KeyError
app_error "no such table: #{id}"
end
imgtable_image(id, caption, metric)
if caption.present?
unless caption_top?('table')
puts captionstr
end
puts '\end{table}'
end
blank
end
|
#imgtable_image(id, _caption, metric) ⇒ Object
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
|
# File 'lib/review/latexbuilder.rb', line 935
def imgtable_image(id, _caption, metric)
metrics = parse_metric('latex', metric)
puts "\\begin{reviewimage}%%#{id}"
command = 'reviewincludegraphics'
if @book.config.check_version('2', exception: false)
command = 'includegraphics'
end
if metrics.present?
puts "\\#{command}[#{metrics}]{#{@chapter.image(id).path}}"
else
puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}"
end
puts '\end{reviewimage}'
end
|
#indepimage(lines, id, caption = nil, metric = nil) ⇒ Object
Also known as:
numberlessimage
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
|
# File 'lib/review/latexbuilder.rb', line 676
def indepimage(lines, id, caption = nil, metric = nil)
metrics = parse_metric('latex', metric)
captionstr = nil
if caption.present?
@doc_status[:caption] = true
captionstr = macro('reviewindepimagecaption',
%Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)}))
@doc_status[:caption] = nil
end
if @chapter.image(id).path
puts "\\begin{reviewimage}%%#{id}"
if caption_top?('image') && captionstr
puts captionstr
end
command = 'reviewincludegraphics'
if @book.config.check_version('2', exception: false)
command = 'includegraphics'
end
if metrics.present?
puts "\\#{command}[#{metrics}]{#{@chapter.image(id).path}}"
else
puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}"
end
else
warn "image not bound: #{id}", location: location
puts '\begin{reviewdummyimage}'
puts escape("--[[path = #{escape(id)} (#{existence(id)})]]--")
lines.each do |line|
puts "\n"
puts detab(line.rstrip)
end
end
if !caption_top?('image') && captionstr
puts captionstr
end
if @chapter.image(id).path
puts '\end{reviewimage}'
else
puts '\end{reviewdummyimage}'
end
end
|
#index(str) ⇒ Object
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
|
# File 'lib/review/latexbuilder.rb', line 1385
def index(str)
sa = str.split('<<>>')
sa.map! do |item|
if @index_db[item]
escape_mendex_key(escape_index(@index_db[item])) + '@' + escape_mendex_display(escape_index(escape(item)))
elsif item =~ /\A[[:ascii:]]+\Z/ || @index_mecab.nil?
esc_item = escape_mendex_display(escape_index(escape(item)))
if esc_item == item
esc_item
else
"#{escape_mendex_key(escape_index(item))}@#{esc_item}"
end
else
yomi = NKF.nkf('-w --hiragana', @index_mecab.parse(item).force_encoding('UTF-8').chomp)
escape_mendex_key(escape_index(yomi)) + '@' + escape_mendex_display(escape_index(escape(item)))
end
end
"\\index{#{sa.join('!')}}"
end
|
#inline_ami(str) ⇒ Object
1327
1328
1329
|
# File 'lib/review/latexbuilder.rb', line 1327
def inline_ami(str)
macro('reviewami', escape(str))
end
|
#inline_b(str) ⇒ Object
1213
1214
1215
1216
1217
1218
1219
|
# File 'lib/review/latexbuilder.rb', line 1213
def inline_b(str)
if @book.config.check_version('2', exception: false)
macro('textbf', escape(str))
else
macro('reviewbold', escape(str))
end
end
|
#inline_balloon(str) ⇒ Object
1366
1367
1368
|
# File 'lib/review/latexbuilder.rb', line 1366
def inline_balloon(str)
macro('reviewballoon', escape(str))
end
|
#inline_bib(id) ⇒ Object
1276
1277
1278
|
# File 'lib/review/latexbuilder.rb', line 1276
def inline_bib(id)
macro('reviewbibref', "[#{@chapter.bibpaper(id).number}]", bib_label(id))
end
|
#inline_bou(str) ⇒ Object
1171
1172
1173
|
# File 'lib/review/latexbuilder.rb', line 1171
def inline_bou(str)
macro('reviewbou', escape(str))
end
|
#inline_br(_str) ⇒ Object
1222
1223
1224
|
# File 'lib/review/latexbuilder.rb', line 1222
def inline_br(_str)
"\\\\\n"
end
|
#inline_chap(id) ⇒ Object
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
|
# File 'lib/review/latexbuilder.rb', line 1062
def inline_chap(id)
if @book.config['chapterlink']
"\\reviewchapref{#{@book.chapter_index.number(id)}}{chap:#{id}}"
else
@book.chapter_index.number(id)
end
rescue KeyError
app_error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
|
#inline_chapref(id) ⇒ Object
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
|
# File 'lib/review/latexbuilder.rb', line 1050
def inline_chapref(id)
title = super
if @book.config['chapterlink']
"\\reviewchapref{#{title}}{chap:#{id}}"
else
title
end
rescue KeyError
app_error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
|
#inline_code(str) ⇒ Object
1232
1233
1234
1235
1236
1237
1238
|
# File 'lib/review/latexbuilder.rb', line 1232
def inline_code(str)
if @book.config.check_version('2', exception: false)
macro('texttt', escape(str))
else
macro('reviewcode', escape(str))
end
end
|
#inline_column_chap(chapter, id) ⇒ Object
1295
1296
1297
1298
1299
1300
1301
|
# File 'lib/review/latexbuilder.rb', line 1295
def inline_column_chap(chapter, id)
macro('reviewcolumnref',
I18n.t('column', compile_inline(chapter.column(id).caption)),
column_label(id, chapter))
rescue KeyError
app_error "unknown column: #{id}"
end
|
1354
1355
1356
1357
1358
1359
1360
|
# File 'lib/review/latexbuilder.rb', line 1354
def (str)
if @book.config['draft']
macro('pdfcomment', escape(str))
else
''
end
end
|
#inline_del(str) ⇒ Object
1256
1257
1258
|
# File 'lib/review/latexbuilder.rb', line 1256
def inline_del(str)
macro('reviewstrike', escape(str))
end
|
#inline_dtp(_str) ⇒ Object
1226
1227
1228
1229
|
# File 'lib/review/latexbuilder.rb', line 1226
def inline_dtp(_str)
''
end
|
#inline_em(str) ⇒ Object
1315
1316
1317
|
# File 'lib/review/latexbuilder.rb', line 1315
def inline_em(str)
macro('reviewem', escape(str))
end
|
#inline_endnote(id) ⇒ Object
1156
1157
1158
1159
1160
|
# File 'lib/review/latexbuilder.rb', line 1156
def inline_endnote(id)
macro('endnote', compile_inline(@chapter.endnote(id).content.strip))
rescue KeyError
app_error "unknown footnote: #{id}"
end
|
#inline_eq(id) ⇒ Object
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
|
# File 'lib/review/latexbuilder.rb', line 1123
def inline_eq(id)
chapter, id = (id)
if get_chap(chapter).nil?
macro('reviewequationref', I18n.t('format_number_without_chapter', [chapter.equation(id).number]))
else
macro('reviewequationref', I18n.t('format_number', [get_chap(chapter), chapter.equation(id).number]))
end
rescue KeyError
app_error "unknown equation: #{id}"
end
|
#inline_fn(id) ⇒ Object
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
|
# File 'lib/review/latexbuilder.rb', line 1143
def inline_fn(id)
if @book.config['footnotetext']
macro("footnotemark[#{@chapter.(id).number}]", '')
elsif @doc_status[:caption] || @doc_status[:table] || @doc_status[:column] || @doc_status[:dt]
@foottext[id] = @chapter.(id).number
macro('protect\\footnotemark', '')
else
macro('footnote', compile_inline(@chapter.(id).content.strip))
end
rescue KeyError
app_error "unknown footnote: #{id}"
end
|
#inline_hd_chap(chap, id) ⇒ Object
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
|
# File 'lib/review/latexbuilder.rb', line 1280
def inline_hd_chap(chap, id)
n = chap.headline_index.number(id)
if n.present? && chap.number && over_secnolevel?(n)
str = I18n.t('hd_quote', [chap.headline_index.number(id), compile_inline(chap.headline(id).caption)])
else
str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
end
if @book.config['chapterlink']
anchor = n.tr('.', '-')
macro('reviewsecref', str, sec_label(anchor))
else
str
end
end
|
#inline_hi(str) ⇒ Object
1189
1190
1191
|
# File 'lib/review/latexbuilder.rb', line 1189
def inline_hi(str)
index(str)
end
|
#inline_hidx(str) ⇒ Object
1208
1209
1210
|
# File 'lib/review/latexbuilder.rb', line 1208
def inline_hidx(str)
index(str)
end
|
#inline_i(str) ⇒ Object
1194
1195
1196
1197
1198
1199
1200
|
# File 'lib/review/latexbuilder.rb', line 1194
def inline_i(str)
if @book.config.check_version('2', exception: false)
macro('textit', escape(str))
else
macro('reviewit', escape(str))
end
end
|
#inline_icon(id) ⇒ Object
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
|
# File 'lib/review/latexbuilder.rb', line 1331
def inline_icon(id)
if @chapter.image(id).path
command = 'reviewincludegraphics'
if @book.config.check_version('2', exception: false)
command = 'includegraphics'
end
macro(command, @chapter.image(id).path)
else
warn "image not bound: #{id}", location: location
"\\verb|--[[path = #{id} (#{existence(id)})]]--|"
end
end
|
#inline_idx(str) ⇒ Object
1203
1204
1205
|
# File 'lib/review/latexbuilder.rb', line 1203
def inline_idx(str)
escape(str) + index(str)
end
|
#inline_img(id) ⇒ Object
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
|
# File 'lib/review/latexbuilder.rb', line 1112
def inline_img(id)
chapter, id = (id)
if get_chap(chapter).nil?
macro('reviewimageref', I18n.t('format_number_without_chapter', [chapter.image(id).number]), image_label(id, chapter))
else
macro('reviewimageref', I18n.t('format_number', [get_chap(chapter), chapter.image(id).number]), image_label(id, chapter))
end
rescue KeyError
app_error "unknown image: #{id}"
end
|
#inline_ins(str) ⇒ Object
1252
1253
1254
|
# File 'lib/review/latexbuilder.rb', line 1252
def inline_ins(str)
macro('reviewinsert', escape(str))
end
|
#inline_list(id) ⇒ Object
FIXME: use TeX native label/ref.
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
|
# File 'lib/review/latexbuilder.rb', line 1090
def inline_list(id)
chapter, id = (id)
if get_chap(chapter).nil?
macro('reviewlistref', I18n.t('format_number_without_chapter', [chapter.list(id).number]))
else
macro('reviewlistref', I18n.t('format_number', [get_chap(chapter), chapter.list(id).number]))
end
rescue KeyError
app_error "unknown list: #{id}"
end
|
#inline_m(str) ⇒ Object
1180
1181
1182
1183
1184
1185
1186
|
# File 'lib/review/latexbuilder.rb', line 1180
def inline_m(str)
if @book.config.check_version('2', exception: false)
" $#{str}$ "
else
"$#{str}$"
end
end
|
1085
1086
1087
|
# File 'lib/review/latexbuilder.rb', line 1085
def (id)
"\\pageref{#{id}}"
end
|
#inline_raw(str) ⇒ Object
rubocop:disable Lint/UselessMethodDefinition
1303
1304
1305
|
# File 'lib/review/latexbuilder.rb', line 1303
def inline_raw(str) super(str)
end
|
#inline_strong(str) ⇒ Object
1319
1320
1321
|
# File 'lib/review/latexbuilder.rb', line 1319
def inline_strong(str)
macro('reviewstrong', escape(str))
end
|
#inline_sub(str) ⇒ Object
1307
1308
1309
|
# File 'lib/review/latexbuilder.rb', line 1307
def inline_sub(str)
macro('textsubscript', escape(str))
end
|
#inline_sup(str) ⇒ Object
1311
1312
1313
|
# File 'lib/review/latexbuilder.rb', line 1311
def inline_sup(str)
macro('textsuperscript', escape(str))
end
|
#inline_table(id) ⇒ Object
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
|
# File 'lib/review/latexbuilder.rb', line 1101
def inline_table(id)
chapter, id = (id)
if get_chap(chapter).nil?
macro('reviewtableref', I18n.t('format_number_without_chapter', [chapter.table(id).number]), table_label(id, chapter))
else
macro('reviewtableref', I18n.t('format_number', [get_chap(chapter), chapter.table(id).number]), table_label(id, chapter))
end
rescue KeyError
app_error "unknown table: #{id}"
end
|
#inline_tcy(str) ⇒ Object
1362
1363
1364
|
# File 'lib/review/latexbuilder.rb', line 1362
def inline_tcy(str)
macro('reviewtcy', escape(str))
end
|
#inline_title(id) ⇒ Object
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
|
# File 'lib/review/latexbuilder.rb', line 1073
def inline_title(id)
title = super
if @book.config['chapterlink']
"\\reviewchapref{#{title}}{chap:#{id}}"
else
title
end
rescue KeyError
app_error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
|
#inline_tt(str) ⇒ Object
1244
1245
1246
1247
1248
1249
1250
|
# File 'lib/review/latexbuilder.rb', line 1244
def inline_tt(str)
if @book.config.check_version('2', exception: false)
macro('texttt', escape(str))
else
macro('reviewtt', escape(str))
end
end
|
#inline_ttb(str) ⇒ Object
1268
1269
1270
1271
1272
1273
1274
|
# File 'lib/review/latexbuilder.rb', line 1268
def inline_ttb(str)
if @book.config.check_version('2', exception: false)
macro('texttt', macro('textbf', escape(str)))
else
macro('reviewttb', escape(str))
end
end
|
#inline_tti(str) ⇒ Object
1260
1261
1262
1263
1264
1265
1266
|
# File 'lib/review/latexbuilder.rb', line 1260
def inline_tti(str)
if @book.config.check_version('2', exception: false)
macro('texttt', macro('textit', escape(str)))
else
macro('reviewtti', escape(str))
end
end
|
#inline_u(str) ⇒ Object
1323
1324
1325
|
# File 'lib/review/latexbuilder.rb', line 1323
def inline_u(str)
macro('reviewunderline', escape(str))
end
|
#inline_uchar(str) ⇒ Object
1344
1345
1346
1347
1348
1349
1350
1351
1352
|
# File 'lib/review/latexbuilder.rb', line 1344
def inline_uchar(str)
if @texcompiler && @texcompiler.start_with?('platex')
macro('UTF', escape(str))
else
[str.to_i(16)].pack('U')
end
end
|
#label(id) ⇒ Object
1034
1035
1036
|
# File 'lib/review/latexbuilder.rb', line 1034
def label(id)
puts macro('label', id)
end
|
#latextsize(str) ⇒ Object
1428
1429
1430
|
# File 'lib/review/latexbuilder.rb', line 1428
def latextsize(str)
@latex_tsize = str
end
|
#list(lines, id, caption, lang = nil) ⇒ Object
441
442
443
444
445
446
447
|
# File 'lib/review/latexbuilder.rb', line 441
def list(lines, id, caption, lang = nil)
if highlight_listings?
common_code_block_lst(id, lines, 'reviewlistlst', 'caption', caption, lang)
else
common_code_block(id, lines, 'reviewlist', caption, lang) { |line, idx| code_line('list', line, idx, id, caption, lang) }
end
end
|
#listnum(lines, id, caption, lang = nil) ⇒ Object
450
451
452
453
454
455
456
457
|
# File 'lib/review/latexbuilder.rb', line 450
def listnum(lines, id, caption, lang = nil)
first_line_num = line_num
if highlight_listings?
common_code_block_lst(id, lines, 'reviewlistnumlst', 'caption', caption, lang, first_line_num: first_line_num)
else
common_code_block(id, lines, 'reviewlist', caption, lang) { |line, idx| code_line_num('listnum', line, first_line_num, idx, id, caption, lang) }
end
end
|
#load_idxdb(file) ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/review/latexbuilder.rb', line 68
def load_idxdb(file)
table = {}
File.foreach(file) do |line|
key, value = *line.strip.split(/\t+/, 2)
table[key] = value
end
table
end
|
#make_code_block_args(title, caption, lang, first_line_num: 1) ⇒ Object
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
|
# File 'lib/review/latexbuilder.rb', line 525
def make_code_block_args(title, caption, lang, first_line_num: 1)
caption_str = compile_inline((caption || ''))
if title == 'title' && caption_str == '' && @book.config.check_version('2', exception: false)
caption_str = '\relax' end
lexer = if @book.config['highlight'] && @book.config['highlight']['lang']
@book.config['highlight']['lang'] else
''
end
lexer = lang if lang.present?
args = "language={#{lexer}}"
if title == 'title' && caption_str == ''
else
args = "#{title}={#{caption_str}}," + args
end
if first_line_num != 1
args << ",firstnumber=#{first_line_num}"
end
args
end
|
#nodisp_begin(level, _label, caption) ⇒ Object
185
186
187
188
189
190
191
192
193
|
# File 'lib/review/latexbuilder.rb', line 185
def nodisp_begin(level, _label, caption)
if @output.pos == 0
puts macro('clearpage')
else
blank
end
puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
end
|
#nodisp_end(level) ⇒ Object
195
196
|
# File 'lib/review/latexbuilder.rb', line 195
def nodisp_end(level)
end
|
#nofunc_text(str) ⇒ Object
1240
1241
1242
|
# File 'lib/review/latexbuilder.rb', line 1240
def nofunc_text(str)
escape(str)
end
|
1046
1047
1048
|
# File 'lib/review/latexbuilder.rb', line 1046
def noindent
print '\noindent'
end
|
#nonum_begin(level, _label, caption) ⇒ Object
164
165
166
167
168
169
170
|
# File 'lib/review/latexbuilder.rb', line 164
def nonum_begin(level, _label, caption)
blank unless @output.pos == 0
@doc_status[:caption] = true
puts macro(HEADLINE[level] + '*', compile_inline(caption))
@doc_status[:caption] = nil
puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
end
|
#nonum_end(level) ⇒ Object
172
173
|
# File 'lib/review/latexbuilder.rb', line 172
def nonum_end(level)
end
|
#notoc_begin(level, _label, caption) ⇒ Object
175
176
177
178
179
180
|
# File 'lib/review/latexbuilder.rb', line 175
def notoc_begin(level, _label, caption)
blank unless @output.pos == 0
@doc_status[:caption] = true
puts macro(HEADLINE[level] + '*', compile_inline(caption))
@doc_status[:caption] = nil
end
|
#notoc_end(level) ⇒ Object
182
183
|
# File 'lib/review/latexbuilder.rb', line 182
def notoc_end(level)
end
|
336
337
338
339
340
341
342
343
|
# File 'lib/review/latexbuilder.rb', line 336
def ol_begin
blank
puts '\begin{enumerate}'
return true unless @ol_num
puts "\\setcounter{enumi}{#{@ol_num - 1}}"
@ol_num = nil
end
|
355
356
357
358
|
# File 'lib/review/latexbuilder.rb', line 355
def ol_end
puts '\end{enumerate}'
blank
end
|
#ol_item(lines, _num) ⇒ Object
345
346
347
348
349
350
351
352
353
|
# File 'lib/review/latexbuilder.rb', line 345
def ol_item(lines, _num)
str = join_lines_to_paragraph(lines)
unless @book.config['join_lines_by_lang']
str = lines.map(&:chomp).join("\n")
end
str.sub!(/\A(\[)/) { '\lbrack{}' }
puts '\item ' + str
end
|
#olnum(num) ⇒ Object
1436
1437
1438
|
# File 'lib/review/latexbuilder.rb', line 1436
def olnum(num)
@ol_num = num.to_i
end
|
#pagebreak ⇒ Object
1038
1039
1040
|
# File 'lib/review/latexbuilder.rb', line 1038
def pagebreak
puts '\pagebreak'
end
|
#paragraph(lines) ⇒ Object
383
384
385
386
387
388
389
390
391
|
# File 'lib/review/latexbuilder.rb', line 383
def paragraph(lines)
blank
if @book.config['join_lines_by_lang']
puts join_lines_to_paragraph(lines)
else
lines.each { |line| puts line }
end
blank
end
|
393
394
395
|
# File 'lib/review/latexbuilder.rb', line 393
def parasep
puts '\\parasep'
end
|
#parse_metric(type, metric) ⇒ Object
559
560
561
562
563
564
565
566
|
# File 'lib/review/latexbuilder.rb', line 559
def parse_metric(type, metric)
s = super(type, metric)
if @book.config['pdfmaker']['use_original_image_size'] && s.empty? && !metric.present?
return ' ' end
s
end
|
#printendnotes ⇒ Object
1162
1163
1164
1165
1166
1167
|
# File 'lib/review/latexbuilder.rb', line 1162
def printendnotes
@shown_endnotes = true
blank
puts '\theendnotes'
blank
end
|
#quote(lines) ⇒ Object
953
954
955
|
# File 'lib/review/latexbuilder.rb', line 953
def quote(lines)
latex_block('quote', lines)
end
|
#read(lines) ⇒ Object
Also known as:
lead
397
398
399
|
# File 'lib/review/latexbuilder.rb', line 397
def read(lines)
latex_block('quotation', lines)
end
|
100
101
102
103
104
105
106
107
|
# File 'lib/review/latexbuilder.rb', line 100
def result
check_printendnotes
if @chapter.is_a?(ReVIEW::Book::Part) && !@book.config.check_version('2', exception: false)
puts '\end{reviewpart}'
end
solve_nest(@output.string)
end
|
#result_metric(array) ⇒ Object
576
577
578
|
# File 'lib/review/latexbuilder.rb', line 576
def result_metric(array)
array.join(',')
end
|
#separate_tsize(size) ⇒ Object
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
|
# File 'lib/review/latexbuilder.rb', line 823
def separate_tsize(size)
ret = []
s = ''
brace = nil
size.chars.each do |ch|
case ch
when '|'
next
when '{'
brace = true
s << ch
when '}'
brace = nil
s << ch
ret << s
s = ''
else
if brace || s.empty?
s << ch
else
ret << s
s = ch
end
end
end
unless s.empty?
ret << s
end
ret
end
|
#setup_index ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/review/latexbuilder.rb', line 45
def setup_index
@index_db = {}
@index_mecab = nil
return true unless @book.config['pdfmaker']['makeindex']
if @book.config['pdfmaker']['makeindex_dic']
@index_db = load_idxdb(@book.config['pdfmaker']['makeindex_dic'])
end
return true unless @book.config['pdfmaker']['makeindex_mecab']
begin
begin
require 'MeCab'
rescue LoadError
require 'mecab'
end
require 'nkf'
@index_mecab = MeCab::Tagger.new(@book.config['pdfmaker']['makeindex_mecab_opts'])
rescue LoadError
warn 'not found MeCab', location: location
end
end
|
#solve_nest(s) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/review/latexbuilder.rb', line 109
def solve_nest(s)
check_nest
s.gsub("\\end{description}\n\n\x01→dl←\x01\n", "\n").
gsub("\x01→/dl←\x01", "\\end{description}←END\x01").
gsub("\\end{itemize}\n\n\x01→ul←\x01\n", "\n").
gsub("\x01→/ul←\x01", "\\end{itemize}←END\x01").
gsub("\\end{enumerate}\n\n\x01→ol←\x01\n", "\n").
gsub("\x01→/ol←\x01", "\\end{enumerate}←END\x01").
gsub("\\end{description}←END\x01\n\n\\begin{description}", '').
gsub("\\end{itemize}←END\x01\n\n\\begin{itemize}", '').
gsub("\\end{enumerate}←END\x01\n\n\\begin{enumerate}", '').
gsub("←END\x01", '')
end
|
#source(lines, caption = nil, lang = nil) ⇒ Object
548
549
550
551
552
553
554
|
# File 'lib/review/latexbuilder.rb', line 548
def source(lines, caption = nil, lang = nil)
if highlight_listings?
common_code_block_lst(nil, lines, 'reviewsourcelst', 'title', caption, lang)
else
common_code_block(nil, lines, 'reviewsource', caption, lang) { |line, idx| code_line('source', line, idx, nil, caption, lang) }
end
end
|
#table(lines, id = nil, caption = nil) ⇒ Object
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
|
# File 'lib/review/latexbuilder.rb', line 727
def table(lines, id = nil, caption = nil)
if caption.present?
if @book.config.check_version('2', exception: false)
puts "\\begin{table}[h]%%#{id}"
else
puts "\\begin{table}%%#{id}"
end
end
sepidx, rows = parse_table_rows(lines)
begin
if caption_top?('table') && caption.present?
(id, caption)
end
rescue KeyError
app_error "no such table: #{id}"
end
table_begin(rows.first.size)
table_rows(sepidx, rows)
table_end
if caption.present?
unless caption_top?('table')
(id, caption)
end
puts '\end{table}'
end
blank
end
|
#table_begin(ncols) ⇒ Object
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
|
# File 'lib/review/latexbuilder.rb', line 802
def table_begin(ncols)
if @latex_tsize
@tsize = @latex_tsize
end
if @tsize
if @tsize =~ /\A[\d., ]+\Z/
@cellwidth = @tsize.split(/\s*,\s*/)
@cellwidth.collect! { |i| "p{#{i}mm}" }
puts macro('begin', 'reviewtable', '|' + @cellwidth.join('|') + '|')
else
@cellwidth = separate_tsize(@tsize)
puts macro('begin', 'reviewtable', @tsize)
end
else
puts macro('begin', 'reviewtable', (['|'] * (ncols + 1)).join('l'))
@cellwidth = ['l'] * ncols
end
puts '\\hline'
end
|
#table_end ⇒ Object
891
892
893
894
895
896
|
# File 'lib/review/latexbuilder.rb', line 891
def table_end
puts macro('end', 'reviewtable')
@tsize = nil
@latex_tsize = nil
@cellwidth = nil
end
|
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
|
# File 'lib/review/latexbuilder.rb', line 785
def (id, caption)
if id.nil?
if caption.present?
@doc_status[:caption] = true
puts macro('reviewtablecaption*', compile_inline(caption))
@doc_status[:caption] = nil
end
else
if caption.present?
@doc_status[:caption] = true
puts macro('reviewtablecaption', compile_inline(caption))
@doc_status[:caption] = nil
end
puts macro('label', table_label(id))
end
end
|
#table_rows(sepidx, rows) ⇒ Object
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
|
# File 'lib/review/latexbuilder.rb', line 756
def table_rows(sepidx, rows)
if sepidx
sepidx.times do
cno = -1
tr(rows.shift.map do |s|
cno += 1
th(s, @cellwidth[cno])
end)
end
rows.each do |cols|
cno = -1
tr(cols.map do |s|
cno += 1
td(s, @cellwidth[cno])
end)
end
else
rows.each do |cols|
h, *cs = *cols
cno = 0
tr([th(h, @cellwidth[0])] +
cs.map do |s|
cno += 1
td(s, @cellwidth[cno])
end)
end
end
end
|
#table_separator ⇒ Object
856
857
858
|
# File 'lib/review/latexbuilder.rb', line 856
def table_separator
end
|
#td(s, cellwidth = 'l') ⇒ Object
873
874
875
876
877
878
879
880
881
882
883
884
|
# File 'lib/review/latexbuilder.rb', line 873
def td(s, cellwidth = 'l')
if /\\\\/ =~ s
if !@book.config.check_version('2', exception: false) && cellwidth =~ /\{/
s.gsub("\\\\\n", '\\newline{}')
else
macro('shortstack[l]', s)
end
else
s
end
end
|
#texequation(lines, id = nil, caption = '') ⇒ Object
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
|
# File 'lib/review/latexbuilder.rb', line 967
def texequation(lines, id = nil, caption = '')
blank
captionstr = nil
if id
puts macro('begin', 'reviewequationblock')
if get_chap.nil?
captionstr = macro('reviewequationcaption', "#{I18n.t('equation')}#{I18n.t('format_number_header_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
else
captionstr = macro('reviewequationcaption', "#{I18n.t('equation')}#{I18n.t('format_number_header', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
end
end
if caption_top?('equation') && captionstr
puts captionstr
end
puts macro('begin', 'equation*')
lines.each do |line|
puts line
end
puts macro('end', 'equation*')
if !caption_top?('equation') && captionstr
puts captionstr
end
if id
puts macro('end', 'reviewequationblock')
end
blank
end
|
#th(s, cellwidth = 'l') ⇒ Object
860
861
862
863
864
865
866
867
868
869
870
871
|
# File 'lib/review/latexbuilder.rb', line 860
def th(s, cellwidth = 'l')
if /\\\\/ =~ s
if !@book.config.check_version('2', exception: false) && cellwidth =~ /\{/
macro('reviewth', s.gsub("\\\\\n", '\\newline{}'))
else
macro('reviewth', macro('shortstack[l]', s))
end
else
macro('reviewth', s)
end
end
|
886
887
888
889
|
# File 'lib/review/latexbuilder.rb', line 886
def tr(rows)
print rows.join(' & ')
puts ' \\\\ \hline'
end
|
316
317
318
319
|
# File 'lib/review/latexbuilder.rb', line 316
def ul_begin
blank
puts '\begin{itemize}'
end
|
331
332
333
334
|
# File 'lib/review/latexbuilder.rb', line 331
def ul_end
puts '\end{itemize}'
blank
end
|
#ul_item(lines) ⇒ Object
321
322
323
324
325
326
327
328
329
|
# File 'lib/review/latexbuilder.rb', line 321
def ul_item(lines)
str = join_lines_to_paragraph(lines)
unless @book.config['join_lines_by_lang']
str = lines.map(&:chomp).join("\n")
end
str.sub!(/\A(\[)/) { '\lbrack{}' }
puts '\item ' + str
end
|