Helpgen is able to parse *.m and *.cpp files and detect "magic" comment format specifiers. The "magic" comments are then converted into documentation, sanity tests or separate regression test scripts. 

Format of the comments that are processed by helpgen.

Documentation block: delimits the start and end of the "magic" comment block.
The documentation block begins and ends with comment string that starts with exclamation point character "!".

Example:
Matlab:
%!
%@Module INTRODUCTION This is a doc block.
%!

C/C++:
//!
//@Module INTRODUCTION This is a doc block.
//!

------------------------------------------------------------------------------

Module Name: subsection name. 
For a function module name would be the function name. Module name starts with "@Module" followed by module name and description.

Example:
Matlab:
%@Module IMAGE Image Display Function

C/C++:
//@Module IMAGE Image Display Function

------------------------------------------------------------------------------

Section Name: name of the help section where the command help will be placed. 
Possible section names are listed in file "section_descriptors.txt" (if you want to add a new section name you have to edit that file before running helpgen). Section name starts with "@@Section" followed by the section name.

Example:
Matlab:
%@@Section HANDLE

C/C++:
//@@Section HANDLE

------------------------------------------------------------------------------

Named section: any section name that will be placed as heading in the help section for the current command.
Named section starts with "@@Name", where "Name" can be anything.

Example:
Matlab:
%@@Usage
will add subheading "Usage" to the help page for the current command.

C/C++:
//@@Usage

------------------------------------------------------------------------------

Sample script to be added to help: executes script and adds script and output to the help.
Script is added as a comment delimited by "@<" and "@>". You can use "mprint imageX" to add figure to the help file.

Example:
Matlab:
%@<
%x = rand(512);
%x((-64:63)+256,(-128:127)+256) = 1.0;
%figure
%image(x)
%colormap(gray)
%mprint image1
%@>

This will generate figure with the name image1 that can be inserted in the help text using figure tag (see below).

C/C++:
//@<
//A = int32(10*rand(4,5))
//diag(A)
//diag(A,1)
//@>

------------------------------------------------------------------------------

Verbatim block: block of text to be put verbatim in the help file (e.g. with offset and different font).
Text block delimited by "@[" and "@]" will be added verbatim.

Example:
Matlab:
%@[
%  handle = image(C, properties...)
%@]

C/C++:
//@<
//A = int32(10*rand(4,5))
//diag(A)
//diag(A,1)
//@>

------------------------------------------------------------------------------

Figure tag: inserts figure (e.g. generated by mprint as in sample script example). 
Use special comment "@figure NAME" to insert the figure.

Example:
Matlab:
%The resulting image looks like:
%@figure image1


------------------------------------------------------------------------------

Test section: regression test section begins.
"@@Tests" denotes the start of regression test section. Regression tests are not placed in the help file. Instead they are 
added to the toolbox/tests directory. There are two types of tests that can be added: whitebox tests and test functions.

Example:
Matlab:
%@@Tests

C/C++:
//@@Tests

------------------------------------------------------------------------------
 
 Whitebox test: should be placed after the tests section header. The whitebox test starts with "@$" tag, followed by 3 strings: expression to be evaluated, expected result and type of match ("exact" or "close"). Expression must have form "y=expr", where expr is any valid FreeMat expression (you must use variable name "y" to assign the result). If match type is set to "close" the results with small relative error (10^-14 for doubles or 10^-6 for singles) are considered equal.
 
The test is added to the toolbox/tests directory with name wbtest_modulename_num.m and run using run_tests script.

Example:
Matlab:
%@@Tests
%@$"y=any([1,0,0;1,0,0;0,0,1],2)","[1;1;1]","exact"
%@$"y=norm([4,3])","5","close"

C/C++:
//@$"y=sprintf('hello %d',5)","'hello 5'","exact"

------------------------------------------------------------------------------

Unit test: add unit test function. Unit test function is delimited by "@{" and "@}". The first line following "${" should contain a unique matlab file name where the test will be saved. The script is saved in the toolbox/tests directory. The function should return "1" if the test succeeds.

Example:
Matlab:
%@@Tests
%@{ test_test1.m
%% Check that test function works properly for a scalar 1
%function test_val = test_test1
%test_val = test(1) == 1;
%@}

