text_and_tex2typst_with_macros

Function text_and_tex2typst_with_macros 

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

Converts a given input string containing TeX math expressions to Typst format with custom macro definitions.

This function searches for inline and display math expressions within the input string, converts them to Typst format using the tex2typst_with_macros function, and returns the resulting string.

§Arguments

  • input - A string slice that holds the input text containing TeX math expressions.
  • macro_definitions - A string slice that holds the custom macro definitions.

§Returns

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

§Errors

This function will return an error if the TeX to Typst conversion fails.

§Example

use tex2typst_rs::text_and_tex2typst_with_macros;
let input = r"This is inline math: \(\foo\) and this is display math: \[\foo\]";
let macro_definitions = r"\newcommand{\foo}{bar}";
let output = text_and_tex2typst_with_macros(input, macro_definitions).unwrap();
println!("{}", output);