mathematical 1.3.0 → 1.4.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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -7
  3. data/Rakefile +4 -1
  4. data/ext/mathematical/cairo_callbacks.h +5 -0
  5. data/ext/mathematical/extconf.rb +34 -8
  6. data/ext/mathematical/lasem_overrides.c +32 -3
  7. data/ext/mathematical/lasem_overrides.h +11 -2
  8. data/ext/mathematical/mathematical.c +27 -26
  9. data/ext/mathematical/mathematical.h +5 -1
  10. data/ext/mathematical/mtex2MML/deps/strdup/strdup.c +24 -0
  11. data/ext/mathematical/mtex2MML/deps/strdup/strdup.h +24 -0
  12. data/ext/mathematical/mtex2MML/deps/uthash/utarray.h +1 -0
  13. data/ext/mathematical/mtex2MML/src/{color_definitions.c → colors.c} +2 -3
  14. data/ext/mathematical/mtex2MML/src/colors.h +23 -0
  15. data/ext/mathematical/mtex2MML/src/em.c +99 -0
  16. data/ext/mathematical/mtex2MML/src/em.h +31 -0
  17. data/ext/mathematical/mtex2MML/src/{parse_extras.c → environment.c} +73 -157
  18. data/ext/mathematical/mtex2MML/src/environment.h +85 -0
  19. data/ext/mathematical/mtex2MML/src/{mtex2MML.l → lexer.l} +26 -15
  20. data/ext/mathematical/mtex2MML/src/main.c +31 -10
  21. data/ext/mathematical/mtex2MML/src/mtex2MML.h +19 -7
  22. data/ext/mathematical/mtex2MML/src/{mtex2MML.y → parser.y} +451 -446
  23. data/ext/mathematical/mtex2MML/src/string_extras.c +4 -3
  24. data/ext/mathematical/mtex2MML/src/string_extras.h +7 -7
  25. data/ext/mathematical/mtex2MML/tests/array.c +11 -11
  26. data/ext/mathematical/mtex2MML/tests/basic.c +14 -13
  27. data/ext/mathematical/mtex2MML/tests/clar.c +2 -0
  28. data/ext/mathematical/mtex2MML/tests/clar/fs.h +3 -1
  29. data/ext/mathematical/mtex2MML/tests/clar/sandbox.h +3 -1
  30. data/ext/mathematical/mtex2MML/tests/cornercases.c +3 -2
  31. data/ext/mathematical/mtex2MML/tests/delimiters.c +126 -0
  32. data/ext/mathematical/mtex2MML/tests/deps/file2str/file2str.c +2 -4
  33. data/ext/mathematical/mtex2MML/tests/deps/mkdtemp/mkdtemp.c +151 -0
  34. data/ext/mathematical/mtex2MML/tests/deps/mkdtemp/mkdtemp.h +10 -0
  35. data/ext/mathematical/mtex2MML/tests/deps/trim/trim.c +4 -1
  36. data/ext/mathematical/mtex2MML/tests/env.c +35 -34
  37. data/ext/mathematical/mtex2MML/tests/functions.c +3 -2
  38. data/ext/mathematical/mtex2MML/tests/helpers.c +6 -4
  39. data/ext/mathematical/mtex2MML/tests/helpers.h +2 -2
  40. data/ext/mathematical/mtex2MML/tests/main.c +1 -1
  41. data/ext/mathematical/mtex2MML/tests/maliciousness.c +35 -9
  42. data/ext/mathematical/mtex2MML/tests/mathjax.c +202 -202
  43. data/ext/mathematical/mtex2MML/tests/numbered_equations.c +6 -6
  44. data/ext/mathematical/mtex2MML/tests/performance.c +39 -0
  45. data/lib/mathematical.rb +38 -5
  46. data/lib/mathematical/configuration.rb +19 -0
  47. data/lib/mathematical/validator.rb +17 -31
  48. data/lib/mathematical/version.rb +1 -1
  49. data/mathematical.gemspec +3 -1
  50. data/test/mathematical/basic_test.rb +60 -7
  51. data/test/mathematical/corrections_test.rb +1 -1
  52. data/test/mathematical/delimiters_test.rb +58 -0
  53. data/test/mathematical/fixtures_test.rb +3 -2
  54. data/test/mathematical/maliciousness_test.rb +19 -27
  55. data/test/mathematical/mathjax_test.rb +6 -5
  56. data/test/mathematical/mathml_test.rb +1 -1
  57. data/test/mathematical/multiples_test.rb +1 -1
  58. data/test/mathematical/performance_test.rb +3 -1
  59. data/test/mathematical/png_test.rb +3 -3
  60. data/test/test_helper.rb +4 -1
  61. metadata +35 -21
  62. data/ext/mathematical/lasem/src/lsmdomenumtypes.c +0 -99
  63. data/ext/mathematical/lasem/src/lsmdomenumtypes.h +0 -26
  64. data/ext/mathematical/lasem/src/lsmmathmlenumtypes.c +0 -737
  65. data/ext/mathematical/lasem/src/lsmmathmlenumtypes.h +0 -93
  66. data/ext/mathematical/lasem/src/lsmsvgenumtypes.c +0 -1083
  67. data/ext/mathematical/lasem/src/lsmsvgenumtypes.h +0 -111
  68. data/ext/mathematical/mtex2MML/Makefile +0 -100
  69. data/ext/mathematical/mtex2MML/build/libmtex2MML.a +0 -0
  70. data/ext/mathematical/mtex2MML/build/mtex2MML.h +0 -73
  71. data/ext/mathematical/mtex2MML/src/lex.yy.c +0 -8845
  72. data/ext/mathematical/mtex2MML/src/parse_extras.h +0 -111
  73. data/ext/mathematical/mtex2MML/src/y.tab.c +0 -10178
  74. data/ext/mathematical/mtex2MML/src/y.tab.h +0 -617
@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
37
  #include <stddef.h> /* size_t */
38
38
  #include <string.h> /* memset, etc */
39
39
  #include <stdlib.h> /* exit */
40
+ #include "../strdup/strdup.h"
40
41
 
41
42
  #define oom() exit(-1)
42
43
 
@@ -1,7 +1,6 @@
1
- #include "parse_extras.h"
2
- #include "../deps/uthash/uthash.h"
1
+ #include "colors.h"
3
2
 
4
- void create_css_colors(struct css_colors **colors)
3
+ void mtex2MML_create_css_colors(struct css_colors **colors)
5
4
  {
6
5
  const char **n, **h,
7
6
  *names[] = { "\"Apricot\"","\"Aquamarine\"","\"Bittersweet\"",
@@ -0,0 +1,23 @@
1
+ #ifndef COLORS_H
2
+ #define COLORS_H
3
+
4
+ #include "../deps/uthash/uthash.h"
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ struct css_colors {
11
+ char name[22]; /* key */
12
+ char color[10];
13
+ UT_hash_handle hh; /* makes this structure hashable */
14
+ };
15
+
16
+ /* Assemble a mapping of color names */
17
+ void mtex2MML_create_css_colors(struct css_colors **colors);
18
+
19
+ #ifdef __cplusplus
20
+ }
21
+ #endif
22
+
23
+ #endif /* ! COLORS_H */
@@ -0,0 +1,99 @@
1
+ #include "em.h"
2
+ #include <stdio.h>
3
+ #include <stdlib.h>
4
+ #include "../deps/strdup/strdup.h"
5
+ #include "../deps/uthash/utstring.h"
6
+
7
+ float mtex2MML_extract_number_from_pxstring(char * str)
8
+ {
9
+ float dbl;
10
+ int match = 0;
11
+
12
+ match = sscanf (str, "%*[^-0123456789]%f", &dbl);
13
+ if (match == 1) {
14
+ return dbl;
15
+ }
16
+
17
+ /* must not be a float */
18
+ sscanf (str, "%d", &match);
19
+ return (float) match;
20
+ }
21
+
22
+ char *mtex2MML_extract_string_from_pxstring(char * str)
23
+ {
24
+ char *pixel;
25
+ float dbl;
26
+ pixel = malloc(3*sizeof(char));
27
+ sscanf (str, "%f%s", &dbl, pixel);
28
+ return pixel;
29
+ }
30
+
31
+ char *mtex2MML_dbl2em(char *str)
32
+ {
33
+ float dbl;
34
+ char *em_str;
35
+ UT_string *em;
36
+ utstring_new(em);
37
+
38
+ dbl = mtex2MML_extract_number_from_pxstring(str);
39
+ dbl *= 0.056;
40
+
41
+ utstring_printf(em, "%.3fem", dbl);
42
+ em_str = strdup(utstring_body(em));
43
+
44
+ utstring_free(em);
45
+
46
+ return em_str;
47
+ }
48
+
49
+ char *mtex2MML_double_pixel(float f, char *pixel)
50
+ {
51
+ float dbl;
52
+ char *em_str;
53
+ UT_string *em;
54
+ utstring_new(em);
55
+
56
+ dbl = f * 2;
57
+ utstring_printf(em, "%.3f%s", dbl, pixel);
58
+ em_str = strdup(utstring_body(em));
59
+
60
+ utstring_free(em);
61
+
62
+ return em_str;
63
+ }
64
+
65
+ char *mtex2MML_implement_skew(char *base_str, char *em_skew, char *pattern)
66
+ {
67
+ char *skew_mathml_str;
68
+ UT_string *skew_mathml;
69
+ utstring_new(skew_mathml);
70
+
71
+ utstring_printf(skew_mathml, "%s%s%s", "<mrow><mrow><mrow><mover><mrow>", base_str, "<mspace width=\"");
72
+ utstring_printf(skew_mathml, "%s%s%s", em_skew, "\" /></mrow>", "<mo stretchy=\"false\">");
73
+ utstring_printf(skew_mathml, "%s%s%s", pattern, "</mo></mover></mrow><mspace width=\"-", em_skew);
74
+ utstring_printf(skew_mathml, "%s", "\" /></mrow><mrow></mrow></mrow>");
75
+
76
+ skew_mathml_str = strdup(utstring_body(skew_mathml));
77
+
78
+ utstring_free(skew_mathml);
79
+
80
+ return skew_mathml_str;
81
+ }
82
+
83
+ char *mtex2MML_root_pos_to_em(char * str)
84
+ {
85
+ float dbl;
86
+ char *em_str;
87
+ UT_string *em;
88
+ utstring_new(em);
89
+
90
+ dbl = mtex2MML_extract_number_from_pxstring(str);
91
+ dbl /= 15;
92
+
93
+ utstring_printf(em, "%.3fem", dbl);
94
+ em_str = strdup(utstring_body(em));
95
+
96
+ utstring_free(em);
97
+
98
+ return em_str;
99
+ }
@@ -0,0 +1,31 @@
1
+ #ifndef EM_H
2
+ #define EM_H
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ /* given a pixel string, retrieve the numeric portion from it */
9
+ float mtex2MML_extract_number_from_pxstring(char * str);
10
+
11
+ /* given a pixel string, retrieve the pixel type portion from it */
12
+ char *mtex2MML_extract_string_from_pxstring(char * str);
13
+
14
+ /* given a number, return it as an em */
15
+ char *mtex2MML_dbl2em(char *str);
16
+
17
+ /* given a number, return it as a root position
18
+ taken straight from MathJax */
19
+ char *mtex2MML_root_pos_to_em(char * str);
20
+
21
+ /* given a number and a pixel string, return the doubled number */
22
+ char *mtex2MML_double_pixel(float f, char *pixel);
23
+
24
+ /* construct a skew sequence */
25
+ char *mtex2MML_implement_skew(char *base_str, char *em_skew, char *pattern);
26
+
27
+ #ifdef __cplusplus
28
+ }
29
+ #endif
30
+
31
+ #endif /* ! EM_H */
@@ -3,7 +3,8 @@
3
3
  #include <string.h>
4
4
  #include <math.h>
5
5
 
6
- #include "parse_extras.h"
6
+ #include "../deps/strdup/strdup.h"
7
+ #include "environment.h"
7
8
  #include "string_extras.h"
8
9
 
9
10
  static const char *BEGIN = "\\begin";
@@ -15,9 +16,9 @@ const char *HLINE = "\\hline", *HDASHLINE = "\\hdashline",
15
16
  *CR_SEPARATOR = "\\cr",
16
17
  *NEWLINE_SEPARATOR = "\\newline",
17
18
  *EM_PATTERN_BEGIN = "\\[", *EM_PATTERN_END = "]",
18
- *NOTAG = "\\notag", *NONUMBER = "\\nonumber";
19
+ *NOTAG = "\\notag", *NONUMBER = "\\nonumber";
19
20
 
20
- int determine_environment(const char *environment)
21
+ int mtex2MML_determine_environment(const char *environment)
21
22
  {
22
23
  if (strstr(environment, "\\end{smallmatrix}") != NULL) {
23
24
  return ENV_SMALLMATRIX;
@@ -44,28 +45,27 @@ int determine_environment(const char *environment)
44
45
  return OTHER;
45
46
  }
46
47
 
47
- int identify_eqn_number(envType environment_type, char *line)
48
+ int mtex2MML_identify_eqn_number(envType environment_type, char *line)
48
49
  {
49
- // some environments have labelling for every row.
50
- // supress it if it has a \notag or \nonumber
50
+ /* some environments have labelling for every row.
51
+ supress it if it has a \notag or \nonumber */
51
52
  if (environment_type == ENV_EQUATION || \
52
53
  environment_type == ENV_ALIGN || \
53
54
  environment_type == ENV_ALIGNAT ||
54
55
  environment_type == ENV_EQNARRAY) {
55
- if (line == NULL)
56
- return 1;
57
- else
58
- return !(strstr(line, NOTAG) != NULL || \
59
- strstr(line, NONUMBER) != NULL);
60
- }
61
- else {
56
+ if (line == NULL) {
57
+ return 1;
58
+ } else
59
+ return !(strstr(line, NOTAG) != NULL || \
60
+ strstr(line, NONUMBER) != NULL);
61
+ } else {
62
62
  return 0;
63
63
  }
64
64
  }
65
65
 
66
- void env_replacements(UT_array **environment_data_stack, encaseType * encase, const char *environment)
66
+ void mtex2MML_env_replacements(UT_array **environment_data_stack, encaseType **encase, const char *environment)
67
67
  {
68
- // if not an environment, don't bother going on
68
+ /* if not an environment, don't bother going on */
69
69
  if ((strstr(environment, BEGIN) == NULL && strstr(environment, END) == NULL) || strstr(environment, BEGIN_SVG)) {
70
70
  return;
71
71
  }
@@ -79,12 +79,12 @@ void env_replacements(UT_array **environment_data_stack, encaseType * encase, co
79
79
  *temp = "", **prev_stack_item,
80
80
  *a, *em_str;
81
81
 
82
- int rowlines_stack_len = 0, em_offset = 0, eqn = 0, i = 0, insertion_idx = 0;
82
+ unsigned int rowlines_stack_len = 0, eqn = 0, i = 0, insertion_idx = 0;
83
83
 
84
84
  char *dupe_environment = strdup(environment);
85
85
  char *line = strtok(dupe_environment, "\n");
86
86
 
87
- // set up the array stack
87
+ /* set up the array stack */
88
88
  utarray_new(array_stack, &ut_str_icd);
89
89
  utarray_new(row_spacing_stack, &ut_str_icd);
90
90
  utarray_new(rowlines_stack, &ut_str_icd);
@@ -94,7 +94,7 @@ void env_replacements(UT_array **environment_data_stack, encaseType * encase, co
94
94
  utarray_push_back(array_stack, &line);
95
95
 
96
96
  if (strstr(line, END) != NULL) {
97
- envType environment_type = determine_environment(line);
97
+ envType environment_type = mtex2MML_determine_environment(line);
98
98
 
99
99
  while (utarray_len(array_stack) > 0) {
100
100
  prev_stack_item = (char **)utarray_back(array_stack);
@@ -102,34 +102,34 @@ void env_replacements(UT_array **environment_data_stack, encaseType * encase, co
102
102
  rowlines_stack_len = utarray_len(rowlines_stack);
103
103
  at_top = strstr(*prev_stack_item, BEGIN);
104
104
 
105
- // we've reached the top, but there looks like there might be some data
105
+ /* we've reached the top, but there looks like there might be some data */
106
106
  if (at_top != NULL && strstr(*prev_stack_item, LINE_SEPARATOR) == NULL && \
107
107
  strstr(*prev_stack_item, CR_SEPARATOR) == NULL && \
108
108
  strstr(*prev_stack_item, NEWLINE_SEPARATOR) == NULL) {
109
109
  if (strstr(*prev_stack_item, HLINE) != NULL || strstr(*prev_stack_item, HDASHLINE) != NULL) {
110
- *encase = TOPENCLOSE;
110
+ *encase = (encaseType*)TOPENCLOSE;
111
111
  }
112
- // TODO: not super confident this is bulletproof
112
+ /* TODO: not super confident this is bulletproof */
113
113
  if (rowlines_stack_len == 0) {
114
- eqn = identify_eqn_number(environment_type, *prev_stack_item);
114
+ eqn = mtex2MML_identify_eqn_number(environment_type, *prev_stack_item);
115
115
  utarray_push_back(eqn_number_stack, &eqn);
116
116
  }
117
117
  break;
118
118
  }
119
119
 
120
- // these environments are a bit...special. they still use
121
- // the same line separators, so they tend to mess with "proper"
122
- // labelled environments, because they exist within \begin{equation}
123
- // if we find one, erase all the stored row info.
120
+ /* these environments are a bit...special. they still use
121
+ the same line separators, so they tend to mess with "proper"
122
+ labelled environments, because they exist within \begin{equation}
123
+ if we find one, erase all the stored row info. */
124
124
  if (strstr(*prev_stack_item, "\\eqalign") != NULL || \
125
- strstr(*prev_stack_item, "\\split") != NULL) {
125
+ strstr(*prev_stack_item, "\\split") != NULL) {
126
126
  for (i = rowlines_stack_len; i > 1; i--) {
127
127
  utarray_pop_back(rowlines_stack);
128
128
  utarray_pop_back(eqn_number_stack);
129
129
  }
130
130
  }
131
131
 
132
- // looking for a hline/hdashline match
132
+ /* looking for a hline/hdashline match */
133
133
  if (strstr(*prev_stack_item, HLINE) != NULL) {
134
134
  if (rowlines_stack_len > 0) {
135
135
  utarray_pop_back(rowlines_stack);
@@ -147,24 +147,24 @@ void env_replacements(UT_array **environment_data_stack, encaseType * encase, co
147
147
  utarray_push_back(rowlines_stack, &a);
148
148
  }
149
149
 
150
- eqn = identify_eqn_number(environment_type, *prev_stack_item);
150
+ eqn = mtex2MML_identify_eqn_number(environment_type, *prev_stack_item);
151
151
  utarray_push_back(eqn_number_stack, &eqn);
152
152
 
153
- // if there's a line break...
153
+ /* if there's a line break... */
154
154
  if (strstr(*prev_stack_item, LINE_SEPARATOR) != NULL || \
155
155
  strstr(*prev_stack_item, CR_SEPARATOR) != NULL || \
156
156
  strstr(*prev_stack_item, NEWLINE_SEPARATOR) != NULL) {
157
- // ...with an emphasis match, add it...
157
+ /* ...with an emphasis match, add it... */
158
158
  if ( (tok = strstr(*prev_stack_item, EM_PATTERN_BEGIN)) != NULL) {
159
- temp = tok + 2; // skip the first part ("\[")
159
+ temp = tok + 2; /* skip the first part ("\[") */
160
160
  if ( (tok = strstr(temp, EM_PATTERN_END)) != NULL) {
161
- em_offset = (int)(tok - temp);
162
- char *s = strndup(temp, em_offset);
161
+ mtex2MML_remove_last_char(temp);
162
+ char *s = strdup(temp);
163
163
  utarray_push_back(row_spacing_stack, &s);
164
164
  free(s);
165
165
  }
166
166
  }
167
- // ...otherwise, use the default emphasis
167
+ /* ...otherwise, use the default emphasis */
168
168
  else {
169
169
  if (environment_type == ENV_SMALLMATRIX) {
170
170
  em_str = "0.2em";
@@ -181,25 +181,25 @@ void env_replacements(UT_array **environment_data_stack, encaseType * encase, co
181
181
  }
182
182
  }
183
183
 
184
- // make sure to pop at the end here; it messes with some references in Travis/Ubuntu for some reason
184
+ /* make sure to pop at the end here; it messes with some references in Travis/Ubuntu for some reason */
185
185
  utarray_pop_back(array_stack);
186
186
 
187
- // we've reached the top, so stop.
187
+ /* we've reached the top, so stop. */
188
188
  if (at_top != NULL) {
189
189
  break;
190
190
  }
191
191
  }
192
192
 
193
- // some environments only have one label for the whole environment,
194
- // rather than a label per row. in that case, jam a label
195
- // in the middle.
193
+ /* some environments only have one label for the whole environment,
194
+ rather than a label per row. in that case, jam a label
195
+ in the middle. */
196
196
  if (environment_type == ENV_GATHER || environment_type == ENV_MULTLINE) {
197
197
  insertion_idx = ceil(utarray_len(eqn_number_stack) / 2);
198
198
  eqn = 1;
199
199
  utarray_insert(eqn_number_stack, &eqn, insertion_idx);
200
200
  utarray_pop_back(eqn_number_stack);
201
201
  }
202
- perform_replacement(environment_data_stack, rowlines_stack, environment_type, eqn_number_stack, row_spacing_stack);
202
+ mtex2MML_perform_replacement(environment_data_stack, rowlines_stack, environment_type, eqn_number_stack, row_spacing_stack);
203
203
 
204
204
  utarray_clear(row_spacing_stack);
205
205
  utarray_clear(rowlines_stack);
@@ -218,27 +218,29 @@ void env_replacements(UT_array **environment_data_stack, encaseType * encase, co
218
218
  free(dupe_environment);
219
219
  }
220
220
 
221
- void perform_replacement(UT_array **environment_data_stack, UT_array *rowlines_stack, envType environment_type, UT_array *eqn_number_stack, UT_array *row_spacing_stack)
221
+ void mtex2MML_perform_replacement(UT_array **environment_data_stack, UT_array *rowlines_stack, envType environment_type, UT_array *eqn_number_stack, UT_array *row_spacing_stack)
222
222
  {
223
223
  char *a, *attr_rowlines, *attr_rowspacing;
224
224
  envdata_t env_data;
225
225
 
226
- // we cut the last char because we can always skip the first row
227
- if (utarray_len(rowlines_stack) != 0)
226
+ /* we cut the last char because we can always skip the first row */
227
+ if (utarray_len(rowlines_stack) != 0) {
228
228
  utarray_pop_back(rowlines_stack);
229
+ }
229
230
 
230
- if (utarray_len(eqn_number_stack) > 1)
231
+ if (utarray_len(eqn_number_stack) > 1) {
231
232
  utarray_erase(eqn_number_stack, 0, 1);
233
+ }
232
234
 
233
- int line_count = utarray_len(rowlines_stack);
235
+ unsigned int line_count = utarray_len(rowlines_stack);
234
236
 
235
- // empty rowlines should be reset
237
+ /* empty rowlines should be reset */
236
238
  if (line_count == 0) {
237
239
  a = "none";
238
240
  utarray_push_back(rowlines_stack, &a);
239
241
  }
240
242
 
241
- // given the row_attribute values, construct an attribute list (separated by spaces)
243
+ /* given the row_attribute values, construct an attribute list (separated by spaces) */
242
244
  UT_string *l;
243
245
  utstring_new(l);
244
246
  char **o=NULL;
@@ -250,10 +252,10 @@ void perform_replacement(UT_array **environment_data_stack, UT_array *rowlines_s
250
252
 
251
253
  attr_rowlines = utstring_body(l);
252
254
  if (strlen(attr_rowlines) > 0) {
253
- remove_last_char(attr_rowlines); // remove the final space
255
+ mtex2MML_remove_last_char(attr_rowlines); /* remove the final space */
254
256
  }
255
257
 
256
- // given the row_spacing values, construct an attribute list (separated by spaces)
258
+ /* given the row_spacing values, construct an attribute list (separated by spaces) */
257
259
  UT_string *s;
258
260
  utstring_new(s);
259
261
  char **p=NULL;
@@ -269,7 +271,7 @@ void perform_replacement(UT_array **environment_data_stack, UT_array *rowlines_s
269
271
 
270
272
  attr_rowspacing = utstring_body(s);
271
273
  if (strlen(attr_rowspacing) > 0) {
272
- remove_last_char(attr_rowspacing); // remove the final space
274
+ mtex2MML_remove_last_char(attr_rowspacing); /* remove the final space */
273
275
  } else {
274
276
  if (environment_type == ENV_SMALLMATRIX) {
275
277
  attr_rowspacing = "0.2em";
@@ -280,7 +282,7 @@ void perform_replacement(UT_array **environment_data_stack, UT_array *rowlines_s
280
282
  }
281
283
  }
282
284
 
283
- // store pertinent metadata
285
+ /* store pertinent metadata */
284
286
  env_data.rowspacing = attr_rowspacing;
285
287
  env_data.rowlines = attr_rowlines;
286
288
  env_data.environment_type = environment_type;
@@ -292,23 +294,23 @@ void perform_replacement(UT_array **environment_data_stack, UT_array *rowlines_s
292
294
  utstring_free(s);
293
295
  }
294
296
 
295
- const char *vertical_pipe_extract(const char *string)
297
+ char *mtex2MML_vertical_pipe_extract(char *string)
296
298
  {
297
299
  char *dupe = strdup(string);
298
300
  UT_string *columnlines, *border;
299
301
  char *previous_column = "", *attr_columnlines, *attr_border;
300
- int i = 0;
302
+ unsigned int i = 0;
301
303
 
302
304
  utstring_new(columnlines);
303
305
  utstring_new(border);
304
306
 
305
- // the first character (if it exists) determines the frame border
307
+ /* the first character (if it exists) determines the frame border */
306
308
  if (strncmp(dupe, "s", 1) == 0) {
307
309
  utstring_printf(columnlines, "%s", "frame=\"solid\" columnlines=\"");
308
- remove_first_char(dupe);
310
+ mtex2MML_remove_first_char(dupe);
309
311
  } else if (strncmp(dupe, "d", 1) == 0) {
310
312
  utstring_printf(columnlines, "%s", "frame=\"dashed\" columnlines=\"");
311
- remove_first_char(dupe);
313
+ mtex2MML_remove_first_char(dupe);
312
314
  } else {
313
315
  utstring_printf(columnlines, "%s", "columnlines=\"");
314
316
  }
@@ -323,8 +325,9 @@ const char *vertical_pipe_extract(const char *string)
323
325
  previous_column = "d";
324
326
  utstring_printf(border, "%s ", "dashed");
325
327
  } else {
326
- if (i >= 1) { // we must skip the first blank col
327
- // only if there is no previous border should a border be considered, eg. "cc", not "c|c"
328
+ /* we must skip the first blank col only if there is no previous border
329
+ should a border be considered, eg. "cc", not "c|c" */
330
+ if (i >= 1) {
328
331
  if (strncmp(previous_column, "s", 1) != 0 && strncmp(previous_column, "d", 1) != 0) {
329
332
  utstring_printf(border, "%s ", "none");
330
333
  }
@@ -338,11 +341,11 @@ const char *vertical_pipe_extract(const char *string)
338
341
 
339
342
  attr_border = utstring_body(border);
340
343
  if (strlen(attr_border) > 0) {
341
- remove_last_char(attr_border); // remove the final space
344
+ mtex2MML_remove_last_char(attr_border); /* remove the final space */
342
345
  }
343
346
  utstring_printf(columnlines, "%s", attr_border);
344
347
 
345
- // an empty string here angers Lasem, so let's remember to add 'none'
348
+ /* an empty string here angers Lasem, so let's remember to add 'none' */
346
349
  if (utstring_len(border) == 0) {
347
350
  utstring_printf(columnlines, "%s", "none");
348
351
  }
@@ -355,7 +358,7 @@ const char *vertical_pipe_extract(const char *string)
355
358
  return attr_columnlines;
356
359
  }
357
360
 
358
- const char *remove_excess_pipe_chars(const char *string)
361
+ char *mtex2MML_remove_excess_pipe_chars(char *string)
359
362
  {
360
363
  UT_string *columnalign;
361
364
  utstring_new(columnalign);
@@ -376,15 +379,15 @@ const char *remove_excess_pipe_chars(const char *string)
376
379
  utstring_free(columnalign);
377
380
 
378
381
  if (strlen(attr_columnalign) > 0) {
379
- remove_last_char(attr_columnalign); // remove the final space
382
+ mtex2MML_remove_last_char(attr_columnalign); /* remove the final space */
380
383
  }
381
384
 
382
385
  return attr_columnalign;
383
386
  }
384
387
 
385
- const char *combine_row_data(UT_array **environment_data_stack)
388
+ char *mtex2MML_combine_row_data(UT_array **environment_data_stack)
386
389
  {
387
- // if no information was provided, give a standard sizing
390
+ /* if no information was provided, give a standard sizing */
388
391
  if (utarray_len(*environment_data_stack) == 0) {
389
392
  const char* s = "rowspacing=\"0.5ex\" rowlines=\"none\"";
390
393
  char* c = (char*)malloc(strlen(s) + 1);
@@ -400,7 +403,7 @@ const char *combine_row_data(UT_array **environment_data_stack)
400
403
  UT_string *row_attr_data;
401
404
  utstring_new(row_attr_data);
402
405
 
403
- // combine the row spacing and row lines data
406
+ /* combine the row spacing and row lines data */
404
407
  utstring_printf(row_attr_data, "%s%s\" %s\"", "rowspacing=\"", row_spacing_data, row_lines_data);
405
408
 
406
409
  row_attr = strdup(utstring_body(row_attr_data));
@@ -411,9 +414,9 @@ const char *combine_row_data(UT_array **environment_data_stack)
411
414
  return row_attr;
412
415
  }
413
416
 
414
- int fetch_eqn_number(UT_array **environment_data_stack)
417
+ int mtex2MML_fetch_eqn_number(UT_array **environment_data_stack)
415
418
  {
416
- // if no information was provided, expect nothing
419
+ /* if no information was provided, expect nothing */
417
420
  if (utarray_len(*environment_data_stack) == 0) {
418
421
  return 0;
419
422
  }
@@ -429,94 +432,7 @@ int fetch_eqn_number(UT_array **environment_data_stack)
429
432
  return *e;
430
433
  }
431
434
 
432
- float extract_number_from_pxstring(const char * str)
433
- {
434
- float dbl;
435
- int match = 0;
436
-
437
- match = sscanf (str, "%*[^-0123456789]%f", &dbl);
438
- if (match == 1) {
439
- return dbl;
440
- }
441
-
442
- // must not be a float.
443
- sscanf (str, "%d", &match);
444
- return (float) match;
445
- }
446
-
447
- const char *extract_string_from_pxstring(const char * str)
448
- {
449
- char *pixel;
450
- float dbl;
451
- pixel = malloc(3*sizeof(char));
452
- sscanf (str, "%f%s", &dbl, pixel);
453
- return pixel;
454
- }
455
-
456
- const char * dbl2em(const char *str)
457
- {
458
- UT_string *em;
459
- utstring_new(em);
460
-
461
- float dbl = extract_number_from_pxstring(str);
462
- dbl *= 0.056;
463
-
464
- utstring_printf(em, "%.3fem", dbl);
465
- char * em_str = strdup(utstring_body(em));
466
-
467
- utstring_free(em);
468
-
469
- return em_str;
470
- }
471
-
472
- const char * double_pixel(float f, char *pixel)
473
- {
474
- UT_string *em;
475
- utstring_new(em);
476
-
477
- float dbl = f * 2;
478
- utstring_printf(em, "%.3f%s", dbl, pixel);
479
- char * em_str = strdup(utstring_body(em));
480
-
481
- utstring_free(em);
482
-
483
- return em_str;
484
- }
485
-
486
- const char * implement_skew(char *base_str, char *em_skew, char *pattern)
487
- {
488
- UT_string *skew_mathml;
489
- utstring_new(skew_mathml);
490
-
491
- utstring_printf(skew_mathml, "%s%s%s", "<mrow><mrow><mrow><mover><mrow>", base_str, "<mspace width=\"");
492
- utstring_printf(skew_mathml, "%s%s%s", em_skew, "\" /></mrow>", "<mo stretchy=\"false\">");
493
- utstring_printf(skew_mathml, "%s%s%s", pattern, "</mo></mover></mrow><mspace width=\"-", em_skew);
494
- utstring_printf(skew_mathml, "%s", "\" /></mrow><mrow></mrow></mrow>");
495
-
496
- char * skew_mathml_str = strdup(utstring_body(skew_mathml));
497
-
498
- utstring_free(skew_mathml);
499
-
500
- return skew_mathml_str;
501
- }
502
-
503
- const char * root_pos_to_em(const char * str)
504
- {
505
- UT_string *em;
506
- utstring_new(em);
507
-
508
- float dbl = extract_number_from_pxstring(str);
509
- dbl /= 15;
510
-
511
- utstring_printf(em, "%.3fem", dbl);
512
- char * em_str = strdup(utstring_body(em));
513
-
514
- utstring_free(em);
515
-
516
- return em_str;
517
- }
518
-
519
- envType current_env_type(UT_array **environment_data_stack)
435
+ envType mtex2MML_current_env_type(UT_array **environment_data_stack)
520
436
  {
521
437
  if (utarray_len(*environment_data_stack) == 0) {
522
438
  return -1;
@@ -527,7 +443,7 @@ envType current_env_type(UT_array **environment_data_stack)
527
443
  return row_data_elem->environment_type;
528
444
  }
529
445
 
530
- int current_env_line_count(UT_array **environment_data_stack)
446
+ int mtex2MML_current_env_line_count(UT_array **environment_data_stack)
531
447
  {
532
448
  if (utarray_len(*environment_data_stack) == 0) {
533
449
  return -1;