class ReVIEW::LATEXBuilder
Constants
- BOUTEN
- HEADLINE
Public Instance Methods
bibpaper_bibpaper(_id, _caption, lines)
click to toggle source
# File lib/review/latexbuilder.rb, line 1217 def bibpaper_bibpaper(_id, _caption, lines) print split_paragraph(lines).map(&:chomp).join("\n") puts '' end
bibpaper_header(id, caption)
click to toggle source
# File lib/review/latexbuilder.rb, line 1212 def bibpaper_header(id, caption) puts "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}" puts macro('label', bib_label(id)) end
blankline()
click to toggle source
# File lib/review/latexbuilder.rb, line 904 def blankline puts '\vspace*{\baselineskip}' end
box(lines, caption = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 243 def box(lines, caption = nil) blank puts macro('reviewboxcaption', compile_inline(caption)) if caption.present? puts '\begin{reviewbox}' lines.each do |line| puts detab(line) end puts '\end{reviewbox}' blank end
captionblock(type, lines, caption)
click to toggle source
# File lib/review/latexbuilder.rb, line 216 def captionblock(type, lines, caption) if @book.config.check_version('2', exception: false) type = 'minicolumn' end print "\\begin{review#{type}}" @doc_status[:caption] = true if @book.config.check_version('2', exception: false) puts if caption.present? puts "\\reviewminicolumntitle{#{compile_inline(caption)}}" end else if caption.present? print "[#{compile_inline(caption)}]" end puts end @doc_status[:caption] = nil blocked_lines = split_paragraph(lines) puts blocked_lines.join("\n\n") puts "\\end{review#{type}}" end
center(lines)
click to toggle source
# File lib/review/latexbuilder.rb, line 830 def center(lines) latex_block 'center', lines end
Also aliased as: centering
cmd(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 370 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) { |line, _idx| detab(line) + "\n" } end end
column_begin(level, label, caption)
click to toggle source
# File lib/review/latexbuilder.rb, line 182 def column_begin(level, label, caption) blank @doc_status[:column] = true target = nil if label target = "\\hypertarget{#{column_label(label)}}{}" else target = "\\hypertarget{#{column_label(caption)}}{}" end @doc_status[:caption] = true if @book.config.check_version('2', exception: false) puts '\\begin{reviewcolumn}' puts target puts macro('reviewcolumnhead', nil, compile_inline(caption)) else # ver.3 print '\\begin{reviewcolumn}' puts "[#{compile_inline(caption)}#{target}]" end @doc_status[:caption] = nil if level <= @book.config['toclevel'].to_i puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}" end end
column_end(_level)
click to toggle source
# File lib/review/latexbuilder.rb, line 210 def column_end(_level) puts '\\end{reviewcolumn}' blank @doc_status[:column] = nil end
comment(lines, comment = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 882 def comment(lines, comment = nil) return true unless @book.config['draft'] lines ||= [] unless comment.blank? lines.unshift escape(comment) end str = lines.join('\par ') puts macro('pdfcomment', str) end
common_code_block(id, lines, command, caption, _lang) { |line, idx| ... }
click to toggle source
# File lib/review/latexbuilder.rb, line 379 def common_code_block(id, lines, command, caption, _lang) @doc_status[:caption] = true unless @book.config.check_version('2', exception: false) puts '\\begin{reviewlistblock}' end if caption.present? if command =~ /emlist/ || command =~ /cmd/ || command =~ /source/ puts macro(command + 'caption', compile_inline(caption)) else begin if get_chap.nil? puts macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") else puts macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") end rescue KeyError error "no such list: #{id}" end end end @doc_status[:caption] = nil body = '' lines.each_with_index do |line, idx| body.concat(yield(line, idx)) end puts macro('begin', command) print body puts macro('end', command) unless @book.config.check_version('2', exception: false) puts '\\end{reviewlistblock}' end blank end
common_code_block_lst(_id, lines, command, title, caption, lang, first_line_num: 1)
click to toggle source
# File lib/review/latexbuilder.rb, line 413 def common_code_block_lst(_id, lines, command, title, caption, lang, first_line_num: 1) if title == 'title' && caption.blank? && @book.config.check_version('2', exception: false) print '\vspace{-1.5em}' end body = lines.inject('') { |i, j| i + detab(unescape(j)) + "\n" } args = make_code_block_args(title, caption, lang, first_line_num: first_line_num) puts %Q(\\begin{#{command}}[#{args}]) print body puts %Q(\\end{#{command}}) blank end
compile_href(url, label)
click to toggle source
# File lib/review/latexbuilder.rb, line 1254 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)
click to toggle source
# File lib/review/latexbuilder.rb, line 1246 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)
click to toggle source
# File lib/review/latexbuilder.rb, line 1021 def compile_ruby(base, ruby) macro('ruby', escape(base), escape(ruby).gsub('\\textbar{}', '|')) end
dd(lines)
click to toggle source
# File lib/review/latexbuilder.rb, line 300 def dd(lines) puts lines.map(&:chomp).join("\n") end
direct(lines, fmt)
click to toggle source
# File lib/review/latexbuilder.rb, line 875 def direct(lines, fmt) return unless fmt == 'latex' lines.each do |line| puts line end end
dl_begin()
click to toggle source
# File lib/review/latexbuilder.rb, line 289 def dl_begin blank puts '\begin{description}' end
dl_end()
click to toggle source
# File lib/review/latexbuilder.rb, line 304 def dl_end puts '\end{description}' blank end
dt(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 294 def dt(str) str.sub!(/\[/) { '\lbrack{}' } str.sub!(/\]/) { '\rbrack{}' } puts '\item[' + str + '] \mbox{} \\\\' end
emlist(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 332 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) { |line, _idx| detab(line) + "\n" } end end
emlistnum(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 341 def emlistnum(lines, caption = nil, lang = nil) blank first_line_num = line_num if highlight_listings? common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang, first_line_num: first_line_num) else common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, idx| detab((idx + first_line_num).to_s.rjust(2) + ': ' + line) + "\n" } end end
emtable(lines, caption = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 778 def emtable(lines, caption = nil) table(lines, nil, caption) end
extname()
click to toggle source
# File lib/review/latexbuilder.rb, line 26 def extname '.tex' end
flushright(lines)
click to toggle source
# File lib/review/latexbuilder.rb, line 836 def flushright(lines) latex_block 'flushright', lines end
footnote(id, content)
click to toggle source
# File lib/review/latexbuilder.rb, line 996 def footnote(id, content) if @book.config['footnotetext'] || @foottext[id] puts macro("footnotetext[#{@chapter.footnote(id).number}]", compile_inline(content.strip)) end end
handle_metric(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 459 def handle_metric(str) if @book.config['image_scale2width'] && str =~ /\Ascale=([\d.]+)\Z/ return "width=#{$1}\\maxwidth" end str end
headline(level, label, caption)
click to toggle source
# File lib/review/latexbuilder.rb, line 116 def headline(level, label, caption) _, anchor = headline_prefix(level) headline_name = HEADLINE[level] if @chapter.is_a?(ReVIEW::Book::Part) if @book.config.check_version('2', exception: false) headline_name = 'part' elsif level == 1 headline_name = 'part' puts '\begin{reviewpart}' end end prefix = '' if level > @book.config['secnolevel'] || (@chapter.number.to_s.empty? && level > 1) prefix = '*' end blank unless @output.pos == 0 @doc_status[:caption] = true puts macro(headline_name + prefix, compile_inline(caption)) @doc_status[:caption] = nil 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)) puts macro('label', label) if label end rescue error "unknown level: #{level}" end
hr()
click to toggle source
# File lib/review/latexbuilder.rb, line 892 def hr puts '\hrule' end
image_dummy(id, caption, lines)
click to toggle source
# File lib/review/latexbuilder.rb, line 497 def image_dummy(id, caption, lines) warn "image not bound: #{id}" puts '\begin{reviewdummyimage}' # path = @chapter.image(id).path puts "--[[path = #{id} (#{existence(id)})]]--" lines.each do |line| puts detab(line.rstrip) end puts macro('label', image_label(id)) @doc_status[:caption] = true if @book.config.check_version('2', exception: false) puts macro('caption', compile_inline(caption)) if caption.present? else puts macro('reviewimagecaption', compile_inline(caption)) if caption.present? end @doc_status[:caption] = nil puts '\end{reviewdummyimage}' end
image_ext()
click to toggle source
# File lib/review/latexbuilder.rb, line 1270 def image_ext 'pdf' end
image_header(id, caption)
click to toggle source
# File lib/review/latexbuilder.rb, line 456 def image_header(id, caption) end
image_image(id, caption, metric)
click to toggle source
# File lib/review/latexbuilder.rb, line 470 def image_image(id, caption, metric) metrics = parse_metric('latex', metric) # image is always bound here puts "\\begin{reviewimage}%%#{id}" command = 'reviewincludegraphics' if @book.config.check_version('2', exception: false) command = 'includegraphics' end if metrics.present? puts "\\#{command}[#{metrics}]{#{@chapter.image(id).path}}" else puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}" end @doc_status[:caption] = true if @book.config.check_version('2', exception: false) puts macro('caption', compile_inline(caption)) if caption.present? else puts macro('reviewimagecaption', compile_inline(caption)) if caption.present? end @doc_status[:caption] = nil puts macro('label', image_label(id)) puts '\end{reviewimage}' end
imgtable(lines, id, caption = nil, metric = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 782 def imgtable(lines, id, caption = nil, metric = nil) unless @chapter.image(id).bound? warn "image not bound: #{id}" image_dummy id, caption, lines return end begin if caption.present? @table_caption = true @doc_status[:caption] = true puts "\\begin{table}[h]%%#{id}" puts macro('reviewimgtablecaption', compile_inline(caption)) @doc_status[:caption] = nil end puts macro('label', table_label(id)) rescue ReVIEW::KeyError error "no such table: #{id}" end imgtable_image(id, caption, metric) puts '\end{table}' if @table_caption @table_caption = nil blank end
imgtable_image(id, _caption, metric)
click to toggle source
# File lib/review/latexbuilder.rb, line 808 def imgtable_image(id, _caption, metric) metrics = parse_metric('latex', metric) # image is always bound here puts "\\begin{reviewimage}%%#{id}" command = 'reviewincludegraphics' if @book.config.check_version('2', exception: false) command = 'includegraphics' end if metrics.present? puts "\\#{command}[#{metrics}]{#{@chapter.image(id).path}}" else puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}" end puts '\end{reviewimage}' end
indepimage(lines, id, caption = nil, metric = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 555 def indepimage(lines, id, caption = nil, metric = nil) metrics = parse_metric('latex', metric) if @chapter.image(id).path puts "\\begin{reviewimage}%%#{id}" command = 'reviewincludegraphics' if @book.config.check_version('2', exception: false) command = 'includegraphics' end if metrics.present? puts "\\#{command}[#{metrics}]{#{@chapter.image(id).path}}" else puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}" end else warn "image not bound: #{id}" puts '\begin{reviewdummyimage}' puts "--[[path = #{id} (#{existence(id)})]]--" lines.each do |line| puts detab(line.rstrip) end end @doc_status[:caption] = true if caption.present? puts macro('reviewindepimagecaption', %Q(#{I18n.t('numberless_image')}#{I18n.t('caption_prefix')}#{compile_inline(caption)})) end @doc_status[:caption] = nil if @chapter.image(id).path puts '\end{reviewimage}' else puts '\end{reviewdummyimage}' end end
Also aliased as: numberlessimage
index(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1222 def index(str) sa = str.split('<<>>') sa.map! do |item| if @index_db[item] escape_index(escape(@index_db[item])) + '@' + escape_index(escape(item)) else if item =~ /\A[[:ascii:]]+\Z/ || @index_mecab.nil? esc_item = escape_index(escape(item)) if esc_item != item "#{escape_index(item)}@#{esc_item}" else esc_item end else yomi = NKF.nkf('-w --hiragana', @index_mecab.parse(item).force_encoding('UTF-8').chomp) escape_index(escape(yomi)) + '@' + escape_index(escape(item)) end end end "\\index{#{sa.join('!')}}" end
inline_ami(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1169 def inline_ami(str) macro('reviewami', escape(str)) end
inline_b(str)
click to toggle source
bold
# File lib/review/latexbuilder.rb, line 1059 def inline_b(str) if @book.config.check_version('2', exception: false) macro('textbf', escape(str)) else macro('reviewbold', escape(str)) end end
inline_balloon(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1208 def inline_balloon(str) macro('reviewballoon', escape(str)) end
inline_bib(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 1118 def inline_bib(id) macro('reviewbibref', "[#{@chapter.bibpaper(id).number}]", bib_label(id)) end
inline_bou(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1017 def inline_bou(str) macro('reviewbou', escape(str)) end
inline_br(_str)
click to toggle source
line break
# File lib/review/latexbuilder.rb, line 1068 def inline_br(_str) "\\\\\n" end
inline_chap(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 924 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)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_chapref
# File lib/review/latexbuilder.rb, line 912 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)
click to toggle source
@<code> is same as @<tt>
# File lib/review/latexbuilder.rb, line 1078 def inline_code(str) if @book.config.check_version('2', exception: false) macro('texttt', escape(str)) else macro('reviewcode', escape(str)) end end
inline_column_chap(chapter, id)
click to toggle source
# File lib/review/latexbuilder.rb, line 1137 def inline_column_chap(chapter, id) macro('reviewcolumnref', I18n.t('column', compile_inline(chapter.column(id).caption)), column_label(id, chapter)) rescue KeyError error "unknown column: #{id}" end
inline_comment(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1196 def inline_comment(str) if @book.config['draft'] macro('pdfcomment', escape(str)) else '' end end
inline_del(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1098 def inline_del(str) macro('reviewstrike', escape(str)) end
inline_dtp(_str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1072 def inline_dtp(_str) # ignore '' end
inline_em(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1157 def inline_em(str) macro('reviewem', escape(str)) end
inline_eq(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 985 def inline_eq(id) chapter, id = extract_chapter_id(id) if get_chap(chapter).nil? macro('reviewequationref', I18n.t('format_number_without_chapter', [chapter.equation(id).number])) else macro('reviewequationref', I18n.t('format_number', [get_chap(chapter), chapter.equation(id).number])) end rescue KeyError error "unknown equation: #{id}" end
inline_fn(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 1002 def inline_fn(id) if @book.config['footnotetext'] macro("footnotemark[#{@chapter.footnote(id).number}]", '') elsif @doc_status[:caption] || @doc_status[:table] || @doc_status[:column] @foottext[id] = @chapter.footnote(id).number macro('protect\\footnotemark', '') else macro('footnote', compile_inline(@chapter.footnote(id).content.strip)) end rescue KeyError error "unknown footnote: #{id}" end
inline_hd_chap(chap, id)
click to toggle source
# File lib/review/latexbuilder.rb, line 1122 def inline_hd_chap(chap, id) n = chap.headline_index.number(id) if n.present? && chap.number && over_secnolevel?(n) str = I18n.t('hd_quote', [chap.headline_index.number(id), compile_inline(chap.headline(id).caption)]) else str = I18n.t('hd_quote_without_number', 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)
click to toggle source
hidden index
# File lib/review/latexbuilder.rb, line 1035 def inline_hi(str) index(str) end
inline_hidx(str)
click to toggle source
hidden index
# File lib/review/latexbuilder.rb, line 1054 def inline_hidx(str) index(str) end
inline_i(str)
click to toggle source
index -> italic
# File lib/review/latexbuilder.rb, line 1040 def inline_i(str) if @book.config.check_version('2', exception: false) macro('textit', escape(str)) else macro('reviewit', escape(str)) end end
inline_icon(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 1173 def inline_icon(id) if @chapter.image(id).path command = 'reviewincludegraphics' if @book.config.check_version('2', exception: false) command = 'includegraphics' end macro(command, @chapter.image(id).path) else warn "image not bound: #{id}" "\\verb|--[[path = #{id} (#{existence(id)})]]--|" end end
inline_idx(str)
click to toggle source
index
# File lib/review/latexbuilder.rb, line 1049 def inline_idx(str) escape(str) + index(str) end
inline_img(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 974 def inline_img(id) chapter, id = extract_chapter_id(id) if get_chap(chapter).nil? macro('reviewimageref', I18n.t('format_number_without_chapter', [chapter.image(id).number]), image_label(id, chapter)) else macro('reviewimageref', I18n.t('format_number', [get_chap(chapter), chapter.image(id).number]), image_label(id, chapter)) end rescue KeyError error "unknown image: #{id}" end
inline_list(id)
click to toggle source
FIXME: use TeX native label/ref.
# File lib/review/latexbuilder.rb, line 952 def inline_list(id) chapter, id = extract_chapter_id(id) if get_chap(chapter).nil? macro('reviewlistref', I18n.t('format_number_without_chapter', [chapter.list(id).number])) else macro('reviewlistref', I18n.t('format_number', [get_chap(chapter), chapter.list(id).number])) end rescue KeyError error "unknown list: #{id}" end
inline_m(str)
click to toggle source
math
# File lib/review/latexbuilder.rb, line 1026 def inline_m(str) if @book.config.check_version('2', exception: false) " $#{str}$ " else "$#{str}$" end end
inline_pageref(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 947 def inline_pageref(id) "\\pageref{#{id}}" end
inline_raw(str)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_raw
# File lib/review/latexbuilder.rb, line 1145 def inline_raw(str) super(str) end
inline_strong(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1161 def inline_strong(str) macro('reviewstrong', escape(str)) end
inline_sub(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1149 def inline_sub(str) macro('textsubscript', escape(str)) end
inline_sup(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1153 def inline_sup(str) macro('textsuperscript', escape(str)) end
inline_table(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 963 def inline_table(id) chapter, id = extract_chapter_id(id) if get_chap(chapter).nil? macro('reviewtableref', I18n.t('format_number_without_chapter', [chapter.table(id).number]), table_label(id, chapter)) else macro('reviewtableref', I18n.t('format_number', [get_chap(chapter), chapter.table(id).number]), table_label(id, chapter)) end rescue KeyError error "unknown table: #{id}" end
inline_tcy(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1204 def inline_tcy(str) macro('rensuji', escape(str)) end
inline_title(id)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_title
# File lib/review/latexbuilder.rb, line 935 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)
click to toggle source
# File lib/review/latexbuilder.rb, line 1090 def inline_tt(str) if @book.config.check_version('2', exception: false) macro('texttt', escape(str)) else macro('reviewtt', escape(str)) end end
inline_ttb(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1110 def inline_ttb(str) if @book.config.check_version('2', exception: false) macro('texttt', macro('textbf', escape(str))) else macro('reviewttb', escape(str)) end end
inline_tti(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1102 def inline_tti(str) if @book.config.check_version('2', exception: false) macro('texttt', macro('textit', escape(str))) else macro('reviewtti', escape(str)) end end
inline_u(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1165 def inline_u(str) macro('reviewunderline', escape(str)) end
inline_uchar(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1186 def inline_uchar(str) if @texcompiler && @texcompiler.start_with?('platex') # with otf package macro('UTF', escape(str)) else # passthrough [str.to_i(16)].pack('U') end end
label(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 896 def label(id) puts macro('label', id) end
latextsize(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1266 def latextsize(str) @latex_tsize = str end
list(lines, id, caption, lang = nil)
click to toggle source
override Builder#list
# File lib/review/latexbuilder.rb, line 352 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) { |line, _idx| detab(line) + "\n" } end end
listnum(lines, id, caption, lang = nil)
click to toggle source
override Builder#listnum
# File lib/review/latexbuilder.rb, line 361 def listnum(lines, id, caption, lang = nil) first_line_num = line_num if highlight_listings? common_code_block_lst(id, lines, 'reviewlistnumlst', 'caption', caption, lang, first_line_num: first_line_num) else common_code_block(id, lines, 'reviewlist', caption, lang) { |line, idx| detab((idx + first_line_num).to_s.rjust(2) + ': ' + line) + "\n" } end end
load_idxdb(file)
click to toggle source
# File lib/review/latexbuilder.rb, line 68 def load_idxdb(file) table = {} File.foreach(file) do |line| key, value = *line.strip.split(/\t+/, 2) table[key] = value end table end
make_code_block_args(title, caption, lang, first_line_num: 1)
click to toggle source
# File lib/review/latexbuilder.rb, line 425 def make_code_block_args(title, caption, lang, first_line_num: 1) caption_str = compile_inline((caption || '')) if title == 'title' && caption_str == '' && @book.config.check_version('2', exception: false) caption_str = '\relax' ## dummy charactor to remove lstname end lexer = if @book.config['highlight'] && @book.config['highlight']['lang'] @book.config['highlight']['lang'] # default setting else '' end lexer = lang if lang.present? args = "language={#{lexer}}" if title == 'title' && caption_str == '' # ignore else args = "#{title}={#{caption_str}}," + args end if first_line_num != 1 args << ",firstnumber=#{first_line_num}" end args end
nodisp_begin(level, _label, caption)
click to toggle source
# File lib/review/latexbuilder.rb, line 169 def nodisp_begin(level, _label, caption) if @output.pos != 0 blank else puts macro('clearpage') end puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption)) # FIXME: headings end
nodisp_end(level)
click to toggle source
# File lib/review/latexbuilder.rb, line 179 def nodisp_end(level) end
nofunc_text(str)
click to toggle source
# File lib/review/latexbuilder.rb, line 1086 def nofunc_text(str) escape(str) end
noindent()
click to toggle source
# File lib/review/latexbuilder.rb, line 908 def noindent print '\noindent' end
nonum_begin(level, _label, caption)
click to toggle source
# File lib/review/latexbuilder.rb, line 148 def nonum_begin(level, _label, caption) blank unless @output.pos == 0 @doc_status[:caption] = true puts macro(HEADLINE[level] + '*', compile_inline(caption)) @doc_status[:caption] = nil puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption)) end
nonum_end(level)
click to toggle source
# File lib/review/latexbuilder.rb, line 156 def nonum_end(level) end
notoc_begin(level, _label, caption)
click to toggle source
# File lib/review/latexbuilder.rb, line 159 def notoc_begin(level, _label, caption) blank unless @output.pos == 0 @doc_status[:caption] = true puts macro(HEADLINE[level] + '*', compile_inline(caption)) @doc_status[:caption] = nil end
notoc_end(level)
click to toggle source
# File lib/review/latexbuilder.rb, line 166 def notoc_end(level) end
ol_begin()
click to toggle source
# File lib/review/latexbuilder.rb, line 270 def ol_begin blank puts '\begin{enumerate}' return true unless @ol_num puts "\\setcounter{enumi}{#{@ol_num - 1}}" @ol_num = nil end
ol_end()
click to toggle source
# File lib/review/latexbuilder.rb, line 284 def ol_end puts '\end{enumerate}' blank end
ol_item(lines, _num)
click to toggle source
# File lib/review/latexbuilder.rb, line 278 def ol_item(lines, _num) str = lines.map(&:chomp).join("\n") str.sub!(/\A(\[)/) { '\lbrack{}' } puts '\item ' + str end
olnum(num)
click to toggle source
# File lib/review/latexbuilder.rb, line 1274 def olnum(num) @ol_num = num.to_i end
pagebreak()
click to toggle source
# File lib/review/latexbuilder.rb, line 900 def pagebreak puts '\pagebreak' end
paragraph(lines)
click to toggle source
# File lib/review/latexbuilder.rb, line 309 def paragraph(lines) blank lines.each do |line| puts line end blank end
parasep()
click to toggle source
# File lib/review/latexbuilder.rb, line 317 def parasep puts '\\parasep' end
quote(lines)
click to toggle source
# File lib/review/latexbuilder.rb, line 826 def quote(lines) latex_block 'quote', lines end
read(lines)
click to toggle source
# File lib/review/latexbuilder.rb, line 321 def read(lines) latex_block 'quotation', lines end
Also aliased as: lead
result()
click to toggle source
# File lib/review/latexbuilder.rb, line 100 def result if @chapter.is_a?(ReVIEW::Book::Part) && !@book.config.check_version('2', exception: false) puts '\end{reviewpart}' end @output.string end
result_metric(array)
click to toggle source
# File lib/review/latexbuilder.rb, line 466 def result_metric(array) array.join(',') end
separate_tsize(size)
click to toggle source
# File lib/review/latexbuilder.rb, line 696 def separate_tsize(size) ret = [] s = '' brace = nil size.split('').each do |ch| case ch when '|' next when '{' brace = true s << ch when '}' brace = nil s << ch ret << s s = '' else if brace s << ch else if s.empty? s << ch else ret << s s = ch end end end end unless s.empty? ret << s end ret end
setup_index()
click to toggle source
# File lib/review/latexbuilder.rb, line 46 def setup_index @index_db = {} @index_mecab = nil return true unless @book.config['pdfmaker']['makeindex'] if @book.config['pdfmaker']['makeindex_dic'] @index_db = load_idxdb(@book.config['pdfmaker']['makeindex_dic']) end return true unless @book.config['pdfmaker']['makeindex_mecab'] begin begin require 'MeCab' rescue LoadError require 'mecab' end require 'nkf' @index_mecab = MeCab::Tagger.new(@book.config['pdfmaker']['makeindex_mecab_opts']) rescue LoadError error 'not found MeCab' end end
source(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 448 def source(lines, caption = nil, lang = nil) if highlight_listings? common_code_block_lst(nil, lines, 'reviewsourcelst', 'title', caption, lang) else common_code_block(nil, lines, 'reviewsource', caption, lang) { |line, _idx| detab(line) + "\n" } end end
table(lines, id = nil, caption = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 596 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) error 'no rows in the table' if rows.empty? begin table_header(id, caption) if caption.present? rescue KeyError error "no such table: #{id}" end table_begin(rows.first.size) if sepidx sepidx.times do cno = -1 tr(rows.shift.map do |s| cno += 1 th(s, @cellwidth[cno]) end) end rows.each do |cols| cno = -1 tr(cols.map do |s| cno += 1 td(s, @cellwidth[cno]) end) end else rows.each do |cols| h, *cs = *cols cno = 0 tr([th(h, @cellwidth[0])] + cs.map do |s| cno += 1 td(s, @cellwidth[cno]) end) end end table_end end
table_begin(ncols)
click to toggle source
# File lib/review/latexbuilder.rb, line 675 def table_begin(ncols) if @latex_tsize @tsize = @latex_tsize end if @tsize if @tsize =~ /\A[\d., ]+\Z/ @cellwidth = @tsize.split(/\s*,\s*/) @cellwidth.collect! { |i| "p{#{i}mm}" } puts macro('begin', 'reviewtable', '|' + @cellwidth.join('|') + '|') else @cellwidth = separate_tsize(@tsize) puts macro('begin', 'reviewtable', @tsize) end else puts macro('begin', 'reviewtable', (['|'] * (ncols + 1)).join('l')) @cellwidth = ['l'] * ncols end puts '\\hline' end
table_end()
click to toggle source
# File lib/review/latexbuilder.rb, line 768 def table_end puts macro('end', 'reviewtable') puts '\end{table}' if @table_caption @table_caption = nil @tsize = nil @latex_tsize = nil @cellwidth = nil blank end
table_header(id, caption)
click to toggle source
# File lib/review/latexbuilder.rb, line 646 def table_header(id, caption) if id.nil? if caption.present? @table_caption = true @doc_status[:caption] = true if @book.config.check_version('2', exception: false) puts "\\begin{table}[h]%%#{id}" else puts "\\begin{table}%%#{id}" end puts macro('reviewtablecaption*', compile_inline(caption)) @doc_status[:caption] = nil end else if caption.present? @table_caption = true @doc_status[:caption] = true if @book.config.check_version('2', exception: false) puts "\\begin{table}[h]%%#{id}" else puts "\\begin{table}%%#{id}" end puts macro('reviewtablecaption', compile_inline(caption)) @doc_status[:caption] = nil end puts macro('label', table_label(id)) end end
table_separator()
click to toggle source
# File lib/review/latexbuilder.rb, line 733 def table_separator # puts '\hline' end
td(s, cellwidth = 'l')
click to toggle source
# File lib/review/latexbuilder.rb, line 750 def td(s, cellwidth = 'l') if /\\\\/ =~ s if !@book.config.check_version('2', exception: false) && cellwidth =~ /\{/ s.gsub("\\\\\n", '\\newline{}') else ## use shortstack for @<br> macro('shortstack[l]', s) end else s end end
texequation(lines, id = nil, caption = '')
click to toggle source
# File lib/review/latexbuilder.rb, line 840 def texequation(lines, id = nil, caption = '') blank if id puts macro('begin', 'reviewequationblock') if get_chap.nil? puts macro('reviewequationcaption', "#{I18n.t('equation')}#{I18n.t('format_number_header_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") else puts macro('reviewequationcaption', "#{I18n.t('equation')}#{I18n.t('format_number_header', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}") end end puts macro('begin', 'equation*') lines.each do |line| puts unescape(line) end puts macro('end', 'equation*') if id puts macro('end', 'reviewequationblock') end blank end
th(s, cellwidth = 'l')
click to toggle source
# File lib/review/latexbuilder.rb, line 737 def th(s, cellwidth = 'l') if /\\\\/ =~ s if !@book.config.check_version('2', exception: false) && cellwidth =~ /\{/ macro('reviewth', s.gsub("\\\\\n", '\\newline{}')) else ## use shortstack for @<br> macro('reviewth', macro('shortstack[l]', s)) end else macro('reviewth', s) end end
tr(rows)
click to toggle source
# File lib/review/latexbuilder.rb, line 763 def tr(rows) print rows.join(' & ') puts ' \\\\ \hline' end
ul_begin()
click to toggle source
# File lib/review/latexbuilder.rb, line 254 def ul_begin blank puts '\begin{itemize}' end
ul_end()
click to toggle source
# File lib/review/latexbuilder.rb, line 265 def ul_end puts '\end{itemize}' blank end
ul_item(lines)
click to toggle source
# File lib/review/latexbuilder.rb, line 259 def ul_item(lines) str = lines.map(&:chomp).join("\n") str.sub!(/\A(\[)/) { '\lbrack{}' } puts '\item ' + str end
Private Instance Methods
bib_label(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 543 def bib_label(id) "bib:#{id}" end
blank()
click to toggle source
# File lib/review/latexbuilder.rb, line 77 def blank @blank_needed = true end
builder_init_file()
click to toggle source
# File lib/review/latexbuilder.rb, line 30 def builder_init_file @chapter.book.image_types = %w[.ai .eps .pdf .tif .tiff .png .bmp .jpg .jpeg .gif] @blank_needed = false @latex_tsize = nil @tsize = nil @table_caption = nil @cellwidth = nil @ol_num = nil @first_line_num = nil @sec_counter = SecCounter.new(5, @chapter) @foottext = {} setup_index initialize_metachars(@book.config['texcommand']) end
chapter_label()
click to toggle source
# File lib/review/latexbuilder.rb, line 527 def chapter_label "chap:#{@chapter.id}" end
column_label(id, chapter = @chapter)
click to toggle source
# File lib/review/latexbuilder.rb, line 548 def column_label(id, chapter = @chapter) filename = chapter.id num = chapter.column(id).number "column:#{filename}:#{num}" end
existence(id)
click to toggle source
# File lib/review/latexbuilder.rb, line 516 def existence(id) @chapter.image(id).bound? ? 'exist' : 'not exist' end
highlight_listings?()
click to toggle source
# File lib/review/latexbuilder.rb, line 327 def highlight_listings? @book.config['highlight'] && @book.config['highlight']['latex'] == 'listings' end
image_label(id, chapter = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 521 def image_label(id, chapter = nil) chapter ||= @chapter "image:#{chapter.id}:#{id}" end
latex_block(type, lines)
click to toggle source
# File lib/review/latexbuilder.rb, line 865 def latex_block(type, lines) blank puts macro('begin', type) blocked_lines = split_paragraph(lines) puts blocked_lines.join("\n\n") puts macro('end', type) blank end
print(*s)
click to toggle source
Calls superclass method
ReVIEW::Builder#print
# File lib/review/latexbuilder.rb, line 82 def print(*s) if @blank_needed @output.puts @blank_needed = false end super end
puts(*s)
click to toggle source
Calls superclass method
ReVIEW::Builder#puts
# File lib/review/latexbuilder.rb, line 91 def puts(*s) if @blank_needed @output.puts @blank_needed = false end super end
sec_label(sec_anchor)
click to toggle source
# File lib/review/latexbuilder.rb, line 532 def sec_label(sec_anchor) "sec:#{sec_anchor}" end
table_label(id, chapter = nil)
click to toggle source
# File lib/review/latexbuilder.rb, line 537 def table_label(id, chapter = nil) chapter ||= @chapter "table:#{chapter.id}:#{id}" end