lib/review/latexbuilder.rb in review-5.1.1 vs lib/review/latexbuilder.rb in review-5.2.0
- old
+ new
@@ -26,18 +26,18 @@
def extname
'.tex'
end
def builder_init_file
+ super
@chapter.book.image_types = %w[.ai .eps .pdf .tif .tiff .png .bmp .jpg .jpeg .gif]
@blank_needed = false
@latex_tsize = nil
@tsize = nil
@cellwidth = nil
@ol_num = nil
@first_line_num = nil
- @sec_counter = SecCounter.new(5, @chapter)
@foottext = {}
setup_index
initialize_metachars(@book.config['texcommand'])
end
private :builder_init_file
@@ -59,11 +59,11 @@
require 'mecab'
end
require 'nkf'
@index_mecab = MeCab::Tagger.new(@book.config['pdfmaker']['makeindex_mecab_opts'])
rescue LoadError
- warn 'not found MeCab'
+ warn 'not found MeCab', location: location
end
end
def load_idxdb(file)
table = {}
@@ -154,11 +154,11 @@
else
puts macro('label', sec_label(anchor))
puts macro('label', label) if label
end
rescue
- error "unknown level: #{level}"
+ app_error "unknown level: #{level}"
end
def nonum_begin(level, _label, caption)
blank unless @output.pos == 0
@doc_status[:caption] = true
@@ -478,11 +478,11 @@
captionstr = macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
else
captionstr = macro('reviewlistcaption', "#{I18n.t('list')}#{I18n.t('format_number_header', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}")
end
rescue KeyError
- error "no such list: #{id}"
+ app_error "no such list: #{id}"
end
end
end
@doc_status[:caption] = nil
@@ -611,23 +611,23 @@
puts '\end{reviewimage}'
end
def image_dummy(id, caption, lines)
- warn "image not bound: #{id}"
+ warn "image not bound: #{id}", location: location
puts '\begin{reviewdummyimage}'
- # path = @chapter.image(id).path
- puts "--[[path = #{id} (#{existence(id)})]]--"
+ puts escape("--[[path = #{id} (#{existence(id)})]]--")
lines.each do |line|
+ puts "\n"
puts detab(line.rstrip)
end
puts macro('label', image_label(id))
@doc_status[:caption] = true
if @book.config.check_version('2', exception: false)
puts macro('caption', compile_inline(caption)) if caption.present?
- else
- puts macro('reviewimagecaption', compile_inline(caption)) if caption.present?
+ elsif caption.present?
+ puts macro('reviewimagecaption', compile_inline(caption))
end
@doc_status[:caption] = nil
puts '\end{reviewdummyimage}'
end
@@ -698,14 +698,15 @@
puts "\\#{command}[#{metrics}]{#{@chapter.image(id).path}}"
else
puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}"
end
else
- warn "image not bound: #{id}"
+ warn "image not bound: #{id}", location: location
puts '\begin{reviewdummyimage}'
- puts "--[[path = #{escape(id)} (#{existence(id)})]]--"
+ puts escape("--[[path = #{escape(id)} (#{existence(id)})]]--")
lines.each do |line|
+ puts "\n"
puts detab(line.rstrip)
end
end
if !caption_top?('image') && captionstr
@@ -734,11 +735,11 @@
begin
if caption_top?('table') && caption.present?
table_header(id, caption)
end
rescue KeyError
- error "no such table: #{id}"
+ app_error "no such table: #{id}"
end
table_begin(rows.first.size)
table_rows(sepidx, rows)
table_end
if caption.present?
@@ -819,11 +820,11 @@
def separate_tsize(size)
ret = []
s = ''
brace = nil
- size.split('').each do |ch|
+ size.chars.each do |ch|
case ch
when '|'
next
when '{'
brace = true
@@ -832,19 +833,15 @@
brace = nil
s << ch
ret << s
s = ''
else
- if brace
+ if brace || s.empty?
s << ch
else
- if s.empty?
- s << ch
- else
- ret << s
- s = ch
- end
+ ret << s
+ s = ch
end
end
end
unless s.empty?
@@ -900,11 +897,11 @@
table(lines, nil, caption)
end
def imgtable(lines, id, caption = nil, metric = nil)
unless @chapter.image_bound?(id)
- warn "image not bound: #{id}"
+ warn "image not bound: #{id}", location: location
image_dummy(id, caption, lines)
return
end
captionstr = nil
@@ -918,11 +915,11 @@
puts captionstr
end
end
puts macro('label', table_label(id))
rescue ReVIEW::KeyError
- error "no such table: #{id}"
+ app_error "no such table: #{id}"
end
imgtable_image(id, caption, metric)
if caption.present?
unless caption_top?('table')
@@ -1054,22 +1051,22 @@
"\\reviewchapref{#{title}}{chap:#{id}}"
else
title
end
rescue KeyError
- error "unknown chapter: #{id}"
+ app_error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
def inline_chap(id)
if @book.config['chapterlink']
"\\reviewchapref{#{@book.chapter_index.number(id)}}{chap:#{id}}"
else
@book.chapter_index.number(id)
end
rescue KeyError
- error "unknown chapter: #{id}"
+ app_error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
def inline_title(id)
title = super
@@ -1077,11 +1074,11 @@
"\\reviewchapref{#{title}}{chap:#{id}}"
else
title
end
rescue KeyError
- error "unknown chapter: #{id}"
+ app_error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
def inline_pageref(id)
"\\pageref{#{id}}"
@@ -1094,50 +1091,50 @@
macro('reviewlistref', I18n.t('format_number_without_chapter', [chapter.list(id).number]))
else
macro('reviewlistref', I18n.t('format_number', [get_chap(chapter), chapter.list(id).number]))
end
rescue KeyError
- error "unknown list: #{id}"
+ app_error "unknown list: #{id}"
end
def inline_table(id)
chapter, id = extract_chapter_id(id)
if get_chap(chapter).nil?
macro('reviewtableref', I18n.t('format_number_without_chapter', [chapter.table(id).number]), table_label(id, chapter))
else
macro('reviewtableref', I18n.t('format_number', [get_chap(chapter), chapter.table(id).number]), table_label(id, chapter))
end
rescue KeyError
- error "unknown table: #{id}"
+ app_error "unknown table: #{id}"
end
def inline_img(id)
chapter, id = extract_chapter_id(id)
if get_chap(chapter).nil?
macro('reviewimageref', I18n.t('format_number_without_chapter', [chapter.image(id).number]), image_label(id, chapter))
else
macro('reviewimageref', I18n.t('format_number', [get_chap(chapter), chapter.image(id).number]), image_label(id, chapter))
end
rescue KeyError
- error "unknown image: #{id}"
+ app_error "unknown image: #{id}"
end
def inline_eq(id)
chapter, id = extract_chapter_id(id)
if get_chap(chapter).nil?
macro('reviewequationref', I18n.t('format_number_without_chapter', [chapter.equation(id).number]))
else
macro('reviewequationref', I18n.t('format_number', [get_chap(chapter), chapter.equation(id).number]))
end
rescue KeyError
- error "unknown equation: #{id}"
+ app_error "unknown equation: #{id}"
end
def footnote(id, content)
if @book.config['footnotetext'] || @foottext[id]
if @doc_status[:column]
- warn "//footnote[#{id}] is in the column block. It is recommended to move out of the column block."
+ warn "//footnote[#{id}] is in the column block. It is recommended to move out of the column block.", location: location
end
puts macro("footnotetext[#{@chapter.footnote(id).number}]", compile_inline(content.strip))
end
end
@@ -1149,11 +1146,11 @@
macro('protect\\footnotemark', '')
else
macro('footnote', compile_inline(@chapter.footnote(id).content.strip))
end
rescue KeyError
- error "unknown footnote: #{id}"
+ app_error "unknown footnote: #{id}"
end
BOUTEN = '・'.freeze
def inline_bou(str)
@@ -1283,11 +1280,11 @@
def inline_column_chap(chapter, id)
macro('reviewcolumnref',
I18n.t('column', compile_inline(chapter.column(id).caption)),
column_label(id, chapter))
rescue KeyError
- error "unknown column: #{id}"
+ app_error "unknown column: #{id}"
end
def inline_raw(str) # rubocop:disable Lint/UselessMethodDefinition
super(str)
end
@@ -1322,11 +1319,11 @@
if @book.config.check_version('2', exception: false)
command = 'includegraphics'
end
macro(command, @chapter.image(id).path)
else
- warn "image not bound: #{id}"
+ warn "image not bound: #{id}", location: location
"\\verb|--[[path = #{id} (#{existence(id)})]]--|"
end
end
def inline_uchar(str)
@@ -1375,21 +1372,19 @@
sa = str.split('<<>>')
sa.map! do |item|
if @index_db[item]
escape_mendex_key(escape_index(@index_db[item])) + '@' + escape_mendex_display(escape_index(escape(item)))
- else
- if item =~ /\A[[:ascii:]]+\Z/ || @index_mecab.nil?
- esc_item = escape_mendex_display(escape_index(escape(item)))
- if esc_item == item
- esc_item
- else
- "#{escape_mendex_key(escape_index(item))}@#{esc_item}"
- end
+ elsif item =~ /\A[[:ascii:]]+\Z/ || @index_mecab.nil?
+ esc_item = escape_mendex_display(escape_index(escape(item)))
+ if esc_item == item
+ esc_item
else
- yomi = NKF.nkf('-w --hiragana', @index_mecab.parse(item).force_encoding('UTF-8').chomp)
- escape_mendex_key(escape_index(yomi)) + '@' + escape_mendex_display(escape_index(escape(item)))
+ "#{escape_mendex_key(escape_index(item))}@#{esc_item}"
end
+ else
+ yomi = NKF.nkf('-w --hiragana', @index_mecab.parse(item).force_encoding('UTF-8').chomp)
+ escape_mendex_key(escape_index(yomi)) + '@' + escape_mendex_display(escape_index(escape(item)))
end
end
"\\index{#{sa.join('!')}}"
end