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 included from LaTeXUtils

ReVIEW::LaTeXUtils::METACHARS, ReVIEW::LaTeXUtils::METACHARS_INVERT, ReVIEW::LaTeXUtils::METACHARS_RE

Constants inherited from Builder

Builder::CAPTION_TITLES

Instance Method Summary collapse

Methods included from TextUtils

#convert_inencoding, #convert_outencoding, #detab, #split_paragraph

Methods included from LaTeXUtils

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

Methods inherited from Builder

#bibpaper, #bind, #compile_inline, #detab, #error, #extract_chapter_id, #get_chap, #graph, #handle_metric, #image, #include, #initialize, #inline_hd, #inline_href, #inline_include, #inline_kw, #inline_ruby, #list, #listnum, #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



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

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

#bibpaper_header(id, caption) ⇒ Object



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

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



152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/review/latexbuilder.rb', line 152

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



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/review/latexbuilder.rb', line 134

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

  if @book.config["deprecated-blocklines"].nil?
    blocked_lines = split_paragraph(lines)
    puts blocked_lines.join("\n\n")
  else
    lines.each do |line|
      puts line
    end
  end

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

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



510
511
512
# File 'lib/review/latexbuilder.rb', line 510

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

#cmd(lines, caption = nil) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/review/latexbuilder.rb', line 275

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

#column_begin(level, label, caption) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/review/latexbuilder.rb', line 115

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



129
130
131
132
# File 'lib/review/latexbuilder.rb', line 129

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

#comment(lines, comment = nil) ⇒ Object



553
554
555
556
557
558
559
560
# File 'lib/review/latexbuilder.rb', line 553

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

#compile_href(url, label) ⇒ Object



828
829
830
831
832
833
834
835
836
837
838
# File 'lib/review/latexbuilder.rb', line 828

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



820
821
822
823
824
825
826
# File 'lib/review/latexbuilder.rb', line 820

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



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

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

#dd(lines) ⇒ Object



212
213
214
# File 'lib/review/latexbuilder.rb', line 212

def dd(lines)
  puts lines.join
end

#direct(lines, fmt) ⇒ Object



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

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

#dl_beginObject



201
202
203
204
# File 'lib/review/latexbuilder.rb', line 201

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

#dl_endObject



216
217
218
219
# File 'lib/review/latexbuilder.rb', line 216

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

#dt(str) ⇒ Object



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

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

#emlist(lines, caption = nil) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/review/latexbuilder.rb', line 239

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

#emlistnum(lines, caption = nil) ⇒ Object



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

def emlistnum(lines, caption = nil)
  blank
  if caption
    puts macro('reviewemlistcaption', "#{compile_inline(caption)}")
  end
  puts '\begin{reviewemlist}'
  lines.each_with_index do |line, i|
    puts detab((i+1).to_s.rjust(2) + ": " + line)
  end
  puts '\end{reviewemlist}'
  blank
end

#extnameObject



32
33
34
# File 'lib/review/latexbuilder.rb', line 32

def extname
  '.tex'
end

#flushright(lines) ⇒ Object



516
517
518
# File 'lib/review/latexbuilder.rb', line 516

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

#footnote(id, content) ⇒ Object



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

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

#headline(level, label, caption) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/review/latexbuilder.rb', line 87

def headline(level, label, caption)
  _, anchor = headline_prefix(level)
  prefix = ""
  if level > @book.config["secnolevel"] || (@chapter.number.to_s.empty? && level > 1)
    prefix = "*"
  end
  blank unless @output.pos == 0
  puts macro(HEADLINE[level]+prefix, compile_inline(caption))
  if prefix == "*" && level <= @book.config["toclevel"].to_i
    puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{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



562
563
564
# File 'lib/review/latexbuilder.rb', line 562

def hr
  puts '\hrule'
end

#image_dummy(id, caption, lines) ⇒ Object



343
344
345
346
347
348
349
350
351
352
353
# File 'lib/review/latexbuilder.rb', line 343

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



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

def image_ext
  "pdf"
end

#image_header(id, caption) ⇒ Object



320
321
# File 'lib/review/latexbuilder.rb', line 320

def image_header(id, caption)
end

#image_image(id, caption, metric) ⇒ Object



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

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

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



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

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



802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
# File 'lib/review/latexbuilder.rb', line 802

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



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

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

#inline_b(str) ⇒ Object

bold



685
686
687
# File 'lib/review/latexbuilder.rb', line 685

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

#inline_bib(id) ⇒ Object



724
725
726
# File 'lib/review/latexbuilder.rb', line 724

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

#inline_bou(str) ⇒ Object



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

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

#inline_br(str) ⇒ Object

line break



690
691
692
# File 'lib/review/latexbuilder.rb', line 690

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

#inline_chap(id) ⇒ Object



594
595
596
597
598
599
600
601
602
603
# File 'lib/review/latexbuilder.rb', line 594

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

#inline_chapref(id) ⇒ Object



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

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>



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

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

#inline_column(id) ⇒ Object



743
744
745
# File 'lib/review/latexbuilder.rb', line 743

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

#inline_comment(str) ⇒ Object



784
785
786
787
788
789
790
# File 'lib/review/latexbuilder.rb', line 784

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

#inline_del(str) ⇒ Object



712
713
714
# File 'lib/review/latexbuilder.rb', line 712

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

#inline_dtp(str) ⇒ Object



694
695
696
697
# File 'lib/review/latexbuilder.rb', line 694

def inline_dtp(str)
  # ignore
  ""
end

#inline_em(str) ⇒ Object



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

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

#inline_fn(id) ⇒ Object



641
642
643
644
645
646
647
# File 'lib/review/latexbuilder.rb', line 641

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



728
729
730
731
732
733
734
735
736
737
738
739
740
741
# File 'lib/review/latexbuilder.rb', line 728

def inline_hd_chap(chap, id)
  n = chap.headline_index.number(id)
  if chap.number and @book.config["secnolevel"] >= n.split('.').size
    str = "#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}"
  else
    str = "#{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



665
666
667
# File 'lib/review/latexbuilder.rb', line 665

def inline_hi(str)
  index(str)
end

#inline_hidx(str) ⇒ Object

hidden index??



680
681
682
# File 'lib/review/latexbuilder.rb', line 680

def inline_hidx(str)
  index(str)
end

#inline_i(str) ⇒ Object

index -> italic



670
671
672
# File 'lib/review/latexbuilder.rb', line 670

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

#inline_icon(id) ⇒ Object



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

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

#inline_idx(str) ⇒ Object

index



675
676
677
# File 'lib/review/latexbuilder.rb', line 675

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

#inline_img(id) ⇒ Object



629
630
631
632
# File 'lib/review/latexbuilder.rb', line 629

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.



619
620
621
622
# File 'lib/review/latexbuilder.rb', line 619

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

#inline_m(str) ⇒ Object

math



660
661
662
# File 'lib/review/latexbuilder.rb', line 660

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

#inline_raw(str) ⇒ Object



747
748
749
# File 'lib/review/latexbuilder.rb', line 747

def inline_raw(str)
  super(str)
end

#inline_strong(str) ⇒ Object



763
764
765
# File 'lib/review/latexbuilder.rb', line 763

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

#inline_sub(str) ⇒ Object



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

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

#inline_sup(str) ⇒ Object



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

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

#inline_table(id) ⇒ Object



624
625
626
627
# File 'lib/review/latexbuilder.rb', line 624

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

#inline_title(id) ⇒ Object



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

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



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

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

#inline_ttb(str) ⇒ Object



720
721
722
# File 'lib/review/latexbuilder.rb', line 720

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

#inline_tti(str) ⇒ Object



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

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

#inline_u(str) ⇒ Object



767
768
769
# File 'lib/review/latexbuilder.rb', line 767

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

#inline_uchar(str) ⇒ Object



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

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

#label(id) ⇒ Object



566
567
568
# File 'lib/review/latexbuilder.rb', line 566

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

#latextsize(str) ⇒ Object



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

def latextsize(str)
  @latex_tsize = str
end

#linebreakObject



574
575
576
# File 'lib/review/latexbuilder.rb', line 574

def linebreak
  puts '\\\\'
end

#list_body(id, lines) ⇒ Object



292
293
294
295
296
297
298
299
# File 'lib/review/latexbuilder.rb', line 292

def list_body(id, lines)
  puts '\begin{reviewlist}'
  lines.each do |line|
    puts detab(line)
  end
  puts '\end{reviewlist}'
  puts ""
end

#list_header(id, caption) ⇒ Object



288
289
290
# File 'lib/review/latexbuilder.rb', line 288

def list_header(id, caption)
  puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}")
end

#listnum_body(lines) ⇒ Object



265
266
267
268
269
270
271
272
273
# File 'lib/review/latexbuilder.rb', line 265

def listnum_body(lines)
  puts '\begin{reviewlist}'
  lines.each_with_index do |line, i|
    puts detab((i+1).to_s.rjust(2) + ": " + line)
  end
  puts '\end{reviewlist}'
  blank

end

#nofunc_text(str) ⇒ Object



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

def nofunc_text(str)
  escape(str)
end

#noindentObject



578
579
580
# File 'lib/review/latexbuilder.rb', line 578

def noindent
  print '\noindent'
end

#nonum_begin(level, label, caption) ⇒ Object



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

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

#nonum_end(level) ⇒ Object



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

def nonum_end(level)
end

#ol_beginObject



181
182
183
184
185
186
187
188
# File 'lib/review/latexbuilder.rb', line 181

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

#ol_endObject



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

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

#ol_item(lines, num) ⇒ Object



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

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

#olnum(num) ⇒ Object



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

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

#pagebreakObject



570
571
572
# File 'lib/review/latexbuilder.rb', line 570

def pagebreak
  puts '\pagebreak'
end

#paragraph(lines) ⇒ Object



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

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

#parasepObject



229
230
231
# File 'lib/review/latexbuilder.rb', line 229

def parasep
  puts '\\parasep'
end

#quote(lines) ⇒ Object



506
507
508
# File 'lib/review/latexbuilder.rb', line 506

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

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



233
234
235
# File 'lib/review/latexbuilder.rb', line 233

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

#result_metric(array) ⇒ Object



323
324
325
# File 'lib/review/latexbuilder.rb', line 323

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

#source(lines, caption) ⇒ Object



301
302
303
304
305
306
307
# File 'lib/review/latexbuilder.rb', line 301

def source(lines, caption)
  puts '\begin{reviewlist}'
  source_header caption
  source_body lines
  puts '\end{reviewlist}'
  puts ""
end

#source_body(lines) ⇒ Object



313
314
315
316
317
# File 'lib/review/latexbuilder.rb', line 313

def source_body(lines)
  lines.each do |line|
    puts detab(line)
  end
end

#source_header(caption) ⇒ Object



309
310
311
# File 'lib/review/latexbuilder.rb', line 309

def source_header(caption)
  puts macro('reviewlistcaption', compile_inline(caption))
end

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



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/review/latexbuilder.rb', line 410

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



456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/review/latexbuilder.rb', line 456

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



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

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

#table_header(id, caption) ⇒ Object



447
448
449
450
451
452
453
454
# File 'lib/review/latexbuilder.rb', line 447

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



470
471
472
# File 'lib/review/latexbuilder.rb', line 470

def table_separator
  #puts '\hline'
end

#td(s) ⇒ Object



483
484
485
486
487
488
489
490
# File 'lib/review/latexbuilder.rb', line 483

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

#texequation(lines) ⇒ Object



520
521
522
523
524
525
526
527
528
# File 'lib/review/latexbuilder.rb', line 520

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



474
475
476
477
478
479
480
481
# File 'lib/review/latexbuilder.rb', line 474

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



492
493
494
495
# File 'lib/review/latexbuilder.rb', line 492

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

#tsize(str) ⇒ Object



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

def tsize(str)
  @tsize = str
end

#ul_beginObject



165
166
167
168
# File 'lib/review/latexbuilder.rb', line 165

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

#ul_endObject



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

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

#ul_item(lines) ⇒ Object



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

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