Module: MathToItex

Defined in:
lib/math-to-itex.rb,
lib/math-to-itex/parser.rb,
lib/math-to-itex/version.rb

Defined Under Namespace

Classes: Parser

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.convert(&block) ⇒ Object



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
42
# File 'lib/math-to-itex.rb', line 12

def self.convert(&block)
  @string.gsub(MathToItex::Parser::REGEX) do |maths|
    if maths =~ /\A\$(?!\$)/
      just_maths = maths[1..-2]
      type = :inline
    elsif maths =~ /^\\\((?!\\\()/
      just_maths = maths[2..-3]
      type = :inline
    elsif maths =~ /\A\$\$/
      just_maths = maths[2..-3]
      type = :display
    elsif maths =~ /\A\\\[(?!\\\[)/
      just_maths = maths[2..-3]
      type = :display
    elsif maths =~ /\A\\begin(?!\\begin)/
      just_maths = maths[16..-15]
      type = :display
    end

    # this is the format itex2MML expects
    if type == :inline
      just_maths = "$#{just_maths}$"
    else
      just_maths = "$$#{just_maths}$$"
    end

    next(just_maths) if block.nil?

    yield just_maths, type
  end
end

.parens(string) ⇒ Object



7
8
9
10
# File 'lib/math-to-itex.rb', line 7

def self.parens(string)
  @string = string
  self
end