1
# Ruby module for itex2MML
5
# 1. You need SWIG (>= 1.3) and GNU Make to install
11
# 3. This module can then be invoked like:
15
# itex = Itex2MML::Parser.new
16
# itex.html_filter(string)
21
# There are two public methods
23
# itex.html_filter(a_string)
24
# converts all itex equations in a_string to MathML, passing the
25
# rest of a_string unmodified. Returns the converted string.
27
# itex.filter(a_string)
28
# converts all itex equations in a_string to MathML. Returns just
29
# the MathML equation(s), as a string.
31
# Author: Justin Bonnar <jbonnar@berkeley.edu>
32
# Placed in the Public Domain
38
class Error < RuntimeError; end
42
@semaphore ||= Mutex.new
45
def html_filter(string)
46
parse(string, :itex2MML_html_filter)
50
parse(string, :itex2MML_filter)
55
def parse(string, message)
56
string = string.to_str
57
self.class.semaphore.synchronize do
58
raise Itex2MML::Error unless Itex2MML.send(message, string, string.length) == 0
59
Itex2MML.itex2MML_output
69
class Itex2MMLTest < Test::Unit::TestCase
72
itex = Itex2MML::Parser.new
73
assert_equal("Inline: <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.html_filter('Inline: $\sin(x)$'))
77
itex = Itex2MML::Parser.new
78
assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.filter('Inline: $\sin(x)$'))
82
itex = Itex2MML::Parser.new
83
assert_equal("Block: <math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.html_filter('Block: $$\sin(x)$$'))
87
itex = Itex2MML::Parser.new
88
assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.filter('Block: $$\sin(x)$$'))