Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ documentation = "https://nsoiffer.github.io/MathCAT/"
edition = "2018"
exclude = ["src/main.rs", "docs", "PythonScripts"] # should have "Rules/", but then one can't run build.rs to build the zip file


[features]
"include-zip" = []
"enable-logs" = ["android_logger"]
Expand Down Expand Up @@ -38,6 +37,7 @@ log = "0.4"
env_logger = "0.11.8"
cfg-if = "1.0.1"
fastrand = { version = "2.3.0" }
ext-php-rs = "0.10.0"

[target.'cfg(target_family = "wasm")'.dependencies]
zip = { version = "4.3", default-features = false, features = ["deflate"] }
Expand All @@ -47,17 +47,17 @@ zip = { version = "4.3", default-features = false, features = ["bzip2"] }
android_logger = {version = "0.15.1", optional = true}



[build-dependencies]
bitflags = "2.6"
error-chain = "0.12.4"
[target.'cfg(target_family = "wasm")'.build-dependencies]
zip = { version = "4.3", default-features = false, features = ["deflate"] }
[target.'cfg(not(target_family = "wasm"))'.build-dependencies]
zip = { version = "4.3", default-features = false, features = ["bzip2"] }
bindgen = "0.64.0"

[lib]
name = "libmathcat"
name = "mathcat"
crate-type = ["rlib", "cdylib"]

[profile.test]
Expand Down
13 changes: 1 addition & 12 deletions src/chemistry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,18 +606,7 @@ fn is_changed_after_unmarking_chemistry(mathml: Element) -> bool {
} else {
let mut answer = false;
for child in mathml.children() {
let child = as_element(child);
if name(child) == "mtd" {
assert_eq!(child.children().len(), 1);
// let mtd_child = as_element(child.children()[0]);
// if mtd_child.attribute(CHEM_FORMULA).is_none() && mtd_child.attribute(CHEM_EQUATION).is_none() {
// } else {

// }
answer = true;
} else {
answer |= is_changed_after_unmarking_chemistry(child);
}
answer |= is_changed_after_unmarking_chemistry(as_element(child));
}
if name(mathml) == "mrow" {
if let Some(changed_value) = mathml.attribute_value(CHANGED_ATTR) {
Expand Down
62 changes: 62 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ mod chemistry;

pub mod shim_filesystem; // really just for override_file_for_debugging_rules, but the config seems to throw it off
pub use interface::*;
use std::convert::TryInto;
use ext_php_rs::builders::ModuleBuilder;
use ext_php_rs::prelude::*;

#[cfg(test)]
pub fn init_logger() {
Expand Down Expand Up @@ -124,3 +127,62 @@ pub fn are_strs_canonically_equal(test: &str, target: &str) -> bool {
return are_strs_canonically_equal_with_locale(test, target, ", \u{00A0}\u{202F}", ".");
}

#[php_function]
pub fn mathcat_set_rules_dir(dir: String) {
let _ = set_rules_dir(dir);
}

#[php_function]
pub fn mathcat_set_mathml(mathml_str: String) -> Option<String> {
let result = set_mathml(mathml_str);
let return_val = match result {
Ok(val) => Some(val),
Err(error) => {
php_println!("Problem with the mathml: {:?}", error);
return None;
}
};
return return_val;
}

#[php_function]
pub fn mathcat_get_spoken_text() -> Option<String> {
let result = get_spoken_text();
let return_val = match result {
Ok(val) => Some(val),
Err(error) => {
php_println!("Problem with generating text: {:?}", error);
return None;
}
};
return return_val;
}

#[php_function]
pub fn mathcat_get_overview_text() -> Option<String> {
let result = get_overview_text();
let return_val = match result {
Ok(val) => Some(val),
Err(error) => {
php_println!("Problem with generating text: {:?}", error);
return None;
}
};
return return_val;
}

#[php_function]
pub fn mathcat_set_preference(name: String, value: String) {
let _ = set_preference(name, value);
}

#[php_module]
pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
module
.function(wrap_function!(mathcat_set_rules_dir))
.function(wrap_function!(mathcat_set_mathml))
.function(wrap_function!(mathcat_get_spoken_text))
.function(wrap_function!(mathcat_get_overview_text))
.function(wrap_function!(mathcat_set_preference))
}