tex2typst_with_macros

Function tex2typst_with_macros 

Source
pub fn tex2typst_with_macros(
    tex: &str,
    macro_definitions: &str,
) -> Result<String, String>
Expand description

Converts a given TeX string to a Typst string with custom macro definitions.

This function takes a TeX string and a string containing macro definitions as input, tokenizes the TeX string, parses the custom macros, registers them, expands the macros, parses the expanded tokens into a TeX tree, converts the TeX tree to a Typst tree, serializes the Typst tree, and returns the resulting Typst string.

§Arguments

  • tex - A string slice that holds the TeX input.
  • macro_definitions - A string slice that holds the custom macro definitions.

§Returns

  • Result<String, String> - On success, returns the Typst string wrapped in Ok. On failure, returns an error message wrapped in Err.

§Errors

This function will return an error if the tokenization, macro parsing, macro expansion, TeX parsing, conversion, or serialization fails.

§Example

use tex2typst_rs::tex2typst_with_macros;
let tex_input = r"\foo";
let macro_definitions = r"\newcommand{\foo}{bar}";
let typst_output = tex2typst_with_macros(tex_input, macro_definitions).unwrap();
println!("{}", typst_output);