What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

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?

share|improve this question
4  
We do have custom prettify javascript for a few languages, TeX for one. Ideally it'd be contributed back to prettify. –  Kevin Montrose 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
1  
Don't forget Octave. –  Mechanical snail Sep 13 '12 at 10:12
6  
@KevinMontrose, it's been integrated into prettify. Could you look at updating the version used on Stack Overflow? –  Matthew Simoneau Mar 6 '13 at 21:09
1  
@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 at 18:15

3 Answers 3

up vote 27 down vote accepted
+50

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.

share|improve this answer
    
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 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 at 12:23
    
See here for detailed instructions for various browsers: stackapps.com/tags/script/info –  Amro Jun 16 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 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 at 12:50
    
Nope. I restarted Chrome and it got disabled again, without the possibility to re-enable it. –  am304 Jun 16 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 at 18:47
    
Here is someone who asked about the same problem: superuser.com/questions/767286/… –  Amro Jun 16 at 18:53
    
Thanks, I think I have managed to get Tampermonkey to work... –  am304 Jun 17 at 8:30

Shameless bump.

I think proper syntax highlighting for matlab would be a very welcome addition. Given the number of questions regarding matlab on a daily basis, I'd say it deserves pretty code.

I tried to use other languages' syntax highlighting as a workaround, but no other language seems to have syntax which resembles matlab closely.

share|improve this answer
2  
You can apply as much colour as you like, matlab code will never be pretty. Understanding it did for that ever happening –  Richard Tingle Sep 29 '13 at 8:51
1  
@RichardTingle Yes the matlab language has some ugly quirks. That said, syntax highlighting can make code significantly more readable, which in turn makes it easier for us to provide clear questions/answers. A simple color difference for comments and actual code would already go a long way. –  Marc Claesen Sep 29 '13 at 8:55
    
I am of course joking (sort of). Syntax highlighting would of course be a good thing –  Richard Tingle Sep 29 '13 at 9:16
2  
Judging by other answers (and the docs) it's already in Prettify so all that's required is SE to pull the latest version (if they haven't already) and apply default syntax highlighting to the tag. –  ben is uǝq backwards Sep 29 '13 at 10:08

Amro's support for the MATLAB language has been accepted into google-code-prettify and the new version has been released. Can we update the version used here on stackoverflow.com?

share|improve this answer
    
I totally agree that MATLAB syntax highlighting on SO sucks! I really hope it gets updated soon. –  Oleg Komarov Apr 12 '13 at 14:28
1  
MATLAB support has been integrated into google-code-prettify for some time now, but one must explicitly enable support for any of the additional languages. Stack Overflow chose to enable some of them but not all... As of now (and according to the JS file being served), the following additional languages are enabled by SO (not listing the ones included in the base package): Closure, CSS, Go, Haskel, Lisp, Lua, F#, Pascal, Protocol Buffers, R, Scala, SQL, LaTeX, VB, VHDL –  Amro Jun 16 at 13:13

You must log in to answer this question.

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