lib/review/latexbuilder.rb in review-0.9.0 vs lib/review/latexbuilder.rb in review-1.0.0

- old
+ new

@@ -19,11 +19,11 @@ class LATEXBuilder < Builder include LaTeXUtils include TextUtils - [:icon, :dtp, :hd_chap].each {|e| + [:dtp, :hd_chap].each {|e| Compiler.definline(e) } Compiler.defblock(:memo, 0..1) Compiler.defsingle(:latextsize, 1) @@ -71,15 +71,18 @@ 4 => 'subsubsection' } def headline(level, label, caption) prefix = "" - if level > ReVIEW.book.param["secnolevel"] + if level > ReVIEW.book.param["secnolevel"] || (@chapter.number.to_s.empty? && level > 1) prefix = "*" end blank unless @output.pos == 0 puts macro(HEADLINE[level]+prefix, compile_inline(caption)) + if level == 1 + puts macro('label', chapter_label) + end end def nonum_begin(level, label, caption) blank unless @output.pos == 0 puts macro(HEADLINE[level]+"*", compile_inline(caption)) @@ -88,11 +91,11 @@ def nonum_end(level) end def column_begin(level, label, caption) blank - ## puts '\vspace{2zw}' + ## puts '\vspace{2zw}' ## puts '\begin{center}' ## puts '\begin{minipage}{1.0\linewidth}' ## puts '\begin{framed}' ## puts '\setlength{\FrameSep}{1zw}' @@ -110,32 +113,35 @@ ## ## puts '\vspace{2zw}' puts "\\end{reviewcolumn}\n" blank end - def minicolumn(type, lines, caption) + def captionblock(type, lines, caption) puts "\\begin{reviewminicolumn}\n" unless caption.nil? puts "\\reviewminicolumntitle{#{compile_inline(caption)}}\n" end - lines.each {|l| - puts l - } + + if ReVIEW.book.param["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 - def memo(lines, caption = nil) - minicolumn("memo", lines, caption) - end - def ul_begin blank puts '\begin{itemize}' end def ul_item(lines) - puts '\item ' + lines.join("\n") + puts '\item ' + lines.join end def ul_end puts '\end{itemize}' blank @@ -145,11 +151,11 @@ blank puts '\begin{enumerate}' end def ol_item(lines, num) - puts '\item ' + lines.join("\n") + puts '\item ' + lines.join end def ol_end puts '\end{enumerate}' blank @@ -163,13 +169,11 @@ def dt(str) puts '\item[' + str + '] \mbox{} \\\\' end def dd(lines) - lines.each do |line| - puts line - end + puts lines.join end def dl_end puts '\end{description}' blank @@ -191,24 +195,30 @@ latex_block 'quotation', lines end alias lead read - def emlist(lines) + def emlist(lines, caption = nil) blank + if caption + puts macro('reviewemlistcaption', "#{compile_inline(caption)}") + end puts '\begin{reviewemlist}' puts '\begin{alltt}' lines.each do |line| puts line end puts '\end{alltt}' puts '\end{reviewemlist}' blank end - def emlistnum(lines) + def emlistnum(lines, caption = nil) blank + if caption + puts macro('reviewemlistcaption', "#{compile_inline(caption)}") + end puts '\begin{reviewemlist}' puts '\begin{alltt}' lines.each_with_index do |line, i| puts detab((i+1).to_s.rjust(2) + ": " + line) end @@ -223,16 +233,19 @@ lines.each_with_index do |line, i| puts detab((i+1).to_s.rjust(2) + ": " + line) end puts '\end{alltt}' puts '\end{reviewlist}' - puts + blank end - def cmd(lines) + def cmd(lines, caption = nil) blank + if caption + puts macro('reviewcmdcaption', "#{compile_inline(caption)}") + end puts '\begin{reviewcmd}' puts '\begin{alltt}' lines.each do |line| puts line end @@ -240,11 +253,11 @@ puts '\end{reviewcmd}' blank end def list_header(id, caption) - puts macro('reviewlistcaption', "リスト#{@chapter.number}.#{@chapter.list(id).number}: #{compile_inline(caption)}") + puts macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])} #{compile_inline(caption)}") end def list_body(lines) puts '\begin{reviewlist}' puts '\begin{alltt}' @@ -278,17 +291,22 @@ def image_header(id, caption) end + def result_metric(array) + "#{array.join(',')}" + end + def image_image(id, caption, metric) + metrics = parse_metric("latex", metric) # image is always bound here puts '\begin{reviewimage}' - if metric - puts "\\includegraphics[#{metric}]{#{@chapter.image(id).path}}" + if !metrics.empty? + puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}" else - puts macro('includegraphics', @chapter.image(id).path) + puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}" end puts macro('label', image_label(id)) if !caption.empty? puts macro('caption', compile_inline(caption)) end @@ -317,16 +335,22 @@ def image_label(id) "image:#{@chapter.id}:#{id}" end private :image_label + def chapter_label() + "chap:#{@chapter.id}" + end + private :chapter_label + def indepimage(id, caption=nil, metric=nil) + metrics = parse_metric("latex", metric) puts '\begin{reviewimage}' - if metric - puts "\\includegraphics[#{metric}]{#{@chapter.image(id).path}}" + if !metrics.empty? + puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}" else - puts macro('includegraphics', @chapter.image(id).path) + puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}" end if !caption.nil? && !caption.empty? puts macro('caption', compile_inline(caption)) end puts '\end{reviewimage}' @@ -437,11 +461,13 @@ puts line end end def comment(str) - puts "% #{str}" + if ReVIEW.book.param["draft"] + puts macro('pdfcomment', escape(str)) + end end def label(id) puts macro('label', id) end @@ -453,13 +479,47 @@ def linebreak puts '\\\\' end def noindent - puts '\noindent' + print '\noindent' end + def inline_chapref(id) + if ReVIEW.book.param["chapterlink"] + "\\hyperref[chap:#{id}]{#{@chapter.env.chapter_index.display_string(id)}}" + else + @chapter.env.chapter_index.display_string(id) + end + rescue KeyError + error "unknown chapter: #{id}" + nofunc_text("[UnknownChapter:#{id}]") + end + + def inline_chap(id) + if ReVIEW.book.param["chapterlink"] + "\\hyperref[chap:#{id}]{#{@chapter.env.chapter_index.number(id)}}" + else + @chapter.env.chapter_index.number(id) + end + rescue KeyError + error "unknown chapter: #{id}" + nofunc_text("[UnknownChapter:#{id}]") + end + + def inline_title(id) + if ReVIEW.book.param["chapterlink"] + "\\hyperref[chap:#{id}]{#{@chapter.env.chapter_index.title(id)}}" + else + @chapter.env.chapter_index.title(id) + end + 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}") end @@ -473,14 +533,22 @@ chapter, id = extract_chapter_id(id) macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}") end def footnote(id, content) + if ReVIEW.book.param["footnotetext"] + puts macro("footnotetext[#{@chapter.footnote(id).number}]", + compile_inline(content.strip)) + end end def inline_fn(id) - macro('footnote', compile_inline(@chapter.footnote(id).content.strip)) + if ReVIEW.book.param["footnotetext"] + macro("footnotemark[#{@chapter.footnote(id).number}]", "") + else + macro('footnote', compile_inline(@chapter.footnote(id).content.strip)) + end end BOUTEN = "・" def inline_bou(str) @@ -552,16 +620,20 @@ def inline_ttb(str) macro('texttt', macro('textbf', escape(str))) end + def inline_bib(id) + "[#{@chapter.bibpaper(id).number}]" + end + def inline_hd_chap(chap, id) "「#{chap.headline_index.number(id)} #{chap.headline(id).caption}」" end def inline_raw(str) - escape(str) + super(str) end def inline_sub(str) macro('textsubscript', escape(str)) end @@ -589,10 +661,26 @@ def inline_uchar(str) # with otf package macro('UTF', escape(str)) end + def inline_comment(str) + if ReVIEW.book.param["draft"] + macro('pdfcomment', escape(str)) + end + end + + def bibpaper_header(id, caption) + puts "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}" + end + + def bibpaper_bibpaper(id, caption, lines) + lines.each do |line| + puts detab(line) + end + end + def index(str) str.sub!(/\(\)/, '') decl = '' if /@\z/ =~ str str.chop! @@ -616,13 +704,16 @@ macro('reviewkw', escape(word)) end end def compile_href(url, label) - label ||= url if /\A[a-z]+:\/\// =~ url - macro("href", url, escape(label)) + if label + macro("href", escape_url(url), escape(label)) + else + macro("url", escape_url(url)) + end else macro("ref", url) end end @@ -630,9 +721,13 @@ @tsize = str end def latextsize(str) @latex_tsize = str + end + + def image_ext + "svg" end end end