Until recently whenever I wanted to post some code on my wordpress blog I used to put something like this

```
function m = magicsquare(n)
%MAGICSQUARE generates a magic square matrix of the size specified
% by the input parameter n.
% Copyright 2003-2006 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);
```

Which is actually not bad at all. But what if I wanted it with syntax highlights for a specific language, say C++, Java, or why not MATLAB as well. And on top of that, that you could get line numbering, line highlighting, no column wrapping, and a bunch of other cool ways to display code. Well the guys at wordpress came up with a nice way to do it:

We have created a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages […] To accomplish the above, just wrap your code in these tags:

**[****sourcecode language=”css”]**

your code here

[/sourcecode]

via Posting Source Code — Support — WordPress.com.

So if I input something like this:

`[`

```
sourcecode language="matlab"]
function m = magicsquare(n)
%MAGICSQUARE generates a magic square matrix of the size specified
% by the input parameter n.
% Copyright 2003-2006 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);
[/sourcecode]
```

I actually get this:

function m = magicsquare(n)
%MAGICSQUARE generates a magic square matrix of the size specified
% by the input parameter n.
% Copyright 2003-2006 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);

Pretty neat! There are a lot of options for the shortcode check the link to see them.

### Like this:

Like Loading...

*Related*

Just what I wanted! Thanks for posting 😀

Thanks for the comment!

Pingback: Legendre polynomials in MatLab | Room 196, Hilbert's Hotel

Thank you for the information.

You’re welcome. Thanks for the comment.

Pingback: Matlab em wordpress | Pedro Dreyer

Nice blog!

Please post more about Matlab ^^

Thanks for the comment. I’ll keep that in mind.

Pingback: Using MATLAB codes | hiepvudang