MATLAB language posts don't look good under google-code-prettify. As far as I understand from this post, MATLAB is currently highlighted by using the default language syntax.

For example, you can see this question. Since % is the standard in MATLAB to write comments, but it is not known, comments look weird.

However, it has an option to write a custom .js that defines a new language. I was thinking about writing myself a custom .js that will do the trick, but before I do that, I want to make sure that it will actually be used in Stack Overflow, and my effort is not in vain.

Is it possible to add custom google-code-prettify .js files to the server of Stack Overflow?

  • 4
    We do have custom prettify javascript for a few languages, TeX for one. Ideally it'd be contributed back to prettify. Feb 23 '12 at 18:47
  • I've been looking for a simple MATLAB highlighter but so far I've had no luck. Did you do your custom prettify? It would be nice if you post it somewhere if you did.
    – jmlopez
    Apr 6 '12 at 7:45
  • 2
    Don't forget Octave. Sep 13 '12 at 10:12
  • 7
    @KevinMontrose, it's been integrated into prettify. Could you look at updating the version used on Stack Overflow? Mar 6 '13 at 21:09
  • 2
    @KevinMontrose, over a year later, it has yet to be integrated on Stack Overflow. Is that a possibility, for us MatLab developpers?
    – Sifu
    Jul 25 '14 at 18:15
  • 1
    @KevinMontrose With the risk of being repetitive: This would be an awesome feature for the Matlab tag, that still doesn't have syntax highlight even if TeX has. And TeX is now off topic in stackoverflow... Jul 21 '15 at 10:09

Matlab syntax support is rolling in.

This is basic syntax support without keywords, as these add a lot to the size of the highlighter and do not gzip well at all.

Still - comments should be comments and basic highlighting should work as expected.

  • 6
    Wonderful news! Thanks you for taking the time to add the MATLAB support. I'll see if I can get the "Lite" version included upstream in google/code-prettify in addition to the regular version, that way it would be easier to pull changes in the future.
    – Amro
    May 20 '16 at 14:31
  • 4
    Thanks for writing it in the first place!
    – Oded
    May 20 '16 at 14:43
  • 3
    \o/ It's so working! All my posts suddenly became gorgeous!
    – Adriaan
    May 20 '16 at 15:59

Back in May 2012, I started a project hosted on GitHub that implements MATLAB syntax highlighting for google-code-prettify (released under the MIT License). See here for the initial announcement, plus there was some discussion in the MATLAB chat room.

It comes in two flavors, one that detects and stylize all core MATLAB functions (plus functions from select toolboxes), and another that doesn't (mainly to keep file size to a minimum).

Should Stack Overflow choose to use it, it's as simple as serving an additional JavaScript file, which extends the code prettifier to handle MATLAB code.

For the time being, I created a userscript version so people can try it immediately (I have been using it myself for some time now).

You can install the userscript directly from the link https://github.com/amroamroamro/prettify-matlab/raw/master/js/prettify-matlab.user.js or choose the "lite" version, https://github.com/amroamroamro/prettify-matlab/raw/no_functions/js/prettify-matlab.user.js.

  • I have been using this very happily until now, when Google decided to disable any extensions that didn't originate from their store, and there's no way to re-enable them. It looks like the only way for people using Chrome to use this is for the developer (s) to upload the extension into the Chrome Web Store.
    – am304
    Jun 16 '14 at 8:27
  • @am304: Firefox is my main browser, so I hadn't noticed the change.. Apparently the workaround is easy: just download the userscript as a regular file (prettify-matlab.user.js), go to your extensions page (chrome://extensions/), and drag/drop the file onto the page. That will bypass the store-only limitation. I just tried it and it worked fine. Alternatively you could install the Tampermonkey extension, this is like Greasemonkey for Chrome browsers (it's a must have extension for anyone who uses userscripts regularly).
    – Amro
    Jun 16 '14 at 12:23
  • See here for detailed instructions for various browsers: stackapps.com/tags/script/info
    – Amro
    Jun 16 '14 at 12:24
  • I tried it and it didn't work. That's what I used to do but this week-end Google pushed a new version of Chrome that doesn't allow you to do that (Version 35.0.1916.153 m).
    – am304
    Jun 16 '14 at 12:49
  • Update: it looks like if I first delete the existing extension and drag & drop the file again, it works. I'll try closing and re-starting Chrome next to see if it holds.
    – am304
    Jun 16 '14 at 12:50
  • Nope. I restarted Chrome and it got disabled again, without the possibility to re-enable it.
    – am304
    Jun 16 '14 at 16:30
  • I just tried it on a freshly installed Chrome (latest v35), and now I see what mean. Apparently Google has started blocking all extensions on Windows not installed from the Web Store (even permanently disables installed ones too!), except installs via enterprise policy or developer mode (unfortunately those are not the most straightforward ways). IMO the easiest method to working with userscripts is to just install the Tampermonkey extension to manage all your userscripts.
    – Amro
    Jun 16 '14 at 18:47
  • Here is someone who asked about the same problem: superuser.com/questions/767286/…
    – Amro
    Jun 16 '14 at 18:53
  • Thanks, I think I have managed to get Tampermonkey to work...
    – am304
    Jun 17 '14 at 8:30
  • 1
    @Amro I'm not sure if you've seen this: meta.stackexchange.com/questions/278141/… It appears the size of the prettify script is a problem.
    – beaker
    May 18 '16 at 15:22
  • Oded also notes in a subsequent comment that if it's possible to deflate the thing by throwing away features, they would consider it if its final size was comparable to other languages. (cc @beaker) May 18 '16 at 16:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .