Class: Metanorma::Standoc::LatexmlRequirement

Inherits:
Requirement
  • Object
show all
Defined in:
lib/metanorma/standoc/latexml_requirement.rb

Instance Method Summary collapse

Constructor Details

#initializeLatexmlRequirement

Returns a new instance of LatexmlRequirement.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/metanorma/standoc/latexml_requirement.rb', line 9

def initialize
  version_output, = Open3.capture2e("latexml --VERSION")
  version = version_output&.match(%r{\d+(.\d+)*})

  if version.to_s.empty?
    @error_message = "LaTeXML is not available. (Or is PATH not setup properly?)"\
      " You must upgrade/install LaTeXML to a version higher than `#{@recommended_version}`"

  elsif Gem::Version.new(version) < Gem::Version.new(@minimal_version)
    @error_message = "Minimal supported LaTeXML version is `#{@minimal_version}` "\
        "Version `#{version}` found; recommended version is `#{@recommended_version}`"

  elsif Gem::Version.new(version) < Gem::Version.new(@recommended_version)
    version = "unknown" if version.to_s.empty?
    header_msg = "latexmlmath version `#{version}` below `#{@recommended_version}`!"
    suggestion = if Gem.win_platform?
                   "cmd encoding is set to UTF-8 with `chcp 65001`"
                 else
                   "terminal encoding is set to UTF-8 with `export LANG=en_US.UTF-8`"
                 end

    @error_message = "WARNING #{header_msg} Please sure that #{suggestion} command."

    @cmd = 'latexmlmath --strict --preload=amsmath -- -'
    @cmd2 = 'latexmlmath --strict -- -'
  else
    @cmd = 'latexmlmath --strict --preload=amsmath --inputencoding=UTF-8 -- -'
    @cmd2 = 'latexmlmath --strict --inputencoding=UTF-8 -- -'
  end
rescue
  @error_message = "LaTeXML is not available. (Or is PATH not setup properly?)"\
      " You must upgrade/install LaTeXML to a version higher than `#{@recommended_version}`"
end

Instance Method Details

#cmdObject



55
56
57
58
59
# File 'lib/metanorma/standoc/latexml_requirement.rb', line 55

def cmd
  abort @error_message unless @error_message.nil?

  [@cmd, @cmd2]
end

#satisfied(abort = false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/metanorma/standoc/latexml_requirement.rb', line 43

def satisfied(abort = false)
  unless @error_message.nil?
    if abort
      abort @error_message
    else
      warn @error_message
    end
  end

  @error_message.nil?
end