10
$\begingroup$

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.

$\endgroup$
3
  • 2
    $\begingroup$ You might want to see this, by our very own halirutan. $\endgroup$ Commented Oct 27, 2012 at 15:57
  • $\begingroup$ 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? $\endgroup$
    – halirutan
    Commented Oct 27, 2012 at 22:33
  • $\begingroup$ 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. $\endgroup$
    – vlsd
    Commented Oct 28, 2012 at 1:23

1 Answer 1

16
$\begingroup$

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.

$\endgroup$
12
  • $\begingroup$ 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. $\endgroup$
    – vlsd
    Commented Oct 28, 2012 at 1:25
  • $\begingroup$ 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. $\endgroup$
    – vlsd
    Commented Nov 25, 2012 at 3:04
  • 2
    $\begingroup$ @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.23`3?? $\endgroup$
    – halirutan
    Commented Nov 25, 2012 at 3:35
  • $\begingroup$ 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. $\endgroup$
    – vlsd
    Commented Nov 26, 2012 at 19:51
  • $\begingroup$ THANKS A LOT! It works GREAT on my wordpress site! $\endgroup$
    – Silvia
    Commented May 7, 2013 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.