Class: HParser::Inline::Tex

Inherits:
Object
  • Object
show all
Includes:
Collectable
Defined in:
lib/hparser/html.rb,
lib/hparser/text.rb,
lib/hparser/latex.rb,
lib/hparser/inline/tex.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Tex

Returns a new instance of Tex.



12
13
14
# File 'lib/hparser/inline/tex.rb', line 12

def initialize(text)
  @text = text
end

Instance Attribute Details

#textObject (readonly) Also known as: to_text

Returns the value of attribute text.



11
12
13
# File 'lib/hparser/inline/tex.rb', line 11

def text
  @text
end

Class Method Details

.parse(scanner, context = nil) ⇒ Object



16
17
18
19
20
# File 'lib/hparser/inline/tex.rb', line 16

def self.parse(scanner, context=nil)
  if scanner.scan(/\[tex:([^\]]+)\]/) then
    Tex.new scanner[1]
  end
end

Instance Method Details

#==(o) ⇒ Object



22
23
24
# File 'lib/hparser/inline/tex.rb', line 22

def ==(o)
  self.class == o.class and @text == o.text
end

#to_htmlObject



332
333
334
335
336
# File 'lib/hparser/html.rb', line 332

def to_html
  require "cgi"
  url = "http://chart.apis.google.com/chart?cht=tx&chf=bg,s,00000000&chl=" + CGI.escape(self.text)
  %(<img src="#{url}" class="tex" alt="#{CGI.escapeHTML(self.text)}">)
end

#to_latexObject



254
255
256
# File 'lib/hparser/latex.rb', line 254

def to_latex
  %($#{self.text}$)
end