Class: ReVIEW::LATEXBuilder

Inherits:
Builder show all
Includes:
LaTeXUtils, TextUtils
Defined in:
lib/review/latexbuilder.rb

Constant Summary collapse

HEADLINE =
{
  1 => 'chapter',
  2 => 'section',
  3 => 'subsection',
  4 => 'subsubsection',
  5 => 'paragraph',
  6 => 'subparagraph'
}
BOUTEN =
"・"

Constants inherited from Builder

Builder::CAPTION_TITLES

Instance Method Summary collapse

Methods included from TextUtils

#detab, #split_paragraph

Methods included from LaTeXUtils

#escape_index, #escape_latex, #escape_url, #initialize_metachars, #macro, #unescape_latex

Methods inherited from Builder

#bibpaper, #bind, #compile_inline, #detab, #error, #extract_chapter_id, #get_chap, #graph, #image, #include, #initialize, #inline_column, #inline_hd, #inline_href, #inline_imgref, #inline_include, #inline_kw, #inline_ruby, #parse_metric, #post_paragraph, #pre_paragraph, #raw, #result, #target_name, #text, #ul_item_begin, #ul_item_end, #warn

Constructor Details

This class inherits a constructor from ReVIEW::Builder

Instance Method Details

#bibpaper_bibpaper(id, caption, lines) ⇒ Object



881
882
883
884
# File 'lib/review/latexbuilder.rb', line 881

def bibpaper_bibpaper(id, caption, lines)
  print split_paragraph(lines).join("")
  puts ""
end

#bibpaper_header(id, caption) ⇒ Object



876
877
878
879
# File 'lib/review/latexbuilder.rb', line 876

def bibpaper_header(id, caption)
  puts "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}"
  puts macro('label', bib_label(id))
end

#box(lines, caption = nil) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/review/latexbuilder.rb', line 159

def box(lines, caption = nil)
  blank
  if caption
    puts macro('reviewboxcaption', "#{compile_inline(caption)}")
  end
  puts '\begin{reviewbox}'
  lines.each do |line|
    puts detab(line)
  end
  puts '\end{reviewbox}'
  blank
end

#captionblock(type, lines, caption) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
# File 'lib/review/latexbuilder.rb', line 147

def captionblock(type, lines, caption)
  puts "\\begin{reviewminicolumn}\n"
  unless caption.nil?
    puts "\\reviewminicolumntitle{#{compile_inline(caption)}}\n"
  end

  blocked_lines = split_paragraph(lines)
  puts blocked_lines.join("\n\n")

  puts "\\end{reviewminicolumn}\n"
end

#center(lines) ⇒ Object Also known as: centering



596
597
598
# File 'lib/review/latexbuilder.rb', line 596

def center(lines)
  latex_block 'center', lines
end

#cmd(lines, caption = nil, lang = nil) ⇒ Object



295
296
297
298
299
300
301
302
303
304
# File 'lib/review/latexbuilder.rb', line 295

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) do |line, idx|
      detab(line) + "\n"
    end
  end
end

#column_begin(level, label, caption) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/review/latexbuilder.rb', line 128

def column_begin(level, label, caption)
  blank
  puts "\\begin{reviewcolumn}\n"
  if label
    puts "\\hypertarget{#{column_label(label)}}{}"
  else
    puts "\\hypertarget{#{column_label(caption)}}{}"
  end
  puts macro('reviewcolumnhead', nil, compile_inline(caption))
  if level <= @book.config["toclevel"].to_i
    puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
  end
end

#column_end(level) ⇒ Object



142
143
144
145
# File 'lib/review/latexbuilder.rb', line 142

def column_end(level)
  puts "\\end{reviewcolumn}\n"
  blank
end

#comment(lines, comment = nil) ⇒ Object



633
634
635
636
637
638
639
640
# File 'lib/review/latexbuilder.rb', line 633

def comment(lines, comment = nil)
  lines ||= []
  lines.unshift comment unless comment.blank?
  if @book.config["draft"]
    str = lines.join("")
    puts macro('pdfcomment', escape(str))
  end
end

#common_code_block(id, lines, command, caption, lang) ⇒ Object



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/review/latexbuilder.rb', line 306

def common_code_block(id, lines, command, caption, lang)
  if caption
    if command =~ /emlist/ || command =~ /cmd/
      puts macro(command + 'caption', "#{compile_inline(caption)}")
    else
      begin
        puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}")
      rescue KeyError
        error "no such list: #{id}"
      end
    end
  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)
  blank
end

#common_code_block_lst(id, lines, command, title, caption, lang) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/review/latexbuilder.rb', line 328

def common_code_block_lst(id, lines, command, title, caption, lang)
  caption_str = compile_inline((caption || ""))
  if title == "title" && caption_str == ""
    caption_str = "\\relax" ## dummy charactor to remove lstname
    print "\\vspace{-1.5em}"
  end
  if @book.config["highlight"] && @book.config["highlight"]["lang"]
    lexer = @book.config["highlight"]["lang"] # default setting
  else
    lexer = ""
  end
  lexer = lang if lang.present?
  body = lines.inject(''){|i, j| i + detab(unescape_latex(j)) + "\n"}
  puts "\\begin{"+command+"}["+title+"={"+caption_str+"},language={"+ lexer+"}]"
  print body
  puts "\\end{"+ command + "}"
  blank
end

#compile_href(url, label) ⇒ Object



912
913
914
915
916
917
918
919
920
921
922
# File 'lib/review/latexbuilder.rb', line 912

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



904
905
906
907
908
909
910
# File 'lib/review/latexbuilder.rb', line 904

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



735
736
737
# File 'lib/review/latexbuilder.rb', line 735

def compile_ruby(base, ruby)
  macro('ruby', escape(base), escape(ruby))
end

#dd(lines) ⇒ Object



219
220
221
# File 'lib/review/latexbuilder.rb', line 219

def dd(lines)
  puts lines.join
end

#direct(lines, fmt) ⇒ Object



626
627
628
629
630
631
# File 'lib/review/latexbuilder.rb', line 626

def direct(lines, fmt)
  return unless fmt == 'latex'
  lines.each do |line|
    puts line
  end
end

#dl_beginObject



208
209
210
211
# File 'lib/review/latexbuilder.rb', line 208

def dl_begin
  blank
  puts '\begin{description}'
end

#dl_endObject



223
224
225
226
# File 'lib/review/latexbuilder.rb', line 223

def dl_end
  puts '\end{description}'
  blank
end

#dt(str) ⇒ Object



213
214
215
216
217
# File 'lib/review/latexbuilder.rb', line 213

def dt(str)
  str.sub!(/\[/){'\lbrack{}'}
  str.sub!(/\]/){'\rbrack{}'}
  puts '\item[' + str + '] \mbox{} \\\\'
end

#emlist(lines, caption = nil, lang = nil) ⇒ Object



251
252
253
254
255
256
257
258
259
260
# File 'lib/review/latexbuilder.rb', line 251

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) do |line, idx|
      detab(line) + "\n"
    end
  end
end

#emlistnum(lines, caption = nil, lang = nil) ⇒ Object



262
263
264
265
266
267
268
269
270
271
# File 'lib/review/latexbuilder.rb', line 262

def emlistnum(lines, caption = nil, lang = nil)
  blank
  if highlight_listings?
    common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang)
  else
    common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx|
      detab((idx+1).to_s.rjust(2)+": " + line) + "\n"
    end
  end
end

#extnameObject



30
31
32
# File 'lib/review/latexbuilder.rb', line 30

def extname
  '.tex'
end

#flushright(lines) ⇒ Object



602
603
604
# File 'lib/review/latexbuilder.rb', line 602

def flushright(lines)
  latex_block 'flushright', lines
end

#footnote(id, content) ⇒ Object



714
715
716
717
718
719
# File 'lib/review/latexbuilder.rb', line 714

def footnote(id, content)
  if @book.config["footnotetext"]
    puts macro("footnotetext[#{@chapter.footnote(id).number}]",
               compile_inline(content.strip))
  end
end

#handle_metric(str) ⇒ Object



365
366
367
368
369
370
# File 'lib/review/latexbuilder.rb', line 365

def handle_metric(str)
  if @book.config["image_scale2width"] && str =~ /\Ascale=([\d.]+)\Z/
    return "width=#{$1}\\maxwidth"
  end
  str
end

#headline(level, label, caption) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/review/latexbuilder.rb', line 77

def headline(level, label, caption)
  _, anchor = headline_prefix(level)
  headline_name = HEADLINE[level]
  if @chapter.kind_of? ReVIEW::Book::Part
    headline_name = "part"
  end
  prefix = ""
  if level > @book.config["secnolevel"] || (@chapter.number.to_s.empty? && level > 1)
    prefix = "*"
  end
  blank unless @output.pos == 0
  puts macro(headline_name+prefix, compile_inline(caption))
  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))
  end
rescue
  error "unknown level: #{level}"
end

#hrObject



642
643
644
# File 'lib/review/latexbuilder.rb', line 642

def hr
  puts '\hrule'
end

#image_dummy(id, caption, lines) ⇒ Object



392
393
394
395
396
397
398
399
400
401
402
# File 'lib/review/latexbuilder.rb', line 392

def image_dummy(id, caption, lines)
  puts '\begin{reviewdummyimage}'
  path = @chapter.image(id).path
  puts "--[[path = #{path} (#{existence(id)})]]--"
  lines.each do |line|
    puts detab(line.rstrip)
  end
  puts macro('label', image_label(id))
  puts compile_inline(caption)
  puts '\end{reviewdummyimage}'
end

#image_extObject



932
933
934
# File 'lib/review/latexbuilder.rb', line 932

def image_ext
  "pdf"
end

#image_header(id, caption) ⇒ Object



362
363
# File 'lib/review/latexbuilder.rb', line 362

def image_header(id, caption)
end

#image_image(id, caption, metric) ⇒ Object



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/review/latexbuilder.rb', line 376

def image_image(id, caption, metric)
  metrics = parse_metric("latex", metric)
  # image is always bound here
  puts '\begin{reviewimage}'
  if metrics.present?
    puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
  else
    puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
  end
  if caption.present?
    puts macro('caption', compile_inline(caption))
  end
  puts macro('label', image_label(id))
  puts '\end{reviewimage}'
end

#imgtable(lines, id, caption = nil, metric = nil) ⇒ Object



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# File 'lib/review/latexbuilder.rb', line 556

def imgtable(lines, id, caption = nil, metric = nil)
  if !@chapter.image(id).bound?
    warn "image not bound: #{id}"
    image_dummy id, caption, lines
    return
  end

  begin
    if caption.present?
      @table_caption = true
      puts '\begin{table}[h]'
      puts macro('reviewimgtablecaption', compile_inline(caption))
    end
    puts macro('label', table_label(id))
  rescue ReVIEW::KeyError
    error "no such table: #{id}"
  end
  imgtable_image(id, caption, metric)

  puts '\end{table}' if @table_caption
  @table_caption = nil
  blank
end

#imgtable_image(id, caption, metric) ⇒ Object



580
581
582
583
584
585
586
587
588
589
590
# File 'lib/review/latexbuilder.rb', line 580

def imgtable_image(id, caption, metric)
  metrics = parse_metric("latex", metric)
  # image is always bound here
  puts '\begin{reviewimage}'
  if metrics.present?
    puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
  else
    puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
  end
  puts '\end{reviewimage}'
end

#indepimage(id, caption = nil, metric = nil) ⇒ Object Also known as: numberlessimage



443
444
445
446
447
448
449
450
451
452
453
454
455
456
# File 'lib/review/latexbuilder.rb', line 443

def indepimage(id, caption=nil, metric=nil)
  metrics = parse_metric("latex", metric)
  puts '\begin{reviewimage}'
  if metrics.present?
    puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
  else
    puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
  end
  if caption.present?
    puts macro('reviewindepimagecaption',
               %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}])
  end
  puts '\end{reviewimage}'
end

#index(str) ⇒ Object



886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
# File 'lib/review/latexbuilder.rb', line 886

def index(str)
  str.sub!(/\(\)/, '')
  decl = ''
  if /@\z/ =~ str
    str.chop!
    decl = '|IndexDecl'
  end
  unless /[^ -~]/ =~ str
    if /\^/ =~ str
      macro('index', escape_index(str.gsub(/\^/, '')) + '@' + escape_index(text(str)) + decl)
    else
      '\index{' + escape_index(text(str)) + decl + '}'
    end
  else
    '\index{' + escape_index(@index_db[str]) + '@' + escape_index(text(str)) + '}'
  end
end

#inline_ami(str) ⇒ Object



851
852
853
# File 'lib/review/latexbuilder.rb', line 851

def inline_ami(str)
  macro('reviewami', escape(str))
end

#inline_b(str) ⇒ Object

bold



765
766
767
# File 'lib/review/latexbuilder.rb', line 765

def inline_b(str)
  macro('textbf', escape(str))
end

#inline_bib(id) ⇒ Object



804
805
806
# File 'lib/review/latexbuilder.rb', line 804

def inline_bib(id)
  macro('reviewbibref', "[#{@chapter.bibpaper(id).number}]", bib_label(id))
end

#inline_bou(str) ⇒ Object



731
732
733
# File 'lib/review/latexbuilder.rb', line 731

def inline_bou(str)
  str.split(//).map {|c| macro('ruby', escape(c), macro('textgt', BOUTEN)) }.join('\allowbreak')
end

#inline_br(str) ⇒ Object

line break



770
771
772
# File 'lib/review/latexbuilder.rb', line 770

def inline_br(str)
  "\\\\\n"
end

#inline_chap(id) ⇒ Object



674
675
676
677
678
679
680
681
682
683
# File 'lib/review/latexbuilder.rb', line 674

def inline_chap(id)
  if @book.config["chapterlink"]
    "\\hyperref[chap:#{id}]{#{@book.chapter_index.number(id)}}"
  else
    @book.chapter_index.number(id)
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end

#inline_chapref(id) ⇒ Object



662
663
664
665
666
667
668
669
670
671
672
# File 'lib/review/latexbuilder.rb', line 662

def inline_chapref(id)
  title = super
  if @book.config["chapterlink"]
    "\\hyperref[chap:#{id}]{#{title}}"
  else
    title
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end

#inline_code(str) ⇒ Object

@<code> is same as @<tt>



780
781
782
# File 'lib/review/latexbuilder.rb', line 780

def inline_code(str)
  macro('texttt', escape(str))
end

#inline_column_chap(chapter, id) ⇒ Object



823
824
825
# File 'lib/review/latexbuilder.rb', line 823

def inline_column_chap(chapter, id)
  macro('reviewcolumnref', "#{chapter.column(id).caption}", column_label(id))
end

#inline_comment(str) ⇒ Object



864
865
866
867
868
869
870
# File 'lib/review/latexbuilder.rb', line 864

def inline_comment(str)
  if @book.config["draft"]
    macro('pdfcomment', escape(str))
  else
    ""
  end
end

#inline_del(str) ⇒ Object



792
793
794
# File 'lib/review/latexbuilder.rb', line 792

def inline_del(str)
  macro('reviewstrike', escape(str))
end

#inline_dtp(str) ⇒ Object



774
775
776
777
# File 'lib/review/latexbuilder.rb', line 774

def inline_dtp(str)
  # ignore
  ""
end

#inline_em(str) ⇒ Object



839
840
841
# File 'lib/review/latexbuilder.rb', line 839

def inline_em(str)
  macro('reviewem', escape(str))
end

#inline_fn(id) ⇒ Object



721
722
723
724
725
726
727
# File 'lib/review/latexbuilder.rb', line 721

def inline_fn(id)
  if @book.config["footnotetext"]
    macro("footnotemark[#{@chapter.footnote(id).number}]", "")
  else
    macro('footnote', compile_inline(@chapter.footnote(id).content.strip))
  end
end

#inline_hd_chap(chap, id) ⇒ Object



808
809
810
811
812
813
814
815
816
817
818
819
820
821
# File 'lib/review/latexbuilder.rb', line 808

def inline_hd_chap(chap, id)
  n = chap.headline_index.number(id)
  if chap.number and @book.config["secnolevel"] >= n.split('.').size
    str = I18n.t("chapter_quote", "#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}")
  else
    str = I18n.t("chapter_quote", compile_inline(chap.headline(id).caption))
  end
  if @book.config["chapterlink"]
    anchor = n.gsub(/\./, "-")
    macro('reviewsecref', str, sec_label(anchor))
  else
    str
  end
end

#inline_hi(str) ⇒ Object

hidden index



745
746
747
# File 'lib/review/latexbuilder.rb', line 745

def inline_hi(str)
  index(str)
end

#inline_hidx(str) ⇒ Object

hidden index??



760
761
762
# File 'lib/review/latexbuilder.rb', line 760

def inline_hidx(str)
  index(str)
end

#inline_i(str) ⇒ Object

index -> italic



750
751
752
# File 'lib/review/latexbuilder.rb', line 750

def inline_i(str)
  macro('textit', escape(str))
end

#inline_icon(id) ⇒ Object



855
856
857
# File 'lib/review/latexbuilder.rb', line 855

def inline_icon(id)
  macro('includegraphics', @chapter.image(id).path)
end

#inline_idx(str) ⇒ Object

index



755
756
757
# File 'lib/review/latexbuilder.rb', line 755

def inline_idx(str)
  escape(str) + index(str)
end

#inline_img(id) ⇒ Object



709
710
711
712
# File 'lib/review/latexbuilder.rb', line 709

def inline_img(id)
  chapter, id = extract_chapter_id(id)
  macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}", image_label(id, chapter))
end

#inline_list(id) ⇒ Object

FIXME: use TeX native label/ref.



699
700
701
702
# File 'lib/review/latexbuilder.rb', line 699

def inline_list(id)
  chapter, id = extract_chapter_id(id)
  macro('reviewlistref', "#{chapter.number}.#{chapter.list(id).number}")
end

#inline_m(str) ⇒ Object

math



740
741
742
# File 'lib/review/latexbuilder.rb', line 740

def inline_m(str)
  " $#{str}$ "
end

#inline_raw(str) ⇒ Object



827
828
829
# File 'lib/review/latexbuilder.rb', line 827

def inline_raw(str)
  super(str)
end

#inline_strong(str) ⇒ Object



843
844
845
# File 'lib/review/latexbuilder.rb', line 843

def inline_strong(str)
  macro('reviewstrong', escape(str))
end

#inline_sub(str) ⇒ Object



831
832
833
# File 'lib/review/latexbuilder.rb', line 831

def inline_sub(str)
  macro('textsubscript', escape(str))
end

#inline_sup(str) ⇒ Object



835
836
837
# File 'lib/review/latexbuilder.rb', line 835

def inline_sup(str)
  macro('textsuperscript', escape(str))
end

#inline_table(id) ⇒ Object



704
705
706
707
# File 'lib/review/latexbuilder.rb', line 704

def inline_table(id)
  chapter, id = extract_chapter_id(id)
  macro('reviewtableref', "#{chapter.number}.#{chapter.table(id).number}", table_label(id, chapter))
end

#inline_tcy(str) ⇒ Object



872
873
874
# File 'lib/review/latexbuilder.rb', line 872

def inline_tcy(str)
  macro('rensuji', escape(str))
end

#inline_title(id) ⇒ Object



685
686
687
688
689
690
691
692
693
694
695
# File 'lib/review/latexbuilder.rb', line 685

def inline_title(id)
  title = super
  if @book.config["chapterlink"]
    "\\hyperref[chap:#{id}]{#{title}}"
  else
    title
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end

#inline_tt(str) ⇒ Object



788
789
790
# File 'lib/review/latexbuilder.rb', line 788

def inline_tt(str)
  macro('texttt', escape(str))
end

#inline_ttb(str) ⇒ Object



800
801
802
# File 'lib/review/latexbuilder.rb', line 800

def inline_ttb(str)
  macro('texttt', macro('textbf', escape(str)))
end

#inline_tti(str) ⇒ Object



796
797
798
# File 'lib/review/latexbuilder.rb', line 796

def inline_tti(str)
  macro('texttt', macro('textit', escape(str)))
end

#inline_u(str) ⇒ Object



847
848
849
# File 'lib/review/latexbuilder.rb', line 847

def inline_u(str)
  macro('reviewunderline', escape(str))
end

#inline_uchar(str) ⇒ Object



859
860
861
862
# File 'lib/review/latexbuilder.rb', line 859

def inline_uchar(str)
  # with otf package
  macro('UTF', escape(str))
end

#label(id) ⇒ Object



646
647
648
# File 'lib/review/latexbuilder.rb', line 646

def label(id)
  puts macro('label', id)
end

#latextsize(str) ⇒ Object



928
929
930
# File 'lib/review/latexbuilder.rb', line 928

def latextsize(str)
  @latex_tsize = str
end

#linebreakObject



654
655
656
# File 'lib/review/latexbuilder.rb', line 654

def linebreak
  puts '\\\\'
end

#list(lines, id, caption, lang = nil) ⇒ Object

override Builder#list



274
275
276
277
278
279
280
281
282
# File 'lib/review/latexbuilder.rb', line 274

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) do |line, idx|
      detab(line) + "\n"
    end
  end
end

#listnum(lines, id, caption, lang = nil) ⇒ Object

override Builder#listnum



285
286
287
288
289
290
291
292
293
# File 'lib/review/latexbuilder.rb', line 285

def listnum(lines, id, caption, lang = nil)
  if highlight_listings?
    common_code_block_lst(id, lines, 'reviewlistnumlst', 'caption', caption, lang)
  else
    common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx|
      detab((idx+1).to_s.rjust(2)+": " + line) + "\n"
    end
  end
end

#nodisp_begin(level, label, caption) ⇒ Object



118
119
120
121
122
123
# File 'lib/review/latexbuilder.rb', line 118

def nodisp_begin(level, label, caption)
  blank unless @output.pos == 0
  puts macro('clearpage') if @output.pos == 0
  puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
  # FIXME: headings
end

#nodisp_end(level) ⇒ Object



125
126
# File 'lib/review/latexbuilder.rb', line 125

def nodisp_end(level)
end

#nofunc_text(str) ⇒ Object



784
785
786
# File 'lib/review/latexbuilder.rb', line 784

def nofunc_text(str)
  escape(str)
end

#noindentObject



658
659
660
# File 'lib/review/latexbuilder.rb', line 658

def noindent
  print '\noindent'
end

#nonum_begin(level, label, caption) ⇒ Object



101
102
103
104
105
# File 'lib/review/latexbuilder.rb', line 101

def nonum_begin(level, label, caption)
  blank unless @output.pos == 0
  puts macro(HEADLINE[level]+"*", compile_inline(caption))
  puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
end

#nonum_end(level) ⇒ Object



107
108
# File 'lib/review/latexbuilder.rb', line 107

def nonum_end(level)
end

#notoc_begin(level, label, caption) ⇒ Object



110
111
112
113
# File 'lib/review/latexbuilder.rb', line 110

def notoc_begin(level, label, caption)
  blank unless @output.pos == 0
  puts macro(HEADLINE[level]+"*", compile_inline(caption))
end

#notoc_end(level) ⇒ Object



115
116
# File 'lib/review/latexbuilder.rb', line 115

def notoc_end(level)
end

#ol_beginObject



188
189
190
191
192
193
194
195
# File 'lib/review/latexbuilder.rb', line 188

def ol_begin
  blank
  puts '\begin{enumerate}'
  if @ol_num
    puts "\\setcounter{enumi}{#{@ol_num - 1}}"
    @ol_num = nil
  end
end

#ol_endObject



203
204
205
206
# File 'lib/review/latexbuilder.rb', line 203

def ol_end
  puts '\end{enumerate}'
  blank
end

#ol_item(lines, num) ⇒ Object



197
198
199
200
201
# File 'lib/review/latexbuilder.rb', line 197

def ol_item(lines, num)
  str = lines.join
  str.sub!(/\A(\[)/){'\lbrack{}'}
  puts '\item ' + str
end

#olnum(num) ⇒ Object



936
937
938
# File 'lib/review/latexbuilder.rb', line 936

def olnum(num)
  @ol_num = num.to_i
end

#pagebreakObject



650
651
652
# File 'lib/review/latexbuilder.rb', line 650

def pagebreak
  puts '\pagebreak'
end

#paragraph(lines) ⇒ Object



228
229
230
231
232
233
234
# File 'lib/review/latexbuilder.rb', line 228

def paragraph(lines)
  blank
  lines.each do |line|
    puts line
  end
  blank
end

#parasepObject



236
237
238
# File 'lib/review/latexbuilder.rb', line 236

def parasep
  puts '\\parasep'
end

#quote(lines) ⇒ Object



592
593
594
# File 'lib/review/latexbuilder.rb', line 592

def quote(lines)
  latex_block 'quote', lines
end

#read(lines) ⇒ Object Also known as: lead



240
241
242
# File 'lib/review/latexbuilder.rb', line 240

def read(lines)
  latex_block 'quotation', lines
end

#result_metric(array) ⇒ Object



372
373
374
# File 'lib/review/latexbuilder.rb', line 372

def result_metric(array)
  "#{array.join(',')}"
end

#source(lines, caption, lang = nil) ⇒ Object



347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/review/latexbuilder.rb', line 347

def source(lines, caption, lang = nil)
  if highlight_listings?
    common_code_block_lst(nil, lines, 'reviewlistlst', 'title', caption, lang)
  else
    puts '\begin{reviewlist}'
    puts macro('reviewlistcaption', compile_inline(caption))
    lines.each do |line|
      puts detab(line)
    end
    puts '\end{reviewlist}'
    puts ""
  end
end

#table(lines, id = nil, caption = nil) ⇒ Object



460
461
462
463
464
465
466
467
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
# File 'lib/review/latexbuilder.rb', line 460

def table(lines, id = nil, caption = nil)
  rows = []
  sepidx = nil
  lines.each_with_index do |line, idx|
    if /\A[\=\{\-\}]{12}/ =~ line
      # just ignore
      #error "too many table separator" if sepidx
      sepidx ||= idx
      next
    end
    rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
  end
  rows = adjust_n_cols(rows)

  begin
    table_header id, caption unless caption.nil?
  rescue KeyError
    error "no such table: #{id}"
  end
  return if rows.empty?
  table_begin rows.first.size
  if sepidx
    sepidx.times do
      tr rows.shift.map {|s| th(s) }
    end
    rows.each do |cols|
      tr cols.map {|s| td(s) }
    end
  else
    rows.each do |cols|
      h, *cs = *cols
      tr [th(h)] + cs.map {|s| td(s) }
    end
  end
  table_end
end

#table_begin(ncols) ⇒ Object



506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/review/latexbuilder.rb', line 506

def table_begin(ncols)
  if @latex_tsize
    puts macro('begin', 'reviewtable', @latex_tsize)
  elsif @tsize
    cellwidth = @tsize.split(/\s*,\s*/)
    puts macro('begin', 'reviewtable', '|'+cellwidth.collect{|i| "p{#{i}mm}"}.join('|')+'|')
  else
    puts macro('begin', 'reviewtable', (['|'] * (ncols + 1)).join('l'))
  end
  puts '\hline'
  @tsize = nil
  @latex_tsize = nil
end

#table_endObject



547
548
549
550
551
552
553
554
# File 'lib/review/latexbuilder.rb', line 547

def table_end
  puts macro('end', 'reviewtable')
  if @table_caption
    puts '\end{table}'
  end
  @table_caption = nil
  blank
end

#table_header(id, caption) ⇒ Object



497
498
499
500
501
502
503
504
# File 'lib/review/latexbuilder.rb', line 497

def table_header(id, caption)
  if caption.present?
    @table_caption = true
    puts '\begin{table}[h]'
    puts macro('reviewtablecaption', compile_inline(caption))
  end
  puts macro('label', table_label(id))
end

#table_separatorObject



520
521
522
# File 'lib/review/latexbuilder.rb', line 520

def table_separator
  #puts '\hline'
end

#td(s) ⇒ Object



533
534
535
536
537
538
539
540
# File 'lib/review/latexbuilder.rb', line 533

def td(s)
  ## use shortstack for @<br>
  if /\\\\/ =~ s
    macro('shortstack[l]', s)
  else
    s
  end
end

#texequation(lines) ⇒ Object



606
607
608
609
610
611
612
613
614
# File 'lib/review/latexbuilder.rb', line 606

def texequation(lines)
  blank
  puts macro('begin','equation*')
  lines.each do |line|
    puts unescape_latex(line)
  end
  puts macro('end', 'equation*')
  blank
end

#th(s) ⇒ Object



524
525
526
527
528
529
530
531
# File 'lib/review/latexbuilder.rb', line 524

def th(s)
  ## use shortstack for @<br>
  if /\\\\/i =~ s
    macro('reviewth', macro('shortstack[l]', s))
  else
    macro('reviewth', s)
  end
end

#tr(rows) ⇒ Object



542
543
544
545
# File 'lib/review/latexbuilder.rb', line 542

def tr(rows)
  print rows.join(' & ')
  puts ' \\\\  \hline'
end

#tsize(str) ⇒ Object



924
925
926
# File 'lib/review/latexbuilder.rb', line 924

def tsize(str)
  @tsize = str
end

#ul_beginObject



172
173
174
175
# File 'lib/review/latexbuilder.rb', line 172

def ul_begin
  blank
  puts '\begin{itemize}'
end

#ul_endObject



183
184
185
186
# File 'lib/review/latexbuilder.rb', line 183

def ul_end
  puts '\end{itemize}'
  blank
end

#ul_item(lines) ⇒ Object



177
178
179
180
181
# File 'lib/review/latexbuilder.rb', line 177

def ul_item(lines)
  str = lines.join
  str.sub!(/\A(\[)/){'\lbrack{}'}
  puts '\item ' + str
end