lib/review/latexbuilder.rb in review-5.0.0 vs lib/review/latexbuilder.rb in review-5.1.0
- old
+ new
@@ -1,8 +1,8 @@
# Copyright (c) 2002-2007 Minero Aoki
# 2008-2009 Minero Aoki, Kenshi Muto
-# 2010-2020 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi
+# 2010-2021 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".
@@ -49,10 +49,11 @@
if @book.config['pdfmaker']['makeindex_dic']
@index_db = load_idxdb(@book.config['pdfmaker']['makeindex_dic'])
end
return true unless @book.config['pdfmaker']['makeindex_mecab']
+
begin
begin
require 'MeCab'
rescue LoadError
require 'mecab'
@@ -178,14 +179,14 @@
def notoc_end(level)
end
def nodisp_begin(level, _label, caption)
- if @output.pos != 0
- blank
- else
+ if @output.pos == 0
puts macro('clearpage')
+ else
+ blank
end
puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
# FIXME: headings
end
@@ -332,10 +333,11 @@
def ol_begin
blank
puts '\begin{enumerate}'
return true unless @ol_num
+
puts "\\setcounter{enumi}{#{@ol_num - 1}}"
@ol_num = nil
end
def ol_item(lines, _num)
@@ -555,40 +557,42 @@
def parse_metric(type, metric)
s = super(type, metric)
if @book.config['pdfmaker']['use_original_image_size'] && s.empty? && !metric.present?
return ' ' # pass empty to \reviewincludegraphics
end
+
s
end
def handle_metric(str)
if @book.config['pdfmaker']['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)
+ def image_image(id, caption = '', metric = nil)
captionstr = nil
@doc_status[:caption] = true
if @book.config.check_version('2', exception: false)
- captionstr = macro('caption', compile_inline(caption)) + "\n" if caption.present?
+ captionstr = macro('caption', compile_inline(caption)) + "\n"
else
- captionstr = macro('reviewimagecaption', compile_inline(caption)) + "\n" if caption.present?
+ captionstr = macro('reviewimagecaption', compile_inline(caption)) + "\n"
end
captionstr << macro('label', image_label(id))
@doc_status[:caption] = nil
metrics = parse_metric('latex', metric)
# image is always bound here
puts "\\begin{reviewimage}%%#{id}"
- if caption_top?('image') && captionstr
+ if caption_top?('image')
puts captionstr
end
command = 'reviewincludegraphics'
if @book.config.check_version('2', exception: false)
@@ -599,11 +603,11 @@
puts "\\#{command}[#{metrics}]{#{@chapter.image(id).path}}"
else
puts "\\#{command}[width=\\maxwidth]{#{@chapter.image(id).path}}"
end
- if !caption_top?('image') && captionstr
+ unless caption_top?('image')
puts captionstr
end
puts '\end{reviewimage}'
end
@@ -1005,17 +1009,19 @@
end
private :latex_block
def direct(lines, fmt)
return unless fmt == 'latex'
+
lines.each do |line|
puts line
end
end
def comment(lines, comment = nil)
return true unless @book.config['draft']
+
lines ||= []
unless comment.blank?
lines.unshift(escape(comment))
end
str = lines.join('\par ')
@@ -1043,22 +1049,22 @@
end
def inline_chapref(id)
title = super
if @book.config['chapterlink']
- "\\hyperref[chap:#{id}]{#{title}}"
+ "\\reviewchapref{#{title}}{chap:#{id}}"
else
title
end
rescue KeyError
error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
def inline_chap(id)
if @book.config['chapterlink']
- "\\hyperref[chap:#{id}]{#{@book.chapter_index.number(id)}}"
+ "\\reviewchapref{#{@book.chapter_index.number(id)}}{chap:#{id}}"
else
@book.chapter_index.number(id)
end
rescue KeyError
error "unknown chapter: #{id}"
@@ -1066,11 +1072,11 @@
end
def inline_title(id)
title = super
if @book.config['chapterlink']
- "\\hyperref[chap:#{id}]{#{title}}"
+ "\\reviewchapref{#{title}}{chap:#{id}}"
else
title
end
rescue KeyError
error "unknown chapter: #{id}"
@@ -1229,10 +1235,14 @@
else
macro('reviewtt', escape(str))
end
end
+ def inline_ins(str)
+ macro('reviewinsert', escape(str))
+ end
+
def inline_del(str)
macro('reviewstrike', escape(str))
end
def inline_tti(str)
@@ -1261,11 +1271,11 @@
str = I18n.t('hd_quote', [chap.headline_index.number(id), compile_inline(chap.headline(id).caption)])
else
str = I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
end
if @book.config['chapterlink']
- anchor = n.gsub(/\./, '-')
+ anchor = n.tr('.', '-')
macro('reviewsecref', str, sec_label(anchor))
else
str
end
end
@@ -1359,25 +1369,26 @@
puts ''
end
def index(str)
+ # XXX: mendex/upmendex specific
sa = str.split('<<>>')
sa.map! do |item|
if @index_db[item]
- escape_index(escape(@index_db[item])) + '@' + escape_index(escape(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_index(escape(item))
- if esc_item != item
- "#{escape_index(item)}@#{esc_item}"
- else
+ 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
else
yomi = NKF.nkf('-w --hiragana', @index_mecab.parse(item).force_encoding('UTF-8').chomp)
- escape_index(escape(yomi)) + '@' + escape_index(escape(item))
+ escape_mendex_key(escape_index(yomi)) + '@' + escape_mendex_display(escape_index(escape(item)))
end
end
end
"\\index{#{sa.join('!')}}"