mathematical 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/mathematical/mathematical.c +15 -3
- data/lib/mathematical/render.rb +2 -8
- data/lib/mathematical/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b928c24ef87a4975a2b5851a97e5fa591647efe0
|
4
|
+
data.tar.gz: 704f73219af63fd695babd14c5ac5b71b1b2787e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bce8aee4fb278fb8fc4d41dfd91fc5f437027dc383077cdfdc8ee1a6ba1e146a2ab0306f06c260695681d570e3023124d563626a35b4f38108b44e63b8ac777
|
7
|
+
data.tar.gz: 1b6ce19f7871ba48488765fd56f7b98b997828c16ad272381600778cec0739a7656f44fae5fd8d863ca59eb207d2007b141b770e32ba784eec75fb123c977daa
|
@@ -39,6 +39,13 @@
|
|
39
39
|
static VALUE rb_mMathematical;
|
40
40
|
static VALUE rb_cMathematicalProcess;
|
41
41
|
|
42
|
+
// Raised when the contents could not be parsed
|
43
|
+
static VALUE rb_eParseError;
|
44
|
+
// Raised when the SVG document could not be created
|
45
|
+
static VALUE rb_eDocumentCreationError;
|
46
|
+
// Raised when the SVG document could not be read
|
47
|
+
static VALUE rb_eDocumentReadError;
|
48
|
+
|
42
49
|
char* readFile(const char* filename) {
|
43
50
|
FILE* file = fopen(filename, "r");
|
44
51
|
if (file == NULL) return NULL;
|
@@ -87,7 +94,7 @@ static VALUE MATHEMATICAL_process(VALUE self, VALUE rb_LatexCode, VALUE rb_TempF
|
|
87
94
|
// convert the TeX math to MathML
|
88
95
|
char * mathml = lsm_itex_to_mathml(latex_code, latex_size);
|
89
96
|
|
90
|
-
if (mathml == NULL) rb_raise(
|
97
|
+
if (mathml == NULL) rb_raise(rb_eParseError, "Failed to parse itex");
|
91
98
|
|
92
99
|
int mathml_size = strlen(mathml);
|
93
100
|
|
@@ -96,7 +103,7 @@ static VALUE MATHEMATICAL_process(VALUE self, VALUE rb_LatexCode, VALUE rb_TempF
|
|
96
103
|
|
97
104
|
lsm_itex_free_mathml_buffer (mathml);
|
98
105
|
|
99
|
-
if (document == NULL) rb_raise(
|
106
|
+
if (document == NULL) rb_raise(rb_eDocumentCreationError, "Failed to create document");
|
100
107
|
|
101
108
|
LsmDomView *view;
|
102
109
|
|
@@ -132,14 +139,19 @@ static VALUE MATHEMATICAL_process(VALUE self, VALUE rb_LatexCode, VALUE rb_TempF
|
|
132
139
|
|
133
140
|
char* svg_contents = readFile(tempfile);
|
134
141
|
|
135
|
-
if (svg_contents == NULL) rb_raise(
|
142
|
+
if (svg_contents == NULL) rb_raise(rb_eDocumentReadError, "Failed to read SVG contents");
|
136
143
|
|
137
144
|
return rb_str_new2(readFile(tempfile));
|
138
145
|
}
|
139
146
|
|
140
147
|
void Init_mathematical() {
|
141
148
|
rb_mMathematical = rb_define_module("Mathematical");
|
149
|
+
|
142
150
|
rb_cMathematicalProcess = rb_define_class_under(rb_mMathematical, "Process", rb_cObject);
|
151
|
+
rb_eParseError = rb_define_class_under(rb_mMathematical, "ParseError", rb_eStandardError);
|
152
|
+
rb_eDocumentCreationError = rb_define_class_under(rb_mMathematical, "DocumentCreationError", rb_eStandardError);
|
153
|
+
rb_eDocumentReadError = rb_define_class_under(rb_mMathematical, "DocumentReadError", rb_eStandardError);
|
154
|
+
|
143
155
|
rb_define_method(rb_cMathematicalProcess, "initialize", MATHEMATICAL_init, 1);
|
144
156
|
rb_define_method(rb_cMathematicalProcess, "process", MATHEMATICAL_process, 2);
|
145
157
|
}
|
data/lib/mathematical/render.rb
CHANGED
@@ -11,14 +11,8 @@ module Mathematical
|
|
11
11
|
}
|
12
12
|
|
13
13
|
def initialize(opts = {})
|
14
|
-
raise(TypeError, "opts must be a hash!") unless opts.is_a? Hash
|
15
|
-
|
16
14
|
@config = DEFAULT_OPTS.merge(opts)
|
17
|
-
|
18
|
-
@processer = Mathematical::Process.new(@config)
|
19
|
-
rescue TypeError => e # some error in the C code
|
20
|
-
raise
|
21
|
-
end
|
15
|
+
@processer = Mathematical::Process.new(@config)
|
22
16
|
end
|
23
17
|
|
24
18
|
def render(maths)
|
@@ -32,7 +26,7 @@ module Mathematical
|
|
32
26
|
svg_content = File.open(tempfile.path, 'r') { |image_file| image_file.read }
|
33
27
|
svg_content = svg_content[xml_header.length..-1] # remove starting <?xml...> tag
|
34
28
|
@config[:base64] ? svg_to_base64(svg_content) : svg_content
|
35
|
-
rescue
|
29
|
+
rescue ParseError, DocumentCreationError, DocumentReadError => e # an error in the C code, probably a bad TeX parse
|
36
30
|
$stderr.puts "#{e.message}: #{maths}"
|
37
31
|
maths
|
38
32
|
end
|
data/lib/mathematical/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mathematical
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|