Class: ReVIEW::LATEXBuilder
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
-
#bibpaper_bibpaper(id, caption, lines) ⇒ Object
-
#bibpaper_header(id, caption) ⇒ Object
-
#box(lines, caption = nil) ⇒ Object
-
#captionblock(type, lines, caption) ⇒ Object
-
#center(lines) ⇒ Object
(also: #centering)
-
#cmd(lines, caption = nil, lang = nil) ⇒ Object
-
#column_begin(level, label, caption) ⇒ Object
-
#column_end(level) ⇒ Object
-
#comment(lines, comment = nil) ⇒ Object
-
#common_code_block(id, lines, command, caption, lang) ⇒ Object
-
#common_code_block_lst(id, lines, command, title, caption, lang) ⇒ Object
-
#compile_href(url, label) ⇒ Object
-
#compile_kw(word, alt) ⇒ Object
-
#compile_ruby(base, ruby) ⇒ Object
-
#dd(lines) ⇒ Object
-
#direct(lines, fmt) ⇒ Object
-
#dl_begin ⇒ Object
-
#dl_end ⇒ Object
-
#dt(str) ⇒ Object
-
#emlist(lines, caption = nil, lang = nil) ⇒ Object
-
#emlistnum(lines, caption = nil, lang = nil) ⇒ Object
-
#extname ⇒ Object
-
#flushright(lines) ⇒ Object
-
#footnote(id, content) ⇒ Object
-
#headline(level, label, caption) ⇒ Object
-
#hr ⇒ Object
-
#image_dummy(id, caption, lines) ⇒ Object
-
#image_ext ⇒ Object
-
#image_header(id, caption) ⇒ Object
-
#image_image(id, caption, metric) ⇒ Object
-
#indepimage(id, caption = nil, metric = nil) ⇒ Object
(also: #numberlessimage)
-
#index(str) ⇒ Object
-
#inline_ami(str) ⇒ Object
-
#inline_b(str) ⇒ Object
-
#inline_bib(id) ⇒ Object
-
#inline_bou(str) ⇒ Object
-
#inline_br(str) ⇒ Object
-
#inline_chap(id) ⇒ Object
-
#inline_chapref(id) ⇒ Object
-
#inline_code(str) ⇒ Object
@<code> is same as @<tt>.
-
#inline_column(id) ⇒ Object
-
#inline_comment(str) ⇒ Object
-
#inline_del(str) ⇒ Object
-
#inline_dtp(str) ⇒ Object
-
#inline_em(str) ⇒ Object
-
#inline_fn(id) ⇒ Object
-
#inline_hd_chap(chap, id) ⇒ Object
-
#inline_hi(str) ⇒ Object
-
#inline_hidx(str) ⇒ Object
-
#inline_i(str) ⇒ Object
-
#inline_icon(id) ⇒ Object
-
#inline_idx(str) ⇒ Object
-
#inline_img(id) ⇒ Object
-
#inline_list(id) ⇒ Object
FIXME: use TeX native label/ref.
-
#inline_m(str) ⇒ Object
-
#inline_raw(str) ⇒ Object
-
#inline_strong(str) ⇒ Object
-
#inline_sub(str) ⇒ Object
-
#inline_sup(str) ⇒ Object
-
#inline_table(id) ⇒ Object
-
#inline_title(id) ⇒ Object
-
#inline_tt(str) ⇒ Object
-
#inline_ttb(str) ⇒ Object
-
#inline_tti(str) ⇒ Object
-
#inline_u(str) ⇒ Object
-
#inline_uchar(str) ⇒ Object
-
#label(id) ⇒ Object
-
#latextsize(str) ⇒ Object
-
#linebreak ⇒ Object
-
#list(lines, id, caption, lang = nil) ⇒ Object
-
#listnum(lines, id, caption, lang = nil) ⇒ Object
override Builder#listnum.
-
#nofunc_text(str) ⇒ Object
-
#noindent ⇒ Object
-
#nonum_begin(level, label, caption) ⇒ Object
-
#nonum_end(level) ⇒ Object
-
#ol_begin ⇒ Object
-
#ol_end ⇒ Object
-
#ol_item(lines, num) ⇒ Object
-
#olnum(num) ⇒ Object
-
#pagebreak ⇒ Object
-
#paragraph(lines) ⇒ Object
-
#parasep ⇒ Object
-
#quote(lines) ⇒ Object
-
#read(lines) ⇒ Object
(also: #lead)
-
#result_metric(array) ⇒ Object
-
#source(lines, caption, lang = nil) ⇒ Object
-
#table(lines, id = nil, caption = nil) ⇒ Object
-
#table_begin(ncols) ⇒ Object
-
#table_end ⇒ Object
-
#table_header(id, caption) ⇒ Object
-
#table_separator ⇒ Object
-
#td(s) ⇒ Object
-
#texequation(lines) ⇒ Object
-
#th(s) ⇒ Object
-
#tr(rows) ⇒ Object
-
#tsize(str) ⇒ Object
-
#ul_begin ⇒ Object
-
#ul_end ⇒ Object
-
#ul_item(lines) ⇒ Object
Methods included from TextUtils
#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_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
Instance Method Details
#bibpaper_bibpaper(id, caption, lines) ⇒ Object
828
829
830
831
|
# File 'lib/review/latexbuilder.rb', line 828
def bibpaper_bibpaper(id, caption, lines)
print split_paragraph(lines).join("")
puts ""
end
|
823
824
825
826
|
# File 'lib/review/latexbuilder.rb', line 823
def (id, caption)
puts "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}"
puts macro('label', bib_label(id))
end
|
#box(lines, caption = nil) ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/review/latexbuilder.rb', line 146
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/review/latexbuilder.rb', line 128
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
541
542
543
|
# File 'lib/review/latexbuilder.rb', line 541
def center(lines)
latex_block 'center', lines
end
|
#cmd(lines, caption = nil, lang = nil) ⇒ Object
282
283
284
285
286
287
288
289
290
291
|
# File 'lib/review/latexbuilder.rb', line 282
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
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/review/latexbuilder.rb', line 109
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
123
124
125
126
|
# File 'lib/review/latexbuilder.rb', line 123
def column_end(level)
puts "\\end{reviewcolumn}\n"
blank
end
|
584
585
586
587
588
589
590
591
|
# File 'lib/review/latexbuilder.rb', line 584
def (lines, = nil)
lines ||= []
lines.unshift unless .blank?
if @book.config["draft"]
str = lines.join("")
puts macro('pdfcomment', escape(str))
end
end
|
#common_code_block(id, lines, command, caption, lang) ⇒ Object
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
# File 'lib/review/latexbuilder.rb', line 293
def common_code_block(id, lines, command, caption, lang)
buf = ""
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
# File 'lib/review/latexbuilder.rb', line 316
def common_code_block_lst(id, lines, command, title, caption, lang)
caption_str = compile_inline((caption || ""))
if title == "title" && caption_str == ""
caption_str = "\\relax" print "\\vspace{-1.5em}"
end
if @book.config["highlight"] && @book.config["highlight"]["lang"]
lexer = @book.config["highlight"]["lang"] 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
859
860
861
862
863
864
865
866
867
868
869
|
# File 'lib/review/latexbuilder.rb', line 859
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
851
852
853
854
855
856
857
|
# File 'lib/review/latexbuilder.rb', line 851
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
686
687
688
|
# File 'lib/review/latexbuilder.rb', line 686
def compile_ruby(base, ruby)
macro('ruby', escape(base), escape(ruby))
end
|
#dd(lines) ⇒ Object
206
207
208
|
# File 'lib/review/latexbuilder.rb', line 206
def dd(lines)
puts lines.join
end
|
#direct(lines, fmt) ⇒ Object
577
578
579
580
581
582
|
# File 'lib/review/latexbuilder.rb', line 577
def direct(lines, fmt)
return unless fmt == 'latex'
lines.each do |line|
puts line
end
end
|
195
196
197
198
|
# File 'lib/review/latexbuilder.rb', line 195
def dl_begin
blank
puts '\begin{description}'
end
|
210
211
212
213
|
# File 'lib/review/latexbuilder.rb', line 210
def dl_end
puts '\end{description}'
blank
end
|
200
201
202
203
204
|
# File 'lib/review/latexbuilder.rb', line 200
def dt(str)
str.sub!(/\[/){'\lbrack{}'}
str.sub!(/\]/){'\rbrack{}'}
puts '\item[' + str + '] \mbox{} \\\\'
end
|
#emlist(lines, caption = nil, lang = nil) ⇒ Object
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/review/latexbuilder.rb', line 238
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
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/review/latexbuilder.rb', line 249
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
|
31
32
33
|
# File 'lib/review/latexbuilder.rb', line 31
def extname
'.tex'
end
|
#flushright(lines) ⇒ Object
547
548
549
|
# File 'lib/review/latexbuilder.rb', line 547
def flushright(lines)
latex_block 'flushright', lines
end
|
665
666
667
668
669
670
|
# File 'lib/review/latexbuilder.rb', line 665
def (id, content)
if @book.config["footnotetext"]
puts macro("footnotetext[#{@chapter.(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
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
|
593
594
595
|
# File 'lib/review/latexbuilder.rb', line 593
def hr
puts '\hrule'
end
|
#image_dummy(id, caption, lines) ⇒ Object
373
374
375
376
377
378
379
380
381
382
383
|
# File 'lib/review/latexbuilder.rb', line 373
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_ext ⇒ Object
879
880
881
|
# File 'lib/review/latexbuilder.rb', line 879
def image_ext
"pdf"
end
|
350
351
|
# File 'lib/review/latexbuilder.rb', line 350
def (id, caption)
end
|
#image_image(id, caption, metric) ⇒ Object
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
# File 'lib/review/latexbuilder.rb', line 357
def image_image(id, caption, metric)
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('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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
# File 'lib/review/latexbuilder.rb', line 424
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
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
|
# File 'lib/review/latexbuilder.rb', line 833
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
802
803
804
|
# File 'lib/review/latexbuilder.rb', line 802
def inline_ami(str)
macro('reviewami', escape(str))
end
|
#inline_b(str) ⇒ Object
716
717
718
|
# File 'lib/review/latexbuilder.rb', line 716
def inline_b(str)
macro('textbf', escape(str))
end
|
#inline_bib(id) ⇒ Object
755
756
757
|
# File 'lib/review/latexbuilder.rb', line 755
def inline_bib(id)
macro('reviewbibref', "[#{@chapter.bibpaper(id).number}]", bib_label(id))
end
|
#inline_bou(str) ⇒ Object
682
683
684
|
# File 'lib/review/latexbuilder.rb', line 682
def inline_bou(str)
str.split(//).map {|c| macro('ruby', escape(c), macro('textgt', BOUTEN)) }.join('\allowbreak')
end
|
#inline_br(str) ⇒ Object
721
722
723
|
# File 'lib/review/latexbuilder.rb', line 721
def inline_br(str)
"\\\\\n"
end
|
#inline_chap(id) ⇒ Object
625
626
627
628
629
630
631
632
633
634
|
# File 'lib/review/latexbuilder.rb', line 625
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
613
614
615
616
617
618
619
620
621
622
623
|
# File 'lib/review/latexbuilder.rb', line 613
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
731
732
733
|
# File 'lib/review/latexbuilder.rb', line 731
def inline_code(str)
macro('texttt', escape(str))
end
|
#inline_column(id) ⇒ Object
774
775
776
|
# File 'lib/review/latexbuilder.rb', line 774
def inline_column(id)
macro('reviewcolumnref', "#{@chapter.column(id).caption}", column_label(id))
end
|
815
816
817
818
819
820
821
|
# File 'lib/review/latexbuilder.rb', line 815
def (str)
if @book.config["draft"]
macro('pdfcomment', escape(str))
else
""
end
end
|
#inline_del(str) ⇒ Object
743
744
745
|
# File 'lib/review/latexbuilder.rb', line 743
def inline_del(str)
macro('reviewstrike', escape(str))
end
|
#inline_dtp(str) ⇒ Object
725
726
727
728
|
# File 'lib/review/latexbuilder.rb', line 725
def inline_dtp(str)
""
end
|
#inline_em(str) ⇒ Object
790
791
792
|
# File 'lib/review/latexbuilder.rb', line 790
def inline_em(str)
macro('reviewem', escape(str))
end
|
#inline_fn(id) ⇒ Object
672
673
674
675
676
677
678
|
# File 'lib/review/latexbuilder.rb', line 672
def inline_fn(id)
if @book.config["footnotetext"]
macro("footnotemark[#{@chapter.(id).number}]", "")
else
macro('footnote', compile_inline(@chapter.(id).content.strip))
end
end
|
#inline_hd_chap(chap, id) ⇒ Object
759
760
761
762
763
764
765
766
767
768
769
770
771
772
|
# File 'lib/review/latexbuilder.rb', line 759
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
696
697
698
|
# File 'lib/review/latexbuilder.rb', line 696
def inline_hi(str)
index(str)
end
|
#inline_hidx(str) ⇒ Object
711
712
713
|
# File 'lib/review/latexbuilder.rb', line 711
def inline_hidx(str)
index(str)
end
|
#inline_i(str) ⇒ Object
701
702
703
|
# File 'lib/review/latexbuilder.rb', line 701
def inline_i(str)
macro('textit', escape(str))
end
|
#inline_icon(id) ⇒ Object
806
807
808
|
# File 'lib/review/latexbuilder.rb', line 806
def inline_icon(id)
macro('includegraphics', @chapter.image(id).path)
end
|
#inline_idx(str) ⇒ Object
706
707
708
|
# File 'lib/review/latexbuilder.rb', line 706
def inline_idx(str)
escape(str) + index(str)
end
|
#inline_img(id) ⇒ Object
660
661
662
663
|
# File 'lib/review/latexbuilder.rb', line 660
def inline_img(id)
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.
650
651
652
653
|
# File 'lib/review/latexbuilder.rb', line 650
def inline_list(id)
chapter, id = (id)
macro('reviewlistref', "#{chapter.number}.#{chapter.list(id).number}")
end
|
#inline_m(str) ⇒ Object
691
692
693
|
# File 'lib/review/latexbuilder.rb', line 691
def inline_m(str)
" $#{str}$ "
end
|
#inline_raw(str) ⇒ Object
778
779
780
|
# File 'lib/review/latexbuilder.rb', line 778
def inline_raw(str)
super(str)
end
|
#inline_strong(str) ⇒ Object
794
795
796
|
# File 'lib/review/latexbuilder.rb', line 794
def inline_strong(str)
macro('reviewstrong', escape(str))
end
|
#inline_sub(str) ⇒ Object
782
783
784
|
# File 'lib/review/latexbuilder.rb', line 782
def inline_sub(str)
macro('textsubscript', escape(str))
end
|
#inline_sup(str) ⇒ Object
786
787
788
|
# File 'lib/review/latexbuilder.rb', line 786
def inline_sup(str)
macro('textsuperscript', escape(str))
end
|
#inline_table(id) ⇒ Object
655
656
657
658
|
# File 'lib/review/latexbuilder.rb', line 655
def inline_table(id)
chapter, id = (id)
macro('reviewtableref', "#{chapter.number}.#{chapter.table(id).number}", table_label(id, chapter))
end
|
#inline_title(id) ⇒ Object
636
637
638
639
640
641
642
643
644
645
646
|
# File 'lib/review/latexbuilder.rb', line 636
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
739
740
741
|
# File 'lib/review/latexbuilder.rb', line 739
def inline_tt(str)
macro('texttt', escape(str))
end
|
#inline_ttb(str) ⇒ Object
751
752
753
|
# File 'lib/review/latexbuilder.rb', line 751
def inline_ttb(str)
macro('texttt', macro('textbf', escape(str)))
end
|
#inline_tti(str) ⇒ Object
747
748
749
|
# File 'lib/review/latexbuilder.rb', line 747
def inline_tti(str)
macro('texttt', macro('textit', escape(str)))
end
|
#inline_u(str) ⇒ Object
798
799
800
|
# File 'lib/review/latexbuilder.rb', line 798
def inline_u(str)
macro('Underline', escape(str))
end
|
#inline_uchar(str) ⇒ Object
810
811
812
813
|
# File 'lib/review/latexbuilder.rb', line 810
def inline_uchar(str)
macro('UTF', escape(str))
end
|
#label(id) ⇒ Object
597
598
599
|
# File 'lib/review/latexbuilder.rb', line 597
def label(id)
puts macro('label', id)
end
|
#latextsize(str) ⇒ Object
875
876
877
|
# File 'lib/review/latexbuilder.rb', line 875
def latextsize(str)
@latex_tsize = str
end
|
#linebreak ⇒ Object
605
606
607
|
# File 'lib/review/latexbuilder.rb', line 605
def linebreak
puts '\\\\'
end
|
#list(lines, id, caption, lang = nil) ⇒ Object
261
262
263
264
265
266
267
268
269
|
# File 'lib/review/latexbuilder.rb', line 261
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
272
273
274
275
276
277
278
279
280
|
# File 'lib/review/latexbuilder.rb', line 272
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
|
#nofunc_text(str) ⇒ Object
735
736
737
|
# File 'lib/review/latexbuilder.rb', line 735
def nofunc_text(str)
escape(str)
end
|
609
610
611
|
# File 'lib/review/latexbuilder.rb', line 609
def noindent
print '\noindent'
end
|
#nonum_begin(level, label, caption) ⇒ Object
101
102
103
104
|
# 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))
end
|
#nonum_end(level) ⇒ Object
106
107
|
# File 'lib/review/latexbuilder.rb', line 106
def nonum_end(level)
end
|
175
176
177
178
179
180
181
182
|
# File 'lib/review/latexbuilder.rb', line 175
def ol_begin
blank
puts '\begin{enumerate}'
if @ol_num
puts "\\setcounter{enumi}{#{@ol_num - 1}}"
@ol_num = nil
end
end
|
190
191
192
193
|
# File 'lib/review/latexbuilder.rb', line 190
def ol_end
puts '\end{enumerate}'
blank
end
|
#ol_item(lines, num) ⇒ Object
184
185
186
187
188
|
# File 'lib/review/latexbuilder.rb', line 184
def ol_item(lines, num)
str = lines.join
str.sub!(/\A(\[)/){'\lbrack{}'}
puts '\item ' + str
end
|
#olnum(num) ⇒ Object
883
884
885
|
# File 'lib/review/latexbuilder.rb', line 883
def olnum(num)
@ol_num = num.to_i
end
|
#pagebreak ⇒ Object
601
602
603
|
# File 'lib/review/latexbuilder.rb', line 601
def pagebreak
puts '\pagebreak'
end
|
#paragraph(lines) ⇒ Object
215
216
217
218
219
220
221
|
# File 'lib/review/latexbuilder.rb', line 215
def paragraph(lines)
blank
lines.each do |line|
puts line
end
blank
end
|
223
224
225
|
# File 'lib/review/latexbuilder.rb', line 223
def parasep
puts '\\parasep'
end
|
#quote(lines) ⇒ Object
537
538
539
|
# File 'lib/review/latexbuilder.rb', line 537
def quote(lines)
latex_block 'quote', lines
end
|
#read(lines) ⇒ Object
Also known as:
lead
227
228
229
|
# File 'lib/review/latexbuilder.rb', line 227
def read(lines)
latex_block 'quotation', lines
end
|
#result_metric(array) ⇒ Object
353
354
355
|
# File 'lib/review/latexbuilder.rb', line 353
def result_metric(array)
"#{array.join(',')}"
end
|
#source(lines, caption, lang = nil) ⇒ Object
335
336
337
338
339
340
341
342
343
344
345
346
347
|
# File 'lib/review/latexbuilder.rb', line 335
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
|
# File 'lib/review/latexbuilder.rb', line 441
def table(lines, id = nil, caption = nil)
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
if /\A[\=\{\-\}]{12}/ =~ line
sepidx ||= idx
next
end
rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
end
rows = adjust_n_cols(rows)
begin
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
487
488
489
490
491
492
493
494
495
496
497
498
499
|
# File 'lib/review/latexbuilder.rb', line 487
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_end ⇒ Object
528
529
530
531
532
533
534
535
|
# File 'lib/review/latexbuilder.rb', line 528
def table_end
puts macro('end', 'reviewtable')
if @table_caption
puts '\end{table}'
end
@table_caption = nil
blank
end
|
478
479
480
481
482
483
484
485
|
# File 'lib/review/latexbuilder.rb', line 478
def (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_separator ⇒ Object
501
502
503
|
# File 'lib/review/latexbuilder.rb', line 501
def table_separator
end
|
514
515
516
517
518
519
520
521
|
# File 'lib/review/latexbuilder.rb', line 514
def td(s)
if /\\\\/ =~ s
macro('shortstack[l]', s)
else
s
end
end
|
#texequation(lines) ⇒ Object
551
552
553
554
555
556
557
558
559
|
# File 'lib/review/latexbuilder.rb', line 551
def texequation(lines)
blank
puts macro('begin','equation*')
lines.each do |line|
puts unescape_latex(line)
end
puts macro('end', 'equation*')
blank
end
|
505
506
507
508
509
510
511
512
|
# File 'lib/review/latexbuilder.rb', line 505
def th(s)
if /\\\\/i =~ s
macro('reviewth', macro('shortstack[l]', s))
else
macro('reviewth', s)
end
end
|
523
524
525
526
|
# File 'lib/review/latexbuilder.rb', line 523
def tr(rows)
print rows.join(' & ')
puts ' \\\\ \hline'
end
|
#tsize(str) ⇒ Object
871
872
873
|
# File 'lib/review/latexbuilder.rb', line 871
def tsize(str)
@tsize = str
end
|
159
160
161
162
|
# File 'lib/review/latexbuilder.rb', line 159
def ul_begin
blank
puts '\begin{itemize}'
end
|
170
171
172
173
|
# File 'lib/review/latexbuilder.rb', line 170
def ul_end
puts '\end{itemize}'
blank
end
|
#ul_item(lines) ⇒ Object
164
165
166
167
168
|
# File 'lib/review/latexbuilder.rb', line 164
def ul_item(lines)
str = lines.join
str.sub!(/\A(\[)/){'\lbrack{}'}
puts '\item ' + str
end
|