Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMLBuilder: hide latex log of @<m>{...} amd //texequation{...//} #1027

Merged
merged 2 commits into from
Jun 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ Metrics/PerceivedComplexity:

Metrics/ClassLength:
Max: 1500
Exclude:
- 'test/*.rb'

Metrics/LineLength:
Max: 256
Expand Down
7 changes: 6 additions & 1 deletion lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'review/webtocprinter'
require 'digest'
require 'tmpdir'
require 'open3'

module ReVIEW
class HTMLBuilder < Builder
Expand Down Expand Up @@ -1208,7 +1209,11 @@ def make_math_image(str, path, fontsize = 12)
tex_path = File.join(tmpdir, 'tmpmath.tex')
dvi_path = File.join(tmpdir, 'tmpmath.dvi')
File.write(tex_path, texsrc)
system("latex --interaction=nonstopmode --output-directory=#{tmpdir} #{tex_path} && dvipng -T tight -z9 -o #{path} #{dvi_path}")
cmd = "latex --interaction=nonstopmode --output-directory=#{tmpdir} #{tex_path} && dvipng -T tight -z9 -o #{path} #{dvi_path}"
out, status = Open3.capture2e(cmd)
unless status.success?
error "latex compile error\n\nError log:\n" + out
end
end
end
end
Expand Down
26 changes: 26 additions & 0 deletions test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,8 @@ def test_cmd_caption
end

def test_texequation
return true if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM
return true unless system('latex -version 1>/dev/null 2>/dev/null')
mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
'ch01.re' => "= test\n\n//texequation{\np \\land \\bm{P} q\n//}\n") do |dir, book, _files|
@book = book
Expand All @@ -1088,6 +1090,30 @@ def test_texequation
end
end

def test_texequation_fail
return true if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM
return true unless system('latex -version 1>/dev/null 2>/dev/null')
mktmpbookdir('catalog.yml' => "CHAPS:\n - ch01.re\n",
'ch01.re' => "= test\n\n//texequation{\np \\land \\bm{P}} q\n//}\n") do |dir, book, _files|
@book = book
@book.config = @config
@config['imgmath'] = true
@chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
location = Location.new(nil, nil)
@builder.bind(@compiler, @chapter, location)
FileUtils.mkdir_p(File.join(dir, 'images'))
tmpio = $stderr
$stderr = StringIO.new
begin
assert_raise(ReVIEW::ApplicationError) do
_result = compile_block("//texequation{\np \\land \\bm{P}} q\n//}\n")
end
ensure
$stderr = tmpio
end
end
end

def test_bib
def @chapter.bibpaper(_id)
Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
Expand Down