lib/review/latexbuilder.rb in review-2.2.0 vs lib/review/latexbuilder.rb in review-2.3.0

- old
+ new

@@ -1,10 +1,10 @@ # encoding: utf-8 -# + # Copyright (c) 2002-2007 Minero Aoki # 2008-2009 Minero Aoki, Kenshi Muto -# 2010-2016 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi +# 2010-2017 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi # # This program is free software. # You can distribute or modify this program under the terms of # the GNU LGPL, Lesser General Public License version 2.1. # For details of the GNU LGPL, see the file "COPYING". @@ -30,10 +30,11 @@ def extname '.tex' end 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 @ol_num = nil @@ -337,11 +338,15 @@ if caption if command =~ /emlist/ || command =~ /cmd/ || command =~ /source/ 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)}") + 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 @@ -393,11 +398,10 @@ detab(line) + "\n" end end end - def image_header(id, caption) end def handle_metric(str) if @book.config["image_scale2width"] && str =~ /\Ascale=([\d.]+)\Z/ @@ -502,11 +506,11 @@ # just ignore #error "too many table separator" if sepidx sepidx ||= idx next end - rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') } + rows.push(line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }) end rows = adjust_n_cols(rows) begin table_header id, caption unless caption.nil? @@ -515,31 +519,39 @@ end return if rows.empty? table_begin rows.first.size if sepidx sepidx.times do - tr rows.shift.map {|s| th(s) } + tr(rows.shift.map {|s| th(s) }) end rows.each do |cols| - tr cols.map {|s| td(s) } + tr(cols.map {|s| td(s) }) end else rows.each do |cols| h, *cs = *cols - tr [th(h)] + cs.map {|s| td(s) } + tr([th(h)] + cs.map {|s| td(s) }) end end table_end end def table_header(id, caption) - if caption.present? - @table_caption = true - puts '\begin{table}[h]' - puts macro('reviewtablecaption', compile_inline(caption)) + if id.nil? + if caption.present? + @table_caption = true + puts '\begin{table}[h]' + puts macro('reviewtablecaption*', compile_inline(caption)) + end + else + if caption.present? + @table_caption = true + puts '\begin{table}[h]' + puts macro('reviewtablecaption', compile_inline(caption)) + end + puts macro('label', table_label(id)) end - puts macro('label', table_label(id)) end def table_begin(ncols) if @latex_tsize puts macro('begin', 'reviewtable', @latex_tsize) @@ -592,10 +604,14 @@ end @table_caption = nil blank end + def emtable(lines, caption = nil) + table(lines, nil, caption) + end + def imgtable(lines, id, caption = nil, metric = nil) if !@chapter.image(id).bound? warn "image not bound: #{id}" image_dummy id, caption, lines return @@ -733,24 +749,35 @@ rescue KeyError error "unknown chapter: #{id}" nofunc_text("[UnknownChapter:#{id}]") end - # FIXME: use TeX native label/ref. def inline_list(id) chapter, id = extract_chapter_id(id) - macro('reviewlistref', "#{chapter.number}.#{chapter.list(id).number}") + if get_chap(chapter).nil? + macro('reviewlistref', I18n.t("format_number_without_header", [chapter.list(id).number])) + else + macro('reviewlistref', I18n.t("format_number", [get_chap(chapter), chapter.list(id).number])) + end end def inline_table(id) chapter, id = extract_chapter_id(id) - macro('reviewtableref', "#{chapter.number}.#{chapter.table(id).number}", table_label(id, chapter)) + if get_chap(chapter).nil? + macro('reviewtableref', I18n.t("format_number_without_header", [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 end def inline_img(id) chapter, id = extract_chapter_id(id) - macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}", image_label(id, chapter)) + if get_chap(chapter).nil? + macro('reviewimageref', I18n.t("format_number_without_header", [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 end def footnote(id, content) if @book.config["footnotetext"] puts macro("footnotetext[#{@chapter.footnote(id).number}]",