When some LaTeX fragments in a buffer already have cached previews and
others need to be compiled, the first compiled fragment that follows a
cached fragment with the same colours is rendered without any colour
command. With dvisvgm it comes out black (no fill='currentColor'),
while all other previews follow the theme's foreground.
Versions:
- Org main, commit f38ac21c2 (2026-10-18)
- Emacs 32.0.50, dvisvgm 3.6
- org-latex-preview-process-default: dvisvgm, :foreground auto
Steps to reproduce:
1. Use a dark theme (so black is visibly wrong).
2. In an Org buffer, write two inline fragments in the same paragraph:
$a+b$ and $\frac{c}{d}$
3. Preview the buffer (C-u C-u C-c C-x C-l). Both are in the theme colour.
4. Edit the second fragment (e.g. change d to e) and preview again.
5. The re-rendered second fragment is black. Its SVG in the cache has
no fill group; the first fragment's SVG has fill='currentColor'.
Cause:
In `org-latex-preview-place', each fragment gets :continue-color when
its fg/bg equal those of the previous fragment, and
`org-latex-preview--tex-styled' then omits \color[rgb]{...} and
\special{dvisvgm:currentcolor on}. But prev-fg/prev-bg are updated for
every fragment, including those whose images are found in the cache.
Cached fragments are not written to the .tex file, so the first
fragment that is compiled after a cached one relies on a colour that
was never set in that file.
(if-let* ((path-info (org-latex-preview--get-cached hash)))
(org-latex-preview--update-overlay ...)
(unless (org-latex-preview--empty-fragment-p value)
(push ... fragment-info)))
(setq prev-fg fg prev-bg bg) ; <- also runs for cached fragments
The same pattern is in `org-latex-preview-cache-images', where
(setq prev-fg fg prev-bg bg) runs after (unless
(org-latex-preview--get-cached hash) ...).
Suggested fix: only update prev-fg/prev-bg when the fragment is
actually added to fragment-info, i.e. move the setq inside the branch
that pushes the fragment, in both functions. For example, in
`org-latex-preview-place':
- (if-let* ((path-info (org-latex-preview--get-cached hash)))
- (org-latex-preview--update-overlay
- (org-latex-preview--ensure-overlay beg end)
- path-info)
- (unless (org-latex-preview--empty-fragment-p value)
- (push (list :string (org-latex-preview--tex-styled
- processing-type value options)
- :overlay (org-latex-preview--ensure-overlay beg
end)
- :key hash)
- fragment-info)))
- (setq prev-fg fg prev-bg bg))))
+ (if-let* ((path-info (org-latex-preview--get-cached hash)))
+ (org-latex-preview--update-overlay
+ (org-latex-preview--ensure-overlay beg end)
+ path-info)
+ (unless (org-latex-preview--empty-fragment-p value)
+ (push (list :string (org-latex-preview--tex-styled
+ processing-type value options)
+ :overlay (org-latex-preview--ensure-overlay beg
end)
+ :key hash)
+ fragment-info)
+ (setq prev-fg fg prev-bg bg))))))
Workaround: advise `org-latex-preview--tex-styled' to always pass
:continue-color nil, then run `org-latex-preview-clear-cache'.
Vikas