# Syntax Highlighting for Mathematica on a Blog

Every once in a while I want to paste Mathematica code on my blog. When I do, I would like it to be somewhat readable, and it would be nice to have syntax highlighting. So far all my searches have turned up with nothing. There are plenty of ways to colorize pretty much every language known to man, except perhaps Mathematica code. See this site, for example. The closest I've gotten to that is using :TOhtml in vim, which is pretty awesome, but gives me a whole HTML file, with and everything, and I'm not savvy enough to figure out exactly how to use it without destroying the rest of my post.

-
You might want to see this, by our very own halirutan. – J. M. Oct 27 '12 at 15:57
Can you add details to you question, what blog-software you use? Are you having a server and full access to the data or do you use any ready to use installation? – halirutan Oct 27 '12 at 22:33
I'm asking for blogger, so I don't really have full control over the server, but I can run remote formatting scripts and whatnot. – vlsd Oct 28 '12 at 1:23

When you're writing a blog, then I assume you take some content management system like Joomla because otherwise a blog is maybe to hard to keep up-to-date in pure html. I have personal experience with Joomla and know, that code-highlighting as described below works great.

As mentioned by J.M. we have worked and tested hard to get a highlighter running for this site. What we did is to write a plug-in for the famous google code prettify. Please read the discussion here.

Therefore, the only thing you have to do is to setup google code prettify for your blog and add our language extension for Mathematica code lang-mma.js into the language files folder. Then you replace (you can of course adjust the colors for your site) the prettify stylesheet with prettify-mma.css.

Look around on this site. All code you see here is highlighted using this plug-in.

-
I will give all this a try. I knew a prettify plugin for Mathematica existed, but I had a lot of trouble finding it. For now, a quick an dirty solution I found works quite well is to use hilite.me and use OCaml as the language. – vlsd Oct 28 '12 at 1:25
Actually, it turns out google code prettify supports Caml style languages. I ended up using <code class="lang-ml"></code> tags around my code and that did the trick. – vlsd Nov 25 '12 at 3:04
@VladSeghete But you do realize that we (1) highlight all built-in functions and symbols, (2) support basic highlighting of patterns and (3) parse all styles of Mathematica numbers like 1.233`?? – halirutan Nov 25 '12 at 3:35
definitely, using lang-ml is just a hack, but it doesn't require anything extra to install on the server. I'll have to look into how to get blogger to see the lang-mms file when I get a chance, but my main gripe (highlighting the comments) is fixed. – vlsd Nov 26 '12 at 19:51
THANKS A LOT! It works GREAT on my wordpress site! – Silvia May 7 '13 at 20:09