Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Fix math alignement ('&') when math contains non-ascii characters #150

Merged
merged 1 commit into from
Feb 10, 2024
Merged
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 src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(crate) fn format_math(parent: &LinkedNode, children: &[String], ctx: &mut Ct
&mut res,
);
ctx.push_raw_in(s, &mut res);
position = align_columns[index] + s.len();
position = align_columns[index] + s.chars().count();
index += 1;

first_align = false;
Expand All @@ -97,7 +97,7 @@ pub(crate) fn format_math(parent: &LinkedNode, children: &[String], ctx: &mut Ct
ctx.push_raw_in(" ", &mut res);
}
_ => {
position += s.len();
position += s.chars().count();
ctx.push_raw_in(s, &mut res)
}
}
Expand Down Expand Up @@ -142,7 +142,7 @@ fn retrieve_align_columns(parent: &LinkedNode, children: &[String]) -> Vec<usize
position += 1;
}
_ => {
position += s.len();
position += s.chars().count();
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/tests/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,14 @@ $
&= "an even longer string!!" & y
$"#
);

make_test!(
unicode_math_alignment,
r#"
$
α & := β & ("text") \
α & := b & ("text") \
a & ≠ β & ("text") \
a & ≠ b & ("text")
$"#
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/tests/math.rs
description: "INPUT\n===\n\"\\n$\\n α & := β & (\\\"text\\\") \\\\\\n α & := b & (\\\"text\\\") \\\\\\n a & ≠ β & (\\\"text\\\") \\\\\\n a & ≠ b & (\\\"text\\\")\\n$\"\n===\n\n$\n α & := β & (\"text\") \\\n α & := b & (\"text\") \\\n a & ≠ β & (\"text\") \\\n a & ≠ b & (\"text\")\n$\n===\nFORMATTED\n===\n\n$\n α & := β & (\"text\") \\\n α & := b & (\"text\") \\\n a & ≠ β & (\"text\") \\\n a & ≠ b & (\"text\")\n$"
expression: formatted
---
"\n$\n α & := β & (\"text\") \\\n α & := b & (\"text\") \\\n a & ≠ β & (\"text\") \\\n a & ≠ b & (\"text\")\n$"
Loading