Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

orgmode - change code block background color

Tags:

org-mode

Below code will change html export background color to #eff0fe:

#+ATTR_HTML: :style background-color:#eff0fe;
#+BEGIN_EXAMPLE
hello world!
#+END_EXAMPLE

like below: enter image description here

How can we change the background color when edit in emacs?

I saw Pretty fontification of source code blocks document but sounds like it doesn't work for me!

like image 811
lucky1928 Avatar asked Jun 28 '17 20:06

lucky1928


2 Answers

Another approach (which I think is more general) is explained in this page and I have copy-pasted the snippet here. It will only change the code block, and not the #+BEGIN, #+END, or #+RESULTS lines.

The example below will darken the code block by 3 percent (notice the number 3 at the last parameter) relative to the background color of your emacs theme. However, if you change your theme during editing the color of the code block will stay the same.

(require 'color)
(set-face-attribute 'org-block nil :background
                    (color-darken-name
                     (face-attribute 'default :background) 3))

Output using a light theme:

light

Output using a dark theme:

dark

You can modify further the code block color for individual programming language. The example below will modify the code block color for emacs-lisp and python.

(setq org-src-block-faces '(("emacs-lisp" (:background "#EEE2FF"))
                            ("python" (:background "#E5FFB8"))))
like image 168
Abang F. Avatar answered Oct 05 '22 12:10

Abang F.


Sounds like some face name changed, below config works:

(custom-set-faces
 '(org-block-begin-line
   ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF" :extend t))))
 '(org-block
   ((t (:background "#EFF0F1" :extend t))))
 '(org-block-end-line
   ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF" :extend t))))
 )

Output: enter image description here

like image 36
beetlej Avatar answered Oct 05 '22 11:10

beetlej