Desktop Tools and Development Environment Previous page   Next Page

Marking Up Text in Cells for Publishing

To publish an M-file and results, mark up the file using cell features. This adds and formats comments for the published results. You can include the markup as you write the basic code, mark up the file after you've written the code, or do both. The markup applies to any of the available publishing options: HTML, XML, LaTeX, Word, and PowerPoint.

Any cell features you use for evaluating and improving your code will be used for publishing purposes as well. The Example of Publishing Without Text Markup shows how the cells used for improving an M-file appear when the M-file is published. You might want to change the existing cells for publishing purposes, but note that this changes the cells for evaluation purposes as well. For example, to have text markup and formatted comments in the output document, the comments must appear at the start of a cell, before any code.

Mark up comment text in one of two ways:

The following table describes each markup option and how to use it, and refers to Example of Publishing with Text Markup.

Format
Menu Item to Produce Format (Cell -> Insert Text Markup -> Item)
Resulting Code
Published Results 
Overall document heading
Cell Title
Add a blank line at the top of the M-file, select this menu item, and replace TITLE in the resulting text with the document heading you want.
See step 1 in the example.
%% TITLE
Add any overall comments about the file in the lines following this title. But do not add code after the first title and before the next cell (line starting with %%) if you want the first title to appear as the overall document title.
In the example, the overall heading is
%% Plot Sine Wave
Formatted as a top level heading (h1 in HTML), using a large bold font.
The title text automatically appears in bold in the M-file and in the resulting published document.
Section title (also known as a cell title)
Cell Title
Position the cursor at the start of a cell, select this menu item, and replace TITLE in the resulting text with the cell title you want.
%% TITLE
In the example, the section titles are
%% Calculate and Plot Sine Wave
%% Modify Plot Properties
Formatted as a heading (h2 in HTML), using a medium size, bold font.
The title text automatically appears in bold in the M-file and in the resulting published document.
Descriptive text
Descriptive Text
Position the cursor where you want to add a formatted comment, select this menu item, and replace the resulting DESCRIPTIVE TEXT with your comment.
% DESCRIPTIVE TEXT
In the example, the descriptive text for the overall heading is
% Calculate and plot a sine wave
Text appears as a formatted comment in the output.
Note that descriptive text must appear before the first line of code in a cell.
Bold text
Bold Text
Select the text within a comment that you want to appear in bold and then select this menu item.
If no text is selected, inserts a new bold comment with sample text, and you replace the sample text.
% *Bold text*
Text appears in bold in the output.
Bold text
Monospaced text
Monospaced text
Select the text within a comment that you want to appear in a monospaced font and then select this menu item. See step 3 in the example.
If no text is selected, inserts a new monospaced comment with sample text, and you replace the sample text.
% |Monospaced text|
In the example, monospaced text is added in line 9:
% Calculate and plot |y=sin(x)|.
Text appears in monospace in the output.
Monospaced text
Indented text
Preformatted Text
Position the cursor before the line where you want to add indented text and select this menu item. Replace the sample text inserted with the text you want, including tabs and spaces.
A line of preformatted text must begin with a % symbol, followed by two or more spaces.
%
%  Preformatted
%      Text
%
The blank comment lines above and below the preformatted lines distinguish the lines in between as preformatted.
The indents, spacing, and line lengths in the M-file are preserved in the output.

Preformatted
     Text

Bullets
Bulleted List
Position the cursor before the line where you want to add a bulleted list and select this menu item. Replace the sample text inserted, ITEM 1 and ITEM 2, with the text you want.
%
% * Item1
% * Item2
%
The blank comment lines above and below the bullet items, as well as the * before each item, distinguish the bulleted list.
Items appear in a bulleted list.
  • Item1
  • Item2
Equations and symbols
TeX Equation
Position the cursor before the line where you want to add an equation or symbols and select this menu item. Replace the sample text inserted, e^{\pi i} + 1 = 0, with the TeX equation you want. See step 2 in the example.
For a list of symbols you can display and the character sequence to create them, see the String property on MATLAB graphics reference page for text properties.
%
% $$e^{\pi i} + 1 = 0$$
%
The blank comment lines above and below the equation line, as well as the $$ before and after the equation text, distinguish the TeX equation.
In the example, line 7 includes a TeX equation:
% $$0\leq 6\pi$$
Equation and symbols appear in TeX output format.
Image of equation showing symbol for pi, showing pi times i as a superscript, and showing e and pi times i in italics.
Links (for HTML output)
Enter comment text that includes a valid Internet address.
% http://www.
mathworks.com

http://www.mathworks.
com


Previous page  Example of Publishing with Text Markup Publishing M-Files Using Cells Next page

© 1994-2005 The MathWorks, Inc.