Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax highlighting within #+begin_src block in emacs orgmode not working

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?

like image 603
danske Avatar asked May 17 '12 20:05

danske


People also ask

What is syntax highlighting in idle?

Syntax highlighting is an important feature of any IDE that highlights the syntax of the language that you're working in. This helps you visually distinguish between the different Python constructs and the data used in your code. Python IDLE allows you to fully customize the appearance of your Python code.

How do you highlight syntax in VS code?

To solve this you can Cmd + Shift + P → "install Extensions" and look for the language you want to add, say "Scala". Find the suitable Syntax package, install it and reload. This will pick up the correct syntax for your files with the predefined extension, i.e. . scala in this case.

How do I turn on syntax highlighting?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

What does Github use for syntax highlighting?

We use Linguist to perform language detection and to select third-party grammars for syntax highlighting. You can find out which keywords are valid in the languages YAML file.


2 Answers

Do you have this?

(setq org-src-fontify-natively t) 
like image 156
bzg Avatar answered Oct 02 '22 00:10

bzg


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.
like image 25
UNagaswamy Avatar answered Oct 01 '22 22:10

UNagaswamy