lib/review/latexbuilder.rb in review-3.0.0.preview4 vs lib/review/latexbuilder.rb in review-3.0.0.rc1

- old
+ new

@@ -31,10 +31,11 @@ @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 @@ -94,10 +95,17 @@ end super end private :puts + def result + if @chapter.is_a?(ReVIEW::Book::Part) && !@book.config.check_version('2', exception: false) + puts '\end{reviewpart}' + end + @output.string + end + HEADLINE = { 1 => 'chapter', 2 => 'section', 3 => 'subsection', 4 => 'subsubsection', @@ -106,12 +114,17 @@ }.freeze def headline(level, label, caption) _, anchor = headline_prefix(level) headline_name = HEADLINE[level] - if @chapter.is_a? ReVIEW::Book::Part - headline_name = 'part' + 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 @@ -580,19 +593,32 @@ end return if rows.empty? table_begin(rows.first.size) if sepidx sepidx.times do - tr(rows.shift.map { |s| th(s) }) + cno = -1 + tr(rows.shift.map do |s| + cno += 1 + th(s, @cellwidth[cno]) + end) end rows.each do |cols| - tr(cols.map { |s| td(s) }) + cno = -1 + tr(cols.map do |s| + cno += 1 + td(s, @cellwidth[cno]) + end) end else rows.each do |cols| h, *cs = *cols - tr([th(h)] + cs.map { |s| td(s) }) + cno = 0 + tr([th(h, @cellwidth[0])] + + cs.map do |s| + cno += 1 + td(s, @cellwidth[cno]) + end) end end table_end end @@ -625,43 +651,91 @@ end end def table_begin(ncols) if @latex_tsize - puts macro('begin', 'reviewtable', @latex_tsize) - elsif @tsize + @tsize = @latex_tsize + end + + if @tsize if @tsize =~ /\A[\d., ]+\Z/ - cellwidth = @tsize.split(/\s*,\s*/) - puts macro('begin', 'reviewtable', '|' + cellwidth.collect { |i| "p{#{i}mm}" }.join('|') + '|') + @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' - @tsize = nil - @latex_tsize = nil + puts '\\hline' end + 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 + def table_separator # puts '\hline' end - def th(s) - ## use shortstack for @<br> + def th(s, cellwidth = 'l') if /\\\\/ =~ s - macro('reviewth', macro('shortstack[l]', 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 - def td(s) - ## use shortstack for @<br> + def td(s, cellwidth = 'l') if /\\\\/ =~ s - macro('shortstack[l]', 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 @@ -672,9 +746,12 @@ 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 def emtable(lines, caption = nil) table(lines, nil, caption)