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
5 changes: 3 additions & 2 deletions crates/mitex/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,8 @@ pub fn convert_inner(
spec: Option<CommandSpec>,
do_parse: fn(input: &str, spec: CommandSpec) -> SyntaxNode,
) -> Result<String, String> {
let node = do_parse(input, spec.unwrap_or_else(|| DEFAULT_SPEC.clone()));
let spec = spec.unwrap_or_else(|| DEFAULT_SPEC.clone());
let node = do_parse(input, spec.clone());
// println!("{:#?}", node);
// println!("{:#?}", node.text());
let mut output = String::new();
Expand All @@ -1227,7 +1228,7 @@ pub fn convert_inner(
let repr = TypstRepr {
elem: LatexSyntaxElem::Node(node),
mode,
spec: DEFAULT_SPEC.clone(),
spec,
error: err.clone(),
};
core::fmt::write(&mut output, format_args!("{}", repr)).map_err(|_| err.borrow().to_owned())?;
Expand Down
9 changes: 9 additions & 0 deletions crates/mitex/tests/cvt/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,12 @@ fn test_fuzzing() {
assert_snapshot!(convert_math(r#"\left\0"#).unwrap_err(), @r###"error: unknown command: \0"###);
assert_snapshot!(convert_math(r#"\end{}"#).unwrap_err(), @r###"error: error unexpected: """###);
}

#[test]
fn test_convert_custom_spec_alias() {
use mitex::command_preludes::*;
let mut builder = SpecBuilder::default();
builder.add_command("partial", define_symbol("myd"));
let spec = builder.build();
assert_snapshot!(mitex_convert_math(r#"$\partial$"#, Some(spec)).unwrap(), @"myd ");
}