lucky1928
lucky1928

Reputation: 8889

orgmode - change code block background color

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!

Upvotes: 10

Views: 6262

Answers (2)

Abang F.
Abang F.

Reputation: 916

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"))))

Upvotes: 14

user6018651
user6018651

Reputation:

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

Upvotes: 7

Related Questions