Ken & Mike on the MATLAB Desktop

April 13th, 2009

Bring along your syntax highlighted code

People often ask how they can incorporate their syntax highlighted code into other mediums, like Microsoft Word, Microsoft PowerPoint, web pages etc. There are actually a number of ways to bring along your colorful code, one of which will likely meet your needs.

Microsoft Word
You can paste text right into Word that you’ve copied in the MATLAB Editor, and it will be auto-magically highlighted. It doesn’t get much easier than that.

Microsoft PowerPoint

It’s not quite as simple to paste syntax-highlighted code into PowerPoint as it is in Word, but it’s still not too difficult.

Select Edit -> Paste Special….

In the Paste Special dialog, select Formatted Text (RTF), and press OK.

That’s it.

HTML
You can also publish your MATLAB code to HTML, which allows you view it in a web browser or insert it into anything that can render HTML. To publish to HTML, open your file in the MATLAB Editor and press the publish () button (note that the default output format is HTML).

In general, I find that if I can show code in a syntax-highlighted form, it’s easier for the viewer to understand — hopefully you find these tips useful for doing just that.

4 Responses to “Bring along your syntax highlighted code”

  1. Naor replied on :

    Ken,
    Can you do a post on the Figure Group Container? Specifically, what is it good for and any ways to change its default behavior.
    Thanks

  2. Ken replied on :

    Hi Naor,

    I’ll add your blog-entry request to the list of future entries.

    Thanks for the request.
    -Ken

  3. Erik replied on :

    Is it possible to automatically publish highlighted code to LaTeX instead of {verbatim}? Right now I’m using dbtype to publish functions defined elsewhere in different files, but it’s not that elegant.

  4. Matthew Simoneau replied on :

    Erik, there isn’t a way to get syntax highlighted code in LaTeX yet. It’s on our wishlist. Thanks for helping us prioritize this.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Ken & Mike work on the MATLAB Desktop team.
  • Ori: The current folder shortcut used to be alt-y. Now it is alt-o. However, while in the editor window, alt-o opens...
  • Jose Miguel: Hi First of all, thanks for the post, it is really useful. I am trying to develop a Java GUI within...
  • Ken: Hi Siddharth, There isn’t currently any way to move the docking controls. Feel free to submit an...
  • Phil: I have the same problem as described above with UITable working fine in the Matlab environment but showing no...
  • Siddharth: Is there any way to move the position of the docking controls (or eliminate them through some...
  • Chris: Yes, it is a challenge to organize functions into categories, especially with so many functions. Ken and I...
  • Mike: Thanks for fielding that one, Yair.
  • Yair Altman: Jimmy - if you mean that you wish to include hyperlinks in your function’s help comment, that will...
  • OysterEngineer: Thanks for explaining the Function Browser. I fired it up and gave it a try. It appears that it has...
  • Jimmy: Is there any way to include hyperlinks in a comment, such as the standard help at the beginning of a function?

These postings are the author's and don't necessarily represent the opinions of The MathWorks.