this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add a new function `tex2typst_with_macros()`

Signed-off-by: Jamie Moriarty <jamiemoriarty@qq.com>

+28 -1
+9
src/lib.rs
··· 46 46 Ok(typst) 47 47 } 48 48 49 + pub fn tex2typst_with_macros(tex: &str, custom_macros: &HashMap<String, String>) -> Result<String, String> { 50 + let tex_tree = tex_parser::parse_tex(tex, custom_macros)?; 51 + let typst_tree = converter::convert_tree(&tex_tree)?; 52 + let mut writer = typst_writer::TypstWriter::new(); 53 + writer.serialize(&typst_tree)?; 54 + let typst = writer.finalize()?; 55 + Ok(typst) 56 + } 57 + 49 58 /// Converts a given input string containing TeX math expressions to Typst format. 50 59 /// 51 60 /// This function searches for inline and display math expressions within the input string,
+19 -1
src/tests.rs
··· 3 3 #[cfg(test)] 4 4 mod tests { 5 5 use std::collections::HashMap; 6 - use crate::{converter, tex2typst, tex_parser, text_and_tex2typst, typst_writer}; 6 + use std::error::Error; 7 + use std::result; 8 + use crate::{converter, tex2typst, tex2typst_with_macros, tex_parser, text_and_tex2typst, typst_writer}; 7 9 8 10 #[test] 9 11 fn simple_test() { ··· 41 43 let typst = text_and_tex2typst(tex).unwrap_or_else(|e| format!("Error: {}", e)); 42 44 println!("{}", &typst); 43 45 Ok(()) 46 + } 47 + 48 + #[test] 49 + fn test_macros() { 50 + let tex = r"\d^2"; 51 + let mut custom_macros = HashMap::new(); 52 + custom_macros.insert(r"\d".to_string(), r"\partial".to_string()); 53 + let result = tex2typst_with_macros(tex, &custom_macros).unwrap_or_else(|e| format!("Error: {}", e)); 54 + println!("{}", result); 55 + } 56 + 57 + #[test] 58 + fn test_floor() { 59 + let tex = r"\left\lfloor \frac{a}{b} \right\rfloor \floor{\frac{a}{b}}"; 60 + let result = tex2typst(tex).unwrap(); 61 + println!("{}", result); 44 62 } 45 63 46 64 #[test]