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 Attribute Summary

Attributes inherited from Builder

#ast, #output

Instance Method Summary collapse

Methods included from TextUtils

#detab

Methods included from LaTeXUtils

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

Methods inherited from Builder

#bind, #detab, #error, #extract_chapter_id, #get_chap, #graph, #handle_metric, #image, #include, #initialize, #inline_chap, #inline_chapref, #inline_column, #inline_fn, #inline_href, #inline_img, #inline_include, #inline_kw, #inline_list, #inline_ruby, #inline_table, #inline_title, #node_inline_hd, #node_inline_imgref, #parse_metric, #post_paragraph, #pre_paragraph, #print, #puts, #raw, #result, #table, #target_name, #text, #ul_item_begin, #ul_item_end, #warn

Constructor Details

This class inherits a constructor from ReVIEW::Builder

Instance Method Details

#bibpaper(lines, id, caption) ⇒ Object



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

def bibpaper(lines, id, caption)
  buf = ""
  buf << bibpaper_header(id, caption)
  if lines.empty?
    buf << "\n"
  else
    buf << "\n"
    buf << bibpaper_bibpaper(id, caption, lines)
  end
  buf << "\n"
  buf
end

#bibpaper_bibpaper(id, caption, lines) ⇒ Object



908
909
910
# File 'lib/review/latexbuilder.rb', line 908

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

#bibpaper_header(id, caption) ⇒ Object



903
904
905
906
# File 'lib/review/latexbuilder.rb', line 903

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

#box(lines, caption = nil) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/review/latexbuilder.rb', line 140

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

#captionblock(type, lines, caption) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/review/latexbuilder.rb', line 123

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

  if @book.config["deprecated-blocklines"].nil?
    buf << lines.join("")
  else
    error "deprecated-blocklines is obsoleted."
  end

  buf << "\\end{reviewminicolumn}\n"
  buf
end

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



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

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

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



281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/review/latexbuilder.rb', line 281

def cmd(lines, caption = nil, lang = nil)
  buf = ""
  if highlight_listings?
    buf << common_code_block_lst(nil, lines, 'reviewcmdlst', 'title', caption, lang)
  else
    buf << "\n"
    buf << common_code_block(nil, lines, 'reviewcmd', caption, lang) do |line, idx|
      detab(line) + "\n"
    end
  end
  buf
end

#column_begin(level, label, caption) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/review/latexbuilder.rb', line 96

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

#column_end(level) ⇒ Object



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

def column_end(level)
  buf = ""
  buf << "\\end{reviewcolumn}\n"
  blank
  buf
end

#comment(lines, comment = nil) ⇒ Object



620
621
622
623
624
625
626
627
628
629
# File 'lib/review/latexbuilder.rb', line 620

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

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



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/review/latexbuilder.rb', line 294

def common_code_block(id, lines, command, caption, lang)
  buf = ""
  if caption
    if command =~ /emlist/ || command =~ /cmd/
      buf << macro(command + 'caption', "#{caption}") + "\n"
    else
      begin
        buf << "\n"
        buf << macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{caption}") + "\n"
      rescue KeyError
        error "no such list: #{id}"
      end
    end
  end
  body = ""
  lines.each_with_index do |line, idx|
    body.concat(yield(line, idx))
  end
  buf << macro('begin' ,command) + "\n"
  buf << body
  buf << macro('end' ,command) + "\n"
  buf
end

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



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

def common_code_block_lst(id, lines, command, title, caption, lang)
  buf = ""
  caption_str = (caption || "")
  if title == "title" && caption_str == ""
    caption_str = "\\relax" ## dummy charactor to remove lstname
    buf << "\\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"}
  buf << "\\begin{"+command+"}["+title+"={"+caption_str+"},language={"+ lexer+"}]" + "\n"
  buf << body
  buf << "\\end{"+ command + "}" + "\n"
  buf
end

#compile_href(url, label) ⇒ Object



924
925
926
927
928
929
930
931
932
933
934
# File 'lib/review/latexbuilder.rb', line 924

def compile_href(url, label)
  if /\A[a-z]+:/ =~ url
    if label
      macro("href", escape_url(url), label)
    else
      macro("url", escape_url(url))
    end
  else
    macro("ref", url)
  end
end

#compile_kw(word, alt) ⇒ Object



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

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

#compile_ruby(base, ruby) ⇒ Object



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

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

#dd(lines) ⇒ Object



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

def dd(lines)
  lines.join + "\n"
end

#direct(lines, fmt) ⇒ Object



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

def direct(lines, fmt)
  buf = ""
  return buf unless fmt == 'latex'
  lines.each do |line|
    buf << line << "\n"
  end
  buf
end

#dl_beginObject



188
189
190
# File 'lib/review/latexbuilder.rb', line 188

def dl_begin
  "\n" + '\begin{description}' + "\n"
end

#dl_endObject



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

def dl_end
  '\end{description}' + "\n"
end

#dt(str) ⇒ Object



192
193
194
195
196
# File 'lib/review/latexbuilder.rb', line 192

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

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



230
231
232
233
234
235
236
237
238
239
240
# File 'lib/review/latexbuilder.rb', line 230

def emlist(lines, caption = nil, lang = nil)
  buf = "\n"
  if highlight_listings?
    buf << common_code_block_lst(nil, lines, 'reviewemlistlst', 'title', caption, lang)
  else
    buf << common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx|
      detab(line) + "\n"
    end
  end
  buf
end

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



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

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

#extnameObject



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

def extname
  '.tex'
end

#flushright(lines) ⇒ Object



583
584
585
# File 'lib/review/latexbuilder.rb', line 583

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"]
    macro("footnotetext[#{@chapter.footnote(id).number}]",
               content.strip) + "\n"
  end
end

#headline(level, label, caption) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/review/latexbuilder.rb', line 64

def headline(level, label, caption)
  buf = ""
  _, 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
  buf << macro(headline_name+prefix, caption) << "\n"
  if prefix == "*" && level <= @book.config["toclevel"].to_i
    buf << "\\addcontentsline{toc}{#{headline_name}}{#{caption}}\n"
  end
  if level == 1
    buf << macro('label', chapter_label) << "\n"
  else
    buf << macro('label', sec_label(anchor)) << "\n"
  end
  buf
rescue
  error "unknown level: #{level}"
end

#hrObject



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

def hr
  '\hrule' + "\n"
end

#image_dummy(id, caption, lines) ⇒ Object



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

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

#image_extObject



944
945
946
# File 'lib/review/latexbuilder.rb', line 944

def image_ext
  "pdf"
end

#image_header(id, caption) ⇒ Object



365
366
# File 'lib/review/latexbuilder.rb', line 365

def image_header(id, caption)
end

#image_image(id, caption, metric) ⇒ Object



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

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

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



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

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

#index(str) ⇒ Object



912
913
914
# File 'lib/review/latexbuilder.rb', line 912

def index(str)
 "\\index{" + str + "}"
end

#inline_ami(str) ⇒ Object



868
869
870
# File 'lib/review/latexbuilder.rb', line 868

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

#inline_b(str) ⇒ Object

bold



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

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

#inline_bou(str) ⇒ Object



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

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

#inline_br(str) ⇒ Object

line break



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

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

#inline_code(str) ⇒ Object

@<code> is same as @<tt>



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

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

#inline_comment(str) ⇒ Object



882
883
884
885
886
887
888
# File 'lib/review/latexbuilder.rb', line 882

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

#inline_del(str) ⇒ Object



807
808
809
# File 'lib/review/latexbuilder.rb', line 807

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

#inline_dtp(str) ⇒ Object



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

def inline_dtp(str)
  # ignore
  ""
end

#inline_em(str) ⇒ Object



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

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

#inline_hd_chap(chap, id) ⇒ Object



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

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)} #{chap.headline(id).caption}")
  else
    str = I18n.t("chapter_quote", chap.headline(id).caption)
  end
  if @book.config["chapterlink"]
    anchor = n.gsub(/\./, "-")
    macro('reviewsecref', escape(str), sec_label(anchor))
  else
    escape(str)
  end
end

#inline_hi(str) ⇒ Object

hidden index



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

def inline_hi(str)
  index(str)
end

#inline_hidx(str) ⇒ Object

hidden index??



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

def inline_hidx(str)
  index(str)
end

#inline_i(str) ⇒ Object

index -> italic



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

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

#inline_idx(str) ⇒ Object

index



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

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

#inline_raw(str) ⇒ Object



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

def inline_raw(str)
  super(str)
end

#inline_strong(str) ⇒ Object



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

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

#inline_sub(str) ⇒ Object



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

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

#inline_sup(str) ⇒ Object



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

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

#inline_tt(str) ⇒ Object



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

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

#inline_ttb(str) ⇒ Object



815
816
817
# File 'lib/review/latexbuilder.rb', line 815

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

#inline_tti(str) ⇒ Object



811
812
813
# File 'lib/review/latexbuilder.rb', line 811

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

#inline_u(str) ⇒ Object



864
865
866
# File 'lib/review/latexbuilder.rb', line 864

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

#inline_uchar(str) ⇒ Object



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

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

#label(id) ⇒ Object



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

def label(id)
  macro('label', id) + "\n"
end

#latextsize(str) ⇒ Object



940
941
942
# File 'lib/review/latexbuilder.rb', line 940

def latextsize(str)
  @latex_tsize = str
end

#linebreakObject



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

def linebreak
  '\\\\' + "\n"
end

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

override Builder#list



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

def list(lines, id, caption = nil, lang = nil)
  buf = ""
  if highlight_listings?
    buf << common_code_block_lst(id, lines, 'reviewlistlst', 'caption', caption, lang)
  else
    buf << common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx|
      detab(line) + "\n"
    end
  end
  buf
end

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

override Builder#listnum



269
270
271
272
273
274
275
276
277
278
279
# File 'lib/review/latexbuilder.rb', line 269

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

#node_inline_bib(node) ⇒ Object



819
820
821
822
# File 'lib/review/latexbuilder.rb', line 819

def node_inline_bib(node)
  id = node[0].to_raw
  macro('reviewbibref', "[#{@chapter.bibpaper(id).number}]", bib_label(id))
end

#node_inline_chap(node) ⇒ Object



669
670
671
672
673
674
675
676
677
678
679
# File 'lib/review/latexbuilder.rb', line 669

def node_inline_chap(node)
  id = node[0].to_raw
  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

#node_inline_chapref(node) ⇒ Object



656
657
658
659
660
661
662
663
664
665
666
667
# File 'lib/review/latexbuilder.rb', line 656

def node_inline_chapref(node)
  id = node[0].to_raw
  title = @book.chapter_index.display_string(id)
  if @book.config["chapterlink"]
    "\\hyperref[chap:#{id}]{#{title}}"
  else
    title
  end
rescue KeyError
  error "unknown chapter: #{id}"
  nofunc_text("[UnknownChapter:#{id}]")
end

#node_inline_column(node) ⇒ Object



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

def node_inline_column(node)
  id = node[0].to_raw
  macro('reviewcolumnref', "#{@chapter.column(id).caption}", column_label(id))
end

#node_inline_fn(node) ⇒ Object



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

def node_inline_fn(node)
  id = node[0].to_raw
  if @book.config["footnotetext"]
    macro("footnotemark[#{@chapter.footnote(id).number}]", "")
  else
    macro('footnote', @chapter.footnote(id).content.strip)
  end
end

#node_inline_hidx(nodelist) ⇒ Object



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

def node_inline_hidx(nodelist)
  content = nodelist[0].to_raw
  index(content)
end

#node_inline_icon(node) ⇒ Object



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

def node_inline_icon(node)
  id = node[0].to_raw
  macro('includegraphics', @chapter.image(id).path)
end

#node_inline_idx(nodelist) ⇒ Object



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

def node_inline_idx(nodelist)
  content = nodelist[0].to_raw
  escape(content) + index(content)
end

#node_inline_img(node) ⇒ Object



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

def node_inline_img(node)
  id = node[0].to_raw
  chapter, id = extract_chapter_id(id)
  macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}", image_label(id, chapter))
end

#node_inline_list(node) ⇒ Object

FIXME: use TeX native label/ref.



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

def node_inline_list(node)
  id = node[0].to_raw
  chapter, id = extract_chapter_id(id)
  macro('reviewlistref', "#{chapter.number}.#{chapter.list(id).number}")
end

#node_inline_m(node) ⇒ Object

def inline_m(str)

  " $#{str}$ "
end


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

def node_inline_m(node)
  " $#{node[0].to_raw}$ "
end

#node_inline_table(node) ⇒ Object



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

def node_inline_table(node)
  id = node[0].to_raw
  chapter, id = extract_chapter_id(id)
  macro('reviewtableref', "#{chapter.number}.#{chapter.table(id).number}", table_label(id, chapter))
end

#node_inline_title(node) ⇒ Object



681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/review/latexbuilder.rb', line 681

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

#node_label(node) ⇒ Object



639
640
641
642
# File 'lib/review/latexbuilder.rb', line 639

def node_label(node)
  id = node.args[0].to_raw
  macro('label', id) + "\n"
end

#node_table(node) ⇒ Object



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
496
497
498
499
500
501
502
503
504
# File 'lib/review/latexbuilder.rb', line 461

def node_table(node)
  id = node.args[0].to_raw
  caption = node.args[1].to_doc
  lines = []
  node.content.each do |line|
    lines << line.to_doc
  end
  buf = ""
  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
    buf << table_header(id, caption) unless caption.nil?
  rescue KeyError
    error "no such table: #{id}"
  end
  return buf if rows.empty?
  buf << table_begin(rows.first.size)
  if sepidx
    sepidx.times do
      buf << tr(rows.shift.map {|s| th(s) })
    end
    rows.each do |cols|
      buf << tr(cols.map {|s| td(s) })
    end
  else
    rows.each do |cols|
      h, *cs = *cols
      buf << tr([th(h)] + cs.map {|s| td(s) })
    end
  end
  buf << table_end
  buf
end

#nofunc_text(str) ⇒ Object



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

def nofunc_text(str)
  escape(str)
end

#noindentObject



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

def noindent
  '\noindent'
end

#nonum_begin(level, label, caption) ⇒ Object



89
90
91
# File 'lib/review/latexbuilder.rb', line 89

def nonum_begin(level, label, caption)
  "\n" + macro(HEADLINE[level]+"*", caption) + "\n"
end

#nonum_end(level) ⇒ Object



93
94
# File 'lib/review/latexbuilder.rb', line 93

def nonum_end(level)
end

#ol_beginObject



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

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

#ol_endObject



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

def ol_end
  '\end{enumerate}' + "\n"
end

#ol_item(lines, num) ⇒ Object



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

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

#olnum(num) ⇒ Object



948
949
950
# File 'lib/review/latexbuilder.rb', line 948

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

#pagebreakObject



644
645
646
# File 'lib/review/latexbuilder.rb', line 644

def pagebreak
  '\pagebreak' + "\n"
end

#paragraph(lines) ⇒ Object



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

def paragraph(lines)
  buf = "\n"
  lines.each do |line|
    buf << line
  end
  buf << "\n"
  buf
end

#parasepObject



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

def parasep
  '\\parasep' + "\n"
end

#quote(lines) ⇒ Object



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

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

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



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

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

#result_metric(array) ⇒ Object



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

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

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



338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/review/latexbuilder.rb', line 338

def source(lines, caption = nil, lang = nil)
  if highlight_listings?
    common_code_block_lst(nil, lines, 'reviewlistlst', 'title', caption, lang)
  else
  buf = "\n"
  buf << '\begin{reviewlist}' << "\n"
  buf << source_header(caption)
  buf << source_body(lines)
  buf << '\end{reviewlist}' << "\n"
  buf << "\n"
  buf
  end
end

#source_body(lines) ⇒ Object



356
357
358
359
360
361
362
# File 'lib/review/latexbuilder.rb', line 356

def source_body(lines)
  buf = ""
  lines.each do |line|
    buf << detab(line) << "\n"
  end
  buf
end

#source_header(caption) ⇒ Object



352
353
354
# File 'lib/review/latexbuilder.rb', line 352

def source_header(caption)
  macro('reviewlistcaption', caption) + "\n"
end

#table_begin(ncols) ⇒ Object



517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/review/latexbuilder.rb', line 517

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

#table_endObject



562
563
564
565
566
567
568
569
570
571
# File 'lib/review/latexbuilder.rb', line 562

def table_end
  buf = ""
  buf << macro('end', 'reviewtable') << "\n"
  if @table_caption
    buf << '\end{table}' << "\n"
  end
  @table_caption = nil
  buf << "\n"
  buf
end

#table_header(id, caption) ⇒ Object



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

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

#table_separatorObject



533
534
535
# File 'lib/review/latexbuilder.rb', line 533

def table_separator
  #puts '\hline'
end

#td(s) ⇒ Object



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

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

#texequation(lines) ⇒ Object



587
588
589
590
591
592
593
594
595
596
# File 'lib/review/latexbuilder.rb', line 587

def texequation(lines)
  buf = "\n"
  buf << macro('begin','equation*') << "\n"
  lines.each do |line|
    buf << unescape_latex(line) << "\n"
  end
  buf << macro('end', 'equation*') << "\n"
  buf << "\n"
  buf
end

#th(s) ⇒ Object



537
538
539
540
541
542
543
544
# File 'lib/review/latexbuilder.rb', line 537

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



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

def tr(rows)
  buf = ""
  buf << rows.join(' & ')
  buf << ' \\\\  \hline' << "\n"
  buf
end

#tsize(str) ⇒ Object



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

def tsize(str)
  @tsize = str
end

#ul_beginObject



152
153
154
155
156
# File 'lib/review/latexbuilder.rb', line 152

def ul_begin
  buf = "\n"
  buf << '\begin{itemize}' << "\n"
  buf
end

#ul_endObject



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

def ul_end
  '\end{itemize}' + "\n"
end

#ul_item(lines) ⇒ Object



158
159
160
161
162
# File 'lib/review/latexbuilder.rb', line 158

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