codex icon indicating copy to clipboard operation
codex copied to clipboard

[TUI math] Support underbrace annotations in display formulas

Open Seeker0472 opened this issue 2 weeks ago • 2 comments

What variant of Codex are you using?

Codex CLI / TUI, codex-cli 0.167.2 on Linux (Nix-managed installation).

What feature would you like to see?

Support display-math annotations of the form \underbrace{expression}_{label} in the terminal math renderer, where the expression and label fit within the available terminal width.

This is a request to extend the existing limited TeX renderer, not to add full LaTeX support. Underbraces are useful for identifying clauses, terms, and subexpressions in technical explanations.

Example

Have the assistant output the following display math without a code fence:

\[
\varphi=
\underbrace{(x\lor y\lor z)}_{C_1}
\land
\underbrace{(\neg x\lor y\lor\neg z)}_{C_2}
\land
\underbrace{(x\lor\neg y\lor z)}_{C_3}
\]

A smaller example for implementation/testing is:

\[
\underbrace{x+y}_{C_1}
\]

Current behavior and evidence

The reporter encounters unrendered formula source in the terminal and supplied the first expression above. Source inspection of rust-v0.167.2 shows that \underbrace is not handled by the math renderer, although \varphi, \lor, \land, and \neg are supported. Unsupported expressions fall back to the original LaTeX.

This report is based on the user's observation and source inspection; the minimal example above has not been independently tested in a captured TUI session.

Relevant source: https://github.com/openai/codex/blob/rust-v0.167.2/codex-rs/tui/src/markdown_render/math/render.rs

Expected behavior

When feasible, show a terminal-friendly brace or another unambiguous grouping marker beneath the expression, with its label centered below it. Preserve the scope of each annotation. Continue preserving the original LaTeX when the expression is unsupported or cannot fit accurately.

Separating the clauses into definitions such as C₁ = (x ∨ y ∨ z) and then φ = C₁ ∧ C₂ ∧ C₃ works around the problem, but loses the convenient inline annotation of the original expression.

Related issues

  • #18906 — initial TUI math rendering request.
  • #57308 — extending the renderer for specific unsupported mathematical structures.

This request concerns Codex CLI/TUI, not ChatGPT web or iOS rendering.

Seeker0472 avatar Nov 16 '26 11:11 Seeker0472

I ran one offline, test-only check of the display renderer in a local Codex checkout at 8801b9a8a6c606508736d4e01dedabe52833d637. A focused codex-tui test for \underbrace{x+y}_{C_1} compiled and executed, then failed at render(..., MathMode::Display).expect(...): the renderer returned None. This confirms the missing display-renderer path in that checkout. I did not test a released TUI session or implement a fix.

For a bounded first implementation, could underbrace be display-only and consume its expression plus following _{label} as one command? A single-line expression could render as separate expression, scope-marker, and centered-label rows (for example x+y, └─┘, C₁), with adjacent annotations keeping distinct scopes. If the expression or label exceeds the existing row/column or terminal-width limits, preserving the original LaTeX seems safer. Inline, nested, and multiline forms could remain unsupported initially.

Would that limited geometry fit the TUI renderer's intended scope? The suggested layout and fallback cases are design proposals, not tested behavior.

TheOutlandsDev avatar Nov 17 '26 03:11 TheOutlandsDev

Thanks for the feature request. This will be addressed in an upcoming release.

etraut-openai avatar Nov 19 '26 19:11 etraut-openai