Class: MathToItex::Math
- Inherits:
-
Object
- Object
- MathToItex::Math
- Defined in:
- lib/math-to-itex.rb
Instance Method Summary collapse
- #convert(&block) ⇒ Object
-
#initialize(string) ⇒ Math
constructor
A new instance of Math.
Constructor Details
#initialize(string) ⇒ Math
Returns a new instance of Math.
8 9 10 |
# File 'lib/math-to-itex.rb', line 8 def initialize(string) @string = string end |
Instance 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 43 44 45 46 47 48 49 50 51 |
# File 'lib/math-to-itex.rb', line 12 def convert(&block) @string.gsub(MathToItex::Parser::REGEX) do |maths| if /\A\$(?!\$)/.match?(maths) just_maths = maths[1..-2] type = :inline elsif /^\\\((?!\\\()/.match?(maths) just_maths = maths[2..-3] type = :inline elsif /\A\$\$/.match?(maths) just_maths = maths[2..-3] type = :display elsif /\A\\\[(?!\\\[)/.match?(maths) just_maths = maths[2..-3] type = :display elsif /\A\\begin{equation}(?!\\begin{equation})/.match?(maths) just_maths = maths[16..-15] type = :display elsif /\A\\begin{math}(?!\\begin{math})/.match?(maths) just_maths = maths[12..-11] type = :inline elsif /\A\\begin{displaymath}(?!\\begin{displaymath})/.match?(maths) just_maths = maths[19..-18] type = :display elsif /\A\\begin{#{MathToItex::Parser::JOINED_ENVIRONMENTS}}(?!\\begin{#{MathToItex::Parser::JOINED_ENVIRONMENTS}})/.match?(maths) just_maths = maths type = :display end # this is the format itex2MML expects all_maths = if type == :inline "$#{just_maths}$" else "$$#{just_maths}$$" end next(all_maths) if block.nil? yield all_maths, type, just_maths end end |