42

I have tried many different languages and copied various examples, but none of my code blocks within orgmode get syntax highlighting. Here is what I'm trying:

#+begin_src python

def main():
  print "Hello %s" % ("what's the problem")

#+end_src

#+begin_src c++

for (int i = 0; i < 30; i++) 
{
  cout << "Hello" << endl;
}

#+end_src

When exported to HTML, it shows up in a source code block, but with no highlighting there either.

I am using the newest org (7.8.10). Am I missing something here?

danske
  • 637
  • 1
  • 6
  • 11

2 Answers2

70

Do you have this?

(setq org-src-fontify-natively t)
bzg
  • 2,515
  • 17
  • 19
  • 6
    That was it, thanks. as far as HTML exporting, I added htmlize.el ([get it here](http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el.cgi)) to get colorizing in the CSS rules when exported from org-mode. – danske May 17 '12 at 22:00
  • I believe that in newer version of Emacs you can also use `M-x htmlfontify-buffer` instead of htmlize.el – vitaly Jan 15 '14 at 01:55
5

I had a similar problem where despite adding htmlize.el, I couldn't get the code syntax highlighting when exporting to html. I then found this very useful post and just followed the steps:

Syntax highlighting R code in WordPress using Emacs

Just to reiterate the steps:

  1. I copied the htmlize.el in ~/.emacs.d/ directory
  2. In org mode, typed M-x byte-compile-file and navigate to the directory where the htmlize.el is located, select it and press enter. This will compile the htmlize.el file.
  3. Restart emacs and export a file with code block in it. The exported html file will now have syntax highlighted code.
UNagaswamy
  • 2,068
  • 3
  • 30
  • 35