Skip to content

Keep scientific measurements coherent in mixed RTL content #280

Description

@yaacovcorcos

Problem

In mixed Hebrew/English scientific content, a value and its unit can appear in an unintuitive visual order when only the number is authored as math:

ירידה של \(12.8\) mm Hg

The number is an isolated left-to-right math node, while mm Hg remains sibling prose inside an RTL sentence. The unit's internal order stays correct, but the unit can appear on the opposite side of the value from the intended complete measurement.

Verified diagnosis

  • The source separates the number and unit at the math boundary.
  • ScientMathHtml applies dir="ltr" to the math node, and the bidi stylesheet isolates it.
  • The following unit remains part of the surrounding prose direction.
  • The equivalent complete measurement \(12.8\,\mathrm{mm\,Hg}\) provides the intended semantic grouping.
  • This is independent of rejected dollar-math recognition and KaTeX failure.

Relevant code:

  • apps/web/src/scient/math/ScientMath.tsx
  • apps/web/src/scient/presentation/scient-bidi.css
  • apps/web/src/scient/presentation/rehypeScientBidi.ts

Desired behavior

Hebrew prose should remain RTL while complete scientific measurements, comparisons, and similar opposite-direction phrases retain their intended internal order and attachment. Copying and accessibility reading order must remain faithful to source.

Investigation and smallest safe scope

  • Build a source/render corpus for numbers plus units, comparisons, ranges, percentages, arrows, Latin identifiers, punctuation, tables, lists, and ordinary LTR paragraphs.
  • Determine which examples are correctly solved by authoring the complete expression inside math and which reveal a product-level bidi defect.
  • Document complete-expression authoring immediately.
  • Only add renderer behavior if a bounded semantic rule can be defined without guessing arbitrary Latin suffixes or rewriting source.

Non-goals

  • Do not remove math isolation globally.
  • Do not attach arbitrary following Latin words to math.
  • Do not guess units from a medical-only allowlist.
  • Do not treat column alignment as semantic grouping.

Validation

Verify visual order manually in RTL and LTR, plus source preservation, selection copy, message copy, editor round trips, keyboard selection, and accessibility reading order.

Related: the broader comparison/direction-symbol RTL finding currently tracked as DF-019 in the Scient planning inbox.

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