Skip to content

Improve unsupported math fallback and scientific-unit guidance #278

Description

@yaacovcorcos

Problem

Model-generated scientific notation can contain a math-mode command inside a TeX text block, for example:

$$1.8\text{ \mu g/dL}$$

KaTeX rejects \mu in text mode. Scient then displays a code-styled fallback surrounded by manufactured $$ delimiters. The same fallback is used while loading and for render-boundary failures, so the visible result does not explain whether the source is unsupported, still loading, or failed for another reason.

Verified diagnosis

  • Direct KaTeX rendering with Scient's options rejects 1.8\text{ \mu g/dL} with Undefined control sequence: \mu.
  • The equivalent 1.8\,\mu\mathrm{g/dL} renders successfully.
  • The stored message source contained the unsupported form; this was not caused by RTL layout or by the Markdown recognizer.
  • renderScientTexToHtml returns null on the KaTeX error, and ScientMathLiteral supplies the generic fallback.

Relevant code:

  • apps/web/src/scient/math/katexRuntime.ts
  • apps/web/src/scient/math/ScientMath.tsx

Desired behavior

Unsupported TeX should remain readable and copyable, preserve its actual source and delimiter form, and be distinguishable from a temporary loading state. Scient's supported-format guidance should show valid scientific-unit notation.

Targeted scope

  • Preserve the original inline/display delimiter form in the fallback rather than always manufacturing $$.
  • Distinguish unsupported syntax from loading where that can be done without exposing internal errors in ordinary chat UI.
  • Add supported examples for scientific units such as 1.8\,\mu\mathrm{g/dL}.
  • Test inline and display math, streaming/loading, render errors, editing, and copying.

Non-goals

  • Do not regex-rewrite arbitrary TeX.
  • Do not silently move commands into or out of \text{...}.
  • Do not treat this malformed source as an RTL rendering defect.

Evidence limits

The renderer failure is deterministic in automated reproduction. Native visual behavior still needs manual review before closure.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRequested improvement or new capability.needs-triageIssue needs maintainer review and initial categorization.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions