Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Inside the MATLAB Desktop

January 21st, 2008

Marking up M with HTML


I’d like to welcome guest blogger Michael Katz, the newest member of the MATLAB Desktop team. Michael will occasionally be blogging here on the Inside the MATLAB Desktop blog.

For my first post as the newest developer on the desktop team, I want to wax philosophical about how great it is to use the PUBLISH function to turn your MATLAB code into web pages. I am a big believer in letting code speak for itself - that is by having the source generate its own reports or documentation. PUBLISH has useful formatting power by allowing you to add any HTML tag to your published web pages.

To demonstrate PUBLISH’s power, I hoped to pull a brilliant example of HTML usage in a randomly selected, published M-file already out there on the web. We have a report on MATLAB Central that searches the web looking for published M-files.

Unfortunately there is not an overwhelming amount of HTML markup usage in published M-file world.

Why not? It’s as easy as clicking the Cell -> Insert Text Markup -> HTML Markup menu item.

Selecting “HTML Markup” gives you a nice little two cell table, but you can put whatever HTML you want between the <html></html> tags.

But why would you want to do this?

You can already get bold and italic text, pre-formatting, and lists with the regular markup. Sure you can could have some nice red text with <font color=”red”>nice red text</font>, make paragraphs <p> and horizontal lines <hr>. But you can get even more power from iframes, Java Script, forms, and tables.

I’ve created the following example to show off some of those features, which I then published in MATLAB. The two buttons will only work inside MATLAB’s web browser; clicking on them will give you an error in a regular browser.

The following MATLAB code:


%% Publish to HTML Demo
% <html>
% This is a demonstration of PUBLISH’s ability to use html markup inside a
% published m-file. For help about marking up m-files for publishing, see
% the following documentation:<br>
% <iframe
% src="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/f6-30186.html"
% width=600 height=300></iframe>
% <p>Or click on the following button if you have this page opened inside
% MATLAB</p>
% <button onclick="document.location=’matlab:web([docroot \’/techdoc/matlab_env/f6-30186.html\’])’">Open the
% markup Documentation</button>
% </html>
%

Publishes into this document:

If you were to publish this on your machine, you’d be able to click the “Open the markup Documentation” button in the MATLAB web browser. This would take you right to the “Marking Up Text in Cells for Publishing” section in the MATLAB help browser.

All this is great for static text, but if you want to put some calculated data into table in your published document, I suggest you take a look at Ned’s makeHTMLTable on MATLAB Central.

In addition to using HTML formatting in your published M-files, you can have LaTeX equations, links, images, and easier to read markup for making lists, bold, italic and preformatted text. A full listing of the types of markup that one can have in a published M-file is in our documentation

Note that you cannot mix HTML formatting with other publish formatting in the same comment block. If you do it will treat any HTML tags as regular PUBLISH-formatted links.

So, go crazy. Add some flair to your published files: create mash-ups, add tables and JavaScript; make your published files come alive!

Happy formatting.


-by Michael Katz, The MathWorks

5 Responses to “Marking up M with HTML”

  1. Kwadwo Dompreh replied on :

    Awesome, wonderful and smart start keep it up Mich. I am so impressed with your Blog and wish you will continue with the good work.

  2. Michael Katz replied on :

    Thanks for the encouragement.

  3. Daniel Armyr replied on :

    Hi.
    I was very impressed with this possibility when I first read about it, but now that I try to use it for the first time I have noticed two unwanted behaviours that together are so severe as to classify them as bugs from my perspective.

    1) It seems not to be possible to mix HTML and non-html within the comments for a single cell. For example:

    %% Test
    %
    % onetwo
    %
    % Hello World!

    2) If the extra text is placed within the html block, it is formated very differently from the way normal comments are, specifically the line-length is not at all the same. For example:

    %% Test 1
    % It can be argued, though it is not possible to verify
    % without the original calbox which was not sent back to
    % without the original calbox which was not sent back to
    %% Test2
    %
    % onetwo
    % It can be argued, though it is not possible to verify
    % without the original calbox which was not sent back to
    % without the original calbox which was not sent back to
    %

    When studying the HTML output from these examples, it seems Mathworks has chosen quite a sloppy approach to the problem, using the extreme forgivingness of most HTML browsers to allow the HTML markup. Unfortunately this leads to HTMl which looks like a rats-nest and whose results are far from predictable.

    Sincerely
    Daniel Armyr

  4. Daniel Armyr replied on :

    Oh, bummer. The HTML got lost in the process.. Well, I think my descriptions are clear enough as it is.

  5. Michael Katz replied on :

    Daniel,
    Yes it is a limitation in PUBLISH that you can not mix HTML with other types of markup. Hopefully you can use the html-equivalent if you need specific formatting. Can you email me your second example M-file so I can understand the issue better?

Leave a Reply


Inside the MATLAB Desktop is written by the MATLAB Interface teams.

Team picture
  • Etienne: Hello, Is it possible to change the background color of a particular cell?
  • Ken: No problem Mark…glad to help. Enjoy your font!
  • Mark Andrews: Ken, thanks for replying @3 and giving such clear instructions on how to get this to work.
  • Steve Eddins: Hi Ken, Every year or so I try to find a programming font that would really make me happy. A couple of...
  • Ken: @Jiro: Andale Mono looks nice! I especially like the rendering of the letter “g”.
  • Ken: Hi Mark, The issue your referring to (see the bug report here) was fixed in version 7.5 (R2007b). The problem...
  • Jiro: Ken, That’s a nice font. I use “Andale Mono” which has a similar look. I also like the clear...
  • Queffurust: This is my “cleanup” ; shortcut clc % clear Command Window close all hidden % deletes all...
  • Mark Andrews: Ken, should this work with version 7.0 (R14) on Windows? My favorite font is Consolas, but MATLAB seems...
  • Mark Feldman: Like Bryan (#38) and Kim (#40), I strongly request that you add native vi key bindings to the MATLAB...

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

Related Topics