Skip to content

Commit

Permalink
avoid duplication of creating same math. Closes: #1488
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Mar 25, 2020
1 parent 4c985bd commit d5fc8fb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ Metrics/BlockNesting:
Max: 4

Metrics/ModuleLength:
Max: 200
Max: 300

Metrics/ParameterLists:
Max: 8
Expand Down
2 changes: 1 addition & 1 deletion lib/review/epubmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def produce(yamlfile, bookname = nil)
copy_backmatter(basetmpdir)

math_dir = "./#{@config['imagedir']}/_review_math"
if @config['imgmath'] && File.exist?(File.join(math_dir, '__IMGMATH_BODY__.tex'))
if @config['imgmath'] && File.exist?(File.join(math_dir, '__IMGMATH_BODY__.map'))
make_math_images(math_dir)
end
call_hook('hook_afterbackmatter', basetmpdir)
Expand Down
18 changes: 17 additions & 1 deletion lib/review/makerhelper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2012-2018 Yuto HAYAMIZU, Kenshi Muto
# Copyright (c) 2012-2020 Yuto HAYAMIZU, Kenshi Muto
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -112,6 +112,22 @@ def make_math_images(math_dir)
\\end{document}
EOB

hashes = File.readlines(File.join(math_dir, '__IMGMATH_BODY__.map')).sort.uniq
File.write(File.join(math_dir, '__IMGMATH_BODY__.map'), hashes.join)

File.open(File.join(math_dir, '__IMGMATH_BODY__.tex'), 'w') do |f|
File.open(File.join(math_dir, '__IMGMATH_BODY__.map')) do |map|
map.each_line do |l|
l.chomp!
f.puts "% #{l}"
f.puts File.read(File.join(math_dir, "__IMGMATH_BODY__#{l}.tex"))
File.unlink(File.join(math_dir, "__IMGMATH_BODY__#{l}.tex"))
f.puts '\\clearpage'
f.puts
end
end
end

math_dir = File.realpath(math_dir)
Dir.mktmpdir do |tmpdir|
FileUtils.cp([File.join(math_dir, '__IMGMATH_BODY__.tex'),
Expand Down
3 changes: 1 addition & 2 deletions lib/review/textutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ def join_lines_to_paragraph(lines)

def defer_math_image(str, path, key)
# for Re:VIEW >3
File.open(File.join(File.dirname(path), '__IMGMATH_BODY__.tex'), 'a+') do |f|
File.open(File.join(File.dirname(path), "__IMGMATH_BODY__#{key}.tex"), 'w') do |f|
f.puts str
f.puts '\\clearpage'
end
File.open(File.join(File.dirname(path), '__IMGMATH_BODY__.map'), 'a+') do |f|
f.puts key
Expand Down

0 comments on commit d5fc8fb

Please sign in to comment.