lib/review/latexbuilder.rb in review-2.0.0.beta1 vs lib/review/latexbuilder.rb in review-2.0.0
- old
+ new
@@ -1,10 +1,10 @@
# encoding: utf-8
#
# Copyright (c) 2002-2007 Minero Aoki
# 2008-2009 Minero Aoki, Kenshi Muto
-# 2010 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi
+# 2010-2016 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".
@@ -23,11 +23,10 @@
[:dtp, :hd_chap].each {|e|
Compiler.definline(e)
}
- Compiler.defblock(:memo, 0..1)
Compiler.defsingle(:latextsize, 1)
def extname
'.tex'
end
@@ -37,185 +36,207 @@
@latex_tsize = nil
@tsize = nil
@table_caption = nil
@ol_num = nil
@sec_counter = SecCounter.new(5, @chapter)
+ initialize_metachars(@book.config["texcommand"])
end
private :builder_init_file
def blank
@blank_needed = true
end
private :blank
- def blank_reset
- @blank_needed = false
+ def print(*s)
+ if @blank_needed
+ @output.puts
+ @blank_needed = false
+ end
+ super
end
- private :blank_reset
+ private :print
+ def puts(*s)
+ if @blank_needed
+ @output.puts
+ @blank_needed = false
+ end
+ super
+ end
+ private :puts
+
HEADLINE = {
1 => 'chapter',
2 => 'section',
3 => 'subsection',
4 => 'subsubsection',
5 => 'paragraph',
6 => 'subparagraph'
}
def headline(level, label, caption)
- buf = ""
_, anchor = headline_prefix(level)
headline_name = HEADLINE[level]
if @chapter.kind_of? ReVIEW::Book::Part
headline_name = "part"
end
prefix = ""
if level > @book.config["secnolevel"] || (@chapter.number.to_s.empty? && level > 1)
prefix = "*"
end
- buf << macro(headline_name+prefix, caption) << "\n"
+ blank unless @output.pos == 0
+ puts macro(headline_name+prefix, compile_inline(caption))
if prefix == "*" && level <= @book.config["toclevel"].to_i
- buf << "\\addcontentsline{toc}{#{headline_name}}{#{caption}}\n"
+ puts "\\addcontentsline{toc}{#{headline_name}}{#{compile_inline(caption)}}"
end
if level == 1
- buf << macro('label', chapter_label) << "\n"
+ puts macro('label', chapter_label)
else
- buf << macro('label', sec_label(anchor)) << "\n"
+ puts macro('label', sec_label(anchor))
end
- buf
rescue
error "unknown level: #{level}"
end
def nonum_begin(level, label, caption)
- "\n" + macro(HEADLINE[level]+"*", caption) + "\n"
+ blank unless @output.pos == 0
+ puts macro(HEADLINE[level]+"*", compile_inline(caption))
+ puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
end
def nonum_end(level)
end
+ def notoc_begin(level, label, caption)
+ blank unless @output.pos == 0
+ puts macro(HEADLINE[level]+"*", compile_inline(caption))
+ end
+
+ def notoc_end(level)
+ end
+
+ def nodisp_begin(level, label, caption)
+ blank unless @output.pos == 0
+ puts macro('clearpage') if @output.pos == 0
+ puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
+ # FIXME: headings
+ end
+
+ def nodisp_end(level)
+ end
+
def column_begin(level, label, caption)
- buf = ""
blank
- if @blank_needed
- buf << "\n"
- blank_reset
- end
- buf << "\\begin{reviewcolumn}\n"
+ puts "\\begin{reviewcolumn}\n"
if label
- buf << "\\hypertarget{#{column_label(label)}}{}\n"
+ puts "\\hypertarget{#{column_label(label)}}{}"
else
- buf << "\\hypertarget{#{column_label(caption)}}{}\n"
+ puts "\\hypertarget{#{column_label(caption)}}{}"
end
- buf << macro('reviewcolumnhead', nil, caption) << "\n"
+ puts macro('reviewcolumnhead', nil, compile_inline(caption))
if level <= @book.config["toclevel"].to_i
- buf << "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{caption}}" << "\n"
+ puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
end
- buf
end
def column_end(level)
- buf = ""
- buf << "\\end{reviewcolumn}\n"
+ puts "\\end{reviewcolumn}\n"
blank
- buf
end
def captionblock(type, lines, caption)
- buf = ""
- buf << "\\begin{reviewminicolumn}\n"
+ puts "\\begin{reviewminicolumn}\n"
unless caption.nil?
- buf << "\\reviewminicolumntitle{#{caption}}"
+ puts "\\reviewminicolumntitle{#{compile_inline(caption)}}\n"
end
- if @book.config["deprecated-blocklines"].nil?
- buf << lines.join("")
- else
- error "deprecated-blocklines is obsoleted."
- end
+ blocked_lines = split_paragraph(lines)
+ puts blocked_lines.join("\n\n")
- buf << "\\end{reviewminicolumn}\n"
- buf
+ puts "\\end{reviewminicolumn}\n"
end
def box(lines, caption = nil)
- buf = "\n"
+ blank
if caption
- buf << macro('reviewboxcaption', "#{caption}") << "\n"
+ puts macro('reviewboxcaption', "#{compile_inline(caption)}")
end
- buf << '\begin{reviewbox}' << "\n"
+ puts '\begin{reviewbox}'
lines.each do |line|
- buf << detab(line) << "\n"
- end<
- buf << '\end{reviewbox}' << "\n"
+ puts detab(line)
+ end
+ puts '\end{reviewbox}'
+ blank
end
def ul_begin
- buf = "\n"
- buf << '\begin{itemize}' << "\n"
- buf
+ blank
+ puts '\begin{itemize}'
end
def ul_item(lines)
str = lines.join
str.sub!(/\A(\[)/){'\lbrack{}'}
- '\item ' + str + "\n"
+ puts '\item ' + str
end
def ul_end
- '\end{itemize}' + "\n"
+ puts '\end{itemize}'
+ blank
end
def ol_begin
- buf = "\n"
- buf << '\begin{enumerate}' << "\n"
+ blank
+ puts '\begin{enumerate}'
if @ol_num
- buf << "\\setcounter{enumi}{#{@ol_num - 1}}\n"
+ puts "\\setcounter{enumi}{#{@ol_num - 1}}"
@ol_num = nil
end
- buf
end
def ol_item(lines, num)
str = lines.join
str.sub!(/\A(\[)/){'\lbrack{}'}
- '\item ' + str + "\n"
+ puts '\item ' + str
end
def ol_end
- '\end{enumerate}' + "\n"
+ puts '\end{enumerate}'
+ blank
end
def dl_begin
- "\n" + '\begin{description}' + "\n"
+ blank
+ puts '\begin{description}'
end
def dt(str)
str.sub!(/\[/){'\lbrack{}'}
str.sub!(/\]/){'\rbrack{}'}
- '\item[' + str + '] \mbox{} \\\\' + "\n"
+ puts '\item[' + str + '] \mbox{} \\\\'
end
def dd(lines)
- lines.join + "\n"
+ puts lines.join
end
def dl_end
- '\end{description}' + "\n"
+ puts '\end{description}'
+ blank
end
def paragraph(lines)
- buf = "\n"
+ blank
lines.each do |line|
- buf << line
+ puts line
end
- buf << "\n"
- buf
+ blank
end
def parasep
- '\\parasep' + "\n"
+ puts '\\parasep'
end
def read(lines)
latex_block 'quotation', lines
end
@@ -226,177 +247,160 @@
@book.config["highlight"] && @book.config["highlight"]["latex"] == "listings"
end
private :highlight_listings?
def emlist(lines, caption = nil, lang = nil)
- buf = "\n"
+ blank
if highlight_listings?
- buf << common_code_block_lst(lines, 'reviewemlistlst', 'title', caption, lang)
+ common_code_block_lst(nil, lines, 'reviewemlistlst', 'title', caption, lang)
else
- buf << 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
- buf
end
def emlistnum(lines, caption = nil, lang = nil)
- buf = "\n"
+ blank
if highlight_listings?
- buf << common_code_block_lst(lines, 'reviewemlistnumlst', 'title', caption, lang)
+ common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang)
else
- buf << 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
- buf
end
## override Builder#list
- def list(lines, id, caption = nil, lang = nil)
- buf = ""
+ def list(lines, id, caption, lang = nil)
if highlight_listings?
- buf << common_code_block_lst(lines, 'reviewlistlst', 'caption', caption, lang)
+ common_code_block_lst(id, lines, 'reviewlistlst', 'caption', caption, lang)
else
- begin
- buf << macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{caption}") + "\n"
- rescue KeyError
- error "no such list: #{id}"
- end
- buf << common_code_block(lines, 'reviewlist', nil, lang) do |line, idx|
+ common_code_block(id, lines, 'reviewlist', caption, lang) do |line, idx|
detab(line) + "\n"
end
end
- buf
end
-
## override Builder#listnum
- def listnum(lines, id, caption = nil, lang = nil)
- buf = ""
+ def listnum(lines, id, caption, lang = nil)
if highlight_listings?
- buf << common_code_block_lst(lines, 'reviewlistnumlst', 'caption', caption, lang)
+ common_code_block_lst(id, lines, 'reviewlistnumlst', 'caption', caption, lang)
else
- begin
- buf << macro('reviewlistcaption', "#{I18n.t("list")}#{I18n.t("format_number_header", [@chapter.number, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{caption}") + "\n"
- rescue KeyError
- error "no such list: #{id}"
- end
- buf << 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
- buf
end
def cmd(lines, caption = nil, lang = nil)
- buf = ""
if highlight_listings?
- buf << common_code_block_lst(lines, 'reviewcmdlst', 'title', caption, lang)
+ common_code_block_lst(nil, lines, 'reviewcmdlst', 'title', caption, lang)
else
- buf << "\n"
- buf << common_code_block(lines, 'reviewcmd', caption, lang) do |line, idx|
+ blank
+ common_code_block(nil, lines, 'reviewcmd', caption, lang) do |line, idx|
detab(line) + "\n"
end
end
- buf
end
- def common_code_block(lines, command, caption, lang)
- buf = ""
+ def common_code_block(id, lines, command, caption, lang)
if caption
- buf << macro(command + 'caption', "#{caption}") + "\n"
+ 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
- buf << macro('begin' ,command) + "\n"
- buf << body
- buf << macro('end' ,command) + "\n"
- buf
+ puts macro('begin' ,command)
+ print body
+ puts macro('end' ,command)
+ blank
end
- def common_code_block_lst(lines, command, title, caption, lang)
- buf = ""
- caption_str = (caption || "")
+ 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
- buf << "\\vspace{-1.5em}"
+ print "\\vspace{-1.5em}"
end
if @book.config["highlight"] && @book.config["highlight"]["lang"]
lexer = @book.config["highlight"]["lang"] # default setting
else
lexer = ""
end
lexer = lang if lang.present?
body = lines.inject(''){|i, j| i + detab(unescape_latex(j)) + "\n"}
- buf << "\\begin{"+command+"}["+title+"={"+caption_str+"},language={"+ lexer+"}]" + "\n"
- buf << body
- buf << "\\end{"+ command + "}" + "\n"
- buf
+ puts "\\begin{"+command+"}["+title+"={"+caption_str+"},language={"+ lexer+"}]"
+ print body
+ puts "\\end{"+ command + "}"
+ blank
end
- def source(lines, caption = nil)
- buf = "\n"
- buf << '\begin{reviewlist}' << "\n"
- buf << source_header(caption)
- buf << source_body(lines)
- buf << '\end{reviewlist}' << "\n"
- buf << "\n"
- buf
- end
-
- def source_header(caption)
- macro('reviewlistcaption', caption) + "\n"
- end
-
- def source_body(lines)
- buf = ""
- lines.each do |line|
- buf << detab(line) << "\n"
+ def source(lines, caption, lang = nil)
+ if highlight_listings?
+ 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)
+ end
+ puts '\end{reviewlist}'
+ puts ""
end
- buf
end
def image_header(id, caption)
end
+ def handle_metric(str)
+ if @book.config["image_scale2width"] && str =~ /\Ascale=([\d.]+)\Z/
+ return "width=#{$1}\\maxwidth"
+ end
+ str
+ end
+
def result_metric(array)
"#{array.join(',')}"
end
def image_image(id, caption, metric)
- buf = ""
metrics = parse_metric("latex", metric)
# image is always bound here
- buf << '\begin{reviewimage}' << "\n"
+ puts '\begin{reviewimage}'
if metrics.present?
- buf << "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}\n"
+ puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
else
- buf << "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}\n"
+ puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
end
if caption.present?
- buf << macro('caption', caption) << "\n"
+ puts macro('caption', compile_inline(caption))
end
- buf << macro('label', image_label(id)) << "\n"
- buf << '\end{reviewimage}' << "\n"
- buf
+ puts macro('label', image_label(id))
+ puts '\end{reviewimage}'
end
def image_dummy(id, caption, lines)
- buf << '\begin{reviewdummyimage}' << "\n"
+ puts '\begin{reviewdummyimage}'
path = @chapter.image(id).path
- buf << "--[[path = #{path} (#{existence(id)})]]--\n"
+ puts "--[[path = #{path} (#{existence(id)})]]--"
lines.each do |line|
- buf << detab(line.rstrip) << "\n"
+ puts detab(line.rstrip)
end
- buf << macro('label', image_label(id)) << "\n"
- buf << caption << "\n"
- buf << '\end{reviewdummyimage}' << "\n"
- buf
+ puts macro('label', image_label(id))
+ puts compile_inline(caption)
+ puts '\end{reviewdummyimage}'
end
def existence(id)
@chapter.image(id).bound? ? 'exist' : 'not exist'
end
@@ -435,30 +439,27 @@
"column:#{filename}:#{num}"
end
private :column_label
def indepimage(id, caption=nil, metric=nil)
- buf = ""
metrics = parse_metric("latex", metric)
- buf << '\begin{reviewimage}' << "\n"
+ puts '\begin{reviewimage}'
if metrics.present?
- buf << "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}\n"
+ puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
else
- buf << "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}\n"
+ puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
end
if caption.present?
- buf << macro('reviewindepimagecaption',
- %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{caption}]) << "\n"
+ puts macro('reviewindepimagecaption',
+ %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}])
end
- buf << '\end{reviewimage}' << "\n"
- buf
+ puts '\end{reviewimage}'
end
alias_method :numberlessimage, :indepimage
def table(lines, id = nil, caption = nil)
- buf = ""
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
if /\A[\=\{\-\}]{12}/ =~ line
# just ignore
@@ -469,100 +470,127 @@
rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
end
rows = adjust_n_cols(rows)
begin
- buf << table_header(id, caption) unless caption.nil?
+ table_header id, caption unless caption.nil?
rescue KeyError
error "no such table: #{id}"
end
- return buf if rows.empty?
- buf << table_begin(rows.first.size)
+ return if rows.empty?
+ table_begin rows.first.size
if sepidx
sepidx.times do
- buf << tr(rows.shift.map {|s| th(s) })
+ tr rows.shift.map {|s| th(s) }
end
rows.each do |cols|
- buf << tr(cols.map {|s| td(s) })
+ tr cols.map {|s| td(s) }
end
else
rows.each do |cols|
h, *cs = *cols
- buf << tr([th(h)] + cs.map {|s| td(s) })
+ tr [th(h)] + cs.map {|s| td(s) }
end
end
- buf << table_end
- buf
+ table_end
end
def table_header(id, caption)
- buf = ""
if caption.present?
@table_caption = true
- buf << '\begin{table}[h]' << "\n"
- buf << macro('reviewtablecaption', caption) << "\n"
+ puts '\begin{table}[h]'
+ puts macro('reviewtablecaption', compile_inline(caption))
end
- buf << macro('label', table_label(id)) << "\n"
- buf
+ puts macro('label', table_label(id))
end
def table_begin(ncols)
- buf = ""
if @latex_tsize
- buf << macro('begin', 'reviewtable', @latex_tsize) << "\n"
+ puts macro('begin', 'reviewtable', @latex_tsize)
elsif @tsize
cellwidth = @tsize.split(/\s*,\s*/)
- buf << macro('begin', 'reviewtable', '|'+(cellwidth.collect{|i| "p{#{i}mm}"}.join('|'))+'|') << "\n"
+ puts macro('begin', 'reviewtable', '|'+cellwidth.collect{|i| "p{#{i}mm}"}.join('|')+'|')
else
- buf << macro('begin', 'reviewtable', (['|'] * (ncols + 1)).join('l')) << "\n"
+ puts macro('begin', 'reviewtable', (['|'] * (ncols + 1)).join('l'))
end
- buf << '\hline' << "\n"
+ puts '\hline'
@tsize = nil
@latex_tsize = nil
- buf
end
def table_separator
#puts '\hline'
end
def th(s)
## use shortstack for @<br>
- if /\\\\/i =~ s
+ if /\\\\/i =~ s
macro('reviewth', macro('shortstack[l]', s))
else
macro('reviewth', s)
end
end
def td(s)
## use shortstack for @<br>
- if /\\\\/ =~ s
+ if /\\\\/ =~ s
macro('shortstack[l]', s)
else
s
end
end
def tr(rows)
- buf = ""
- buf << rows.join(' & ') << "\n"
- buf << ' \\\\ \hline' << "\n"
- buf
+ print rows.join(' & ')
+ puts ' \\\\ \hline'
end
def table_end
- buf = ""
- buf << macro('end', 'reviewtable') << "\n"
+ puts macro('end', 'reviewtable')
if @table_caption
- buf << '\end{table}' << "\n"
+ puts '\end{table}'
end
@table_caption = nil
- buf << "\n"
- buf
+ blank
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
+ end
+
+ begin
+ if caption.present?
+ @table_caption = true
+ puts '\begin{table}[h]'
+ puts macro('reviewimgtablecaption', compile_inline(caption))
+ end
+ puts macro('label', table_label(id))
+ rescue ReVIEW::KeyError
+ error "no such table: #{id}"
+ end
+ imgtable_image(id, caption, metric)
+
+ puts '\end{table}' if @table_caption
+ @table_caption = nil
+ blank
+ end
+
+ def imgtable_image(id, caption, metric)
+ metrics = parse_metric("latex", metric)
+ # image is always bound here
+ puts '\begin{reviewimage}'
+ if metrics.present?
+ puts "\\includegraphics[#{metrics}]{#{@chapter.image(id).path}}"
+ else
+ puts "\\includegraphics[width=\\maxwidth]{#{@chapter.image(id).path}}"
+ end
+ puts '\end{reviewimage}'
+ end
+
def quote(lines)
latex_block 'quote', lines
end
def center(lines)
@@ -574,76 +602,63 @@
def flushright(lines)
latex_block 'flushright', lines
end
def texequation(lines)
- buf = "\n"
- buf << macro('begin','equation*') << "\n"
+ blank
+ puts macro('begin','equation*')
lines.each do |line|
- buf << unescape_latex(line) << "\n"
+ puts unescape_latex(line)
end
- buf << macro('end', 'equation*') << "\n"
- buf << "\n"
- buf
+ puts macro('end', 'equation*')
+ blank
end
def latex_block(type, lines)
- buf = "\n"
- buf << macro('begin', type)
- if @book.config["deprecated-blocklines"].nil?
- buf << lines.join("")
- else
- error "deprecated-blocklines is obsoleted."
- end
- buf << macro('end', type) << "\n"
- buf
+ blank
+ puts macro('begin', type)
+ blocked_lines = split_paragraph(lines)
+ puts blocked_lines.join("\n\n")
+ puts macro('end', type)
+ blank
end
private :latex_block
def direct(lines, fmt)
- buf = ""
- return buf unless fmt == 'latex'
+ return unless fmt == 'latex'
lines.each do |line|
- buf << line << "\n"
+ puts line
end
- buf
end
def comment(lines, comment = nil)
- buf = ""
lines ||= []
lines.unshift comment unless comment.blank?
if @book.config["draft"]
str = lines.join("")
- buf << macro('pdfcomment', str) << "\n"
+ puts macro('pdfcomment', escape(str))
end
- buf
end
def hr
- '\hrule' + "\n"
+ puts '\hrule'
end
def label(id)
- macro('label', id) + "\n"
+ puts macro('label', id)
end
- def node_label(node)
- id = node.args[0].to_raw
- macro('label', id) + "\n"
- end
-
def pagebreak
- '\pagebreak' + "\n"
+ puts '\pagebreak'
end
def linebreak
- '\\\\' + "\n"
+ puts '\\\\'
end
def noindent
- '\noindent'
+ print '\noindent'
end
def inline_chapref(id)
title = super
if @book.config["chapterlink"]
@@ -696,75 +711,61 @@
macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}", image_label(id, chapter))
end
def footnote(id, content)
if @book.config["footnotetext"]
- macro("footnotetext[#{@chapter.footnote(id).number}]",
- content.strip) + "\n"
+ puts macro("footnotetext[#{@chapter.footnote(id).number}]",
+ compile_inline(content.strip))
end
end
def inline_fn(id)
if @book.config["footnotetext"]
macro("footnotemark[#{@chapter.footnote(id).number}]", "")
else
- macro('footnote', escape(@chapter.footnote(id).content.strip))
+ macro('footnote', compile_inline(@chapter.footnote(id).content.strip))
end
end
BOUTEN = "・"
def inline_bou(str)
str.split(//).map {|c| macro('ruby', escape(c), macro('textgt', BOUTEN)) }.join('\allowbreak')
end
def compile_ruby(base, ruby)
- macro('ruby', base, ruby)
+ macro('ruby', escape(base), escape(ruby))
end
# math
-# def inline_m(str)
-# " $#{str}$ "
-# end
-
- def node_inline_m(node)
- " $#{node[0].to_raw}$ "
+ def inline_m(str)
+ " $#{str}$ "
end
# hidden index
def inline_hi(str)
index(str)
end
# index -> italic
def inline_i(str)
- macro('textit', str)
+ macro('textit', escape(str))
end
# index
def inline_idx(str)
escape(str) + index(str)
end
- def node_inline_idx(nodelist)
- content = nodelist[0].to_raw
- escape(content) + index(content)
- end
-
# hidden index??
def inline_hidx(str)
index(str)
end
- def node_inline_hidx(nodelist)
- content = nodelist[0].to_raw
- index(content)
- end
-
# bold
def inline_b(str)
- macro('textbf', str)
+ macro('textbf', escape(str))
end
# line break
def inline_br(str)
"\\\\\n"
@@ -775,138 +776,144 @@
""
end
## @<code> is same as @<tt>
def inline_code(str)
- macro('texttt', str)
+ macro('texttt', escape(str))
end
def nofunc_text(str)
escape(str)
end
def inline_tt(str)
- macro('texttt', str)
+ macro('texttt', escape(str))
end
def inline_del(str)
- macro('reviewstrike', str)
+ macro('reviewstrike', escape(str))
end
def inline_tti(str)
- macro('texttt', macro('textit', str))
+ macro('texttt', macro('textit', escape(str)))
end
def inline_ttb(str)
- macro('texttt', macro('textbf', str))
+ macro('texttt', macro('textbf', escape(str)))
end
def inline_bib(id)
macro('reviewbibref', "[#{@chapter.bibpaper(id).number}]", bib_label(id))
end
def inline_hd_chap(chap, id)
n = chap.headline_index.number(id)
if chap.number and @book.config["secnolevel"] >= n.split('.').size
- str = I18n.t("chapter_quote", "#{chap.headline_index.number(id)} #{chap.headline(id).caption}")
+ str = I18n.t("chapter_quote", "#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}")
else
- str = I18n.t("chapter_quote", chap.headline(id).caption)
+ str = I18n.t("chapter_quote", compile_inline(chap.headline(id).caption))
end
if @book.config["chapterlink"]
anchor = n.gsub(/\./, "-")
- macro('reviewsecref', escape(str), sec_label(anchor))
+ macro('reviewsecref', str, sec_label(anchor))
else
- escape(str)
+ str
end
end
- def inline_column(id)
- macro('reviewcolumnref', "#{@chapter.column(id).caption}", column_label(id))
+ def inline_column_chap(chapter, id)
+ macro('reviewcolumnref', "#{chapter.column(id).caption}", column_label(id))
end
def inline_raw(str)
super(str)
end
def inline_sub(str)
- macro('textsubscript', str)
+ macro('textsubscript', escape(str))
end
def inline_sup(str)
- macro('textsuperscript', str)
+ macro('textsuperscript', escape(str))
end
def inline_em(str)
- macro('reviewem', str)
+ macro('reviewem', escape(str))
end
def inline_strong(str)
- macro('reviewstrong', str)
+ macro('reviewstrong', escape(str))
end
def inline_u(str)
- macro('Underline', str)
+ macro('reviewunderline', escape(str))
end
def inline_ami(str)
- macro('reviewami', str)
+ macro('reviewami', escape(str))
end
def inline_icon(id)
macro('includegraphics', @chapter.image(id).path)
end
def inline_uchar(str)
# with otf package
- macro('UTF', str)
+ macro('UTF', escape(str))
end
def inline_comment(str)
if @book.config["draft"]
macro('pdfcomment', escape(str))
else
""
end
end
- def bibpaper(lines, id, caption)
- buf = ""
- buf << bibpaper_header(id, caption)
- if lines.empty?
- buf << "\n"
- else
- buf << "\n"
- buf << bibpaper_bibpaper(id, caption, lines)
- end
- buf << "\n"
- buf
+ def inline_tcy(str)
+ macro('rensuji', escape(str))
end
def bibpaper_header(id, caption)
- "[#{@chapter.bibpaper(id).number}] #{caption}\n" +
- macro('label', bib_label(id))
+ puts "[#{@chapter.bibpaper(id).number}] #{compile_inline(caption)}"
+ puts macro('label', bib_label(id))
end
def bibpaper_bibpaper(id, caption, lines)
- lines.join("")
+ print split_paragraph(lines).join("")
+ puts ""
end
def index(str)
- "\\index{" + str + "}"
+ str.sub!(/\(\)/, '')
+ decl = ''
+ if /@\z/ =~ str
+ str.chop!
+ decl = '|IndexDecl'
+ end
+ unless /[^ -~]/ =~ str
+ if /\^/ =~ str
+ macro('index', escape_index(str.gsub(/\^/, '')) + '@' + escape_index(text(str)) + decl)
+ else
+ '\index{' + escape_index(text(str)) + decl + '}'
+ end
+ else
+ '\index{' + escape_index(@index_db[str]) + '@' + escape_index(text(str)) + '}'
+ end
end
def compile_kw(word, alt)
if alt
- macro('reviewkw', word) + "(#{alt.strip})"
+ macro('reviewkw', escape(word)) + "(#{escape(alt.strip)})"
else
- macro('reviewkw', word)
+ macro('reviewkw', escape(word))
end
end
def compile_href(url, label)
if /\A[a-z]+:/ =~ url
if label
- macro("href", escape_url(url), label)
+ macro("href", escape_url(url), escape(label))
else
macro("url", escape_url(url))
end
else
macro("ref", url)