Skip to content

Conversation

@sei40kr
Copy link

@sei40kr sei40kr commented Dec 27, 2025

Description

Improves anti-aliasing quality for LaTeX math expressions on both light and dark backgrounds by using background-aware rendering during ImageMagick conversion.

Previously, LaTeX math was rendered with a transparent background, causing ImageMagick to default to white for anti-aliasing. This created white halos around math expressions on dark backgrounds.

The fix uses fixed background colors (#ffffff for light, #000000 for dark) based on vim.o.background, then makes the background transparent after proper anti-aliasing is applied.

Related Issue(s)

Screenshots

before:

after:

@github-actions github-actions bot added image size/s Small PR (<10 lines changed) labels Dec 27, 2025
Use fixed background colors (#ffffff for light, #000000 for dark) when
rendering LaTeX math to improve anti-aliasing quality. The background
is later made transparent via ImageMagick's -transparent option.

This eliminates white halos on dark backgrounds while maintaining cache
reusability across different themes (only 2 cache variants: light/dark).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@sei40kr sei40kr force-pushed the fix/math-antialiasing-2644 branch from e73f676 to 422f380 Compare December 28, 2025 05:34
@github-actions github-actions bot added docs size/m Medium PR (<50 lines changed) labels Dec 28, 2025
@sei40kr
Copy link
Author

sei40kr commented Dec 28, 2025

  • It is unclear why anti-aliasing processing assuming a white background occurs even when the background is made transparent.
  • If you don't mind the reusability of the image cache,
    convert = {
      magick = {
        math = function()
          local bgcolor = Snacks.util.color("Normal", "bg")
          -- stylua: ignore start
          return {
            "-density", 192,
            "-background", bgcolor,
            "{src}[{page}]",
            "-flatten",
            "-fuzz", "2%",
            "-transparent", bgcolor,
            "-trim",
          }
          -- stylua: ignore end
        end,
      },
    },
    yields better results.

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

Labels

docs image size/m Medium PR (<50 lines changed) size/s Small PR (<10 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: LaTeX math expressions have white halos on dark backgrounds

1 participant