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
By
Ken Orr
Ken is a developer on the MATLAB Desktop team. He loves the art of graphic design as well as developing visually pleasing user interfaces - he's one of those 'crazy' Mac guys!
9:57 am |
Posted in Editor |
Permalink |
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.
Leave a Reply
|
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.
Thanks for the encouragement.
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
Oh, bummer. The HTML got lost in the process.. Well, I think my descriptions are clear enough as it is.
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?