{"id":189,"date":"2008-01-21T09:57:46","date_gmt":"2008-01-21T14:57:46","guid":{"rendered":"https:\/\/blogs.mathworks.com\/desktop\/2008\/01\/21\/marking-up-m-with-html\/"},"modified":"2016-04-03T15:37:09","modified_gmt":"2016-04-03T19:37:09","slug":"marking-up-m-with-html","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2008\/01\/21\/marking-up-m-with-html\/","title":{"rendered":"Marking up M with HTML"},"content":{"rendered":"<p><i><br \/>\nI&#8217;d like to welcome guest blogger Michael Katz, the newest member of the MATLAB Desktop team. Michael will occasionally be blogging here on the <a href=\"https:\/\/blogs.mathworks.com\/community\/\">Inside the MATLAB Desktop<\/a> blog.<br \/>\n<\/i><\/p>\n<p>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 <a href=\"https:\/\/www.mathworks.com\/access\/helpdesk\/help\/techdoc\/index.html?\/access\/helpdesk\/help\/techdoc\/ref\/publish.html\">PUBLISH<\/a> function to turn your MATLAB code into web pages. I am a big believer in letting code speak for itself &#8211; that is by having the source generate its own reports or documentation. PUBLISH has useful formatting power by allowing you to add any <a href=\"http:\/\/www.w3schools.com\/html\/default.asp\">HTML<\/a> tag to your published web pages.<\/p>\n<p>To demonstrate PUBLISH&#8217;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.<\/p>\n<p>Unfortunately there is not an overwhelming amount of HTML markup usage in published M-file world.<\/p>\n<p>Why not? It&#8217;s as easy as clicking the <i>Cell -&gt; Insert Text Markup -&gt; HTML Markup<\/i> menu item.<\/p>\n<div align=\"center\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/michael_katz_publishing\/cell_menu_small.jpg\" alt=\"\" align=\"center\" hspace=\"5\" vspace=\"5\" \/><\/div>\n<p>Selecting &#8220;HTML Markup&#8221; gives you a nice little two cell table, but you can put whatever HTML you want between the &lt;html&gt;&lt;\/html&gt; tags.<\/p>\n<p>But why would you want to do this?<\/p>\n<p>You can already get bold and italic text, pre-formatting, and lists with the regular markup. Sure you can could have some <span style=\"color: red;\">nice red text<\/span> with &lt;font color=&#8221;red&#8221;&gt;nice red text&lt;\/font&gt;, make paragraphs &lt;p&gt; and horizontal lines &lt;hr&gt;. But you can get even more power from iframes, Java Script, forms, and tables.<\/p>\n<p>I&#8217;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&#8217;s web browser; clicking on them will give you an error in a regular browser.<\/p>\n<p>The following MATLAB code:<\/p>\n<p>&nbsp;<\/p>\n<div style=\"width: 500px; text-align: left; overflow: auto; border: 1px solid #DDDDDD; background: #EEEEEE; padding: 0px 10px 0px 10px;\">\n<pre style=\"font-size: small;\"><span style=\"color: #228b22;\">\t\r\n%% Publish to HTML Demo\r\n% &lt;html&gt;\r\n% This is a demonstration of PUBLISH's ability to use html markup inside a\r\n% published m-file. For help about marking up m-files for publishing, see\r\n% the following documentation:&lt;br&gt;\r\n% &lt;iframe\r\n% src=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/marking-up-matlab-comments-for-publishing.html\"\r\n% width=600 height=300&gt;&lt;\/iframe&gt;\r\n% &lt;p&gt;Or click on the following button if you have this page opened inside\r\n% MATLAB&lt;\/p&gt;\r\n% &lt;button onclick=\"document.location='matlab:web([docroot \\'\/techdoc\/matlab_env\/f6-30186.html\\'])'\"&gt;Open the\r\n% markup Documentation&lt;\/button&gt;\r\n% &lt;\/html&gt;\r\n%\r\n<\/span><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Publishes into this document:<\/p>\n<div align=\"center\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/michael_katz_publishing\/published_output_small.jpg\" alt=\"\" align=\"center\" hspace=\"5\" vspace=\"5\" \/><\/div>\n<p>&nbsp;<\/p>\n<p>If you were to publish this on your machine, you&#8217;d be able to click the &#8220;Open the markup Documentation&#8221; button in the MATLAB web browser. This would take you right to the &#8220;Marking Up Text in Cells for Publishing&#8221; section in the MATLAB help browser.<\/p>\n<p>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&#8217;s <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=14453&amp;objectType=file#\">makeHTMLTable<\/a> on MATLAB Central.<\/p>\n<p>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 <a href=\"https:\/\/www.mathworks.com\/access\/helpdesk\/help\/techdoc\/index.html?\/access\/helpdesk\/help\/techdoc\/matlab_env\/f6-30186.html\">documentation<\/a><\/p>\n<p>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.<\/p>\n<p>So, go crazy. Add some flair to your published files: create mash-ups, add tables and JavaScript; make your published files come alive!<\/p>\n<p>Happy formatting.<\/p>\n<p><i><br \/>\n-by Michael Katz, The MathWorks<br \/>\n<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\nI&#8217;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.<\/p>\n<p>For my first&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2008\/01\/21\/marking-up-m-with-html\/\">read more >><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/189"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=189"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/189\/revisions"}],"predecessor-version":[{"id":3412,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/189\/revisions\/3412"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}