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::MATACHARS, ReVIEW::LaTeXUtils::MATACHARS_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, #entries, #error, #extract_chapter_id, #find_pathes, #get_chap, #graph, #handle_metric, #image, #include, #initialize, #inline_hd, #inline_href, #inline_include, #inline_kw, #list, #listnum, #parse_metric, #post_paragraph, #pre_paragraph, #raw, #result, #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



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

def bibpaper_bibpaper(id, caption, lines)
  lines.each do |line|
    puts detab(line)
  end
end

#bibpaper_header(id, caption) ⇒ Object



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

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

#captionblock(type, lines, caption) ⇒ Object



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

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

  if ReVIEW.book.param["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



486
487
488
# File 'lib/review/latexbuilder.rb', line 486

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

#cmd(lines, caption = nil) ⇒ Object



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

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

#column_begin(level, label, caption) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/review/latexbuilder.rb', line 102

def column_begin(level, label, caption)
  blank
  ## puts '\vspace{2zw}'
##      puts '\begin{center}'
##      puts '\begin{minipage}{1.0\linewidth}'
##      puts '\begin{framed}'
##      puts '\setlength{\FrameSep}{1zw}'

##      nonum_begin(3, label, caption)   # FIXME

  puts "\\begin{reviewcolumn}\n"
  puts macro('reviewcolumnhead', nil, compile_inline(caption))

end

#column_end(level) ⇒ Object



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

def column_end(level)
##      puts '\end{framed}'
##      puts '\end{minipage}'
##      puts '\end{center}'
##      ## puts '\vspace{2zw}'
  puts "\\end{reviewcolumn}\n"
  blank
end

#comment(str) ⇒ Object



529
530
531
532
533
# File 'lib/review/latexbuilder.rb', line 529

def comment(str)
  if ReVIEW.book.param["draft"]
    puts macro('pdfcomment', escape(str))
  end
end

#compile_href(url, label) ⇒ Object



785
786
787
788
789
790
791
792
793
794
795
# File 'lib/review/latexbuilder.rb', line 785

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



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

def compile_kw(word, alt)
  if alt
    macro('reviewkw', escape(word)) + "(#{escape(alt.strip)})"
  else
    macro('reviewkw', escape(word))
  end
end

#dd(lines) ⇒ Object



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

def dd(lines)
  puts lines.join
end

#direct(lines, fmt) ⇒ Object



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

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

#dl_beginObject



180
181
182
183
# File 'lib/review/latexbuilder.rb', line 180

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

#dl_endObject



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

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

#dt(str) ⇒ Object



185
186
187
188
189
# File 'lib/review/latexbuilder.rb', line 185

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

#emlist(lines, caption = nil) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/review/latexbuilder.rb', line 218

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

#emlistnum(lines, caption = nil) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/review/latexbuilder.rb', line 233

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

#extnameObject



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

def extname
  '.tex'
end

#flushright(lines) ⇒ Object



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

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

#footnote(id, content) ⇒ Object



605
606
607
608
609
610
# File 'lib/review/latexbuilder.rb', line 605

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

#headline(level, label, caption) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/review/latexbuilder.rb', line 77

def headline(level, label, caption)
  prefix = ""
  if level > ReVIEW.book.param["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 <= ReVIEW.book.param["toclevel"].to_i
    puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
  end
  if level == 1
    puts macro('label', chapter_label)
  end
rescue
  error "unknown level: #{level}"
end

#hrObject



535
536
537
# File 'lib/review/latexbuilder.rb', line 535

def hr
  puts '\hrule'
end

#image_dummy(id, caption, lines) ⇒ Object



334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/review/latexbuilder.rb', line 334

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

#image_extObject



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

def image_ext
  "svg"
end

#image_header(id, caption) ⇒ Object



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

def image_header(id, caption)
end

#image_image(id, caption, metric) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/review/latexbuilder.rb', line 318

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



368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/review/latexbuilder.rb', line 368

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



759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/review/latexbuilder.rb', line 759

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



728
729
730
# File 'lib/review/latexbuilder.rb', line 728

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

#inline_b(str) ⇒ Object

bold



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

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

#inline_bib(id) ⇒ Object



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

def inline_bib(id)
  "[#{@chapter.bibpaper(id).number}]"
end

#inline_bou(str) ⇒ Object



622
623
624
# File 'lib/review/latexbuilder.rb', line 622

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

#inline_br(str) ⇒ Object

line break



662
663
664
# File 'lib/review/latexbuilder.rb', line 662

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

#inline_chap(id) ⇒ Object



566
567
568
569
570
571
572
573
574
575
# File 'lib/review/latexbuilder.rb', line 566

def inline_chap(id)
  if ReVIEW.book.param["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



555
556
557
558
559
560
561
562
563
564
# File 'lib/review/latexbuilder.rb', line 555

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

#inline_code(str) ⇒ Object

@<code> is same as @<tt>



672
673
674
# File 'lib/review/latexbuilder.rb', line 672

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

#inline_comment(str) ⇒ Object



741
742
743
744
745
746
747
# File 'lib/review/latexbuilder.rb', line 741

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

#inline_del(str) ⇒ Object



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

def inline_del(str)
  escape(str)               # TODO: use strike ?
end

#inline_dtp(str) ⇒ Object



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

def inline_dtp(str)
  # ignore
  ""
end

#inline_em(str) ⇒ Object



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

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

#inline_fn(id) ⇒ Object



612
613
614
615
616
617
618
# File 'lib/review/latexbuilder.rb', line 612

def inline_fn(id)
  if ReVIEW.book.param["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



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

def inline_hd_chap(chap, id)
  "「#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}」"
end

#inline_hi(str) ⇒ Object

hidden index



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

def inline_hi(str)
  index(str)
end

#inline_hidx(str) ⇒ Object

hidden index??



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

def inline_hidx(str)
  index(str)
end

#inline_i(str) ⇒ Object

index -> italic



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

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

#inline_icon(id) ⇒ Object



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

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

#inline_idx(str) ⇒ Object

index



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

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

#inline_img(id) ⇒ Object



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

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

#inline_list(id) ⇒ Object

FIXME: use TeX native label/ref.



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

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

#inline_m(str) ⇒ Object

math



632
633
634
# File 'lib/review/latexbuilder.rb', line 632

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

#inline_raw(str) ⇒ Object



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

def inline_raw(str)
  super(str)
end

#inline_ruby(str) ⇒ Object



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

def inline_ruby(str)
  base, ruby = *str.split(/,/)
  macro('ruby', base, ruby)
end

#inline_strong(str) ⇒ Object



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

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

#inline_sub(str) ⇒ Object



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

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

#inline_sup(str) ⇒ Object



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

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

#inline_table(id) ⇒ Object



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

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



577
578
579
580
581
582
583
584
585
586
# File 'lib/review/latexbuilder.rb', line 577

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

#inline_tt(str) ⇒ Object



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

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

#inline_ttb(str) ⇒ Object



692
693
694
# File 'lib/review/latexbuilder.rb', line 692

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

#inline_tti(str) ⇒ Object



688
689
690
# File 'lib/review/latexbuilder.rb', line 688

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

#inline_u(str) ⇒ Object



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

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

#inline_uchar(str) ⇒ Object



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

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

#label(id) ⇒ Object



539
540
541
# File 'lib/review/latexbuilder.rb', line 539

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

#latextsize(str) ⇒ Object



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

def latextsize(str)
  @latex_tsize = str
end

#linebreakObject



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

def linebreak
  puts '\\\\'
end

#list_body(lines) ⇒ Object



279
280
281
282
283
284
285
286
287
288
# File 'lib/review/latexbuilder.rb', line 279

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

#list_header(id, caption) ⇒ Object



275
276
277
# File 'lib/review/latexbuilder.rb', line 275

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



248
249
250
251
252
253
254
255
256
257
258
# File 'lib/review/latexbuilder.rb', line 248

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

end

#nofunc_text(str) ⇒ Object



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

def nofunc_text(str)
  escape(str)
end

#noindentObject



551
552
553
# File 'lib/review/latexbuilder.rb', line 551

def noindent
  print '\noindent'
end

#nonum_begin(level, label, caption) ⇒ Object



94
95
96
97
# File 'lib/review/latexbuilder.rb', line 94

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

#nonum_end(level) ⇒ Object



99
100
# File 'lib/review/latexbuilder.rb', line 99

def nonum_end(level)
end

#ol_beginObject



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

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

#ol_endObject



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

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

#ol_item(lines, num) ⇒ Object



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

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

#olnum(num) ⇒ Object



809
810
811
# File 'lib/review/latexbuilder.rb', line 809

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

#pagebreakObject



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

def pagebreak
  puts '\pagebreak'
end

#paragraph(lines) ⇒ Object



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

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

#parasepObject



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

def parasep()
  puts '\\parasep'
end

#quote(lines) ⇒ Object



482
483
484
# File 'lib/review/latexbuilder.rb', line 482

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

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



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

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

#result_metric(array) ⇒ Object



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

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

#source(lines, caption) ⇒ Object



290
291
292
293
294
295
296
# File 'lib/review/latexbuilder.rb', line 290

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

#source_body(lines) ⇒ Object



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

def source_body(lines)
  puts '\begin{alltt}'
  lines.each do |line|
    puts detab(line)
  end
  puts '\end{alltt}'
end

#source_header(caption) ⇒ Object



298
299
300
# File 'lib/review/latexbuilder.rb', line 298

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

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



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/review/latexbuilder.rb', line 385

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 => err
    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



432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/review/latexbuilder.rb', line 432

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



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

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

#table_header(id, caption) ⇒ Object



422
423
424
425
426
427
428
429
430
# File 'lib/review/latexbuilder.rb', line 422

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

#table_separatorObject



446
447
448
# File 'lib/review/latexbuilder.rb', line 446

def table_separator
  #puts '\hline'
end

#td(s) ⇒ Object



459
460
461
462
463
464
465
466
# File 'lib/review/latexbuilder.rb', line 459

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

#texequation(lines) ⇒ Object



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

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



450
451
452
453
454
455
456
457
# File 'lib/review/latexbuilder.rb', line 450

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



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

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

#tsize(str) ⇒ Object



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

def tsize(str)
  @tsize = str
end

#ul_beginObject



144
145
146
147
# File 'lib/review/latexbuilder.rb', line 144

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

#ul_endObject



155
156
157
158
# File 'lib/review/latexbuilder.rb', line 155

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

#ul_item(lines) ⇒ Object



149
150
151
152
153
# File 'lib/review/latexbuilder.rb', line 149

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