Latex Transparent Preview

I believe most of people who use org-roam as their go to knowledge management tool would have particular setting regarding latex setup.
I am trying to achieve a transparent latex preview in org buffers.
I hate the fact latex code renders like this

I would like to configure it like this. I did find a way to set the background of org-latex-format option to my background color scheme but whenever I restarted it is overwritten by the theme default color.
I am complete noob when it comes to emacs or elisp, would like if some one could help with it or share their latex configuration for org-roam.
Thanks

I am using doom emacs with spacemacs light theme.
with these lines added to my config.el

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won’t work right.
'(org-format-latex-options
(quote
(:foreground default :background “#efeae9” :scale 1.5 :html-foreground “Black” :html-background “Transparent” :html-scale 1.0 :matchers
(“begin” “1" "” “$$” “\(” “\[”))))

@noe,
I no longer use Doom. I’ll let Doom users to step in.

Don’t use customize with Doom. I think Doom “tucks” your customizing away in a special file for you (I believe it’s ~/.emacs.d/.local/custom.el by default), and I believe it disables it for you automatically.

This is by design, and is because Doom wants you to use :custom option in its own variation of use-package, use-package! (note the “!” at the end).

So… Two options.

Put setq somewhere after your org setting in your config.el.

(setq org-format-latex-options
  (quote (:foreground default :background “#efeae9” :scale 1.5 :html-foreground “Black” :html-background “Transparent” :html-scale 1.0 :matchers
             (“begin” “1" "” “$$” “\(” “\[”))))

Alternatively, something like this:

(use-package! org
              :custom
               (setq org-format-latex-options
                 (quote
                  (:foreground default
                   :background “#efeae9”
                   :scale 1.5 :html-foreground “Black”
                   :html-background “Transparent”
                   :html-scale 1.0
                   :matchers (“begin” “1" "” “$$” “\(” “\[”)))))

I think org-format-latex-options can be in your :config part, instead of :custom.

Hopefully one of these works for you.

Thank you @nobiot for writing, I have tried both option but background property does not change when I look up in emacs using customize group.
I have also tried

(after! org-latex
(setq org-format-latex-options
(quote
(:foreground default :background auto :scale 1.5 :html-foreground “Black” :html-scale 1.0 :matchers
(“begin” “$1” “$” “$$” “\(” “\[”)))))
but it doesn’t.

The org-latex-format-option transparent is always set to spacemacs light theme default face color.
I have cleared the cache of latex images as well.

I misunderstood that this is what you would like to do from the code snippet, but that’s not what you are going for…Then, I am afraid I don’t understand what you wish to achieve.

In the part quoted below, you seem to want to overwrite something when something happens. Sorry not clear to me. I’ll let someone else to jump in and help you. I don’t use org-latex; that’s probably why I don’t understand your wish.

a way to set the background of org-latex-format option to my background color scheme but whenever I restarted it is overwritten by the theme default color.

By the way, this is probably correct behaviour. You are using Doom. I don’t believe you are encouraged to use customize group. setq does not affect what you see in customize group (it might say something like “value changed ouside customising”); it’s a different way to set variables.

I would like to have something like this. This I achieved using customize group and setting org-latex-format to theme background. so the image generated from latex matches with my theme color. I can’t get this change to be reflected permanently in emacs. Even if I set the variable in config, it somehow resets to theme default color.

:custom keyword within use-package! should do what customize group does. if this does not happen, try :init keyword. I think it is Doom that removes your changes you did in customize group.

Also, if this didn’t do what you wanted, I surmise that org-format-latex-options need to be set before org-latex, not after. Did you try removing this after! part?

Yes i tried it but it didn’t work. I also tried to run the code after the theme is loaded via hook but that also didn’t work. I’ll further explore how doom emacs load things. Thank you for your help. I’ll update if i got this working.

And you say you checked that the first two options didn’t work by looking at customizing group. I assume you also saw the actual note and latex to come to that conclusion (?).

Tricky, this issue…

@noe

I think I was incorretly using :custom option.

use-package documentation has this below

(use-package comint
  :custom
  (comint-buffer-maximum-size 20000 "Increase comint buffer size.")
  (comint-prompt-read-only t "Make the prompt read only."))

So… the code snippet above, probably, should have been without setq (setq can change the loading order, I think):

(use-package! org
              :custom
               (org-format-latex-options
                 (quote
                  (:foreground default
                   :background “#efeae9”
                   :scale 1.5 :html-foreground “Black”
                   :html-background “Transparent”
                   :html-scale 1.0
                   :matchers (“begin” “1" "” “$” “\(” “\[”)))))

One thing I struggled with was setting it up so that the background is truly transparent - not just that the Latex image has background color matching the theme’s background. This makes a difference when you have different types of background colors. For example,

  1. Some nice themes like Leuven highlight different header levels with different background colors to make them stand out
  2. hl-line-mode slightly highlights the current line which is very useful to keep track of your location.

In these cases, the Latex inline image will still have a background color that doesn’t match the snippet’s actual background. I’m very interested to find a solution but it doesn’t appear to be possible as far as I can tell.

Thanks for pitching in. You are right about it, just a temporary solution I found is changing the theme to “modus-operandi”.Without any changes latex renders renders nicely as background.
example.

Currently, I use emacs primarly for note taking but I guess this wont blend nicely with other program eg. org-adenda .