I saw this question: How to customize background color for some web pages opened with eww? but this won't work for me. I'm trying to read Wikipedia pages and in many places Wikipedia uses images to render mathematical formulae. When these have transparent background, the appear not to render acceptably (example below). So, I'd like to have white-ish background theme for eww, while keeping everything else with a dark-background theme.
2 Answers
Update:
load-theme-buffer-local.el
(GitHub repository) is supposed to do what I tried to do, but do it the right way.
To use it with eww
, install it and add
(add-hook 'eww-mode-hook
(lambda () (load-theme-buffer-local 'tango (current-buffer))))
to your init file.
PS: I cannot test this approach myself, so let me know if this works.
Original answer (kept just for the record):
You can use face-remap-add-relative
to set faces in the current buffer.
After a little bit of digging around I came up with this hack. It extracts face settings from a theme and applies them in the current buffer.
(defun set-theme-faces-in-buffer (theme)
"Use face remapping to set faces from a theme in the current
buffer. THEME should be a symbol."
(dolist (setting (get theme 'theme-settings))
(when (eq (car setting) 'theme-face)
(let ((face (nth 1 setting))
(spec (cadar (nth 3 setting))))
(ignore-errors
(apply #'face-remap-add-relative face spec))))))
You can combine this with an eww-mode-hook
to set a different theme in eww
buffers.
(add-hook 'eww-mode-hook
(lambda () (set-theme-faces-in-buffer 'tango)))
(Replace tango
with your favorite light theme.)
-
It sort of works for me. The backgrounds of those transparent png's still show the background from the previous theme. Looks like we'd need to disable the previous theme in the current buffer as well. How can I do that? Commented Dec 11, 2014 at 4:42
-
@kaushalmodi: After some more digging around I found
load-theme-buffer-local.el
, which should be much better than my hack. Give it a try! (I linked to it in the updated answer.) Commented Dec 11, 2014 at 6:18 -
@Constantine: unfortunately it has the same problem with transparent images Commented Feb 6, 2015 at 0:41
Alternatively, if you are comfortable with reading LaTeX markup, you might prefer to configure wikipedia to not use images for rendering math. This requires you to create a wikipedia account, then go to Preferences->Appearance->Math to select an option. I would recommend "Client-side MathJax", since this will render prettily in a browser that understands javascript, but will just show the LaTeX source in a browser like eww
that does not.
For instance, your page looks like this for me:
Perhaps in the future someone might adapt code from preview-latex
or org-preview-latex-fragment
to allow display of the formatted math in eww
in a way that is aware of the color scheme. (Or integrate a javascript interpreter!)
-
Maxima's Emacs binding kind of does it (it renders LaTeX in the colors of the current theme). I might look into how it does it to maybe incorporate that. Funny, I actually ended up doing both, (disabling the server-side rendering in Wikipedia) and adding a hook to
eww
, but I'm going to accept Constantine's question because it's more generic. Thank you though!– wvxvwCommented Dec 11, 2014 at 6:29
eww-mode