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(lines, command, caption, lang) ⇒ Object
-
#common_code_block_lst(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) ⇒ 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
#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_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
820
821
822
823
|
# File 'lib/review/latexbuilder.rb', line 820
def bibpaper_bibpaper(id, caption, lines)
print split_paragraph(lines).join("")
puts ""
end
|
815
816
817
818
|
# File 'lib/review/latexbuilder.rb', line 815
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
533
534
535
|
# File 'lib/review/latexbuilder.rb', line 533
def center(lines)
latex_block 'center', lines
end
|
#cmd(lines, caption = nil, lang = nil) ⇒ Object
292
293
294
295
296
297
298
299
300
301
|
# File 'lib/review/latexbuilder.rb', line 292
def cmd(lines, caption = nil, lang = nil)
if highlight_listings?
common_code_block_lst(lines, 'reviewcmdlst', 'title', caption, lang)
else
blank
common_code_block(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
|
576
577
578
579
580
581
582
583
|
# File 'lib/review/latexbuilder.rb', line 576
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(lines, command, caption, lang) ⇒ Object
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'lib/review/latexbuilder.rb', line 303
def common_code_block(lines, command, caption, lang)
if caption
puts macro(command + 'caption', "#{compile_inline(caption)}")
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(lines, command, title, caption, lang) ⇒ Object
317
318
319
320
321
322
323
324
325
326
327
328
329
|
# File 'lib/review/latexbuilder.rb', line 317
def common_code_block_lst(lines, command, title, caption, lang)
caption_str = compile_inline((caption || ""))
if title == "title" && caption_str == ""
caption_str = "\\relax" print "\\vspace{-1.5em}"
end
lexer = lang || ""
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
851
852
853
854
855
856
857
858
859
860
861
|
# File 'lib/review/latexbuilder.rb', line 851
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
843
844
845
846
847
848
849
|
# File 'lib/review/latexbuilder.rb', line 843
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
678
679
680
|
# File 'lib/review/latexbuilder.rb', line 678
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
569
570
571
572
573
574
|
# File 'lib/review/latexbuilder.rb', line 569
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(lines, 'reviewemlistlst', 'title', caption, lang)
else
common_code_block(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(lines, 'reviewemlistnumlst', 'title', caption, lang)
else
common_code_block(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
539
540
541
|
# File 'lib/review/latexbuilder.rb', line 539
def flushright(lines)
latex_block 'flushright', lines
end
|
657
658
659
660
661
662
|
# File 'lib/review/latexbuilder.rb', line 657
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
|
585
586
587
|
# File 'lib/review/latexbuilder.rb', line 585
def hr
puts '\hrule'
end
|
#image_dummy(id, caption, lines) ⇒ Object
365
366
367
368
369
370
371
372
373
374
375
|
# File 'lib/review/latexbuilder.rb', line 365
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
871
872
873
|
# File 'lib/review/latexbuilder.rb', line 871
def image_ext
"pdf"
end
|
342
343
|
# File 'lib/review/latexbuilder.rb', line 342
def (id, caption)
end
|
#image_image(id, caption, metric) ⇒ Object
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
# File 'lib/review/latexbuilder.rb', line 349
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
# File 'lib/review/latexbuilder.rb', line 416
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
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
|
# File 'lib/review/latexbuilder.rb', line 825
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
794
795
796
|
# File 'lib/review/latexbuilder.rb', line 794
def inline_ami(str)
macro('reviewami', escape(str))
end
|
#inline_b(str) ⇒ Object
708
709
710
|
# File 'lib/review/latexbuilder.rb', line 708
def inline_b(str)
macro('textbf', escape(str))
end
|
#inline_bib(id) ⇒ Object
747
748
749
|
# File 'lib/review/latexbuilder.rb', line 747
def inline_bib(id)
macro('reviewbibref', "[#{@chapter.bibpaper(id).number}]", bib_label(id))
end
|
#inline_bou(str) ⇒ Object
674
675
676
|
# File 'lib/review/latexbuilder.rb', line 674
def inline_bou(str)
str.split(//).map {|c| macro('ruby', escape(c), macro('textgt', BOUTEN)) }.join('\allowbreak')
end
|
#inline_br(str) ⇒ Object
713
714
715
|
# File 'lib/review/latexbuilder.rb', line 713
def inline_br(str)
"\\\\\n"
end
|
#inline_chap(id) ⇒ Object
617
618
619
620
621
622
623
624
625
626
|
# File 'lib/review/latexbuilder.rb', line 617
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
605
606
607
608
609
610
611
612
613
614
615
|
# File 'lib/review/latexbuilder.rb', line 605
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
723
724
725
|
# File 'lib/review/latexbuilder.rb', line 723
def inline_code(str)
macro('texttt', escape(str))
end
|
#inline_column(id) ⇒ Object
766
767
768
|
# File 'lib/review/latexbuilder.rb', line 766
def inline_column(id)
macro('reviewcolumnref', "#{@chapter.column(id).caption}", column_label(id))
end
|
807
808
809
810
811
812
813
|
# File 'lib/review/latexbuilder.rb', line 807
def (str)
if @book.config["draft"]
macro('pdfcomment', escape(str))
else
""
end
end
|
#inline_del(str) ⇒ Object
735
736
737
|
# File 'lib/review/latexbuilder.rb', line 735
def inline_del(str)
macro('reviewstrike', escape(str))
end
|
#inline_dtp(str) ⇒ Object
717
718
719
720
|
# File 'lib/review/latexbuilder.rb', line 717
def inline_dtp(str)
""
end
|
#inline_em(str) ⇒ Object
782
783
784
|
# File 'lib/review/latexbuilder.rb', line 782
def inline_em(str)
macro('reviewem', escape(str))
end
|
#inline_fn(id) ⇒ Object
664
665
666
667
668
669
670
|
# File 'lib/review/latexbuilder.rb', line 664
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
751
752
753
754
755
756
757
758
759
760
761
762
763
764
|
# File 'lib/review/latexbuilder.rb', line 751
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
688
689
690
|
# File 'lib/review/latexbuilder.rb', line 688
def inline_hi(str)
index(str)
end
|
#inline_hidx(str) ⇒ Object
703
704
705
|
# File 'lib/review/latexbuilder.rb', line 703
def inline_hidx(str)
index(str)
end
|
#inline_i(str) ⇒ Object
693
694
695
|
# File 'lib/review/latexbuilder.rb', line 693
def inline_i(str)
macro('textit', escape(str))
end
|
#inline_icon(id) ⇒ Object
798
799
800
|
# File 'lib/review/latexbuilder.rb', line 798
def inline_icon(id)
macro('includegraphics', @chapter.image(id).path)
end
|
#inline_idx(str) ⇒ Object
698
699
700
|
# File 'lib/review/latexbuilder.rb', line 698
def inline_idx(str)
escape(str) + index(str)
end
|
#inline_img(id) ⇒ Object
652
653
654
655
|
# File 'lib/review/latexbuilder.rb', line 652
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.
642
643
644
645
|
# File 'lib/review/latexbuilder.rb', line 642
def inline_list(id)
chapter, id = (id)
macro('reviewlistref', "#{chapter.number}.#{chapter.list(id).number}")
end
|
#inline_m(str) ⇒ Object
683
684
685
|
# File 'lib/review/latexbuilder.rb', line 683
def inline_m(str)
" $#{str}$ "
end
|
#inline_raw(str) ⇒ Object
770
771
772
|
# File 'lib/review/latexbuilder.rb', line 770
def inline_raw(str)
super(str)
end
|
#inline_strong(str) ⇒ Object
786
787
788
|
# File 'lib/review/latexbuilder.rb', line 786
def inline_strong(str)
macro('reviewstrong', escape(str))
end
|
#inline_sub(str) ⇒ Object
774
775
776
|
# File 'lib/review/latexbuilder.rb', line 774
def inline_sub(str)
macro('textsubscript', escape(str))
end
|
#inline_sup(str) ⇒ Object
778
779
780
|
# File 'lib/review/latexbuilder.rb', line 778
def inline_sup(str)
macro('textsuperscript', escape(str))
end
|
#inline_table(id) ⇒ Object
647
648
649
650
|
# File 'lib/review/latexbuilder.rb', line 647
def inline_table(id)
chapter, id = (id)
macro('reviewtableref', "#{chapter.number}.#{chapter.table(id).number}", table_label(id, chapter))
end
|
#inline_title(id) ⇒ Object
628
629
630
631
632
633
634
635
636
637
638
|
# File 'lib/review/latexbuilder.rb', line 628
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
731
732
733
|
# File 'lib/review/latexbuilder.rb', line 731
def inline_tt(str)
macro('texttt', escape(str))
end
|
#inline_ttb(str) ⇒ Object
743
744
745
|
# File 'lib/review/latexbuilder.rb', line 743
def inline_ttb(str)
macro('texttt', macro('textbf', escape(str)))
end
|
#inline_tti(str) ⇒ Object
739
740
741
|
# File 'lib/review/latexbuilder.rb', line 739
def inline_tti(str)
macro('texttt', macro('textit', escape(str)))
end
|
#inline_u(str) ⇒ Object
790
791
792
|
# File 'lib/review/latexbuilder.rb', line 790
def inline_u(str)
macro('Underline', escape(str))
end
|
#inline_uchar(str) ⇒ Object
802
803
804
805
|
# File 'lib/review/latexbuilder.rb', line 802
def inline_uchar(str)
macro('UTF', escape(str))
end
|
#label(id) ⇒ Object
589
590
591
|
# File 'lib/review/latexbuilder.rb', line 589
def label(id)
puts macro('label', id)
end
|
#latextsize(str) ⇒ Object
867
868
869
|
# File 'lib/review/latexbuilder.rb', line 867
def latextsize(str)
@latex_tsize = str
end
|
#linebreak ⇒ Object
597
598
599
|
# File 'lib/review/latexbuilder.rb', line 597
def linebreak
puts '\\\\'
end
|
#list(lines, id, caption, lang = nil) ⇒ Object
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/review/latexbuilder.rb', line 261
def list(lines, id, caption, lang = nil)
if highlight_listings?
common_code_block_lst(lines, 'reviewlistlst', 'caption', caption, lang)
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
common_code_block(lines, 'reviewlist', nil, lang) do |line, idx|
detab(line) + "\n"
end
end
end
|
#listnum(lines, id, caption, lang = nil) ⇒ Object
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# File 'lib/review/latexbuilder.rb', line 277
def listnum(lines, id, caption, lang = nil)
if highlight_listings?
common_code_block_lst(lines, 'reviewlistnumlst', 'caption', caption, lang)
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
common_code_block(lines, 'reviewlist', caption, lang) do |line, idx|
detab((idx+1).to_s.rjust(2)+": " + line) + "\n"
end
end
end
|
#nofunc_text(str) ⇒ Object
727
728
729
|
# File 'lib/review/latexbuilder.rb', line 727
def nofunc_text(str)
escape(str)
end
|
601
602
603
|
# File 'lib/review/latexbuilder.rb', line 601
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
875
876
877
|
# File 'lib/review/latexbuilder.rb', line 875
def olnum(num)
@ol_num = num.to_i
end
|
#pagebreak ⇒ Object
593
594
595
|
# File 'lib/review/latexbuilder.rb', line 593
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
529
530
531
|
# File 'lib/review/latexbuilder.rb', line 529
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
345
346
347
|
# File 'lib/review/latexbuilder.rb', line 345
def result_metric(array)
"#{array.join(',')}"
end
|
#source(lines, caption) ⇒ Object
331
332
333
334
335
336
337
338
339
|
# File 'lib/review/latexbuilder.rb', line 331
def source(lines, caption)
puts '\begin{reviewlist}'
puts macro('reviewlistcaption', compile_inline(caption))
lines.each do |line|
puts detab(line)
end
puts '\end{reviewlist}'
puts ""
end
|
#table(lines, id = nil, caption = nil) ⇒ Object
433
434
435
436
437
438
439
440
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
|
# File 'lib/review/latexbuilder.rb', line 433
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
479
480
481
482
483
484
485
486
487
488
489
490
491
|
# File 'lib/review/latexbuilder.rb', line 479
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
520
521
522
523
524
525
526
527
|
# File 'lib/review/latexbuilder.rb', line 520
def table_end
puts macro('end', 'reviewtable')
if @table_caption
puts '\end{table}'
end
@table_caption = nil
blank
end
|
470
471
472
473
474
475
476
477
|
# File 'lib/review/latexbuilder.rb', line 470
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
493
494
495
|
# File 'lib/review/latexbuilder.rb', line 493
def table_separator
end
|
506
507
508
509
510
511
512
513
|
# File 'lib/review/latexbuilder.rb', line 506
def td(s)
if /\\\\/ =~ s
macro('shortstack[l]', s)
else
s
end
end
|
#texequation(lines) ⇒ Object
543
544
545
546
547
548
549
550
551
|
# File 'lib/review/latexbuilder.rb', line 543
def texequation(lines)
blank
puts macro('begin','equation*')
lines.each do |line|
puts unescape_latex(line)
end
puts macro('end', 'equation*')
blank
end
|
497
498
499
500
501
502
503
504
|
# File 'lib/review/latexbuilder.rb', line 497
def th(s)
if /\\\\/i =~ s
macro('reviewth', macro('shortstack[l]', s))
else
macro('reviewth', s)
end
end
|
515
516
517
518
|
# File 'lib/review/latexbuilder.rb', line 515
def tr(rows)
print rows.join(' & ')
puts ' \\\\ \hline'
end
|
#tsize(str) ⇒ Object
863
864
865
|
# File 'lib/review/latexbuilder.rb', line 863
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
|