Skip to content

fix(latex): render unbraced greek sub/sup symbols#475

Closed
tianbaiting wants to merge 1 commit intoOXY2DEV:mainfrom
tianbaiting:fix/latex-unbraced-greek-subsuperscripts
Closed

fix(latex): render unbraced greek sub/sup symbols#475
tianbaiting wants to merge 1 commit intoOXY2DEV:mainfrom
tianbaiting:fix/latex-unbraced-greek-subsuperscripts

Conversation

@tianbaiting
Copy link

@tianbaiting tianbaiting commented Mar 7, 2026

Summary

  • normalize unbraced sub/sup style-symbol lookups so _\alpha and ^\alpha resolve through the existing subscript/superscript glyph maps
  • fall back to regular symbol glyphs for unbraced style-symbols when no dedicated Unicode sub/sup form exists, so cases like _\delta and _\theta still render as symbols instead of raw TeX
  • derive parser fake-preview allowlists from markview.symbols.entries to keep parser and renderer behavior aligned
  • add regression examples for unbraced and braced greek sub/sup forms in test/latex.md

Reproduction

Before this change, plain \alpha rendered correctly, but unbraced forms such as q_\alpha and q^\alpha stayed as raw TeX in Markview preview. The same issue affected other greek symbol commands in unbraced sub/sup form.

Verification

  • headless render check now emits for _\alpha, δ for _\delta, and θ for _\theta
  • headless render check now emits for ^\alpha, for ^\delta, and ᶿ for ^\theta
  • braced forms _{\alpha} and ^{\alpha} still render correctly

Copilot AI review requested due to automatic review settings March 7, 2026 09:31
@tianbaiting tianbaiting force-pushed the fix/latex-unbraced-greek-subsuperscripts branch from aab16de to 32c619f Compare March 7, 2026 09:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Markview’s LaTeX preview rendering so unbraced Greek subscript/superscript forms (e.g. _\alpha, ^\alpha) resolve through the existing subscript/superscript glyph maps, avoiding raw-TeX fallback in previews.

Changes:

  • Normalize unbraced sub/sup symbol lookups in the LaTeX renderer so _\alpha / ^\alpha map to / .
  • Derive parser fake-preview allowlists from markview.symbols.subscripts / markview.symbols.superscripts to reduce parser/renderer drift.
  • Add regression examples covering unbraced and braced Greek sub/sup usage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/latex.md Adds regression examples for unbraced/braced Greek sub/superscripts and a mixed expression.
lua/markview/renderers/latex.lua Normalizes unbraced sub/sup keys (e.g. strips leading \) before glyph-map lookup.
lua/markview/parsers/latex.lua Generates supported “fake preview” command allowlists directly from the glyph maps.
Comments suppressed due to low confidence (2)

lua/markview/parsers/latex.lua:327

  • supported_symbols is rebuilt (including iterating + sorting) on every subscript capture. Since markview.symbols.subscripts is effectively static, consider computing/caching the command list once at module scope (or memoizing per map) to avoid repeated work during parsing large documents.
---@param range markview.parsed.range
latex.subscript = function (_, TSNode, text, range)

lua/markview/parsers/latex.lua:366

  • supported_symbols is rebuilt (including iterating + sorting) on every superscript capture. Since markview.symbols.superscripts is effectively static, consider computing/caching the command list once at module scope (or memoizing per map) to reduce repeated work during parsing.
---@param range markview.parsed.range
latex.superscript = function (_, TSNode, text, range)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@OXY2DEV
Copy link
Owner

OXY2DEV commented Mar 7, 2026

@tianbaiting Sir, did you actually read what the original code did?

The whole reason a SUPPORTED_SYMBOLS table exists is so that an unsupported symbol can be shown as ↑(<symbol>)/↓(<symbol>) instead of breaking style of text that can be shown as superscript/subscript text.

I also don't understand why you bothered adding a new function to check for supported symbols. You could've simply removed the original piece of code and it should've been enough.

@tianbaiting
Copy link
Author

You're right — I expanded the fix too far and changed the intended role of SUPPORTED_SYMBOLS.
I misunderstood that table as just a preview allowlist, while it actually also preserves the fallback behavior for unsupported symbols.

The real bug is narrower: for unbraced forms like _\alpha / ^\alpha, the renderer strips _ / ^ but still keeps the leading backslash, so it looks up "\alpha" instead of "alpha" in symbols.subscripts / symbols.superscripts.

@OXY2DEV
Copy link
Owner

OXY2DEV commented Mar 7, 2026

@tianbaiting I have added direct support for symbols inside subscript/superscript(for some reason it is parsed differently to normal symbols). It should now fix all edge cases.

@OXY2DEV
Copy link
Owner

OXY2DEV commented Mar 7, 2026

The real bug is narrower: for unbraced forms like _\alpha / ^\alpha, the renderer strips _ / ^ but still keeps the leading backslash, so it looks up "\alpha" instead of "alpha" in symbols.subscripts / symbols.superscripts.

Fixing this by itself isn't enough btw(cause the function needs to register a style region which is used for symbol lookup). But the commit I made also carries additional changes to make it work correctly.

@tianbaiting
Copy link
Author

Thanks for the fix!

And thanks for the explanation about the style-region registration and symbol lookup — that helped me understand the rendering pipeline better.

I also realized that more complex subscripts like \mu_{\text{pair}} probably can't be rendered cleanly with Unicode alone, since there isn't a full set of subscript glyphs for arbitrary text.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants