Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Fix TUI math rendering for zero and big wedge expressions (#48551)

Eric Traut7b7d934408e6
diff --git a/codex-rs/tui/src/markdown_render/math.rs b/codex-rs/tui/src/markdown_render/math.rs
index fc012aec1e..fbd53ccc91 100644
--- a/codex-rs/tui/src/markdown_render/math.rs
+++ b/codex-rs/tui/src/markdown_render/math.rs
@@ -213,7 +213,8 @@ impl<'a> MathMarkdown<'a> {
{
continue;
}
- if formula.starts_with(|ch: char| ch.is_ascii_digit())
+ if formula != "0"
+ && formula.starts_with(|ch: char| ch.is_ascii_digit())
&& !formula.contains(['\\', '^', '_', '=', '+', '-', '*', '/', '<', '>'])
|| formula.len() > 1 && formula.chars().all(|ch| ch.is_ascii_uppercase())
{
diff --git a/codex-rs/tui/src/markdown_render/math/render.rs b/codex-rs/tui/src/markdown_render/math/render.rs
index 3897315423..85babcf334 100644
--- a/codex-rs/tui/src/markdown_render/math/render.rs
+++ b/codex-rs/tui/src/markdown_render/math/render.rs
@@ -222,7 +222,9 @@ impl MathParser<'_> {
let name = &self.remaining[..length];
self.remaining = &self.remaining[length..];
match name {
- "sum" if self.stack_annotations => self.display_sum(),
+ "sum" | "bigwedge" if self.stack_annotations => {
+ self.display_operator(if name == "sum" { "∑" } else { "⋀" })
+ }
"begin" | "boxed" | "underset" | "overset" | "substack" | "mathcal" => {
self.structured_command(name)
}
@@ -313,7 +315,7 @@ impl MathParser<'_> {
self.remaining = &self.remaining[end + 1..];
Some(Layout::text(text))
}
- "left" | "right" => {
+ "left" | "right" | "bigl" | "bigr" => {
self.remaining = self.remaining.trim_start();
match self.take()? {
'.' => Some(Layout::text("")),
@@ -443,6 +445,7 @@ fn symbol(name: &str) -> Option<&'static str> {
"cap" => "∩",
"bigcup" => "⋃",
"bigcap" => "⋂",
+ "bigwedge" => "⋀",
"setminus" => "∖",
"emptyset" | "varnothing" => "∅",
"land" | "wedge" => "∧",
diff --git a/codex-rs/tui/src/markdown_render/math/render/structured.rs b/codex-rs/tui/src/markdown_render/math/render/structured.rs
index 463f85d4d5..d012fa0501 100644
--- a/codex-rs/tui/src/markdown_render/math/render/structured.rs
+++ b/codex-rs/tui/src/markdown_render/math/render/structured.rs
@@ -1,7 +1,7 @@
//! Small, bounded layouts for aligned equations and common optimization notation.
//! Cell parsing shares the parent parser's depth budget and preserves nested groups.
//! Aligned blocks compose with surrounding math at their first row's baseline.
-//! Display annotations and sum limits are centered above or below their base.
+//! Display annotations and operator limits are centered above or below their base.
use super::Layout;
use super::MAX_COLUMNS;
@@ -48,7 +48,7 @@ impl MathParser<'_> {
argument
}
- pub(super) fn display_sum(&mut self) -> Option<Layout> {
+ pub(super) fn display_operator(&mut self, symbol: &str) -> Option<Layout> {
let mut lower = None;
let mut upper = None;
loop {
@@ -72,7 +72,7 @@ impl MathParser<'_> {
.max()
.unwrap_or(1)
.max(1);
- let mut base = Layout::text(format!("{:^width$}", "∑"));
+ let mut base = Layout::text(format!("{symbol:^width$}"));
if let Some(lower) = lower {
base = base.annotated(lower, AnnotationPosition::Below)?;
}
diff --git a/codex-rs/tui/src/markdown_render/math_display_tests.rs b/codex-rs/tui/src/markdown_render/math_display_tests.rs
index 64d4572928..12468788ac 100644
--- a/codex-rs/tui/src/markdown_render/math_display_tests.rs
+++ b/codex-rs/tui/src/markdown_render/math_display_tests.rs
@@ -56,6 +56,21 @@ $$\beta$$";
insta::assert_snapshot!(plain(source, /*width*/ 80));
}
+#[test]
+fn issue_48403_renders_zero_and_multiline_display() {
+ insta::assert_snapshot!(plain(
+ r"Inline math: $0$; inline operator: $\bigwedge_{j=0}^{n}$
+
+$$
+F_{n}(s)\land
+\bigwedge_{j=0}^{n}
+\bigl(R(\land T \bigr)
+\Rightarrow R.
+$$",
+ /*width*/ 80
+ ));
+}
+
#[test]
fn unicode_math_schrodinger_equation_snapshot() {
insta::assert_snapshot!(plain(
diff --git a/codex-rs/tui/src/markdown_render/snapshots/codex_tui__markdown_render__math__display_tests__issue_48403_renders_zero_and_multiline_display.snap b/codex-rs/tui/src/markdown_render/snapshots/codex_tui__markdown_render__math__display_tests__issue_48403_renders_zero_and_multiline_display.snap
new file mode 100644
index 0000000000..20c3784f32
--- /dev/null
+++ b/codex-rs/tui/src/markdown_render/snapshots/codex_tui__markdown_render__math__display_tests__issue_48403_renders_zero_and_multiline_display.snap
@@ -0,0 +1,10 @@
+---
+source: tui/src/markdown_render/math_display_tests.rs
+assertion_line: 61
+expression: "plain(r\"Inline math: $0$; inline operator: $\\bigwedge_{j=0}^{n}$\n\n$$\nF_{n}(s)\\land\n\\bigwedge_{j=0}^{n}\n\\bigl(R(\\land T \\bigr)\n\\Rightarrow R.\n$$\",\n80)"
+---
+Inline math: 0; inline operator: ⋀ⱼ₌₀ⁿ
+
+ n
+Fₙ(s)∧ ⋀ (R(∧ T ) ⇒ R.
+ j=0