Org LaTeX preview background face
andreyorst opened this issue · 11 comments
This is what I am currently what I'm using to get around the issue with latex previews:
(defun +org-update-latex-preview-background-color (&rest _)
(setq-default
org-format-latex-options
(plist-put org-format-latex-options
:background
(face-attribute (or (cadr (assq 'default face-remapping-alist))
'default)
:background nil t))))
(advice-add #'load-theme :after #'+org-update-latex-preview-background-color)
I'm not sure about transparent images, however. I'll look into that.
This works for LaTeX indeed. Can I hook it with Solaire and not with load-theme
somehow? I don't see solaire-mode-hook
or something like that.
There is a solaire-mode-hook
(they're implicitly defined for all minor modes -- and well-behaved major-modes).
(add-hook 'solaire-mode-hook #'+org-update-latex-preview-background-color)
With this hook it works fine. Thanks. Now only transparent images need to be configured. It's not high priority though as I rarely use them.
This is not working with mixed-pitch-mode
. For eg., if i have this in my config.el
(setq doom-variable-pitch-font (font-spec :family "ETBembo" :size 13))
Then, when i load an org file, and enable mixed-pitch-mode, and then solaire-mode, i get the following error:
face-attribute: Invalid face: :family, "ETBembo", :height, 130
This is because with mixed-pitch-mode
, (assq 'default face-remapping-alist)
returns (default (:family "ETBembo" :height 130) variable-pitch default)
I've used this function to fix the color of transparent backgrounds of images in org mode:
(defun aorst/create-image-with-background-color (args)
"Specify background color of Org-mode inline image through modify `ARGS'."
(let* ((file (car args))
(type (cadr args))
(data-p (caddr args))
(props (cdddr args)))
;; get this return result style from `create-image'
(append (list file type data-p)
(list :background (face-attribute (or (cadr (assq 'default face-remapping-alist))
'default)
:background nil t))
props)))
(advice-add 'create-image :filter-args #'aorst/create-image-with-background-color)
Taken from this SO answer
This is not working with
mixed-pitch-mode
. For eg., if i have this in my config.el
(setq doom-variable-pitch-font (font-spec :family "ETBembo" :size 13))
Then, when i load an org file, and enable mixed-pitch-mode, and then solaire-mode, i get the following error:
face-attribute: Invalid face: :family, "ETBembo", :height, 130
This is because with
mixed-pitch-mode
,(assq 'default face-remapping-alist)
returns(default (:family "ETBembo" :height 130) variable-pitch default)
I've fixed this for my image function by checking if we extract face:
(defun aorst/create-image-with-background-color (args)
"Specify background color of inline image by modifing ARGS."
(apply (lambda (file type data-p &rest props)
(append (list file type data-p)
(list :background (face-attribute
(let ((face (cadr (assq 'default face-remapping-alist))))
(if (facep face) face 'default))
:background nil t))
props))
args))
(advice-add 'create-image :filter-args #'aorst/create-image-with-background-color)
This way, if you use some modes, like text-scale-mode
you'll at least get images without errors, though with incorrect background color. If you have further Ideas how to avoid this error, I'd like to hear. I've thought also about memoizing color, but this will not work as reliable as detection.
Sorry for the tremendously late reply. As of f3c7213 this should be fixed. Please unpin then update solaire-mode and let me know if that isn't the case and I'll reopen this. Thanks for your help and input!
Sorry for the tremendously late reply.
No worries! Everything seems to work great!