lib/review/latexbuilder.rb in review-1.7.0 vs lib/review/latexbuilder.rb in review-1.7.1

- old
+ new

@@ -236,75 +236,74 @@ private :highlight_listings? def emlist(lines, caption = nil, lang = nil) blank if highlight_listings? - common_code_block_lst(lines, 'reviewemlistlst', 'title', caption, lang) + common_code_block_lst(nil, lines, 'reviewemlistlst', 'title', caption, lang) else - common_code_block(lines, 'reviewemlist', caption, lang) do |line, idx| + common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx| detab(line) + "\n" end end end def emlistnum(lines, caption = nil, lang = nil) blank if highlight_listings? - common_code_block_lst(lines, 'reviewemlistnumlst', 'title', caption, lang) + common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang) else - common_code_block(lines, 'reviewemlist', caption, lang) do |line, idx| + common_code_block(nil, lines, 'reviewemlist', caption, lang) do |line, idx| detab((idx+1).to_s.rjust(2)+": " + line) + "\n" end end end ## override Builder#list def list(lines, id, caption, lang = nil) if highlight_listings? - common_code_block_lst(lines, 'reviewlistlst', 'caption', caption, lang) + common_code_block_lst(id, 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| + common_code_block(id, lines, 'reviewlist', nil, lang) do |line, idx| detab(line) + "\n" end end end ## override Builder#listnum def listnum(lines, id, caption, lang = nil) if highlight_listings? - common_code_block_lst(lines, 'reviewlistnumlst', 'caption', caption, lang) + common_code_block_lst(id, 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| + common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx| detab((idx+1).to_s.rjust(2)+": " + line) + "\n" end end end def cmd(lines, caption = nil, lang = nil) if highlight_listings? - common_code_block_lst(lines, 'reviewcmdlst', 'title', caption, lang) + common_code_block_lst(nil, lines, 'reviewcmdlst', 'title', caption, lang) else blank - common_code_block(lines, 'reviewcmd', caption, lang) do |line, idx| + common_code_block(nil, lines, 'reviewcmd', caption, lang) do |line, idx| detab(line) + "\n" end end end - def common_code_block(lines, command, caption, lang) + def common_code_block(id, lines, command, caption, lang) + buf = "" if caption - puts macro(command + 'caption', "#{compile_inline(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 @@ -312,11 +311,11 @@ print body puts macro('end' ,command) blank end - def common_code_block_lst(lines, command, title, caption, lang) + def common_code_block_lst(id, lines, command, title, caption, lang) caption_str = compile_inline((caption || "")) if title == "title" && caption_str == "" caption_str = "\\relax" ## dummy charactor to remove lstname print "\\vspace{-1.5em}" end @@ -333,10 +332,10 @@ blank end def source(lines, caption, lang = nil) if highlight_listings? - common_code_block_lst(lines, 'reviewlistlst', 'title', caption, lang) + 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)