MATLAB syntax highlighting for Google Code prettify
The project was inspired by the similar Mathematica.SE syntax highlighter.
Currently the following constructs are recognized:
- single line as well as block comments (
% this is a comment)
- quoted string (
- number literals (
- system commands (
- line continuation characters (
- transpose operator (single quote) vs. strings
- command prompt/command output (
- error/warning messages (
??? Error in ...and
- parentheses, brackets, braces (
- other operators (
- MATLAB language keywords (
- some special variables and constants (
- over 1300 builtin functions from core MATLAB (
- additional functions from popular toolboxes (Statistics, IPT, and Optimization)
- user-defined indentifiers (function and variable names not matched in previous steps)
See the wiki for sample screenshots.
You can rebuild the project by running
rake SO:build. This will create the output
js directory using the templates sources from
(This step requires Rake, a Make-like build tool for Ruby, used here to provide
basic template processing).
The script is only activated on questions tagged
In addition, a separate userscript is included to allow switching the language used by the prettifier. It adds a small button to the top-right corner of each code block, with an attached drop-down menu to allow language selection.
MathWorks (MATLAB Answers / File Exchange)
To apply the MALTAB syntax highlighting on code snippets in your own web pages, first include the prettify scripts and stylesheets in your document (as explained in the prettify project documentation). To use the MATLAB language extension, include the MATLAB script, and place your source code inside a preformatted HTML tag as follows:
<pre class="prettyprint lang-matlab"> <code> % example code x = [1,2,3]; sum(x.^2) </code> </pre>
prettyPrint(), marked sections will be pretty-printed, and the
default styles will be applied. You can customize them with your own, or use the
provided CSS file which resembles the color scheme of
the MATLAB IDE (with some additions of my own).
Check the demo page for a demonstration.
Copyright (c) 2013 by Amro <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.