views:

83

answers:

3

I could not find what formatting available to write help for your own MATLAB function. Very little information is available in official documentation.

Do you know about any other formatting that can be visible with Help Browser (not with help function)? As it is for built-in functions. How to format headings (like Syntax, Description, Examples)? Are bullets, tables possible? Or may be it should be a separate file?

I've tried text markup as used for PUBLISH and HTML, didn't work.

I found only one interesting thing. If your function contains mixed case, like testHelpFunction, its name will be highlighted:

alt text

No highlighting if it's just testhelpfunction.

Any other thoughts?

UPDATE

Here is extensive documentation I found on creating your own help files:

Providing Your Own Help and Demos

+1  A: 

I figure there is some (see example), but I've never found the appropriate documentation. I often have such blocks:

% ...
%
% See also:
%   this_other_function()
%
% <author>

And the See also part is formatted as a title, but if you replace See also by something else, it doesn't work. If anyone finds the list of such supported titles, please link to it here!

André Caron
@Andre, thanks. Great finding, +1. Interestingly, "See also" section will be at the very end of the help in Help Browser. And existing functions will have links to its help page.
yuk
+3  A: 

Try this other section in the official documentation. It's more thorough. MATLAB > User's Guide > Desktop Tools and Development Environment > Customizing Help and Demos > Providing Your Own Help and Demos. This describes both simple helptext and generating separate HTML help files.

Here's the helptext formatting I've picked up on and found useful.

function foo(x,y,z)
%FOO One-line description goes here
%
% foo(x,y,z)
%
% Multi-line paragraphs of descriptive text go here. It's fine for them to
% span lines. It's treated as preformatted text; help() and doc() will not
% re-wrap lines. In the editor, you can highlight paragraphs, right-click,
% and choose "Wrap selected comments" to re-flow the text.
%
% More detailed help is in the <a href="matlab: help foo>extended_help">extended help</a>.
% It's broken out like this so you can keep the main "help foo" text on 
% a single screen, and then break out obscure parts to separate sections.
%
% Examples:
% foo(1,2,3)
%
% See also:
% BAR
% SOMECLASS/SOMEMETHOD

disp(x+y+z);

function extended_help
%EXTENDED_HELP Some additional technical details and examples
%
% Here is where you would put additional examples, technical discussions,
% documentation on obscure features and options, and so on.

error('This is a placeholder function just for helptext');
  • The first line after the function signature is called the "H1 line". It needs to be just one line so it is properly picked up by contentsrpt(), which can autogenerate a Contents.m file from the helptext in your functions
  • The function name in the H1 line is all caps, regardless of actual capitalization of the function name in the signature
  • Case matters for the "See also". I'm not sure which all cases work; this one does for sure.
  • Function names after "See also:" are all caps. Method names are qualified; I think names of methods in the same class as the current method can be unqualified.

Everything between the H1 line and "Examples:" is just a conventional formatting that I find readable; help() doesn't treat it specially.

You can use a limited form of hyperlinks in help. In particular, you can use hyperlinks to invoke arbitrary Matlab commands, and point to other sections of helptext by having it invoke help(). You can use this to point to any function; "function>subfunction" is just the syntax for addressing subfunctions in help() calls. Unfortunately, since you need to put either "help" or "doc" in those hyperlinks, it only works in one or the other presentation form. It would be nicer if there were a direct helptext hyperlink form.

Andrew Janke
I've decided to accept this answer as the most full summary of m-file help formatting features. Thanks, Andrew. I'm very appreciate other answers as well.
yuk
+1  A: 

I think the most important aspect in help formatting is that there is a help at all, and that your formatting is consistent, so that you (and people working with you) don't waste time finding out how to look for the information. Note that for OOP, it is useful to have a superclass with a 'help'-method that calls doc(class(obj)), since you cannot easily access the help from an instantiation of your class

To help me be consistent (and to make sure I don't forget stuff), I have created an automatic function template on the file exchange.

Here's the minimal header

function testhelp
%TESTHELP is an example (this is the H1 line)
%
% SYNOPSIS: a=testhelp(b,c)
%
% INPUT b: some input parameter
%       c: (opt) some optional input parameter. Default: []
%
% OUTPUT a: some output parameter
%
% REMARKS This is just an example, it won't run
%
% SEE ALSO testHelpFunction
%
% created with MATLAB ver.: 7.11.0.584 (R2010b) on Mac OS X  Version: 10.6.4 Build: 10F569 
%
% created by: Jonas
% DATE: 01-Oct-2010
%
Jonas