lib/review/latexbuilder.rb in review-1.2.0 vs lib/review/latexbuilder.rb in review-1.3.0
- old
+ new
@@ -11,10 +11,11 @@
#
require 'review/builder'
require 'review/latexutils'
require 'review/textutils'
+require 'review/sec_counter'
module ReVIEW
class LATEXBuilder < Builder
@@ -31,16 +32,16 @@
def extname
'.tex'
end
def builder_init_file
- #@index = indexes[:latex_index]
@blank_needed = false
@latex_tsize = nil
@tsize = nil
@table_caption = nil
@ol_num = nil
+ @sec_counter = SecCounter.new(5, @chapter)
end
private :builder_init_file
def blank
@blank_needed = true
@@ -72,22 +73,34 @@
4 => 'subsubsection',
5 => 'paragraph',
6 => 'subparagraph'
}
+ def headline_prefix(level)
+ @sec_counter.inc(level)
+ anchor = @sec_counter.anchor(level)
+ prefix = @sec_counter.prefix(level, @book.config["secnolevel"])
+ [prefix, anchor]
+ end
+ private :headline_prefix
+
+
def headline(level, label, caption)
+ _, anchor = headline_prefix(level)
prefix = ""
- if level > ReVIEW.book.param["secnolevel"] || (@chapter.number.to_s.empty? && level > 1)
+ if level > @book.config["secnolevel"] || (@chapter.number.to_s.empty? && level > 1)
prefix = "*"
end
blank unless @output.pos == 0
puts macro(HEADLINE[level]+prefix, compile_inline(caption))
- if prefix == "*" && level <= ReVIEW.book.param["toclevel"].to_i
+ if prefix == "*" && level <= @book.config["toclevel"].to_i
puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
end
if level == 1
puts macro('label', chapter_label)
+ else
+ puts macro('label', sec_label(anchor))
end
rescue
error "unknown level: #{level}"
end
@@ -100,12 +113,19 @@
end
def column_begin(level, label, caption)
blank
puts "\\begin{reviewcolumn}\n"
+ if label
+ puts "\\hypertarget{#{column_label(label)}}{}"
+ else
+ puts "\\hypertarget{#{column_label(caption)}}{}"
+ end
puts macro('reviewcolumnhead', nil, compile_inline(caption))
-
+ if level <= @book.config["toclevel"].to_i
+ puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
+ end
end
def column_end(level)
puts "\\end{reviewcolumn}\n"
blank
@@ -115,11 +135,11 @@
puts "\\begin{reviewminicolumn}\n"
unless caption.nil?
puts "\\reviewminicolumntitle{#{compile_inline(caption)}}\n"
end
- if ReVIEW.book.param["deprecated-blocklines"].nil?
+ if @book.config["deprecated-blocklines"].nil?
blocked_lines = split_paragraph(lines)
puts blocked_lines.join("\n\n")
else
lines.each do |line|
puts line
@@ -204,19 +224,19 @@
puts line
end
blank
end
- def parasep()
+ def parasep
puts '\\parasep'
end
def read(lines)
latex_block 'quotation', lines
end
- alias lead read
+ alias_method :lead, :read
def emlist(lines, caption = nil)
blank
if caption
puts macro('reviewemlistcaption', "#{compile_inline(caption)}")
@@ -335,30 +355,43 @@
def existence(id)
@chapter.image(id).bound? ? 'exist' : 'not exist'
end
private :existence
- def image_label(id)
- "image:#{@chapter.id}:#{id}"
+ def image_label(id, chapter=nil)
+ chapter ||= @chapter
+ "image:#{chapter.id}:#{id}"
end
private :image_label
- def chapter_label()
+ def chapter_label
"chap:#{@chapter.id}"
end
private :chapter_label
+ def sec_label(sec_anchor)
+ "sec:#{sec_anchor}"
+ end
+ private :sec_label
+
def table_label(id)
"table:#{@chapter.id}:#{id}"
end
private :table_label
def bib_label(id)
"bib:#{id}"
end
private :bib_label
+ def column_label(id)
+ filename = @chapter.id
+ num = @chapter.column(id).number
+ "column:#{filename}:#{num}"
+ end
+ private :column_label
+
def indepimage(id, caption=nil, metric=nil)
metrics = parse_metric("latex", metric)
puts '\begin{reviewimage}'
if metrics.present?
puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
@@ -370,11 +403,11 @@
%Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}])
end
puts '\end{reviewimage}'
end
- alias :numberlessimage indepimage
+ alias_method :numberlessimage, :indepimage
def table(lines, id = nil, caption = nil)
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
@@ -476,11 +509,11 @@
def center(lines)
latex_block 'center', lines
end
- alias centering center
+ alias_method :centering, :center
def flushright(lines)
latex_block 'flushright', lines
end
@@ -495,11 +528,11 @@
end
def latex_block(type, lines)
blank
puts macro('begin', type)
- if ReVIEW.book.param["deprecated-blocklines"].nil?
+ if @book.config["deprecated-blocklines"].nil?
blocked_lines = split_paragraph(lines)
puts blocked_lines.join("\n\n")
else
lines.each do |line|
puts line
@@ -518,11 +551,11 @@
end
def comment(lines, comment = nil)
lines ||= []
lines.unshift comment unless comment.blank?
- if ReVIEW.book.param["draft"]
+ if @book.config["draft"]
str = lines.join("")
puts macro('pdfcomment', escape(str))
end
end
@@ -546,33 +579,33 @@
print '\noindent'
end
def inline_chapref(id)
title = super
- if ReVIEW.book.param["chapterlink"]
+ if @book.config["chapterlink"]
"\\hyperref[chap:#{id}]{#{title}}"
else
title
end
rescue KeyError
error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
def inline_chap(id)
- if ReVIEW.book.param["chapterlink"]
+ if @book.config["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"]
+ if @book.config["chapterlink"]
"\\hyperref[chap:#{id}]{#{@chapter.env.chapter_index.title(id)}}"
else
@chapter.env.chapter_index.title(id)
end
rescue KeyError
@@ -592,22 +625,22 @@
macro('reviewtableref', "#{chapter.number}.#{chapter.table(id).number}", table_label(id))
end
def inline_img(id)
chapter, id = extract_chapter_id(id)
- macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}", image_label(id))
+ macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}", image_label(id, chapter))
end
def footnote(id, content)
- if ReVIEW.book.param["footnotetext"]
+ if @book.config["footnotetext"]
puts macro("footnotetext[#{@chapter.footnote(id).number}]",
compile_inline(content.strip))
end
end
def inline_fn(id)
- if ReVIEW.book.param["footnotetext"]
+ if @book.config["footnotetext"]
macro("footnotemark[#{@chapter.footnote(id).number}]", "")
else
macro('footnote', compile_inline(@chapter.footnote(id).content.strip))
end
end
@@ -637,11 +670,11 @@
macro('textit', escape(str))
end
# index
def inline_idx(str)
- text(str) + index(str)
+ escape(str) + index(str)
end
# hidden index??
def inline_hidx(str)
index(str)
@@ -690,13 +723,28 @@
def inline_bib(id)
macro('reviewbibref', "[#{@chapter.bibpaper(id).number}]", bib_label(id))
end
def inline_hd_chap(chap, id)
- "「#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}」"
+ n = chap.headline_index.number(id)
+ if chap.number and @book.config["secnolevel"] >= n.split('.').size
+ str = "「#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}」"
+ else
+ str = "「#{compile_inline(chap.headline(id).caption)}」"
+ end
+ if @book.config["chapterlink"]
+ anchor = n.gsub(/\./, "-")
+ macro('reviewsecref', str, sec_label(anchor))
+ else
+ str
+ end
end
+ def inline_column(id)
+ macro('reviewcolumnref', "#{@chapter.column(id).caption}", column_label(id))
+ end
+
def inline_raw(str)
super(str)
end
def inline_sub(str)
@@ -731,11 +779,11 @@
# with otf package
macro('UTF', escape(str))
end
def inline_comment(str)
- if ReVIEW.book.param["draft"]
+ if @book.config["draft"]
macro('pdfcomment', escape(str))
else
""
end
end
@@ -795,10 +843,10 @@
def latextsize(str)
@latex_tsize = str
end
def image_ext
- "svg"
+ "pdf"
end
def olnum(num)
@ol_num = num.to_i
end